]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/xfs_inode.h
Merge branch 'libxfs-4.18-sync' into for-next
[thirdparty/xfsprogs-dev.git] / include / xfs_inode.h
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6
7 #ifndef __XFS_INODE_H__
8 #define __XFS_INODE_H__
9
10 /* These match kernel side includes */
11 #include "xfs_inode_buf.h"
12 #include "xfs_inode_fork.h"
13
14 struct xfs_trans;
15 struct xfs_mount;
16 struct xfs_inode_log_item;
17 struct xfs_dir_ops;
18
19 /*
20 * Inode interface. This fakes up a "VFS inode" to make the xfs_inode appear
21 * similar to the kernel which now is used tohold certain parts of the on-disk
22 * metadata.
23 */
24 struct inode {
25 mode_t i_mode;
26 uint32_t i_nlink;
27 xfs_dev_t i_rdev; /* This actually holds xfs_dev_t */
28 uint32_t i_generation;
29 uint64_t i_version;
30 struct timespec i_atime;
31 struct timespec i_mtime;
32 struct timespec i_ctime;
33 };
34
35 typedef struct xfs_inode {
36 struct cache_node i_node;
37 struct xfs_mount *i_mount; /* fs mount struct ptr */
38 xfs_ino_t i_ino; /* inode number (agno/agino) */
39 struct xfs_imap i_imap; /* location for xfs_imap() */
40 struct xfs_buftarg i_dev; /* dev for this inode */
41 struct xfs_ifork *i_afp; /* attribute fork pointer */
42 struct xfs_ifork *i_cowfp; /* copy on write extents */
43 struct xfs_ifork i_df; /* data fork */
44 struct xfs_trans *i_transp; /* ptr to owning transaction */
45 struct xfs_inode_log_item *i_itemp; /* logging information */
46 unsigned int i_delayed_blks; /* count of delay alloc blks */
47 struct xfs_icdinode i_d; /* most of ondisk inode */
48
49 xfs_extnum_t i_cnextents; /* # of extents in cow fork */
50 unsigned int i_cformat; /* format of cow fork */
51
52 xfs_fsize_t i_size; /* in-memory size */
53 const struct xfs_dir_ops *d_ops; /* directory ops vector */
54 struct inode i_vnode;
55 } xfs_inode_t;
56
57 /* Convert from vfs inode to xfs inode */
58 static inline struct xfs_inode *XFS_I(struct inode *inode)
59 {
60 return container_of(inode, struct xfs_inode, i_vnode);
61 }
62
63 /* convert from xfs inode to vfs inode */
64 static inline struct inode *VFS_I(struct xfs_inode *ip)
65 {
66 return &ip->i_vnode;
67 }
68
69 /* We only have i_size in the xfs inode in userspace */
70 static inline loff_t i_size_read(struct inode *inode)
71 {
72 return XFS_I(inode)->i_size;
73 }
74
75 /*
76 * wrappers around the mode checks to simplify code
77 */
78 static inline bool XFS_ISREG(struct xfs_inode *ip)
79 {
80 return S_ISREG(VFS_I(ip)->i_mode);
81 }
82
83 static inline bool XFS_ISDIR(struct xfs_inode *ip)
84 {
85 return S_ISDIR(VFS_I(ip)->i_mode);
86 }
87
88 /*
89 * For regular files we only update the on-disk filesize when actually
90 * writing data back to disk. Until then only the copy in the VFS inode
91 * is uptodate.
92 */
93 static inline xfs_fsize_t XFS_ISIZE(struct xfs_inode *ip)
94 {
95 if (XFS_ISREG(ip))
96 return ip->i_size;
97 return ip->i_d.di_size;
98 }
99 #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
100
101 /* inode link counts */
102 static inline void set_nlink(struct inode *inode, uint32_t nlink)
103 {
104 inode->i_nlink = nlink;
105 }
106 static inline void inc_nlink(struct inode *inode)
107 {
108 inode->i_nlink++;
109 }
110
111 /*
112 * Project quota id helpers (previously projid was 16bit only and using two
113 * 16bit values to hold new 32bit projid was chosen to retain compatibility with
114 * "old" filesystems).
115 *
116 * Copied here from xfs_inode.h because it has to be defined after the struct
117 * xfs_inode...
118 */
119 static inline prid_t
120 xfs_get_projid(struct xfs_icdinode *id)
121 {
122 return (prid_t)id->di_projid_hi << 16 | id->di_projid_lo;
123 }
124
125 static inline void
126 xfs_set_projid(struct xfs_icdinode *id, prid_t projid)
127 {
128 id->di_projid_hi = (uint16_t) (projid >> 16);
129 id->di_projid_lo = (uint16_t) (projid & 0xffff);
130 }
131
132 static inline bool xfs_is_reflink_inode(struct xfs_inode *ip)
133 {
134 return ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK;
135 }
136
137 typedef struct cred {
138 uid_t cr_uid;
139 gid_t cr_gid;
140 } cred_t;
141
142 extern int libxfs_inode_alloc (struct xfs_trans **, struct xfs_inode *,
143 mode_t, nlink_t, xfs_dev_t, struct cred *,
144 struct fsxattr *, struct xfs_inode **);
145 extern void libxfs_trans_inode_alloc_buf (struct xfs_trans *,
146 struct xfs_buf *);
147
148 extern void libxfs_trans_ichgtime(struct xfs_trans *,
149 struct xfs_inode *, int);
150 extern int libxfs_iflush_int (struct xfs_inode *, struct xfs_buf *);
151
152 /* Inode Cache Interfaces */
153 extern bool libxfs_inode_verify_forks(struct xfs_inode *ip,
154 struct xfs_ifork_ops *);
155 extern int libxfs_iget(struct xfs_mount *, struct xfs_trans *, xfs_ino_t,
156 uint, struct xfs_inode **,
157 struct xfs_ifork_ops *);
158 extern void libxfs_iput(struct xfs_inode *);
159
160 #define IRELE(ip) libxfs_iput(ip)
161
162 #endif /* __XFS_INODE_H__ */