In order to test an analysis tool, I need a file where the depth (eh.eh_depth) is greater than 1.

I've tried a couple of things:

  • A large file (1GiB)
  • Creating hundreds of smaller files (1MiB), deleting every other one, and then filling the disk with one file (hoping for massive fragmentation).

In both cases I only got a depth of 1!

I even tried manually modifying the inodes in a hex editor, but I ended up corrupting the file system.

I wondered if it could be done with debugfs, but I can't see how?

PS: I have seen the 'increasing depth of extent tree in ext4' question on stackoverflow, but I don't really want to create a 174GiB file.

  • I think this question is evidence of good design of ext4. It should be very, very difficult to make a file with depth greater than 1. :) Hope you find a solution for your testing though. – Wildcard Dec 15 '15 at 23:04
  • Thinking about it, though...it seems like your hundreds of small files approach should work, except (1) if the OS is doing defrag on the fly, or (2) if you deleted "every other" file based on directory listing rather than based on the extents specified in their inodes. – Wildcard Dec 15 '15 at 23:08

If you want a file with a lot of extents, just do:

$ perl -we 'for ($i=0;$i<100000;$i++) {seek STDOUT,$i*8192,0; print "."}' > a
$ ll a
-rw-r--r-- 1 stephane stephane 819191809 Dec 15 23:50 a
$ filefrag a
a: 100000 extents found

That's a sparse file where every other block is sparse, so it forces the extents to be 4KiB large.

debugfs:  dump_extents a
Level Entries         Logical          Physical Length Flags
 0/ 2   1/  1      0 - 199998   33413           199999
 1/ 2   1/295      0 -    679   33409              680
 2/ 2   1/340      0 -      0   34816 -   34816      1
 2/ 2   2/340      2 -      2   34818 -   34818      1
  • 1
    Yay holy files! ;) – psusi Dec 16 '15 at 2:26
  • Thanks @Stéphan. That perfectly answers my question. I could also do with an example without extents, but I guess that'd be a new question :) – Bridgey Dec 16 '15 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.