Sample Header Ad - 728x90

Does splitting a file in more files necessarily mean that some/all of the overall content will not be where it was?

1 vote
2 answers
227 views
I guess that given a file of a certain size, not all of its bytes will be contiguous on disk (or will they? Just for existence of the phrase "defragmenting a disk" I assume they will not). But at least from the application point of view, they are. I mean, I can use head -c [-]n+tail -c [-]n to extract a portion of a file thinking of it as a contiguous sequence of bytes. So say that a file is 10 bytes long and contains all equal bytes, e.g.
$ cat someFile
AAAAAAAAAA
is it possible to spilt it in two files, say someFile.part1 and someFile.part2, such that
$ cat someFile.part1
AAAAA
$ cat someFile.part2
AAAAA
and that actually no byte has been moved anywhere, in the sense that those 10 bytes are still precisely where they were before? After all, the name someFile must one way or another map to the physical position (on the disk or on some kind of virtual memory that the OS (or the kernel?) makes me deal with) where the content actually starts. In a way, I imagine someFile not being much different from a pointer and length, say 0xabc/10, whereas the target files would be 0xabc/5 and 0xac1/5. Maybe I'm being to much infuenced by my C++ experience and really inexistent file system experience :D --- I'm not interesting in doing it per se. I'm curious about understanding how programs like [lxsplit](https://lxsplit.sourceforge.net/) work, and where their strengths are. Mostly for curiosity, but maybe, why not, to play at writing one myself.
Asked by Enlico (2258 rep)
Apr 4, 2023, 06:16 PM
Last activity: Aug 6, 2023, 10:01 AM