VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / fs / ntfs / inode.h
1 /*
2  * inode.h - Defines for inode structures NTFS Linux kernel driver. Part of
3  *           the Linux-NTFS project.
4  *
5  * Copyright (c) 2001-2004 Anton Altaparmakov
6  * 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/seq_file.h>
28
29 #include "layout.h"
30 #include "volume.h"
31
32 typedef struct _ntfs_inode ntfs_inode;
33
34 /*
35  * The NTFS in-memory inode structure. It is just used as an extension to the
36  * fields already provided in the VFS inode.
37  */
38 struct _ntfs_inode {
39         s64 initialized_size;   /* Copy from the attribute record. */
40         s64 allocated_size;     /* Copy from the attribute record. */
41         unsigned long state;    /* NTFS specific flags describing this inode.
42                                    See ntfs_inode_state_bits below. */
43         unsigned long mft_no;   /* Number of the mft record / inode. */
44         u16 seq_no;             /* Sequence number of the mft record. */
45         atomic_t count;         /* Inode reference count for book keeping. */
46         ntfs_volume *vol;       /* Pointer to the ntfs volume of this inode. */
47         /*
48          * If NInoAttr() is true, the below fields describe the attribute which
49          * this fake inode belongs to. The actual inode of this attribute is
50          * pointed to by base_ntfs_ino and nr_extents is always set to -1 (see
51          * below). For real inodes, we also set the type (AT_DATA for files and
52          * AT_INDEX_ALLOCATION for directories), with the name = NULL and
53          * name_len = 0 for files and name = I30 (global constant) and
54          * name_len = 4 for directories.
55          */
56         ATTR_TYPES type;        /* Attribute type of this fake inode. */
57         ntfschar *name;         /* Attribute name of this fake inode. */
58         u32 name_len;           /* Attribute name length of this fake inode. */
59         run_list run_list;      /* If state has the NI_NonResident bit set,
60                                    the run list of the unnamed data attribute
61                                    (if a file) or of the index allocation
62                                    attribute (directory) or of the attribute
63                                    described by the fake inode (if NInoAttr()).
64                                    If run_list.rl is NULL, the run list has not
65                                    been read in yet or has been unmapped. If
66                                    NI_NonResident is clear, the attribute is
67                                    resident (file and fake inode) or there is
68                                    no $I30 index allocation attribute
69                                    (small directory). In the latter case
70                                    run_list.rl is always NULL.*/
71         /*
72          * The following fields are only valid for real inodes and extent
73          * inodes.
74          */
75         struct semaphore mrec_lock; /* Lock for serializing access to the
76                                    mft record belonging to this inode. */
77         struct page *page;      /* The page containing the mft record of the
78                                    inode. This should only be touched by the
79                                    (un)map_mft_record*() functions. */
80         int page_ofs;           /* Offset into the page at which the mft record
81                                    begins. This should only be touched by the
82                                    (un)map_mft_record*() functions. */
83         /*
84          * Attribute list support (only for use by the attribute lookup
85          * functions). Setup during read_inode for all inodes with attribute
86          * lists. Only valid if NI_AttrList is set in state, and attr_list_rl is
87          * further only valid if NI_AttrListNonResident is set.
88          */
89         u32 attr_list_size;     /* Length of attribute list value in bytes. */
90         u8 *attr_list;          /* Attribute list value itself. */
91         run_list attr_list_rl;  /* Run list for the attribute list value. */
92         union {
93                 struct { /* It is a directory, $MFT, or an index inode. */
94                         struct inode *bmp_ino;  /* Attribute inode for the
95                                                    index $BITMAP. */
96                         u32 block_size;         /* Size of an index block. */
97                         u32 vcn_size;           /* Size of a vcn in this
98                                                    index. */
99                         COLLATION_RULES collation_rule; /* The collation rule
100                                                    for the index. */
101                         u8 block_size_bits;     /* Log2 of the above. */
102                         u8 vcn_size_bits;       /* Log2 of the above. */
103                 } index;
104                 struct { /* It is a compressed file or an attribute inode. */
105                         s64 size;               /* Copy of compressed_size from
106                                                    $DATA. */
107                         u32 block_size;         /* Size of a compression block
108                                                    (cb). */
109                         u8 block_size_bits;     /* Log2 of the size of a cb. */
110                         u8 block_clusters;      /* Number of clusters per cb. */
111                 } compressed;
112         } itype;
113         struct semaphore extent_lock;   /* Lock for accessing/modifying the
114                                            below . */
115         s32 nr_extents; /* For a base mft record, the number of attached extent
116                            inodes (0 if none), for extent records and for fake
117                            inodes describing an attribute this is -1. */
118         union {         /* This union is only used if nr_extents != 0. */
119                 ntfs_inode **extent_ntfs_inos;  /* For nr_extents > 0, array of
120                                                    the ntfs inodes of the extent
121                                                    mft records belonging to
122                                                    this base inode which have
123                                                    been loaded. */
124                 ntfs_inode *base_ntfs_ino;      /* For nr_extents == -1, the
125                                                    ntfs inode of the base mft
126                                                    record. For fake inodes, the
127                                                    real (base) inode to which
128                                                    the attribute belongs. */
129         } ext;
130 };
131
132 /*
133  * Defined bits for the state field in the ntfs_inode structure.
134  * (f) = files only, (d) = directories only, (a) = attributes/fake inodes only
135  */
136 typedef enum {
137         NI_Dirty,               /* 1: Mft record needs to be written to disk. */
138         NI_AttrList,            /* 1: Mft record contains an attribute list. */
139         NI_AttrListNonResident, /* 1: Attribute list is non-resident. Implies
140                                       NI_AttrList is set. */
141
142         NI_Attr,                /* 1: Fake inode for attribute i/o.
143                                    0: Real inode or extent inode. */
144
145         NI_MstProtected,        /* 1: Attribute is protected by MST fixups.
146                                    0: Attribute is not protected by fixups. */
147         NI_NonResident,         /* 1: Unnamed data attr is non-resident (f).
148                                    1: Attribute is non-resident (a). */
149         NI_IndexAllocPresent = NI_NonResident,  /* 1: $I30 index alloc attr is
150                                                    present (d). */
151         NI_Compressed,          /* 1: Unnamed data attr is compressed (f).
152                                    1: Create compressed files by default (d).
153                                    1: Attribute is compressed (a). */
154         NI_Encrypted,           /* 1: Unnamed data attr is encrypted (f).
155                                    1: Create encrypted files by default (d).
156                                    1: Attribute is encrypted (a). */
157         NI_Sparse,              /* 1: Unnamed data attr is sparse (f).
158                                    1: Create sparse files by default (d).
159                                    1: Attribute is sparse (a). */
160 } ntfs_inode_state_bits;
161
162 /*
163  * NOTE: We should be adding dirty mft records to a list somewhere and they
164  * should be independent of the (ntfs/vfs) inode structure so that an inode can
165  * be removed but the record can be left dirty for syncing later.
166  */
167
168 /*
169  * Macro tricks to expand the NInoFoo(), NInoSetFoo(), and NInoClearFoo()
170  * functions.
171  */
172 #define NINO_FNS(flag)                                  \
173 static inline int NIno##flag(ntfs_inode *ni)            \
174 {                                                       \
175         return test_bit(NI_##flag, &(ni)->state);       \
176 }                                                       \
177 static inline void NInoSet##flag(ntfs_inode *ni)        \
178 {                                                       \
179         set_bit(NI_##flag, &(ni)->state);               \
180 }                                                       \
181 static inline void NInoClear##flag(ntfs_inode *ni)      \
182 {                                                       \
183         clear_bit(NI_##flag, &(ni)->state);             \
184 }
185
186 /*
187  * As above for NInoTestSetFoo() and NInoTestClearFoo().
188  */
189 #define TAS_NINO_FNS(flag)                                      \
190 static inline int NInoTestSet##flag(ntfs_inode *ni)             \
191 {                                                               \
192         return test_and_set_bit(NI_##flag, &(ni)->state);       \
193 }                                                               \
194 static inline int NInoTestClear##flag(ntfs_inode *ni)           \
195 {                                                               \
196         return test_and_clear_bit(NI_##flag, &(ni)->state);     \
197 }
198
199 /* Emit the ntfs inode bitops functions. */
200 NINO_FNS(Dirty)
201 TAS_NINO_FNS(Dirty)
202 NINO_FNS(AttrList)
203 NINO_FNS(AttrListNonResident)
204 NINO_FNS(Attr)
205 NINO_FNS(MstProtected)
206 NINO_FNS(NonResident)
207 NINO_FNS(IndexAllocPresent)
208 NINO_FNS(Compressed)
209 NINO_FNS(Encrypted)
210 NINO_FNS(Sparse)
211
212 /*
213  * The full structure containing a ntfs_inode and a vfs struct inode. Used for
214  * all real and fake inodes but not for extent inodes which lack the vfs struct
215  * inode.
216  */
217 typedef struct {
218         ntfs_inode ntfs_inode;
219         struct inode vfs_inode;         /* The vfs inode structure. */
220 } big_ntfs_inode;
221
222 /**
223  * NTFS_I - return the ntfs inode given a vfs inode
224  * @inode:      VFS inode
225  *
226  * NTFS_I() returns the ntfs inode associated with the VFS @inode.
227  */
228 static inline ntfs_inode *NTFS_I(struct inode *inode)
229 {
230         return (ntfs_inode *)list_entry(inode, big_ntfs_inode, vfs_inode);
231 }
232
233 static inline struct inode *VFS_I(ntfs_inode *ni)
234 {
235         return &((big_ntfs_inode *)ni)->vfs_inode;
236 }
237
238 /**
239  * ntfs_attr - ntfs in memory attribute structure
240  * @mft_no:     mft record number of the base mft record of this attribute
241  * @name:       Unicode name of the attribute (NULL if unnamed)
242  * @name_len:   length of @name in Unicode characters (0 if unnamed)
243  * @type:       attribute type (see layout.h)
244  *
245  * This structure exists only to provide a small structure for the
246  * ntfs_{attr_}iget()/ntfs_test_inode()/ntfs_init_locked_inode() mechanism.
247  *
248  * NOTE: Elements are ordered by size to make the structure as compact as
249  * possible on all architectures.
250  */
251 typedef struct {
252         unsigned long mft_no;
253         ntfschar *name;
254         u32 name_len;
255         ATTR_TYPES type;
256 } ntfs_attr;
257
258 typedef int (*test_t)(struct inode *, void *);
259
260 extern int ntfs_test_inode(struct inode *vi, ntfs_attr *na);
261
262 extern struct inode *ntfs_iget(struct super_block *sb, unsigned long mft_no);
263 extern struct inode *ntfs_attr_iget(struct inode *base_vi, ATTR_TYPES type,
264                 ntfschar *name, u32 name_len);
265 extern struct inode *ntfs_index_iget(struct inode *base_vi, ntfschar *name,
266                 u32 name_len);
267
268 extern struct inode *ntfs_alloc_big_inode(struct super_block *sb);
269 extern void ntfs_destroy_big_inode(struct inode *inode);
270 extern void ntfs_clear_big_inode(struct inode *vi);
271
272 extern ntfs_inode *ntfs_new_extent_inode(struct super_block *sb,
273                 unsigned long mft_no);
274 extern void ntfs_clear_extent_inode(ntfs_inode *ni);
275
276 extern int ntfs_read_inode_mount(struct inode *vi);
277
278 extern void ntfs_put_inode(struct inode *vi);
279
280 extern int ntfs_show_options(struct seq_file *sf, struct vfsmount *mnt);
281
282 #ifdef NTFS_RW
283
284 extern void ntfs_truncate(struct inode *vi);
285
286 extern int ntfs_setattr(struct dentry *dentry, struct iattr *attr);
287
288 extern void ntfs_write_inode(struct inode *vi, int sync);
289
290 static inline void ntfs_commit_inode(struct inode *vi)
291 {
292         if (!is_bad_inode(vi))
293                 ntfs_write_inode(vi, 1);
294         return;
295 }
296
297 #endif /* NTFS_RW */
298
299 #endif /* _LINUX_NTFS_INODE_H */