Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / platform / pc32 / boot / dosboot / inode.h
1 /*\r
2  * Copyright (c) 1982, 1989 The Regents of the University of California.\r
3  * All rights reserved.\r
4  *\r
5  * Redistribution and use in source and binary forms, with or without\r
6  * modification, are permitted provided that the following conditions\r
7  * are met:\r
8  * 1. Redistributions of source code must retain the above copyright\r
9  *    notice, this list of conditions and the following disclaimer.\r
10  * 2. Redistributions in binary form must reproduce the above copyright\r
11  *    notice, this list of conditions and the following disclaimer in the\r
12  *    documentation and/or other materials provided with the distribution.\r
13  * 3. All advertising materials mentioning features or use of this software\r
14  *    must display the following acknowledgement:\r
15  *      This product includes software developed by the University of\r
16  *      California, Berkeley and its contributors.\r
17  * 4. Neither the name of the University nor the names of its contributors\r
18  *    may be used to endorse or promote products derived from this software\r
19  *    without specific prior written permission.\r
20  *\r
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
31  * SUCH DAMAGE.\r
32  *\r
33  *      from: @(#)inode.h       7.17 (Berkeley) 5/8/91\r
34  * $FreeBSD: src/sys/i386/boot/dosboot/inode.h,v 1.7 1999/12/29 04:32:51 peter Exp $\r
35  */\r
36 \r
37 #ifndef _UFS_INODE_H_\r
38 #define _UFS_INODE_H_ 1\r
39 \r
40 #ifdef KERNEL\r
41 include "../ufs/dinode.h"\r
42 #else\r
43 #include "dinode.h"\r
44 #endif\r
45 \r
46 /*\r
47  * The inode is used to describe each active (or recently active)\r
48  * file in the UFS filesystem. It is composed of two types of\r
49  * information. The first part is the information that is needed\r
50  * only while the file is active (such as the identity of the file\r
51  * and linkage to speed its lookup). The second part is the \r
52  * permannent meta-data associated with the file which is read\r
53  * in from the permanent dinode from long term storage when the\r
54  * file becomes active, and is put back when the file is no longer\r
55  * being used.\r
56  */\r
57 struct inode {\r
58         struct  inode *i_chain[2]; /* hash chain, MUST be first */\r
59         struct  vnode *i_vnode; /* vnode associated with this inode */\r
60         struct  vnode *i_devvp; /* vnode for block I/O */\r
61         u_long  i_flag;         /* see below */\r
62         dev_t   i_dev;          /* device where inode resides */\r
63         ino_t   i_number;       /* the identity of the inode */\r
64         struct  fs *i_fs;       /* filesystem associated with this inode */\r
65         struct  dquot *i_dquot[MAXQUOTAS]; /* pointer to dquot structures */\r
66         struct  lockf *i_lockf; /* head of byte-level lock list */\r
67         long    i_diroff;       /* offset in dir, where we found last entry */\r
68         off_t   i_endoff;       /* end of useful stuff in directory */\r
69         long    i_spare0;\r
70         long    i_spare1;\r
71         struct  dinode i_din;   /* the on-disk dinode */\r
72 };\r
73 \r
74 #define FASTLINK(ip)    (DFASTLINK((ip)->i_din))\r
75 #define i_symlink       i_din.di_symlink\r
76 #define i_mode          i_din.di_mode\r
77 #define i_nlink         i_din.di_nlink\r
78 #define i_uid           i_din.di_uid\r
79 #define i_gid           i_din.di_gid\r
80 #if BYTE_ORDER == LITTLE_ENDIAN || defined(tahoe) /* ugh! -- must be fixed */\r
81 #define i_size          i_din.di_qsize.val[0]\r
82 #else /* BYTE_ORDER == BIG_ENDIAN */\r
83 #define i_size          i_din.di_qsize.val[1]\r
84 #endif\r
85 #define i_db            i_din.di_db\r
86 #define i_ib            i_din.di_ib\r
87 #define i_atime         i_din.di_atime\r
88 #define i_mtime         i_din.di_mtime\r
89 #define i_ctime         i_din.di_ctime\r
90 #define i_blocks        i_din.di_blocks\r
91 #define i_rdev          i_din.di_db[0]\r
92 #define i_flags         i_din.di_flags\r
93 #define i_gen           i_din.di_gen\r
94 #define i_forw          i_chain[0]\r
95 #define i_back          i_chain[1]\r
96 #define i_di_spare      i_din.di_spare\r
97 \r
98 /* flags */\r
99 #define ILOCKED         0x0001          /* inode is locked */\r
100 #define IWANT           0x0002          /* some process waiting on lock */\r
101 #define IRENAME         0x0004          /* inode is being renamed */\r
102 #define IUPD            0x0010          /* file has been modified */\r
103 #define IACC            0x0020          /* inode access time to be updated */\r
104 #define ICHG            0x0040          /* inode has been changed */\r
105 #define IMOD            0x0080          /* inode has been modified */\r
106 #define ISHLOCK         0x0100          /* file has shared lock */\r
107 #define IEXLOCK         0x0200          /* file has exclusive lock */\r
108 #define ILWAIT          0x0400          /* someone waiting on file lock */\r
109 \r
110 #ifdef KERNEL\r
111 /*\r
112  * Convert between inode pointers and vnode pointers\r
113  */\r
114 #define VTOI(vp)        ((struct inode *)(vp)->v_data)\r
115 #define ITOV(ip)        ((ip)->i_vnode)\r
116 \r
117 /*\r
118  * Convert between vnode types and inode formats\r
119  */\r
120 extern enum vtype       iftovt_tab[];\r
121 extern int              vttoif_tab[];\r
122 #define IFTOVT(mode)    (iftovt_tab[((mode) & IFMT) >> 12])\r
123 #define VTTOIF(indx)    (vttoif_tab[(int)(indx)])\r
124 \r
125 #define MAKEIMODE(indx, mode)   (int)(VTTOIF(indx) | (mode))\r
126 \r
127 extern u_long   nextgennumber;  /* next generation number to assign */\r
128 \r
129 extern ino_t    dirpref();\r
130 \r
131 /*\r
132  * Lock and unlock inodes.\r
133  */\r
134 #ifdef notdef\r
135 #define ILOCK(ip) { \\r
136         while ((ip)->i_flag & ILOCKED) { \\r
137                 (ip)->i_flag |= IWANT; \\r
138                 (void) sleep((caddr_t)(ip), PINOD); \\r
139         } \\r
140         (ip)->i_flag |= ILOCKED; \\r
141 }\r
142 \r
143 #define IUNLOCK(ip) { \\r
144         (ip)->i_flag &= ~ILOCKED; \\r
145         if ((ip)->i_flag&IWANT) { \\r
146                 (ip)->i_flag &= ~IWANT; \\r
147                 wakeup((caddr_t)(ip)); \\r
148         } \\r
149 }\r
150 #else\r
151 #define ILOCK(ip)       ilock(ip)\r
152 #define IUNLOCK(ip)     iunlock(ip)\r
153 #endif\r
154 \r
155 #define IUPDAT(ip, t1, t2, waitfor) { \\r
156         if (ip->i_flag&(IUPD|IACC|ICHG|IMOD)) \\r
157                 (void) iupdat(ip, t1, t2, waitfor); \\r
158 }\r
159 \r
160 /*\r
161  * This overlays the fid sturcture (see mount.h)\r
162  */\r
163 struct ufid {\r
164         u_short ufid_len;       /* length of structure */\r
165         u_short ufid_pad;       /* force long alignment */\r
166         ino_t   ufid_ino;       /* file number (ino) */\r
167         long    ufid_gen;       /* generation number */\r
168 };\r
169 \r
170 /*\r
171  * Prototypes for UFS vnode operations\r
172  */\r
173 int ufs_lookup __P((struct vnode *vp, struct nameidata *ndp, struct proc *p));\r
174 int ufs_create __P((struct nameidata *ndp, struct vattr *vap, struct proc *p));\r
175 int ufs_mknod __P((struct nameidata *ndp, struct vattr *vap, struct ucred *cred,\r
176         struct proc *p));\r
177 int ufs_open __P((struct vnode *vp, int mode, struct ucred *cred,\r
178         struct proc *p));\r
179 int ufs_close __P((struct vnode *vp, int fflag, struct ucred *cred,\r
180         struct proc *p));\r
181 int ufs_access __P((struct vnode *vp, int mode, struct ucred *cred,\r
182         struct proc *p));\r
183 int ufs_getattr __P((struct vnode *vp, struct vattr *vap, struct ucred *cred,\r
184         struct proc *p));\r
185 int ufs_setattr __P((struct vnode *vp, struct vattr *vap, struct ucred *cred,\r
186         struct proc *p));\r
187 int ufs_read __P((struct vnode *vp, struct uio *uio, int ioflag,\r
188         struct ucred *cred));\r
189 int ufs_write __P((struct vnode *vp, struct uio *uio, int ioflag,\r
190         struct ucred *cred));\r
191 int ufs_ioctl __P((struct vnode *vp, int command, caddr_t data, int fflag,\r
192         struct ucred *cred, struct proc *p));\r
193 int ufs_select __P((struct vnode *vp, int which, int fflags, struct ucred *cred,\r
194         struct proc *p));\r
195 int ufs_mmap __P((struct vnode *vp, int fflags, struct ucred *cred,\r
196         struct proc *p));\r
197 int ufs_fsync __P((struct vnode *vp, int fflags, struct ucred *cred,\r
198         int waitfor, struct proc *p));\r
199 int ufs_seek __P((struct vnode *vp, off_t oldoff, off_t newoff,\r
200         struct ucred *cred));\r
201 int ufs_remove __P((struct nameidata *ndp, struct proc *p));\r
202 int ufs_link __P((struct vnode *vp, struct nameidata *ndp, struct proc *p));\r
203 int ufs_rename __P((struct nameidata *fndp, struct nameidata *tdnp,\r
204         struct proc *p));\r
205 int ufs_mkdir __P((struct nameidata *ndp, struct vattr *vap, struct proc *p));\r
206 int ufs_rmdir __P((struct nameidata *ndp, struct proc *p));\r
207 int ufs_symlink __P((struct nameidata *ndp, struct vattr *vap, char *target,\r
208         struct proc *p));\r
209 int ufs_readdir __P((struct vnode *vp, struct uio *uio, struct ucred *cred,\r
210         int *eofflagp));\r
211 int ufs_readlink __P((struct vnode *vp, struct uio *uio, struct ucred *cred));\r
212 int ufs_abortop __P((struct nameidata *ndp));\r
213 int ufs_inactive __P((struct vnode *vp, struct proc *p));\r
214 int ufs_reclaim __P((struct vnode *vp));\r
215 int ufs_lock __P((struct vnode *vp));\r
216 int ufs_unlock __P((struct vnode *vp));\r
217 int ufs_bmap __P((struct vnode *vp, daddr_t bn, struct vnode **vpp,\r
218         daddr_t *bnp));\r
219 int ufs_strategy __P((struct buf *bp));\r
220 void ufs_print __P((struct vnode *vp));\r
221 int ufs_islocked __P((struct vnode *vp));\r
222 int ufs_advlock __P((struct vnode *vp, caddr_t id, int op, struct flock *fl,\r
223         int flags));\r
224 \r
225 extern void blkfree(struct inode *, daddr_t, off_t);\r
226 extern void ifree(struct inode *, ino_t, int);\r
227 extern void iput(struct inode *);\r
228 extern void ilock(struct inode *);\r
229 extern void iunlock(struct inode *);\r
230 extern void dirbad(struct inode *, off_t, char *);\r
231 \r
232 extern int alloc(struct inode *, daddr_t, daddr_t, int, daddr_t *);\r
233 extern int realloccg(struct inode *, off_t, daddr_t, int, int, struct buf **);\r
234 extern int ialloc(struct inode *, ino_t, int, struct ucred *, struct inode **);\r
235 extern daddr_t blkpref(struct inode *, daddr_t, int, daddr_t *);\r
236 extern u_long hashalloc(struct inode *, int, long, int, \r
237                         u_long (*)(struct inode *, int, long, int));\r
238 extern daddr_t fragextend(struct inode *, int, long, int, int);\r
239 extern daddr_t alloccg(struct inode *, int, daddr_t, int);\r
240 \r
241 struct cg;                      /* I really don't want to know why */\r
242 struct direct;                  /* this header is required by NFS... */\r
243 \r
244 extern daddr_t alloccgblk(struct fs *, struct cg *, daddr_t);\r
245 extern ino_t ialloccg(struct inode *, int, daddr_t, int);\r
246 extern int ufs_lookup(struct vnode *, struct nameidata *, struct proc *);\r
247 extern int dirbadentry(struct direct *, int);\r
248 extern int direnter(struct inode *, struct nameidata *);\r
249 extern int dirremove(struct nameidata *);\r
250 extern int dirrewrite(struct inode *, struct inode *, struct nameidata *);\r
251 extern int blkatoff(struct inode *, off_t, char **, struct buf **);\r
252 extern int dirempty(struct inode *, ino_t, struct ucred *);\r
253 extern int checkpath(struct inode *, struct inode *, struct ucred *);\r
254 \r
255 extern void ufs_init(void);\r
256 extern int iget(struct inode *, ino_t, struct inode **);\r
257 extern int ufs_inactive(struct vnode *, struct proc *);\r
258 extern int ufs_reclaim(struct vnode *);\r
259 extern int iupdat(struct inode *, struct timeval *, struct timeval *,\r
260                   int);\r
261 extern int itrunc(struct inode *, u_long, int);\r
262 extern int indirtrunc(struct inode *, daddr_t, daddr_t, int, long *);\r
263 \r
264 extern int bmap(struct inode *, daddr_t, daddr_t *);\r
265 extern int balloc(struct inode *, daddr_t, int, struct buf **, int);\r
266 \r
267 #endif /* _KERNEL */\r
268 #endif /* _UFS_INODE_H_ */\r