/* ntfs.h - header for the NTFS filesystem */ /* * VasEBoot -- GRand Unified Bootloader * Copyright (C) 2007,2009 Free Software Foundation, Inc. * * VasEBoot 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. * * VasEBoot 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 VasEBoot. If not, see . */ #ifndef VasEBoot_NTFS_H #define VasEBoot_NTFS_H 1 enum { VasEBoot_NTFS_FILE_MFT = 0, VasEBoot_NTFS_FILE_MFTMIRR = 1, VasEBoot_NTFS_FILE_LOGFILE = 2, VasEBoot_NTFS_FILE_VOLUME = 3, VasEBoot_NTFS_FILE_ATTRDEF = 4, VasEBoot_NTFS_FILE_ROOT = 5, VasEBoot_NTFS_FILE_BITMAP = 6, VasEBoot_NTFS_FILE_BOOT = 7, VasEBoot_NTFS_FILE_BADCLUS = 8, VasEBoot_NTFS_FILE_QUOTA = 9, VasEBoot_NTFS_FILE_UPCASE = 10, }; enum { VasEBoot_NTFS_AT_STANDARD_INFORMATION = 0x10, VasEBoot_NTFS_AT_ATTRIBUTE_LIST = 0x20, VasEBoot_NTFS_AT_FILENAME = 0x30, VasEBoot_NTFS_AT_OBJECT_ID = 0x40, VasEBoot_NTFS_AT_SECURITY_DESCRIPTOR = 0x50, VasEBoot_NTFS_AT_VOLUME_NAME = 0x60, VasEBoot_NTFS_AT_VOLUME_INFORMATION = 0x70, VasEBoot_NTFS_AT_DATA = 0x80, VasEBoot_NTFS_AT_INDEX_ROOT = 0x90, VasEBoot_NTFS_AT_INDEX_ALLOCATION = 0xA0, VasEBoot_NTFS_AT_BITMAP = 0xB0, VasEBoot_NTFS_AT_SYMLINK = 0xC0, VasEBoot_NTFS_AT_EA_INFORMATION = 0xD0, VasEBoot_NTFS_AT_EA = 0xE0, }; enum { VasEBoot_NTFS_ATTR_READ_ONLY = 0x1, VasEBoot_NTFS_ATTR_HIDDEN = 0x2, VasEBoot_NTFS_ATTR_SYSTEM = 0x4, VasEBoot_NTFS_ATTR_ARCHIVE = 0x20, VasEBoot_NTFS_ATTR_DEVICE = 0x40, VasEBoot_NTFS_ATTR_NORMAL = 0x80, VasEBoot_NTFS_ATTR_TEMPORARY = 0x100, VasEBoot_NTFS_ATTR_SPARSE = 0x200, VasEBoot_NTFS_ATTR_REPARSE = 0x400, VasEBoot_NTFS_ATTR_COMPRESSED = 0x800, VasEBoot_NTFS_ATTR_OFFLINE = 0x1000, VasEBoot_NTFS_ATTR_NOT_INDEXED = 0x2000, VasEBoot_NTFS_ATTR_ENCRYPTED = 0x4000, VasEBoot_NTFS_ATTR_DIRECTORY = 0x10000000, VasEBoot_NTFS_ATTR_INDEX_VIEW = 0x20000000 }; enum { VasEBoot_NTFS_FLAG_COMPRESSED = 1, VasEBoot_NTFS_FLAG_ENCRYPTED = 0x4000, VasEBoot_NTFS_FLAG_SPARSE = 0x8000 }; #define VasEBoot_NTFS_BLK_SHR VasEBoot_DISK_SECTOR_BITS #define VasEBoot_NTFS_MAX_MFT (4096 >> VasEBoot_NTFS_BLK_SHR) #define VasEBoot_NTFS_MAX_IDX (16384 >> VasEBoot_NTFS_BLK_SHR) #define VasEBoot_NTFS_COM_LEN 4096 #define VasEBoot_NTFS_COM_LOG_LEN 12 #define VasEBoot_NTFS_COM_SEC (VasEBoot_NTFS_COM_LEN >> VasEBoot_NTFS_BLK_SHR) #define VasEBoot_NTFS_LOG_COM_SEC (VasEBoot_NTFS_COM_LOG_LEN - VasEBoot_NTFS_BLK_SHR) enum { VasEBoot_NTFS_AF_ALST = 1, VasEBoot_NTFS_AF_MMFT = 2, VasEBoot_NTFS_AF_GPOS = 4, }; enum { VasEBoot_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; } VasEBoot_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; 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 /* ! VasEBoot_NTFS_H */