当前位置: 首页>>代码示例>>C++>>正文


C++ disk_read函数代码示例

本文整理汇总了C++中disk_read函数的典型用法代码示例。如果您正苦于以下问题:C++ disk_read函数的具体用法?C++ disk_read怎么用?C++ disk_read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了disk_read函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fs_write

int fs_write( char *name, const char *data, int length, int offset )
{
 

  if(mb.magic != FS_MAGIC){
    printf("disk not mounted\n");
    return -1;
  }

  if(!valid_name(name)){
     printf("invalid name\n");
    return -1;
  }

  dir_entry* file = found_file(name);

  if(!file){
    printf("file not found\n");
    return -1;
  }

  unsigned first_block = get_block(file, offset);

  if(first_block == -1){
    printf("invalid offset");
    return -1;
  }

  int bytes_written = 0;
  unsigned block_offset = offset % DISK_BLOCK_SIZE;
  unsigned block = first_block;

  char current_block[DISK_BLOCK_SIZE];
  
  disk_read(first_block, current_block);

  int to_write = DISK_BLOCK_SIZE;
  while(bytes_written < length){
    if(block == EOFF) {
      printf("invalid length\n");
      return -1;
    }

    if(length - bytes_written < DISK_BLOCK_SIZE){
      to_write = length - bytes_written;
      disk_read(block, current_block);
    }

    memcpy(current_block + block_offset, data, to_write);
    
    disk_write(block, current_block);

    block_offset = 0;
    bytes_written += to_write;
    block = fat[block];
  }

  return bytes_written;
}
开发者ID:GoncaloBFM,项目名称:DiskEmulator,代码行数:59,代码来源:fs+(copy).c

示例2: read_mac_partition

static quik_err_t
read_mac_partition(ihandle dev,
                   unsigned part,
                   part_t *p)
{
   unsigned i;
   unsigned upart;
   unsigned blocks_in_map;
   length_t len;
   length_t secsize;
   char blk[SECTOR_SIZE];

   struct mac_partition *mp = (struct mac_partition *) blk;
   struct mac_driver_desc *md = (struct mac_driver_desc *) blk;

   len = disk_read(dev, blk, SECTOR_SIZE, 0LL);
   if (len != SECTOR_SIZE) {
      return ERR_DEV_SHORT_READ;
   }

   if (md->signature != MAC_DRIVER_MAGIC) {
      return ERR_PART_NOT_MAC;
   }

   secsize = md->block_size;
   blocks_in_map = 1;
   upart = 0;
   for (i = 1; i <= blocks_in_map; ++i) {
      if (disk_read(dev, blk, SECTOR_SIZE, (offset_t) i * secsize) != SECTOR_SIZE) {
         return ERR_DEV_SHORT_READ;
      }

      if (mp->signature != MAC_PARTITION_MAGIC) {
         break;
      }

      if (i == 1) {
         blocks_in_map = mp->map_count;
      }

      ++upart;

      /* If part is 0, use the first bootable partition. */
      if (part == upart
          || (part == 0 && (mp->status & STATUS_BOOTABLE) != 0
              && strcasecmp(mp->processor, "powerpc") == 0)) {
         p->start = (offset_t) mp->start_block * (offset_t) secsize;
         p->len = (offset_t) mp->block_count * (offset_t) secsize;
         p->dev = dev;
         return ERR_NONE;
      }
   }

   return ERR_PART_NOT_FOUND;
}
开发者ID:andreiw,项目名称:iQUIK,代码行数:55,代码来源:part.c

示例3: inode_read_at

/* Reads SIZE bytes from INODE into BUFFER, starting at position OFFSET.
   Returns the number of bytes actually read, which may be less
   than SIZE if an error occurs or end of file is reached. */
