Find the answer to your Linux question:
Results 1 to 4 of 4
The blocks allocation is decided by the kernel. When writing new data to a file, if the block is not enough, the kernel will select a new block from the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2009
    Posts
    2

    Smile how to create a file that the device blocks are non-contiguous?


    The blocks allocation is decided by the kernel. When writing new data to a file, if the block is not enough, the kernel will select a new block from the device that is contiguous with file's last block.
    If the selected block has been used by other file. The kernel can only select a non-contiguous block.

    My questions is that:How can we create a file, the device block are non-contguous?

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,525
    Please clarify. Are you asking how to create a file that consists totally (or mostly) of non-contiguous blocks?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Aug 2009
    Posts
    2
    Quote Originally Posted by Rubberman View Post
    Please clarify. Are you asking how to create a file that consists totally (or mostly) of non-contiguous blocks?
    Yes. How to create it?

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,525
    I don't think there is a way to guarantee this. The only reliable (sort of) way to do this is to create 2 files on the same device, and then delete the one you don't want. The algorithm, in pseudo-code, goes something like this:
    Code:
    while not done
        open file 1 to append
        write 1 block to file
        close file
        sync file systems
        open file 2 to append
        write 1 block to file
        close file
        sync file systems
        if total size written >= requested size
            unlink file 2
            set done flag
        endif
    endwhile
    # at this point, file 1 (target file) should consist of non-contiguous blocks
    # however, there is no guarantee of that
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •