at v4.13 4.3 kB view raw
1/* 2 * FS_IOC_GETFSMAP ioctl infrastructure. 3 * 4 * Copyright (C) 2017 Oracle. All Rights Reserved. 5 * 6 * Author: Darrick J. Wong <darrick.wong@oracle.com> 7 */ 8#ifndef _LINUX_FSMAP_H 9#define _LINUX_FSMAP_H 10 11#include <linux/types.h> 12 13/* 14 * Structure for FS_IOC_GETFSMAP. 15 * 16 * The memory layout for this call are the scalar values defined in 17 * struct fsmap_head, followed by two struct fsmap that describe 18 * the lower and upper bound of mappings to return, followed by an 19 * array of struct fsmap mappings. 20 * 21 * fmh_iflags control the output of the call, whereas fmh_oflags report 22 * on the overall record output. fmh_count should be set to the 23 * length of the fmh_recs array, and fmh_entries will be set to the 24 * number of entries filled out during each call. If fmh_count is 25 * zero, the number of reverse mappings will be returned in 26 * fmh_entries, though no mappings will be returned. fmh_reserved 27 * must be set to zero. 28 * 29 * The two elements in the fmh_keys array are used to constrain the 30 * output. The first element in the array should represent the 31 * lowest disk mapping ("low key") that the user wants to learn 32 * about. If this value is all zeroes, the filesystem will return 33 * the first entry it knows about. For a subsequent call, the 34 * contents of fsmap_head.fmh_recs[fsmap_head.fmh_count - 1] should be 35 * copied into fmh_keys[0] to have the kernel start where it left off. 36 * 37 * The second element in the fmh_keys array should represent the 38 * highest disk mapping ("high key") that the user wants to learn 39 * about. If this value is all ones, the filesystem will not stop 40 * until it runs out of mapping to return or runs out of space in 41 * fmh_recs. 42 * 43 * fmr_device can be either a 32-bit cookie representing a device, or 44 * a 32-bit dev_t if the FMH_OF_DEV_T flag is set. fmr_physical, 45 * fmr_offset, and fmr_length are expressed in units of bytes. 46 * fmr_owner is either an inode number, or a special value if 47 * FMR_OF_SPECIAL_OWNER is set in fmr_flags. 48 */ 49struct fsmap { 50 __u32 fmr_device; /* device id */ 51 __u32 fmr_flags; /* mapping flags */ 52 __u64 fmr_physical; /* device offset of segment */ 53 __u64 fmr_owner; /* owner id */ 54 __u64 fmr_offset; /* file offset of segment */ 55 __u64 fmr_length; /* length of segment */ 56 __u64 fmr_reserved[3]; /* must be zero */ 57}; 58 59struct fsmap_head { 60 __u32 fmh_iflags; /* control flags */ 61 __u32 fmh_oflags; /* output flags */ 62 __u32 fmh_count; /* # of entries in array incl. input */ 63 __u32 fmh_entries; /* # of entries filled in (output). */ 64 __u64 fmh_reserved[6]; /* must be zero */ 65 66 struct fsmap fmh_keys[2]; /* low and high keys for the mapping search */ 67 struct fsmap fmh_recs[]; /* returned records */ 68}; 69 70/* Size of an fsmap_head with room for nr records. */ 71static inline size_t 72fsmap_sizeof( 73 unsigned int nr) 74{ 75 return sizeof(struct fsmap_head) + nr * sizeof(struct fsmap); 76} 77 78/* Start the next fsmap query at the end of the current query results. */ 79static inline void 80fsmap_advance( 81 struct fsmap_head *head) 82{ 83 head->fmh_keys[0] = head->fmh_recs[head->fmh_entries - 1]; 84} 85 86/* fmh_iflags values - set by FS_IOC_GETFSMAP caller in the header. */ 87/* no flags defined yet */ 88#define FMH_IF_VALID 0 89 90/* fmh_oflags values - returned in the header segment only. */ 91#define FMH_OF_DEV_T 0x1 /* fmr_device values will be dev_t */ 92 93/* fmr_flags values - returned for each non-header segment */ 94#define FMR_OF_PREALLOC 0x1 /* segment = unwritten pre-allocation */ 95#define FMR_OF_ATTR_FORK 0x2 /* segment = attribute fork */ 96#define FMR_OF_EXTENT_MAP 0x4 /* segment = extent map */ 97#define FMR_OF_SHARED 0x8 /* segment = shared with another file */ 98#define FMR_OF_SPECIAL_OWNER 0x10 /* owner is a special value */ 99#define FMR_OF_LAST 0x20 /* segment is the last in the FS */ 100 101/* Each FS gets to define its own special owner codes. */ 102#define FMR_OWNER(type, code) (((__u64)type << 32) | \ 103 ((__u64)code & 0xFFFFFFFFULL)) 104#define FMR_OWNER_TYPE(owner) ((__u32)((__u64)owner >> 32)) 105#define FMR_OWNER_CODE(owner) ((__u32)(((__u64)owner & 0xFFFFFFFFULL))) 106#define FMR_OWN_FREE FMR_OWNER(0, 1) /* free space */ 107#define FMR_OWN_UNKNOWN FMR_OWNER(0, 2) /* unknown owner */ 108#define FMR_OWN_METADATA FMR_OWNER(0, 3) /* metadata */ 109 110#define FS_IOC_GETFSMAP _IOWR('X', 59, struct fsmap_head) 111 112#endif /* _LINUX_FSMAP_H */