http://linux-ntfs.sourceforge.net/snapshots/ntfsprogs-200309071734.tar.bz2
[ntfsprogs.git] / include / inode.h
1 /*
2  * inode.h - Defines for NTFS inode handling. Part of the Linux-NTFS project.
3  *
4  * Copyright (c) 2001,2002 Anton Altaparmakov
5  *
6  * This program/include file is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as published
8  * by the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program/include file is distributed in the hope that it will be
12  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program (in the main directory of the Linux-NTFS
18  * distribution in the file COPYING); if not, write to the Free Software
19  * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #ifndef _NTFS_INODE_H
23 #define _NTFS_INODE_H
24
25 /* Forward declaration */
26 typedef struct _ntfs_inode ntfs_inode;
27
28 #include "types.h"
29 #include "support.h"
30 #include "runlist.h"
31
32 /*
33  * Defined bits for the state field in the ntfs_inode structure.
34  * (f) = files only, (d) = directories only
35  */
36 typedef enum {
37         NI_Dirty,               /* 1: Mft record needs to be written to disk. */
38
39         /* The NI_AttrList* tests only make sense for base inodes. */
40         NI_AttrList,            /* 1: Mft record contains an attribute list. */
41         NI_AttrListNonResident, /* 1: Attribute list is non-resident. Implies
42                                       NI_AttrList is set. */
43         NI_AttrListDirty,       /* 1: Attribute list needs to be written to the
44                                       mft record and then to disk. */
45 } ntfs_inode_state_bits;
46
47 #define  test_nino_flag(ni, flag)          test_bit(NI_##flag, (ni)->state)
48 #define   set_nino_flag(ni, flag)           set_bit(NI_##flag, (ni)->state)
49 #define clear_nino_flag(ni, flag)         clear_bit(NI_##flag, (ni)->state)
50
51 #define test_and_set_nino_flag(ni, flag)        \
52                                    test_and_set_bit(NI_##flag, (ni)->state)
53 #define test_and_clear_nino_flag(ni, flag)      \
54                                  test_and_clear_bit(NI_##flag, (ni)->state)
55
56 #define NInoDirty(ni)                             test_nino_flag(ni, Dirty)
57 #define NInoSetDirty(ni)                           set_nino_flag(ni, Dirty)
58 #define NInoClearDirty(ni)                       clear_nino_flag(ni, Dirty)
59 #define NInoTestAndSetDirty(ni)           test_and_set_nino_flag(ni, Dirty)
60 #define NInoTestAndClearDirty(ni)       test_and_clear_nino_flag(ni, Dirty)
61
62 #define NInoAttrList(ni)                          test_nino_flag(ni, AttrList)
63 #define NInoSetAttrList(ni)                        set_nino_flag(ni, AttrList)
64 #define NInoClearAttrList(ni)                    clear_nino_flag(ni, AttrList)
65
66
67 #define  test_nino_al_flag(ni, flag)     test_nino_flag(ni, AttrList##flag)
68 #define   set_nino_al_flag(ni, flag)      set_nino_flag(ni, AttrList##flag)
69 #define clear_nino_al_flag(ni, flag)    clear_nino_flag(ni, AttrList##flag)
70
71 #define NInoAttrListNonResident(ni)        test_nino_al_flag(ni, NonResident)
72 #define NInoSetAttrListNonResident(ni)      set_nino_al_flag(ni, NonResident)
73 #define NInoClearAttrListNonResident(ni)  clear_nino_al_flag(ni, NonResident)
74
75 #define NInoAttrListDirty(ni)              test_nino_al_flag(ni, Dirty)
76 #define NInoAttrListSetDirty(ni)            set_nino_al_flag(ni, Dirty)
77 #define NInoAttrListClearDirty(ni)        clear_nino_al_flag(ni, Dirty)
78
79 /*
80  * The NTFS in-memory inode structure. It is just used as an extension to the
81  * fields already provided in the VFS inode.
82  */
83 struct _ntfs_inode {
84         u64 mft_no;             /* Inode / mft record number. */
85         MFT_RECORD *mrec;       /* The actual mft record of the inode. */
86         ntfs_volume *vol;       /* Pointer to the ntfs volume of this inode. */
87         unsigned long state;    /* NTFS specific flags describing this inode.
88                                    See ntfs_inode_state_bits above. */
89         /*
90          * Attribute list support (for use by the attribute lookup functions).
91          * Setup during ntfs_open_inode() for all inodes with attribute lists.
92          * Only valid if NI_AttrList is set in state, further attr_list_rl is
93          * only valid if NI_AttrListNonResident is set.
94          */
95         u32 attr_list_size;     /* Length of attribute list value in bytes. */
96         u8 *attr_list;          /* Attribute list value itself. */
97         runlist *attr_list_rl;  /* Run list for the attribute list value. */
98         /* Below fields are always valid. */
99         s32 nr_extents;         /* For a base mft record, the number of
100                                    attached extent inodes (0 if none), for
101                                    extent records this is -1. */
102         union {         /* This union is only used if nr_extents != 0. */
103                 ntfs_inode **extent_nis;/* For nr_extents > 0, array of the
104                                            ntfs inodes of the extent mft
105                                            records belonging to this base
106                                            inode which have been loaded. */
107                 ntfs_inode *base_ni;    /* For nr_extents == -1, the ntfs
108                                            inode of the base mft record. */
109         };
110 };
111
112 extern ntfs_inode *ntfs_inode_open(ntfs_volume *vol, const MFT_REF mref);
113
114 extern int ntfs_inode_close(ntfs_inode *ni);
115
116 extern ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni,
117                 const MFT_REF mref);
118
119 /**
120  * ntfs_inode_mark_dirty - set the inode (and its base inode if it exists) dirty
121  * @ni:         ntfs inode to set dirty
122  *
123  * Set the inode @ni dirty so it is written out later (at the latest at
124  * ntfs_inode_close() time). If @ni is an extent inode, set the base inode
125  * dirty, too.
126  *
127  * This function cannot fail.
128  */
129 static __inline__ void ntfs_inode_mark_dirty(ntfs_inode *ni) {
130         NInoSetDirty(ni);
131         if (ni->nr_extents == -1)
132                 NInoSetDirty(ni->base_ni);
133 }
134
135 extern int ntfs_inode_sync(ntfs_inode *ni);
136
137 #endif /* defined _NTFS_INODE_H */
138