inode.h revision 30513
1201360Srdivacky/* 2201360Srdivacky * Copyright (c) 1982, 1989, 1993 3201360Srdivacky * The Regents of the University of California. All rights reserved. 4201360Srdivacky * (c) UNIX System Laboratories, Inc. 5201360Srdivacky * All or some portions of this file are derived from material licensed 6201360Srdivacky * to the University of California by American Telephone and Telegraph 7201360Srdivacky * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8201360Srdivacky * the permission of UNIX System Laboratories, Inc. 9201360Srdivacky * 10201360Srdivacky * Redistribution and use in source and binary forms, with or without 11201360Srdivacky * modification, are permitted provided that the following conditions 12201360Srdivacky * are met: 13201360Srdivacky * 1. Redistributions of source code must retain the above copyright 14201360Srdivacky * notice, this list of conditions and the following disclaimer. 15201360Srdivacky * 2. Redistributions in binary form must reproduce the above copyright 16249423Sdim * notice, this list of conditions and the following disclaimer in the 17249423Sdim * documentation and/or other materials provided with the distribution. 18201360Srdivacky * 3. All advertising materials mentioning features or use of this software 19201360Srdivacky * must display the following acknowledgement: 20234982Sdim * This product includes software developed by the University of 21226584Sdim * California, Berkeley and its contributors. 22201360Srdivacky * 4. Neither the name of the University nor the names of its contributors 23201360Srdivacky * may be used to endorse or promote products derived from this software 24226584Sdim * without specific prior written permission. 25226584Sdim * 26201360Srdivacky * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27234982Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28201360Srdivacky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29201360Srdivacky * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30201360Srdivacky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31201360Srdivacky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32201360Srdivacky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33201360Srdivacky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34201360Srdivacky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35201360Srdivacky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36201360Srdivacky * SUCH DAMAGE. 37201360Srdivacky * 38223013Sdim * @(#)inode.h 8.9 (Berkeley) 5/14/95 39201360Srdivacky * $Id: inode.h,v 1.17 1997/10/14 18:46:45 phk Exp $ 40201360Srdivacky */ 41201360Srdivacky 42201360Srdivacky#ifndef _UFS_UFS_INODE_H_ 43218885Sdim#define _UFS_UFS_INODE_H_ 44201360Srdivacky 45201360Srdivacky#include <ufs/ufs/dinode.h> 46201360Srdivacky 47201360Srdivacky/* 48201360Srdivacky * This must agree with the definition in <ufs/ufs/dir.h>. 49201360Srdivacky */ 50201360Srdivacky#define doff_t int32_t 51205407Srdivacky 52234982Sdim/* 53234982Sdim * The inode is used to describe each active (or recently active) file in the 54234982Sdim * UFS filesystem. It is composed of two types of information. The first part 55201360Srdivacky * is the information that is needed only while the file is active (such as 56201360Srdivacky * the identity of the file and linkage to speed its lookup). The second part 57223013Sdim * is the permanent meta-data associated with the file which is read in 58203954Srdivacky * from the permanent dinode from long term storage when the file becomes 59201360Srdivacky * active, and is put back when the file is no longer being used. 60203954Srdivacky */ 61223013Sdimstruct inode { 62203954Srdivacky struct lock i_lock; /* Inode lock. >Keep this first< */ 63203954Srdivacky LIST_ENTRY(inode) i_hash;/* Hash chain. */ 64223013Sdim struct vnode *i_vnode;/* Vnode associated with this inode. */ 65226584Sdim struct vnode *i_devvp;/* Vnode for block I/O. */ 66226584Sdim u_int32_t i_flag; /* flags, see below */ 67226584Sdim dev_t i_dev; /* Device associated with the inode. */ 68226584Sdim ino_t i_number; /* The identity of the inode. */ 69226584Sdim 70203954Srdivacky union { /* Associated filesystem. */ 71234353Sdim struct fs *fs; /* FFS */ 72234353Sdim struct lfs *lfs; /* LFS */ 73203954Srdivacky struct ext2_sb_info *e2fs; /* EXT2FS */ 74203954Srdivacky } inode_u; 75226584Sdim#define i_fs inode_u.fs 76226584Sdim#define i_lfs inode_u.lfs 77226584Sdim#define i_e2fs inode_u.e2fs 78226584Sdim struct dquot *i_dquot[MAXQUOTAS]; /* Dquot structures. */ 79234353Sdim u_quad_t i_modrev; /* Revision level for NFS lease. */ 80234353Sdim struct lockf *i_lockf;/* Head of byte-level lock list. */ 81226584Sdim /* 82226584Sdim * Side effects; used during directory lookup. 83226584Sdim */ 84234982Sdim int32_t i_count; /* Size of free slot in directory. */ 85226584Sdim doff_t i_endoff; /* End of useful stuff in directory. */ 86203954Srdivacky doff_t i_diroff; /* Offset in dir, where we found last entry. */ 87201360Srdivacky doff_t i_offset; /* Offset of free space in directory. */ 88223013Sdim ino_t i_ino; /* Inode number of found directory. */ 89201360Srdivacky u_int32_t i_reclen; /* Size of found directory entry. */ 90201360Srdivacky int i_spare[5]; /* XXX actually non-spare (for ext2fs). */ 91201360Srdivacky /* 92223013Sdim * The on-disk dinode itself. 93223013Sdim */ 94207618Srdivacky struct dinode i_din; /* 128 bytes of the on-disk dinode. */ 95201360Srdivacky}; 96201360Srdivacky 97201360Srdivacky#define i_atime i_din.di_atime 98201360Srdivacky#define i_atimensec i_din.di_atimensec 99201360Srdivacky#define i_blocks i_din.di_blocks 100201360Srdivacky#define i_ctime i_din.di_ctime 101223013Sdim#define i_ctimensec i_din.di_ctimensec 102203954Srdivacky#define i_db i_din.di_db 103203954Srdivacky#define i_flags i_din.di_flags 104201360Srdivacky#define i_gen i_din.di_gen 105201360Srdivacky#define i_gid i_din.di_gid 106201360Srdivacky#define i_ib i_din.di_ib 107207618Srdivacky#define i_mode i_din.di_mode 108201360Srdivacky#define i_mtime i_din.di_mtime 109207618Srdivacky#define i_mtimensec i_din.di_mtimensec 110201360Srdivacky#define i_nlink i_din.di_nlink 111201360Srdivacky#define i_rdev i_din.di_rdev 112201360Srdivacky#define i_shortlink i_din.di_shortlink 113201360Srdivacky#define i_size i_din.di_size 114201360Srdivacky#define i_uid i_din.di_uid 115201360Srdivacky 116223013Sdim/* These flags are kept in i_flag. */ 117201360Srdivacky#define IN_ACCESS 0x0001 /* Access time update request. */ 118201360Srdivacky#define IN_CHANGE 0x0002 /* Inode change time update request. */ 119201360Srdivacky#define IN_UPDATE 0x0004 /* Modification time update request. */ 120223013Sdim#define IN_MODIFIED 0x0008 /* Inode has been modified. */ 121201360Srdivacky#define IN_RENAME 0x0010 /* Inode is being renamed. */ 122201360Srdivacky#define IN_SHLOCK 0x0020 /* File has shared lock. */ 123201360Srdivacky#define IN_EXLOCK 0x0040 /* File has exclusive lock. */ 124201360Srdivacky#define IN_HASHED 0x0080 /* Inode is on hash list */ 125234353Sdim 126234353Sdim#ifdef KERNEL 127201360Srdivacky/* 128201360Srdivacky * Structure used to pass around logical block paths generated by 129201360Srdivacky * ufs_getlbns and used by truncate and bmap code. 130201360Srdivacky */ 131223013Sdimstruct indir { 132201360Srdivacky ufs_daddr_t in_lbn; /* Logical block number. */ 133201360Srdivacky int in_off; /* Offset in buffer. */ 134201360Srdivacky int in_exists; /* Flag if the block exists. */ 135223013Sdim}; 136207618Srdivacky 137207618Srdivacky/* Convert between inode pointers and vnode pointers. */ 138207618Srdivacky#define VTOI(vp) ((struct inode *)(vp)->v_data) 139224133Sdim#define ITOV(ip) ((ip)->i_vnode) 140221337Sdim 141234982Sdim/* 142234982Sdim * XXX this is too long to be a macro, and isn't used in any time-critical 143212793Sdim * place; in fact it is only used in ufs_vnops.c so it shouldn't be in a 144234982Sdim * header file. 145212793Sdim */ 146234982Sdim#define ITIMES(ip, t1, t2) { \ 147207618Srdivacky long tv_sec = time.tv_sec; \ 148207618Srdivacky if ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) { \ 149207618Srdivacky (ip)->i_flag |= IN_MODIFIED; \ 150207618Srdivacky if ((ip)->i_flag & IN_ACCESS) \ 151223013Sdim (ip)->i_atime \ 152234982Sdim = ((t1) == &time ? tv_sec : (t1)->tv_sec); \ 153234982Sdim if ((ip)->i_flag & IN_UPDATE) { \ 154234353Sdim (ip)->i_mtime \ 155207618Srdivacky = ((t2) == &time ? tv_sec : (t2)->tv_sec); \ 156223013Sdim (ip)->i_modrev++; \ 157207618Srdivacky } \ 158207618Srdivacky if ((ip)->i_flag & IN_CHANGE) \ 159207618Srdivacky (ip)->i_ctime = tv_sec; \ 160223013Sdim (ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE); \ 161207618Srdivacky } \ 162223013Sdim} 163201360Srdivacky 164234982Sdim/* This overlays the fid structure (see mount.h). */ 165223013Sdimstruct ufid { 166201360Srdivacky u_int16_t ufid_len; /* Length of structure. */ 167201360Srdivacky u_int16_t ufid_pad; /* Force 32-bit alignment. */ 168 ino_t ufid_ino; /* File number (ino). */ 169 int32_t ufid_gen; /* Generation number. */ 170}; 171#endif /* KERNEL */ 172 173#endif /* !_UFS_UFS_INODE_H_ */ 174