^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * volume.h - Defines for volume structures in NTFS Linux kernel driver. Part
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * of the Linux-NTFS project.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2001-2006 Anton Altaparmakov
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (c) 2002 Richard Russon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifndef _LINUX_NTFS_VOLUME_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define _LINUX_NTFS_VOLUME_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/rwsem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/uidgid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "types.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "layout.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * The NTFS in memory super block structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * FIXME: Reorder to have commonly used together element within the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * same cache line, aiming at a cache line size of 32 bytes. Aim for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * 64 bytes for less commonly used together elements. Put most commonly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * used elements to front of structure. Obviously do this only when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * structure has stabilized... (AIA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /* Device specifics. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct super_block *sb; /* Pointer back to the super_block. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) LCN nr_blocks; /* Number of sb->s_blocksize bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) sized blocks on the device. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* Configuration provided by user at mount time. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned long flags; /* Miscellaneous flags, see below. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) kuid_t uid; /* uid that files will be mounted as. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) kgid_t gid; /* gid that files will be mounted as. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) umode_t fmask; /* The mask for file permissions. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) umode_t dmask; /* The mask for directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) permissions. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u8 mft_zone_multiplier; /* Initial mft zone multiplier. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) u8 on_errors; /* What to do on filesystem errors. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* NTFS bootsector provided information. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) u16 sector_size; /* in bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) u8 sector_size_bits; /* log2(sector_size) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u32 cluster_size; /* in bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u32 cluster_size_mask; /* cluster_size - 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u8 cluster_size_bits; /* log2(cluster_size) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) u32 mft_record_size; /* in bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u32 mft_record_size_mask; /* mft_record_size - 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) u8 mft_record_size_bits; /* log2(mft_record_size) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u32 index_record_size; /* in bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) u32 index_record_size_mask; /* index_record_size - 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u8 index_record_size_bits; /* log2(index_record_size) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) LCN nr_clusters; /* Volume size in clusters == number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) bits in lcn bitmap. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) LCN mft_lcn; /* Cluster location of mft data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) LCN mftmirr_lcn; /* Cluster location of copy of mft. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) u64 serial_no; /* The volume serial number. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /* Mount specific NTFS information. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) u32 upcase_len; /* Number of entries in upcase[]. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ntfschar *upcase; /* The upcase table. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) s32 attrdef_size; /* Size of the attribute definition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) table in bytes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) ATTR_DEF *attrdef; /* Table of attribute definitions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) Obtained from FILE_AttrDef. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #ifdef NTFS_RW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* Variables used by the cluster and mft allocators. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) s64 mft_data_pos; /* Mft record number at which to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) allocate the next mft record. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) LCN mft_zone_start; /* First cluster of the mft zone. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) LCN mft_zone_end; /* First cluster beyond the mft zone. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) LCN mft_zone_pos; /* Current position in the mft zone. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) LCN data1_zone_pos; /* Current position in the first data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) zone. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) LCN data2_zone_pos; /* Current position in the second data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) zone. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #endif /* NTFS_RW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct inode *mft_ino; /* The VFS inode of $MFT. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct inode *mftbmp_ino; /* Attribute inode for $MFT/$BITMAP. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct rw_semaphore mftbmp_lock; /* Lock for serializing accesses to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) mft record bitmap ($MFT/$BITMAP). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #ifdef NTFS_RW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct inode *mftmirr_ino; /* The VFS inode of $MFTMirr. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) int mftmirr_size; /* Size of mft mirror in mft records. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct inode *logfile_ino; /* The VFS inode of $LogFile. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #endif /* NTFS_RW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct inode *lcnbmp_ino; /* The VFS inode of $Bitmap. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct rw_semaphore lcnbmp_lock; /* Lock for serializing accesses to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) cluster bitmap ($Bitmap/$DATA). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct inode *vol_ino; /* The VFS inode of $Volume. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) VOLUME_FLAGS vol_flags; /* Volume flags. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) u8 major_ver; /* Ntfs major version of volume. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) u8 minor_ver; /* Ntfs minor version of volume. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct inode *root_ino; /* The VFS inode of the root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) directory. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct inode *secure_ino; /* The VFS inode of $Secure (NTFS3.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) only, otherwise NULL). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct inode *extend_ino; /* The VFS inode of $Extend (NTFS3.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) only, otherwise NULL). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #ifdef NTFS_RW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /* $Quota stuff is NTFS3.0+ specific. Unused/NULL otherwise. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct inode *quota_ino; /* The VFS inode of $Quota. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct inode *quota_q_ino; /* Attribute inode for $Quota/$Q. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* $UsnJrnl stuff is NTFS3.0+ specific. Unused/NULL otherwise. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct inode *usnjrnl_ino; /* The VFS inode of $UsnJrnl. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct inode *usnjrnl_max_ino; /* Attribute inode for $UsnJrnl/$Max. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct inode *usnjrnl_j_ino; /* Attribute inode for $UsnJrnl/$J. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #endif /* NTFS_RW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct nls_table *nls_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) } ntfs_volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * Defined bits for the flags field in the ntfs_volume structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) typedef enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) NV_Errors, /* 1: Volume has errors, prevent remount rw. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) NV_ShowSystemFiles, /* 1: Return system files in ntfs_readdir(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) NV_CaseSensitive, /* 1: Treat file names as case sensitive and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) create filenames in the POSIX namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) Otherwise be case insensitive but still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) create file names in POSIX namespace. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) NV_LogFileEmpty, /* 1: $LogFile journal is empty. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) NV_QuotaOutOfDate, /* 1: $Quota is out of date. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) NV_UsnJrnlStamped, /* 1: $UsnJrnl has been stamped. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) NV_SparseEnabled, /* 1: May create sparse files. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) } ntfs_volume_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * Macro tricks to expand the NVolFoo(), NVolSetFoo(), and NVolClearFoo()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #define DEFINE_NVOL_BIT_OPS(flag) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static inline int NVol##flag(ntfs_volume *vol) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return test_bit(NV_##flag, &(vol)->flags); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static inline void NVolSet##flag(ntfs_volume *vol) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) set_bit(NV_##flag, &(vol)->flags); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static inline void NVolClear##flag(ntfs_volume *vol) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) clear_bit(NV_##flag, &(vol)->flags); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /* Emit the ntfs volume bitops functions. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) DEFINE_NVOL_BIT_OPS(Errors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) DEFINE_NVOL_BIT_OPS(ShowSystemFiles)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) DEFINE_NVOL_BIT_OPS(CaseSensitive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) DEFINE_NVOL_BIT_OPS(LogFileEmpty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) DEFINE_NVOL_BIT_OPS(QuotaOutOfDate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) DEFINE_NVOL_BIT_OPS(UsnJrnlStamped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) DEFINE_NVOL_BIT_OPS(SparseEnabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) #endif /* _LINUX_NTFS_VOLUME_H */