/* ntfs.h - header for the NTFS filesystem */ /* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2007,2009 Free Software Foundation, Inc. * * VAS_EBOOT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VAS_EBOOT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAS_EBOOT. If not, see . */ #ifndef VAS_EBOOT_NTFS_H #define VAS_EBOOT_NTFS_H 1 enum { VAS_EBOOT_NTFS_FILE_MFT = 0, VAS_EBOOT_NTFS_FILE_MFTMIRR = 1, VAS_EBOOT_NTFS_FILE_LOGFILE = 2, VAS_EBOOT_NTFS_FILE_VOLUME = 3, VAS_EBOOT_NTFS_FILE_ATTRDEF = 4, VAS_EBOOT_NTFS_FILE_ROOT = 5, VAS_EBOOT_NTFS_FILE_BITMAP = 6, VAS_EBOOT_NTFS_FILE_BOOT = 7, VAS_EBOOT_NTFS_FILE_BADCLUS = 8, VAS_EBOOT_NTFS_FILE_QUOTA = 9, VAS_EBOOT_NTFS_FILE_UPCASE = 10, }; enum { VAS_EBOOT_NTFS_AT_STANDARD_INFORMATION = 0x10, VAS_EBOOT_NTFS_AT_ATTRIBUTE_LIST = 0x20, VAS_EBOOT_NTFS_AT_FILENAME = 0x30, VAS_EBOOT_NTFS_AT_OBJECT_ID = 0x40, VAS_EBOOT_NTFS_AT_SECURITY_DESCRIPTOR = 0x50, VAS_EBOOT_NTFS_AT_VOLUME_NAME = 0x60, VAS_EBOOT_NTFS_AT_VOLUME_INFORMATION = 0x70, VAS_EBOOT_NTFS_AT_DATA = 0x80, VAS_EBOOT_NTFS_AT_INDEX_ROOT = 0x90, VAS_EBOOT_NTFS_AT_INDEX_ALLOCATION = 0xA0, VAS_EBOOT_NTFS_AT_BITMAP = 0xB0, VAS_EBOOT_NTFS_AT_SYMLINK = 0xC0, VAS_EBOOT_NTFS_AT_EA_INFORMATION = 0xD0, VAS_EBOOT_NTFS_AT_EA = 0xE0, }; enum { VAS_EBOOT_NTFS_ATTR_READ_ONLY = 0x1, VAS_EBOOT_NTFS_ATTR_HIDDEN = 0x2, VAS_EBOOT_NTFS_ATTR_SYSTEM = 0x4, VAS_EBOOT_NTFS_ATTR_ARCHIVE = 0x20, VAS_EBOOT_NTFS_ATTR_DEVICE = 0x40, VAS_EBOOT_NTFS_ATTR_NORMAL = 0x80, VAS_EBOOT_NTFS_ATTR_TEMPORARY = 0x100, VAS_EBOOT_NTFS_ATTR_SPARSE = 0x200, VAS_EBOOT_NTFS_ATTR_REPARSE = 0x400, VAS_EBOOT_NTFS_ATTR_COMPRESSED = 0x800, VAS_EBOOT_NTFS_ATTR_OFFLINE = 0x1000, VAS_EBOOT_NTFS_ATTR_NOT_INDEXED = 0x2000, VAS_EBOOT_NTFS_ATTR_ENCRYPTED = 0x4000, VAS_EBOOT_NTFS_ATTR_DIRECTORY = 0x10000000, VAS_EBOOT_NTFS_ATTR_INDEX_VIEW = 0x20000000 }; enum { VAS_EBOOT_NTFS_FLAG_COMPRESSED = 1, VAS_EBOOT_NTFS_FLAG_ENCRYPTED = 0x4000, VAS_EBOOT_NTFS_FLAG_SPARSE = 0x8000 }; #define VAS_EBOOT_NTFS_BLK_SHR VAS_EBOOT_DISK_SECTOR_BITS #define VAS_EBOOT_NTFS_MAX_MFT (4096 >> VAS_EBOOT_NTFS_BLK_SHR) #define VAS_EBOOT_NTFS_MAX_IDX (16384 >> VAS_EBOOT_NTFS_BLK_SHR) #define VAS_EBOOT_NTFS_COM_LEN 4096 #define VAS_EBOOT_NTFS_COM_LOG_LEN 12 #define VAS_EBOOT_NTFS_COM_SEC (VAS_EBOOT_NTFS_COM_LEN >> VAS_EBOOT_NTFS_BLK_SHR) #define VAS_EBOOT_NTFS_LOG_COM_SEC (VAS_EBOOT_NTFS_COM_LOG_LEN - VAS_EBOOT_NTFS_BLK_SHR) #define VAS_EBOOT_NTFS_ATTRIBUTE_HEADER_SIZE 16 /* * To make attribute validation clearer the offsets for each value in the * attribute headers are defined as macros. * * These offsets are all from: * https://flatcap.github.io/linux-ntfs/ntfs/concepts/attribute_header.html */ /* These offsets are part of the attribute header. */ #define VAS_EBOOT_NTFS_ATTRIBUTE_LENGTH 4 #define VAS_EBOOT_NTFS_ATTRIBUTE_RESIDENT 8 #define VAS_EBOOT_NTFS_ATTRIBUTE_NAME_LENGTH 9 #define VAS_EBOOT_NTFS_ATTRIBUTE_NAME_OFFSET 10 /* Offsets for values needed for resident data. */ #define VAS_EBOOT_NTFS_ATTRIBUTE_RES_LENGTH 16 #define VAS_EBOOT_NTFS_ATTRIBUTE_RES_OFFSET 20 /* Offsets for values needed for non-resident data. */ #define VAS_EBOOT_NTFS_ATTRIBUTE_DATA_RUNS 32 #define VAS_EBOOT_NTFS_ATTRIBUTE_COMPRESSION_UNIT_SIZE 34 enum { VAS_EBOOT_NTFS_AF_ALST = 1, VAS_EBOOT_NTFS_AF_MMFT = 2, VAS_EBOOT_NTFS_AF_GPOS = 4, }; enum { VAS_EBOOT_NTFS_RF_BLNK = 1 }; struct VasEBoot_ntfs_bpb { VasEBoot_uint8_t jmp_boot[3]; VasEBoot_uint8_t oem_name[8]; VasEBoot_uint16_t bytes_per_sector; VasEBoot_uint8_t sectors_per_cluster; VasEBoot_uint8_t reserved_1[7]; VasEBoot_uint8_t media; VasEBoot_uint16_t reserved_2; VasEBoot_uint16_t sectors_per_track; VasEBoot_uint16_t num_heads; VasEBoot_uint32_t num_hidden_sectors; VasEBoot_uint32_t reserved_3; VasEBoot_uint8_t bios_drive; VasEBoot_uint8_t reserved_4[3]; VasEBoot_uint64_t num_total_sectors; VasEBoot_uint64_t mft_lcn; VasEBoot_uint64_t mft_mirr_lcn; VasEBoot_int8_t clusters_per_mft; VasEBoot_int8_t reserved_5[3]; VasEBoot_int8_t clusters_per_index; VasEBoot_int8_t reserved_6[3]; VasEBoot_uint64_t num_serial; VasEBoot_uint32_t checksum; } VAS_EBOOT_PACKED; struct VasEBoot_ntfs_attr { int flags; VasEBoot_uint8_t *emft_buf, *edat_buf; VasEBoot_uint8_t *attr_cur, *attr_nxt, *attr_end; VasEBoot_uint32_t save_pos; VasEBoot_uint8_t *sbuf; VasEBoot_uint8_t *end; struct VasEBoot_ntfs_file *mft; }; struct VasEBoot_ntfs_file { struct VasEBoot_ntfs_data *data; VasEBoot_uint8_t *buf; VasEBoot_uint64_t size; VasEBoot_uint64_t mtime; VasEBoot_uint64_t ino; int inode_read; struct VasEBoot_ntfs_attr attr; }; struct VasEBoot_ntfs_data { struct VasEBoot_ntfs_file cmft; struct VasEBoot_ntfs_file mmft; VasEBoot_disk_t disk; VasEBoot_uint64_t mft_size; VasEBoot_uint64_t idx_size; int log_spc; VasEBoot_uint64_t mft_start; VasEBoot_uint64_t uuid; }; struct VasEBoot_ntfs_comp_table_element { VasEBoot_uint32_t next_vcn; VasEBoot_uint32_t next_lcn; }; struct VasEBoot_ntfs_comp { VasEBoot_disk_t disk; int comp_head, comp_tail; struct VasEBoot_ntfs_comp_table_element comp_table[16]; VasEBoot_uint32_t cbuf_ofs, cbuf_vcn; int log_spc; VasEBoot_uint8_t *cbuf; }; struct VasEBoot_ntfs_rlst { int flags; VasEBoot_disk_addr_t target_vcn, curr_vcn, next_vcn, curr_lcn; VasEBoot_uint8_t *cur_run; struct VasEBoot_ntfs_attr *attr; struct VasEBoot_ntfs_comp comp; void *file; }; typedef VasEBoot_err_t (*VasEBoot_ntfscomp_func_t) (VasEBoot_uint8_t *dest, VasEBoot_disk_addr_t ofs, VasEBoot_size_t len, struct VasEBoot_ntfs_rlst * ctx); extern VasEBoot_ntfscomp_func_t VasEBoot_ntfscomp_func; VasEBoot_err_t VasEBoot_ntfs_read_run_list (struct VasEBoot_ntfs_rlst *ctx); #endif /* ! VAS_EBOOT_NTFS_H */