s/PORTAL/SOCK/
[unix-history] / usr / src / sys / ufs / ffs / inode.h
CommitLineData
dc9a2d80 1/* inode.h 4.18 82/10/31 */
d0064d3a
BJ
2
3/*
a59abf09
BJ
4 * The I node is the focus of all file activity in UNIX.
5 * There is a unique inode allocated for each active file,
6 * each current directory, each mounted-on file, text file, and the root.
7 * An inode is 'named' by its dev/inumber pair. (iget/iget.c)
ad30fb67 8 * Data in icommon is read in from permanent inode on volume.
d0064d3a 9 */
ad30fb67
KM
10
11#define NDADDR 8 /* direct addresses in inode */
12#define NIADDR 2 /* indirect addresses in inode */
d0064d3a 13
a59abf09 14struct inode {
69bd12a8 15 struct inode *i_chain[2]; /* must be first */
b0954044 16 u_short i_flag;
3e27ef55 17 u_short i_count; /* reference count */
d0064d3a 18 dev_t i_dev; /* device where inode resides */
b0954044
SL
19 u_short i_rdlockc; /* count of locked readers on inode */
20 u_short i_wrlockc; /* count of locked writers on inode */
d0064d3a 21 ino_t i_number; /* i number, 1-to-1 with device address */
ad30fb67 22 struct fs *i_fs; /* file sys associated with this inode */
3e27ef55 23 struct dquot *i_dquot; /* quota structure controlling this file */
d0064d3a 24 union {
ad30fb67
KM
25 daddr_t if_lastr; /* last read (read-ahead) */
26 struct socket *is_socket;
69bd12a8
RE
27 struct {
28 struct inode *if_freef; /* free list forward */
29 struct inode **if_freeb; /* free list back */
30 } i_fr;
d0064d3a 31 } i_un;
ad30fb67
KM
32 struct icommon
33 {
34 u_short ic_mode; /* 0: mode and type of file */
35 short ic_nlink; /* 2: number of links to file */
36 short ic_uid; /* 4: owner's user id */
37 short ic_gid; /* 6: owner's group id */
38 off_t ic_size; /* 8: number of bytes in file */
39 daddr_t ic_db[NDADDR]; /* 12: disk block addresses */
40 daddr_t ic_ib[NIADDR]; /* 44: indirect blocks */
41 time_t ic_atime; /* 52: time last accessed */
42 time_t ic_mtime; /* 56: time last modified */
43 time_t ic_ctime; /* 60: time created */
44 } i_ic;
d0064d3a
BJ
45};
46
ad30fb67
KM
47struct dinode {
48 union {
49 struct icommon di_icom;
50 char di_size[64];
51 } di_un;
52};
53
54#define i_mode i_ic.ic_mode
55#define i_nlink i_ic.ic_nlink
56#define i_uid i_ic.ic_uid
57#define i_gid i_ic.ic_gid
58#define i_size i_ic.ic_size
59#define i_db i_ic.ic_db
60#define i_ib i_ic.ic_ib
61#define i_atime i_ic.ic_atime
62#define i_mtime i_ic.ic_mtime
63#define i_ctime i_ic.ic_ctime
64#define i_rdev i_ic.ic_db[0]
65#define i_lastr i_un.if_lastr
66#define i_socket is_socket
69bd12a8
RE
67#define i_forw i_chain[0]
68#define i_back i_chain[1]
69#define i_freef i_un.i_fr.if_freef
70#define i_freeb i_un.i_fr.if_freeb
ad30fb67
KM
71
72#define di_ic di_un.di_icom
73#define di_mode di_ic.ic_mode
74#define di_nlink di_ic.ic_nlink
75#define di_uid di_ic.ic_uid
76#define di_gid di_ic.ic_gid
77#define di_size di_ic.ic_size
78#define di_db di_ic.ic_db
79#define di_ib di_ic.ic_ib
80#define di_atime di_ic.ic_atime
81#define di_mtime di_ic.ic_mtime
82#define di_ctime di_ic.ic_ctime
83#define di_rdev di_ic.ic_db[0]
84
d0064d3a 85#ifdef KERNEL
6e7edb25
BJ
86struct inode *inode; /* the inode table itself */
87struct inode *inodeNINODE; /* the end of the inode table */
88int ninode; /* number of slots in the table */
d0064d3a 89
ad30fb67 90struct inode *rootdir; /* pointer to inode of root directory */
d0064d3a
BJ
91
92struct inode *ialloc();
d0064d3a
BJ
93struct inode *iget();
94struct inode *owner();
95struct inode *maknode();
96struct inode *namei();
97#endif
98
99/* flags */
02dd5a44 100#define ILOCKED 0x1 /* inode is locked */
b0954044
SL
101#define IUPD 0x2 /* file has been modified */
102#define IACC 0x4 /* inode access time to be updated */
103#define IMOUNT 0x8 /* inode is mounted on */
104#define IWANT 0x10 /* some process waiting on lock */
105#define ITEXT 0x20 /* inode is pure text prototype */
106#define ICHG 0x40 /* inode has been changed */
107#define IRDLOCK 0x80 /* file is read locked */
108#define IWRLOCK 0x100 /* file is write locked */
109#define ILWAIT 0x200 /* someone waiting on file lock */
d0064d3a
BJ
110
111/* modes */
ad30fb67
KM
112#define IFMT 0170000 /* type of file */
113#define IFCHR 0020000 /* character special */
114#define IFDIR 0040000 /* directory */
115#define IFBLK 0060000 /* block special */
116#define IFREG 0100000 /* regular */
117#define IFLNK 0120000 /* symbolic link */
dc9a2d80
BJ
118#define IFSOCK 0140000 /* socket */
119
ad30fb67
KM
120#define ISUID 04000 /* set user id on execution */
121#define ISGID 02000 /* set group id on execution */
122#define ISVTX 01000 /* save swapped text even after use */
123#define IREAD 0400 /* read, write, execute permissions */
124#define IWRITE 0200
125#define IEXEC 0100
02dd5a44
BJ
126
127#define ILOCK(ip) { \
128 while ((ip)->i_flag & ILOCKED) { \
129 (ip)->i_flag |= IWANT; \
130 sleep((caddr_t)(ip), PINOD); \
131 } \
132 (ip)->i_flag |= ILOCKED; \
133}
134
135#define IUNLOCK(ip) { \
136 (ip)->i_flag &= ~ILOCKED; \
137 if ((ip)->i_flag&IWANT) { \
138 (ip)->i_flag &= ~IWANT; \
139 wakeup((caddr_t)(ip)); \
140 } \
141}
142
143#define IUPDAT(ip, t1, t2, waitfor) { \
144 if (ip->i_flag&(IUPD|IACC|ICHG)) \
145 iupdat(ip, t1, t2, waitfor); \
146}