···11+/*22+ * FS_IOC_GETFSMAP ioctl infrastructure.33+ *44+ * Copyright (C) 2017 Oracle. All Rights Reserved.55+ *66+ * Author: Darrick J. Wong <darrick.wong@oracle.com>77+ */88+#ifndef _LINUX_FSMAP_H99+#define _LINUX_FSMAP_H1010+1111+#include <linux/types.h>1212+1313+/*1414+ * Structure for FS_IOC_GETFSMAP.1515+ *1616+ * The memory layout for this call are the scalar values defined in1717+ * struct fsmap_head, followed by two struct fsmap that describe1818+ * the lower and upper bound of mappings to return, followed by an1919+ * array of struct fsmap mappings.2020+ *2121+ * fmh_iflags control the output of the call, whereas fmh_oflags report2222+ * on the overall record output. fmh_count should be set to the2323+ * length of the fmh_recs array, and fmh_entries will be set to the2424+ * number of entries filled out during each call. If fmh_count is2525+ * zero, the number of reverse mappings will be returned in2626+ * fmh_entries, though no mappings will be returned. fmh_reserved2727+ * must be set to zero.2828+ *2929+ * The two elements in the fmh_keys array are used to constrain the3030+ * output. The first element in the array should represent the3131+ * lowest disk mapping ("low key") that the user wants to learn3232+ * about. If this value is all zeroes, the filesystem will return3333+ * the first entry it knows about. For a subsequent call, the3434+ * contents of fsmap_head.fmh_recs[fsmap_head.fmh_count - 1] should be3535+ * copied into fmh_keys[0] to have the kernel start where it left off.3636+ *3737+ * The second element in the fmh_keys array should represent the3838+ * highest disk mapping ("high key") that the user wants to learn3939+ * about. If this value is all ones, the filesystem will not stop4040+ * until it runs out of mapping to return or runs out of space in4141+ * fmh_recs.4242+ *4343+ * fmr_device can be either a 32-bit cookie representing a device, or4444+ * a 32-bit dev_t if the FMH_OF_DEV_T flag is set. fmr_physical,4545+ * fmr_offset, and fmr_length are expressed in units of bytes.4646+ * fmr_owner is either an inode number, or a special value if4747+ * FMR_OF_SPECIAL_OWNER is set in fmr_flags.4848+ */4949+struct fsmap {5050+ __u32 fmr_device; /* device id */5151+ __u32 fmr_flags; /* mapping flags */5252+ __u64 fmr_physical; /* device offset of segment */5353+ __u64 fmr_owner; /* owner id */5454+ __u64 fmr_offset; /* file offset of segment */5555+ __u64 fmr_length; /* length of segment */5656+ __u64 fmr_reserved[3]; /* must be zero */5757+};5858+5959+struct fsmap_head {6060+ __u32 fmh_iflags; /* control flags */6161+ __u32 fmh_oflags; /* output flags */6262+ __u32 fmh_count; /* # of entries in array incl. input */6363+ __u32 fmh_entries; /* # of entries filled in (output). */6464+ __u64 fmh_reserved[6]; /* must be zero */6565+6666+ struct fsmap fmh_keys[2]; /* low and high keys for the mapping search */6767+ struct fsmap fmh_recs[]; /* returned records */6868+};6969+7070+/* Size of an fsmap_head with room for nr records. */7171+static inline size_t7272+fsmap_sizeof(7373+ unsigned int nr)7474+{7575+ return sizeof(struct fsmap_head) + nr * sizeof(struct fsmap);7676+}7777+7878+/* Start the next fsmap query at the end of the current query results. */7979+static inline void8080+fsmap_advance(8181+ struct fsmap_head *head)8282+{8383+ head->fmh_keys[0] = head->fmh_recs[head->fmh_entries - 1];8484+}8585+8686+/* fmh_iflags values - set by FS_IOC_GETFSMAP caller in the header. */8787+/* no flags defined yet */8888+#define FMH_IF_VALID 08989+9090+/* fmh_oflags values - returned in the header segment only. */9191+#define FMH_OF_DEV_T 0x1 /* fmr_device values will be dev_t */9292+9393+/* fmr_flags values - returned for each non-header segment */9494+#define FMR_OF_PREALLOC 0x1 /* segment = unwritten pre-allocation */9595+#define FMR_OF_ATTR_FORK 0x2 /* segment = attribute fork */9696+#define FMR_OF_EXTENT_MAP 0x4 /* segment = extent map */9797+#define FMR_OF_SHARED 0x8 /* segment = shared with another file */9898+#define FMR_OF_SPECIAL_OWNER 0x10 /* owner is a special value */9999+#define FMR_OF_LAST 0x20 /* segment is the last in the FS */100100+101101+/* Each FS gets to define its own special owner codes. */102102+#define FMR_OWNER(type, code) (((__u64)type << 32) | \103103+ ((__u64)code & 0xFFFFFFFFULL))104104+#define FMR_OWNER_TYPE(owner) ((__u32)((__u64)owner >> 32))105105+#define FMR_OWNER_CODE(owner) ((__u32)(((__u64)owner & 0xFFFFFFFFULL)))106106+#define FMR_OWN_FREE FMR_OWNER(0, 1) /* free space */107107+#define FMR_OWN_UNKNOWN FMR_OWNER(0, 2) /* unknown owner */108108+#define FMR_OWN_METADATA FMR_OWNER(0, 3) /* metadata */109109+110110+#define FS_IOC_GETFSMAP _IOWR('X', 59, struct fsmap_head)111111+112112+#endif /* _LINUX_FSMAP_H */