![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0-or-later */ 0002 /* 0003 * inode.h - Defines for inode structures NTFS Linux kernel driver. Part of 0004 * the Linux-NTFS project. 0005 * 0006 * Copyright (c) 2001-2007 Anton Altaparmakov 0007 * Copyright (c) 2002 Richard Russon 0008 */ 0009 0010 #ifndef _LINUX_NTFS_INODE_H 0011 #define _LINUX_NTFS_INODE_H 0012 0013 #include <linux/atomic.h> 0014 0015 #include <linux/fs.h> 0016 #include <linux/list.h> 0017 #include <linux/mm.h> 0018 #include <linux/mutex.h> 0019 #include <linux/seq_file.h> 0020 0021 #include "layout.h" 0022 #include "volume.h" 0023 #include "types.h" 0024 #include "runlist.h" 0025 #include "debug.h" 0026 0027 typedef struct _ntfs_inode ntfs_inode; 0028 0029 /* 0030 * The NTFS in-memory inode structure. It is just used as an extension to the 0031 * fields already provided in the VFS inode. 0032 */ 0033 struct _ntfs_inode { 0034 rwlock_t size_lock; /* Lock serializing access to inode sizes. */ 0035 s64 initialized_size; /* Copy from the attribute record. */ 0036 s64 allocated_size; /* Copy from the attribute record. */ 0037 unsigned long state; /* NTFS specific flags describing this inode. 0038 See ntfs_inode_state_bits below. */ 0039 unsigned long mft_no; /* Number of the mft record / inode. */ 0040 u16 seq_no; /* Sequence number of the mft record. */ 0041 atomic_t count; /* Inode reference count for book keeping. */ 0042 ntfs_volume *vol; /* Pointer to the ntfs volume of this inode. */ 0043 /* 0044 * If NInoAttr() is true, the below fields describe the attribute which 0045 * this fake inode belongs to. The actual inode of this attribute is 0046 * pointed to by base_ntfs_ino and nr_extents is always set to -1 (see 0047 * below). For real inodes, we also set the type (AT_DATA for files and 0048 * AT_INDEX_ALLOCATION for directories), with the name = NULL and 0049 * name_len = 0 for files and name = I30 (global constant) and 0050 * name_len = 4 for directories. 0051 */ 0052 ATTR_TYPE type; /* Attribute type of this fake inode. */ 0053 ntfschar *name; /* Attribute name of this fake inode. */ 0054 u32 name_len; /* Attribute name length of this fake inode. */ 0055 runlist runlist; /* If state has the NI_NonResident bit set, 0056 the runlist of the unnamed data attribute 0057 (if a file) or of the index allocation 0058 attribute (directory) or of the attribute 0059 described by the fake inode (if NInoAttr()). 0060 If runlist.rl is NULL, the runlist has not 0061 been read in yet or has been unmapped. If 0062 NI_NonResident is clear, the attribute is 0063 resident (file and fake inode) or there is 0064 no $I30 index allocation attribute 0065 (small directory). In the latter case 0066 runlist.rl is always NULL.*/ 0067 /* 0068 * The following fields are only valid for real inodes and extent 0069 * inodes. 0070 */ 0071 struct mutex mrec_lock; /* Lock for serializing access to the 0072 mft record belonging to this inode. */ 0073 struct page *page; /* The page containing the mft record of the 0074 inode. This should only be touched by the 0075 (un)map_mft_record*() functions. */ 0076 int page_ofs; /* Offset into the page at which the mft record 0077 begins. This should only be touched by the 0078 (un)map_mft_record*() functions. */ 0079 /* 0080 * Attribute list support (only for use by the attribute lookup 0081 * functions). Setup during read_inode for all inodes with attribute 0082 * lists. Only valid if NI_AttrList is set in state, and attr_list_rl is 0083 * further only valid if NI_AttrListNonResident is set. 0084 */ 0085 u32 attr_list_size; /* Length of attribute list value in bytes. */ 0086 u8 *attr_list; /* Attribute list value itself. */ 0087 runlist attr_list_rl; /* Run list for the attribute list value. */ 0088 union { 0089 struct { /* It is a directory, $MFT, or an index inode. */ 0090 u32 block_size; /* Size of an index block. */ 0091 u32 vcn_size; /* Size of a vcn in this 0092 index. */ 0093 COLLATION_RULE collation_rule; /* The collation rule 0094 for the index. */ 0095 u8 block_size_bits; /* Log2 of the above. */ 0096 u8 vcn_size_bits; /* Log2 of the above. */ 0097 } index; 0098 struct { /* It is a compressed/sparse file/attribute inode. */ 0099 s64 size; /* Copy of compressed_size from 0100 $DATA. */ 0101 u32 block_size; /* Size of a compression block 0102 (cb). */ 0103 u8 block_size_bits; /* Log2 of the size of a cb. */ 0104 u8 block_clusters; /* Number of clusters per cb. */ 0105 } compressed; 0106 } itype; 0107 struct mutex extent_lock; /* Lock for accessing/modifying the 0108 below . */ 0109 s32 nr_extents; /* For a base mft record, the number of attached extent 0110 inodes (0 if none), for extent records and for fake 0111 inodes describing an attribute this is -1. */ 0112 union { /* This union is only used if nr_extents != 0. */ 0113 ntfs_inode **extent_ntfs_inos; /* For nr_extents > 0, array of 0114 the ntfs inodes of the extent 0115 mft records belonging to 0116 this base inode which have 0117 been loaded. */ 0118 ntfs_inode *base_ntfs_ino; /* For nr_extents == -1, the 0119 ntfs inode of the base mft 0120 record. For fake inodes, the 0121 real (base) inode to which 0122 the attribute belongs. */ 0123 } ext; 0124 }; 0125 0126 /* 0127 * Defined bits for the state field in the ntfs_inode structure. 0128 * (f) = files only, (d) = directories only, (a) = attributes/fake inodes only 0129 */ 0130 typedef enum { 0131 NI_Dirty, /* 1: Mft record needs to be written to disk. */ 0132 NI_AttrList, /* 1: Mft record contains an attribute list. */ 0133 NI_AttrListNonResident, /* 1: Attribute list is non-resident. Implies 0134 NI_AttrList is set. */ 0135 0136 NI_Attr, /* 1: Fake inode for attribute i/o. 0137 0: Real inode or extent inode. */ 0138 0139 NI_MstProtected, /* 1: Attribute is protected by MST fixups. 0140 0: Attribute is not protected by fixups. */ 0141 NI_NonResident, /* 1: Unnamed data attr is non-resident (f). 0142 1: Attribute is non-resident (a). */ 0143 NI_IndexAllocPresent = NI_NonResident, /* 1: $I30 index alloc attr is 0144 present (d). */ 0145 NI_Compressed, /* 1: Unnamed data attr is compressed (f). 0146 1: Create compressed files by default (d). 0147 1: Attribute is compressed (a). */ 0148 NI_Encrypted, /* 1: Unnamed data attr is encrypted (f). 0149 1: Create encrypted files by default (d). 0150 1: Attribute is encrypted (a). */ 0151 NI_Sparse, /* 1: Unnamed data attr is sparse (f). 0152 1: Create sparse files by default (d). 0153 1: Attribute is sparse (a). */ 0154 NI_SparseDisabled, /* 1: May not create sparse regions. */ 0155 NI_TruncateFailed, /* 1: Last ntfs_truncate() call failed. */ 0156 } ntfs_inode_state_bits; 0157 0158 /* 0159 * NOTE: We should be adding dirty mft records to a list somewhere and they 0160 * should be independent of the (ntfs/vfs) inode structure so that an inode can 0161 * be removed but the record can be left dirty for syncing later. 0162 */ 0163 0164 /* 0165 * Macro tricks to expand the NInoFoo(), NInoSetFoo(), and NInoClearFoo() 0166 * functions. 0167 */ 0168 #define NINO_FNS(flag) \ 0169 static inline int NIno##flag(ntfs_inode *ni) \ 0170 { \ 0171 return test_bit(NI_##flag, &(ni)->state); \ 0172 } \ 0173 static inline void NInoSet##flag(ntfs_inode *ni) \ 0174 { \ 0175 set_bit(NI_##flag, &(ni)->state); \ 0176 } \ 0177 static inline void NInoClear##flag(ntfs_inode *ni) \ 0178 { \ 0179 clear_bit(NI_##flag, &(ni)->state); \ 0180 } 0181 0182 /* 0183 * As above for NInoTestSetFoo() and NInoTestClearFoo(). 0184 */ 0185 #define TAS_NINO_FNS(flag) \ 0186 static inline int NInoTestSet##flag(ntfs_inode *ni) \ 0187 { \ 0188 return test_and_set_bit(NI_##flag, &(ni)->state); \ 0189 } \ 0190 static inline int NInoTestClear##flag(ntfs_inode *ni) \ 0191 { \ 0192 return test_and_clear_bit(NI_##flag, &(ni)->state); \ 0193 } 0194 0195 /* Emit the ntfs inode bitops functions. */ 0196 NINO_FNS(Dirty) 0197 TAS_NINO_FNS(Dirty) 0198 NINO_FNS(AttrList) 0199 NINO_FNS(AttrListNonResident) 0200 NINO_FNS(Attr) 0201 NINO_FNS(MstProtected) 0202 NINO_FNS(NonResident) 0203 NINO_FNS(IndexAllocPresent) 0204 NINO_FNS(Compressed) 0205 NINO_FNS(Encrypted) 0206 NINO_FNS(Sparse) 0207 NINO_FNS(SparseDisabled) 0208 NINO_FNS(TruncateFailed) 0209 0210 /* 0211 * The full structure containing a ntfs_inode and a vfs struct inode. Used for 0212 * all real and fake inodes but not for extent inodes which lack the vfs struct 0213 * inode. 0214 */ 0215 typedef struct { 0216 ntfs_inode ntfs_inode; 0217 struct inode vfs_inode; /* The vfs inode structure. */ 0218 } big_ntfs_inode; 0219 0220 /** 0221 * NTFS_I - return the ntfs inode given a vfs inode 0222 * @inode: VFS inode 0223 * 0224 * NTFS_I() returns the ntfs inode associated with the VFS @inode. 0225 */ 0226 static inline ntfs_inode *NTFS_I(struct inode *inode) 0227 { 0228 return (ntfs_inode *)container_of(inode, big_ntfs_inode, vfs_inode); 0229 } 0230 0231 static inline struct inode *VFS_I(ntfs_inode *ni) 0232 { 0233 return &((big_ntfs_inode *)ni)->vfs_inode; 0234 } 0235 0236 /** 0237 * ntfs_attr - ntfs in memory attribute structure 0238 * @mft_no: mft record number of the base mft record of this attribute 0239 * @name: Unicode name of the attribute (NULL if unnamed) 0240 * @name_len: length of @name in Unicode characters (0 if unnamed) 0241 * @type: attribute type (see layout.h) 0242 * 0243 * This structure exists only to provide a small structure for the 0244 * ntfs_{attr_}iget()/ntfs_test_inode()/ntfs_init_locked_inode() mechanism. 0245 * 0246 * NOTE: Elements are ordered by size to make the structure as compact as 0247 * possible on all architectures. 0248 */ 0249 typedef struct { 0250 unsigned long mft_no; 0251 ntfschar *name; 0252 u32 name_len; 0253 ATTR_TYPE type; 0254 } ntfs_attr; 0255 0256 extern int ntfs_test_inode(struct inode *vi, void *data); 0257 0258 extern struct inode *ntfs_iget(struct super_block *sb, unsigned long mft_no); 0259 extern struct inode *ntfs_attr_iget(struct inode *base_vi, ATTR_TYPE type, 0260 ntfschar *name, u32 name_len); 0261 extern struct inode *ntfs_index_iget(struct inode *base_vi, ntfschar *name, 0262 u32 name_len); 0263 0264 extern struct inode *ntfs_alloc_big_inode(struct super_block *sb); 0265 extern void ntfs_free_big_inode(struct inode *inode); 0266 extern void ntfs_evict_big_inode(struct inode *vi); 0267 0268 extern void __ntfs_init_inode(struct super_block *sb, ntfs_inode *ni); 0269 0270 static inline void ntfs_init_big_inode(struct inode *vi) 0271 { 0272 ntfs_inode *ni = NTFS_I(vi); 0273 0274 ntfs_debug("Entering."); 0275 __ntfs_init_inode(vi->i_sb, ni); 0276 ni->mft_no = vi->i_ino; 0277 } 0278 0279 extern ntfs_inode *ntfs_new_extent_inode(struct super_block *sb, 0280 unsigned long mft_no); 0281 extern void ntfs_clear_extent_inode(ntfs_inode *ni); 0282 0283 extern int ntfs_read_inode_mount(struct inode *vi); 0284 0285 extern int ntfs_show_options(struct seq_file *sf, struct dentry *root); 0286 0287 #ifdef NTFS_RW 0288 0289 extern int ntfs_truncate(struct inode *vi); 0290 extern void ntfs_truncate_vfs(struct inode *vi); 0291 0292 extern int ntfs_setattr(struct user_namespace *mnt_userns, 0293 struct dentry *dentry, struct iattr *attr); 0294 0295 extern int __ntfs_write_inode(struct inode *vi, int sync); 0296 0297 static inline void ntfs_commit_inode(struct inode *vi) 0298 { 0299 if (!is_bad_inode(vi)) 0300 __ntfs_write_inode(vi, 1); 0301 return; 0302 } 0303 0304 #else 0305 0306 static inline void ntfs_truncate_vfs(struct inode *vi) {} 0307 0308 #endif /* NTFS_RW */ 0309 0310 #endif /* _LINUX_NTFS_INODE_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |