How might one go about implementing a disk fragmenter?
Asked Answered
S

4

5

I have a few ideas I would like to try out in the Disk Defragmentation Arena. I came to the conclusion that as a precursor to the implementation, it would be useful, to be able to put a disk into a state where it was fragmented. This seems to me to be a state that is more difficult to achieve than a defragmented one. I would assume that the commercial defragmenter companies probably have solved this issue.

So my question.....

How might one go about implementing a fragmenter? What makes sense in the context that it would be used, to test a defragmenter?

Structural answered 29/3, 2009 at 20:50 Comment(0)
C
2

How you can best fragement depends on the file system.

In general, concurrently open a large number of files. Opening a file will create a new directory entry but won't cause a block to be written for that file. But now go through each file in turn, writing one block. This typically will cause the next free block to be consumed, which will lead to all your files being fragmented with regard to each other.

Fragmenting existing files is another matter. Basically, do the same, but do it on a file copy of existing files, doing a delete of the original and rename of copy.

Crabstick answered 29/3, 2009 at 20:56 Comment(0)
A
7

Maybe instead of fragmenting the actual disk, you should really test your defragmentation algorithm on a simulation/mock disk? Only once you're satisfied the algorithm itself works as specified, you could do the testing on actual disks using the actual disk API.

You could even take snapshots of actual fragmented disks (yours or of someone you know) and use this data as a mock model for testing.

Accumulate answered 29/3, 2009 at 20:55 Comment(1)
Man, your answer beat me with seconds!Shopworn
C
2

How you can best fragement depends on the file system.

In general, concurrently open a large number of files. Opening a file will create a new directory entry but won't cause a block to be written for that file. But now go through each file in turn, writing one block. This typically will cause the next free block to be consumed, which will lead to all your files being fragmented with regard to each other.

Fragmenting existing files is another matter. Basically, do the same, but do it on a file copy of existing files, doing a delete of the original and rename of copy.

Crabstick answered 29/3, 2009 at 20:56 Comment(0)
S
2

I may be oversimplifying here but if you artificially fragment the disk won't any tests you run will be only true for the fragmentation created by your fragmenter rather than any real world fragmentation. You may end up optimising for assumptions in the fragmenter tool that don't represent real world occurrences.

Wouldn't it be easier and more accurate to take some disk images of fragmented disks? Do you have any friends or colleagues who trust you not to do anything anti-social with their data?

Stillman answered 29/3, 2009 at 21:8 Comment(0)
K
0

Fragmentation is a mathematical problem such that you are trying to maximize the distance the head of the hard drive is traveling while performing a specific operation. So in order to effectively fragment something you need to define the specific operation first

Kukri answered 29/3, 2009 at 21:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.