]> wimlib.net Git - wimlib/blob - include/wimlib/dentry.h
Tweak support for extracting paths
[wimlib] / include / wimlib / dentry.h
1 #ifndef _WIMLIB_DENTRY_H
2 #define _WIMLIB_DENTRY_H
3
4 #include "wimlib/compiler.h"
5 #include "wimlib/list.h"
6 #include "wimlib/rbtree.h"
7 #include "wimlib/sha1.h"
8 #include "wimlib/types.h"
9
10 #include <string.h>
11 #include <sys/types.h> /* uid_t, gid_t */
12
13 struct wim_lookup_table;
14 struct wim_lookup_table_entry;
15 struct wimfs_fd;
16 struct wim_inode;
17 struct wim_security_data;
18
19 /* Size of the struct wim_dentry up to and including the file_name_len. */
20 #define WIM_DENTRY_DISK_SIZE    102
21
22 /*
23  * Reparse tags documented at
24  * http://msdn.microsoft.com/en-us/library/dd541667(v=prot.10).aspx
25  */
26 #define WIM_IO_REPARSE_TAG_RESERVED_ZERO        0x00000000
27 #define WIM_IO_REPARSE_TAG_RESERVED_ONE         0x00000001
28 #define WIM_IO_REPARSE_TAG_MOUNT_POINT          0xA0000003
29 #define WIM_IO_REPARSE_TAG_HSM                  0xC0000004
30 #define WIM_IO_REPARSE_TAG_HSM2                 0x80000006
31 #define WIM_IO_REPARSE_TAG_DRIVER_EXTENDER      0x80000005
32 #define WIM_IO_REPARSE_TAG_SIS                  0x80000007
33 #define WIM_IO_REPARSE_TAG_DFS                  0x8000000A
34 #define WIM_IO_REPARSE_TAG_DFSR                 0x80000012
35 #define WIM_IO_REPARSE_TAG_FILTER_MANAGER       0x8000000B
36 #define WIM_IO_REPARSE_TAG_SYMLINK              0xA000000C
37
38 #define FILE_ATTRIBUTE_READONLY            0x00000001
39 #define FILE_ATTRIBUTE_HIDDEN              0x00000002
40 #define FILE_ATTRIBUTE_SYSTEM              0x00000004
41 #define FILE_ATTRIBUTE_DIRECTORY           0x00000010
42 #define FILE_ATTRIBUTE_ARCHIVE             0x00000020
43 #define FILE_ATTRIBUTE_DEVICE              0x00000040
44 #define FILE_ATTRIBUTE_NORMAL              0x00000080
45 #define FILE_ATTRIBUTE_TEMPORARY           0x00000100
46 #define FILE_ATTRIBUTE_SPARSE_FILE         0x00000200
47 #define FILE_ATTRIBUTE_REPARSE_POINT       0x00000400
48 #define FILE_ATTRIBUTE_COMPRESSED          0x00000800
49 #define FILE_ATTRIBUTE_OFFLINE             0x00001000
50 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
51 #define FILE_ATTRIBUTE_ENCRYPTED           0x00004000
52 #define FILE_ATTRIBUTE_VIRTUAL             0x00010000
53
54
55 /* Alternate data stream entry.
56  *
57  * We read this from disk in the read_ads_entries() function; see that function
58  * for more explanation. */
59 struct wim_ads_entry {
60         union {
61                 /* SHA-1 message digest of stream contents */
62                 u8 hash[SHA1_HASH_SIZE];
63
64                 /* The corresponding lookup table entry (only for resolved
65                  * streams) */
66                 struct wim_lookup_table_entry *lte;
67         };
68
69         /* Length of UTF16-encoded stream name, in bytes, not including the
70          * terminating null character; or 0 if the stream is unnamed. */
71         u16 stream_name_nbytes;
72
73         /* Number to identify an alternate data stream even after it's possibly
74          * been moved or renamed. */
75         u32 stream_id;
76
77         /* Stream name (UTF-16LE), null-terminated, or NULL if the stream is
78          * unnamed.  */
79         utf16lechar *stream_name;
80
81         /* Reserved field.  We read it into memory so we can write it out
82          * unchanged. */
83         u64 reserved;
84 };
85
86
87 static inline bool
88 ads_entries_have_same_name(const struct wim_ads_entry *entry_1,
89                            const struct wim_ads_entry *entry_2)
90 {
91         return entry_1->stream_name_nbytes == entry_2->stream_name_nbytes &&
92                memcmp(entry_1->stream_name, entry_2->stream_name,
93                       entry_1->stream_name_nbytes) == 0;
94 }
95
96 /*
97  * In-memory structure for a WIM directory entry (dentry).  There is a directory
98  * tree for each image in the WIM.
99  *
100  * Note that this is a directory entry and not an inode.  Since NTFS allows hard
101  * links, it's possible for a NTFS inode to correspond to multiple WIM dentries.
102  * The hard link group ID field of the on-disk WIM dentry tells us the number of
103  * the NTFS inode that the dentry corresponds to (and this gets placed in
104  * d_inode->i_ino).
105  *
106  * Unfortunately, WIM files do not have an analogue to an inode; instead certain
107  * information, such as file attributes, the security descriptor, and file
108  * streams is replicated in each hard-linked dentry, even though this
109  * information really is associated with an inode.  In-memory, we fix up this
110  * flaw by allocating a `struct wim_inode' for each dentry that contains some of
111  * this duplicated information, then combining the inodes for each hard link
112  * group together.
113  *
114  * Confusingly, it's possible for stream information to be missing from a dentry
115  * in a hard link set, in which case the stream information needs to be gotten
116  * from one of the other dentries in the hard link set.  In addition, it is
117  * possible for dentries to have inconsistent security IDs, file attributes, or
118  * file streams when they share the same hard link ID (don't even ask.  I hope
119  * that Microsoft may have fixed this problem, since I've only noticed it in the
120  * 'install.wim' for Windows 7).  For those dentries, we have to use the
121  * conflicting fields to split up the hard link groups.  (See
122  * dentry_tree_fix_inodes() in hardlink.c).
123  */
124 struct wim_dentry {
125         /* Pointer to the inode for this dentry.  This will contain some
126          * information that was factored out of the on-disk WIM dentry as common
127          * to all dentries in a hard link group.  */
128         struct wim_inode *d_inode;
129
130         /* Node for the parent's red-black tree of child dentries, sorted by
131          * case sensitive long name. */
132         struct rb_node rb_node;
133
134         /* Node for the parent's red-black tree of child dentries, sorted by
135          * case insensitive long name. */
136         struct rb_node rb_node_case_insensitive;
137
138         /* List of dentries in a directory that have different case sensitive
139          * long names but share the same case insensitive long name */
140         struct list_head case_insensitive_conflict_list;
141
142         /* Length of UTF-16LE encoded short filename, in bytes, not including
143          * the terminating zero wide-character. */
144         u16 short_name_nbytes;
145
146         /* Length of UTF-16LE encoded "long" file name, in bytes, not including
147          * the terminating null character. */
148         u16 file_name_nbytes;
149
150         /* Length of full path name encoded using "tchars", in bytes, not
151          * including the terminating null character. */
152         u32 full_path_nbytes;
153
154         /* For extraction operations, this flag will be set on dentries in the
155          * tree being extracted.  Otherwise this will always be 0.  */
156         u8 in_extraction_tree : 1;
157
158         /* For extraction operations, this flag will be set when a dentry in the
159          * tree being extracted is not being extracted for some reason (file
160          * type not supported by target filesystem, contains invalid characters,
161          * or not in one of the multiple sub-trees being extracted).  Otherwise
162          * this will always be 0.  */
163         u8 extraction_skipped : 1;
164
165         /* During extraction extractions, this flag will be set after the
166          * "skeleton" of the dentry has been extracted.  */
167         u8 skeleton_extracted : 1;
168
169         /* When capturing from a NTFS volume using NTFS-3g, this flag is set on
170          * dentries that were created from a filename in the WIN32 or WIN32+DOS
171          * namespaces rather than the POSIX namespace.  Otherwise this will
172          * always be 0.  */
173         u8 is_win32_name : 1;
174
175         /* When verifying the dentry tree after reading it into memory, this
176          * flag will be set on all dentries in a hard link group that have a
177          * nonempty DOS name except one.  This is because it is supposed to be
178          * illegal (on NTFS, at least) for a single inode to have multiple DOS
179          * names.  */
180         u8 dos_name_invalid : 1;
181
182         u8 tmp_flag : 1;
183
184         u8 was_hardlinked : 1;
185
186         /* Temporary list field used to make lists of dentries in a few places.
187          * */
188         struct list_head tmp_list;
189
190         /* Linked list node that places this dentry in the list of aliases for
191          * its inode (d_inode) */
192         struct list_head d_alias;
193
194         /* The parent of this directory entry. */
195         struct wim_dentry *parent;
196
197         /* 'length' and 'subdir_offset' are only used while reading and writing
198          * this dentry; see the corresponding field in
199          * `struct wim_dentry_on_disk' for explanation.  */
200         u64 length;
201         u64 subdir_offset;
202
203         /* These correspond to the two unused fields in the on-disk WIM dentry;
204          * we read them into memory so we can write them unchanged.  These
205          * fields are set to 0 on new dentries.  */
206         u64 d_unused_1;
207         u64 d_unused_2;
208
209         /* Pointer to the UTF-16LE short filename (malloc()ed buffer), or NULL
210          * if this dentry has no short name.  */
211         utf16lechar *short_name;
212
213         /* Pointer to the UTF-16LE filename (malloc()ed buffer), or NULL if this
214          * dentry has no filename.  */
215         utf16lechar *file_name;
216
217         /* Full path to this dentry in the WIM, in platform-dependent tchars
218          * that can be printed without conversion.  By default this field will
219          * be NULL and will only be calculated on-demand by the
220          * calculate_dentry_full_path() or dentry_full_path() functions.  */
221         tchar *_full_path;
222
223         /* (Extraction only) Actual name to extract this dentry as, along with
224          * its length in tchars excluding the NULL terminator.  This usually
225          * will be the same as file_name, with the character encoding converted
226          * if needed.  But if file_name contains characters not accepted on the
227          * current platform, then this may be set slightly differently from
228          * file_name.  This will be either NULL or a malloc()ed buffer that may
229          * alias file_name.  */
230         tchar *extraction_name;
231         size_t extraction_name_nchars;
232 };
233
234 #define rbnode_dentry(node) container_of(node, struct wim_dentry, rb_node)
235
236 /*
237  * WIM inode.
238  *
239  * As mentioned in the comment above `struct wim_dentry', in the WIM file that
240  * is no on-disk analogue of a real inode, as most of these fields are
241  * duplicated in the dentries.  Instead, a `struct wim_inode' is something we
242  * create ourselves to simplify the handling of hard links.
243  */
244 struct wim_inode {
245         /* If i_resolved == 0:
246          *      SHA1 message digest of the contents of the unnamed-data stream
247          *      of this inode.
248          *
249          * If i_resolved == 1:
250          *      Pointer to the lookup table entry for the unnamed data stream
251          *      of this inode, or NULL.
252          *
253          * i_hash corresponds to the 'unnamed_stream_hash' field of the `struct
254          * wim_dentry_on_disk' and the additional caveats documented about that
255          * field apply here (for example, the quirks regarding all-zero hashes).
256          */
257         union {
258                 u8 i_hash[SHA1_HASH_SIZE];
259                 struct wim_lookup_table_entry *i_lte;
260         };
261
262         /* Corresponds to the 'attributes' field of `struct wim_dentry_on_disk';
263          * bitwise OR of the FILE_ATTRIBUTE_* flags that give the attributes of
264          * this inode. */
265         u32 i_attributes;
266
267         /* Root of a red-black tree storing the child dentries of this inode, if
268          * any.  Keyed by wim_dentry->file_name, case sensitively. */
269         struct rb_root i_children;
270
271         /* Root of a red-black tree storing the children of this inode, if any.
272          * Keyed by wim_dentry->file_name, case insensitively. */
273         struct rb_root i_children_case_insensitive;
274
275         /* List of dentries that are aliases for this inode.  There will be
276          * i_nlink dentries in this list.  */
277         struct list_head i_dentry;
278
279         /* Field to place this inode into a list. */
280         union {
281                 /* Hash list node- used in hardlink.c when the inodes are placed
282                  * into a hash table keyed by inode number and optionally device
283                  * number, in order to detect dentries that are aliases for the
284                  * same inode. */
285                 struct hlist_node i_hlist;
286
287                 /* Normal list node- used to connect all the inodes of a WIM image
288                  * into a single linked list referenced from the
289                  * `struct wim_image_metadata' for that image. */
290                 struct list_head i_list;
291         };
292
293         /* Number of dentries that are aliases for this inode.  */
294         u32 i_nlink;
295
296         /* Number of alternate data streams (ADS) associated with this inode */
297         u16 i_num_ads;
298
299         /* Flag that indicates whether this inode's streams have been
300          * "resolved".  By default, the inode starts as "unresolved", meaning
301          * that the i_hash field, along with the hash field of any associated
302          * wim_ads_entry's, are valid and should be used as keys in the WIM
303          * lookup table to find the associated `struct wim_lookup_table_entry'.
304          * But if the inode has been resolved, then each of these fields is
305          * replaced with a pointer directly to the appropriate `struct
306          * wim_lookup_table_entry', or NULL if the stream is empty.  */
307         u8 i_resolved : 1;
308
309         /* Flag used to mark this inode as visited; this is used when visiting
310          * all the inodes in a dentry tree exactly once.  It will be 0 by
311          * default and must be cleared following the tree traversal, even in
312          * error paths.  */
313         u8 i_visited : 1;
314
315         /* Set if the DOS name of an inode has already been extracted.  */
316         u8 i_dos_name_extracted : 1;
317
318         /* 1 iff all ADS entries of this inode are named or if this inode
319          * has no ADS entries  */
320         u8 i_canonical_streams : 1;
321
322         /* Pointer to a malloc()ed array of i_num_ads alternate data stream
323          * entries for this inode.  */
324         struct wim_ads_entry *i_ads_entries;
325
326         /* Creation time, last access time, and last write time for this inode, in
327          * 100-nanosecond intervals since 12:00 a.m UTC January 1, 1601.  They
328          * should correspond to the times gotten by calling GetFileTime() on
329          * Windows. */
330         u64 i_creation_time;
331         u64 i_last_access_time;
332         u64 i_last_write_time;
333
334         /* Corresponds to 'security_id' in `struct wim_dentry_on_disk':  The
335          * index of this inode's security descriptor in the WIM image's table of
336          * security descriptors, or -1.  Note: in verify_inode(), called
337          * whenever a WIM image is loaded, out-of-bounds indices are set to -1,
338          * so the extraction code does not need to do bounds checks.  */
339         int32_t i_security_id;
340
341         /* Identity of a reparse point.  See
342          * http://msdn.microsoft.com/en-us/library/windows/desktop/aa365503(v=vs.85).aspx
343          * for what a reparse point is. */
344         u32 i_reparse_tag;
345
346         /* Unused/unknown fields that we just read into memory so we can
347          * re-write them unchanged.  */
348         u32 i_rp_unknown_1;
349         u16 i_rp_unknown_2;
350
351         /* Corresponds to not_rpfixed in `struct wim_dentry_on_disk':  Set to 0
352          * if reparse point fixups have been done.  Otherwise set to 1.  Note:
353          * this actually may reflect the SYMBOLIC_LINK_RELATIVE flag.
354          */
355         u16 i_not_rpfixed;
356
357         /* Inode number; corresponds to hard_link_group_id in the `struct
358          * wim_dentry_on_disk'.  */
359         u64 i_ino;
360
361         union {
362                 /* Device number, used only during image capture, so we can
363                  * identify hard linked files by the combination of inode number
364                  * and device number (rather than just inode number, which could
365                  * be ambigious if the captured tree spans a mountpoint).  Set
366                  * to 0 otherwise.  */
367                 u64 i_devno;
368
369                 struct {
370
371                         /* Used only during image extraction: pointer to the first path
372                          * (malloc()ed buffer) at which this inode has been extracted.
373                          * Freed and set to NULL after the extraction is done (either
374                          * success or failure).  */
375                         tchar *i_extracted_file;
376
377                         /** Used only during image extraction: "cookie" that
378                          * identifies this extracted file (inode), for example
379                          * an inode number.  Only used if supported by the
380                          * extraction mode.  */
381                         u64 extract_cookie;
382                 };
383
384 #ifdef WITH_FUSE
385                 /* Used only during image mount:  Table of file descriptors that
386                  * have been opened to this inode.  The table is automatically
387                  * freed when the last file descriptor is closed.  */
388                 struct wimfs_fd **i_fds;
389 #endif
390         };
391
392 #ifdef WITH_FUSE
393         u16 i_num_opened_fds;
394         u16 i_num_allocated_fds;
395 #endif
396
397         /* Next alternate data stream ID to be assigned */
398         u32 i_next_stream_id;
399 };
400
401 #define inode_for_each_dentry(dentry, inode) \
402                 list_for_each_entry((dentry), &(inode)->i_dentry, d_alias)
403
404 #define inode_add_dentry(dentry, inode) \
405                 list_add_tail(&(dentry)->d_alias, &(inode)->i_dentry)
406
407 #define inode_first_dentry(inode) \
408                 container_of(inode->i_dentry.next, struct wim_dentry, d_alias)
409
410 #define inode_first_full_path(inode) \
411                 dentry_full_path(inode_first_dentry(inode))
412
413 static inline bool
414 dentry_is_first_in_inode(const struct wim_dentry *dentry)
415 {
416         return inode_first_dentry(dentry->d_inode) == dentry;
417 }
418
419 extern u64
420 dentry_out_total_length(const struct wim_dentry *dentry);
421
422 extern int
423 for_dentry_in_tree(struct wim_dentry *root,
424                    int (*visitor)(struct wim_dentry*, void*),
425                    void *args);
426
427 extern int
428 for_dentry_in_rbtree(struct rb_node *node,
429                      int (*visitor)(struct wim_dentry *, void *),
430                      void *arg);
431
432 extern int
433 for_dentry_child(const struct wim_dentry *dentry,
434                  int (*visitor)(struct wim_dentry *, void *),
435                  void *arg);
436
437 extern int
438 for_dentry_in_tree_depth(struct wim_dentry *root,
439                          int (*visitor)(struct wim_dentry*, void*),
440                          void *args);
441
442 extern void
443 calculate_subdir_offsets(struct wim_dentry *dentry, u64 *subdir_offset_p);
444
445 extern int
446 set_dentry_name(struct wim_dentry *dentry, const tchar *new_name);
447
448
449 /* Note: the NTFS-3g headers define CASE_SENSITIVE, hence the WIMLIB prefix.  */
450 typedef enum {
451         /* Use either case-sensitive or case-insensitive search, depending on
452          * the variable @default_ignore_case.  */
453         WIMLIB_CASE_PLATFORM_DEFAULT = 0,
454
455         /* Use case-sensitive search.  */
456         WIMLIB_CASE_SENSITIVE = 1,
457
458         /* Use case-insensitive search.  */
459         WIMLIB_CASE_INSENSITIVE = 2,
460 } CASE_SENSITIVITY_TYPE;
461
462 extern bool default_ignore_case;
463
464 extern struct wim_dentry *
465 get_dentry(struct WIMStruct *wim, const tchar *path,
466            CASE_SENSITIVITY_TYPE case_type);
467
468 extern struct wim_dentry *
469 get_dentry_child_with_name(const struct wim_dentry *dentry,
470                            const tchar *name,
471                            CASE_SENSITIVITY_TYPE case_type);
472
473 extern struct wim_dentry *
474 get_dentry_child_with_utf16le_name(const struct wim_dentry *dentry,
475                                    const utf16lechar *name,
476                                    size_t name_nbytes,
477                                    CASE_SENSITIVITY_TYPE case_type);
478
479 extern struct wim_dentry *
480 get_parent_dentry(struct WIMStruct *wim, const tchar *path,
481                   CASE_SENSITIVITY_TYPE case_type);
482
483 extern int
484 print_dentry(struct wim_dentry *dentry, void *lookup_table);
485
486 extern int
487 print_dentry_full_path(struct wim_dentry *entry, void *ignore);
488
489 extern int
490 calculate_dentry_full_path(struct wim_dentry *dentry);
491
492 extern int
493 calculate_dentry_tree_full_paths(struct wim_dentry *root);
494
495 extern tchar *
496 dentry_full_path(struct wim_dentry *dentry);
497
498 extern struct wim_inode *
499 new_timeless_inode(void) _malloc_attribute;
500
501 extern int
502 new_dentry(const tchar *name, struct wim_dentry **dentry_ret);
503
504 extern int
505 new_dentry_with_inode(const tchar *name, struct wim_dentry **dentry_ret);
506
507 extern int
508 new_dentry_with_timeless_inode(const tchar *name, struct wim_dentry **dentry_ret);
509
510 extern void
511 dentry_tree_clear_inode_visited(struct wim_dentry *root);
512
513 extern int
514 new_filler_directory(const tchar *name, struct wim_dentry **dentry_ret);
515
516 extern void
517 free_inode(struct wim_inode *inode);
518
519 extern void
520 free_dentry(struct wim_dentry *dentry);
521
522 extern void
523 put_dentry(struct wim_dentry *dentry);
524
525 extern void
526 free_dentry_tree(struct wim_dentry *root,
527                  struct wim_lookup_table *lookup_table);
528
529 extern void
530 unlink_dentry(struct wim_dentry *dentry);
531
532 extern struct wim_dentry *
533 dentry_add_child(struct wim_dentry * restrict parent,
534                  struct wim_dentry * restrict child);
535
536 extern int
537 rename_wim_path(WIMStruct *wim, const tchar *from, const tchar *to,
538                 CASE_SENSITIVITY_TYPE case_type);
539
540 extern struct wim_ads_entry *
541 inode_get_ads_entry(struct wim_inode *inode, const tchar *stream_name,
542                     u16 *idx_ret);
543
544 extern struct wim_ads_entry *
545 inode_add_ads_utf16le(struct wim_inode *inode,
546                       const utf16lechar *stream_name,
547                       size_t stream_name_nbytes);
548
549 extern struct wim_ads_entry *
550 inode_add_ads(struct wim_inode *dentry, const tchar *stream_name);
551
552 extern int
553 inode_add_ads_with_data(struct wim_inode *inode, const tchar *name,
554                         const void *value, size_t size,
555                         struct wim_lookup_table *lookup_table);
556
557 bool
558 inode_has_named_stream(const struct wim_inode *inode);
559
560 extern int
561 inode_set_unnamed_stream(struct wim_inode *inode, const void *data, size_t len,
562                          struct wim_lookup_table *lookup_table);
563
564 extern void
565 inode_remove_ads(struct wim_inode *inode, u16 idx,
566                  struct wim_lookup_table *lookup_table);
567
568
569 #define WIMLIB_UNIX_DATA_TAG "$$__wimlib_UNIX_data"
570 #define WIMLIB_UNIX_DATA_TAG_NBYTES (sizeof(WIMLIB_UNIX_DATA_TAG) - 1)
571
572 #define WIMLIB_UNIX_DATA_TAG_UTF16LE "$\0$\0_\0_\0w\0i\0m\0l\0i\0b\0_\0U\0N\0I\0X\0_\0d\0a\0t\0a\0"
573 #define WIMLIB_UNIX_DATA_TAG_UTF16LE_NBYTES (sizeof(WIMLIB_UNIX_DATA_TAG_UTF16LE) - 1)
574
575 static inline bool
576 ads_entry_is_unix_data(const struct wim_ads_entry *entry)
577 {
578         return (entry->stream_name_nbytes ==
579                         WIMLIB_UNIX_DATA_TAG_UTF16LE_NBYTES) &&
580                 !memcmp(entry->stream_name, WIMLIB_UNIX_DATA_TAG_UTF16LE,
581                         WIMLIB_UNIX_DATA_TAG_UTF16LE_NBYTES);
582 }
583
584 static inline bool
585 ads_entry_is_named_stream(const struct wim_ads_entry *entry)
586 {
587         return entry->stream_name_nbytes != 0 && !ads_entry_is_unix_data(entry);
588 }
589
590 #ifndef __WIN32__
591 /* Format for special alternate data stream entries to store UNIX data for files
592  * and directories (see: WIMLIB_ADD_FLAG_UNIX_DATA) */
593 struct wimlib_unix_data {
594         u16 version; /* Must be 0 */
595         u16 uid;
596         u16 gid;
597         u16 mode;
598 } _packed_attribute;
599
600 #define NO_UNIX_DATA (-1)
601 #define BAD_UNIX_DATA (-2)
602 extern int
603 inode_get_unix_data(const struct wim_inode *inode,
604                     struct wimlib_unix_data *unix_data,
605                     u16 *stream_idx_ret);
606
607 #define UNIX_DATA_UID    0x1
608 #define UNIX_DATA_GID    0x2
609 #define UNIX_DATA_MODE   0x4
610 #define UNIX_DATA_ALL    (UNIX_DATA_UID | UNIX_DATA_GID | UNIX_DATA_MODE)
611 #define UNIX_DATA_CREATE 0x8
612 extern int
613 inode_set_unix_data(struct wim_inode *inode, uid_t uid, gid_t gid, mode_t mode,
614                     struct wim_lookup_table *lookup_table, int which);
615 #endif /* !__WIN32__ */
616
617 extern bool
618 inode_has_unix_data(const struct wim_inode *inode);
619
620 extern int
621 read_dentry(const u8 * restrict metadata_resource,
622             u64 metadata_resource_len, u64 offset,
623             struct wim_dentry * restrict dentry);
624
625 extern int
626 read_dentry_tree(const u8 * restrict metadata_resource,
627                  u64 metadata_resource_len,
628                  struct wim_dentry * restrict dentry);
629
630 extern u8 *
631 write_dentry_tree(const struct wim_dentry * restrict tree,
632                   u8 * restrict p);
633
634 static inline bool
635 dentry_is_root(const struct wim_dentry *dentry)
636 {
637         return dentry->parent == dentry;
638 }
639
640 static inline bool
641 inode_is_directory(const struct wim_inode *inode)
642 {
643         return (inode->i_attributes & (FILE_ATTRIBUTE_DIRECTORY |
644                                        FILE_ATTRIBUTE_REPARSE_POINT))
645                         == FILE_ATTRIBUTE_DIRECTORY;
646 }
647
648 static inline bool
649 inode_is_encrypted_directory(const struct wim_inode *inode)
650 {
651         return ((inode->i_attributes & (FILE_ATTRIBUTE_DIRECTORY |
652                                         FILE_ATTRIBUTE_ENCRYPTED))
653                 == (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_ENCRYPTED));
654 }
655
656 static inline bool
657 dentry_is_directory(const struct wim_dentry *dentry)
658 {
659         return inode_is_directory(dentry->d_inode);
660 }
661
662 /* For our purposes, we consider "real" symlinks and "junction points" to both
663  * be symlinks. */
664 static inline bool
665 inode_is_symlink(const struct wim_inode *inode)
666 {
667         return (inode->i_attributes & FILE_ATTRIBUTE_REPARSE_POINT)
668                 && (inode->i_reparse_tag == WIM_IO_REPARSE_TAG_SYMLINK ||
669                     inode->i_reparse_tag == WIM_IO_REPARSE_TAG_MOUNT_POINT);
670 }
671
672 static inline bool
673 inode_has_children(const struct wim_inode *inode)
674 {
675         return inode->i_children.rb_node != NULL;
676 }
677
678 static inline bool
679 dentry_has_children(const struct wim_dentry *dentry)
680 {
681         return inode_has_children(dentry->d_inode);
682 }
683
684 static inline bool
685 dentry_has_short_name(const struct wim_dentry *dentry)
686 {
687         return dentry->short_name_nbytes != 0;
688 }
689
690 static inline bool
691 dentry_has_long_name(const struct wim_dentry *dentry)
692 {
693         return dentry->file_name_nbytes != 0;
694 }
695
696 extern void
697 inode_ref_streams(struct wim_inode *inode);
698
699 extern int
700 dentry_tree_fix_inodes(struct wim_dentry *root, struct list_head *inode_list);
701
702 extern int
703 verify_inode(struct wim_inode *inode, const struct wim_security_data *sd);
704
705 #endif /* _WIMLIB_DENTRY_H */