文件系统如何定位文件的数据?

时间:2016-07-23 15:25:12

标签: c linux-kernel filesystems linux-device-driver ext2

我尝试删除特定文件的inode,如下所示:

    ext2_filsys filsys;
    errcode_t error = ext2fs_open("/dev/sdb1",EXT2_FLAG_RW, 0, 0, unix_io_manager, &filsys);  // I know my file is located on /dev/sdb1
    ext2_ino_t ino = 13; // I found this number using ls -i command in terminal

    // first I read the inode to check that I am reading the correct one correctly
    struct ext2_inode inode;    
    errcode_t err_iread = ext2fs_read_inode(filsys, ino, &inode);

    // I change the data blocks pointers array and zero them all, then I change file size to zero
    unsigned int blocks_array[15] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    inode.i_size = 0;
    memcpy(&inode.i_block, &blocks_array, sizeof inode.i_block);  // I use this to remove data block indexes of the file.

    // I write the changed inode on to my desired file's inode
    errcode_t err_iwrite = ext2fs_write_inode(filsys, ino, &inode);
    errcode_t err_flush = ext2fs_flush(filsys);

    // Again I check that I have written the inode correctly
    err_iread = ext2fs_read_inode(filsys, ino, &inode);
    errcode_t err_close = ext2fs_close(filsys);

问题是我仍然可以从文件浏览器应用程序中打开文件 所以我的问题是这里发生了什么?文件浏览器应用程序如何找到我文件的数据块并打开它? 我在ubuntu 14.0.4

上运行了这段代码

0 个答案:

没有答案