]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/ufs/ufs/inode.h
Import the kyua test framework.
[FreeBSD/FreeBSD.git] / sys / ufs / ufs / inode.h
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1982, 1989, 1993
5  *      The Regents of the University of California.  All rights reserved.
6  * (c) UNIX System Laboratories, Inc.
7  * All or some portions of this file are derived from material licensed
8  * to the University of California by American Telephone and Telegraph
9  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10  * the permission of UNIX System Laboratories, Inc.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *      @(#)inode.h     8.9 (Berkeley) 5/14/95
37  * $FreeBSD$
38  */
39
40 #ifndef _UFS_UFS_INODE_H_
41 #define _UFS_UFS_INODE_H_
42
43 #include <sys/lock.h>
44 #include <sys/queue.h>
45 #include <ufs/ufs/dinode.h>
46
47 /*
48  * This must agree with the definition in <ufs/ufs/dir.h>.
49  */
50 #define doff_t          int32_t
51
52 /*
53  * The inode is used to describe each active (or recently active) file in the
54  * UFS filesystem. It is composed of two types of information. The first part
55  * is the information that is needed only while the file is active (such as
56  * the identity of the file and linkage to speed its lookup). The second part
57  * is the permanent meta-data associated with the file which is read in
58  * from the permanent dinode from long term storage when the file becomes
59  * active, and is put back when the file is no longer being used.
60  *
61  * An inode may only be changed while holding either the exclusive
62  * vnode lock or the shared vnode lock and the vnode interlock. We use
63  * the latter only for "read" and "get" operations that require
64  * changing i_flag, or a timestamp. This locking protocol allows executing
65  * those operations without having to upgrade the vnode lock from shared to
66  * exclusive.
67  */
68 struct inode {
69         TAILQ_ENTRY(inode) i_nextsnap; /* snapshot file list. */
70         struct  vnode  *i_vnode;/* Vnode associated with this inode. */
71         struct  ufsmount *i_ump;/* Ufsmount point associated with this inode. */
72         struct   dquot *i_dquot[MAXQUOTAS]; /* Dquot structures. */
73         union {
74                 struct dirhash *dirhash; /* Hashing for large directories. */
75                 daddr_t *snapblklist;    /* Collect expunged snapshot blocks. */
76         } i_un;
77         /*
78          * The real copy of the on-disk inode.
79          */
80         union {
81                 struct ufs1_dinode *din1;       /* UFS1 on-disk dinode. */
82                 struct ufs2_dinode *din2;       /* UFS2 on-disk dinode. */
83         } dinode_u;
84
85         ino_t     i_number;     /* The identity of the inode. */
86         u_int32_t i_flag;       /* flags, see below */
87         int       i_effnlink;   /* i_nlink when I/O completes */
88
89
90         /*
91          * Side effects; used during directory lookup.
92          */
93         int32_t   i_count;      /* Size of free slot in directory. */
94         doff_t    i_endoff;     /* End of useful stuff in directory. */
95         doff_t    i_diroff;     /* Offset in dir, where we found last entry. */
96         doff_t    i_offset;     /* Offset of free space in directory. */
97
98         int     i_nextclustercg; /* last cg searched for cluster */
99
100         /*
101          * Data for extended attribute modification.
102          */
103         u_char    *i_ea_area;   /* Pointer to malloced copy of EA area */
104         unsigned  i_ea_len;     /* Length of i_ea_area */
105         int       i_ea_error;   /* First errno in transaction */
106         int       i_ea_refs;    /* Number of users of EA area */
107
108         /*
109          * Copies from the on-disk dinode itself.
110          */
111         u_int64_t i_size;       /* File byte count. */
112         u_int64_t i_gen;        /* Generation number. */
113         u_int32_t i_flags;      /* Status flags (chflags). */
114         u_int32_t i_uid;        /* File owner. */
115         u_int32_t i_gid;        /* File group. */
116         u_int16_t i_mode;       /* IFMT, permissions; see below. */
117         int16_t   i_nlink;      /* File link count. */
118 };
119 /*
120  * These flags are kept in i_flag.
121  */
122 #define IN_ACCESS       0x0001          /* Access time update request. */
123 #define IN_CHANGE       0x0002          /* Inode change time update request. */
124 #define IN_UPDATE       0x0004          /* Modification time update request. */
125 #define IN_MODIFIED     0x0008          /* Inode has been modified. */
126 #define IN_NEEDSYNC     0x0010          /* Inode requires fsync. */
127 #define IN_LAZYMOD      0x0020          /* Modified, but don't write yet. */
128 #define IN_LAZYACCESS   0x0040          /* Process IN_ACCESS after the
129                                            suspension finished */
130 #define IN_EA_LOCKED    0x0080
131 #define IN_EA_LOCKWAIT  0x0100
132
133 #define IN_TRUNCATED    0x0200          /* Journaled truncation pending. */
134
135 #define IN_UFS2         0x0400          /* UFS2 vs UFS1 */
136
137 #define PRINT_INODE_FLAGS "\20\20b16\17b15\16b14\15b13" \
138         "\14b12\13is_ufs2\12truncated\11ea_lockwait\10ea_locked" \
139         "\7lazyaccess\6lazymod\5needsync\4modified\3update\2change\1access"
140
141 #define UFS_INODE_FLAG_LAZY_MASK        \
142         (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE | IN_LAZYMOD | IN_LAZYACCESS)
143 /*
144  * Some flags can persist a vnode transitioning to 0 hold count and being tkaen
145  * off the list.
146  */
147 #define UFS_INODE_FLAG_LAZY_MASK_ASSERTABLE \
148         (UFS_INODE_FLAG_LAZY_MASK & ~(IN_LAZYMOD | IN_LAZYACCESS))
149
150 #define UFS_INODE_SET_FLAG(ip, flags) do {                      \
151         struct inode *_ip = (ip);                               \
152         struct vnode *_vp = ITOV(_ip);                          \
153         int _flags = (flags);                                   \
154                                                                 \
155         _ip->i_flag |= _flags;                                  \
156         if (_flags & UFS_INODE_FLAG_LAZY_MASK)                  \
157                 vlazy(_vp);                                     \
158 } while (0)
159
160 #define UFS_INODE_SET_FLAG_SHARED(ip, flags) do {               \
161         struct inode *_ip = (ip);                               \
162         struct vnode *_vp = ITOV(_ip);                          \
163         int _flags = (flags);                                   \
164                                                                 \
165         ASSERT_VI_UNLOCKED(_vp, __func__);                      \
166         if ((_ip->i_flag & (_flags)) != _flags) {               \
167                 VI_LOCK(_vp);                                   \
168                 _ip->i_flag |= _flags;                          \
169                 if (_flags & UFS_INODE_FLAG_LAZY_MASK)          \
170                         vlazy(_vp);                             \
171                 VI_UNLOCK(_vp);                                 \
172         }                                                       \
173 } while (0)
174
175 #define i_dirhash i_un.dirhash
176 #define i_snapblklist i_un.snapblklist
177 #define i_din1 dinode_u.din1
178 #define i_din2 dinode_u.din2
179
180 #ifdef _KERNEL
181
182 #define ITOUMP(ip)      ((ip)->i_ump)
183 #define ITODEV(ip)      (ITOUMP(ip)->um_dev)
184 #define ITODEVVP(ip)    (ITOUMP(ip)->um_devvp)
185 #define ITOFS(ip)       (ITOUMP(ip)->um_fs)
186 #define ITOVFS(ip)      ((ip)->i_vnode->v_mount)
187
188 static inline _Bool
189 I_IS_UFS1(const struct inode *ip)
190 {
191
192         return ((ip->i_flag & IN_UFS2) == 0);
193 }
194
195 static inline _Bool
196 I_IS_UFS2(const struct inode *ip)
197 {
198
199         return ((ip->i_flag & IN_UFS2) != 0);
200 }
201
202 /*
203  * The DIP macro is used to access fields in the dinode that are
204  * not cached in the inode itself.
205  */
206 #define DIP(ip, field)  (I_IS_UFS1(ip) ? (ip)->i_din1->d##field : \
207     (ip)->i_din2->d##field)
208 #define DIP_SET(ip, field, val) do {                            \
209         if (I_IS_UFS1(ip))                                      \
210                 (ip)->i_din1->d##field = (val);                 \
211         else                                                    \
212                 (ip)->i_din2->d##field = (val);                 \
213         } while (0)
214
215 #define SHORTLINK(ip)   (I_IS_UFS1(ip) ?                        \
216     (caddr_t)(ip)->i_din1->di_db : (caddr_t)(ip)->i_din2->di_db)
217 #define IS_SNAPSHOT(ip)         ((ip)->i_flags & SF_SNAPSHOT)
218
219 /*
220  * Structure used to pass around logical block paths generated by
221  * ufs_getlbns and used by truncate and bmap code.
222  */
223 struct indir {
224         ufs2_daddr_t in_lbn;            /* Logical block number. */
225         int     in_off;                 /* Offset in buffer. */
226 };
227
228 /* Convert between inode pointers and vnode pointers. */
229 #define VTOI(vp)        ((struct inode *)(vp)->v_data)
230 #define ITOV(ip)        ((ip)->i_vnode)
231
232 /* Determine if soft dependencies are being done */
233 #define DOINGSOFTDEP(vp)   ((vp)->v_mount->mnt_flag & (MNT_SOFTDEP | MNT_SUJ))
234 #define MOUNTEDSOFTDEP(mp) ((mp)->mnt_flag & (MNT_SOFTDEP | MNT_SUJ))
235 #define DOINGSUJ(vp)       ((vp)->v_mount->mnt_flag & MNT_SUJ)
236 #define MOUNTEDSUJ(mp)     ((mp)->mnt_flag & MNT_SUJ)
237
238 /* This overlays the fid structure (see mount.h). */
239 struct ufid {
240         u_int16_t ufid_len;     /* Length of structure. */
241         u_int16_t ufid_pad;     /* Force 32-bit alignment. */
242         uint32_t  ufid_ino;     /* File number (ino). */
243         uint32_t  ufid_gen;     /* Generation number. */
244 };
245 #endif /* _KERNEL */
246
247 #endif /* !_UFS_UFS_INODE_H_ */