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