示例#1
0
static long ReadFile(InodePtr fileInode, long *length)
{
  long bytesLeft, curSize, curBlock = 0;
  char *buffer, *curAddr = (char *)kLoadAddr;
  
  bytesLeft = *length = fileInode->e2di_size;
  
  if (*length > kLoadSize) {
    printf("File is too large.\n");
    return -1;
  }
  
  while (bytesLeft) {
    if (bytesLeft > gBlockSize) curSize = gBlockSize;
    else curSize = bytesLeft;
    
    buffer = ReadFileBlock(fileInode, curBlock, 0, curSize, curAddr, 0);
    if (buffer == 0) break;
    
    curBlock++;
    curAddr += curSize;
    bytesLeft -= curSize;
  }
  
  return bytesLeft;
}
示例#2
0
static long ReadDirEntry( InodePtr dirInode, long * fileInodeNum,
                          long long * dirIndex, char ** name )
{
    struct direct *dir;
    char          *buffer;
    long long     index;
    long          dirBlockNum, dirBlockOffset;

    while (1) {
        index = *dirIndex;
    
        dirBlockOffset = (long) (index % DIRBLKSIZ);
        dirBlockNum    = (long) (index / DIRBLKSIZ);

        buffer = ReadFileBlock(dirInode, dirBlockNum, 0, DIRBLKSIZ, 0, 1);
        if (buffer == 0) return -1;

        dir = (struct direct *)(buffer + dirBlockOffset);
        byte_swap_dir_block_in((char *)dir, 1);

        *dirIndex += dir->d_reclen;
        
        if (dir->d_ino != 0) break;
        
        if (dirBlockOffset != 0) return -1;
    }

    *fileInodeNum = dir->d_ino;
    *name = strlcpy(gTempName2, dir->d_name, dir->d_namlen+1);

    return 0;
}
示例#3
0
static long ReadDirEntry(InodePtr dirInode, long *fileInodeNum,
			 long *dirIndex, char **name)
{
  struct ext2fs_direct *dir;
  char                 *buffer;
  long                 offset, index;
  long                 blockNum, inodeNum;
  
  while (1) {
    index = *dirIndex;
    
    offset = index % gBlockSize;
    blockNum = index / gBlockSize;
    
    buffer = ReadFileBlock(dirInode, blockNum, 0, gBlockSize, 0, 1);
    if (buffer == 0) return -1;
    
    dir = (struct ext2fs_direct *)(buffer + offset);
    *dirIndex += bswap16(dir->e2d_reclen);
    
    inodeNum = bswap32(dir->e2d_ino);
    if (inodeNum != 0) break;
    
    if (offset != 0) return -1;
  }
  
  *fileInodeNum = inodeNum;
  *name = strncpy(gTempName2, dir->e2d_name, dir->e2d_namlen);
  
  return 0;
}
示例#4
0
static long ReadFile( InodePtr fileInode, uint64_t * length, void * base, uint64_t offset )
{
    long bytesLeft, curSize, curFrag;
    char *buffer, *curAddr = (char *)base;

    bytesLeft = fileInode->di_size;

    if (offset > bytesLeft) {
        printf("Offset is too large.\n");
        return -1;
    }

    if ((*length == 0) || ((offset + *length) > bytesLeft)) {
        *length = bytesLeft - offset;
    }
/*
    if (bytesLeft > kLoadSize) {
        printf("File is too large.\n");
        return -1;
    }
*/
    bytesLeft = *length;
    curFrag = (offset / gBlockSize) * gFragsPerBlock;
    offset %= gBlockSize;

    while (bytesLeft) {
        curSize = gBlockSize;
        if (curSize > bytesLeft) curSize = bytesLeft;
        if ((offset + curSize) > gBlockSize) curSize = (gBlockSize - offset);

        buffer = ReadFileBlock(fileInode, curFrag, offset, curSize, curAddr, 0);
        if (buffer == 0) break;

        if (offset != 0) offset = 0;

        curFrag += gFragsPerBlock;
        curAddr += curSize;
        bytesLeft -= curSize;
    }

    return bytesLeft;
}