off_t
inode_read_at (struct inode *inode, void *buffer_, off_t size, off_t offset) 
{
  uint8_t *buffer = buffer_;
  off_t bytes_read = 0;
  uint8_t *bounce = NULL;
  int i=0;
  while (size > 0) 
    {
      i++;
      /* Disk sector to read, starting byte offset within sector. */
      disk_sector_t sector_idx = byte_to_sector (inode, offset);
      int sector_ofs = offset % DISK_SECTOR_SIZE;

      /* Bytes left in inode, bytes left in sector, lesser of the two. */
      off_t inode_left = inode_length (inode) - offset;
      int sector_left = DISK_SECTOR_SIZE - sector_ofs;
      int min_left = inode_left < sector_left ? inode_left : sector_left;

      /* Number of bytes to actually copy out of this sector. */
      int chunk_size = size < min_left ? size : min_left;
      if (chunk_size <= 0)
        break;

      if (sector_ofs == 0 && chunk_size == DISK_SECTOR_SIZE) 
        {
          /* Read full sector directly into caller's buffer. */
          disk_read (filesys_disk, sector_idx, buffer + bytes_read); 
        }
      else 
        {
          /* Read sector into bounce buffer, then partially copy
             into caller's buffer. */
          if (bounce == NULL) 
            {
              bounce = malloc (DISK_SECTOR_SIZE);
              if (bounce == NULL)
                break;
            }
          disk_read (filesys_disk, sector_idx, bounce);
          memcpy (buffer + bytes_read, bounce + sector_ofs, chunk_size);
        }
      
      /* Advance. */
      size -= chunk_size;
      offset += chunk_size;
      bytes_read += chunk_size;
    }
  free (bounce);
  return bytes_read;
}
开发者ID:goodahn,项目名称:cs330_OperatingSystem,代码行数:54,代码来源:inode.c

示例4: load_super

static int load_super ()
{
	int err;

	while (1) {
		err = disk_read (0, 2, 2, sb_block, seg_data ());
		//if (err) break;

		sb_data = (struct super_block *) sb_block;
		/*
		if (sb_data->s_log_zone_size) {
			//log_err ("zone size");
			err = -1;
			break;
		}
		*/

		ib_first = 2 + sb_data->s_imap_blocks + sb_data->s_zmap_blocks;

		/*
		if (sb_data->s_magic == SUPER_MAGIC) {
			dir_32 = 0;
		} else if (sb_data->s_magic == SUPER_MAGIC2) {
			dir_32 = 1;
		} else {
			//log_err ("super magic");
			err = -1;
		}
		*/

		break;
	}

	return err;
}
开发者ID:jbruchon,项目名称:elks,代码行数:35,代码来源:minix_second.c

示例5: BTree_search

BTNode* BTree_search(const BTree tree, int key, int* pos)
{
	if (!tree) {
		return NULL;
	}

	int i = 0;

	while (i < tree->keynum && key > tree->key[i]) {
		++i;
	}

	// Find the key.
	if (i < tree->keynum && tree->key[i] == key) {
		if (pos) {
			*pos = i;
		}

		return tree;
	}

	// tree 为叶子节点,找不到 key,查找失败返回
	if (tree->isLeaf) {
		return NULL;
	}

	// 节点内查找失败,但 tree->key[i - 1]< key < tree->key[i],
	// 下一个查找的结点应为 child[i]

	// 从磁盘读取第 i 个孩子的数据
	disk_read(&tree->child[i]);

	// 递归地继续查找于树 tree->child[i]
	return BTree_search(tree->child[i], key, pos);
}
开发者ID:isbase,项目名称:CppSnippet,代码行数:35,代码来源:BTree.cpp

示例6: ioread

static int
ioread(void *addr, int count, int phys)
{
	int logno, off, size;

	while (count) {
		off = blkoff(fs, poff);
		logno = lblkno(fs, poff);
		cnt = size = blksize(fs, &inode, logno);
		bnum = block_map(logno);
		if (bnum == -1)
			return(1);
		bnum = fsbtodb(fs, bnum) + boff;
		size -= off;
		if (size > count)
			size = count;
		if (disk_read(bnum, cnt, (vm_offset_t)iobuf))
			return(1);
		if (phys)
			pcpy(iobuf+off,addr,size);
		else
			bcopy(iobuf+off,addr,size);
		addr = (char *)addr + size;
		count -= size;
		poff += size;
	}
	return(0);
}
开发者ID:rohsaini,项目名称:mkunity,代码行数:28,代码来源:sys.c

示例7: MAL_Read

/*******************************************************************************
* Function Name  : MAL_Read
* Description    : Read sectors
* Input          : None
* Output         : None
* Return         : Buffer pointer
*******************************************************************************/
uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, volatile uint8_t * Readbuff, uint32_t Transfer_Length)
{
  switch (lun)
  {
    case 0: /* Physical drive number (0) */
      Status = disk_read (0, (volatile uint8_t*)Readbuff, Memory_Offset/512, Transfer_Length/512);
      //Status = SD_ReadBlock((uint8_t*)Readbuff, Memory_Offset, Transfer_Length);
#ifdef USE_STM3210E_EVAL      
      if ( Status != SD_OK )
      {
        return MAL_FAIL;
      }
#endif /* USE_STM3210E_EVAL */ 
      if(Status)
	return MAL_FAIL;   
      break;
#ifdef USE_STM3210E_EVAL
    case 1:
      NAND_Read(Memory_Offset, Readbuff, Transfer_Length);
      ;
      break;
#endif
    default:
      return MAL_FAIL;
  }
  return MAL_OK;
}
开发者ID:akohlsmith,项目名称:Equine,代码行数:34,代码来源:mass_mal.c

