162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * volume.h - Defines for volume structures in NTFS Linux kernel driver. Part 462306a36Sopenharmony_ci * of the Linux-NTFS project. 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Copyright (c) 2001-2006 Anton Altaparmakov 762306a36Sopenharmony_ci * Copyright (c) 2002 Richard Russon 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#ifndef _LINUX_NTFS_VOLUME_H 1162306a36Sopenharmony_ci#define _LINUX_NTFS_VOLUME_H 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#include <linux/rwsem.h> 1462306a36Sopenharmony_ci#include <linux/uidgid.h> 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#include "types.h" 1762306a36Sopenharmony_ci#include "layout.h" 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* 2062306a36Sopenharmony_ci * The NTFS in memory super block structure. 2162306a36Sopenharmony_ci */ 2262306a36Sopenharmony_citypedef struct { 2362306a36Sopenharmony_ci /* 2462306a36Sopenharmony_ci * FIXME: Reorder to have commonly used together element within the 2562306a36Sopenharmony_ci * same cache line, aiming at a cache line size of 32 bytes. Aim for 2662306a36Sopenharmony_ci * 64 bytes for less commonly used together elements. Put most commonly 2762306a36Sopenharmony_ci * used elements to front of structure. Obviously do this only when the 2862306a36Sopenharmony_ci * structure has stabilized... (AIA) 2962306a36Sopenharmony_ci */ 3062306a36Sopenharmony_ci /* Device specifics. */ 3162306a36Sopenharmony_ci struct super_block *sb; /* Pointer back to the super_block. */ 3262306a36Sopenharmony_ci LCN nr_blocks; /* Number of sb->s_blocksize bytes 3362306a36Sopenharmony_ci sized blocks on the device. */ 3462306a36Sopenharmony_ci /* Configuration provided by user at mount time. */ 3562306a36Sopenharmony_ci unsigned long flags; /* Miscellaneous flags, see below. */ 3662306a36Sopenharmony_ci kuid_t uid; /* uid that files will be mounted as. */ 3762306a36Sopenharmony_ci kgid_t gid; /* gid that files will be mounted as. */ 3862306a36Sopenharmony_ci umode_t fmask; /* The mask for file permissions. */ 3962306a36Sopenharmony_ci umode_t dmask; /* The mask for directory 4062306a36Sopenharmony_ci permissions. */ 4162306a36Sopenharmony_ci u8 mft_zone_multiplier; /* Initial mft zone multiplier. */ 4262306a36Sopenharmony_ci u8 on_errors; /* What to do on filesystem errors. */ 4362306a36Sopenharmony_ci /* NTFS bootsector provided information. */ 4462306a36Sopenharmony_ci u16 sector_size; /* in bytes */ 4562306a36Sopenharmony_ci u8 sector_size_bits; /* log2(sector_size) */ 4662306a36Sopenharmony_ci u32 cluster_size; /* in bytes */ 4762306a36Sopenharmony_ci u32 cluster_size_mask; /* cluster_size - 1 */ 4862306a36Sopenharmony_ci u8 cluster_size_bits; /* log2(cluster_size) */ 4962306a36Sopenharmony_ci u32 mft_record_size; /* in bytes */ 5062306a36Sopenharmony_ci u32 mft_record_size_mask; /* mft_record_size - 1 */ 5162306a36Sopenharmony_ci u8 mft_record_size_bits; /* log2(mft_record_size) */ 5262306a36Sopenharmony_ci u32 index_record_size; /* in bytes */ 5362306a36Sopenharmony_ci u32 index_record_size_mask; /* index_record_size - 1 */ 5462306a36Sopenharmony_ci u8 index_record_size_bits; /* log2(index_record_size) */ 5562306a36Sopenharmony_ci LCN nr_clusters; /* Volume size in clusters == number of 5662306a36Sopenharmony_ci bits in lcn bitmap. */ 5762306a36Sopenharmony_ci LCN mft_lcn; /* Cluster location of mft data. */ 5862306a36Sopenharmony_ci LCN mftmirr_lcn; /* Cluster location of copy of mft. */ 5962306a36Sopenharmony_ci u64 serial_no; /* The volume serial number. */ 6062306a36Sopenharmony_ci /* Mount specific NTFS information. */ 6162306a36Sopenharmony_ci u32 upcase_len; /* Number of entries in upcase[]. */ 6262306a36Sopenharmony_ci ntfschar *upcase; /* The upcase table. */ 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci s32 attrdef_size; /* Size of the attribute definition 6562306a36Sopenharmony_ci table in bytes. */ 6662306a36Sopenharmony_ci ATTR_DEF *attrdef; /* Table of attribute definitions. 6762306a36Sopenharmony_ci Obtained from FILE_AttrDef. */ 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci#ifdef NTFS_RW 7062306a36Sopenharmony_ci /* Variables used by the cluster and mft allocators. */ 7162306a36Sopenharmony_ci s64 mft_data_pos; /* Mft record number at which to 7262306a36Sopenharmony_ci allocate the next mft record. */ 7362306a36Sopenharmony_ci LCN mft_zone_start; /* First cluster of the mft zone. */ 7462306a36Sopenharmony_ci LCN mft_zone_end; /* First cluster beyond the mft zone. */ 7562306a36Sopenharmony_ci LCN mft_zone_pos; /* Current position in the mft zone. */ 7662306a36Sopenharmony_ci LCN data1_zone_pos; /* Current position in the first data 7762306a36Sopenharmony_ci zone. */ 7862306a36Sopenharmony_ci LCN data2_zone_pos; /* Current position in the second data 7962306a36Sopenharmony_ci zone. */ 8062306a36Sopenharmony_ci#endif /* NTFS_RW */ 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci struct inode *mft_ino; /* The VFS inode of $MFT. */ 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci struct inode *mftbmp_ino; /* Attribute inode for $MFT/$BITMAP. */ 8562306a36Sopenharmony_ci struct rw_semaphore mftbmp_lock; /* Lock for serializing accesses to the 8662306a36Sopenharmony_ci mft record bitmap ($MFT/$BITMAP). */ 8762306a36Sopenharmony_ci#ifdef NTFS_RW 8862306a36Sopenharmony_ci struct inode *mftmirr_ino; /* The VFS inode of $MFTMirr. */ 8962306a36Sopenharmony_ci int mftmirr_size; /* Size of mft mirror in mft records. */ 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci struct inode *logfile_ino; /* The VFS inode of $LogFile. */ 9262306a36Sopenharmony_ci#endif /* NTFS_RW */ 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci struct inode *lcnbmp_ino; /* The VFS inode of $Bitmap. */ 9562306a36Sopenharmony_ci struct rw_semaphore lcnbmp_lock; /* Lock for serializing accesses to the 9662306a36Sopenharmony_ci cluster bitmap ($Bitmap/$DATA). */ 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci struct inode *vol_ino; /* The VFS inode of $Volume. */ 9962306a36Sopenharmony_ci VOLUME_FLAGS vol_flags; /* Volume flags. */ 10062306a36Sopenharmony_ci u8 major_ver; /* Ntfs major version of volume. */ 10162306a36Sopenharmony_ci u8 minor_ver; /* Ntfs minor version of volume. */ 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci struct inode *root_ino; /* The VFS inode of the root 10462306a36Sopenharmony_ci directory. */ 10562306a36Sopenharmony_ci struct inode *secure_ino; /* The VFS inode of $Secure (NTFS3.0+ 10662306a36Sopenharmony_ci only, otherwise NULL). */ 10762306a36Sopenharmony_ci struct inode *extend_ino; /* The VFS inode of $Extend (NTFS3.0+ 10862306a36Sopenharmony_ci only, otherwise NULL). */ 10962306a36Sopenharmony_ci#ifdef NTFS_RW 11062306a36Sopenharmony_ci /* $Quota stuff is NTFS3.0+ specific. Unused/NULL otherwise. */ 11162306a36Sopenharmony_ci struct inode *quota_ino; /* The VFS inode of $Quota. */ 11262306a36Sopenharmony_ci struct inode *quota_q_ino; /* Attribute inode for $Quota/$Q. */ 11362306a36Sopenharmony_ci /* $UsnJrnl stuff is NTFS3.0+ specific. Unused/NULL otherwise. */ 11462306a36Sopenharmony_ci struct inode *usnjrnl_ino; /* The VFS inode of $UsnJrnl. */ 11562306a36Sopenharmony_ci struct inode *usnjrnl_max_ino; /* Attribute inode for $UsnJrnl/$Max. */ 11662306a36Sopenharmony_ci struct inode *usnjrnl_j_ino; /* Attribute inode for $UsnJrnl/$J. */ 11762306a36Sopenharmony_ci#endif /* NTFS_RW */ 11862306a36Sopenharmony_ci struct nls_table *nls_map; 11962306a36Sopenharmony_ci} ntfs_volume; 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci/* 12262306a36Sopenharmony_ci * Defined bits for the flags field in the ntfs_volume structure. 12362306a36Sopenharmony_ci */ 12462306a36Sopenharmony_citypedef enum { 12562306a36Sopenharmony_ci NV_Errors, /* 1: Volume has errors, prevent remount rw. */ 12662306a36Sopenharmony_ci NV_ShowSystemFiles, /* 1: Return system files in ntfs_readdir(). */ 12762306a36Sopenharmony_ci NV_CaseSensitive, /* 1: Treat file names as case sensitive and 12862306a36Sopenharmony_ci create filenames in the POSIX namespace. 12962306a36Sopenharmony_ci Otherwise be case insensitive but still 13062306a36Sopenharmony_ci create file names in POSIX namespace. */ 13162306a36Sopenharmony_ci NV_LogFileEmpty, /* 1: $LogFile journal is empty. */ 13262306a36Sopenharmony_ci NV_QuotaOutOfDate, /* 1: $Quota is out of date. */ 13362306a36Sopenharmony_ci NV_UsnJrnlStamped, /* 1: $UsnJrnl has been stamped. */ 13462306a36Sopenharmony_ci NV_SparseEnabled, /* 1: May create sparse files. */ 13562306a36Sopenharmony_ci} ntfs_volume_flags; 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci/* 13862306a36Sopenharmony_ci * Macro tricks to expand the NVolFoo(), NVolSetFoo(), and NVolClearFoo() 13962306a36Sopenharmony_ci * functions. 14062306a36Sopenharmony_ci */ 14162306a36Sopenharmony_ci#define DEFINE_NVOL_BIT_OPS(flag) \ 14262306a36Sopenharmony_cistatic inline int NVol##flag(ntfs_volume *vol) \ 14362306a36Sopenharmony_ci{ \ 14462306a36Sopenharmony_ci return test_bit(NV_##flag, &(vol)->flags); \ 14562306a36Sopenharmony_ci} \ 14662306a36Sopenharmony_cistatic inline void NVolSet##flag(ntfs_volume *vol) \ 14762306a36Sopenharmony_ci{ \ 14862306a36Sopenharmony_ci set_bit(NV_##flag, &(vol)->flags); \ 14962306a36Sopenharmony_ci} \ 15062306a36Sopenharmony_cistatic inline void NVolClear##flag(ntfs_volume *vol) \ 15162306a36Sopenharmony_ci{ \ 15262306a36Sopenharmony_ci clear_bit(NV_##flag, &(vol)->flags); \ 15362306a36Sopenharmony_ci} 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci/* Emit the ntfs volume bitops functions. */ 15662306a36Sopenharmony_ciDEFINE_NVOL_BIT_OPS(Errors) 15762306a36Sopenharmony_ciDEFINE_NVOL_BIT_OPS(ShowSystemFiles) 15862306a36Sopenharmony_ciDEFINE_NVOL_BIT_OPS(CaseSensitive) 15962306a36Sopenharmony_ciDEFINE_NVOL_BIT_OPS(LogFileEmpty) 16062306a36Sopenharmony_ciDEFINE_NVOL_BIT_OPS(QuotaOutOfDate) 16162306a36Sopenharmony_ciDEFINE_NVOL_BIT_OPS(UsnJrnlStamped) 16262306a36Sopenharmony_ciDEFINE_NVOL_BIT_OPS(SparseEnabled) 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ci#endif /* _LINUX_NTFS_VOLUME_H */ 165