- #define EXT3_IOC_WAIT_FOR_READONLY _IOR('f', 99, long)
- #endif
--#define EXT3_IOC_GETRSVSZ _IOR('f', 5, long)
--#define EXT3_IOC_SETRSVSZ _IOW('f', 6, long)
-+
-+/* FIEMAP flags supported by ext3 */
-+#define EXT3_FIEMAP_FLAGS_COMPAT (FIEMAP_FLAG_SYNC)
-
- /*
- * Mount options
-@@ -1041,6 +1045,9 @@ extern int ext3_block_truncate_page(hand
- /* ioctl.c */
- extern int ext3_ioctl (struct inode *, struct file *, unsigned int,
- unsigned long);
-+struct fiemap_extent_info;
-+extern int ext3_fiemap(struct inode *, struct fiemap_extent_info *, __u64,
-+ __u64);
-
- /* namei.c */
- extern int ext3_orphan_add(handle_t *, struct inode *);
-@@ -1118,7 +1125,6 @@ ext3_get_blocks_wrap(handle_t *handle, s
- return ret;
- }
-
--
- #endif /* __KERNEL__ */
-
- /* EXT3_IOC_CREATE_INUM at bottom of file (visible to kernel and user). */
-Index: linux-2.6.18-128.1.6/include/linux/ext3_extents.h
-===================================================================
---- linux-2.6.18-128.1.6.orig/include/linux/ext3_extents.h
-+++ linux-2.6.18-128.1.6/include/linux/ext3_extents.h
-@@ -142,8 +142,10 @@ struct ext3_ext_path {
- * callback must return valid extent (passed or newly created)
- */
- typedef int (*ext_prepare_callback)(struct inode *, struct ext3_ext_path *,
-- struct ext3_ext_cache *,
-- void *);
-+ struct ext3_ext_cache *,
-+ struct ext3_extent *, void *);
-+
-+#define HAVE_EXT_PREPARE_CB_EXTENT
-
- #define EXT_CONTINUE 0
- #define EXT_BREAK 1
-@@ -153,6 +155,26 @@ typedef int (*ext_prepare_callback)(stru
- #define EXT_MAX_BLOCK 0xffffffff
- #define EXT_UNSET_BLOCK 1
-
-+/*
-+ * EXT_INIT_MAX_LEN is the maximum number of blocks we can have in an
-+ * initialized extent. This is 2^15 and not (2^16 - 1), since we use the
-+ * MSB of ee_len field in the extent datastructure to signify if this
-+ * particular extent is an initialized extent or an uninitialized (i.e.
-+ * preallocated).
-+ * EXT_UNINIT_MAX_LEN is the maximum number of blocks we can have in an
-+ * uninitialized extent.
-+ * If ee_len is <= 0x8000, it is an initialized extent. Otherwise, it is an
-+ * uninitialized one. In other words, if MSB of ee_len is set, it is an
-+ * uninitialized extent with only one special scenario when ee_len = 0x8000.
-+ * In this case we can not have an uninitialized extent of zero length and
-+ * thus we make it as a special case of initialized extent with 0x8000 length.
-+ * This way we get better extent-to-group alignment for initialized extents.
-+ * Hence, the maximum number of blocks we can have in an *initialized*
-+ * extent is 2^15 (32768) and in an *uninitialized* extent is 2^15-1 (32767).
-+ */
-+#define EXT_INIT_MAX_LEN (1UL << 15)
-+#define EXT_UNINIT_MAX_LEN (EXT_INIT_MAX_LEN - 1)
-+
- #define EXT_FLAGS_CLR_UNKNOWN 0x7 /* Flags cleared on modification */
- #define EXT_HDR_GEN_BITS 24
- #define EXT_HDR_GEN_MASK ((1 << EXT_HDR_GEN_BITS) - 1)
-@@ -220,6 +242,12 @@ ext3_ext_invalidate_cache(struct inode *
- EXT3_I(inode)->i_cached_extent.ec_type = EXT3_EXT_CACHE_NO;
- }
-
-+static inline int ext3_ext_is_uninitialized(struct ext3_extent *ext)
-+{
-+ /* Extent with ee_len of 0x8000 is treated as an initialized extent */
-+ return (le16_to_cpu(ext->ee_len) > EXT_INIT_MAX_LEN);
-+}
-+
- extern int ext3_ext_search_left(struct inode *, struct ext3_ext_path *, unsigned long *, unsigned long *);
- extern int ext3_ext_search_right(struct inode *, struct ext3_ext_path *, unsigned long *, unsigned long *);
- extern int ext3_extent_tree_init(handle_t *, struct inode *);
-Index: linux-2.6.18-128.1.6/fs/ext3/extents.c
-===================================================================
---- linux-2.6.18-128.1.6.orig/fs/ext3/extents.c
-+++ linux-2.6.18-128.1.6/fs/ext3/extents.c
-@@ -41,6 +41,7 @@
- #include <linux/string.h>
- #include <linux/slab.h>
- #include <linux/ext3_extents.h>
-+#include "fiemap.h"
- #include <asm/uaccess.h>
-
-
-@@ -1481,7 +1482,7 @@ int ext3_ext_walk_space(struct inode *in
- }
-
- BUG_ON(cbex.ec_len == 0);
-- err = func(inode, path, &cbex, cbdata);
-+ err = func(inode, path, &cbex, ex, cbdata);
- ext3_ext_drop_refs(path);
-
- if (err < 0)
-@@ -2296,6 +2297,103 @@ int ext3_ext_writepage_trans_blocks(stru
- return needed;
- }
-
-+/*
-+ * Callback function called for each extent to gather FIEMAP information.
-+ */
-+int ext3_ext_fiemap_cb(struct inode *inode, struct ext3_ext_path *path,
-+ struct ext3_ext_cache *newex, struct ext3_extent *ex,
-+ void *data)
-+{
-+ struct fiemap_extent_info *fieinfo = data;
-+ unsigned char blksize_bits = inode->i_sb->s_blocksize_bits;
-+ __u64 logical;
-+ __u64 physical;
-+ __u64 length;
-+ __u32 flags = 0;
-+ int error;
-+
-+ logical = (__u64)newex->ec_block << blksize_bits;
-+
-+ if (newex->ec_type == EXT3_EXT_CACHE_GAP) {
-+ pgoff_t offset;
-+ struct page *page;
-+ struct buffer_head *bh = NULL;
-+
-+ offset = logical >> PAGE_SHIFT;
-+ page = find_get_page(inode->i_mapping, offset);
-+ if (!page || !page_has_buffers(page))
-+ return EXT_CONTINUE;
-+
-+ bh = page_buffers(page);
-+
-+ if (!bh)
-+ return EXT_CONTINUE;
-+
-+ if (buffer_delay(bh)) {
-+ flags |= FIEMAP_EXTENT_DELALLOC;
-+ page_cache_release(page);
-+ } else {
-+ page_cache_release(page);
-+ return EXT_CONTINUE;
-+ }
-+ }
-+
-+ physical = (__u64)newex->ec_start << blksize_bits;
-+ length = (__u64)newex->ec_len << blksize_bits;
-+
-+ if (ex && ext3_ext_is_uninitialized(ex))
-+ flags |= FIEMAP_EXTENT_UNWRITTEN;
-+
-+ /*
-+ * If this extent reaches EXT_MAX_BLOCK, it must be last.
-+ *
-+ * Or if ext3_ext_next_allocated_block is EXT_MAX_BLOCK,
-+ * this indicates no more allocated blocks.
-+ *
-+ * XXX this might miss a single-block extent at EXT_MAX_BLOCK
-+ */
-+ if (ext3_ext_next_allocated_block(path) == EXT_MAX_BLOCK ||
-+ newex->ec_block + newex->ec_len - 1 == EXT_MAX_BLOCK)
-+ flags |= FIEMAP_EXTENT_LAST;
-+
-+ error = fiemap_fill_next_extent(fieinfo, logical, physical,
-+ length, flags, inode->i_sb->s_dev);
-+ if (error < 0)
-+ return error;
-+ if (error == 1)
-+ return EXT_BREAK;
-+
-+ return EXT_CONTINUE;
-+}
-+
-+int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
-+ __u64 start, __u64 len)
-+{
-+ ext3_fsblk_t start_blk;
-+ ext3_fsblk_t len_blks;
-+ int error = 0;
-+
-+ if (!(EXT3_I(inode)->i_flags & EXT3_EXTENTS_FL))
-+ return -EOPNOTSUPP;
-+
-+ if (fiemap_check_flags(fieinfo, EXT3_FIEMAP_FLAGS_COMPAT))
-+ return -EBADR;
-+
-+ start_blk = start >> inode->i_sb->s_blocksize_bits;
-+ len_blks = (len + inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits;
-+
-+ /*
-+ * Walk the extent tree gathering extent information.
-+ * ext3_ext_fiemap_cb will push extents back to user.
-+ */
-+ mutex_lock(&EXT3_I(inode)->truncate_mutex);
-+ error = ext3_ext_walk_space(inode, start_blk, len_blks,
-+ ext3_ext_fiemap_cb, fieinfo);
-+ mutex_unlock(&EXT3_I(inode)->truncate_mutex);
-+
-+ return error;
-+}
-+
- EXPORT_SYMBOL(ext3_mark_inode_dirty);
- EXPORT_SYMBOL(ext3_ext_invalidate_cache);
- EXPORT_SYMBOL(ext3_ext_insert_extent);
-Index: linux-2.6.18-128.1.6/fs/ext3/fiemap.h
-===================================================================
---- /dev/null
-+++ linux-2.6.18-128.1.6/fs/ext3/fiemap.h
-@@ -0,0 +1,85 @@
-+/*
-+ * FIEMAP ioctl infrastructure.
-+ *
-+ * Copyright 2008 Sun Microsystems, Inc.
-+ *
-+ * Author: Kalpak Shah <kalpak.shah@sun.com>
-+ * Andreas Dilger <adilger@sun.com>
-+ */
-+
-+#ifndef _LINUX_EXT3_FIEMAP_H
-+#define _LINUX_EXT3_FIEMAP_H
-+
-+struct fiemap_extent {
-+ __u64 fe_logical; /* logical offset in bytes for the start of
-+ * the extent from the beginning of the file */
-+ __u64 fe_physical; /* physical offset in bytes for the start
-+ * of the extent from the beginning of the disk */
-+ __u64 fe_length; /* length in bytes for this extent */
-+ __u64 fe_reserved64[2];
-+ __u32 fe_flags; /* FIEMAP_EXTENT_* flags for this extent */
-+ __u32 fe_device; /* device number for this extent */
-+ __u32 fe_reserved[2];
-+};
-+
-+struct fiemap {
-+ __u64 fm_start; /* logical offset (inclusive) at
-+ * which to start mapping (in) */
-+ __u64 fm_length; /* logical length of mapping which
-+ * userspace wants (in) */
-+ __u32 fm_flags; /* FIEMAP_FLAG_* flags for request (in/out) */
-+ __u32 fm_mapped_extents;/* number of extents that were mapped (out) */
-+ __u32 fm_extent_count; /* size of fm_extents array (in) */
-+ __u32 fm_reserved;
-+ struct fiemap_extent fm_extents[0]; /* array of mapped extents (out) */
-+};
-+
-+/*
-+ * FIEMAP helper definition.
-+ */
-+struct fiemap_extent_info {
-+ unsigned int fi_flags; /* Flags as passed from user */
-+ unsigned int fi_extents_mapped; /* Number of mapped extents */
-+ unsigned int fi_extents_max; /* Size of fiemap_extent array*/
-+ struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent array */
-+};
-+
-+int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags);
-+int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
-+ u64 phys, u64 len, u32 flags, u32 lun);
-+
-+#define FIEMAP_MAX_OFFSET (~0ULL)
-+
-+#define FIEMAP_FLAG_SYNC 0x00000001 /* sync file data before map */
-+#define FIEMAP_FLAG_XATTR 0x00000002 /* map extended attribute tree */
-+
-+/* ldiskfs only supports FLAG_SYNC flag currently */
-+#define FIEMAP_FLAGS_COMPAT (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR)
-+
-+#define FIEMAP_EXTENT_LAST 0x00000001 /* Last extent in file. */
-+#define FIEMAP_EXTENT_UNKNOWN 0x00000002 /* Data location unknown. */
-+#define FIEMAP_EXTENT_DELALLOC 0x00000004 /* Location still pending.
-+ * Sets EXTENT_UNKNOWN. */
-+#define FIEMAP_EXTENT_ENCODED 0x00000008 /* Data can not be read
-+ * while fs is unmounted */
-+#define FIEMAP_EXTENT_DATA_ENCRYPTED 0x00000080 /* Data is encrypted by fs.
-+ * Sets EXTENT_NO_DIRECT. */
-+#define FIEMAP_EXTENT_NOT_ALIGNED 0x00000100 /* Extent offsets may not be
-+ * block aligned. */
-+#define FIEMAP_EXTENT_DATA_INLINE 0x00000200 /* Data mixed with metadata.
-+ * Sets EXTENT_NOT_ALIGNED.*/
-+#define FIEMAP_EXTENT_DATA_TAIL 0x00000400 /* Multiple files in block.
-+ * Sets EXTENT_NOT_ALIGNED.*/
-+#define FIEMAP_EXTENT_UNWRITTEN 0x00000800 /* Space allocated, but
-+ * no data (i.e. zero). */
-+#define FIEMAP_EXTENT_MERGED 0x00001000 /* File does not natively
-+ * support extents. Result
-+ * merged for efficiency. */
-+
-+/* Lustre specific flags - use a high bit, don't conflict with upstream flag */
-+#define FIEMAP_EXTENT_NO_DIRECT 0x40000000 /* Data mapping undefined */
-+#define FIEMAP_EXTENT_NET 0x80000000 /* Data stored remotely.
-+ * Sets NO_DIRECT flag */
-+
-+#endif /* _LINUX_EXT3_FIEMAP_H */
-+