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