*/
/*
- * Copyright (C) 2015-2017 Eric Biggers
+ * Copyright 2015-2023 Eric Biggers
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
static inline bool
is_valid_filename_char(utf16lechar c)
{
-#ifdef __WIN32__
+#ifdef _WIN32
return is_valid_windows_filename_char(c);
#else
return c != cpu_to_le16('\0') && c != cpu_to_le16('/');
/* Generate the characters in the name. */
for (int i = 0; i < len; i++) {
do {
- name[i] = rand16();
+ name[i] = cpu_to_le16(rand16());
} while (!is_valid_filename_char(name[i]));
}
static bool
am_root(void)
{
-#ifdef __WIN32__
+#ifdef _WIN32
return false;
#else
return (getuid() == 0);
static u32
generate_uid(void)
{
-#ifdef __WIN32__
+#ifdef _WIN32
return 0;
#else
if (am_root())
static u32
generate_gid(void)
{
-#ifdef __WIN32__
+#ifdef _WIN32
return 0;
#else
if (am_root())
#endif
}
-#ifdef __WIN32__
+#ifdef _WIN32
# ifndef S_IFLNK
# define S_IFLNK 0120000
# endif
set_random_xattrs(struct wim_inode *inode)
{
int num_xattrs = 1 + rand32() % 16;
- char entries[8192] _aligned_attribute(4);
- struct wimlib_xattr_entry *entry = (void *)entries;
+ char entries[8192];
+ struct wim_xattr_entry *entry = (void *)entries;
size_t entries_size;
struct wimlib_unix_data unix_data;
+#ifdef _WIN32
+ const char *prefix = "";
+#else
const char *prefix = "user.";
+#endif
static const char capability_name[] = "security.capability";
bool generated_capability_xattr = false;
int value_len = rand32() % 64;
u8 *p;
- entry->reserved = 0;
- entry->value_len = cpu_to_le32(value_len);
+ #ifdef _WIN32
+ if (value_len == 0)
+ value_len++;
+ #endif
+
+ entry->value_len = cpu_to_le16(value_len);
+ entry->flags = 0;
if (rand32() % 16 == 0 && am_root() &&
!generated_capability_xattr) {
int name_len = sizeof(capability_name) - 1;
- entry->name_len = cpu_to_le16(name_len);
- p = mempcpy(entry->name, capability_name, name_len);
+ entry->name_len = name_len;
+ p = mempcpy(entry->name, capability_name, name_len + 1);
generated_capability_xattr = true;
} else {
int name_len = 1 + rand32() % 64;
- entry->name_len = cpu_to_le16(strlen(prefix) + name_len);
+ entry->name_len = strlen(prefix) + name_len;
p = mempcpy(entry->name, prefix, strlen(prefix));
- *p++ = 'a' + i;
+ *p++ = 'A' + i;
for (int j = 1; j < name_len; j++) {
do {
+ #ifdef _WIN32
+ *p = 'A' + rand8() % 26;
+ #else
*p = rand8();
+ #endif
} while (*p == '\0');
p++;
}
+ *p++ = '\0';
}
for (int j = 0; j < value_len; j++)
*p++ = rand8();
- while ((uintptr_t)p % 4)
- *p++ = 0;
-
entry = (void *)p;
}
entries_size = (char *)entry - entries;
- wimlib_assert(entries_size > 0 && entries_size % 4 == 0 &&
- entries_size <= sizeof(entries));
+ wimlib_assert(entries_size > 0 && entries_size <= sizeof(entries));
- if (!inode_set_linux_xattrs(inode, entries, entries_size))
+ if (!inode_set_xattrs(inode, entries, entries_size))
return WIMLIB_ERR_NOMEM;
return 0;
}
}
-static int
-add_stream(struct wim_inode *inode, struct generation_context *ctx,
- int stream_type, const utf16lechar *stream_name,
- void *buffer, size_t size)
-{
- struct blob_descriptor *blob = NULL;
- struct wim_inode_stream *strm;
-
- if (size) {
- blob = new_blob_descriptor();
- if (!blob)
- goto err_nomem;
- blob->attached_buffer = buffer;
- blob->blob_location = BLOB_IN_ATTACHED_BUFFER;
- blob->size = size;
- }
-
- strm = inode_add_stream(inode, stream_type, stream_name, blob);
- if (unlikely(!strm))
- goto err_nomem;
-
- prepare_unhashed_blob(blob, inode, strm->stream_id,
- ctx->params->unhashed_blobs);
- return 0;
-
-err_nomem:
- free_blob_descriptor(blob);
- return WIMLIB_ERR_NOMEM;
-}
-
static noinline_for_stack int
set_random_reparse_point(struct wim_inode *inode, struct generation_context *ctx)
{
{
void *buffer = NULL;
size_t size;
+ int ret;
size = select_stream_size(ctx);
if (size) {
generate_data(buffer, size, ctx);
}
- return add_stream(inode, ctx, STREAM_TYPE_DATA, stream_name,
- buffer, size);
+ ret = 0;
+ if (!inode_add_stream_with_data(inode, STREAM_TYPE_DATA, stream_name,
+ buffer, size, ctx->params->blob_table))
+ ret = WIMLIB_ERR_NOMEM;
+ FREE(buffer);
+ return ret;
}
static int
ret = add_random_data_stream(inode, ctx, stream_name);
if (ret)
return ret;
- stream_name[0] += cpu_to_le16(1);
+ stream_name[0] =
+ cpu_to_le16(le16_to_cpu(stream_name[0]) + 1);
}
}
* within the same directory. */
hash = 0;
for (const utf16lechar *p = name; *p; p++)
- hash = (hash * 31) + *p;
+ hash = (hash * 31) + le16_to_cpu(*p);
FREE(child->d_short_name);
child->d_short_name = memdup(name, (name_len + 1) * 2);
child->d_short_name_nbytes = name_len * 2;
static int
cmp_xattr_names(const void *p1, const void *p2)
{
- const struct wimlib_xattr_entry *entry1 = *(const struct wimlib_xattr_entry **)p1;
- const struct wimlib_xattr_entry *entry2 = *(const struct wimlib_xattr_entry **)p2;
- u16 name_len1 = le16_to_cpu(entry1->name_len);
- u16 name_len2 = le16_to_cpu(entry2->name_len);
+ const struct wim_xattr_entry *entry1 = *(const struct wim_xattr_entry **)p1;
+ const struct wim_xattr_entry *entry2 = *(const struct wim_xattr_entry **)p2;
int res;
- res = cmp_u32(name_len1, name_len2);
+ res = entry1->name_len - entry2->name_len;
if (res)
return res;
- return memcmp(entry1->name, entry2->name, name_len1);
+ return memcmp(entry1->name, entry2->name, entry1->name_len);
}
/* Validate and sort by name a list of extended attributes */
static int
parse_xattrs(const void *xattrs, u32 len,
- const struct wimlib_xattr_entry *entries[],
+ const struct wim_xattr_entry *entries[],
u32 *num_entries_p)
{
u32 limit = *num_entries_p;
u32 num_entries = 0;
- const struct wimlib_xattr_entry *entry = xattrs;
+ const struct wim_xattr_entry *entry = xattrs;
while ((void *)entry < xattrs + len) {
if (!valid_xattr_entry(entry, xattrs + len - (void *)entry)) {
}
static int
-cmp_linux_xattrs(const struct wim_inode *inode1,
- const struct wim_inode *inode2, int cmp_flags)
+cmp_xattrs(const struct wim_inode *inode1, const struct wim_inode *inode2,
+ int cmp_flags)
{
const void *xattrs1, *xattrs2;
u32 len1, len2;
- xattrs1 = inode_get_linux_xattrs(inode1, &len1);
- xattrs2 = inode_get_linux_xattrs(inode2, &len2);
+ xattrs1 = inode_get_xattrs(inode1, &len1);
+ xattrs2 = inode_get_xattrs(inode2, &len2);
if (!xattrs1 && !xattrs2) {
return 0;
} else if (xattrs1 && !xattrs2) {
- if (cmp_flags & (WIMLIB_CMP_FLAG_NTFS_3G_MODE |
- WIMLIB_CMP_FLAG_WINDOWS_MODE))
+ if (cmp_flags & WIMLIB_CMP_FLAG_NTFS_3G_MODE)
return 0;
ERROR("%"TS" unexpectedly lost its xattrs",
inode_any_full_path(inode1));
return WIMLIB_ERR_IMAGES_ARE_DIFFERENT;
} else {
const int max_entries = 64;
- const struct wimlib_xattr_entry *entries1[max_entries];
- const struct wimlib_xattr_entry *entries2[max_entries];
+ const struct wim_xattr_entry *entries1[max_entries];
+ const struct wim_xattr_entry *entries2[max_entries];
u32 xattr_count1 = max_entries;
u32 xattr_count2 = max_entries;
int ret;
xattr_count1, xattr_count2);
}
for (u32 i = 0; i < xattr_count1; i++) {
- const struct wimlib_xattr_entry *entry1 = entries1[i];
- const struct wimlib_xattr_entry *entry2 = entries2[i];
+ const struct wim_xattr_entry *entry1 = entries1[i];
+ const struct wim_xattr_entry *entry2 = entries2[i];
- if (entry1->name_len != entry2->name_len ||
- entry1->value_len != entry2->value_len ||
- entry1->reserved != entry2->reserved ||
+ if (entry1->value_len != entry2->value_len ||
+ entry1->name_len != entry2->name_len ||
+ entry1->flags != entry2->flags ||
memcmp(entry1->name, entry2->name,
- le16_to_cpu(entry1->name_len)) ||
- memcmp(entry1->name + le16_to_cpu(entry1->name_len),
- entry2->name + le16_to_cpu(entry1->name_len),
- le32_to_cpu(entry1->value_len)))
+ entry1->name_len) ||
+ memcmp(entry1->name + entry1->name_len + 1,
+ entry2->name + entry2->name_len + 1,
+ le16_to_cpu(entry1->value_len)))
{
ERROR("xattr %.*s of %"TS" differs",
- le16_to_cpu(entry1->name_len),
- entry1->name, inode_any_full_path(inode1));
+ entry1->name_len, entry1->name,
+ inode_any_full_path(inode1));
return WIMLIB_ERR_IMAGES_ARE_DIFFERENT;
}
}
if (ret)
return ret;
- /* Compare Linux-style xattrs */
- ret = cmp_linux_xattrs(inode1, inode2, cmp_flags);
+ /* Compare extended attributes */
+ ret = cmp_xattrs(inode1, inode2, cmp_flags);
if (ret)
return ret;