rc = ioctl(fd, FS_IOC_FIEMAP, (unsigned long) fiemap);
if (rc < 0) {
static int fiemap_incompat_printed;
+
rc = -errno;
if (rc == -EBADR && !fiemap_incompat_printed) {
- printf("FIEMAP failed with unknown flags %#x\n",
+ fprintf(stderr, "FIEMAP failed with unknown "
+ "flags %x\n",
fiemap->fm_flags);
fiemap_incompat_printed = 1;
}
int num_extents = 1, expected = ~0;
int is_ext2 = 0;
static dev_t last_device;
- unsigned int flags;
int width;
int rc = 0;
(unsigned long)fsinfo.f_type);
}
st.st_blksize = blksize;
- if (ioctl(fd, EXT3_IOC_GETFLAGS, &flags) < 0)
- flags = 0;
- if (!(flags & EXT4_EXTENTS_FL) &&
- ((fsinfo.f_type == 0xef51) || (fsinfo.f_type == 0xef52) ||
- (fsinfo.f_type == 0xef53)))
- is_ext2++;
+ if (fsinfo.f_type == 0xef51 || fsinfo.f_type == 0xef52 ||
+ fsinfo.f_type == 0xef53) {
+ unsigned int flags;
+
+ if (ioctl(fd, EXT3_IOC_GETFLAGS, &flags) == 0 &&
+ !(flags & EXT4_EXTENTS_FL))
+ is_ext2 = 1;
+ }
if (is_ext2) {
long cylgroups = div_ceil(fsinfo.f_blocks, blksize * 8);
expected = 0;
}
- if (force_bmap || rc < 0) {
+ if (force_bmap || rc < 0) { /* FIEMAP failed, try FIBMAP instead */
expected = filefrag_fibmap(fd, blk_shift, &num_extents,
&st, numblocks, is_ext2);
if (expected < 0) {
char **cpp;
int rc = 0, c;
- while ((c = getopt(argc, argv, "Bb::eksvxX")) != EOF)
+ while ((c = getopt(argc, argv, "Bb::eksvxX")) != EOF) {
switch (c) {
case 'B':
force_bmap++;
usage(argv[0]);
break;
}
+ }
if (optind == argc)
usage(argv[0]);
rc = rc2;
}
- return rc;
+ return -rc;
}
#endif