1e09c00caSUlf Lilleengen /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3d63027b6SPedro F. Giffuni * 4e09c00caSUlf Lilleengen * Copyright (c) 2009 Aditya Sarawgi 5e09c00caSUlf Lilleengen * All rights reserved. 6e09c00caSUlf Lilleengen * 7e09c00caSUlf Lilleengen * Redistribution and use in source and binary forms, with or without 8e09c00caSUlf Lilleengen * modification, are permitted provided that the following conditions 9e09c00caSUlf Lilleengen * are met: 10e09c00caSUlf Lilleengen * 1. Redistributions of source code must retain the above copyright 11e09c00caSUlf Lilleengen * notice, this list of conditions and the following disclaimer. 12e09c00caSUlf Lilleengen * 2. Redistributions in binary form must reproduce the above copyright 13e09c00caSUlf Lilleengen * notice, this list of conditions and the following disclaimer in the 14e09c00caSUlf Lilleengen * documentation and/or other materials provided with the distribution. 15e09c00caSUlf Lilleengen * 16e09c00caSUlf Lilleengen * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17e09c00caSUlf Lilleengen * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18e09c00caSUlf Lilleengen * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19e09c00caSUlf Lilleengen * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20e09c00caSUlf Lilleengen * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21e09c00caSUlf Lilleengen * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22e09c00caSUlf Lilleengen * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23e09c00caSUlf Lilleengen * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24e09c00caSUlf Lilleengen * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25e09c00caSUlf Lilleengen * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26e09c00caSUlf Lilleengen * SUCH DAMAGE. 27e09c00caSUlf Lilleengen */ 28e09c00caSUlf Lilleengen 29e09c00caSUlf Lilleengen #ifndef _FS_EXT2FS_EXT2_DIR_H_ 30e09c00caSUlf Lilleengen #define _FS_EXT2FS_EXT2_DIR_H_ 31e09c00caSUlf Lilleengen 32e09c00caSUlf Lilleengen /* 33e09c00caSUlf Lilleengen * Structure of a directory entry 34e09c00caSUlf Lilleengen */ 35e09c00caSUlf Lilleengen #define EXT2FS_MAXNAMLEN 255 36e09c00caSUlf Lilleengen 37e09c00caSUlf Lilleengen struct ext2fs_direct { 384d2ede67SJohn Baldwin uint32_t e2d_ino; /* inode number of entry */ 394d2ede67SJohn Baldwin uint16_t e2d_reclen; /* length of this record */ 40757224cbSPedro F. Giffuni uint16_t e2d_namlen; /* length of string in e2d_name */ 41e09c00caSUlf Lilleengen char e2d_name[EXT2FS_MAXNAMLEN];/* name with length<=EXT2FS_MAXNAMLEN */ 42e09c00caSUlf Lilleengen }; 439824e4adSPedro F. Giffuni 449824e4adSPedro F. Giffuni enum slotstatus { 459824e4adSPedro F. Giffuni NONE, 469824e4adSPedro F. Giffuni COMPACT, 479824e4adSPedro F. Giffuni FOUND 489824e4adSPedro F. Giffuni }; 499824e4adSPedro F. Giffuni 509824e4adSPedro F. Giffuni struct ext2fs_searchslot { 519824e4adSPedro F. Giffuni enum slotstatus slotstatus; 529824e4adSPedro F. Giffuni doff_t slotoffset; /* offset of area with free space */ 539824e4adSPedro F. Giffuni int slotsize; /* size of area at slotoffset */ 549824e4adSPedro F. Giffuni int slotfreespace; /* amount of space free in slot */ 559824e4adSPedro F. Giffuni int slotneeded; /* sizeof the entry we are seeking */ 569824e4adSPedro F. Giffuni }; 579824e4adSPedro F. Giffuni 58e09c00caSUlf Lilleengen /* 59e09c00caSUlf Lilleengen * The new version of the directory entry. Since EXT2 structures are 60e09c00caSUlf Lilleengen * stored in intel byte order, and the name_len field could never be 61e09c00caSUlf Lilleengen * bigger than 255 chars, it's safe to reclaim the extra byte for the 62e09c00caSUlf Lilleengen * file_type field. 63e09c00caSUlf Lilleengen */ 64e09c00caSUlf Lilleengen struct ext2fs_direct_2 { 654d2ede67SJohn Baldwin uint32_t e2d_ino; /* inode number of entry */ 664d2ede67SJohn Baldwin uint16_t e2d_reclen; /* length of this record */ 67757224cbSPedro F. Giffuni uint8_t e2d_namlen; /* length of string in e2d_name */ 684d2ede67SJohn Baldwin uint8_t e2d_type; /* file type */ 69bf9a211dSPedro F. Giffuni char e2d_name[EXT2FS_MAXNAMLEN]; /* name with 70bf9a211dSPedro F. Giffuni * length<=EXT2FS_MAXNAMLEN */ 71e09c00caSUlf Lilleengen }; 729e43acf6SPedro F. Giffuni 73512f29d1SFedor Uporov struct ext2fs_direct_tail { 74512f29d1SFedor Uporov uint32_t e2dt_reserved_zero1; /* pretend to be unused */ 75512f29d1SFedor Uporov uint16_t e2dt_rec_len; /* 12 */ 76512f29d1SFedor Uporov uint8_t e2dt_reserved_zero2; /* zero name length */ 77512f29d1SFedor Uporov uint8_t e2dt_reserved_ft; /* 0xDE, fake file type */ 78512f29d1SFedor Uporov uint32_t e2dt_checksum; /* crc32c(uuid+inum+dirblock) */ 79512f29d1SFedor Uporov }; 80512f29d1SFedor Uporov 81512f29d1SFedor Uporov #define EXT2_FT_DIR_CSUM 0xDE 82512f29d1SFedor Uporov 83512f29d1SFedor Uporov #define EXT2_DIRENT_TAIL(data, blocksize) \ 84512f29d1SFedor Uporov ((struct ext2fs_direct_tail *)(((char *)(data)) + \ 85512f29d1SFedor Uporov (blocksize) - sizeof(struct ext2fs_direct_tail))) 86512f29d1SFedor Uporov 879e43acf6SPedro F. Giffuni /* 889e43acf6SPedro F. Giffuni * Maximal count of links to a file 899e43acf6SPedro F. Giffuni */ 90a821bdcfSPedro F. Giffuni #define EXT4_LINK_MAX 65000 919e43acf6SPedro F. Giffuni 92e09c00caSUlf Lilleengen /* 93e09c00caSUlf Lilleengen * Ext2 directory file types. Only the low 3 bits are used. The 94e09c00caSUlf Lilleengen * other bits are reserved for now. 95e09c00caSUlf Lilleengen */ 96e09c00caSUlf Lilleengen #define EXT2_FT_UNKNOWN 0 97e09c00caSUlf Lilleengen #define EXT2_FT_REG_FILE 1 98e09c00caSUlf Lilleengen #define EXT2_FT_DIR 2 99e09c00caSUlf Lilleengen #define EXT2_FT_CHRDEV 3 100e09c00caSUlf Lilleengen #define EXT2_FT_BLKDEV 4 101e09c00caSUlf Lilleengen #define EXT2_FT_FIFO 5 102e09c00caSUlf Lilleengen #define EXT2_FT_SOCK 6 103e09c00caSUlf Lilleengen #define EXT2_FT_SYMLINK 7 104e09c00caSUlf Lilleengen #define EXT2_FT_MAX 8 105e09c00caSUlf Lilleengen 106e09c00caSUlf Lilleengen /* 107e09c00caSUlf Lilleengen * EXT2_DIR_PAD defines the directory entries boundaries 108e09c00caSUlf Lilleengen * 109e09c00caSUlf Lilleengen * NOTE: It must be a multiple of 4 110e09c00caSUlf Lilleengen */ 111e09c00caSUlf Lilleengen #define EXT2_DIR_PAD 4 112e09c00caSUlf Lilleengen #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1) 113e09c00caSUlf Lilleengen #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \ 114e09c00caSUlf Lilleengen ~EXT2_DIR_ROUND) 115e09c00caSUlf Lilleengen #endif /* !_FS_EXT2FS_EXT2_DIR_H_ */ 116