xref: /original-bsd/sys/ufs/ufs/dinode.h (revision 4e1ffb20)
1 /*
2  * Copyright (c) 1982, 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  * (c) UNIX System Laboratories, Inc.
5  * All or some portions of this file are derived from material licensed
6  * to the University of California by American Telephone and Telegraph
7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8  * the permission of UNIX System Laboratories, Inc.
9  *
10  * %sccs.include.redist.c%
11  *
12  *	@(#)dinode.h	8.4 (Berkeley) 07/08/94
13  */
14 
15 /*
16  * The root inode is the root of the file system.  Inode 0 can't be used for
17  * normal purposes and historically bad blocks were linked to inode 1, thus
18  * the root inode is 2.  (Inode 1 is no longer used for this purpose, however
19  * numerous dump tapes make this assumption, so we are stuck with it).
20  */
21 #define	ROOTINO	((ino_t)2)
22 
23 /*
24  * A dinode contains all the meta-data associated with a UFS file.
25  * This structure defines the on-disk format of a dinode.
26  */
27 
28 #define	NDADDR	12			/* Direct addresses in inode. */
29 #define	NIADDR	3			/* Indirect addresses in inode. */
30 
31 struct dinode {
32 	u_int16_t	di_mode;	/*   0: IFMT, permissions; see below. */
33 	int16_t		di_nlink;	/*   2: File link count. */
34 	union {
35 		u_int16_t oldids[2];	/*   4: Ffs: old user and group ids. */
36 		ino_t	  inumber;	/*   4: Lfs: inode number. */
37 	} di_u;
38 	u_quad_t	di_size;	/*   8: File byte count. */
39 	struct timespec	di_atime;	/*  16: Last access time. */
40 	struct timespec	di_mtime;	/*  24: Last modified time. */
41 	struct timespec	di_ctime;	/*  32: Last inode change time. */
42 	daddr_t		di_db[NDADDR];	/*  40: Direct disk blocks. */
43 	daddr_t		di_ib[NIADDR];	/*  88: Indirect disk blocks. */
44 	u_int32_t	di_flags;	/* 100: Status flags (chflags). */
45 	int32_t		di_blocks;	/* 104: Blocks actually held. */
46 	int32_t		di_gen;		/* 108: Generation number. */
47 	u_int32_t	di_uid;		/* 112: File owner. */
48 	u_int32_t	di_gid;		/* 116: File group. */
49 	int32_t		di_spare[2];	/* 120: Reserved; currently unused */
50 };
51 
52 /*
53  * The di_db fields may be overlaid with other information for
54  * file types that do not have associated disk storage. Block
55  * and character devices overlay the first data block with their
56  * dev_t value. Short symbolic links place their path in the
57  * di_db area.
58  */
59 #define	di_inumber	di_u.inumber
60 #define	di_ogid		di_u.oldids[1]
61 #define	di_ouid		di_u.oldids[0]
62 #define	di_rdev		di_db[0]
63 #define	di_shortlink	di_db
64 #define	MAXSYMLINKLEN	((NDADDR + NIADDR) * sizeof(daddr_t))
65 
66 /* File permissions. */
67 #define	IEXEC		0000100		/* Executable. */
68 #define	IWRITE		0000200		/* Writeable. */
69 #define	IREAD		0000400		/* Readable. */
70 #define	ISVTX		0001000		/* Sticky bit. */
71 #define	ISGID		0002000		/* Set-gid. */
72 #define	ISUID		0004000		/* Set-uid. */
73 
74 /* File types. */
75 #define	IFMT		0170000		/* Mask of file type. */
76 #define	IFIFO		0010000		/* Named pipe (fifo). */
77 #define	IFCHR		0020000		/* Character device. */
78 #define	IFDIR		0040000		/* Directory file. */
79 #define	IFBLK		0060000		/* Block device. */
80 #define	IFREG		0100000		/* Regular file. */
81 #define	IFLNK		0120000		/* Symbolic link. */
82 #define	IFSOCK		0140000		/* UNIX domain socket. */
83