aspose file tools*
The moose likes I/O and Streams and the fly likes writing to file via fileChannel in 4kb blocks to match disk sectors perfectly. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "writing to file via fileChannel in 4kb blocks to match disk sectors perfectly." Watch "writing to file via fileChannel in 4kb blocks to match disk sectors perfectly." New topic
Author

writing to file via fileChannel in 4kb blocks to match disk sectors perfectly.

Daedalus Tien
Greenhorn

Joined: Dec 23, 2008
Posts: 4
Hi

I am writing some data to a file via a fileChannel and I want to make sure that it fits neatly on the disk block size so the disk does not end up doing the read,copy, write routine to fill sectors that are only half used. I am writing 4KB blocks which are the same size as the disks 4096 byte sectors so when I write each block it will fit nicely in a sector and not get split into two pieces.

The file will start at the beginning of a block I presume so I should be able to get everything aligned by making sure that everything is a multiple of 4096 bytes including padding free space with zeros so every write is 4KB.

At the beginning of the file do I write the first block from 0 to 4095 or from 1 to 4096? I need this info because I will be performing random 4k writes in other areas of the file and I need to make sure it all lines up with blocks on the disk ie. block 1 =0-4095 block 2 =4096-8191 block 3 =8192-12287 etc. or block 1 =1-4096 block 2 =4097-8192 block 3= 8193-12288 etc.

The filechannel API only says I can use any non negative integer for the position parameter so I would assume that it starts from 0.

I have made sure that my partition starts on a sector so the file-system should as well I presume after reading > http://www.ibm.com/developerworks/linux/library/l-4kb-sector-disks/index.html

Thanks in advance

 
Don't get me started about those stupid light bulbs.
 
subject: writing to file via fileChannel in 4kb blocks to match disk sectors perfectly.