On Mon, Mar 26, 2012 at 9:24 PM, Glenn Fowler <[email protected]> wrote: ... > one other question > is this a valid check for a sparse file on fd open for read: > lseek(fd, SEEK_HOLE, 0) >= 0
Glenn, this may help: ---------- Forwarded message ---------- From: Andrew Gabriel <[email protected]> Date: 2012/3/27 Subject: Re: [zfs-discuss] test for holes in a file? To: [email protected] I just played and knocked this up (note the stunning lack of comments, missing optarg processing, etc)... Give it a list of files to check... #define _FILE_OFFSET_BITS 64 #include<sys/types.h> #include<unistd.h> #include<stdio.h> #include<sys/stat.h> #include<fcntl.h> int main(int argc, char **argv) { int i; for (i = 1; i< argc; i++) { int fd; fd = open(argv[i], O_RDONLY); if (fd< 0) { perror(argv[i]); } else { off_t eof; off_t hole; if (((eof = lseek(fd, 0, SEEK_END))< 0) || lseek(fd, 0, SEEK_SET)< 0) { perror(argv[i]); } else if (eof == 0) { printf("%s: empty\n", argv[i]); } else { hole = lseek(fd, 0, SEEK_HOLE); if (hole< 0) { perror(argv[i]); } else if (hole< eof) { printf("%s: sparse\n", argv[i]); } else { printf("%s: not sparse\n", argv[i]); } } close(fd); } } return 0; } -- , _ _ , { \/`o;====- Olga Kryzhanovska -====;o`\/ } .----'-/`-/ [email protected] \-`\-'----. `'-..-| / http://twitter.com/fleyta \ |-..-'` /\/\ Solaris/BSD//C/C++ programmer /\/\ `--` `--` _______________________________________________ ast-users mailing list [email protected] https://mailman.research.att.com/mailman/listinfo/ast-users
