debugging, print out inode lock owner and waiter
[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 *
30fd732d 17 * @(#)inode.h 7.8 (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) */
be213d5e 44 long i_diroff; /* offset in dir, where we found last entry */
6d0f0ece 45 off_t i_endoff; /* end of useful stuff in directory */
361968cf 46 long i_spare[5];
d0064d3a 47 union {
ad30fb67
KM
48 daddr_t if_lastr; /* last read (read-ahead) */
49 struct socket *is_socket;
d0064d3a 50 } i_un;
be213d5e 51 struct dinode i_din; /* the on-disk inode */
d0064d3a
BJ
52};
53
be213d5e
KM
54#define i_mode i_din.di_mode
55#define i_nlink i_din.di_nlink
56#define i_uid i_din.di_uid
57#define i_gid i_din.di_gid
961945a8 58/* ugh! -- must be fixed */
22a22bd0 59#if defined(vax) || defined(tahoe)
be213d5e 60#define i_size i_din.di_qsize.val[0]
961945a8 61#endif
be213d5e
KM
62#define i_db i_din.di_db
63#define i_ib i_din.di_ib
64#define i_atime i_din.di_atime
65#define i_mtime i_din.di_mtime
66#define i_ctime i_din.di_ctime
67#define i_blocks i_din.di_blocks
68#define i_rdev i_din.di_db[0]
69#define i_flags i_din.di_flags
70#define i_gen i_din.di_gen
ad30fb67 71#define i_lastr i_un.if_lastr
7ef603f5 72#define i_socket i_un.is_socket
69bd12a8
RE
73#define i_forw i_chain[0]
74#define i_back i_chain[1]
ad30fb67 75
d0064d3a 76/* flags */
02dd5a44 77#define ILOCKED 0x1 /* inode is locked */
b0954044
SL
78#define IUPD 0x2 /* file has been modified */
79#define IACC 0x4 /* inode access time to be updated */
6d0f0ece
KM
80#define IWANT 0x8 /* some process waiting on lock */
81#define ICHG 0x10 /* inode has been changed */
82#define ISHLOCK 0x20 /* file has shared lock */
83#define IEXLOCK 0x40 /* file has exclusive lock */
84#define ILWAIT 0x80 /* someone waiting on file lock */
85#define IMOD 0x100 /* inode has been modified */
86#define IRENAME 0x200 /* inode is being renamed */
d0064d3a 87
6d0f0ece
KM
88#ifdef KERNEL
89/*
90 * Convert between inode pointers and vnode pointers
91 */
92#define VTOI(vp) ((struct inode *)(vp)->v_data)
be213d5e 93#define ITOV(ip) ((ip)->i_vnode)
6d0f0ece
KM
94
95/*
96 * Convert between vnode types and inode formats
97 */
98extern enum vtype iftovt_tab[];
99extern int vttoif_tab[];
100#define IFTOVT(mode) (iftovt_tab[((mode) & IFMT) >> 13])
101#define VTTOIF(indx) (vttoif_tab[(int)(indx)])
102
103#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode))
104
361968cf
KM
105u_long nextgennumber; /* next generation number to assign */
106
107extern ino_t dirpref();
108
6d0f0ece
KM
109/*
110 * Lock and unlock inodes.
111 */
30fd732d 112#ifdef notdef
02dd5a44
BJ
113#define ILOCK(ip) { \
114 while ((ip)->i_flag & ILOCKED) { \
115 (ip)->i_flag |= IWANT; \
6d0f0ece 116 (void) sleep((caddr_t)(ip), PINOD); \
02dd5a44
BJ
117 } \
118 (ip)->i_flag |= ILOCKED; \
119}
120
121#define IUNLOCK(ip) { \
122 (ip)->i_flag &= ~ILOCKED; \
123 if ((ip)->i_flag&IWANT) { \
124 (ip)->i_flag &= ~IWANT; \
125 wakeup((caddr_t)(ip)); \
126 } \
127}
30fd732d
KM
128#else
129#define ILOCK(ip) ilock(ip)
130#define IUNLOCK(ip) iunlock(ip)
131#endif
02dd5a44
BJ
132
133#define IUPDAT(ip, t1, t2, waitfor) { \
232d0cb7 134 if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \
6d0f0ece 135 (void) iupdat(ip, t1, t2, waitfor); \
02dd5a44 136}
232d0cb7
MK
137
138#define ITIMES(ip, t1, t2) { \
139 if ((ip)->i_flag&(IUPD|IACC|ICHG)) { \
140 (ip)->i_flag |= IMOD; \
141 if ((ip)->i_flag&IACC) \
142 (ip)->i_atime = (t1)->tv_sec; \
143 if ((ip)->i_flag&IUPD) \
144 (ip)->i_mtime = (t2)->tv_sec; \
145 if ((ip)->i_flag&ICHG) \
146 (ip)->i_ctime = time.tv_sec; \
147 (ip)->i_flag &= ~(IACC|IUPD|ICHG); \
148 } \
149}
6d0f0ece
KM
150
151/*
152 * This overlays the fid sturcture (see mount.h)
153 */
154struct ufid {
be213d5e
KM
155 u_short ufid_len; /* length of structure */
156 u_short ufid_pad; /* force long alignment */
157 ino_t ufid_ino; /* file number (ino) */
158 long ufid_gen; /* generation number */
6d0f0ece
KM
159};
160#endif