1*a1d312deSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * volume.h - Defines for volume structures in NTFS Linux kernel driver. Part 41da177e4SLinus Torvalds * of the Linux-NTFS project. 51da177e4SLinus Torvalds * 61cf3109fSAnton Altaparmakov * Copyright (c) 2001-2006 Anton Altaparmakov 71da177e4SLinus Torvalds * Copyright (c) 2002 Richard Russon 81da177e4SLinus Torvalds */ 91da177e4SLinus Torvalds 101da177e4SLinus Torvalds #ifndef _LINUX_NTFS_VOLUME_H 111da177e4SLinus Torvalds #define _LINUX_NTFS_VOLUME_H 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds #include <linux/rwsem.h> 14b29f7751SEric W. Biederman #include <linux/uidgid.h> 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #include "types.h" 171da177e4SLinus Torvalds #include "layout.h" 181da177e4SLinus Torvalds 191da177e4SLinus Torvalds /* 201da177e4SLinus Torvalds * The NTFS in memory super block structure. 211da177e4SLinus Torvalds */ 221da177e4SLinus Torvalds typedef struct { 231da177e4SLinus Torvalds /* 241da177e4SLinus Torvalds * FIXME: Reorder to have commonly used together element within the 251da177e4SLinus Torvalds * same cache line, aiming at a cache line size of 32 bytes. Aim for 261da177e4SLinus Torvalds * 64 bytes for less commonly used together elements. Put most commonly 271da177e4SLinus Torvalds * used elements to front of structure. Obviously do this only when the 281da177e4SLinus Torvalds * structure has stabilized... (AIA) 291da177e4SLinus Torvalds */ 301da177e4SLinus Torvalds /* Device specifics. */ 311cf3109fSAnton Altaparmakov struct super_block *sb; /* Pointer back to the super_block. */ 321cf3109fSAnton Altaparmakov LCN nr_blocks; /* Number of sb->s_blocksize bytes 331da177e4SLinus Torvalds sized blocks on the device. */ 341da177e4SLinus Torvalds /* Configuration provided by user at mount time. */ 351da177e4SLinus Torvalds unsigned long flags; /* Miscellaneous flags, see below. */ 36b29f7751SEric W. Biederman kuid_t uid; /* uid that files will be mounted as. */ 37b29f7751SEric W. Biederman kgid_t gid; /* gid that files will be mounted as. */ 38d0c00d06SAl Viro umode_t fmask; /* The mask for file permissions. */ 39d0c00d06SAl Viro umode_t dmask; /* The mask for directory 401da177e4SLinus Torvalds permissions. */ 411da177e4SLinus Torvalds u8 mft_zone_multiplier; /* Initial mft zone multiplier. */ 421da177e4SLinus Torvalds u8 on_errors; /* What to do on filesystem errors. */ 431da177e4SLinus Torvalds /* NTFS bootsector provided information. */ 441da177e4SLinus Torvalds u16 sector_size; /* in bytes */ 451da177e4SLinus Torvalds u8 sector_size_bits; /* log2(sector_size) */ 461da177e4SLinus Torvalds u32 cluster_size; /* in bytes */ 471da177e4SLinus Torvalds u32 cluster_size_mask; /* cluster_size - 1 */ 481da177e4SLinus Torvalds u8 cluster_size_bits; /* log2(cluster_size) */ 491da177e4SLinus Torvalds u32 mft_record_size; /* in bytes */ 501da177e4SLinus Torvalds u32 mft_record_size_mask; /* mft_record_size - 1 */ 511da177e4SLinus Torvalds u8 mft_record_size_bits; /* log2(mft_record_size) */ 521da177e4SLinus Torvalds u32 index_record_size; /* in bytes */ 531da177e4SLinus Torvalds u32 index_record_size_mask; /* index_record_size - 1 */ 541da177e4SLinus Torvalds u8 index_record_size_bits; /* log2(index_record_size) */ 551da177e4SLinus Torvalds LCN nr_clusters; /* Volume size in clusters == number of 561da177e4SLinus Torvalds bits in lcn bitmap. */ 571da177e4SLinus Torvalds LCN mft_lcn; /* Cluster location of mft data. */ 581da177e4SLinus Torvalds LCN mftmirr_lcn; /* Cluster location of copy of mft. */ 591da177e4SLinus Torvalds u64 serial_no; /* The volume serial number. */ 601da177e4SLinus Torvalds /* Mount specific NTFS information. */ 611da177e4SLinus Torvalds u32 upcase_len; /* Number of entries in upcase[]. */ 621da177e4SLinus Torvalds ntfschar *upcase; /* The upcase table. */ 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds s32 attrdef_size; /* Size of the attribute definition 651da177e4SLinus Torvalds table in bytes. */ 661da177e4SLinus Torvalds ATTR_DEF *attrdef; /* Table of attribute definitions. 671da177e4SLinus Torvalds Obtained from FILE_AttrDef. */ 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds #ifdef NTFS_RW 701da177e4SLinus Torvalds /* Variables used by the cluster and mft allocators. */ 711da177e4SLinus Torvalds s64 mft_data_pos; /* Mft record number at which to 721da177e4SLinus Torvalds allocate the next mft record. */ 731da177e4SLinus Torvalds LCN mft_zone_start; /* First cluster of the mft zone. */ 741da177e4SLinus Torvalds LCN mft_zone_end; /* First cluster beyond the mft zone. */ 751da177e4SLinus Torvalds LCN mft_zone_pos; /* Current position in the mft zone. */ 761da177e4SLinus Torvalds LCN data1_zone_pos; /* Current position in the first data 771da177e4SLinus Torvalds zone. */ 781da177e4SLinus Torvalds LCN data2_zone_pos; /* Current position in the second data 791da177e4SLinus Torvalds zone. */ 801da177e4SLinus Torvalds #endif /* NTFS_RW */ 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds struct inode *mft_ino; /* The VFS inode of $MFT. */ 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds struct inode *mftbmp_ino; /* Attribute inode for $MFT/$BITMAP. */ 851da177e4SLinus Torvalds struct rw_semaphore mftbmp_lock; /* Lock for serializing accesses to the 861da177e4SLinus Torvalds mft record bitmap ($MFT/$BITMAP). */ 871da177e4SLinus Torvalds #ifdef NTFS_RW 881da177e4SLinus Torvalds struct inode *mftmirr_ino; /* The VFS inode of $MFTMirr. */ 891da177e4SLinus Torvalds int mftmirr_size; /* Size of mft mirror in mft records. */ 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds struct inode *logfile_ino; /* The VFS inode of $LogFile. */ 921da177e4SLinus Torvalds #endif /* NTFS_RW */ 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds struct inode *lcnbmp_ino; /* The VFS inode of $Bitmap. */ 951da177e4SLinus Torvalds struct rw_semaphore lcnbmp_lock; /* Lock for serializing accesses to the 961da177e4SLinus Torvalds cluster bitmap ($Bitmap/$DATA). */ 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds struct inode *vol_ino; /* The VFS inode of $Volume. */ 991da177e4SLinus Torvalds VOLUME_FLAGS vol_flags; /* Volume flags. */ 1001da177e4SLinus Torvalds u8 major_ver; /* Ntfs major version of volume. */ 1011da177e4SLinus Torvalds u8 minor_ver; /* Ntfs minor version of volume. */ 1021da177e4SLinus Torvalds 1031da177e4SLinus Torvalds struct inode *root_ino; /* The VFS inode of the root 1041da177e4SLinus Torvalds directory. */ 1051da177e4SLinus Torvalds struct inode *secure_ino; /* The VFS inode of $Secure (NTFS3.0+ 1061da177e4SLinus Torvalds only, otherwise NULL). */ 1071da177e4SLinus Torvalds struct inode *extend_ino; /* The VFS inode of $Extend (NTFS3.0+ 1081da177e4SLinus Torvalds only, otherwise NULL). */ 1091da177e4SLinus Torvalds #ifdef NTFS_RW 1101da177e4SLinus Torvalds /* $Quota stuff is NTFS3.0+ specific. Unused/NULL otherwise. */ 1111da177e4SLinus Torvalds struct inode *quota_ino; /* The VFS inode of $Quota. */ 1121da177e4SLinus Torvalds struct inode *quota_q_ino; /* Attribute inode for $Quota/$Q. */ 1133f2faef0SAnton Altaparmakov /* $UsnJrnl stuff is NTFS3.0+ specific. Unused/NULL otherwise. */ 1143f2faef0SAnton Altaparmakov struct inode *usnjrnl_ino; /* The VFS inode of $UsnJrnl. */ 1153f2faef0SAnton Altaparmakov struct inode *usnjrnl_max_ino; /* Attribute inode for $UsnJrnl/$Max. */ 1163f2faef0SAnton Altaparmakov struct inode *usnjrnl_j_ino; /* Attribute inode for $UsnJrnl/$J. */ 1171da177e4SLinus Torvalds #endif /* NTFS_RW */ 1181da177e4SLinus Torvalds struct nls_table *nls_map; 1191da177e4SLinus Torvalds } ntfs_volume; 1201da177e4SLinus Torvalds 1211da177e4SLinus Torvalds /* 1221da177e4SLinus Torvalds * Defined bits for the flags field in the ntfs_volume structure. 1231da177e4SLinus Torvalds */ 1241da177e4SLinus Torvalds typedef enum { 1251da177e4SLinus Torvalds NV_Errors, /* 1: Volume has errors, prevent remount rw. */ 1261da177e4SLinus Torvalds NV_ShowSystemFiles, /* 1: Return system files in ntfs_readdir(). */ 1271da177e4SLinus Torvalds NV_CaseSensitive, /* 1: Treat file names as case sensitive and 1281da177e4SLinus Torvalds create filenames in the POSIX namespace. 1291cf3109fSAnton Altaparmakov Otherwise be case insensitive but still 1301cf3109fSAnton Altaparmakov create file names in POSIX namespace. */ 1311da177e4SLinus Torvalds NV_LogFileEmpty, /* 1: $LogFile journal is empty. */ 1321da177e4SLinus Torvalds NV_QuotaOutOfDate, /* 1: $Quota is out of date. */ 1333f2faef0SAnton Altaparmakov NV_UsnJrnlStamped, /* 1: $UsnJrnl has been stamped. */ 134c002f425SAnton Altaparmakov NV_SparseEnabled, /* 1: May create sparse files. */ 1351da177e4SLinus Torvalds } ntfs_volume_flags; 1361da177e4SLinus Torvalds 1371da177e4SLinus Torvalds /* 1381da177e4SLinus Torvalds * Macro tricks to expand the NVolFoo(), NVolSetFoo(), and NVolClearFoo() 1391da177e4SLinus Torvalds * functions. 1401da177e4SLinus Torvalds */ 1411cf3109fSAnton Altaparmakov #define DEFINE_NVOL_BIT_OPS(flag) \ 1421da177e4SLinus Torvalds static inline int NVol##flag(ntfs_volume *vol) \ 1431da177e4SLinus Torvalds { \ 1441da177e4SLinus Torvalds return test_bit(NV_##flag, &(vol)->flags); \ 1451da177e4SLinus Torvalds } \ 1461da177e4SLinus Torvalds static inline void NVolSet##flag(ntfs_volume *vol) \ 1471da177e4SLinus Torvalds { \ 1481da177e4SLinus Torvalds set_bit(NV_##flag, &(vol)->flags); \ 1491da177e4SLinus Torvalds } \ 1501da177e4SLinus Torvalds static inline void NVolClear##flag(ntfs_volume *vol) \ 1511da177e4SLinus Torvalds { \ 1521da177e4SLinus Torvalds clear_bit(NV_##flag, &(vol)->flags); \ 1531da177e4SLinus Torvalds } 1541da177e4SLinus Torvalds 1551da177e4SLinus Torvalds /* Emit the ntfs volume bitops functions. */ 1561cf3109fSAnton Altaparmakov DEFINE_NVOL_BIT_OPS(Errors) 1571cf3109fSAnton Altaparmakov DEFINE_NVOL_BIT_OPS(ShowSystemFiles) 1581cf3109fSAnton Altaparmakov DEFINE_NVOL_BIT_OPS(CaseSensitive) 1591cf3109fSAnton Altaparmakov DEFINE_NVOL_BIT_OPS(LogFileEmpty) 1601cf3109fSAnton Altaparmakov DEFINE_NVOL_BIT_OPS(QuotaOutOfDate) 1611cf3109fSAnton Altaparmakov DEFINE_NVOL_BIT_OPS(UsnJrnlStamped) 1621cf3109fSAnton Altaparmakov DEFINE_NVOL_BIT_OPS(SparseEnabled) 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds #endif /* _LINUX_NTFS_VOLUME_H */ 165