split out that part of inode.h that is relevant only to the kernel incore info
[unix-history] / usr / src / sys / ufs / ffs / 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 *
be213d5e 17 * @(#)inode.h 7.6 (Berkeley) %G%
da7c5cc6 18 */
d0064d3a 19
be213d5e
KM
20#ifdef KERNEL
21#include "../ufs/dinode.h"
22#else
23#include <ufs/dinode.h>
24#endif
25
d0064d3a 26/*
a59abf09
BJ
27 * The I node is the focus of all file activity in UNIX.
28 * There is a unique inode allocated for each active file,
29 * each current directory, each mounted-on file, text file, and the root.
30 * An inode is 'named' by its dev/inumber pair. (iget/iget.c)
be213d5e 31 * Data in `struct dinode' is read in from permanent inode on volume.
d0064d3a 32 */
ad30fb67 33
a59abf09 34struct inode {
be213d5e
KM
35 struct inode *i_chain[2]; /* hash chain, MUST be first */
36 struct vnode *i_vnode; /* vnode associated with this inode */
6d0f0ece 37 struct vnode *i_devvp; /* vnode for block I/O */
be213d5e 38 u_short i_flag; /* see below */
d0064d3a
BJ
39 dev_t i_dev; /* device where inode resides */
40 ino_t i_number; /* i number, 1-to-1 with device address */
ad30fb67 41 struct fs *i_fs; /* file sys associated with this inode */
3e27ef55 42 struct dquot *i_dquot; /* quota structure controlling this file */
68dc14d7 43 struct text *i_text; /* text entry, if any (should be region) */
6d0f0ece 44 struct inode *i_devlst;/* list of block device inodes */
be213d5e 45 long i_diroff; /* offset in dir, where we found last entry */
6d0f0ece 46 off_t i_endoff; /* end of useful stuff in directory */
1806caca 47 long i_spare[4];
d0064d3a 48 union {
ad30fb67
KM
49 daddr_t if_lastr; /* last read (read-ahead) */
50 struct socket *is_socket;
d0064d3a 51 } i_un;
be213d5e 52 struct dinode i_din; /* the on-disk inode */
d0064d3a
BJ
53};
54
be213d5e
KM
55#define i_mode i_din.di_mode
56#define i_nlink i_din.di_nlink
57#define i_uid i_din.di_uid
58#define i_gid i_din.di_gid
961945a8 59/* ugh! -- must be fixed */
22a22bd0 60#if defined(vax) || defined(tahoe)
be213d5e 61#define i_size i_din.di_qsize.val[0]
961945a8 62#endif
be213d5e
KM
63#define i_db i_din.di_db
64#define i_ib i_din.di_ib
65#define i_atime i_din.di_atime
66#define i_mtime i_din.di_mtime
67#define i_ctime i_din.di_ctime
68#define i_blocks i_din.di_blocks
69#define i_rdev i_din.di_db[0]
70#define i_flags i_din.di_flags
71#define i_gen i_din.di_gen
ad30fb67 72#define i_lastr i_un.if_lastr
7ef603f5 73#define i_socket i_un.is_socket
69bd12a8
RE
74#define i_forw i_chain[0]
75#define i_back i_chain[1]
ad30fb67 76
d0064d3a 77#ifdef KERNEL
f96164be
KM
78u_long nextgennumber; /* next generation number to assign */
79
6d0f0ece
KM
80extern struct vnodeops ufs_vnodeops; /* vnode operations for ufs */
81extern struct vnodeops blk_vnodeops; /* vnode operations for blk devices */
af0b24db 82
6d0f0ece 83extern ino_t dirpref();
d0064d3a
BJ
84#endif
85
86/* flags */
02dd5a44 87#define ILOCKED 0x1 /* inode is locked */
b0954044
SL
88#define IUPD 0x2 /* file has been modified */
89#define IACC 0x4 /* inode access time to be updated */
6d0f0ece
KM
90#define IWANT 0x8 /* some process waiting on lock */
91#define ICHG 0x10 /* inode has been changed */
92#define ISHLOCK 0x20 /* file has shared lock */
93#define IEXLOCK 0x40 /* file has exclusive lock */
94#define ILWAIT 0x80 /* someone waiting on file lock */
95#define IMOD 0x100 /* inode has been modified */
96#define IRENAME 0x200 /* inode is being renamed */
d0064d3a 97
6d0f0ece
KM
98#ifdef KERNEL
99/*
100 * Convert between inode pointers and vnode pointers
101 */
102#define VTOI(vp) ((struct inode *)(vp)->v_data)
be213d5e 103#define ITOV(ip) ((ip)->i_vnode)
6d0f0ece
KM
104
105/*
106 * Convert between vnode types and inode formats
107 */
108extern enum vtype iftovt_tab[];
109extern int vttoif_tab[];
110#define IFTOVT(mode) (iftovt_tab[((mode) & IFMT) >> 13])
111#define VTTOIF(indx) (vttoif_tab[(int)(indx)])
112
113#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode))
114
115/*
116 * Lock and unlock inodes.
117 */
02dd5a44
BJ
118#define ILOCK(ip) { \
119 while ((ip)->i_flag & ILOCKED) { \
120 (ip)->i_flag |= IWANT; \
6d0f0ece 121 (void) sleep((caddr_t)(ip), PINOD); \
02dd5a44
BJ
122 } \
123 (ip)->i_flag |= ILOCKED; \
124}
125
126#define IUNLOCK(ip) { \
127 (ip)->i_flag &= ~ILOCKED; \
128 if ((ip)->i_flag&IWANT) { \
129 (ip)->i_flag &= ~IWANT; \
130 wakeup((caddr_t)(ip)); \
131 } \
132}
133
134#define IUPDAT(ip, t1, t2, waitfor) { \
232d0cb7 135 if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
6d0f0ece 136 (void) iupdat(ip, t1, t2, waitfor); \
02dd5a44 137}
232d0cb7
MK
138
139#define ITIMES(ip, t1, t2) { \
140 if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
141 (ip)->i_flag |= IMOD; \
142 if ((ip)->i_flag&IACC) \
143 (ip)->i_atime = (t1)->tv_sec; \
144 if ((ip)->i_flag&IUPD) \
145 (ip)->i_mtime = (t2)->tv_sec; \
146 if ((ip)->i_flag&ICHG) \
147 (ip)->i_ctime = time.tv_sec; \
148 (ip)->i_flag &= ~(IACC|IUPD|ICHG); \
149 } \
150}
6d0f0ece
KM
151
152/*
153 * This overlays the fid sturcture (see mount.h)
154 */
155struct ufid {
be213d5e
KM
156 u_short ufid_len; /* length of structure */
157 u_short ufid_pad; /* force long alignment */
158 ino_t ufid_ino; /* file number (ino) */
159 long ufid_gen; /* generation number */
6d0f0ece
KM
160};
161#endif