reorganization to move ufsmount ops to be vnode ops;
[unix-history] / usr / src / sys / ufs / ffs / inode.h
... / ...
CommitLineData
1/*
2 * Copyright (c) 1982, 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 *
7 * @(#)inode.h 7.18 (Berkeley) %G%
8 */
9
10#include <ufs/ufs/dinode.h>
11
12/*
13 * The inode is used to describe each active (or recently active)
14 * file in the UFS filesystem. It is composed of two types of
15 * information. The first part is the information that is needed
16 * only while the file is active (such as the identity of the file
17 * and linkage to speed its lookup). The second part is the
18 * permannent meta-data associated with the file which is read
19 * in from the permanent dinode from long term storage when the
20 * file becomes active, and is put back when the file is no longer
21 * being used.
22 */
23struct inode {
24 struct inode *i_chain[2]; /* hash chain, MUST be first */
25 struct vnode *i_vnode; /* vnode associated with this inode */
26 struct vnode *i_devvp; /* vnode for block I/O */
27 u_long i_flag; /* see below */
28 dev_t i_dev; /* device where inode resides */
29 ino_t i_number; /* the identity of the inode */
30 union { /* associated filesystem */
31 struct fs *fs; /* FFS */
32 struct lfs *lfs; /* LFS */
33 } inode_u;
34#define i_fs inode_u.fs
35#define i_lfs inode_u.lfs
36 struct dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */
37 struct lockf *i_lockf; /* head of byte-level lock list */
38 long i_diroff; /* offset in dir, where we found last entry */
39 off_t i_endoff; /* end of useful stuff in directory */
40 long i_spare0;
41 long i_spare1;
42 struct dinode i_din; /* the on-disk dinode */
43};
44
45#define i_mode i_din.di_mode
46#define i_nlink i_din.di_nlink
47#define i_uid i_din.di_uid
48#define i_gid i_din.di_gid
49#if BYTE_ORDER == LITTLE_ENDIAN || defined(tahoe) /* ugh! -- must be fixed */
50#define i_size i_din.di_qsize.val[0]
51#else /* BYTE_ORDER == BIG_ENDIAN */
52#define i_size i_din.di_qsize.val[1]
53#endif
54#define i_db i_din.di_db
55#define i_ib i_din.di_ib
56#define i_atime i_din.di_atime
57#define i_mtime i_din.di_mtime
58#define i_ctime i_din.di_ctime
59#define i_blocks i_din.di_blocks
60#define i_rdev i_din.di_db[0]
61#define i_flags i_din.di_flags
62#define i_gen i_din.di_gen
63#define i_forw i_chain[0]
64#define i_back i_chain[1]
65
66/* flags */
67#define ILOCKED 0x0001 /* inode is locked */
68#define IWANT 0x0002 /* some process waiting on lock */
69#define IRENAME 0x0004 /* inode is being renamed */
70#define IUPD 0x0010 /* file has been modified */
71#define IACC 0x0020 /* inode access time to be updated */
72#define ICHG 0x0040 /* inode has been changed */
73#define IMOD 0x0080 /* inode has been modified */
74#define ISHLOCK 0x0100 /* file has shared lock */
75#define IEXLOCK 0x0200 /* file has exclusive lock */
76#define ILWAIT 0x0400 /* someone waiting on file lock */
77
78#ifdef KERNEL
79/* Convert between inode pointers and vnode pointers. */
80#define VTOI(vp) ((struct inode *)(vp)->v_data)
81#define ITOV(ip) ((ip)->i_vnode)
82
83/* Convert between vnode types and inode formats. */
84extern enum vtype iftovt_tab[];
85extern int vttoif_tab[];
86#define IFTOVT(mode) (iftovt_tab[((mode) & IFMT) >> 12])
87#define VTTOIF(indx) (vttoif_tab[(int)(indx)])
88
89#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode))
90
91/* Lock and unlock inodes. */
92#ifdef notdef
93#define ILOCK(ip) { \
94 while ((ip)->i_flag & ILOCKED) { \
95 (ip)->i_flag |= IWANT; \
96 (void) sleep((caddr_t)(ip), PINOD); \
97 } \
98 (ip)->i_flag |= ILOCKED; \
99}
100
101#define IUNLOCK(ip) { \
102 (ip)->i_flag &= ~ILOCKED; \
103 if ((ip)->i_flag&IWANT) { \
104 (ip)->i_flag &= ~IWANT; \
105 wakeup((caddr_t)(ip)); \
106 } \
107}
108#else
109#define ILOCK(ip) ufs_ilock(ip)
110#define IUNLOCK(ip) ufs_iunlock(ip)
111#endif
112
113#define ITIMES(ip, t1, t2) { \
114 if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
115 (ip)->i_flag |= IMOD; \
116 if ((ip)->i_flag&IACC) \
117 (ip)->i_atime = (t1)->tv_sec; \
118 if ((ip)->i_flag&IUPD) \
119 (ip)->i_mtime = (t2)->tv_sec; \
120 if ((ip)->i_flag&ICHG) \
121 (ip)->i_ctime = time.tv_sec; \
122 (ip)->i_flag &= ~(IACC|IUPD|ICHG); \
123 } \
124}
125
126/* This overlays the fid structure (see mount.h). */
127struct ufid {
128 u_short ufid_len; /* length of structure */
129 u_short ufid_pad; /* force long alignment */
130 ino_t ufid_ino; /* file number (ino) */
131 long ufid_gen; /* generation number */
132};
133#endif /* KERNEL */