]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
fiemap: include linux fiemap.h header; unconditionally compile helper
authorSage Weil <sage@newdream.net>
Tue, 9 Nov 2010 22:35:33 +0000 (14:35 -0800)
committerSage Weil <sage@newdream.net>
Tue, 9 Nov 2010 22:35:33 +0000 (14:35 -0800)
If the system doesn't have the header, use our copy.

Signed-off-by: Sage Weil <sage@newdream.net>
src/Makefile.am
src/common/fiemap.cc
src/include/fiemap.h
src/include/linux_fiemap.h [new file with mode: 0644]

index 60329e3e663014f486f3bae4863c20b7b1b5fe4c..238e5e47f589acb67688d23de4f83ace0d597817 100644 (file)
@@ -626,6 +626,7 @@ noinst_HEADERS = \
         include/inttypes.h\
        include/librados.h\
        include/librados.hpp\
+       include/linux_fiemap.h\
         include/lru.h\
        include/msgr.h\
         include/nstring.h\
index f4f9467f430f7b62b251a21fbe5ff58246422bd0..23e614f691770fd35f28f4435eaf9bee060ec43d 100644 (file)
  *  Author Colin Ian King,  colin.king@canonical.com
  */
 
-
-#ifdef HAVE_FIEMAP_H
-
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -42,6 +38,7 @@ struct fiemap *read_fiemap(int fd)
 {
   struct fiemap *fiemap;
   int extents_size;
+  int r;
 
   if ((fiemap = (struct fiemap*)malloc(sizeof(struct fiemap))) == NULL) {
     fprintf(stderr, "Out of memory allocating fiemap\n");
@@ -56,7 +53,8 @@ struct fiemap *read_fiemap(int fd)
   fiemap->fm_mapped_extents = 0;
 
   /* Find out how many extents there are */
-  if (ioctl(fd, FS_IOC_FIEMAP, fiemap) < 0) {
+  r = ioctl(fd, FS_IOC_FIEMAP, fiemap);
+  if (r < 0) {
     fprintf(stderr, "fiemap ioctl() failed\n");
     goto done_err;
   }
@@ -86,4 +84,3 @@ done_err:
   return NULL;
 }
 
-#endif
index d5d163706efdd3f774f4f055b12267e092628c9e..17b4430a52a8f60ca4403fab905825d3df984e42 100644 (file)
@@ -1,42 +1,23 @@
 #ifndef __CEPH_FIEMAP_H
 #define __CEPH_FIEMAP_H
 
-#include "config.h"
+#include "acconfig.h"
 
+/*
+ * the header is missing on most systems.  for the time being at
+ * least, include our own copy in the repo.
+ */
 #ifdef HAVE_FIEMAP_H
-
-#include <linux/fiemap.h>
-
-extern "C" struct fiemap *read_fiemap(int fd);
-
+# include <linux/fiemap.h>
 #else
+# include "linux_fiemap.h"
+#endif
 
-/*
- the following structures differ from the original structures.
- Using it for the fiemap ioctl will not work.
-*/
-struct fiemap_extent {
-  __u64 fe_logical;
-  __u64 fe_physical;
-  __u64 fe_length;
-  __u32 fe_flags;
-};
-
-struct fiemap {
-  __u64 fm_start;
-  __u64 fm_length;
-  __u32 fm_flags;
-  __u32 fm_mapped_extents;
-  __u32 fm_extent_count;
-  struct fiemap_extent fm_extents[0];
-};
-
-static inline struct fiemap *read_fiemap(int fd)
-{
-  return NULL;
-}
-
+#include <linux/ioctl.h>
+#ifndef FS_IOC_FIEMAP
+# define FS_IOC_FIEMAP                        _IOWR('f', 11, struct fiemap)
 #endif
 
+extern "C" struct fiemap *read_fiemap(int fd);
 
 #endif
diff --git a/src/include/linux_fiemap.h b/src/include/linux_fiemap.h
new file mode 100644 (file)
index 0000000..d830747
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * FS_IOC_FIEMAP ioctl infrastructure.
+ *
+ * Some portions copyright (C) 2007 Cluster File Systems, Inc
+ *
+ * Authors: Mark Fasheh <mfasheh@suse.com>
+ *          Kalpak Shah <kalpak.shah@sun.com>
+ *          Andreas Dilger <adilger@sun.com>
+ */
+
+#ifndef _LINUX_FIEMAP_H
+#define _LINUX_FIEMAP_H
+
+#include <linux/types.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_reserved[3];
+};
+
+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) */
+};
+
+#define FIEMAP_MAX_OFFSET      (~0ULL)
+
+#define FIEMAP_FLAG_SYNC       0x00000001 /* sync file data before map */
+#define FIEMAP_FLAG_XATTR      0x00000002 /* map extended attribute tree */
+
+#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_BYPASS. */
+#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. */
+#define FIEMAP_EXTENT_SHARED           0x00002000 /* Space shared with other
+                                                   * files. */
+
+#endif /* _LINUX_FIEMAP_H */