aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMark Fasheh <mfasheh@suse.com>2008-10-08 19:44:18 -0400
committerTheodore Ts'o <tytso@mit.edu>2008-10-08 19:44:18 -0400
commitc4b929b85bdb64afacbbf6453b1f2bf7e14c9e89 (patch)
tree6f5a4b1378d7b609d0f1ceab93fb501cf91b218a /include
parent4d20c685fa365766a8f13584b4c8178a15ab7103 (diff)
vfs: vfs-level fiemap interface
Basic vfs-level fiemap infrastructure, which sets up a new ->fiemap inode operation. Userspace can get extent information on a file via fiemap ioctl. As input, the fiemap ioctl takes a struct fiemap which includes an array of struct fiemap_extent (fm_extents). Size of the extent array is passed as fm_extent_count and number of extents returned will be written into fm_mapped_extents. Offset and length fields on the fiemap structure (fm_start, fm_length) describe a logical range which will be searched for extents. All extents returned will at least partially contain this range. The actual extent offsets and ranges returned will be unmodified from their offset and range on-disk. The fiemap ioctl returns '0' on success. On error, -1 is returned and errno is set. If errno is equal to EBADR, then fm_flags will contain those flags which were passed in which the kernel did not understand. On all other errors, the contents of fm_extents is undefined. As fiemap evolved, there have been many authors of the vfs patch. As far as I can tell, the list includes: Kalpak Shah <kalpak.shah@sun.com> Andreas Dilger <adilger@sun.com> Eric Sandeen <sandeen@redhat.com> Mark Fasheh <mfasheh@suse.com> Signed-off-by: Mark Fasheh <mfasheh@suse.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Cc: Michael Kerrisk <mtk.manpages@googlemail.com> Cc: linux-api@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org
Diffstat (limited to 'include')
-rw-r--r--include/linux/fiemap.h64
-rw-r--r--include/linux/fs.h18
2 files changed, 82 insertions, 0 deletions
diff --git a/include/linux/fiemap.h b/include/linux/fiemap.h
new file mode 100644
index 000000000000..671decbd2aeb
--- /dev/null
+++ b/include/linux/fiemap.h
@@ -0,0 +1,64 @@
1/*
2 * FS_IOC_FIEMAP ioctl infrastructure.
3 *
4 * Some portions copyright (C) 2007 Cluster File Systems, Inc
5 *
6 * Authors: Mark Fasheh <mfasheh@suse.com>
7 * Kalpak Shah <kalpak.shah@sun.com>
8 * Andreas Dilger <adilger@sun.com>
9 */
10
11#ifndef _LINUX_FIEMAP_H
12#define _LINUX_FIEMAP_H
13
14struct fiemap_extent {
15 __u64 fe_logical; /* logical offset in bytes for the start of
16 * the extent from the beginning of the file */
17 __u64 fe_physical; /* physical offset in bytes for the start
18 * of the extent from the beginning of the disk */
19 __u64 fe_length; /* length in bytes for this extent */
20 __u64 fe_reserved64[2];
21 __u32 fe_flags; /* FIEMAP_EXTENT_* flags for this extent */
22 __u32 fe_reserved[3];
23};
24
25struct fiemap {
26 __u64 fm_start; /* logical offset (inclusive) at
27 * which to start mapping (in) */
28 __u64 fm_length; /* logical length of mapping which
29 * userspace wants (in) */
30 __u32 fm_flags; /* FIEMAP_FLAG_* flags for request (in/out) */
31 __u32 fm_mapped_extents;/* number of extents that were mapped (out) */
32 __u32 fm_extent_count; /* size of fm_extents array (in) */
33 __u32 fm_reserved;
34 struct fiemap_extent fm_extents[0]; /* array of mapped extents (out) */
35};
36
37#define FIEMAP_MAX_OFFSET (~0ULL)
38
39#define FIEMAP_FLAG_SYNC 0x00000001 /* sync file data before map */
40#define FIEMAP_FLAG_XATTR 0x00000002 /* map extended attribute tree */
41
42#define FIEMAP_FLAGS_COMPAT (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR)
43
44#define FIEMAP_EXTENT_LAST 0x00000001 /* Last extent in file. */
45#define FIEMAP_EXTENT_UNKNOWN 0x00000002 /* Data location unknown. */
46#define FIEMAP_EXTENT_DELALLOC 0x00000004 /* Location still pending.
47 * Sets EXTENT_UNKNOWN. */
48#define FIEMAP_EXTENT_ENCODED 0x00000008 /* Data can not be read
49 * while fs is unmounted */
50#define FIEMAP_EXTENT_DATA_ENCRYPTED 0x00000080 /* Data is encrypted by fs.
51 * Sets EXTENT_NO_BYPASS. */
52#define FIEMAP_EXTENT_NOT_ALIGNED 0x00000100 /* Extent offsets may not be
53 * block aligned. */
54#define FIEMAP_EXTENT_DATA_INLINE 0x00000200 /* Data mixed with metadata.
55 * Sets EXTENT_NOT_ALIGNED.*/
56#define FIEMAP_EXTENT_DATA_TAIL 0x00000400 /* Multiple files in block.
57 * Sets EXTENT_NOT_ALIGNED.*/
58#define FIEMAP_EXTENT_UNWRITTEN 0x00000800 /* Space allocated, but
59 * no data (i.e. zero). */
60#define FIEMAP_EXTENT_MERGED 0x00001000 /* File does not natively
61 * support extents. Result
62 * merged for efficiency. */
63
64#endif /* _LINUX_FIEMAP_H */
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 580b513668fe..194fb237a307 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -231,6 +231,7 @@ extern int dir_notify_enable;
231#define FS_IOC_SETFLAGS _IOW('f', 2, long) 231#define FS_IOC_SETFLAGS _IOW('f', 2, long)
232#define FS_IOC_GETVERSION _IOR('v', 1, long) 232#define FS_IOC_GETVERSION _IOR('v', 1, long)
233#define FS_IOC_SETVERSION _IOW('v', 2, long) 233#define FS_IOC_SETVERSION _IOW('v', 2, long)
234#define FS_IOC_FIEMAP _IOWR('f', 11, struct fiemap)
234#define FS_IOC32_GETFLAGS _IOR('f', 1, int) 235#define FS_IOC32_GETFLAGS _IOR('f', 1, int)
235#define FS_IOC32_SETFLAGS _IOW('f', 2, int) 236#define FS_IOC32_SETFLAGS _IOW('f', 2, int)
236#define FS_IOC32_GETVERSION _IOR('v', 1, int) 237#define FS_IOC32_GETVERSION _IOR('v', 1, int)
@@ -291,6 +292,7 @@ extern int dir_notify_enable;
291#include <linux/mutex.h> 292#include <linux/mutex.h>
292#include <linux/capability.h> 293#include <linux/capability.h>
293#include <linux/semaphore.h> 294#include <linux/semaphore.h>
295#include <linux/fiemap.h>
294 296
295#include <asm/atomic.h> 297#include <asm/atomic.h>
296#include <asm/byteorder.h> 298#include <asm/byteorder.h>
@@ -1179,6 +1181,20 @@ extern void dentry_unhash(struct dentry *dentry);
1179extern int file_permission(struct file *, int); 1181extern int file_permission(struct file *, int);
1180 1182
1181/* 1183/*
1184 * VFS FS_IOC_FIEMAP helper definitions.
1185 */
1186struct fiemap_extent_info {
1187 unsigned int fi_flags; /* Flags as passed from user */
1188 unsigned int fi_extents_mapped; /* Number of mapped extents */
1189 unsigned int fi_extents_max; /* Size of fiemap_extent array */
1190 struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent
1191 * array */
1192};
1193int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
1194 u64 phys, u64 len, u32 flags);
1195int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags);
1196
1197/*
1182 * File types 1198 * File types
1183 * 1199 *
1184 * NOTE! These match bits 12..15 of stat.st_mode 1200 * NOTE! These match bits 12..15 of stat.st_mode
@@ -1287,6 +1303,8 @@ struct inode_operations {
1287 void (*truncate_range)(struct inode *, loff_t, loff_t); 1303 void (*truncate_range)(struct inode *, loff_t, loff_t);
1288 long (*fallocate)(struct inode *inode, int mode, loff_t offset, 1304 long (*fallocate)(struct inode *inode, int mode, loff_t offset,
1289 loff_t len); 1305 loff_t len);
1306 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
1307 u64 len);
1290}; 1308};
1291 1309
1292struct seq_file; 1310struct seq_file;