dinode.h revision 98542
11541Srgrimes/*
298542Smckusick * Copyright (c) 2002 Networks Associates Technology, Inc.
398542Smckusick * All rights reserved.
498542Smckusick *
598542Smckusick * This software was developed for the FreeBSD Project by Marshall
698542Smckusick * Kirk McKusick and Network Associates Laboratories, the Security
798542Smckusick * Research Division of Network Associates, Inc. under DARPA/SPAWAR
898542Smckusick * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
998542Smckusick * research program
1098542Smckusick *
111541Srgrimes * Copyright (c) 1982, 1989, 1993
121541Srgrimes *	The Regents of the University of California.  All rights reserved.
131541Srgrimes * (c) UNIX System Laboratories, Inc.
141541Srgrimes * All or some portions of this file are derived from material licensed
151541Srgrimes * to the University of California by American Telephone and Telegraph
161541Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with
171541Srgrimes * the permission of UNIX System Laboratories, Inc.
181541Srgrimes *
191541Srgrimes * Redistribution and use in source and binary forms, with or without
201541Srgrimes * modification, are permitted provided that the following conditions
211541Srgrimes * are met:
221541Srgrimes * 1. Redistributions of source code must retain the above copyright
231541Srgrimes *    notice, this list of conditions and the following disclaimer.
241541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
251541Srgrimes *    notice, this list of conditions and the following disclaimer in the
261541Srgrimes *    documentation and/or other materials provided with the distribution.
2798542Smckusick * 3. The names of the authors may not be used to endorse or promote
2898542Smckusick *    products derived from this software without specific prior written
2998542Smckusick *    permission.
301541Srgrimes *
3198542Smckusick * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
321541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
331541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3498542Smckusick * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
351541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
361541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
371541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
381541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
391541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
401541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
411541Srgrimes * SUCH DAMAGE.
421541Srgrimes *
431541Srgrimes *	@(#)dinode.h	8.3 (Berkeley) 1/21/94
4450477Speter * $FreeBSD: head/sys/ufs/ufs/dinode.h 98542 2002-06-21 06:18:05Z mckusick $
451541Srgrimes */
461541Srgrimes
472177Spaul#ifndef _UFS_UFS_DINODE_H_
4898542Smckusick#define	_UFS_UFS_DINODE_H_
492177Spaul
501541Srgrimes/*
5196755Strhodes * The root inode is the root of the filesystem.  Inode 0 can't be used for
521541Srgrimes * normal purposes and historically bad blocks were linked to inode 1, thus
531541Srgrimes * the root inode is 2.  (Inode 1 is no longer used for this purpose, however
541541Srgrimes * numerous dump tapes make this assumption, so we are stuck with it).
551541Srgrimes */
561541Srgrimes#define	ROOTINO	((ino_t)2)
571541Srgrimes
581541Srgrimes/*
5922521Sdyson * The Whiteout inode# is a dummy non-zero inode number which will
6022521Sdyson * never be allocated to a real file.  It is used as a place holder
6122521Sdyson * in the directory entry which has been tagged as a DT_W entry.
6222521Sdyson * See the comments about ROOTINO above.
6322521Sdyson */
6422521Sdyson#define	WINO	((ino_t)1)
6522521Sdyson
6622521Sdyson/*
6798542Smckusick * The size of physical and logical block numbers and time fields in UFS.
6898542Smckusick */
6998542Smckusicktypedef	int32_t	ufs1_daddr_t;
7098542Smckusicktypedef	int64_t	ufs2_daddr_t;
7198542Smckusicktypedef int64_t ufs_lbn_t;
7298542Smckusicktypedef int64_t ufs_time_t;
7398542Smckusick
7498542Smckusick/* File permissions. */
7598542Smckusick#define	IEXEC		0000100		/* Executable. */
7698542Smckusick#define	IWRITE		0000200		/* Writeable. */
7798542Smckusick#define	IREAD		0000400		/* Readable. */
7898542Smckusick#define	ISVTX		0001000		/* Sticky bit. */
7998542Smckusick#define	ISGID		0002000		/* Set-gid. */
8098542Smckusick#define	ISUID		0004000		/* Set-uid. */
8198542Smckusick
8298542Smckusick/* File types. */
8398542Smckusick#define	IFMT		0170000		/* Mask of file type. */
8498542Smckusick#define	IFIFO		0010000		/* Named pipe (fifo). */
8598542Smckusick#define	IFCHR		0020000		/* Character device. */
8698542Smckusick#define	IFDIR		0040000		/* Directory file. */
8798542Smckusick#define	IFBLK		0060000		/* Block device. */
8898542Smckusick#define	IFREG		0100000		/* Regular file. */
8998542Smckusick#define	IFLNK		0120000		/* Symbolic link. */
9098542Smckusick#define	IFSOCK		0140000		/* UNIX domain socket. */
9198542Smckusick#define	IFWHT		0160000		/* Whiteout. */
9298542Smckusick
9398542Smckusick/*
9498542Smckusick * A dinode contains all the meta-data associated with a UFS2 file.
9522521Sdyson * This structure defines the on-disk format of a dinode. Since
9622521Sdyson * this structure describes an on-disk structure, all its fields
9722521Sdyson * are defined by types with precise widths.
981541Srgrimes */
991541Srgrimes
10098542Smckusick#define	NXADDR	2			/* External addresses in inode. */
1011541Srgrimes#define	NDADDR	12			/* Direct addresses in inode. */
1021541Srgrimes#define	NIADDR	3			/* Indirect addresses in inode. */
1031541Srgrimes
10498542Smckusickstruct ufs2_dinode {
10522521Sdyson	u_int16_t	di_mode;	/*   0: IFMT, permissions; see below. */
10622521Sdyson	int16_t		di_nlink;	/*   2: File link count. */
10798542Smckusick	u_int32_t	di_uid;		/*   4: File owner. */
10898542Smckusick	u_int32_t	di_gid;		/*   8: File group. */
10998542Smckusick	u_int32_t	di_blksize;	/*  12: Inode blocksize. */
11098542Smckusick	u_int64_t	di_size;	/*  16: File byte count. */
11198542Smckusick	u_int64_t	di_blocks;	/*  24: Bytes actually held. */
11298542Smckusick	ufs_time_t	di_atime;	/*  32: Last access time. */
11398542Smckusick	ufs_time_t	di_mtime;	/*  40: Last modified time. */
11498542Smckusick	ufs_time_t	di_ctime;	/*  48: Last inode change time. */
11598542Smckusick	ufs_time_t	di_createtime;	/*  56: Last inode change time. */
11698542Smckusick	int32_t		di_mtimensec;	/*  64: Last modified time. */
11798542Smckusick	int32_t		di_atimensec;	/*  68: Last access time. */
11898542Smckusick	int32_t		di_ctimensec;	/*  72: Last inode change time. */
11998542Smckusick	int32_t		di_creatensec;	/*  76: Last inode change time. */
12098542Smckusick	int32_t		di_gen;		/*  80: Generation number. */
12198542Smckusick	u_int32_t	di_kernflags;	/*  84: Kernel flags. */
12298542Smckusick	u_int32_t	di_flags;	/*  88: Status flags (chflags). */
12398542Smckusick	int32_t		di_extsize;	/*  92: External attributes block. */
12498542Smckusick	ufs2_daddr_t	di_extb[NXADDR];/*  96: External attributes block. */
12598542Smckusick	ufs2_daddr_t	di_db[NDADDR];	/* 112: Direct disk blocks. */
12698542Smckusick	ufs2_daddr_t	di_ib[NIADDR];	/* 208: Indirect disk blocks. */
12798542Smckusick	int64_t		di_spare[3];	/* 232: Reserved; currently unused */
12898542Smckusick};
12998542Smckusick
13098542Smckusick/*
13198542Smckusick * The di_db fields may be overlaid with other information for
13298542Smckusick * file types that do not have associated disk storage. Block
13398542Smckusick * and character devices overlay the first data block with their
13498542Smckusick * dev_t value. Short symbolic links place their path in the
13598542Smckusick * di_db area.
13698542Smckusick */
13798542Smckusick#define	di_rdev di_db[0]
13898542Smckusick
13998542Smckusick/*
14098542Smckusick * A UFS1 dinode contains all the meta-data associated with a UFS1 file.
14198542Smckusick * This structure defines the on-disk format of a UFS1 dinode. Since
14298542Smckusick * this structure describes an on-disk structure, all its fields
14398542Smckusick * are defined by types with precise widths.
14498542Smckusick */
14598542Smckusickstruct ufs1_dinode {
14698542Smckusick	u_int16_t	di_mode;	/*   0: IFMT, permissions; see below. */
14798542Smckusick	int16_t		di_nlink;	/*   2: File link count. */
1481541Srgrimes	union {
14922521Sdyson		u_int16_t oldids[2];	/*   4: Ffs: old user and group ids. */
1501541Srgrimes	} di_u;
15122521Sdyson	u_int64_t	di_size;	/*   8: File byte count. */
15222521Sdyson	int32_t		di_atime;	/*  16: Last access time. */
15322521Sdyson	int32_t		di_atimensec;	/*  20: Last access time. */
15422521Sdyson	int32_t		di_mtime;	/*  24: Last modified time. */
15522521Sdyson	int32_t		di_mtimensec;	/*  28: Last modified time. */
15622521Sdyson	int32_t		di_ctime;	/*  32: Last inode change time. */
15722521Sdyson	int32_t		di_ctimensec;	/*  36: Last inode change time. */
15898542Smckusick	ufs1_daddr_t	di_db[NDADDR];	/*  40: Direct disk blocks. */
15998542Smckusick	ufs1_daddr_t	di_ib[NIADDR];	/*  88: Indirect disk blocks. */
16022521Sdyson	u_int32_t	di_flags;	/* 100: Status flags (chflags). */
16122521Sdyson	int32_t		di_blocks;	/* 104: Blocks actually held. */
16222521Sdyson	int32_t		di_gen;		/* 108: Generation number. */
16322521Sdyson	u_int32_t	di_uid;		/* 112: File owner. */
16422521Sdyson	u_int32_t	di_gid;		/* 116: File group. */
16522521Sdyson	int32_t		di_spare[2];	/* 120: Reserved; currently unused */
1661541Srgrimes};
1671541Srgrimes#define	di_ogid		di_u.oldids[1]
1681541Srgrimes#define	di_ouid		di_u.oldids[0]
1691541Srgrimes
17098542Smckusick#endif /* _UFS_UFS_DINODE_H_ */
171