1139825Simp/*- 21541Srgrimes * Copyright (c) 1982, 1989, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * (c) UNIX System Laboratories, Inc. 51541Srgrimes * All or some portions of this file are derived from material licensed 61541Srgrimes * to the University of California by American Telephone and Telegraph 71541Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with 81541Srgrimes * the permission of UNIX System Laboratories, Inc. 91541Srgrimes * 101541Srgrimes * Redistribution and use in source and binary forms, with or without 111541Srgrimes * modification, are permitted provided that the following conditions 121541Srgrimes * are met: 131541Srgrimes * 1. Redistributions of source code must retain the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer. 151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161541Srgrimes * notice, this list of conditions and the following disclaimer in the 171541Srgrimes * documentation and/or other materials provided with the distribution. 181541Srgrimes * 4. Neither the name of the University nor the names of its contributors 191541Srgrimes * may be used to endorse or promote products derived from this software 201541Srgrimes * without specific prior written permission. 211541Srgrimes * 221541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321541Srgrimes * SUCH DAMAGE. 331541Srgrimes * 3422521Sdyson * @(#)inode.h 8.9 (Berkeley) 5/14/95 3550477Speter * $FreeBSD$ 361541Srgrimes */ 371541Srgrimes 382177Spaul#ifndef _UFS_UFS_INODE_H_ 395247Sbde#define _UFS_UFS_INODE_H_ 402177Spaul 4131557Sjkh#include <sys/lock.h> 4244512Sbde#include <sys/queue.h> 431541Srgrimes#include <ufs/ufs/dinode.h> 441541Srgrimes 451541Srgrimes/* 4624477Sbde * This must agree with the definition in <ufs/ufs/dir.h>. 4724477Sbde */ 4824477Sbde#define doff_t int32_t 4924477Sbde 5024477Sbde/* 5122521Sdyson * The inode is used to describe each active (or recently active) file in the 5222521Sdyson * UFS filesystem. It is composed of two types of information. The first part 5322521Sdyson * is the information that is needed only while the file is active (such as 5422521Sdyson * the identity of the file and linkage to speed its lookup). The second part 5522521Sdyson * is the permanent meta-data associated with the file which is read in 5622521Sdyson * from the permanent dinode from long term storage when the file becomes 5722521Sdyson * active, and is put back when the file is no longer being used. 58163194Skib * 59163194Skib * An inode may only be changed while holding either the exclusive 60163194Skib * vnode lock or the shared vnode lock and the vnode interlock. We use 61163194Skib * the latter only for "read" and "get" operations that require 62163194Skib * changing i_flag, or a timestamp. This locking protocol allows executing 63163194Skib * those operations without having to upgrade the vnode lock from shared to 64163194Skib * exclusive. 651541Srgrimes */ 6622521Sdysonstruct inode { 67104702Smckusick TAILQ_ENTRY(inode) i_nextsnap; /* snapshot file list. */ 6822521Sdyson struct vnode *i_vnode;/* Vnode associated with this inode. */ 6998542Smckusick struct ufsmount *i_ump;/* Ufsmount point associated with this inode. */ 7022521Sdyson u_int32_t i_flag; /* flags, see below */ 71104052Sphk struct cdev *i_dev; /* Device associated with the inode. */ 7222521Sdyson ino_t i_number; /* The identity of the inode. */ 7334266Sjulian int i_effnlink; /* i_nlink when I/O completes */ 741541Srgrimes 7596873Siedowse struct fs *i_fs; /* Associated filesystem superblock. */ 7622521Sdyson struct dquot *i_dquot[MAXQUOTAS]; /* Dquot structures. */ 771541Srgrimes /* 781541Srgrimes * Side effects; used during directory lookup. 791541Srgrimes */ 8022521Sdyson int32_t i_count; /* Size of free slot in directory. */ 8122521Sdyson doff_t i_endoff; /* End of useful stuff in directory. */ 8222521Sdyson doff_t i_diroff; /* Offset in dir, where we found last entry. */ 8322521Sdyson doff_t i_offset; /* Offset of free space in directory. */ 8479561Siedowse 85107915Smckusick union { 86107915Smckusick struct dirhash *dirhash; /* Hashing for large directories. */ 87107915Smckusick daddr_t *snapblklist; /* Collect expunged snapshot blocks. */ 88107915Smckusick } i_un; 89102991Sphk 901541Srgrimes /* 91102991Sphk * Data for extended attribute modification. 92102991Sphk */ 93102991Sphk u_char *i_ea_area; /* Pointer to malloced copy of EA area */ 94102991Sphk unsigned i_ea_len; /* Length of i_ea_area */ 95102991Sphk int i_ea_error; /* First errno in transaction */ 96189737Skib int i_ea_refs; /* Number of users of EA area */ 97102991Sphk 98102991Sphk /* 9998542Smckusick * Copies from the on-disk dinode itself. 1001541Srgrimes */ 10198542Smckusick u_int16_t i_mode; /* IFMT, permissions; see below. */ 10298542Smckusick int16_t i_nlink; /* File link count. */ 10398542Smckusick u_int64_t i_size; /* File byte count. */ 10498542Smckusick u_int32_t i_flags; /* Status flags (chflags). */ 105252435Spfg u_int64_t i_gen; /* Generation number. */ 10698542Smckusick u_int32_t i_uid; /* File owner. */ 10798542Smckusick u_int32_t i_gid; /* File group. */ 10898542Smckusick /* 10998542Smckusick * The real copy of the on-disk inode. 11098542Smckusick */ 11198542Smckusick union { 11298542Smckusick struct ufs1_dinode *din1; /* UFS1 on-disk dinode. */ 11398542Smckusick struct ufs2_dinode *din2; /* UFS2 on-disk dinode. */ 11498542Smckusick } dinode_u; 1151541Srgrimes}; 11698542Smckusick/* 11798542Smckusick * These flags are kept in i_flag. 11898542Smckusick */ 1191541Srgrimes#define IN_ACCESS 0x0001 /* Access time update request. */ 1201541Srgrimes#define IN_CHANGE 0x0002 /* Inode change time update request. */ 12122521Sdyson#define IN_UPDATE 0x0004 /* Modification time update request. */ 12222521Sdyson#define IN_MODIFIED 0x0008 /* Inode has been modified. */ 123207141Sjeff#define IN_NEEDSYNC 0x0010 /* Inode requires fsync. */ 12476357Smckusick#define IN_LAZYMOD 0x0040 /* Modified, but don't write yet. */ 125163194Skib#define IN_LAZYACCESS 0x0100 /* Process IN_ACCESS after the 126163194Skib suspension finished */ 127189737Skib#define IN_EA_LOCKED 0x0200 128189737Skib#define IN_EA_LOCKWAIT 0x0400 1291541Srgrimes 130222958Sjeff#define IN_TRUNCATED 0x0800 /* Journaled truncation pending. */ 131222958Sjeff 132262779Spfg#define i_devvp i_ump->um_devvp 133262779Spfg#define i_umbufobj i_ump->um_bo 134262779Spfg#define i_dirhash i_un.dirhash 135262779Spfg#define i_snapblklist i_un.snapblklist 136262779Spfg#define i_din1 dinode_u.din1 137262779Spfg#define i_din2 dinode_u.din2 13898542Smckusick 13955206Speter#ifdef _KERNEL 1401541Srgrimes/* 14198542Smckusick * The DIP macro is used to access fields in the dinode that are 14298542Smckusick * not cached in the inode itself. 14398542Smckusick */ 14498542Smckusick#define DIP(ip, field) \ 14598542Smckusick (((ip)->i_ump->um_fstype == UFS1) ? \ 14698542Smckusick (ip)->i_din1->d##field : (ip)->i_din2->d##field) 147132775Skan#define DIP_SET(ip, field, val) do { \ 148132775Skan if ((ip)->i_ump->um_fstype == UFS1) \ 149132775Skan (ip)->i_din1->d##field = (val); \ 150132775Skan else \ 151132775Skan (ip)->i_din2->d##field = (val); \ 152132775Skan } while (0) 15398542Smckusick 15498542Smckusick#define SHORTLINK(ip) \ 15598542Smckusick (((ip)->i_ump->um_fstype == UFS1) ? \ 15698542Smckusick (caddr_t)(ip)->i_din1->di_db : (caddr_t)(ip)->i_din2->di_db) 157262779Spfg#define IS_SNAPSHOT(ip) ((ip)->i_flags & SF_SNAPSHOT) 15898542Smckusick 15998542Smckusick/* 1601541Srgrimes * Structure used to pass around logical block paths generated by 1611541Srgrimes * ufs_getlbns and used by truncate and bmap code. 1621541Srgrimes */ 1631541Srgrimesstruct indir { 16498542Smckusick ufs2_daddr_t in_lbn; /* Logical block number. */ 1651541Srgrimes int in_off; /* Offset in buffer. */ 1661541Srgrimes}; 1671541Srgrimes 1681541Srgrimes/* Convert between inode pointers and vnode pointers. */ 169262779Spfg#define VTOI(vp) ((struct inode *)(vp)->v_data) 170262779Spfg#define ITOV(ip) ((ip)->i_vnode) 1711541Srgrimes 17234266Sjulian/* Determine if soft dependencies are being done */ 173262779Spfg#define DOINGSOFTDEP(vp) ((vp)->v_mount->mnt_flag & (MNT_SOFTDEP | MNT_SUJ)) 174262779Spfg#define MOUNTEDSOFTDEP(mp) ((mp)->mnt_flag & (MNT_SOFTDEP | MNT_SUJ)) 175262779Spfg#define DOINGSUJ(vp) ((vp)->v_mount->mnt_flag & MNT_SUJ) 176262779Spfg#define MOUNTEDSUJ(mp) ((mp)->mnt_flag & MNT_SUJ) 17734266Sjulian 1781541Srgrimes/* This overlays the fid structure (see mount.h). */ 1791541Srgrimesstruct ufid { 18022521Sdyson u_int16_t ufid_len; /* Length of structure. */ 18122521Sdyson u_int16_t ufid_pad; /* Force 32-bit alignment. */ 182241011Smdf uint32_t ufid_ino; /* File number (ino). */ 183253163Spfg uint32_t ufid_gen; /* Generation number. */ 1841541Srgrimes}; 18555206Speter#endif /* _KERNEL */ 1862177Spaul 1875247Sbde#endif /* !_UFS_UFS_INODE_H_ */ 188