Prepare a file without a temporary file by manipulating the inode?

Preparing for a large file is difficult because it requires pushing all other characters forward. However, is it possible to do this by manipulating the inode as follows:

  • Highlight a new block on disk and fill in your preliminary data.

  • Adjust the index to indicate that your new block is now the first to block and push the first first block to the second block position, the previous second block to the third position, etc.

I understand that this still requires pushing the blocks forward, but it should be more efficient than using a temporary file.

I also understand that the new first block will be a β€œshort” block (not all data in the block is part of the file), since your preliminary data is unlikely to be exactly the same size as the block.

Or, if the inode blocks are simply connected, it will require very little work on it.

NOTE. My last experience directly manipulating disk data was with the Commodore 1541, so my knowledge may be a bit outdated ...

+4
source share
2 answers

Modern operating systems should not allow the user to do this, since the inode data structures are specific to the underlying file system.

If your file system / operating system supports it, you can make your file a sparse file by first adding empty data at the beginning, and then writing to sparse blocks. Theoretically, this should give you what you want.

YMMV, I'm just throwing ideas.;)

+1
source

It might work! Yes, userland programs should not be reset using inodes. Yes, it certainly depends on any scheme used to track blocks by any file systems that implement this function. None of this is grounds for rejecting this proposal out of control.

Here's how it might work.

To illustrate, suppose we have an index that tracks blocks with an array of direct pointers to data blocks. Also, suppose the inode has an initial offset and an end-offset that apply to the first and last blocks, respectively, so you can have fewer than full blocks at both the beginning and the end of the file.

Now suppose you want to add data. It will be like this.

IF (new data will fit into unused space in first data block) write the new data to the beginning of the first data block update the starting-offset return success indication to caller try to allocate a new data block IF (block allocation failed) return failure indication to caller shift all existing data block pointers down by one write the ID of the newly-allocated data block into the first slot of the array write as much data as will fit into the second block (the old first block) write the rest of data into the newly-allocated data block, shifted to the end starting-offset := (data block size - length of data in first block) return success indication to caller 
0
source

Source: https://habr.com/ru/post/1490165/


All Articles