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