ulfs_dinode.h revision 1.2
1/*	$NetBSD: ulfs_dinode.h,v 1.2 2013/06/06 00:48:04 dholland Exp $	*/
2/*  from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp  */
3
4/*
5 * Copyright (c) 2002 Networks Associates Technology, Inc.
6 * All rights reserved.
7 *
8 * This software was developed for the FreeBSD Project by Marshall
9 * Kirk McKusick and Network Associates Laboratories, the Security
10 * Research Division of Network Associates, Inc. under DARPA/SPAWAR
11 * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
12 * research program
13 *
14 * Copyright (c) 1982, 1989, 1993
15 *	The Regents of the University of California.  All rights reserved.
16 * (c) UNIX System Laboratories, Inc.
17 * All or some portions of this file are derived from material licensed
18 * to the University of California by American Telephone and Telegraph
19 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
20 * the permission of UNIX System Laboratories, Inc.
21 *
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
24 * are met:
25 * 1. Redistributions of source code must retain the above copyright
26 *    notice, this list of conditions and the following disclaimer.
27 * 2. Redistributions in binary form must reproduce the above copyright
28 *    notice, this list of conditions and the following disclaimer in the
29 *    documentation and/or other materials provided with the distribution.
30 * 3. Neither the name of the University nor the names of its contributors
31 *    may be used to endorse or promote products derived from this software
32 *    without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
35 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 * SUCH DAMAGE.
45 *
46 *	@(#)dinode.h	8.9 (Berkeley) 3/29/95
47 */
48
49/*
50 * NOTE: COORDINATE ON-DISK FORMAT CHANGES WITH THE FREEBSD PROJECT.
51 */
52
53#ifndef	_UFS_LFS_ULFS_DINODE_H_
54#define	_UFS_LFS_ULFS_DINODE_H_
55
56/*
57 * The root inode is the root of the file system.  Inode 0 can't be used for
58 * normal purposes and historically bad blocks were linked to inode 1, thus
59 * the root inode is 2.  (Inode 1 is no longer used for this purpose, however
60 * numerous dump tapes make this assumption, so we are stuck with it).
61 */
62#define	ULFS_ROOTINO	((ino_t)2)
63
64/*
65 * The Whiteout inode# is a dummy non-zero inode number which will
66 * never be allocated to a real file.  It is used as a place holder
67 * in the directory entry which has been tagged as a DT_W entry.
68 * See the comments about ULFS_ROOTINO above.
69 */
70#define	ULFS_WINO	((ino_t)1)
71
72/*
73 * A dinode contains all the meta-data associated with a ULFS file.
74 * This structure defines the on-disk format of a dinode. Since
75 * this structure describes an on-disk structure, all its fields
76 * are defined by types with precise widths.
77 */
78
79#define ULFS_NXADDR	2
80#define	ULFS_NDADDR	12		/* Direct addresses in inode. */
81#define	ULFS_NIADDR	3		/* Indirect addresses in inode. */
82
83struct ulfs1_dinode {
84	u_int16_t	di_mode;	/*   0: IFMT, permissions; see below. */
85	int16_t		di_nlink;	/*   2: File link count. */
86	union {
87		u_int16_t oldids[2];	/*   4: Ffs: old user and group ids. */
88		u_int32_t inumber;	/*   4: Lfs: inode number. */
89	} di_u;
90	u_int64_t	di_size;	/*   8: File byte count. */
91	int32_t		di_atime;	/*  16: Last access time. */
92	int32_t		di_atimensec;	/*  20: Last access time. */
93	int32_t		di_mtime;	/*  24: Last modified time. */
94	int32_t		di_mtimensec;	/*  28: Last modified time. */
95	int32_t		di_ctime;	/*  32: Last inode change time. */
96	int32_t		di_ctimensec;	/*  36: Last inode change time. */
97	int32_t		di_db[ULFS_NDADDR]; /*  40: Direct disk blocks. */
98	int32_t		di_ib[ULFS_NIADDR]; /*  88: Indirect disk blocks. */
99	u_int32_t	di_flags;	/* 100: Status flags (chflags). */
100	u_int32_t	di_blocks;	/* 104: Blocks actually held. */
101	int32_t		di_gen;		/* 108: Generation number. */
102	u_int32_t	di_uid;		/* 112: File owner. */
103	u_int32_t	di_gid;		/* 116: File group. */
104	u_int64_t	di_modrev;	/* 120: i_modrev for NFSv4 */
105};
106
107struct ulfs2_dinode {
108	u_int16_t	di_mode;	/*   0: IFMT, permissions; see below. */
109	int16_t		di_nlink;	/*   2: File link count. */
110	u_int32_t	di_uid;		/*   4: File owner. */
111	u_int32_t	di_gid;		/*   8: File group. */
112	u_int32_t	di_blksize;	/*  12: Inode blocksize. */
113	u_int64_t	di_size;	/*  16: File byte count. */
114	u_int64_t	di_blocks;	/*  24: Bytes actually held. */
115	int64_t		di_atime;	/*  32: Last access time. */
116	int64_t		di_mtime;	/*  40: Last modified time. */
117	int64_t		di_ctime;	/*  48: Last inode change time. */
118	int64_t		di_birthtime;	/*  56: Inode creation time. */
119	int32_t		di_mtimensec;	/*  64: Last modified time. */
120	int32_t		di_atimensec;	/*  68: Last access time. */
121	int32_t		di_ctimensec;	/*  72: Last inode change time. */
122	int32_t		di_birthnsec;	/*  76: Inode creation time. */
123	int32_t		di_gen;		/*  80: Generation number. */
124	u_int32_t	di_kernflags;	/*  84: Kernel flags. */
125	u_int32_t	di_flags;	/*  88: Status flags (chflags). */
126	int32_t		di_extsize;	/*  92: External attributes block. */
127	int64_t		di_extb[ULFS_NXADDR];/* 96: External attributes block. */
128	int64_t		di_db[ULFS_NDADDR]; /* 112: Direct disk blocks. */
129	int64_t		di_ib[ULFS_NIADDR]; /* 208: Indirect disk blocks. */
130	u_int64_t	di_modrev;	/* 232: i_modrev for NFSv4 */
131	int64_t		di_spare[2];	/* 240: Reserved; currently unused */
132};
133
134/*
135 * The di_db fields may be overlaid with other information for
136 * file types that do not have associated disk storage. Block
137 * and character devices overlay the first data block with their
138 * dev_t value. Short symbolic links place their path in the
139 * di_db area.
140 */
141#define	di_inumber	di_u.inumber
142#define	di_ogid		di_u.oldids[1]
143#define	di_ouid		di_u.oldids[0]
144#define	di_rdev		di_db[0]
145#define ULFS1_MAXSYMLINKLEN	((ULFS_NDADDR + ULFS_NIADDR) * sizeof(int32_t))
146#define ULFS2_MAXSYMLINKLEN	((ULFS_NDADDR + ULFS_NIADDR) * sizeof(int64_t))
147
148#define ULFS_MAXSYMLINKLEN(ip) \
149	((ip)->i_ump->um_fstype == ULFS1) ? \
150	ULFS1_MAXSYMLINKLEN : ULFS2_MAXSYMLINKLEN
151
152/* NeXT used to keep short symlinks in the inode even when using
153 * FS_42INODEFMT.  In that case fs->fs_maxsymlinklen is probably -1,
154 * but short symlinks were stored in inodes shorter than this:
155 */
156#define	APPLEUFS_MAXSYMLINKLEN 60
157
158/* File permissions. */
159#define	IEXEC		0000100		/* Executable. */
160#define	IWRITE		0000200		/* Writable. */
161#define	IREAD		0000400		/* Readable. */
162#define	ISVTX		0001000		/* Sticky bit. */
163#define	ISGID		0002000		/* Set-gid. */
164#define	ISUID		0004000		/* Set-uid. */
165
166/* File types. */
167#define	IFMT		0170000		/* Mask of file type. */
168#define	IFIFO		0010000		/* Named pipe (fifo). */
169#define	IFCHR		0020000		/* Character device. */
170#define	IFDIR		0040000		/* Directory file. */
171#define	IFBLK		0060000		/* Block device. */
172#define	IFREG		0100000		/* Regular file. */
173#define	IFLNK		0120000		/* Symbolic link. */
174#define	IFSOCK		0140000		/* UNIX domain socket. */
175#define	IFWHT		0160000		/* Whiteout. */
176
177/* Size of the on-disk inode. */
178#define	DINODE1_SIZE	(sizeof(struct ulfs1_dinode))		/* 128 */
179#define	DINODE2_SIZE	(sizeof(struct ulfs2_dinode))
180
181#endif /* !_UFS_LFS_ULFS_DINODE_H_ */
182