xref: /openbsd-src/sys/ufs/ext2fs/ext2fs_dinode.h (revision d31d4a6efc77350e848422a4d0fc38384984d19d)
1*d31d4a6eSpelikan /*	$OpenBSD: ext2fs_dinode.h,v 1.17 2014/07/31 17:37:52 pelikan Exp $	*/
26b38e8dfSart /*	$NetBSD: ext2fs_dinode.h,v 1.6 2000/01/26 16:21:33 bouyer Exp $	*/
35ac2d602Sdownsj 
45ac2d602Sdownsj /*
51f3ff51cSdownsj  * Copyright (c) 1997 Manuel Bouyer.
65ac2d602Sdownsj  * Copyright (c) 1982, 1989, 1993
75ac2d602Sdownsj  *	The Regents of the University of California.  All rights reserved.
85ac2d602Sdownsj  * (c) UNIX System Laboratories, Inc.
95ac2d602Sdownsj  * All or some portions of this file are derived from material licensed
105ac2d602Sdownsj  * to the University of California by American Telephone and Telegraph
115ac2d602Sdownsj  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
125ac2d602Sdownsj  * the permission of UNIX System Laboratories, Inc.
135ac2d602Sdownsj  *
145ac2d602Sdownsj  * Redistribution and use in source and binary forms, with or without
155ac2d602Sdownsj  * modification, are permitted provided that the following conditions
165ac2d602Sdownsj  * are met:
175ac2d602Sdownsj  * 1. Redistributions of source code must retain the above copyright
185ac2d602Sdownsj  *    notice, this list of conditions and the following disclaimer.
195ac2d602Sdownsj  * 2. Redistributions in binary form must reproduce the above copyright
205ac2d602Sdownsj  *    notice, this list of conditions and the following disclaimer in the
215ac2d602Sdownsj  *    documentation and/or other materials provided with the distribution.
2229295d1cSmillert  * 3. Neither the name of the University nor the names of its contributors
235ac2d602Sdownsj  *    may be used to endorse or promote products derived from this software
245ac2d602Sdownsj  *    without specific prior written permission.
255ac2d602Sdownsj  *
265ac2d602Sdownsj  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
275ac2d602Sdownsj  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
285ac2d602Sdownsj  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
295ac2d602Sdownsj  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
305ac2d602Sdownsj  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
315ac2d602Sdownsj  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
325ac2d602Sdownsj  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
335ac2d602Sdownsj  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
345ac2d602Sdownsj  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
355ac2d602Sdownsj  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
365ac2d602Sdownsj  * SUCH DAMAGE.
375ac2d602Sdownsj  *
385ac2d602Sdownsj  *	@(#)dinode.h	8.6 (Berkeley) 9/13/94
391f3ff51cSdownsj  *  Modified for ext2fs by Manuel Bouyer.
405ac2d602Sdownsj  */
415ac2d602Sdownsj 
425ac2d602Sdownsj #include <sys/stat.h>
43e012d6d3Sguenther #include <ufs/ufs/dinode.h>	/* for ufsino_t */
445ac2d602Sdownsj 
455ac2d602Sdownsj /*
465ac2d602Sdownsj  * The root inode is the root of the file system.  Inode 0 can't be used for
475ac2d602Sdownsj  * normal purposes and bad blocks are normally linked to inode 1, thus
485ac2d602Sdownsj  * the root inode is 2.
495ac2d602Sdownsj  * Inode 3 to 10 are reserved in ext2fs.
505ac2d602Sdownsj  */
51e012d6d3Sguenther #define	EXT2_ROOTINO ((ufsino_t)2)
52e012d6d3Sguenther #define EXT2_RESIZEINO ((ufsino_t)7)
53e012d6d3Sguenther #define EXT2_FIRSTINO ((ufsino_t)11)
545ac2d602Sdownsj 
555ac2d602Sdownsj /*
565ac2d602Sdownsj  * A dinode contains all the meta-data associated with a UFS file.
575ac2d602Sdownsj  * This structure defines the on-disk format of a dinode. Since
585ac2d602Sdownsj  * this structure describes an on-disk structure, all its fields
595ac2d602Sdownsj  * are defined by types with precise widths.
605ac2d602Sdownsj  */
615ac2d602Sdownsj 
625ac2d602Sdownsj #define	NDADDR	12			/* Direct addresses in inode. */
635ac2d602Sdownsj #define	NIADDR	3			/* Indirect addresses in inode. */
645ac2d602Sdownsj 
655ac2d602Sdownsj #define EXT2_MAXSYMLINKLEN ((NDADDR+NIADDR) * sizeof (u_int32_t))
665ac2d602Sdownsj 
675ac2d602Sdownsj struct ext2fs_dinode {
685ac2d602Sdownsj 	u_int16_t	e2di_mode;	/*   0: IFMT, permissions; see below. */
6942cd3248Spelikan 	u_int16_t	e2di_uid_low;	/*   2: owner UID, bits 15:0 */
7042cd3248Spelikan 	u_int32_t	e2di_size;	/*   4: file size (bytes) bits 31:0 */
71a5a642b4Spedro 	u_int32_t	e2di_atime;	/*   8: Access time */
7242cd3248Spelikan 	u_int32_t	e2di_ctime;	/*  12: Change time */
735ac2d602Sdownsj 	u_int32_t	e2di_mtime;	/*  16: Modification time */
745ac2d602Sdownsj 	u_int32_t	e2di_dtime;	/*  20: Deletion time */
75d23196ecSpedro 	u_int16_t	e2di_gid_low;	/*  24: Owner GID, lowest bits */
765ac2d602Sdownsj 	u_int16_t	e2di_nlink;	/*  26: File link count */
7742cd3248Spelikan 	u_int32_t	e2di_nblock;	/*  28: blocks count */
7842cd3248Spelikan 	u_int32_t	e2di_flags;	/*  32: status flags (chflags) */
7942cd3248Spelikan 	u_int32_t	e2di_version_lo; /* 36: inode version, bits 31:0 */
805ac2d602Sdownsj 	u_int32_t	e2di_blocks[NDADDR+NIADDR]; /* 40: disk blocks */
816b38e8dfSart 	u_int32_t	e2di_gen;	/* 100: generation number */
8242cd3248Spelikan 	u_int32_t	e2di_facl;	/* 104: file ACL, bits 31:0 */
8342cd3248Spelikan 	u_int32_t	e2di_size_hi;	/* 108: file size (bytes), bits 63:32 */
842d7df345Spelikan 	u_int32_t	e2di_faddr;	/* 112: fragment address (obsolete) */
8542cd3248Spelikan 	u_int16_t	e2di_nblock_hi;	/* 116: blocks count, bits 47:32 */
8642cd3248Spelikan 	u_int16_t	e2di_facl_hi;	/* 118: file ACL, bits 47:32 */
8742cd3248Spelikan 	u_int16_t	e2di_uid_high;	/* 120: owner UID, bits 31:16 */
8842cd3248Spelikan 	u_int16_t	e2di_gid_high;	/* 122: owner GID, bits 31:16 */
8942cd3248Spelikan 	u_int16_t	e2di_chksum_lo;	/* 124: inode checksum, bits 15:0 */
9042cd3248Spelikan 	u_int16_t	e2di__reserved;	/* 126: 	unused */
9142cd3248Spelikan 	u_int16_t	e2di_isize;	/* 128: size of this inode */
9242cd3248Spelikan 	u_int16_t	e2di_chksum_hi;	/* 130: inode checksum, bits 31:16 */
9342cd3248Spelikan 	u_int32_t	e2di_x_ctime;	/* 132: extra Change time */
9442cd3248Spelikan 	u_int32_t	e2di_x_mtime;	/* 136: extra Modification time */
9542cd3248Spelikan 	u_int32_t	e2di_x_atime;	/* 140: extra Access time */
9642cd3248Spelikan 	u_int32_t	e2di_crtime;	/* 144: Creation (birth) time */
9742cd3248Spelikan 	u_int32_t	e2di_x_crtime;	/* 148: extra Creation (birth) time */
9842cd3248Spelikan 	u_int32_t	e2di_version_hi; /* 152: inode version, bits 63:31 */
995ac2d602Sdownsj };
1005ac2d602Sdownsj 
1015ac2d602Sdownsj #define	E2MAXSYMLINKLEN	((NDADDR + NIADDR) * sizeof(u_int32_t))
1025ac2d602Sdownsj 
1035ac2d602Sdownsj /* File permissions. */
1045ac2d602Sdownsj #define	EXT2_IEXEC		0000100		/* Executable. */
1055ac2d602Sdownsj #define	EXT2_IWRITE		0000200		/* Writeable. */
1065ac2d602Sdownsj #define	EXT2_IREAD		0000400		/* Readable. */
1075ac2d602Sdownsj #define	EXT2_ISVTX		0001000		/* Sticky bit. */
1085ac2d602Sdownsj #define	EXT2_ISGID		0002000		/* Set-gid. */
1095ac2d602Sdownsj #define	EXT2_ISUID		0004000		/* Set-uid. */
1105ac2d602Sdownsj 
1115ac2d602Sdownsj /* File types. */
1125ac2d602Sdownsj #define	EXT2_IFMT		0170000		/* Mask of file type. */
1135ac2d602Sdownsj #define	EXT2_IFIFO		0010000		/* Named pipe (fifo). */
1145ac2d602Sdownsj #define	EXT2_IFCHR		0020000		/* Character device. */
1155ac2d602Sdownsj #define	EXT2_IFDIR		0040000		/* Directory file. */
1165ac2d602Sdownsj #define	EXT2_IFBLK		0060000		/* Block device. */
1175ac2d602Sdownsj #define	EXT2_IFREG		0100000		/* Regular file. */
1185ac2d602Sdownsj #define	EXT2_IFLNK		0120000		/* Symbolic link. */
1195ac2d602Sdownsj #define	EXT2_IFSOCK		0140000		/* UNIX domain socket. */
1205ac2d602Sdownsj 
1215ac2d602Sdownsj /* file flags */
1225ac2d602Sdownsj #define EXT2_SECRM		0x00000001	/* Secure deletion */
1235ac2d602Sdownsj #define EXT2_UNRM		0x00000002	/* Undelete */
1245ac2d602Sdownsj #define EXT2_COMPR		0x00000004	/* Compress file */
1255ac2d602Sdownsj #define EXT2_SYNC		0x00000008	/* Synchronous updates */
1265ac2d602Sdownsj #define EXT2_IMMUTABLE		0x00000010	/* Immutable file */
1275ac2d602Sdownsj #define EXT2_APPEND		0x00000020	/* writes to file may only append */
1285ac2d602Sdownsj #define EXT2_NODUMP		0x00000040	/* do not dump file */
1292d7df345Spelikan #define EXT2_NOATIME		0x00000080	/* do not update access time */
1302d7df345Spelikan #define EXT4_INDEX		0x00001000	/* hash-indexed directory */
1312d7df345Spelikan #define EXT4_JOURNAL_DATA	0x00004000	/* file data should be journaled */
1322d7df345Spelikan #define EXT4_DIRSYNC		0x00010000	/* all dirent updates done synchronously */
1332d7df345Spelikan #define EXT4_TOPDIR		0x00020000	/* top of directory hierarchies */
1342d7df345Spelikan #define EXT4_HUGE_FILE		0x00040000	/* nblocks unit is fsb, not db */
1352d7df345Spelikan #define EXT4_EXTENTS		0x00080000	/* inode uses extents */
1362d7df345Spelikan #define EXT4_EOFBLOCKS		0x00400000	/* blocks allocated beyond EOF */
1375ac2d602Sdownsj 
138f5ee6277Sjasoni /* Size of on-disk inode. */
1396b78093aSpelikan #define EXT2_REV0_DINODE_SIZE	128
140976bae86Sotto #define EXT2_DINODE_SIZE(fs)	((fs)->e2fs.e2fs_rev > E2FS_REV0 ?  \
141976bae86Sotto 				    (fs)->e2fs.e2fs_inode_size : \
142976bae86Sotto 				    EXT2_REV0_DINODE_SIZE)
143f5ee6277Sjasoni 
1445ac2d602Sdownsj /*
1455ac2d602Sdownsj  * The e2di_blocks fields may be overlaid with other information for
1465ac2d602Sdownsj  * file types that do not have associated disk storage. Block
1475ac2d602Sdownsj  * and character devices overlay the first data block with their
1485ac2d602Sdownsj  * dev_t value. Short symbolic links place their path in the
1495ac2d602Sdownsj  * di_db area.
1505ac2d602Sdownsj  */
1515ac2d602Sdownsj 
1525ac2d602Sdownsj #define e2di_rdev		e2di_blocks[0]
1535ac2d602Sdownsj #define e2di_shortlink	e2di_blocks
154f5ee6277Sjasoni 
1556b38e8dfSart /* e2fs needs byte swapping on big-endian systems */
1566b38e8dfSart #if BYTE_ORDER == LITTLE_ENDIAN
157*d31d4a6eSpelikan #	define e2fs_iload(fs, old, new)	\
158*d31d4a6eSpelikan 		memcpy((new),(old), MIN(EXT2_DINODE_SIZE(fs), sizeof(*new)))
159*d31d4a6eSpelikan #	define e2fs_isave(fs, old, new) \
160*d31d4a6eSpelikan 		memcpy((new),(old), MIN(EXT2_DINODE_SIZE(fs), sizeof(*new)))
1616b38e8dfSart #else
162*d31d4a6eSpelikan struct m_ext2fs;
163*d31d4a6eSpelikan void e2fs_i_bswap(struct m_ext2fs *, struct ext2fs_dinode *, struct ext2fs_dinode *);
164*d31d4a6eSpelikan #	define e2fs_iload(fs, old, new) e2fs_i_bswap((fs), (old), (new))
165*d31d4a6eSpelikan #	define e2fs_isave(fs, old, new) e2fs_i_bswap((fs), (old), (new))
1666b38e8dfSart #endif
167