MINIX Internal Fragmentation 2

扶醉桌前 提交于 2019-12-04 05:43:26

问题


I am in the middle of writing some software in C that recursively lists all files in a given directory and now I need to work out the internal fragmentation.

I have spent a long time researching this and have found out that the internal fragmentation on ext2 only occurs in the last block. I know that from an inode number in theory you should be able to get the first and last block addresses but I have no idea how.

I have looked into stat(), fcntl() and all sorts of ways. How do I get the last block address from an inode number?

I have also figured out that once I have the address of the last block that I can test to see how much free space is in that block and this will give me the internal fragmentation.

I know that there is a get_inode and a get_block command but have no idea apart from that!


回答1:


I don't think you can get at the addresses of disk block via the regular system calls such as stat(). You would probably have to find the raw inode on disk (which means accessing the raw disk, and requires elevated privileges) and processing the data from there.

Classically, you'd find direct blocks, indirect blocks, double-indirect blocks and a triple-indirect block for a file. However, the relevant file system type is about as dead as the dodo is (I don't think I've seen that file system type this millennium), so that's unlikely to be much help now.

There might be a non-standard system call to get at the information, but I doubt it.




回答2:


Maybe you think too complicated, but roughly the internal fragmentation should be able to calculated if you divide the file size by the block size and take the modulo.

But this is only valid if the file is a "classic one" - with sparse files or files holding much "other information" (such as huge ACLs or extended attributes), there might be a difference. (I don't know where they are stored, but I could imagine that there could be file systems storing them in the last block, effectively (but unnoticedly) reducing the internal fragmentation.)



来源:https://stackoverflow.com/questions/8467053/minix-internal-fragmentation-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!