2
* $Id: types.h,v 1.6 2001/12/15 05:13:08 antona Exp $
4
* types.h - Misc type definitions not related to on-disk structure. Part of
5
* the Linux-NTFS project.
7
* Copyright (c) 2000,2001 Anton Altaparmakov.
9
* This program/include file is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License as published
11
* by the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* This program/include file is distributed in the hope that it will be
15
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
16
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program (in the main directory of the Linux-NTFS
21
* distribution in the file COPYING); if not, write to the Free Software
22
* Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36
* The last vcn (in fact the last vcn + 1) is reached when length == 0.
38
* When lcn == -1 this means that the count vcns starting at vcn are not
39
* physically allocated (i.e. this is a hole / data is sparse).
41
* For attribute extents which have the previous_extents flag set, the first
42
* entry is a sparse entry (lcn == -1). It is used to get the vcn count up to
43
* lowest_vcn for that extent.
45
typedef struct { /* In memory vcn to lcn mapping structure element. */
46
VCN vcn; /* vcn = Starting virtual cluster number. */
47
LCN lcn; /* lcn = Starting logical cluster number. */
48
__u64 length; /* Run length in clusters. */
51
typedef run_list_element run_list; /* In memory vcn to lcn mapping array. */
54
* Union of all known attribute values. For convenience. Used in the attr
58
__u8; /* Unnamed __u8 to serve as default when just using
59
a_val without specifying any of the below. */
60
STANDARD_INFORMATION std_inf;
61
ATTR_LIST_ENTRY al_entry;
62
FILE_NAME_ATTR filename;
63
OBJECT_ID_ATTR obj_id;
64
SECURITY_DESCRIPTOR_ATTR sec_desc;
66
VOLUME_INFORMATION vol_inf;
68
INDEX_ROOT index_root;
69
INDEX_BLOCK index_blk;
71
REPARSE_POINT reparse;
72
EA_INFORMATION ea_inf;
74
PROPERTY_SET property_set;
75
LOGGED_UTILITY_STREAM logged_util_stream;
80
* Necessary forward definitions and typedefs.
83
typedef struct _ntfs_attr attr;
86
typedef struct _mft_entry mft_entry;
89
typedef struct _ntfs_file ntfs_file;
92
typedef struct _ntfs_volume ntfs_volume;
95
* attr - structure describing a mapped attribute
96
* @a_rec: attribute record of the attribute
97
* @a_flags: flags describing the attribute
98
* @a_val: attribute value
99
* @a_run_list: run list of the attribute value
100
* @a_count: usage count of the attribute
101
* @a_dirty_list: anchor for the @a_vol->dirty_attrs linked list
102
* @a_vol: volume the attribute belongs to
103
* @a_m_entry: mft entry @a_rec is contained in
104
* @a_base_m_entry: base mft entry holding the attribute list attribute
105
* @a_attr_list_entry: attribute list entry of this attribute
107
* @a_rec is the attribute record (ATTR_REC *) of the attribute (and is always
110
* The following flags are defined for @a_flags:
111
* dirty - Attribute value is dirty. Needs to be written to disk.
112
* Only for non_resident attributes. For resident ones
113
* the mft entry is set dirty. Note: when the meta data
114
* part of the attribute is dirtied the mft record is
115
* marked dirty directly. No flag reflects this in the
116
* attr structure as it is unnecessary.
117
* val_mapped - Attribute value is mapped. If not mapped @a_val and
118
* @a_dirty_list are not defined.
119
* error - There was some kind of error on I/O so it is possible
120
* that one or more of the other fields are corrupt.
121
* non_resident - Attribute is not resident. If resident, @a_run_list
122
* and @a_dirty_list are not defined.
123
* in_attr_list - Attribute is described by the attribute list attribute
124
* @a_base_m_entry->m_attr_list, the entry in this is
125
* @a_attr_list_entry.
126
* in_ext_record - Attribute is described by the attribute list
127
* attribute and it is stored in an extension record
128
* (pointed to by @a_m_entry) rather than in the base mft
129
* record (pointed to by @a_base_m_entry). This only
130
* makes sense if in_attr_list is set.
131
* previous_extents - Attribute is not the first extent. Only makes sense
132
* if in_attr_list is set. Also, if previous_extents is
133
* set, this implies in_ext_record is also set.
134
* last_extent - Attribute is the last extent. So if there are no
135
* previous_extents and this is the last_extent, we know
136
* there are no extents at all. Only make sense if
137
* in_attr_list is set. Note, we don't keep pointers to
138
* the prev/next extents as their attributes are not
139
* necessarily mapped.
141
* @a_val points to the attribute value of the attribute and will either point
142
* into @a_rec (resident attribute) or it will point to a especially for it
143
* allocated memory which has to be free()d when the attribute is unmapped.
144
* @a_val is only valid when the val_mapped flag is set in @a_flags.
146
* It is important to note that @a_val contains only the mapped portion of this
147
* extent of the attribute value which is indicated by a lcn >= 0 in the run
150
* If lcn is -1, @a_val does contain this portion of the value, but it is all
151
* zero, and there is no storage allocated for it (it is a sparse run). When
152
* writing it to disk, it is checked for being zero again and if it is, the
153
* (zero) data is not written to disk, but a sparse entry is saved in the
154
* mapping pairs array. If it is not zero, storage is allocated on disk and the
155
* data is written. The run list and mapping pairs array is then updated to
156
* reflect this and lcn is no longer -1.
158
* @a_run_list is only valid if the non_resident flag is set. It will only hold
159
* the part of the run list belonging to this extent. If previous_extents is
160
* zero and last_extent is set, this is the full run_list as there are no more
161
* extents. Should the vcn being looked for not be present in @a_run_list, it
162
* should be checked for other extents before returning out of bounds error
163
* (check previous_extents/last_extent flags first).
165
* Note: If previous_extents is set then the first entry of @a_run_list has a
166
* vcn equal to lowest_vcn of this extent. We do NOT have a virtual sparse
167
* entry (vcn = 0, lcn = -1, and length = lowest_vcn) at the beginning, unlike
168
* the WinNT/2k NTFS drivers. IMO this only makes things more complex instead
169
* of easier. If you are familiar with Win NTFS driver this is something to
170
* watch out for... (AIA)
172
* Note, that @a_run_list may be NULL which means that the run list has not
173
* been extracted from @a_rec (yet). This can only happen when the attribute
174
* value is not mapped. If val_mapped is set, @a_run_list must be valid.
176
* @a_count is the number of times the attribute value has been mapped. When it
177
* reaches zero the value may be safely unmapped (after being synced if dirty
178
* and hence also non_resident). This can be done at any point in time. Remember
179
* we only free() the memory if the attribute is non resident! Once the value is
180
* unmapped, it is also safe to free() @a_run_list AND set it to NULL.
182
* @a_dirty_list anchors the attribute entry into the dirty_attrs list of
183
* @a_vol. Used when syncing the volume to be able to quickly walk all dirty
184
* attributes and sync them as well. Only applies to non_resident attributes
185
* as resident ones are covered by virtue of being contained inside their
186
* mft entries (@a_m_entry) which are dirty and synced to disk, already.
188
* @a_vol is the volume the attribute belongs to. This is just so lookups are
189
* quicker. Otherwise it could be obtained from @m_entry->m_vol.
191
* @a_m_entry points to the mft entry in which the attribute is held. If the
192
* attribute is in the base mft record, @a_m_entry is also the base mft record
193
* and @a_base_m_entry equals @m_entry (in_ext_record flag is zero). If the
194
* attribute is located in an extension mft record, @a_base_m_entry points to
195
* the mft entry of the base mft record and the in_ext_record flag is set in
196
* @a_flags (implies in_attr_list flag is also set).
198
* If in_attr_list is set, @a_base_m_entry points to the mft entry containing
199
* the attribute list attribute describing this attribute. The attribute list is
200
* obtained from @a_base_m_entry->m_attr_list.
202
* If in_attr_list is set, @a_attr_list_entry points to the attribute list entry
203
* within the attribute list attribute which describes this attribute.
205
* Note, we don't store the file this attribute belongs to, as this information
206
* is irrelevant for all intents and purposes and can be obtained from
207
* @m_entry->m_file should it be needed at some point.
211
unsigned long a_flags;
213
run_list *a_run_list;
214
unsigned int a_count;
215
struct list_head a_dirty_list;
217
mft_entry *a_m_entry;
218
mft_entry *a_base_m_entry;
219
ATTR_LIST_ENTRY *a_attr_list_entry;
223
* mft_entry - structure describing a loaded mft record
224
* @m_rec: mft record of this mft entry
225
* @m_flags: flags describing the mft entry
226
* @m_ref: mft reference of this mft entry (includes sequence no.)
227
* @m_count: usage count of the mft entry
228
* @m_mapped_attrs: array of all mapped attributes of this mft entry
229
* @nr_mapped_attrs: number of mapped attributes in the @m_mapped_attrs array
230
* @m_file: file this mft entry belongs to (or NULL if none)
231
* @m_list: anchor for the @m_vol->mft_entries linked list
232
* @m_dirty_list: anchor for the @m_vol->dirty_mft_entries linked list
233
* @m_vol: volume the mft entry belongs to
234
* @m_attr_list: the attribute list value of this (base) mft entry
236
* Each loaded mft record is represented by a mft_entry structure.
238
* @m_rec is a pointer to the actual MFT_RECORD. Only valid if mapped flag is
241
* @m_flags is a set of flags describing the mft entry / record. The
242
* following flags are defined:
243
* mapped - Is the MFT_RECORD actually in memory? (i.e. Is @m_rec
245
* dirty - Does the record need to be written to disk? If not,
246
* it is safe to discard @m_rec, but only if @m_count is
248
* error - When reading the entry from disk it was detected that
249
* it is corrupt. For example, it could be that a multi
250
* sector transfer error was detected.
251
* is_base_record - Is this mft record a base record?
252
* attr_list_present - Set if an attribute list is present in this
253
* mft record. This implies that is_base_record
255
* attr_list_mapped - Set if the attribute list is mapped. Implies
256
* that is_base_record and attr_list_present are
259
* @m_ref is the mft reference of the mft record described by this entry. This
260
* includes the sequence number for consistency checking purposes.
262
* @m_count is the usage count. When zero this record is not referenced anywhere
263
* and can be thrown away safely (writing it to disk first if the dirty flag is
266
* @m_mapped_attrs is an array of pointers to all mapped attributes of this mft
269
* @nr_mapped_attrs is the number of mapped attributes and hence the number of
270
* elements in @m_mapped_attrs.
272
* @m_file is the ntfs_file this mft entry belongs to. If this is NULL, the mft
273
* entry does not have a file associated with it. This can happen when a file is
274
* closed but the associated mft entries are left in the cache or when mft
275
* entries are directly accessed at low level for whatever reason.
277
* @m_list is an anchor for the @m_vol->mft_entries linked list.
279
* @m_dirty_list is an anchor for the @m_vol->dirty_mft_enties linked list.
280
* Only valid if the dirty flag is set.
282
* @m_vol is the ntfs_volume this entry belongs to.
284
* @m_attr_list is a pointer to the attribute list attribute value. Only if
285
* @m_flags has the attr_list_mapped flag set (which implies that is_base_record
286
* and attr_list_present flags are set, too). This will effectively just contain
287
* the same memory reference as the @a_val field of the mapped attribute list
292
unsigned long m_flags;
294
unsigned int m_count;
295
attr **m_mapped_attrs;
296
unsigned int nr_mapped_attrs;
298
struct list_head m_list;
299
struct list_head m_dirty_list;
301
ATTR_LIST_ENTRY *m_attr_list;
305
* NOTE: I have completely ignored the existence of things like directories
306
* and directory references for the moment! These will just be added later on.
307
* The directories themselves are of course covered by being base mft records
308
* and hence follow the same semantics like every other mft record.
312
* ntfs_file - structure describing an open file
313
* @f_m_refs: array of mft references belonging to this file
314
* @f_m_entries: array mft entries belonging to the @f_m_refs
315
* @nr_m_refs: number of entries in above two arrays
316
* @f_count: usage count of the file
317
* @f_vol: volume the file belongs to
318
* @f_list: anchor for the @f_vol->open_files list
320
* Each open file is described by an ntfs_file structure.
322
* @f_m_refs is the mft references of the file (i.e. the on disk inode numbers).
323
* This is an array of MFT_REFs. The first reference is the base mft record and
324
* if any others exist they are the associated loaded extension mft records.
325
* Used for attribute list purposes.
327
* @f_m_entries is the loaded mft records for the file. This is an array of
328
* pointers to mft_entries, corresponding to the f_m_refs. This is not strictly
329
* necessary but results in a big speed up as we don't need to search the
330
* @f_vol->mft_entries list every time.
332
* When an entry is referenced in the above lists the usage count for the
333
* corresponding entry is increased by one.
335
* @nr_m_refs is the number of records in the @m_refs and @m_entries arrays. If
336
* it is greater 1, we know there must be an attribute list attribute (but if
337
* equals 1, we cannot assume there isn't one). This is of course the same as a
338
* possible nr_m_entries, but refs is shorter to write. (-8
340
* @f_count it the usage count. When zero, this file is no longer open by anyone
341
* and is thrown away. No need to concern oneself with dirty state as this is
342
* done on a mft_entry level, i.e. a level below the idea of files.
344
* @f_vol is the volume the file belongs to.
346
* @f_list is an anchor into @f_vol->files list. When @f_count reaches 0, the
347
* file is unlinked from the list and disposed off.
351
mft_entry **f_m_entries;
352
unsigned int nr_m_refs;
353
unsigned int f_count;
355
struct list_head f_list;
359
* FIXME: For RAID stuff will need the fd and dev_name variables to be arrays
360
* or lists or something... Also will need to know the number of sectors (and
361
* sector size if not 512) of each device making up the RAID array. Obviously,
362
* will need RAID information as well like which RAID is used together with
363
* state information, etc. But that is the far future.
367
* ntfs_volume - structure describing an open volume in memory
368
* FIXME: put in the remaining fields...
369
* @open_files: linked list of all opened files
370
* @nr_open_files: number of @open_files
371
* @max_open_files: maximum number of @open_files
372
* @mft_entries: linked list of all mft entries cached in memory
373
* @nr_mft_entries: number of @mft_entries
374
* @dirty_mft_entries: linked list of all dirty mft entries
375
* @nr_dirty_mft_entries: number of @dirty_mft_entries
376
* @dirty_attrs: linked list of all dirty, mapped attributes
377
* @nr_dirty_attrs: number of @dirty_attrs
378
* @v_list: anchor for list of mounted volumes
380
* @open_files is a linked list of ntfs_file struct pointers, keeping track of
381
* of all open files. When a file is opened it is added to the back of this list
382
* as we do not expect to be closing the file again that soon.
384
* @nr_open_files is the number of @open_files.
386
* @max_open_files is the maximum number of @open_files allowed.
388
* @mft_entries is a linked list of all loaded mft records (disk inodes) in
389
* order of ascending mft record number (disk inode number, i.e. disregarding
390
* the sequence number). Note, the list members are not the actual MFT_RECORDS,
391
* but in memory mft_entry structs.
393
* @nr_mft_entries is the number of @mft_entries.
395
* @dirty_mft_entries is a linked list of all loaded mft records which are
396
* dirty. Used for flushing the dirty mft entries - when one is marked dirty,
397
* the entry is added to the end of this list. When it is flushed to disk, it is
398
* marked clean and removed from this list. Effectively a FIFO.
400
* @nr_dirty_mft_entries is the number of @dirty_mft_entries.
402
* @dirty_attrs is a linked list of all dirty, non-resident, mapped attributes.
404
* @nr_dirty_attrs is the number of @dirty_attrs.
406
* @v_list is an anchor for the linked list of mounted volume.
408
struct _ntfs_volume {
409
int fd; /* File descriptor associated with volume. */
410
char *dev_name; /* Name of the device/file the volume is in. */
411
char *vol_name; /* Name of the volume from the volume name
413
/* Version nos. and flags are from the volume information attribute. */
414
__u8 major_ver; /* Ntfs major version of volume. */
415
__u8 minor_ver; /* Ntfs minor version of volume. */
416
__u16 flags; /* Bit array of VOLUME_* flags. */
417
__s64 number_of_clusters;/* Volume size in clusters, hence also the
418
number of bits in lcn_bitmap. */
419
__u32 cluster_size; /* Byte size of a cluster. */
420
__u32 mft_record_size; /* Byte size of a mft record. */
421
__s64 mft_lcn; /* Logical cluster number of the data attribute
423
__s64 mftmirr_lcn; /* Logical cluster number of the data attribute
424
for FILE_$MftMirr. */
425
__u8 cluster_size_bits; /* Log(2) of the byte size of a cluster. */
426
__u8 mft_record_size_bits;/* Log(2) of the byte size of a mft record. */
427
__u8 *lcn_bitmap; /* Value of data attribute of FILE_$Bitmap. Each
428
bit represents a cluster on the volume, bit 0
429
representing lcn 0 and so on. A set bit means
430
that the cluster is in use and a zero bit
431
means the cluster is free. */
432
__u8 *mft_bitmap; /* Value of bitmap attribute of FILE_$Mft. Has
433
same interpretation as the lcn_bitmap above
434
but except that it keeps track of the usage
435
of the mft records rather than the lcns. */
436
run_list *mft_runlist; /* Decompressed run list of the data attribute
438
__s64 number_of_mft_records; /* Number of records in the mft, equals
439
the number of bits in mft_bitmap. */
440
uchar_t *upcase; /* Upper case equivalents of all 65536
441
2-byte Unicode characters. Obtained
442
from FILE_$UpCase. */
443
__u32 upcase_len; /* Length in Unicode characters of the
445
struct list_head open_files;
448
struct list_head mft_entries;
450
struct list_head dirty_mft_entries;
451
int nr_dirty_mft_entries;
452
struct list_head dirty_attrs;
454
struct list_head v_list;
457
#endif /* defined NTFS_TYPES_H */