]> wimlib.net Git - wimlib/blob - include/wimlib/reparse.h
reference.c: correct rollback in error paths
[wimlib] / include / wimlib / reparse.h
1 #ifndef _WIMLIB_REPARSE_H
2 #define _WIMLIB_REPARSE_H
3
4 #include "wimlib/types.h"
5
6 struct wim_inode;
7 struct wim_lookup_table;
8
9 #define REPARSE_POINT_MAX_SIZE (16 * 1024)
10
11 /* On-disk format of reparse point buffer  */
12 struct reparse_buffer_disk {
13         le32 rptag;
14         le16 rpdatalen;
15         le16 rpreserved;
16         union {
17                 u8 rpdata[REPARSE_POINT_MAX_SIZE - 8];
18
19                 struct {
20                         le16 substitute_name_offset;
21                         le16 substitute_name_nbytes;
22                         le16 print_name_offset;
23                         le16 print_name_nbytes;
24                         le32 rpflags;
25                         u8 data[REPARSE_POINT_MAX_SIZE - 20];
26                 } _packed_attribute symlink;
27
28                 struct {
29                         le16 substitute_name_offset;
30                         le16 substitute_name_nbytes;
31                         le16 print_name_offset;
32                         le16 print_name_nbytes;
33                         u8 data[REPARSE_POINT_MAX_SIZE - 16];
34                 } _packed_attribute junction;
35         };
36 } _packed_attribute;
37
38 #define REPARSE_DATA_OFFSET (offsetof(struct reparse_buffer_disk, rpdata))
39
40 #define REPARSE_DATA_MAX_SIZE (REPARSE_POINT_MAX_SIZE - REPARSE_DATA_OFFSET)
41
42
43 /* Structured format for symbolic link, junction point, or mount point reparse
44  * data. */
45 struct reparse_data {
46         /* Reparse point tag (see WIM_IO_REPARSE_TAG_* values) */
47         u32 rptag;
48
49         /* Length of reparse data, not including the 8-byte header (ReparseTag,
50          * ReparseDataLength, ReparseReserved) */
51         u16 rpdatalen;
52
53         /* ReparseReserved */
54         u16 rpreserved;
55
56         /* Flags (only for WIM_IO_REPARSE_TAG_SYMLINK reparse points).
57          * SYMBOLIC_LINK_RELATIVE means this is a relative symbolic link;
58          * otherwise should be set to 0. */
59 #define SYMBOLIC_LINK_RELATIVE 0x00000001
60         u32 rpflags;
61
62         /* Pointer to the substitute name of the link (UTF-16LE). */
63         utf16lechar *substitute_name;
64
65         /* Pointer to the print name of the link (UTF-16LE). */
66         utf16lechar *print_name;
67
68         /* Number of bytes of the substitute name, not including null terminator
69          * if present */
70         u16 substitute_name_nbytes;
71
72         /* Number of bytes of the print name, not including null terminator if
73          * present */
74         u16 print_name_nbytes;
75 };
76
77 extern int
78 parse_reparse_data(const u8 * restrict rpbuf, u16 rpbuflen,
79                    struct reparse_data * restrict rpdata);
80
81 extern int
82 make_reparse_buffer(const struct reparse_data * restrict rpdata,
83                     u8 * restrict rpbuf,
84                     u16 * restrict rpbuflen_ret);
85
86 extern int
87 wim_inode_get_reparse_data(const struct wim_inode * restrict inode,
88                            u8 * restrict rpbuf,
89                            u16 * restrict rpbuflen_ret,
90                            struct wim_lookup_table_entry *lte_override);
91
92 #ifndef __WIN32__
93 ssize_t
94 wim_inode_readlink(const struct wim_inode * restrict inode, char * restrict buf,
95                    size_t buf_len, struct wim_lookup_table_entry *lte);
96
97 extern int
98 wim_inode_set_symlink(struct wim_inode *inode, const char *target,
99                       struct wim_lookup_table *lookup_table);
100 #endif
101
102 #endif /* _WIMLIB_REPARSE_H */