]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - include/xfs_inode.h
xfs: fix off-by-one error in xfs_rtalloc_query_range
[thirdparty/xfsprogs-dev.git] / include / xfs_inode.h
index 303efe0e4aff81a3abddd1456b1834db52ec77a9..f29f0f0d388cfdad1aa768f13d86b4eef705ef0c 100644 (file)
@@ -20,8 +20,8 @@
 #define __XFS_INODE_H__
 
 /* These match kernel side includes */
-#include "xfs/xfs_inode_buf.h"
-#include "xfs/xfs_inode_fork.h"
+#include "xfs_inode_buf.h"
+#include "xfs_inode_fork.h"
 
 struct xfs_trans;
 struct xfs_mount;
@@ -29,8 +29,21 @@ struct xfs_inode_log_item;
 struct xfs_dir_ops;
 
 /*
- * Inode interface
+ * Inode interface. This fakes up a "VFS inode" to make the xfs_inode appear
+ * similar to the kernel which now is used tohold certain parts of the on-disk
+ * metadata.
  */
+struct inode {
+       mode_t          i_mode;
+       uint32_t        i_nlink;
+       xfs_dev_t       i_rdev;         /* This actually holds xfs_dev_t */
+       uint32_t        i_generation;
+       uint64_t        i_version;
+       struct timespec i_atime;
+       struct timespec i_mtime;
+       struct timespec i_ctime;
+};
+
 typedef struct xfs_inode {
        struct cache_node       i_node;
        struct xfs_mount        *i_mount;       /* fs mount struct ptr */
@@ -38,15 +51,52 @@ typedef struct xfs_inode {
        struct xfs_imap         i_imap;         /* location for xfs_imap() */
        struct xfs_buftarg      i_dev;          /* dev for this inode */
        struct xfs_ifork        *i_afp;         /* attribute fork pointer */
+       struct xfs_ifork        *i_cowfp;       /* copy on write extents */
        struct xfs_ifork        i_df;           /* data fork */
        struct xfs_trans        *i_transp;      /* ptr to owning transaction */
        struct xfs_inode_log_item *i_itemp;     /* logging information */
        unsigned int            i_delayed_blks; /* count of delay alloc blks */
        struct xfs_icdinode     i_d;            /* most of ondisk inode */
+
+       xfs_extnum_t            i_cnextents;    /* # of extents in cow fork */
+       unsigned int            i_cformat;      /* format of cow fork */
+
        xfs_fsize_t             i_size;         /* in-memory size */
        const struct xfs_dir_ops *d_ops;        /* directory ops vector */
+       struct inode            i_vnode;
 } xfs_inode_t;
 
+/* Convert from vfs inode to xfs inode */
+static inline struct xfs_inode *XFS_I(struct inode *inode)
+{
+       return container_of(inode, struct xfs_inode, i_vnode);
+}
+
+/* convert from xfs inode to vfs inode */
+static inline struct inode *VFS_I(struct xfs_inode *ip)
+{
+       return &ip->i_vnode;
+}
+
+/* We only have i_size in the xfs inode in userspace */
+static inline loff_t i_size_read(struct inode *inode)
+{
+       return XFS_I(inode)->i_size;
+}
+
+/*
+ * wrappers around the mode checks to simplify code
+ */
+static inline bool XFS_ISREG(struct xfs_inode *ip)
+{
+       return S_ISREG(VFS_I(ip)->i_mode);
+}
+
+static inline bool XFS_ISDIR(struct xfs_inode *ip)
+{
+       return S_ISDIR(VFS_I(ip)->i_mode);
+}
+
 /*
  * For regular files we only update the on-disk filesize when actually
  * writing data back to disk.  Until then only the copy in the VFS inode
@@ -54,12 +104,22 @@ typedef struct xfs_inode {
  */
 static inline xfs_fsize_t XFS_ISIZE(struct xfs_inode *ip)
 {
-       if (S_ISREG(ip->i_d.di_mode))
+       if (XFS_ISREG(ip))
                return ip->i_size;
        return ip->i_d.di_size;
 }
 #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
 
+/* inode link counts */
+static inline void set_nlink(struct inode *inode, uint32_t nlink)
+{
+       inode->i_nlink = nlink;
+}
+static inline void inc_nlink(struct inode *inode)
+{
+       inode->i_nlink++;
+}
+
 /*
  * Project quota id helpers (previously projid was 16bit only and using two
  * 16bit values to hold new 32bit projid was chosen to retain compatibility with
@@ -77,8 +137,13 @@ xfs_get_projid(struct xfs_icdinode *id)
 static inline void
 xfs_set_projid(struct xfs_icdinode *id, prid_t projid)
 {
-       id->di_projid_hi = (__uint16_t) (projid >> 16);
-       id->di_projid_lo = (__uint16_t) (projid & 0xffff);
+       id->di_projid_hi = (uint16_t) (projid >> 16);
+       id->di_projid_lo = (uint16_t) (projid & 0xffff);
+}
+
+static inline bool xfs_is_reflink_inode(struct xfs_inode *ip)
+{
+       return ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK;
 }
 
 typedef struct cred {
@@ -97,8 +162,11 @@ extern void libxfs_trans_ichgtime(struct xfs_trans *,
 extern int     libxfs_iflush_int (struct xfs_inode *, struct xfs_buf *);
 
 /* Inode Cache Interfaces */
+extern bool    libxfs_inode_verify_forks(struct xfs_inode *ip,
+                               struct xfs_ifork_ops *);
 extern int     libxfs_iget(struct xfs_mount *, struct xfs_trans *, xfs_ino_t,
-                               uint, struct xfs_inode **, xfs_daddr_t);
+                               uint, struct xfs_inode **,
+                               struct xfs_ifork_ops *);
 extern void    libxfs_iput(struct xfs_inode *);
 
 #define IRELE(ip) libxfs_iput(ip)