18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * volume.h - Defines for volume structures in NTFS Linux kernel driver. Part 48c2ecf20Sopenharmony_ci * of the Linux-NTFS project. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (c) 2001-2006 Anton Altaparmakov 78c2ecf20Sopenharmony_ci * Copyright (c) 2002 Richard Russon 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef _LINUX_NTFS_VOLUME_H 118c2ecf20Sopenharmony_ci#define _LINUX_NTFS_VOLUME_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/rwsem.h> 148c2ecf20Sopenharmony_ci#include <linux/uidgid.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include "types.h" 178c2ecf20Sopenharmony_ci#include "layout.h" 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* 208c2ecf20Sopenharmony_ci * The NTFS in memory super block structure. 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_citypedef struct { 238c2ecf20Sopenharmony_ci /* 248c2ecf20Sopenharmony_ci * FIXME: Reorder to have commonly used together element within the 258c2ecf20Sopenharmony_ci * same cache line, aiming at a cache line size of 32 bytes. Aim for 268c2ecf20Sopenharmony_ci * 64 bytes for less commonly used together elements. Put most commonly 278c2ecf20Sopenharmony_ci * used elements to front of structure. Obviously do this only when the 288c2ecf20Sopenharmony_ci * structure has stabilized... (AIA) 298c2ecf20Sopenharmony_ci */ 308c2ecf20Sopenharmony_ci /* Device specifics. */ 318c2ecf20Sopenharmony_ci struct super_block *sb; /* Pointer back to the super_block. */ 328c2ecf20Sopenharmony_ci LCN nr_blocks; /* Number of sb->s_blocksize bytes 338c2ecf20Sopenharmony_ci sized blocks on the device. */ 348c2ecf20Sopenharmony_ci /* Configuration provided by user at mount time. */ 358c2ecf20Sopenharmony_ci unsigned long flags; /* Miscellaneous flags, see below. */ 368c2ecf20Sopenharmony_ci kuid_t uid; /* uid that files will be mounted as. */ 378c2ecf20Sopenharmony_ci kgid_t gid; /* gid that files will be mounted as. */ 388c2ecf20Sopenharmony_ci umode_t fmask; /* The mask for file permissions. */ 398c2ecf20Sopenharmony_ci umode_t dmask; /* The mask for directory 408c2ecf20Sopenharmony_ci permissions. */ 418c2ecf20Sopenharmony_ci u8 mft_zone_multiplier; /* Initial mft zone multiplier. */ 428c2ecf20Sopenharmony_ci u8 on_errors; /* What to do on filesystem errors. */ 438c2ecf20Sopenharmony_ci /* NTFS bootsector provided information. */ 448c2ecf20Sopenharmony_ci u16 sector_size; /* in bytes */ 458c2ecf20Sopenharmony_ci u8 sector_size_bits; /* log2(sector_size) */ 468c2ecf20Sopenharmony_ci u32 cluster_size; /* in bytes */ 478c2ecf20Sopenharmony_ci u32 cluster_size_mask; /* cluster_size - 1 */ 488c2ecf20Sopenharmony_ci u8 cluster_size_bits; /* log2(cluster_size) */ 498c2ecf20Sopenharmony_ci u32 mft_record_size; /* in bytes */ 508c2ecf20Sopenharmony_ci u32 mft_record_size_mask; /* mft_record_size - 1 */ 518c2ecf20Sopenharmony_ci u8 mft_record_size_bits; /* log2(mft_record_size) */ 528c2ecf20Sopenharmony_ci u32 index_record_size; /* in bytes */ 538c2ecf20Sopenharmony_ci u32 index_record_size_mask; /* index_record_size - 1 */ 548c2ecf20Sopenharmony_ci u8 index_record_size_bits; /* log2(index_record_size) */ 558c2ecf20Sopenharmony_ci LCN nr_clusters; /* Volume size in clusters == number of 568c2ecf20Sopenharmony_ci bits in lcn bitmap. */ 578c2ecf20Sopenharmony_ci LCN mft_lcn; /* Cluster location of mft data. */ 588c2ecf20Sopenharmony_ci LCN mftmirr_lcn; /* Cluster location of copy of mft. */ 598c2ecf20Sopenharmony_ci u64 serial_no; /* The volume serial number. */ 608c2ecf20Sopenharmony_ci /* Mount specific NTFS information. */ 618c2ecf20Sopenharmony_ci u32 upcase_len; /* Number of entries in upcase[]. */ 628c2ecf20Sopenharmony_ci ntfschar *upcase; /* The upcase table. */ 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci s32 attrdef_size; /* Size of the attribute definition 658c2ecf20Sopenharmony_ci table in bytes. */ 668c2ecf20Sopenharmony_ci ATTR_DEF *attrdef; /* Table of attribute definitions. 678c2ecf20Sopenharmony_ci Obtained from FILE_AttrDef. */ 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#ifdef NTFS_RW 708c2ecf20Sopenharmony_ci /* Variables used by the cluster and mft allocators. */ 718c2ecf20Sopenharmony_ci s64 mft_data_pos; /* Mft record number at which to 728c2ecf20Sopenharmony_ci allocate the next mft record. */ 738c2ecf20Sopenharmony_ci LCN mft_zone_start; /* First cluster of the mft zone. */ 748c2ecf20Sopenharmony_ci LCN mft_zone_end; /* First cluster beyond the mft zone. */ 758c2ecf20Sopenharmony_ci LCN mft_zone_pos; /* Current position in the mft zone. */ 768c2ecf20Sopenharmony_ci LCN data1_zone_pos; /* Current position in the first data 778c2ecf20Sopenharmony_ci zone. */ 788c2ecf20Sopenharmony_ci LCN data2_zone_pos; /* Current position in the second data 798c2ecf20Sopenharmony_ci zone. */ 808c2ecf20Sopenharmony_ci#endif /* NTFS_RW */ 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci struct inode *mft_ino; /* The VFS inode of $MFT. */ 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci struct inode *mftbmp_ino; /* Attribute inode for $MFT/$BITMAP. */ 858c2ecf20Sopenharmony_ci struct rw_semaphore mftbmp_lock; /* Lock for serializing accesses to the 868c2ecf20Sopenharmony_ci mft record bitmap ($MFT/$BITMAP). */ 878c2ecf20Sopenharmony_ci#ifdef NTFS_RW 888c2ecf20Sopenharmony_ci struct inode *mftmirr_ino; /* The VFS inode of $MFTMirr. */ 898c2ecf20Sopenharmony_ci int mftmirr_size; /* Size of mft mirror in mft records. */ 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci struct inode *logfile_ino; /* The VFS inode of $LogFile. */ 928c2ecf20Sopenharmony_ci#endif /* NTFS_RW */ 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci struct inode *lcnbmp_ino; /* The VFS inode of $Bitmap. */ 958c2ecf20Sopenharmony_ci struct rw_semaphore lcnbmp_lock; /* Lock for serializing accesses to the 968c2ecf20Sopenharmony_ci cluster bitmap ($Bitmap/$DATA). */ 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci struct inode *vol_ino; /* The VFS inode of $Volume. */ 998c2ecf20Sopenharmony_ci VOLUME_FLAGS vol_flags; /* Volume flags. */ 1008c2ecf20Sopenharmony_ci u8 major_ver; /* Ntfs major version of volume. */ 1018c2ecf20Sopenharmony_ci u8 minor_ver; /* Ntfs minor version of volume. */ 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci struct inode *root_ino; /* The VFS inode of the root 1048c2ecf20Sopenharmony_ci directory. */ 1058c2ecf20Sopenharmony_ci struct inode *secure_ino; /* The VFS inode of $Secure (NTFS3.0+ 1068c2ecf20Sopenharmony_ci only, otherwise NULL). */ 1078c2ecf20Sopenharmony_ci struct inode *extend_ino; /* The VFS inode of $Extend (NTFS3.0+ 1088c2ecf20Sopenharmony_ci only, otherwise NULL). */ 1098c2ecf20Sopenharmony_ci#ifdef NTFS_RW 1108c2ecf20Sopenharmony_ci /* $Quota stuff is NTFS3.0+ specific. Unused/NULL otherwise. */ 1118c2ecf20Sopenharmony_ci struct inode *quota_ino; /* The VFS inode of $Quota. */ 1128c2ecf20Sopenharmony_ci struct inode *quota_q_ino; /* Attribute inode for $Quota/$Q. */ 1138c2ecf20Sopenharmony_ci /* $UsnJrnl stuff is NTFS3.0+ specific. Unused/NULL otherwise. */ 1148c2ecf20Sopenharmony_ci struct inode *usnjrnl_ino; /* The VFS inode of $UsnJrnl. */ 1158c2ecf20Sopenharmony_ci struct inode *usnjrnl_max_ino; /* Attribute inode for $UsnJrnl/$Max. */ 1168c2ecf20Sopenharmony_ci struct inode *usnjrnl_j_ino; /* Attribute inode for $UsnJrnl/$J. */ 1178c2ecf20Sopenharmony_ci#endif /* NTFS_RW */ 1188c2ecf20Sopenharmony_ci struct nls_table *nls_map; 1198c2ecf20Sopenharmony_ci} ntfs_volume; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci/* 1228c2ecf20Sopenharmony_ci * Defined bits for the flags field in the ntfs_volume structure. 1238c2ecf20Sopenharmony_ci */ 1248c2ecf20Sopenharmony_citypedef enum { 1258c2ecf20Sopenharmony_ci NV_Errors, /* 1: Volume has errors, prevent remount rw. */ 1268c2ecf20Sopenharmony_ci NV_ShowSystemFiles, /* 1: Return system files in ntfs_readdir(). */ 1278c2ecf20Sopenharmony_ci NV_CaseSensitive, /* 1: Treat file names as case sensitive and 1288c2ecf20Sopenharmony_ci create filenames in the POSIX namespace. 1298c2ecf20Sopenharmony_ci Otherwise be case insensitive but still 1308c2ecf20Sopenharmony_ci create file names in POSIX namespace. */ 1318c2ecf20Sopenharmony_ci NV_LogFileEmpty, /* 1: $LogFile journal is empty. */ 1328c2ecf20Sopenharmony_ci NV_QuotaOutOfDate, /* 1: $Quota is out of date. */ 1338c2ecf20Sopenharmony_ci NV_UsnJrnlStamped, /* 1: $UsnJrnl has been stamped. */ 1348c2ecf20Sopenharmony_ci NV_SparseEnabled, /* 1: May create sparse files. */ 1358c2ecf20Sopenharmony_ci} ntfs_volume_flags; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci/* 1388c2ecf20Sopenharmony_ci * Macro tricks to expand the NVolFoo(), NVolSetFoo(), and NVolClearFoo() 1398c2ecf20Sopenharmony_ci * functions. 1408c2ecf20Sopenharmony_ci */ 1418c2ecf20Sopenharmony_ci#define DEFINE_NVOL_BIT_OPS(flag) \ 1428c2ecf20Sopenharmony_cistatic inline int NVol##flag(ntfs_volume *vol) \ 1438c2ecf20Sopenharmony_ci{ \ 1448c2ecf20Sopenharmony_ci return test_bit(NV_##flag, &(vol)->flags); \ 1458c2ecf20Sopenharmony_ci} \ 1468c2ecf20Sopenharmony_cistatic inline void NVolSet##flag(ntfs_volume *vol) \ 1478c2ecf20Sopenharmony_ci{ \ 1488c2ecf20Sopenharmony_ci set_bit(NV_##flag, &(vol)->flags); \ 1498c2ecf20Sopenharmony_ci} \ 1508c2ecf20Sopenharmony_cistatic inline void NVolClear##flag(ntfs_volume *vol) \ 1518c2ecf20Sopenharmony_ci{ \ 1528c2ecf20Sopenharmony_ci clear_bit(NV_##flag, &(vol)->flags); \ 1538c2ecf20Sopenharmony_ci} 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci/* Emit the ntfs volume bitops functions. */ 1568c2ecf20Sopenharmony_ciDEFINE_NVOL_BIT_OPS(Errors) 1578c2ecf20Sopenharmony_ciDEFINE_NVOL_BIT_OPS(ShowSystemFiles) 1588c2ecf20Sopenharmony_ciDEFINE_NVOL_BIT_OPS(CaseSensitive) 1598c2ecf20Sopenharmony_ciDEFINE_NVOL_BIT_OPS(LogFileEmpty) 1608c2ecf20Sopenharmony_ciDEFINE_NVOL_BIT_OPS(QuotaOutOfDate) 1618c2ecf20Sopenharmony_ciDEFINE_NVOL_BIT_OPS(UsnJrnlStamped) 1628c2ecf20Sopenharmony_ciDEFINE_NVOL_BIT_OPS(SparseEnabled) 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci#endif /* _LINUX_NTFS_VOLUME_H */ 165