| I have a program called dd. :-)
| I have a program which uses truncate() called truncate.
| I have a program which uses lseek(fd,size-1,SEEK_CUR) + write(fd,"",1) called sparse.
| I have this program called dd. :-)
| I have a program which uses stat() called stat.
| I have a program called ls. :-)
|
| janus don> dd bs=1024k if=/dev/zero of=/tmp/junk count=20
| 20+0 records in
| 20+0 records out
| janus don> ls -ls /tmp/junk
| 20504 -rwxr-xr-x 1 don 20971520 Jul 12 15:40 /tmp/junk
|
| So a non sparse 20 Meg file has 20504 block in it.
That's 24 blocks MORE than the number of blocks of data (20480).
Pointer blocks?
| janus don> truncate /tmp/junk 0
| janus don> ls -ls /tmp/junk
| 0 -rwxr-xr-x 1 don 0 Jul 12 15:43 /tmp/junk
| janus don> truncate /tmp/junk 20971520
| janus don> ls -ls /tmp/junk
| 24 -rwxr-xr-x 1 don 20971520 Jul 12 15:43 /tmp/junk
|
| Truncate will "create" a 20 Meg file, but only uses 24 blocks, so it is a
| sparse file.
At least significantly sparse, but maybe not 100% sparse. Can't be sure.
there are those 24 blocks. That could be accounted for as pointer blocks
so maybe the data blocks really are sparse. I wonder if it is possible
to create a genuinely sparse file without the pointer blocks being there,
yet.
| janus don> rm /tmp/junk
| janus don> sparse /tmp/junk 20971520
| janus don> ls -ls /tmp/junk
| 24 -rwxr-xr-x 1 don 20971520 Jul 12 15:45 /tmp/junk
|
| sparse also creates a sparse 20 Meg file.
This is what I do now.
| But why does a 1 byte file use 2 blocks on Solaris?
|
| janus don> rm /tmp/junk
| janus don> sparse /tmp/junk 1
| janus don> stat /tmp/junk
| /tmp/junk
| st_dev = 30932996
| st_ino = 26
| st_mode = 0o33261
| st_nlink = 1
| st_uid = 100
| st_gid = 100
| st_rdev = 0
| st_size = 1
| st_atime = Fri Jul 12 15:47:27 2002
| st_mtime = Fri Jul 12 15:47:27 2002
| st_ctime = Fri Jul 12 15:47:27 2002
| st_blksize = 8192
| st_blocks = 2
One block for the data, and one block in a one layer pointer hierarchy.
The locations of the data blocks, indexable by the relative offset,
have to reside somewhere.
The case of 20480 blocks of data would probably need at least 20 blocks
for pointers (assuming a block is 4096 bytes, a pointer is 4 bytes, and
a block has 1024 pointers). Now where are those 20 pointer blocks
pointed to from? Just one more block could accomodate a parent with 20
pointers, so 3 blocks is still unaccounted for with that logic. I
suspect the logic is more complex, where the first part of the file has
a 1 level pointer layering, and the rest has a 2 level pointer layering.
I'm just guessing. Surely some Solaris docs on UFS explain how it
works inside (I've never looked and I've used Solaris a lot).
--
-----------------------------------------------------------------
| Phil Howard - KA9WGN | Dallas | http://linuxhomepage.com/ |
-----------------------------------------------------------------