On 10/11/2007, at 9:32 PM, Otto Moerbeek wrote:

yeah, look at stat(2):

 int64_t    st_blocks;  /* blocks allocated for file */
 u_int32_t  st_blksize; /* optimal file sys I/O ops blocksize */

actually st_blocks's unit is disk sectors, to be precise.

I don't read perl, so I cannot comment on the script below.

        -Otto

Thanks for the feedback.

I tried in C, but could not get past getting 0 for st_blocks every time (will be my C, but I can't see (C?) what it is yet ...)

# man -s 2 stat:
[cut]
struct timespec st_ctimespec; /* time of last file status change */
         off_t      st_size;   /* file size, in bytes */
         int64_t    st_blocks; /* blocks allocated for file */
[cut]

check.c
-----------

#include <sys/stat.h>

int main(void) {
        struct stat stat_stuff;
        int result;
        result=stat("/home/sparse-files/sparsefile",&stat_stuff);
        printf("%d %d\n",stat_stuff.st_size,stat_stuff.st_blocks);
}

# cc check.c -o check
# ./check
10485760 0

Reply via email to