#include <ext2fs/ext2fs.h>
#include <ext2fs/ext2_types.h>
#include <ext2fs/fiemap.h>
int verbose = 0;
#include <ext2fs/ext2fs.h>
#include <ext2fs/ext2_types.h>
#include <ext2fs/fiemap.h>
int verbose = 0;
int xattr_map = 0; /* get xattr mapping */
int force_bmap; /* force use of FIBMAP instead of FIEMAP */
int force_extent; /* print output in extent format always */
int xattr_map = 0; /* get xattr mapping */
int force_bmap; /* force use of FIBMAP instead of FIEMAP */
int force_extent; /* print output in extent format always */
#define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
#define EXT3_IOC_GETFLAGS _IOR('f', 1, long)
#define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
#define EXT3_IOC_GETFLAGS _IOR('f', 1, long)
unsigned long long logical_blk;
unsigned long long ext_len;
unsigned long long ext_blks;
unsigned long long logical_blk;
unsigned long long ext_len;
unsigned long long ext_blks;
sprintf(flags, ext_fmt == hex_fmt ? "%*llx: " : "%*llu: ",
physical_width, expected >> blk_shift);
else
sprintf(flags, "%.*s ", physical_width, " ");
sprintf(flags, ext_fmt == hex_fmt ? "%*llx: " : "%*llu: ",
physical_width, expected >> blk_shift);
else
sprintf(flags, "%.*s ", physical_width, " ");
print_flag(&fe_flags, FIEMAP_EXTENT_LAST, flags, "last,");
print_flag(&fe_flags, FIEMAP_EXTENT_UNKNOWN, flags, "unknown_loc,");
print_flag(&fe_flags, FIEMAP_EXTENT_DELALLOC, flags, "delalloc,");
print_flag(&fe_flags, FIEMAP_EXTENT_LAST, flags, "last,");
print_flag(&fe_flags, FIEMAP_EXTENT_UNKNOWN, flags, "unknown_loc,");
print_flag(&fe_flags, FIEMAP_EXTENT_DELALLOC, flags, "delalloc,");
print_flag(&fe_flags, FIEMAP_EXTENT_UNWRITTEN, flags, "unwritten,");
print_flag(&fe_flags, FIEMAP_EXTENT_MERGED, flags, "merged,");
print_flag(&fe_flags, FIEMAP_EXTENT_SHARED, flags, "shared,");
print_flag(&fe_flags, FIEMAP_EXTENT_UNWRITTEN, flags, "unwritten,");
print_flag(&fe_flags, FIEMAP_EXTENT_MERGED, flags, "merged,");
print_flag(&fe_flags, FIEMAP_EXTENT_SHARED, flags, "shared,");
printf(ext_fmt, cur_ex, logical_width, logical_blk,
logical_width, logical_blk + ext_blks,
physical_width, physical_blk,
printf(ext_fmt, cur_ex, logical_width, logical_blk,
logical_width, logical_blk + ext_blks,
physical_width, physical_blk,
__u64 buf[2048]; /* __u64 for proper field alignment */
struct fiemap *fiemap = (struct fiemap *)buf;
struct fiemap_extent *fm_ext = &fiemap->fm_extents[0];
__u64 buf[2048]; /* __u64 for proper field alignment */
struct fiemap *fiemap = (struct fiemap *)buf;
struct fiemap_extent *fm_ext = &fiemap->fm_extents[0];
int count = (sizeof(buf) - sizeof(*fiemap)) /
sizeof(struct fiemap_extent);
unsigned long long expected = 0;
unsigned long long expected_dense = 0;
unsigned long flags = 0;
unsigned int i;
int count = (sizeof(buf) - sizeof(*fiemap)) /
sizeof(struct fiemap_extent);
unsigned long long expected = 0;
unsigned long long expected_dense = 0;
unsigned long flags = 0;
unsigned int i;
int fiemap_header_printed = 0;
int tot_extents = 0, n = 0;
int last = 0;
int rc;
memset(fiemap, 0, sizeof(struct fiemap));
int fiemap_header_printed = 0;
int tot_extents = 0, n = 0;
int last = 0;
int rc;
memset(fiemap, 0, sizeof(struct fiemap));
do {
fiemap->fm_length = ~0ULL;
fiemap->fm_flags = flags;
fiemap->fm_extent_count = count;
do {
fiemap->fm_length = ~0ULL;
fiemap->fm_flags = flags;
fiemap->fm_extent_count = count;
for (i = 0, logical = 0, *num_extents = 0, count = last_block = 0;
i < numblocks;
for (i = 0, logical = 0, *num_extents = 0, count = last_block = 0;
i < numblocks;
- fm_ext.fe_logical / st->st_blksize,
- fm_ext.fe_physical / st->st_blksize,
- expected / st->st_blksize);
+ (unsigned long long) (fm_ext.fe_logical / st->st_blksize),
+ (unsigned long long) (fm_ext.fe_physical / st->st_blksize),
+ (unsigned long long) (expected / st->st_blksize));
blksize = fsinfo.f_bsize;
if (verbose)
printf("Filesystem type is: %lx\n",
blksize = fsinfo.f_bsize;
if (verbose)
printf("Filesystem type is: %lx\n",
- if (verbose)
- printf("File size of %s is %llu (%llu block%s of %d bytes)\n",
- filename, (unsigned long long)st.st_size,
- numblocks * blksize >> blk_shift,
+ if (verbose) {
+ __u32 state;
+
+ printf("File size of %s is %llu (%llu block%s of %d bytes)",
+ filename, (unsigned long long) st.st_size,
+ (unsigned long long) (numblocks * blksize >> blk_shift),
+ if (use_extent_cache &&
+ ioctl(fd, EXT4_IOC_GETSTATE, &state) == 0 &&
+ (state & EXT4_STATE_FLAG_EXT_PRECACHED))
+ fputs(" -- pre-cached", stdout);
+ fputc('\n', stdout);
+ }
if (!force_bmap) {
rc = filefrag_fiemap(fd, blk_shift, &num_extents, &st);
expected = 0;
if (!force_bmap) {
rc = filefrag_fiemap(fd, blk_shift, &num_extents, &st);
expected = 0;
+ if (rc < 0 &&
+ (use_extent_cache || precache_file || xattr_map)) {
+ if (rc != -EBADR)
+ fprintf(stderr, "%s: %s: %s\n ",
+ filename,
+ use_extent_cache ?
+ "EXT4_IOC_GET_ES_CACHE" :
+ "FS_IOC_FIEMAP", strerror(-rc));
+ goto out_close;
+ }
+ /* Specifying too large a blocksize will just
+ * shift all extents down to zero length. Even
+ * 1GB is questionable, but caveat emptor. */
+ if (val > 1024 * 1024 * 1024) {
+ fprintf(stderr,
+ "%s: blocksize %lu over 1GB\n",
+ argv[0], val);
+ usage(argv[0]);
+ }
+ blocksize = val;
} else { /* Allow -b without argument for compat. Remove
* this eventually so "-b {blocksize}" works */
fprintf(stderr, "%s: -b needs a blocksize "
} else { /* Allow -b without argument for compat. Remove
* this eventually so "-b {blocksize}" works */
fprintf(stderr, "%s: -b needs a blocksize "