1*cfe60390STomohiro Kusumi /*- 2*cfe60390STomohiro Kusumi * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3*cfe60390STomohiro Kusumi * 4*cfe60390STomohiro Kusumi * Copyright (c) 2009 Aditya Sarawgi 5*cfe60390STomohiro Kusumi * All rights reserved. 6*cfe60390STomohiro Kusumi * 7*cfe60390STomohiro Kusumi * Redistribution and use in source and binary forms, with or without 8*cfe60390STomohiro Kusumi * modification, are permitted provided that the following conditions 9*cfe60390STomohiro Kusumi * are met: 10*cfe60390STomohiro Kusumi * 1. Redistributions of source code must retain the above copyright 11*cfe60390STomohiro Kusumi * notice, this list of conditions and the following disclaimer. 12*cfe60390STomohiro Kusumi * 2. Redistributions in binary form must reproduce the above copyright 13*cfe60390STomohiro Kusumi * notice, this list of conditions and the following disclaimer in the 14*cfe60390STomohiro Kusumi * documentation and/or other materials provided with the distribution. 15*cfe60390STomohiro Kusumi * 16*cfe60390STomohiro Kusumi * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17*cfe60390STomohiro Kusumi * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*cfe60390STomohiro Kusumi * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*cfe60390STomohiro Kusumi * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20*cfe60390STomohiro Kusumi * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*cfe60390STomohiro Kusumi * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*cfe60390STomohiro Kusumi * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*cfe60390STomohiro Kusumi * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*cfe60390STomohiro Kusumi * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*cfe60390STomohiro Kusumi * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*cfe60390STomohiro Kusumi * SUCH DAMAGE. 27*cfe60390STomohiro Kusumi * 28*cfe60390STomohiro Kusumi * $FreeBSD$ 29*cfe60390STomohiro Kusumi */ 30*cfe60390STomohiro Kusumi 31*cfe60390STomohiro Kusumi #ifndef _FS_EXT2FS_EXT2_DIR_H_ 32*cfe60390STomohiro Kusumi #define _FS_EXT2FS_EXT2_DIR_H_ 33*cfe60390STomohiro Kusumi 34*cfe60390STomohiro Kusumi /* 35*cfe60390STomohiro Kusumi * Structure of a directory entry 36*cfe60390STomohiro Kusumi */ 37*cfe60390STomohiro Kusumi #define EXT2FS_MAXNAMLEN 255 38*cfe60390STomohiro Kusumi 39*cfe60390STomohiro Kusumi struct ext2fs_direct { 40*cfe60390STomohiro Kusumi uint32_t e2d_ino; /* inode number of entry */ 41*cfe60390STomohiro Kusumi uint16_t e2d_reclen; /* length of this record */ 42*cfe60390STomohiro Kusumi uint16_t e2d_namlen; /* length of string in e2d_name */ 43*cfe60390STomohiro Kusumi char e2d_name[EXT2FS_MAXNAMLEN];/* name with length<=EXT2FS_MAXNAMLEN */ 44*cfe60390STomohiro Kusumi }; 45*cfe60390STomohiro Kusumi 46*cfe60390STomohiro Kusumi enum slotstatus { 47*cfe60390STomohiro Kusumi NONE, 48*cfe60390STomohiro Kusumi COMPACT, 49*cfe60390STomohiro Kusumi FOUND 50*cfe60390STomohiro Kusumi }; 51*cfe60390STomohiro Kusumi 52*cfe60390STomohiro Kusumi struct ext2fs_searchslot { 53*cfe60390STomohiro Kusumi enum slotstatus slotstatus; 54*cfe60390STomohiro Kusumi doff_t slotoffset; /* offset of area with free space */ 55*cfe60390STomohiro Kusumi int slotsize; /* size of area at slotoffset */ 56*cfe60390STomohiro Kusumi int slotfreespace; /* amount of space free in slot */ 57*cfe60390STomohiro Kusumi int slotneeded; /* sizeof the entry we are seeking */ 58*cfe60390STomohiro Kusumi }; 59*cfe60390STomohiro Kusumi 60*cfe60390STomohiro Kusumi /* 61*cfe60390STomohiro Kusumi * The new version of the directory entry. Since EXT2 structures are 62*cfe60390STomohiro Kusumi * stored in intel byte order, and the name_len field could never be 63*cfe60390STomohiro Kusumi * bigger than 255 chars, it's safe to reclaim the extra byte for the 64*cfe60390STomohiro Kusumi * file_type field. 65*cfe60390STomohiro Kusumi */ 66*cfe60390STomohiro Kusumi struct ext2fs_direct_2 { 67*cfe60390STomohiro Kusumi uint32_t e2d_ino; /* inode number of entry */ 68*cfe60390STomohiro Kusumi uint16_t e2d_reclen; /* length of this record */ 69*cfe60390STomohiro Kusumi uint8_t e2d_namlen; /* length of string in e2d_name */ 70*cfe60390STomohiro Kusumi uint8_t e2d_type; /* file type */ 71*cfe60390STomohiro Kusumi char e2d_name[EXT2FS_MAXNAMLEN]; /* name with 72*cfe60390STomohiro Kusumi * length<=EXT2FS_MAXNAMLEN */ 73*cfe60390STomohiro Kusumi }; 74*cfe60390STomohiro Kusumi 75*cfe60390STomohiro Kusumi struct ext2fs_direct_tail { 76*cfe60390STomohiro Kusumi uint32_t e2dt_reserved_zero1; /* pretend to be unused */ 77*cfe60390STomohiro Kusumi uint16_t e2dt_rec_len; /* 12 */ 78*cfe60390STomohiro Kusumi uint8_t e2dt_reserved_zero2; /* zero name length */ 79*cfe60390STomohiro Kusumi uint8_t e2dt_reserved_ft; /* 0xDE, fake file type */ 80*cfe60390STomohiro Kusumi uint32_t e2dt_checksum; /* crc32c(uuid+inum+dirblock) */ 81*cfe60390STomohiro Kusumi }; 82*cfe60390STomohiro Kusumi 83*cfe60390STomohiro Kusumi #define EXT2_FT_DIR_CSUM 0xDE 84*cfe60390STomohiro Kusumi 85*cfe60390STomohiro Kusumi #define EXT2_DIRENT_TAIL(data, blocksize) \ 86*cfe60390STomohiro Kusumi ((struct ext2fs_direct_tail *)(((char *)(data)) + \ 87*cfe60390STomohiro Kusumi (blocksize) - sizeof(struct ext2fs_direct_tail))) 88*cfe60390STomohiro Kusumi 89*cfe60390STomohiro Kusumi /* 90*cfe60390STomohiro Kusumi * Maximal count of links to a file 91*cfe60390STomohiro Kusumi */ 92*cfe60390STomohiro Kusumi #define EXT4_LINK_MAX 65000 93*cfe60390STomohiro Kusumi 94*cfe60390STomohiro Kusumi /* 95*cfe60390STomohiro Kusumi * Ext2 directory file types. Only the low 3 bits are used. The 96*cfe60390STomohiro Kusumi * other bits are reserved for now. 97*cfe60390STomohiro Kusumi */ 98*cfe60390STomohiro Kusumi #define EXT2_FT_UNKNOWN 0 99*cfe60390STomohiro Kusumi #define EXT2_FT_REG_FILE 1 100*cfe60390STomohiro Kusumi #define EXT2_FT_DIR 2 101*cfe60390STomohiro Kusumi #define EXT2_FT_CHRDEV 3 102*cfe60390STomohiro Kusumi #define EXT2_FT_BLKDEV 4 103*cfe60390STomohiro Kusumi #define EXT2_FT_FIFO 5 104*cfe60390STomohiro Kusumi #define EXT2_FT_SOCK 6 105*cfe60390STomohiro Kusumi #define EXT2_FT_SYMLINK 7 106*cfe60390STomohiro Kusumi #define EXT2_FT_MAX 8 107*cfe60390STomohiro Kusumi 108*cfe60390STomohiro Kusumi /* 109*cfe60390STomohiro Kusumi * EXT2_DIR_PAD defines the directory entries boundaries 110*cfe60390STomohiro Kusumi * 111*cfe60390STomohiro Kusumi * NOTE: It must be a multiple of 4 112*cfe60390STomohiro Kusumi */ 113*cfe60390STomohiro Kusumi #define EXT2_DIR_PAD 4 114*cfe60390STomohiro Kusumi #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1) 115*cfe60390STomohiro Kusumi #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \ 116*cfe60390STomohiro Kusumi ~EXT2_DIR_ROUND) 117*cfe60390STomohiro Kusumi #endif /* !_FS_EXT2FS_EXT2_DIR_H_ */ 118