Write a program and then answer the questions::
1. Opens a new file for O_RDWR
2. Seeks to offset within the file @ 10K
3. Write one single byte
4. Closes the file
Now Answer The Following Questions::
1. What will be the size of the file?
2. What is the effect of step #2?
3. What is being done internally by the UNIX? (take any flavour is you want, Solaris, HP etc)
4. What are sparse files?
The program mentioned in the segment refers to something called as Sparse
Sparse files are useful if you want to reserve some space in the FS, without worrying much about the fragmentation.
#1. 10K + 1 byte
#2. Changes the file offset pointer in kernel to 10K
#3. Same as in step #2.
There is no physical seek of any sort out to the physical disk. There is a kernel file offset pointer for every open file per process. This is used just as a reference into the file offset. It does not go and place the head over the correct sector and cylinder. All it does it put the seek value into the seek pointer, so when you next do read or write it effects from that
offset. Effect of reading from arbitrarly long offset will result in nothing (NULL). Writing to it will write to the 1st direct INODE and will also record the value of seek offset. So although the file is single INODE long you actually see 10K bytes in it. Another of those UNIX black magics.
#4. Explained above in #3.
Point to make note of here is that not all File Systems treat sparse files the same way. But nonetheless they allow you to create them.
Do you have a UNIX Question?
Unix Home: Unix System Administration
Hints and Tips