示例8: swap_read_and_free

// all the used swap slots are set to TRUE
void
swap_read_and_free (disk_sector_t idx, void *upage)
{
  lock_acquire (&swap_table_lock);
  // all the swap sectors must be in use
  // bitmap_all returns true if all pages are in use (i.e. TRUE)
  // take care of the edge cases
  ASSERT (idx != SECTOR_ERROR);
  ASSERT (bitmap_all (swap_table, idx, SLOT_SIZE));

  struct disk *swap = disk_get (1,1);
  if (!swap)
    PANIC ("No swap disk found\n");

  // read in the upage buffer
  int offset;
  for (offset = 0; offset < SLOT_SIZE; offset++) {
  //  printf ("Swap read sector %d at address %p\n",idx+offset, upage +(offset * DISK_SECTOR_SIZE));
    disk_read (swap, idx + offset, upage + (offset * DISK_SECTOR_SIZE));
  }

  // vacant the swap slot
  bitmap_set_multiple (swap_table, idx, SLOT_SIZE, false);

  lock_release (&swap_table_lock);
//  printf ("Swap read called at %d for %p\n",idx,upage);
}
开发者ID:anilkagak2,项目名称:pintos-server,代码行数:28,代码来源:swap.c

示例9: do_fat_dump

int
do_fat_dump (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
{
	__u8 block[1024];
	int ret;
	int bknum;

	ret = 0;

	if (argc != 2) {
		printf ("needs an argument!\n");
		return (0);
	}

	bknum = simple_strtoul (argv[1], NULL, 10);

	if (disk_read (0, bknum, block) != 0) {
		printf ("Error: reading block\n");
		return -1;
	}
	printf ("FAT dump: %d\n", bknum);
	hexdump (512, block);

	return (ret);
}
开发者ID:haitend,项目名称:u-boot-for-mpc8315,代码行数:25,代码来源:cmd_fat.c

示例10: inode_open

/* Reads an inode from SECTOR
   and returns a `struct inode' that contains it.
   Returns a null pointer if memory allocation fails. */
struct inode *
inode_open (disk_sector_t sector) 
{
  struct list_elem *e;
  struct inode *inode;

  /* Check whether this inode is already open. */
  for (e = list_begin (&open_inodes); e != list_end (&open_inodes);
       e = list_next (e)) 
    {
      inode = list_entry (e, struct inode, elem);
      if (inode->sector == sector) 
        {
          inode_reopen (inode);
          return inode; 
        }
    }

  /* Allocate memory. */
  inode = malloc (sizeof *inode);
  if (inode == NULL)
    return NULL;

  /* Initialize. */
  list_push_front (&open_inodes, &inode->elem);
  inode->sector = sector;
  inode->open_cnt = 1;
  inode->deny_write_cnt = 0;
  inode->removed = false;
  disk_read (filesys_disk, inode->sector, &inode->data);
  return inode;
}
开发者ID:goodahn,项目名称:cs330_OperatingSystem,代码行数:35,代码来源:inode.c

示例11: fs_format

int fs_format()
{
  if(mb.magic == FS_MAGIC) {
    printf("Refusing to format a mounted disk\n");
    return -1;
  }

  disk_read(0, (char *)&mb);
  if(mb.magic == FS_MAGIC){
    printf("Refusing to format a formatted disk!\n");
    mb.magic = 0;
    return -1;
  }

  //Format disk
  init_super_block();
  init_empty_dir();
  
  //Flush
  disk_write(0, (char*)&mb);
  disk_write(1, (char*)dir);

  mb.magic = 0; // mark disk as unmounted

  return 0;
}
开发者ID:GoncaloBFM,项目名称:DiskEmulator,代码行数:26,代码来源:fs+(copy).c

示例12: page_fault_helper

void page_fault_helper(struct page_table *pt, int page, int vPage, int vFrame, int flag)
{
	int vFlag;

	/* get the victim flag */
	page_table_get_entry(pt, vPage, &vFrame, &vFlag);

	/* check for RW flag	*/
	int rw = (PROT_READ|PROT_WRITE);
	if(vFlag == rw)
	{
		/* write victim from physmem to disk */
		disk_write(disk, vPage, &physmem[vFrame*PAGE_SIZE]);
		write_count++;
	}

	/* read from disk to victim frame */
	disk_read(disk, page, &physmem[vFrame*PAGE_SIZE]);
	read_count++;

	/* update page table entries */
	page_table_set_entry(pt, page, vFrame, flag);
	page_table_set_entry(pt, vPage, 0, 0);

	/* update loaded_pages */
	loaded_pages[vFrame] = page;

	/* Second-Chance clock setting */
	if(pageswap == 2 && flag == PROT_READ)
	{
		clock[vFrame] = 0;
	}
}
开发者ID:Madx-com,项目名称:BOSC,代码行数:33,代码来源:main.c

示例13: DiskRead

/** @brief Read sectors from a disk.

    @param bVolNum          The volume number of the volume whose block device
                            is being read from.
    @param ullSectorStart   The starting sector number.
    @param ulSectorCount    The number of sectors to read.
    @param pBuffer          The buffer into which to read the sector data.

    @return A negated ::REDSTATUS code indicating the operation result.

    @retval 0           Operation was successful.
    @retval -RED_EIO    A disk I/O error occurred.
*/
static REDSTATUS DiskRead(
    uint8_t     bVolNum,
    uint64_t    ullSectorStart,
    uint32_t    ulSectorCount,
    void       *pBuffer)
{
    REDSTATUS   ret = 0;
    uint32_t    ulSectorIdx = 0U;
    uint32_t    ulSectorSize = gaRedVolConf[bVolNum].ulSectorSize;
    uint8_t    *pbBuffer = CAST_VOID_PTR_TO_UINT8_PTR(pBuffer);

    while(ulSectorIdx < ulSectorCount)
    {
        uint32_t    ulTransfer = REDMIN(ulSectorCount - ulSectorIdx, MAX_SECTOR_TRANSFER);
        DRESULT     result;

        result = disk_read(bVolNum, &pbBuffer[ulSectorIdx * ulSectorSize], (DWORD)(ullSectorStart + ulSectorIdx), (BYTE)ulTransfer);
        if(result != RES_OK)
        {
            ret = -RED_EIO;
            break;
        }

        ulSectorIdx += ulTransfer;
    }

    return ret;
}
开发者ID:AlexShiLucky,项目名称:freertos,代码行数:41,代码来源:osbdev.c

示例14: read_dos_partition

static quik_err_t
read_dos_partition(ihandle dev,
                   unsigned part,
                   part_t *p)
{
   length_t len;
   unsigned i;
   char blk[SECTOR_SIZE];
   dos_part_t *d;

   len = disk_read(dev, blk, SECTOR_SIZE, 0LL);
   if (len != SECTOR_SIZE) {
      return ERR_DEV_SHORT_READ;
   }

   /* check the MSDOS partition magic */
   if ((blk[0x1fe] != 0x55) || (blk[0x1ff] != 0xaa)) {
      return ERR_PART_NOT_DOS;
   }

   if (part >= 4) {
      return ERR_PART_NOT_FOUND;
   }

   d = (dos_part_t *) &blk[0x1be];
   for (i = 1; i != part ; i++, d++) {
      /* nothing */
   }

   p->dev = dev;
   p->start = swab32(d->start_sect) * SECTOR_SIZE;
   p->len = swab32(d->nr_sects) * SECTOR_SIZE;
   return ERR_NONE;
}
开发者ID:andreiw,项目名称:iQUIK,代码行数:34,代码来源:part.c

示例15: stallEndpoint

void USBMSD::memoryVerify (uint8_t * buf, uint16_t size) {
    uint32_t n;

    if ((addr + size) > MemorySize) {
        size = MemorySize - addr;
        stage = ERROR;
        stallEndpoint(EPBULK_OUT);
    }

    // beginning of a new block -> load a whole block in RAM
    if (!(addr%BlockSize))
        disk_read(page, addr/BlockSize);

    // info are in RAM -> no need to re-read memory
    for (n = 0; n < size; n++) {
        if (page[addr%BlockSize + n] != buf[n]) {
            memOK = false;
            break;
        }
    }

    addr += size;
    length -= size;
    csw.DataResidue -= size;

    if ( !length || (stage != PROCESS_CBW)) {
        csw.Status = (memOK && (stage == PROCESS_CBW)) ? CSW_PASSED : CSW_FAILED;
        sendCSW();
    }
}
开发者ID:balazsracz,项目名称:libmbed_2387,代码行数:30,代码来源:USBMSD.cpp


注:本文中的disk_read函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。