Sparse files

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
5. Exits

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 files.
Sparse files are useful if you want to reserve some space in the FS, without worrying much about the fragmentation.

ANSWERS
-------
#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.

Have a Unix Problem
Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.