4 * Print whether the file start block is stripe-aligned.
6 * Copyright (c) 2010 Eric Sandeen <sandeen@sandeen.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
15 #include <sys/types.h>
19 #include <sys/ioctl.h>
20 #include <linux/fiemap.h>
23 #ifndef FIEMAP_EXTENT_SHARED
24 # define FIEMAP_EXTENT_SHARED 0x00002000
27 #define FIEMAP_EXTENT_ACCEPTABLE (FIEMAP_EXTENT_LAST | \
28 FIEMAP_EXTENT_DATA_ENCRYPTED | FIEMAP_EXTENT_ENCODED | \
29 FIEMAP_EXTENT_UNWRITTEN | FIEMAP_EXTENT_MERGED | \
33 * If only filename given, print first block.
35 * If filename & sunit (in blocks) given, print whether we are well-aligned
38 int main(int argc, char ** argv)
42 struct fiemap_extent *fe;
45 int sunit = 0; /* in blocks */
47 unsigned long long block;
50 printf("Usage: %s <filename> <sunit in blocks>\n", argv[0]);
55 sunit = atoi(argv[2]);
57 fd = open(filename, O_RDONLY);
59 perror("can't open file\n");
70 fie = calloc(1, sizeof(struct fiemap) + sizeof(struct fiemap_extent));
77 fie->fm_flags = FIEMAP_FLAG_SYNC;
78 fie->fm_extent_count = 1;
80 ret = ioctl(fd, FS_IOC_FIEMAP, fie);
82 unsigned int bmap = 0;
84 ret = ioctl(fd, FIBMAP, &bmap);
96 if (fie->fm_mapped_extents != 1) {
97 printf("%s: no extents?\n", filename);
102 fe = &fie->fm_extents[0];
103 if (fe->fe_flags & ~FIEMAP_EXTENT_ACCEPTABLE) {
104 printf("%s: bad flags 0x%x\n", filename, fe->fe_flags);
110 block = fie->fm_extents[0].fe_physical / sb.st_blksize;
113 printf("%s: Start block %llu not multiple of sunit %u\n",
114 filename, block, sunit);
117 printf("%s: well-aligned\n", filename);