Usually there will be no extra data and this will save a bit of memory.
struct blob_descriptor;
struct blob_table;
struct wim_dentry;
struct blob_descriptor;
struct blob_table;
struct wim_dentry;
struct wim_security_data;
struct wimfs_fd;
struct wim_security_data;
struct wimfs_fd;
* dentry. This should be a series of tagged items, each of which
* represents a bit of extra metadata, such as the file's object ID.
* See tagged_items.c for more information. */
* dentry. This should be a series of tagged items, each of which
* represents a bit of extra metadata, such as the file's object ID.
* See tagged_items.c for more information. */
- void *i_extra;
-
- /* Size of @i_extra buffer in bytes. If 0, there is no extra data. */
- size_t i_extra_size;
+ struct wim_inode_extra *i_extra;
/* Creation time, last access time, and last write time for this inode,
* in 100-nanosecond intervals since 12:00 a.m UTC January 1, 1601.
/* Creation time, last access time, and last write time for this inode,
* in 100-nanosecond intervals since 12:00 a.m UTC January 1, 1601.
+/* Optional extra data for a WIM inode */
+struct wim_inode_extra {
+ size_t size; /* Size of the extra data in bytes */
+ u8 data[]; /* The extra data */
+};
+
/*
* The available reparse tags are documented at
* http://msdn.microsoft.com/en-us/library/dd541667(v=prot.10).aspx.
/*
* The available reparse tags are documented at
* http://msdn.microsoft.com/en-us/library/dd541667(v=prot.10).aspx.
dentry->d_short_name_nbytes);
len = ALIGN(len, 8);
dentry->d_short_name_nbytes);
len = ALIGN(len, 8);
- len += ALIGN(inode->i_extra_size, 8);
+ if (inode->i_extra)
+ len += ALIGN(inode->i_extra->size, 8);
if (!(inode->i_attributes & FILE_ATTRIBUTE_ENCRYPTED)) {
/*
if (!(inode->i_attributes & FILE_ATTRIBUTE_ENCRYPTED)) {
/*
p++;
if (unlikely(p < end)) {
p++;
if (unlikely(p < end)) {
- inode->i_extra = memdup(p, end - p);
+ inode->i_extra = MALLOC(sizeof(struct wim_inode_extra) +
+ end - p);
if (!inode->i_extra)
return WIMLIB_ERR_NOMEM;
if (!inode->i_extra)
return WIMLIB_ERR_NOMEM;
- inode->i_extra_size = end - p;
+ inode->i_extra->size = end - p;
+ memcpy(inode->i_extra->data, p, end - p);
while ((uintptr_t)p & 7)
*p++ = 0;
while ((uintptr_t)p & 7)
*p++ = 0;
- if (inode->i_extra_size) {
/* Extra tagged items --- not usually present. */
/* Extra tagged items --- not usually present. */
- p = mempcpy(p, inode->i_extra, inode->i_extra_size);
+ p = mempcpy(p, inode->i_extra->data, inode->i_extra->size);
/* Align to 8-byte boundary */
while ((uintptr_t)p & 7)
/* Align to 8-byte boundary */
while ((uintptr_t)p & 7)
u32 desired_tag, u32 min_data_len)
{
size_t minlen_with_hdr = sizeof(struct tagged_item_header) + min_data_len;
u32 desired_tag, u32 min_data_len)
{
size_t minlen_with_hdr = sizeof(struct tagged_item_header) + min_data_len;
- size_t len_remaining = inode->i_extra_size;
- u8 *p = inode->i_extra;
+ size_t len_remaining;
+ u8 *p;
+
+ if (!inode->i_extra)
+ return NULL;
+
+ len_remaining = inode->i_extra->size;
+ p = inode->i_extra->data;
/* Iterate through the tagged items. */
while (len_remaining >= minlen_with_hdr) {
/* Iterate through the tagged items. */
while (len_remaining >= minlen_with_hdr) {
{
size_t itemsize;
size_t newsize;
{
size_t itemsize;
size_t newsize;
+ struct wim_inode_extra *extra;
struct tagged_item_header *hdr;
/* We prepend the item instead of appending it because it's easier. */
itemsize = sizeof(struct tagged_item_header) + ALIGN(len, 8);
struct tagged_item_header *hdr;
/* We prepend the item instead of appending it because it's easier. */
itemsize = sizeof(struct tagged_item_header) + ALIGN(len, 8);
- newsize = itemsize + inode->i_extra_size;
+ newsize = itemsize;
+ if (inode->i_extra)
+ newsize += inode->i_extra->size;
- buf = MALLOC(newsize);
- if (!buf)
+ extra = MALLOC(sizeof(struct wim_inode_extra) + newsize);
+ if (!extra)
-
- if (inode->i_extra_size) {
- memcpy(buf + itemsize, inode->i_extra, inode->i_extra_size);
+ if (inode->i_extra) {
+ memcpy(&extra->data[itemsize], inode->i_extra->data,
+ inode->i_extra->size);
- inode->i_extra = buf;
- inode->i_extra_size = newsize;
+ extra->size = newsize;
+ inode->i_extra = extra;
- hdr = (struct tagged_item_header *)buf;
+ hdr = (struct tagged_item_header *)extra->data;
hdr->tag = cpu_to_le32(tag);
hdr->length = cpu_to_le32(len);
return memset(hdr->data, 0, ALIGN(len, 8));
hdr->tag = cpu_to_le32(tag);
hdr->length = cpu_to_le32(len);
return memset(hdr->data, 0, ALIGN(len, 8));