merge in vnodes
[unix-history] / usr / src / sys / ufs / ufs / inode.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 *
17 * @(#)inode.h 7.3 (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]
6d0f0ece 97#define i_gen i_ic.ic_gen
ad30fb67 98#define i_lastr i_un.if_lastr
7ef603f5 99#define i_socket i_un.is_socket
69bd12a8
RE
100#define i_forw i_chain[0]
101#define i_back i_chain[1]
102#define i_freef i_un.i_fr.if_freef
103#define i_freeb i_un.i_fr.if_freeb
ad30fb67
KM
104
105#define di_ic di_un.di_icom
106#define di_mode di_ic.ic_mode
107#define di_nlink di_ic.ic_nlink
108#define di_uid di_ic.ic_uid
109#define di_gid di_ic.ic_gid
22a22bd0 110#if defined(vax) || defined(tahoe)
af0b24db 111#define di_size di_ic.ic_size.val[0]
961945a8 112#endif
ad30fb67
KM
113#define di_db di_ic.ic_db
114#define di_ib di_ic.ic_ib
115#define di_atime di_ic.ic_atime
116#define di_mtime di_ic.ic_mtime
117#define di_ctime di_ic.ic_ctime
118#define di_rdev di_ic.ic_db[0]
f2f6c990 119#define di_blocks di_ic.ic_blocks
6d0f0ece 120#define di_gen di_ic.ic_gen
ad30fb67 121
d0064d3a 122#ifdef KERNEL
6e7edb25
BJ
123struct inode *inode; /* the inode table itself */
124struct inode *inodeNINODE; /* the end of the inode table */
125int ninode; /* number of slots in the table */
d0064d3a 126
6d0f0ece
KM
127extern struct vnodeops ufs_vnodeops; /* vnode operations for ufs */
128extern struct vnodeops blk_vnodeops; /* vnode operations for blk devices */
af0b24db 129
6d0f0ece 130extern ino_t dirpref();
d0064d3a
BJ
131#endif
132
133/* flags */
02dd5a44 134#define ILOCKED 0x1 /* inode is locked */
b0954044
SL
135#define IUPD 0x2 /* file has been modified */
136#define IACC 0x4 /* inode access time to be updated */
6d0f0ece
KM
137#define IWANT 0x8 /* some process waiting on lock */
138#define ICHG 0x10 /* inode has been changed */
139#define ISHLOCK 0x20 /* file has shared lock */
140#define IEXLOCK 0x40 /* file has exclusive lock */
141#define ILWAIT 0x80 /* someone waiting on file lock */
142#define IMOD 0x100 /* inode has been modified */
143#define IRENAME 0x200 /* inode is being renamed */
d0064d3a
BJ
144
145/* modes */
ad30fb67
KM
146#define IFMT 0170000 /* type of file */
147#define IFCHR 0020000 /* character special */
148#define IFDIR 0040000 /* directory */
149#define IFBLK 0060000 /* block special */
150#define IFREG 0100000 /* regular */
151#define IFLNK 0120000 /* symbolic link */
dc9a2d80
BJ
152#define IFSOCK 0140000 /* socket */
153
ad30fb67
KM
154#define ISUID 04000 /* set user id on execution */
155#define ISGID 02000 /* set group id on execution */
156#define ISVTX 01000 /* save swapped text even after use */
157#define IREAD 0400 /* read, write, execute permissions */
158#define IWRITE 0200
159#define IEXEC 0100
02dd5a44 160
6d0f0ece
KM
161#ifdef KERNEL
162/*
163 * Convert between inode pointers and vnode pointers
164 */
165#define VTOI(vp) ((struct inode *)(vp)->v_data)
166#define ITOV(ip) ((struct vnode *)&(ip)->i_vnode)
167
168/*
169 * Convert between vnode types and inode formats
170 */
171extern enum vtype iftovt_tab[];
172extern int vttoif_tab[];
173#define IFTOVT(mode) (iftovt_tab[((mode) & IFMT) >> 13])
174#define VTTOIF(indx) (vttoif_tab[(int)(indx)])
175
176#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode))
177
178/*
179 * Lock and unlock inodes.
180 */
02dd5a44
BJ
181#define ILOCK(ip) { \
182 while ((ip)->i_flag & ILOCKED) { \
183 (ip)->i_flag |= IWANT; \
6d0f0ece 184 (void) sleep((caddr_t)(ip), PINOD); \
02dd5a44
BJ
185 } \
186 (ip)->i_flag |= ILOCKED; \
187}
188
189#define IUNLOCK(ip) { \
190 (ip)->i_flag &= ~ILOCKED; \
191 if ((ip)->i_flag&IWANT) { \
192 (ip)->i_flag &= ~IWANT; \
193 wakeup((caddr_t)(ip)); \
194 } \
195}
196
197#define IUPDAT(ip, t1, t2, waitfor) { \
232d0cb7 198 if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
6d0f0ece 199 (void) iupdat(ip, t1, t2, waitfor); \
02dd5a44 200}
232d0cb7
MK
201
202#define ITIMES(ip, t1, t2) { \
203 if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
204 (ip)->i_flag |= IMOD; \
205 if ((ip)->i_flag&IACC) \
206 (ip)->i_atime = (t1)->tv_sec; \
207 if ((ip)->i_flag&IUPD) \
208 (ip)->i_mtime = (t2)->tv_sec; \
209 if ((ip)->i_flag&ICHG) \
210 (ip)->i_ctime = time.tv_sec; \
211 (ip)->i_flag &= ~(IACC|IUPD|ICHG); \
212 } \
213}
6d0f0ece
KM
214
215/*
216 * This overlays the fid sturcture (see mount.h)
217 */
218struct ufid {
219 u_short ufid_len;
220 ino_t ufid_ino;
221 long ufid_gen;
222};
223#endif