reorganization to move ufsmount ops to be vnode ops;
[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 *
beeb3369 5 * %sccs.include.redist.c%
6d0f0ece 6 *
9abdb11d 7 * @(#)inode.h 7.18 (Berkeley) %G%
da7c5cc6 8 */
d0064d3a 9
9abdb11d 10#include <ufs/ufs/dinode.h>
be213d5e 11
d0064d3a 12/*
409536a4
KM
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.
d0064d3a 22 */
a59abf09 23struct inode {
be213d5e
KM
24 struct inode *i_chain[2]; /* hash chain, MUST be first */
25 struct vnode *i_vnode; /* vnode associated with this inode */
6d0f0ece 26 struct vnode *i_devvp; /* vnode for block I/O */
0997b03c 27 u_long i_flag; /* see below */
d0064d3a 28 dev_t i_dev; /* device where inode resides */
409536a4 29 ino_t i_number; /* the identity of the inode */
9abdb11d
KB
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
8923104b 36 struct dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */
409536a4 37 struct lockf *i_lockf; /* head of byte-level lock list */
be213d5e 38 long i_diroff; /* offset in dir, where we found last entry */
6d0f0ece 39 off_t i_endoff; /* end of useful stuff in directory */
0997b03c
KM
40 long i_spare0;
41 long i_spare1;
409536a4 42 struct dinode i_din; /* the on-disk dinode */
d0064d3a
BJ
43};
44
be213d5e
KM
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
beeb3369 49#if BYTE_ORDER == LITTLE_ENDIAN || defined(tahoe) /* ugh! -- must be fixed */
be213d5e 50#define i_size i_din.di_qsize.val[0]
beeb3369
KM
51#else /* BYTE_ORDER == BIG_ENDIAN */
52#define i_size i_din.di_qsize.val[1]
961945a8 53#endif
be213d5e
KM
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
69bd12a8
RE
63#define i_forw i_chain[0]
64#define i_back i_chain[1]
ad30fb67 65
d0064d3a 66/* flags */
771f4649
KM
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 */
d0064d3a 77
6d0f0ece 78#ifdef KERNEL
9abdb11d 79/* Convert between inode pointers and vnode pointers. */
6d0f0ece 80#define VTOI(vp) ((struct inode *)(vp)->v_data)
be213d5e 81#define ITOV(ip) ((ip)->i_vnode)
6d0f0ece 82
9abdb11d 83/* Convert between vnode types and inode formats. */
6d0f0ece
KM
84extern enum vtype iftovt_tab[];
85extern int vttoif_tab[];
45b72508 86#define IFTOVT(mode) (iftovt_tab[((mode) & IFMT) >> 12])
6d0f0ece
KM
87#define VTTOIF(indx) (vttoif_tab[(int)(indx)])
88
89#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode))
90
9abdb11d 91/* Lock and unlock inodes. */
30fd732d 92#ifdef notdef
02dd5a44
BJ
93#define ILOCK(ip) { \
94 while ((ip)->i_flag & ILOCKED) { \
95 (ip)->i_flag |= IWANT; \
6d0f0ece 96 (void) sleep((caddr_t)(ip), PINOD); \
02dd5a44
BJ
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}
30fd732d 108#else
9abdb11d
KB
109#define ILOCK(ip) ufs_ilock(ip)
110#define IUNLOCK(ip) ufs_iunlock(ip)
30fd732d 111#endif
02dd5a44 112
232d0cb7
MK
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}
6d0f0ece 125
9abdb11d 126/* This overlays the fid structure (see mount.h). */
6d0f0ece 127struct ufid {
be213d5e
KM
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 */
6d0f0ece 132};
f1d03a87 133#endif /* KERNEL */