[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: disk usage of an umounted partition?



Roberto C. Sanchez writes:

> That doesn't seem to make sense.  If you want to know how much is used
> up you need to at least be able to tell how many blocks are allocated
> or occupied by files.  That implies that the filesystem must be known
> and readable.

True, but sometimes wrecked filesystems can be repaired.

Many filesystems define a magic number in a particular portion of their
superblock, and from there you can deduce the beginning and end of the
superblock. With luck, the superblock will be intact or mostly intact,
and you might be able to reconstruct the filesystem.

For example, looking at ext3_fs.h from Linux 2.6.12.4, I see that ext3
filesystems use the magic number 0xEF53 (EXT3_SUPER_MAGIC). The
superblock structure is defined lower down in that file, and you'll find
a field named s_magic at byte 58 in the struct. The magic number is
purposefully chosen to be unlikely to appear naturally, allowing you to
search a filesystem image for the superblock. Some filesystems, like BFS
for the (late, great, and lamented) BeOS, used multiple magic numbers to
make identification more certain.

If the filesystem is intact, you can also examine other fields (e.g.
s_blocks_count, s_free_blocks_count, s_log_block_size, et c.) to figure
out how much space is used.

Hopefully the original poster won't have to perform filesystem surgery.
:)



Reply to: