blob: 3de5c0231966708c0ae8346dcf24795ecf761c8d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * inode.h - Defines for inode structures NTFS Linux kernel driver. Part of
3 * the Linux-NTFS project.
4 *
Anton Altaparmakovc002f422005-02-03 12:02:56 +00005 * Copyright (c) 2001-2005 Anton Altaparmakov
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Copyright (c) 2002 Richard Russon
7 *
8 * This program/include file is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published
10 * by the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program/include file is distributed in the hope that it will be
14 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program (in the main directory of the Linux-NTFS
20 * distribution in the file COPYING); if not, write to the Free Software
21 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#ifndef _LINUX_NTFS_INODE_H
25#define _LINUX_NTFS_INODE_H
26
27#include <linux/mm.h>
28#include <linux/fs.h>
29#include <linux/seq_file.h>
30#include <linux/list.h>
31#include <asm/atomic.h>
32#include <asm/semaphore.h>
33
34#include "layout.h"
35#include "volume.h"
36#include "types.h"
37#include "runlist.h"
38#include "debug.h"
39
40typedef struct _ntfs_inode ntfs_inode;
41
42/*
43 * The NTFS in-memory inode structure. It is just used as an extension to the
44 * fields already provided in the VFS inode.
45 */
46struct _ntfs_inode {
Anton Altaparmakov36763672004-11-18 13:46:45 +000047 rwlock_t size_lock; /* Lock serializing access to inode sizes. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 s64 initialized_size; /* Copy from the attribute record. */
49 s64 allocated_size; /* Copy from the attribute record. */
50 unsigned long state; /* NTFS specific flags describing this inode.
51 See ntfs_inode_state_bits below. */
52 unsigned long mft_no; /* Number of the mft record / inode. */
53 u16 seq_no; /* Sequence number of the mft record. */
54 atomic_t count; /* Inode reference count for book keeping. */
55 ntfs_volume *vol; /* Pointer to the ntfs volume of this inode. */
56 /*
57 * If NInoAttr() is true, the below fields describe the attribute which
58 * this fake inode belongs to. The actual inode of this attribute is
59 * pointed to by base_ntfs_ino and nr_extents is always set to -1 (see
60 * below). For real inodes, we also set the type (AT_DATA for files and
61 * AT_INDEX_ALLOCATION for directories), with the name = NULL and
62 * name_len = 0 for files and name = I30 (global constant) and
63 * name_len = 4 for directories.
64 */
65 ATTR_TYPE type; /* Attribute type of this fake inode. */
66 ntfschar *name; /* Attribute name of this fake inode. */
67 u32 name_len; /* Attribute name length of this fake inode. */
68 runlist runlist; /* If state has the NI_NonResident bit set,
69 the runlist of the unnamed data attribute
70 (if a file) or of the index allocation
71 attribute (directory) or of the attribute
72 described by the fake inode (if NInoAttr()).
73 If runlist.rl is NULL, the runlist has not
74 been read in yet or has been unmapped. If
75 NI_NonResident is clear, the attribute is
76 resident (file and fake inode) or there is
77 no $I30 index allocation attribute
78 (small directory). In the latter case
79 runlist.rl is always NULL.*/
80 /*
81 * The following fields are only valid for real inodes and extent
82 * inodes.
83 */
84 struct semaphore mrec_lock; /* Lock for serializing access to the
85 mft record belonging to this inode. */
86 struct page *page; /* The page containing the mft record of the
87 inode. This should only be touched by the
88 (un)map_mft_record*() functions. */
89 int page_ofs; /* Offset into the page at which the mft record
90 begins. This should only be touched by the
91 (un)map_mft_record*() functions. */
92 /*
93 * Attribute list support (only for use by the attribute lookup
94 * functions). Setup during read_inode for all inodes with attribute
95 * lists. Only valid if NI_AttrList is set in state, and attr_list_rl is
96 * further only valid if NI_AttrListNonResident is set.
97 */
98 u32 attr_list_size; /* Length of attribute list value in bytes. */
99 u8 *attr_list; /* Attribute list value itself. */
100 runlist attr_list_rl; /* Run list for the attribute list value. */
101 union {
102 struct { /* It is a directory, $MFT, or an index inode. */
103 struct inode *bmp_ino; /* Attribute inode for the
104 index $BITMAP. */
105 u32 block_size; /* Size of an index block. */
106 u32 vcn_size; /* Size of a vcn in this
107 index. */
108 COLLATION_RULE collation_rule; /* The collation rule
109 for the index. */
110 u8 block_size_bits; /* Log2 of the above. */
111 u8 vcn_size_bits; /* Log2 of the above. */
112 } index;
Anton Altaparmakov3bd1f4a2005-06-25 16:51:58 +0100113 struct { /* It is a compressed/sparse file/attribute inode. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 s64 size; /* Copy of compressed_size from
115 $DATA. */
116 u32 block_size; /* Size of a compression block
117 (cb). */
118 u8 block_size_bits; /* Log2 of the size of a cb. */
119 u8 block_clusters; /* Number of clusters per cb. */
120 } compressed;
121 } itype;
122 struct semaphore extent_lock; /* Lock for accessing/modifying the
123 below . */
124 s32 nr_extents; /* For a base mft record, the number of attached extent
125 inodes (0 if none), for extent records and for fake
126 inodes describing an attribute this is -1. */
127 union { /* This union is only used if nr_extents != 0. */
128 ntfs_inode **extent_ntfs_inos; /* For nr_extents > 0, array of
129 the ntfs inodes of the extent
130 mft records belonging to
131 this base inode which have
132 been loaded. */
133 ntfs_inode *base_ntfs_ino; /* For nr_extents == -1, the
134 ntfs inode of the base mft
135 record. For fake inodes, the
136 real (base) inode to which
137 the attribute belongs. */
138 } ext;
139};
140
141/*
142 * Defined bits for the state field in the ntfs_inode structure.
143 * (f) = files only, (d) = directories only, (a) = attributes/fake inodes only
144 */
145typedef enum {
146 NI_Dirty, /* 1: Mft record needs to be written to disk. */
147 NI_AttrList, /* 1: Mft record contains an attribute list. */
148 NI_AttrListNonResident, /* 1: Attribute list is non-resident. Implies
149 NI_AttrList is set. */
150
151 NI_Attr, /* 1: Fake inode for attribute i/o.
152 0: Real inode or extent inode. */
153
154 NI_MstProtected, /* 1: Attribute is protected by MST fixups.
155 0: Attribute is not protected by fixups. */
156 NI_NonResident, /* 1: Unnamed data attr is non-resident (f).
157 1: Attribute is non-resident (a). */
158 NI_IndexAllocPresent = NI_NonResident, /* 1: $I30 index alloc attr is
159 present (d). */
160 NI_Compressed, /* 1: Unnamed data attr is compressed (f).
161 1: Create compressed files by default (d).
162 1: Attribute is compressed (a). */
163 NI_Encrypted, /* 1: Unnamed data attr is encrypted (f).
164 1: Create encrypted files by default (d).
165 1: Attribute is encrypted (a). */
166 NI_Sparse, /* 1: Unnamed data attr is sparse (f).
167 1: Create sparse files by default (d).
168 1: Attribute is sparse (a). */
Anton Altaparmakovc002f422005-02-03 12:02:56 +0000169 NI_SparseDisabled, /* 1: May not create sparse regions. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 NI_TruncateFailed, /* 1: Last ntfs_truncate() call failed. */
171} ntfs_inode_state_bits;
172
173/*
174 * NOTE: We should be adding dirty mft records to a list somewhere and they
175 * should be independent of the (ntfs/vfs) inode structure so that an inode can
176 * be removed but the record can be left dirty for syncing later.
177 */
178
179/*
180 * Macro tricks to expand the NInoFoo(), NInoSetFoo(), and NInoClearFoo()
181 * functions.
182 */
183#define NINO_FNS(flag) \
184static inline int NIno##flag(ntfs_inode *ni) \
185{ \
186 return test_bit(NI_##flag, &(ni)->state); \
187} \
188static inline void NInoSet##flag(ntfs_inode *ni) \
189{ \
190 set_bit(NI_##flag, &(ni)->state); \
191} \
192static inline void NInoClear##flag(ntfs_inode *ni) \
193{ \
194 clear_bit(NI_##flag, &(ni)->state); \
195}
196
197/*
198 * As above for NInoTestSetFoo() and NInoTestClearFoo().
199 */
200#define TAS_NINO_FNS(flag) \
201static inline int NInoTestSet##flag(ntfs_inode *ni) \
202{ \
203 return test_and_set_bit(NI_##flag, &(ni)->state); \
204} \
205static inline int NInoTestClear##flag(ntfs_inode *ni) \
206{ \
207 return test_and_clear_bit(NI_##flag, &(ni)->state); \
208}
209
210/* Emit the ntfs inode bitops functions. */
211NINO_FNS(Dirty)
212TAS_NINO_FNS(Dirty)
213NINO_FNS(AttrList)
214NINO_FNS(AttrListNonResident)
215NINO_FNS(Attr)
216NINO_FNS(MstProtected)
217NINO_FNS(NonResident)
218NINO_FNS(IndexAllocPresent)
219NINO_FNS(Compressed)
220NINO_FNS(Encrypted)
221NINO_FNS(Sparse)
Anton Altaparmakovc002f422005-02-03 12:02:56 +0000222NINO_FNS(SparseDisabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223NINO_FNS(TruncateFailed)
224
225/*
226 * The full structure containing a ntfs_inode and a vfs struct inode. Used for
227 * all real and fake inodes but not for extent inodes which lack the vfs struct
228 * inode.
229 */
230typedef struct {
231 ntfs_inode ntfs_inode;
232 struct inode vfs_inode; /* The vfs inode structure. */
233} big_ntfs_inode;
234
235/**
236 * NTFS_I - return the ntfs inode given a vfs inode
237 * @inode: VFS inode
238 *
239 * NTFS_I() returns the ntfs inode associated with the VFS @inode.
240 */
241static inline ntfs_inode *NTFS_I(struct inode *inode)
242{
243 return (ntfs_inode *)list_entry(inode, big_ntfs_inode, vfs_inode);
244}
245
246static inline struct inode *VFS_I(ntfs_inode *ni)
247{
248 return &((big_ntfs_inode *)ni)->vfs_inode;
249}
250
251/**
252 * ntfs_attr - ntfs in memory attribute structure
253 * @mft_no: mft record number of the base mft record of this attribute
254 * @name: Unicode name of the attribute (NULL if unnamed)
255 * @name_len: length of @name in Unicode characters (0 if unnamed)
256 * @type: attribute type (see layout.h)
257 *
258 * This structure exists only to provide a small structure for the
259 * ntfs_{attr_}iget()/ntfs_test_inode()/ntfs_init_locked_inode() mechanism.
260 *
261 * NOTE: Elements are ordered by size to make the structure as compact as
262 * possible on all architectures.
263 */
264typedef struct {
265 unsigned long mft_no;
266 ntfschar *name;
267 u32 name_len;
268 ATTR_TYPE type;
269} ntfs_attr;
270
271typedef int (*test_t)(struct inode *, void *);
272
273extern int ntfs_test_inode(struct inode *vi, ntfs_attr *na);
274
275extern struct inode *ntfs_iget(struct super_block *sb, unsigned long mft_no);
276extern struct inode *ntfs_attr_iget(struct inode *base_vi, ATTR_TYPE type,
277 ntfschar *name, u32 name_len);
278extern struct inode *ntfs_index_iget(struct inode *base_vi, ntfschar *name,
279 u32 name_len);
280
281extern struct inode *ntfs_alloc_big_inode(struct super_block *sb);
282extern void ntfs_destroy_big_inode(struct inode *inode);
283extern void ntfs_clear_big_inode(struct inode *vi);
284
285extern void __ntfs_init_inode(struct super_block *sb, ntfs_inode *ni);
286
287static inline void ntfs_init_big_inode(struct inode *vi)
288{
289 ntfs_inode *ni = NTFS_I(vi);
290
291 ntfs_debug("Entering.");
292 __ntfs_init_inode(vi->i_sb, ni);
293 ni->mft_no = vi->i_ino;
294}
295
296extern ntfs_inode *ntfs_new_extent_inode(struct super_block *sb,
297 unsigned long mft_no);
298extern void ntfs_clear_extent_inode(ntfs_inode *ni);
299
300extern int ntfs_read_inode_mount(struct inode *vi);
301
302extern void ntfs_put_inode(struct inode *vi);
303
304extern int ntfs_show_options(struct seq_file *sf, struct vfsmount *mnt);
305
306#ifdef NTFS_RW
307
308extern int ntfs_truncate(struct inode *vi);
309extern void ntfs_truncate_vfs(struct inode *vi);
310
311extern int ntfs_setattr(struct dentry *dentry, struct iattr *attr);
312
313extern int ntfs_write_inode(struct inode *vi, int sync);
314
315static inline void ntfs_commit_inode(struct inode *vi)
316{
317 if (!is_bad_inode(vi))
318 ntfs_write_inode(vi, 1);
319 return;
320}
321
322#endif /* NTFS_RW */
323
324#endif /* _LINUX_NTFS_INODE_H */