replace vn_access with vn_writechk;
[unix-history] / usr / src / sys / ufs / ffs / dinode.h
CommitLineData
da7c5cc6 1/*
6d0f0ece
KM
2 * Copyright (c) 1982, 1989 The Regents of the University of California.
3 * All rights reserved.
da7c5cc6 4 *
6d0f0ece
KM
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 *
f96164be 17 * @(#)dinode.h 7.4 (Berkeley) %G%
da7c5cc6 18 */
d0064d3a
BJ
19
20/*
a59abf09
BJ
21 * The I node is the focus of all file activity in UNIX.
22 * There is a unique inode allocated for each active file,
23 * each current directory, each mounted-on file, text file, and the root.
24 * An inode is 'named' by its dev/inumber pair. (iget/iget.c)
ad30fb67 25 * Data in icommon is read in from permanent inode on volume.
d0064d3a 26 */
ad30fb67 27
af0b24db
SL
28#define NDADDR 12 /* direct addresses in inode */
29#define NIADDR 3 /* indirect addresses in inode */
d0064d3a 30
a59abf09 31struct inode {
69bd12a8 32 struct inode *i_chain[2]; /* must be first */
6d0f0ece
KM
33 struct vnode i_vnode; /* vnode associated with this inode */
34 struct vnode *i_devvp; /* vnode for block I/O */
b0954044 35 u_short i_flag;
d0064d3a
BJ
36 dev_t i_dev; /* device where inode resides */
37 ino_t i_number; /* i number, 1-to-1 with device address */
d40d445c 38 long i_id; /* unique identifier */
6d0f0ece 39 long i_diroff; /* offset in dir, where we found last entry */
ad30fb67 40 struct fs *i_fs; /* file sys associated with this inode */
3e27ef55 41 struct dquot *i_dquot; /* quota structure controlling this file */
68dc14d7 42 struct text *i_text; /* text entry, if any (should be region) */
6d0f0ece
KM
43 struct inode *i_devlst;/* list of block device inodes */
44 off_t i_endoff; /* end of useful stuff in directory */
d0064d3a 45 union {
ad30fb67
KM
46 daddr_t if_lastr; /* last read (read-ahead) */
47 struct socket *is_socket;
69bd12a8
RE
48 struct {
49 struct inode *if_freef; /* free list forward */
50 struct inode **if_freeb; /* free list back */
51 } i_fr;
d0064d3a 52 } i_un;
ad30fb67
KM
53 struct icommon
54 {
55 u_short ic_mode; /* 0: mode and type of file */
56 short ic_nlink; /* 2: number of links to file */
adc65074
MK
57 uid_t ic_uid; /* 4: owner's user id */
58 gid_t ic_gid; /* 6: owner's group id */
af0b24db
SL
59 quad ic_size; /* 8: number of bytes in file */
60 time_t ic_atime; /* 16: time last accessed */
61 long ic_atspare;
62 time_t ic_mtime; /* 24: time last modified */
63 long ic_mtspare;
6c33754a 64 time_t ic_ctime; /* 32: last time inode changed */
af0b24db
SL
65 long ic_ctspare;
66 daddr_t ic_db[NDADDR]; /* 40: disk block addresses */
67 daddr_t ic_ib[NIADDR]; /* 88: indirect blocks */
68 long ic_flags; /* 100: status, currently unused */
f2f6c990 69 long ic_blocks; /* 104: blocks actually held */
6d0f0ece
KM
70 long ic_gen; /* 108: generation number */
71 long ic_spare[4]; /* 112: reserved, currently unused */
ad30fb67 72 } i_ic;
d0064d3a
BJ
73};
74
ad30fb67
KM
75struct dinode {
76 union {
77 struct icommon di_icom;
af0b24db 78 char di_size[128];
ad30fb67
KM
79 } di_un;
80};
81
82#define i_mode i_ic.ic_mode
83#define i_nlink i_ic.ic_nlink
84#define i_uid i_ic.ic_uid
85#define i_gid i_ic.ic_gid
961945a8 86/* ugh! -- must be fixed */
22a22bd0 87#if defined(vax) || defined(tahoe)
af0b24db 88#define i_size i_ic.ic_size.val[0]
961945a8 89#endif
ad30fb67
KM
90#define i_db i_ic.ic_db
91#define i_ib i_ic.ic_ib
92#define i_atime i_ic.ic_atime
93#define i_mtime i_ic.ic_mtime
94#define i_ctime i_ic.ic_ctime
f2f6c990 95#define i_blocks i_ic.ic_blocks
ad30fb67 96#define i_rdev i_ic.ic_db[0]
f96164be 97#define i_flags i_ic.ic_flags
6d0f0ece 98#define i_gen i_ic.ic_gen
ad30fb67 99#define i_lastr i_un.if_lastr
7ef603f5 100#define i_socket i_un.is_socket
69bd12a8
RE
101#define i_forw i_chain[0]
102#define i_back i_chain[1]
103#define i_freef i_un.i_fr.if_freef
104#define i_freeb i_un.i_fr.if_freeb
ad30fb67
KM
105
106#define di_ic di_un.di_icom
107#define di_mode di_ic.ic_mode
108#define di_nlink di_ic.ic_nlink
109#define di_uid di_ic.ic_uid
110#define di_gid di_ic.ic_gid
22a22bd0 111#if defined(vax) || defined(tahoe)
af0b24db 112#define di_size di_ic.ic_size.val[0]
961945a8 113#endif
ad30fb67
KM
114#define di_db di_ic.ic_db
115#define di_ib di_ic.ic_ib
116#define di_atime di_ic.ic_atime
117#define di_mtime di_ic.ic_mtime
118#define di_ctime di_ic.ic_ctime
119#define di_rdev di_ic.ic_db[0]
f2f6c990 120#define di_blocks di_ic.ic_blocks
f96164be 121#define di_flags di_ic.ic_flags
6d0f0ece 122#define di_gen di_ic.ic_gen
ad30fb67 123
d0064d3a 124#ifdef KERNEL
6e7edb25
BJ
125struct inode *inode; /* the inode table itself */
126struct inode *inodeNINODE; /* the end of the inode table */
127int ninode; /* number of slots in the table */
d0064d3a 128
f96164be
KM
129u_long nextgennumber; /* next generation number to assign */
130
6d0f0ece
KM
131extern struct vnodeops ufs_vnodeops; /* vnode operations for ufs */
132extern struct vnodeops blk_vnodeops; /* vnode operations for blk devices */
af0b24db 133
6d0f0ece 134extern ino_t dirpref();
d0064d3a
BJ
135#endif
136
137/* flags */
02dd5a44 138#define ILOCKED 0x1 /* inode is locked */
b0954044
SL
139#define IUPD 0x2 /* file has been modified */
140#define IACC 0x4 /* inode access time to be updated */
6d0f0ece
KM
141#define IWANT 0x8 /* some process waiting on lock */
142#define ICHG 0x10 /* inode has been changed */
143#define ISHLOCK 0x20 /* file has shared lock */
144#define IEXLOCK 0x40 /* file has exclusive lock */
145#define ILWAIT 0x80 /* someone waiting on file lock */
146#define IMOD 0x100 /* inode has been modified */
147#define IRENAME 0x200 /* inode is being renamed */
d0064d3a
BJ
148
149/* modes */
ad30fb67
KM
150#define IFMT 0170000 /* type of file */
151#define IFCHR 0020000 /* character special */
152#define IFDIR 0040000 /* directory */
153#define IFBLK 0060000 /* block special */
154#define IFREG 0100000 /* regular */
155#define IFLNK 0120000 /* symbolic link */
dc9a2d80
BJ
156#define IFSOCK 0140000 /* socket */
157
ad30fb67
KM
158#define ISUID 04000 /* set user id on execution */
159#define ISGID 02000 /* set group id on execution */
160#define ISVTX 01000 /* save swapped text even after use */
161#define IREAD 0400 /* read, write, execute permissions */
162#define IWRITE 0200
163#define IEXEC 0100
02dd5a44 164
6d0f0ece
KM
165#ifdef KERNEL
166/*
167 * Convert between inode pointers and vnode pointers
168 */
169#define VTOI(vp) ((struct inode *)(vp)->v_data)
f96164be 170#define ITOV(ip) (&(ip)->i_vnode)
6d0f0ece
KM
171
172/*
173 * Convert between vnode types and inode formats
174 */
175extern enum vtype iftovt_tab[];
176extern int vttoif_tab[];
177#define IFTOVT(mode) (iftovt_tab[((mode) & IFMT) >> 13])
178#define VTTOIF(indx) (vttoif_tab[(int)(indx)])
179
180#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode))
181
182/*
183 * Lock and unlock inodes.
184 */
02dd5a44
BJ
185#define ILOCK(ip) { \
186 while ((ip)->i_flag & ILOCKED) { \
187 (ip)->i_flag |= IWANT; \
6d0f0ece 188 (void) sleep((caddr_t)(ip), PINOD); \
02dd5a44
BJ
189 } \
190 (ip)->i_flag |= ILOCKED; \
191}
192
193#define IUNLOCK(ip) { \
194 (ip)->i_flag &= ~ILOCKED; \
195 if ((ip)->i_flag&IWANT) { \
196 (ip)->i_flag &= ~IWANT; \
197 wakeup((caddr_t)(ip)); \
198 } \
199}
200
201#define IUPDAT(ip, t1, t2, waitfor) { \
232d0cb7 202 if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
6d0f0ece 203 (void) iupdat(ip, t1, t2, waitfor); \
02dd5a44 204}
232d0cb7
MK
205
206#define ITIMES(ip, t1, t2) { \
207 if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
208 (ip)->i_flag |= IMOD; \
209 if ((ip)->i_flag&IACC) \
210 (ip)->i_atime = (t1)->tv_sec; \
211 if ((ip)->i_flag&IUPD) \
212 (ip)->i_mtime = (t2)->tv_sec; \
213 if ((ip)->i_flag&ICHG) \
214 (ip)->i_ctime = time.tv_sec; \
215 (ip)->i_flag &= ~(IACC|IUPD|ICHG); \
216 } \
217}
6d0f0ece
KM
218
219/*
220 * This overlays the fid sturcture (see mount.h)
221 */
222struct ufid {
223 u_short ufid_len;
224 ino_t ufid_ino;
225 long ufid_gen;
226};
227#endif