/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2009 Aditya Sarawgi4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#ifndef _FS_EXT2FS_EXT2_DIR_H_29#define _FS_EXT2FS_EXT2_DIR_H_3031/*32* Structure of a directory entry33*/34#define EXT2FS_MAXNAMLEN 2553536struct ext2fs_direct {37uint32_t e2d_ino; /* inode number of entry */38uint16_t e2d_reclen; /* length of this record */39uint16_t e2d_namlen; /* length of string in e2d_name */40char e2d_name[EXT2FS_MAXNAMLEN];/* name with length<=EXT2FS_MAXNAMLEN */41};4243enum slotstatus {44NONE,45COMPACT,46FOUND47};4849struct ext2fs_searchslot {50enum slotstatus slotstatus;51doff_t slotoffset; /* offset of area with free space */52int slotsize; /* size of area at slotoffset */53int slotfreespace; /* amount of space free in slot */54int slotneeded; /* sizeof the entry we are seeking */55};5657/*58* The new version of the directory entry. Since EXT2 structures are59* stored in intel byte order, and the name_len field could never be60* bigger than 255 chars, it's safe to reclaim the extra byte for the61* file_type field.62*/63struct ext2fs_direct_2 {64uint32_t e2d_ino; /* inode number of entry */65uint16_t e2d_reclen; /* length of this record */66uint8_t e2d_namlen; /* length of string in e2d_name */67uint8_t e2d_type; /* file type */68char e2d_name[EXT2FS_MAXNAMLEN]; /* name with69* length<=EXT2FS_MAXNAMLEN */70};7172struct ext2fs_direct_tail {73uint32_t e2dt_reserved_zero1; /* pretend to be unused */74uint16_t e2dt_rec_len; /* 12 */75uint8_t e2dt_reserved_zero2; /* zero name length */76uint8_t e2dt_reserved_ft; /* 0xDE, fake file type */77uint32_t e2dt_checksum; /* crc32c(uuid+inum+dirblock) */78};7980#define EXT2_FT_DIR_CSUM 0xDE8182#define EXT2_DIRENT_TAIL(data, blocksize) \83((struct ext2fs_direct_tail *)(((char *)(data)) + \84(blocksize) - sizeof(struct ext2fs_direct_tail)))8586/*87* Maximal count of links to a file88*/89#define EXT4_LINK_MAX 650009091/*92* Ext2 directory file types. Only the low 3 bits are used. The93* other bits are reserved for now.94*/95#define EXT2_FT_UNKNOWN 096#define EXT2_FT_REG_FILE 197#define EXT2_FT_DIR 298#define EXT2_FT_CHRDEV 399#define EXT2_FT_BLKDEV 4100#define EXT2_FT_FIFO 5101#define EXT2_FT_SOCK 6102#define EXT2_FT_SYMLINK 7103#define EXT2_FT_MAX 8104105/*106* EXT2_DIR_PAD defines the directory entries boundaries107*108* NOTE: It must be a multiple of 4109*/110#define EXT2_DIR_PAD 4111#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)112#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \113~EXT2_DIR_ROUND)114#endif /* !_FS_EXT2FS_EXT2_DIR_H_ */115116117