]> wimlib.net Git - wimlib/blob - include/wimlib/reparse.h
hc_matchfinder.h: fix comment
[wimlib] / include / wimlib / reparse.h
1 #ifndef _WIMLIB_REPARSE_H
2 #define _WIMLIB_REPARSE_H
3
4 #include "wimlib/inode.h" /* for reparse tag definitions */
5 #include "wimlib/types.h"
6
7 struct blob_descriptor;
8 struct blob_table;
9
10 /* Windows enforces this limit on the size of a reparse point buffer.  */
11 #define REPARSE_POINT_MAX_SIZE  16384
12
13 /*
14  * On-disk format of a reparse point buffer.  See:
15  *      https://msdn.microsoft.com/en-us/library/dd541671.aspx
16  *
17  * Note: we are not using _packed_attribute for this structure, so only cast to
18  * this if properly aligned!
19  */
20 struct reparse_buffer_disk {
21         le32 rptag;
22         le16 rpdatalen;
23         le16 rpreserved;
24         union {
25                 u8 rpdata[REPARSE_POINT_MAX_SIZE - 8];
26
27                 struct {
28                         le16 substitute_name_offset;
29                         le16 substitute_name_nbytes;
30                         le16 print_name_offset;
31                         le16 print_name_nbytes;
32
33                         union {
34                                 struct {
35                                         u8 data[REPARSE_POINT_MAX_SIZE - 16];
36                                 } junction;
37
38                                 struct {
39                                         le32 flags;
40                         #define SYMBOLIC_LINK_RELATIVE 0x00000001
41                                         u8 data[REPARSE_POINT_MAX_SIZE - 20];
42                                 } symlink;
43                         };
44                 } link;
45         };
46 };
47
48 #define REPARSE_DATA_OFFSET (offsetof(struct reparse_buffer_disk, rpdata))
49
50 #define REPARSE_DATA_MAX_SIZE (REPARSE_POINT_MAX_SIZE - REPARSE_DATA_OFFSET)
51
52 static inline void
53 check_reparse_buffer_disk(void)
54 {
55         BUILD_BUG_ON(offsetof(struct reparse_buffer_disk, rpdata) != 8);
56         BUILD_BUG_ON(offsetof(struct reparse_buffer_disk, link.junction.data) != 16);
57         BUILD_BUG_ON(offsetof(struct reparse_buffer_disk, link.symlink.data) != 20);
58         BUILD_BUG_ON(sizeof(struct reparse_buffer_disk) != REPARSE_POINT_MAX_SIZE);
59 }
60
61 /* Wrapper around a symbolic link or junction reparse point
62  * (WIM_IO_REPARSE_TAG_SYMLINK or WIM_IO_REPARSE_TAG_MOUNT_POINT)  */
63 struct link_reparse_point {
64
65         u32 rptag;
66         u16 rpreserved;
67
68         /* Flags, valid for symbolic links only  */
69         u32 symlink_flags;
70
71         /* Pointers to the substitute name and print name of the link,
72          * potentially not null terminated  */
73         utf16lechar *substitute_name;
74         utf16lechar *print_name;
75
76         /* Lengths of the substitute and print names in bytes, not including
77          * their null terminators if present  */
78         size_t substitute_name_nbytes;
79         size_t print_name_nbytes;
80 };
81
82 static inline bool
83 link_is_relative_symlink(const struct link_reparse_point *link)
84 {
85         return link->rptag == WIM_IO_REPARSE_TAG_SYMLINK &&
86                (link->symlink_flags & SYMBOLIC_LINK_RELATIVE);
87 }
88
89 extern void
90 complete_reparse_point(struct reparse_buffer_disk *rpbuf,
91                        const struct wim_inode *inode, u16 blob_size);
92
93 extern int
94 parse_link_reparse_point(const struct reparse_buffer_disk *rpbuf, u16 rpbuflen,
95                          struct link_reparse_point *link);
96
97 extern int
98 make_link_reparse_point(const struct link_reparse_point *link,
99                         struct reparse_buffer_disk *rpbuf, u16 *rpbuflen_ret);
100
101 #ifndef __WIN32__
102 extern int
103 wim_inode_readlink(const struct wim_inode *inode, char *buf, size_t bufsize,
104                    const struct blob_descriptor *blob,
105                    const char *altroot, size_t altroot_len);
106
107 extern int
108 wim_inode_set_symlink(struct wim_inode *inode, const char *target,
109                       struct blob_table *blob_table);
110 #endif
111
112 #endif /* _WIMLIB_REPARSE_H */