本文整理汇总了C++中disk_read函数的典型用法代码示例。如果您正苦于以下问题:C++ disk_read函数的具体用法?C++ disk_read怎么用?C++ disk_read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了disk_read函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: read_LUN1
VOID read_LUN1(VOID)
{
// A READ operation is underway, and the app has been requested to access the medium. So, call file system to read
// to do so. Note this is a low level FatFs call -- we are not attempting to open a file ourselves. The host is
// in control of this access, we're just carrying it out.
DRESULT dresult = disk_read(0, // Physical drive number (0)
RWbuf_info->bufferAddr, // Pointer to the user buffer
RWbuf_info->lba, // First LBA of this buffer operation
RWbuf_info->lbCount); // The number of blocks being requested as part of this operation
// The result of the file system call needs to be communicated to the host. Different file system software uses
// different return codes, but they all communicate the same types of results. This code ultimately gets passed to the
// host app that issued the command to read (or if the user did it the host OS, perhaps in a dialog box).
switch(dresult)
{
case RES_OK:
RWbuf_info->returnCode = kUSBMSC_RWSuccess;
break;
case RES_ERROR: // In FatFs, this result suggests the medium may have been removed recently.
if(!checkInsertionRemoval()) // This application function checks for the SD-card, and if missing, calls USBMSC_updateMediaInfo() to inform the API
RWbuf_info->returnCode = kUSBMSC_RWMedNotPresent;
break;
case RES_NOTRDY:
RWbuf_info->returnCode = kUSBMSC_RWNotReady;
break;
case RES_PARERR:
RWbuf_info->returnCode = kUSBMSC_RWLbaOutOfRange;
break;
}
USBMSC_bufferProcessed();
}
开发者ID:TECHNOTICSROBOTICS,项目名称:mspdev,代码行数:32,代码来源:main.c
示例17: mbr_part
_size_t mbr_part(_size_t id) {
_mbr_t mbr;
_size_t i, n = 0;
if ((disk_read(id, &mbr, sizeof(_mbr_t), 0x1be) != -1) && (mbr.sign == 0xaa55)) {
debug("Disk %d: Boot signature", id);
for (i = 0; i < 4; i++) {
if (mbr.part[i].part_type == TYPE_EXT) {
debug("Disk %d: DOS Partition %d, Extended", id, i);
n += mbr_part(disk_mmap(id, mbr.part[i].first_sector_lba, mbr.part[i].sector_num));
n++;
}
else if (mbr.part[i].part_type == TYPE_GPT) {
n += gpt_part(id);
}
else if (mbr.part[i].part_type != TYPE_EMPTY) {
debug("Disk %d: DOS Partition %d, Id %02X", id, i, mbr.part[i].part_type);
disk_mmap(id, mbr.part[i].first_sector_lba, mbr.part[i].sector_num);
n++;
}
}
}
return n;
}
开发者ID:zswek,项目名称:bitch,代码行数:27,代码来源:mbr.c
示例18: disk_read
void USBCDCMSC::memoryRead (void) {
uint32_t n;
n = (length > MAX_PACKET) ? MAX_PACKET : length;
if ((addr + n) > MemorySize) {
n = MemorySize - addr;
stage = ERROR;
}
// we read an entire block
if (!(addr%BlockSize))
disk_read((char *)page, addr/BlockSize);
// write data which are in RAM
writeNB(MSDBULK_IN, &page[addr%BlockSize], n, MAX_PACKET_SIZE_EPBULK);
addr += n;
length -= n;
csw.DataResidue -= n;
if ( !length || (stage != PROCESS_CBW)) {
csw.Status = (stage == PROCESS_CBW) ? CSW_PASSED : CSW_FAILED;
stage = (stage == PROCESS_CBW) ? SEND_CSW : stage;
}
}
开发者ID:Haraldix,项目名称:Smoothie,代码行数:27,代码来源:USBCDCMSC.cpp
示例19: move_window
static
BOOL move_window ( /* TRUE: successful, FALSE: failed */
DWORD sector /* Sector number to make apperance in the FatFs->win */
) /* Move to zero only writes back dirty window */
{
DWORD wsect;
FATFS *fs = FatFs;
wsect = fs->winsect;
if (wsect != sector) { /* Changed current window */
#if !_FS_READONLY
BYTE n;
if (fs->winflag) { /* Write back dirty window if needed */
if (disk_write(0, fs->win, wsect, 1) != RES_OK)
return FALSE;
fs->winflag = 0;
if (wsect < (fs->fatbase + fs->sects_fat)) { /* In FAT area */
for (n = fs->n_fats; n >= 2; n--) { /* Refrect the change to all FAT copies */
wsect += fs->sects_fat;
disk_write(0, fs->win, wsect, 1);
}
}
}
#endif
if (sector) {
if (disk_read(0, fs->win, sector, 1) != RES_OK)
return FALSE;
fs->winsect = sector;
}
}
return TRUE;
}
开发者ID:somaproject,项目名称:backplane,代码行数:33,代码来源:tff.c
示例20: part_read
quik_err_t
part_read(part_t *part,
offset_t sector,
offset_t byte_offset,
length_t byte_len,
char *buf)
{
length_t len;
offset_t off;
off = sector << SECTOR_BITS;
/*
* Check partition boundaries.
*/
if ((off + byte_offset + byte_len) >=
part->len) {
return ERR_PART_BEYOND;
}
off += part->start + byte_offset;
len = disk_read(part->dev, buf, byte_len, off);
if (len != byte_len) {
return ERR_DEV_SHORT_READ;
}
return ERR_NONE;
}
开发者ID:andreiw,项目名称:iQUIK,代码行数:28,代码来源:part.c
注:本文中的disk_read函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论