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;
}
On 03/26/12 10:06 PM, ольга крыжановская wrote:
Mike, I was hoping that some one has a complete example for a bool
has_file_one_or_more_holes(const char *path) function.
Olga
2012/3/26 Mike Gerdts<mger...@gmail.com>:
2012/3/26 ольга крыжановская<olga.kryzhanov...@gmail.com>:
How can I test if a file on ZFS has holes, i.e. is a sparse file,
using the C api?
See SEEK_HOLE in lseek(2).
--
Mike Gerdts
http://mgerdts.blogspot.com/
_______________________________________________
zfs-discuss mailing list
zfs-discuss@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/zfs-discuss