static unsigned long get_bmap(int fd, unsigned long block)
{
int ret;
- unsigned long b;
+ unsigned int b;
b = block;
- ret = ioctl(fd, FIBMAP, &b);
+ ret = ioctl(fd, FIBMAP, &b); /* FIBMAP takes a pointer to an integer */
if (ret < 0) {
if (errno == EPERM) {
fprintf(stderr, "No permission to use FIBMAP ioctl; must have root privileges\n");
static void frag_report(const char *filename)
{
struct statfs fsinfo;
+#ifdef HAVE_FSTAT64
struct stat64 fileinfo;
- long i, fd, bs, block, last_block = 0, numblocks;
+#else
+ struct stat fileinfo;
+#endif
+ int bs;
+ long i, fd;
+ unsigned long block, last_block = 0, numblocks;
long bpib; /* Blocks per indirect block */
long cylgroups;
int discont = 0, expected;
perror("statfs");
return;
}
+#ifdef HAVE_FSTAT64
if (stat64(filename, &fileinfo) < 0) {
+#else
+ if (stat(filename, &fileinfo) < 0) {
+#endif
perror("stat");
return;
}
printf("Filesystem cylinder groups is approximately %ld\n",
cylgroups);
}
- fd = open(filename, O_RDONLY | O_LARGEFILE);
+#ifdef HAVE_OPEN64
+ fd = open64(filename, O_RDONLY);
+#else
+ fd = open(filename, O_RDONLY);
+#endif
if (fd < 0) {
perror("open");
return;
}
- if (ioctl(fd, FIGETBSZ, &bs) < 0) {
+ if (ioctl(fd, FIGETBSZ, &bs) < 0) { /* FIGETBSZ takes an int */
perror("FIGETBSZ");
close(fd);
return;
}
- if (ioctl(fd, EXT3_IOC_GETFLAGS, &flags) < 0) {
- perror("EXT3_IOC_GETFLAGS");
- close(fd);
- return;
- }
+ if (ioctl(fd, EXT3_IOC_GETFLAGS, &flags) < 0)
+ flags = 0;
if (flags & EXT3_EXTENTS_FL) {
printf("File is stored in extents format\n");
is_ext2 = 0;
}
if (verbose)
- printf("Blocksize of file %s is %ld\n", filename, bs);
+ printf("Blocksize of file %s is %d\n", filename, bs);
bpib = bs / 4;
numblocks = (fileinfo.st_size + (bs-1)) / bs;
if (verbose) {
printf("File size of %s is %lld (%ld blocks)\n", filename,
(long long) fileinfo.st_size, numblocks);
- printf("First block: %ld\nLast block: %ld\n",
+ printf("First block: %lu\nLast block: %lu\n",
get_bmap(fd, 0), get_bmap(fd, numblocks - 1));
}
for (i=0; i < numblocks; i++) {
- if (is_ext2) {
+ if (is_ext2 && last_block) {
if (((i-EXT2_DIRECT) % bpib) == 0)
last_block++;
if (((i-EXT2_DIRECT-bpib) % (bpib*bpib)) == 0)
continue;
if (last_block && (block != last_block +1) ) {
if (verbose)
- printf("Discontinuity: Block %ld is at %ld (was %ld)\n",
+ printf("Discontinuity: Block %ld is at %lu (was %lu)\n",
i, block, last_block);
discont++;
}