1202283Slulf/*-
2202283Slulf * Copyright (c) 2009 Aditya Sarawgi
3202283Slulf * All rights reserved.
4202283Slulf *
5202283Slulf * Redistribution and use in source and binary forms, with or without
6202283Slulf * modification, are permitted provided that the following conditions
7202283Slulf * are met:
8202283Slulf * 1. Redistributions of source code must retain the above copyright
9202283Slulf *    notice, this list of conditions and the following disclaimer.
10202283Slulf * 2. Redistributions in binary form must reproduce the above copyright
11202283Slulf *    notice, this list of conditions and the following disclaimer in the
12202283Slulf *    documentation and/or other materials provided with the distribution.
13202283Slulf *
14202283Slulf * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15202283Slulf * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16202283Slulf * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17202283Slulf * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18202283Slulf * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19202283Slulf * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20202283Slulf * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21202283Slulf * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22202283Slulf * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23202283Slulf * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24202283Slulf * SUCH DAMAGE.
25202283Slulf *
26202283Slulf * $FreeBSD: releng/10.2/sys/fs/ext2fs/ext2_dir.h 281841 2015-04-22 00:38:11Z pfg $
27202283Slulf */
28202283Slulf
29202283Slulf#ifndef _FS_EXT2FS_EXT2_DIR_H_
30262723Spfg#define	_FS_EXT2FS_EXT2_DIR_H_
31202283Slulf
32202283Slulf/*
33202283Slulf * Structure of a directory entry
34202283Slulf */
35262723Spfg#define	EXT2FS_MAXNAMLEN	255
36202283Slulf
37202283Slulfstruct	ext2fs_direct {
38221126Sjhb	uint32_t e2d_ino;		/* inode number of entry */
39221126Sjhb	uint16_t e2d_reclen;		/* length of this record */
40246258Spfg	uint16_t e2d_namlen;		/* length of string in e2d_name */
41202283Slulf	char e2d_name[EXT2FS_MAXNAMLEN];/* name with length<=EXT2FS_MAXNAMLEN */
42202283Slulf};
43202283Slulf/*
44202283Slulf * The new version of the directory entry.  Since EXT2 structures are
45202283Slulf * stored in intel byte order, and the name_len field could never be
46202283Slulf * bigger than 255 chars, it's safe to reclaim the extra byte for the
47202283Slulf * file_type field.
48202283Slulf */
49202283Slulfstruct	ext2fs_direct_2 {
50221126Sjhb	uint32_t e2d_ino;		/* inode number of entry */
51221126Sjhb	uint16_t e2d_reclen;		/* length of this record */
52246258Spfg	uint8_t e2d_namlen;		/* length of string in e2d_name */
53221126Sjhb	uint8_t e2d_type;		/* file type */
54202283Slulf	char e2d_name[EXT2FS_MAXNAMLEN];/* name with length<=EXT2FS_MAXNAMLEN */
55202283Slulf};
56251952Spfg
57202283Slulf/*
58251952Spfg * Maximal count of links to a file
59251952Spfg */
60262723Spfg#define	EXT2_LINK_MAX	32000
61251952Spfg
62251952Spfg/*
63202283Slulf * Ext2 directory file types.  Only the low 3 bits are used.  The
64202283Slulf * other bits are reserved for now.
65202283Slulf */
66262723Spfg#define	EXT2_FT_UNKNOWN		0
67262723Spfg#define	EXT2_FT_REG_FILE	1
68262723Spfg#define	EXT2_FT_DIR		2
69262723Spfg#define	EXT2_FT_CHRDEV		3
70262723Spfg#define	EXT2_FT_BLKDEV 		4
71262723Spfg#define	EXT2_FT_FIFO		5
72262723Spfg#define	EXT2_FT_SOCK		6
73262723Spfg#define	EXT2_FT_SYMLINK		7
74262723Spfg#define	EXT2_FT_MAX		8
75202283Slulf
76202283Slulf/*
77202283Slulf * EXT2_DIR_PAD defines the directory entries boundaries
78202283Slulf *
79202283Slulf * NOTE: It must be a multiple of 4
80202283Slulf */
81262723Spfg#define	EXT2_DIR_PAD		 	4
82262723Spfg#define	EXT2_DIR_ROUND			(EXT2_DIR_PAD - 1)
83262723Spfg#define	EXT2_DIR_REC_LEN(name_len)	(((name_len) + 8 + EXT2_DIR_ROUND) & \
84202283Slulf					 ~EXT2_DIR_ROUND)
85202283Slulf#endif /* !_FS_EXT2FS_EXT2_DIR_H_ */
86202283Slulf
87