Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) .. SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) ============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) Fiemap Ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) ============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) The fiemap ioctl is an efficient method for userspace to get file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) extent mappings. Instead of block-by-block mapping (such as bmap), fiemap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) returns a list of extents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) Request Basics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) --------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) A fiemap request is encoded within struct fiemap::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)   struct fiemap {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	__u64	fm_start;	 /* logical offset (inclusive) at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 				  * which to start mapping (in) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	__u64	fm_length;	 /* logical length of mapping which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 				  * userspace cares about (in) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	__u32	fm_flags;	 /* FIEMAP_FLAG_* flags for request (in/out) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	__u32	fm_mapped_extents; /* number of extents that were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 				    * mapped (out) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	__u32	fm_extent_count; /* size of fm_extents array (in) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	__u32	fm_reserved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	struct fiemap_extent fm_extents[0]; /* array of mapped extents (out) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)   };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) fm_start, and fm_length specify the logical range within the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) which the process would like mappings for. Extents returned mirror
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) those on disk - that is, the logical offset of the 1st returned extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) may start before fm_start, and the range covered by the last returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) extent may end after fm_length. All offsets and lengths are in bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) Certain flags to modify the way in which mappings are looked up can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) set in fm_flags. If the kernel doesn't understand some particular
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) flags, it will return EBADR and the contents of fm_flags will contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) the set of flags which caused the error. If the kernel is compatible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) with all flags passed, the contents of fm_flags will be unmodified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) It is up to userspace to determine whether rejection of a particular
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) flag is fatal to its operation. This scheme is intended to allow the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) fiemap interface to grow in the future but without losing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) compatibility with old software.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) fm_extent_count specifies the number of elements in the fm_extents[] array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) that can be used to return extents.  If fm_extent_count is zero, then the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) fm_extents[] array is ignored (no extents will be returned), and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) fm_mapped_extents count will hold the number of extents needed in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) fm_extents[] to hold the file's current mapping.  Note that there is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) nothing to prevent the file from changing between calls to FIEMAP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) The following flags can be set in fm_flags:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) FIEMAP_FLAG_SYNC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)   If this flag is set, the kernel will sync the file before mapping extents.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) FIEMAP_FLAG_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)   If this flag is set, the extents returned will describe the inodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)   extended attribute lookup tree, instead of its data tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) Extent Mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) --------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) Extent information is returned within the embedded fm_extents array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) which userspace must allocate along with the fiemap structure. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) number of elements in the fiemap_extents[] array should be passed via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) fm_extent_count. The number of extents mapped by kernel will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) returned via fm_mapped_extents. If the number of fiemap_extents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) allocated is less than would be required to map the requested range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) the maximum number of extents that can be mapped in the fm_extent[]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) array will be returned and fm_mapped_extents will be equal to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) fm_extent_count. In that case, the last extent in the array will not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) complete the requested range and will not have the FIEMAP_EXTENT_LAST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) flag set (see the next section on extent flags).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) Each extent is described by a single fiemap_extent structure as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) returned in fm_extents::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)     struct fiemap_extent {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	    __u64	fe_logical;  /* logical offset in bytes for the start of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 				* the extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	    __u64	fe_physical; /* physical offset in bytes for the start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 				* of the extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	    __u64	fe_length;   /* length in bytes for the extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	    __u64	fe_reserved64[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	    __u32	fe_flags;    /* FIEMAP_EXTENT_* flags for this extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	    __u32	fe_reserved[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)     };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) All offsets and lengths are in bytes and mirror those on disk.  It is valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) for an extents logical offset to start before the request or its logical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) length to extend past the request.  Unless FIEMAP_EXTENT_NOT_ALIGNED is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) returned, fe_logical, fe_physical, and fe_length will be aligned to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) block size of the file system.  With the exception of extents flagged as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) FIEMAP_EXTENT_MERGED, adjacent extents will not be merged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) The fe_flags field contains flags which describe the extent returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) A special flag, FIEMAP_EXTENT_LAST is always set on the last extent in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) the file so that the process making fiemap calls can determine when no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) more extents are available, without having to call the ioctl again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) Some flags are intentionally vague and will always be set in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) presence of other more specific flags. This way a program looking for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) a general property does not have to know all existing and future flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) which imply that property.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) For example, if FIEMAP_EXTENT_DATA_INLINE or FIEMAP_EXTENT_DATA_TAIL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) are set, FIEMAP_EXTENT_NOT_ALIGNED will also be set. A program looking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) for inline or tail-packed data can key on the specific flag. Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) which simply cares not to try operating on non-aligned extents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) however, can just key on FIEMAP_EXTENT_NOT_ALIGNED, and not have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) worry about all present and future flags which might imply unaligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) data. Note that the opposite is not true - it would be valid for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) FIEMAP_EXTENT_NOT_ALIGNED to appear alone.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) FIEMAP_EXTENT_LAST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)   This is generally the last extent in the file. A mapping attempt past
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)   this extent may return nothing. Some implementations set this flag to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)   indicate this extent is the last one in the range queried by the user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)   (via fiemap->fm_length).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) FIEMAP_EXTENT_UNKNOWN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)   The location of this extent is currently unknown. This may indicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)   the data is stored on an inaccessible volume or that no storage has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)   been allocated for the file yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) FIEMAP_EXTENT_DELALLOC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)   This will also set FIEMAP_EXTENT_UNKNOWN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)   Delayed allocation - while there is data for this extent, its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)   physical location has not been allocated yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) FIEMAP_EXTENT_ENCODED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)   This extent does not consist of plain filesystem blocks but is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)   encoded (e.g. encrypted or compressed).  Reading the data in this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)   extent via I/O to the block device will have undefined results.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) Note that it is *always* undefined to try to update the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) in-place by writing to the indicated location without the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) assistance of the filesystem, or to access the data using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) information returned by the FIEMAP interface while the filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) is mounted.  In other words, user applications may only read the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) extent data via I/O to the block device while the filesystem is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) unmounted, and then only if the FIEMAP_EXTENT_ENCODED flag is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) clear; user applications must not try reading or writing to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) filesystem via the block device under any other circumstances.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) FIEMAP_EXTENT_DATA_ENCRYPTED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)   This will also set FIEMAP_EXTENT_ENCODED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)   The data in this extent has been encrypted by the file system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) FIEMAP_EXTENT_NOT_ALIGNED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)   Extent offsets and length are not guaranteed to be block aligned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) FIEMAP_EXTENT_DATA_INLINE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)   This will also set FIEMAP_EXTENT_NOT_ALIGNED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)   Data is located within a meta data block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) FIEMAP_EXTENT_DATA_TAIL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)   This will also set FIEMAP_EXTENT_NOT_ALIGNED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)   Data is packed into a block with data from other files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) FIEMAP_EXTENT_UNWRITTEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)   Unwritten extent - the extent is allocated but its data has not been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)   initialized.  This indicates the extent's data will be all zero if read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)   through the filesystem but the contents are undefined if read directly from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)   the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) FIEMAP_EXTENT_MERGED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)   This will be set when a file does not support extents, i.e., it uses a block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)   based addressing scheme.  Since returning an extent for each block back to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)   userspace would be highly inefficient, the kernel will try to merge most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)   adjacent blocks into 'extents'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) VFS -> File System Implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) ---------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) File systems wishing to support fiemap must implement a ->fiemap callback on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) their inode_operations structure. The fs ->fiemap call is responsible for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) defining its set of supported fiemap flags, and calling a helper function on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) each discovered extent::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)   struct inode_operations {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)        ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)        int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)                      u64 len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) ->fiemap is passed struct fiemap_extent_info which describes the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) fiemap request::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)   struct fiemap_extent_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	unsigned int fi_flags;		/* Flags as passed from user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	unsigned int fi_extents_mapped;	/* Number of mapped extents */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	unsigned int fi_extents_max;	/* Size of fiemap_extent array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct fiemap_extent *fi_extents_start;	/* Start of fiemap_extent array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)   };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) It is intended that the file system should not need to access any of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) structure directly. Filesystem handlers should be tolerant to signals and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) EINTR once fatal signal received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) Flag checking should be done at the beginning of the ->fiemap callback via the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) fiemap_prep() helper::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)   int fiemap_prep(struct inode *inode, struct fiemap_extent_info *fieinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		  u64 start, u64 *len, u32 supported_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) The struct fieinfo should be passed in as received from ioctl_fiemap(). The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) set of fiemap flags which the fs understands should be passed via fs_flags. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) fiemap_prep finds invalid user flags, it will place the bad values in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) fieinfo->fi_flags and return -EBADR. If the file system gets -EBADR, from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) fiemap_prep(), it should immediately exit, returning that error back to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) ioctl_fiemap().  Additionally the range is validate against the supported
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) maximum file size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) For each extent in the request range, the file system should call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) the helper function, fiemap_fill_next_extent()::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)   int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			      u64 phys, u64 len, u32 flags, u32 dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) fiemap_fill_next_extent() will use the passed values to populate the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) next free extent in the fm_extents array. 'General' extent flags will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) automatically be set from specific flags on behalf of the calling file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) system so that the userspace API is not broken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) fiemap_fill_next_extent() returns 0 on success, and 1 when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) user-supplied fm_extents array is full. If an error is encountered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) while copying the extent to user memory, -EFAULT will be returned.