我正在尝试使用我创建的某些vdiTools访问存储在.vdi文件中的超级块。
我编写的工具只是.vdi文件的功能,该文件反映了UNIX系统调用。即vdiOpen()使用UNIX open(并通过UNIX读取将所有内容转储到vdi结构中),vdiRead()使用UNIX读取,vdiWrite使用Unix写入等等进行关闭和查找。一切似乎都工作正常,但我的数据似乎转移了。
这是我的printSuperblock()函数从两个不同的vdi文件在终端中弹出的结果。
vdi1 17GBs
>------------File System info---------------
>Total file system size in bytes: 1140850688
>Size available for files, used and unused:
>Amount of space currently used: 2509353121
>Number of possible files and directories: 1569648350
>Number of existing files:
>Number of existing directories: 0
>Number of block groups: 0
>Block size in bytes: 16777216
>Magic number: 9330
>Error with fileSysState number. 28582
vdi2 37GBs
>------------File System info---------------
>Total file system size in bytes: 42082304
>Size available for files, used and unused:
>Amount of space currently used: 1518474772
>Number of possible files and directories: 352321745
>Number of existing files:
>Number of existing directories: 0
>Number of block groups: 0
>Block size in bytes: 1024
>Magic number: 510
>Error with fileSysState number. 5120
这是我的get superblock函数。
void getSuperblock(struct vdiFile *vdi_ptr, struct superblockStructure *superblock_ptr){//ask if you how to pass in the struct itself as the buffer its reading into.
vdiSeek(vdi_ptr, 1024, 0);
vdiRead(vdi_ptr, superblock_ptr, 84);
//if(superblock_ptr->revLevel >= 1){
//vdiSeek(vdi_ptr, 1024+83, SEEK_START);
//vdiRead(vdi_ptr, superblock_ptr,
//}
}
这是我的vdiRead
ssize_t vdiRead(struct vdiFile *vdi_ptr, void *buffer, size_t length){
int blockNum = vdi_ptr->cursor / vdi_ptr->vdiStruct.blockSize;
int offset = vdi_ptr->cursor % vdi_ptr->vdiStruct.blockSize;
int pos = (vdi_ptr->vdiStruct.offsetBlocks + blockNum) * vdi_ptr->vdiStruct.blockSize;
lseek(vdi_ptr->fileDesc, pos, SEEK_CUR);
int realBlockNum;
read(vdi_ptr->fileDesc, &realBlockNum, 1);
int start = (vdi_ptr->vdiStruct.offsetBlocks + realBlockNum) * vdi_ptr->vdiStruct.blockSize + offset; // location of the data to start
lseek(vdi_ptr->fileDesc, start, SEEK_CUR);
// read in the data to the buffer from start to length
vdi_ptr->cursor += length;
return read(vdi_ptr->fileDesc, buffer, length);
}
这是超级块结构
typedef struct __attribute__((__packed__)) superblockStructure{ // superblock is always located at byte 1024
uint32_t iNodeCount,
blocksCount,
superUserBlocks,
freeBlocks,
freeInodes,
firstDataBlock,
logBlockSize,
logFragSize,
blocksPerGroup,
fragsPerGroup,
iNodesPerGroup,
mountTime,
writeTime;
uint16_t mountCount,
maxMountCount,
magicNum,
fileSysState, //1: clean; 2: error
errors, // 1: continue, 2:remount as read only, 3: kernel panic
minorRevLevel;
uint32_t lastCheck,
checkInterval,
creatorOS,
revLevel;
uint16_t defaultUserIdReservedBlocks,
defaultGroupIdReservedBlocks;
}superblockStructure;
对我来说最重要的是,块大小有很大的不同。我知道,我的两个.vdi文件都使用1kb的块大小。另外,我注意到他们的两个魔术数字都关闭了。 我只是很困惑,一个人正确地设置了块大小,而另一个人则有所不同。