]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/xfs_inode.h
libxfs: cosmetic changes to libxfs_inode_alloc
[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
18 /*
19 * These are not actually used, they are only for userspace build
20 * compatibility in code that looks at i_state
21 */
22 #define I_DIRTY_TIME 0
23 #define I_DIRTY_TIME_EXPIRED 0
24
25 #define IS_I_VERSION(inode) (0)
26 #define inode_maybe_inc_iversion(inode,flags) (0)
27
28 /*
29 * Inode interface. This fakes up a "VFS inode" to make the xfs_inode appear
30 * similar to the kernel which now is used tohold certain parts of the on-disk
31 * metadata.
32 */
33 struct inode {
34 mode_t i_mode;
35 uint32_t i_uid;
36 uint32_t i_gid;
37 uint32_t i_nlink;
38 xfs_dev_t i_rdev; /* This actually holds xfs_dev_t */
39 unsigned int i_count;
40 unsigned long i_state; /* Not actually used in userspace */
41 uint32_t i_generation;
42 uint64_t i_version;
43 struct timespec64 i_atime;
44 struct timespec64 i_mtime;
45 struct timespec64 i_ctime;
46 };
47
48 static inline uint32_t i_uid_read(struct inode *inode)
49 {
50 return inode->i_uid;
51 }
52 static inline uint32_t i_gid_read(struct inode *inode)
53 {
54 return inode->i_gid;
55 }
56 static inline void i_uid_write(struct inode *inode, uint32_t uid)
57 {
58 inode->i_uid = uid;
59 }
60 static inline void i_gid_write(struct inode *inode, uint32_t gid)
61 {
62 inode->i_gid = gid;
63 }
64
65 static inline void ihold(struct inode *inode)
66 {
67 inode->i_count++;
68 }
69
70 typedef struct xfs_inode {
71 struct cache_node i_node;
72 struct xfs_mount *i_mount; /* fs mount struct ptr */
73 xfs_ino_t i_ino; /* inode number (agno/agino) */
74 struct xfs_imap i_imap; /* location for xfs_imap() */
75 struct xfs_buftarg i_dev; /* dev for this inode */
76 struct xfs_ifork *i_afp; /* attribute fork pointer */
77 struct xfs_ifork *i_cowfp; /* copy on write extents */
78 struct xfs_ifork i_df; /* data fork */
79 struct xfs_inode_log_item *i_itemp; /* logging information */
80 unsigned int i_delayed_blks; /* count of delay alloc blks */
81 struct xfs_icdinode i_d; /* most of ondisk inode */
82
83 xfs_extnum_t i_cnextents; /* # of extents in cow fork */
84 unsigned int i_cformat; /* format of cow fork */
85
86 xfs_fsize_t i_size; /* in-memory size */
87 struct inode i_vnode;
88 } xfs_inode_t;
89
90 /* Convert from vfs inode to xfs inode */
91 static inline struct xfs_inode *XFS_I(struct inode *inode)
92 {
93 return container_of(inode, struct xfs_inode, i_vnode);
94 }
95
96 /* convert from xfs inode to vfs inode */
97 static inline struct inode *VFS_I(struct xfs_inode *ip)
98 {
99 return &ip->i_vnode;
100 }
101
102 /* We only have i_size in the xfs inode in userspace */
103 static inline loff_t i_size_read(struct inode *inode)
104 {
105 return XFS_I(inode)->i_size;
106 }
107
108 /*
109 * wrappers around the mode checks to simplify code
110 */
111 static inline bool XFS_ISREG(struct xfs_inode *ip)
112 {
113 return S_ISREG(VFS_I(ip)->i_mode);
114 }
115
116 static inline bool XFS_ISDIR(struct xfs_inode *ip)
117 {
118 return S_ISDIR(VFS_I(ip)->i_mode);
119 }
120
121 /*
122 * For regular files we only update the on-disk filesize when actually
123 * writing data back to disk. Until then only the copy in the VFS inode
124 * is uptodate.
125 */
126 static inline xfs_fsize_t XFS_ISIZE(struct xfs_inode *ip)
127 {
128 if (XFS_ISREG(ip))
129 return ip->i_size;
130 return ip->i_d.di_size;
131 }
132 #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
133
134 /* inode link counts */
135 static inline void set_nlink(struct inode *inode, uint32_t nlink)
136 {
137 inode->i_nlink = nlink;
138 }
139 static inline void inc_nlink(struct inode *inode)
140 {
141 inode->i_nlink++;
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 static inline bool xfs_inode_has_bigtime(struct xfs_inode *ip)
150 {
151 return ip->i_d.di_flags2 & XFS_DIFLAG2_BIGTIME;
152 }
153
154 typedef struct cred {
155 uid_t cr_uid;
156 gid_t cr_gid;
157 } cred_t;
158
159 extern int libxfs_dir_ialloc (struct xfs_trans **, struct xfs_inode *,
160 mode_t, nlink_t, xfs_dev_t, struct cred *,
161 struct fsxattr *, struct xfs_inode **);
162 extern void libxfs_trans_inode_alloc_buf (struct xfs_trans *,
163 struct xfs_buf *);
164
165 extern void libxfs_trans_ichgtime(struct xfs_trans *,
166 struct xfs_inode *, int);
167 extern int libxfs_iflush_int (struct xfs_inode *, struct xfs_buf *);
168
169 extern struct timespec64 current_time(struct inode *inode);
170
171 /* Inode Cache Interfaces */
172 extern int libxfs_iget(struct xfs_mount *, struct xfs_trans *, xfs_ino_t,
173 uint, struct xfs_inode **);
174 extern void libxfs_irele(struct xfs_inode *ip);
175
176 #endif /* __XFS_INODE_H__ */