From: Johan Holmberg Date: 2011-01-06T04:39:24+09:00 Subject: Re: Getting the actual size of a sparse file On Wed, Jan 5, 2011 at 5:37 PM, Daniel Berger wrote: > Hi, > > How do you get the true size of a sparse file? Using /var/log/lastlog > on Ubuntu as an example I see this with "ls -lh" > > 287K lastlog > > With "ls -sh" I see this: > > 40K lastlog > > A File.stat call reveals this: > > #  dev=0x801, >  ino=5249695, >  mode=0100664 (file rw-rw-r--), >  nlink=1, >  uid=0 (root), >  gid=43 (utmp), >  rdev=0x0 (0, 0), >  size=292876, >  blksize=4096, >  blocks=80, >  atime=Mon Jan 03 16:03:24 -0700 2011 (1294095804), >  mtime=Thu Oct 21 11:34:51 -0600 2010 (1287682491), >  ctime=Thu Oct 21 11:34:51 -0600 2010 (1287682491)> > > Multiplying blocks * blksize doesn't seem to match up, either. > See stat(2): The st_blocks field indicates the number of blocks allocated to the file, 512-byte units. (This may be smaller than st_size/512 when the file has holes.) The st_blksize field gives the "preferred" blocksize for efficient file system I/O. (Writing to a file in smaller chunks may cause an ineffi- cient read-modify-rewrite.) So "blksize" has nothing to do with the size of the "blocks". They are always counted in 512-byte units. /Johan Holmberg