va_end(va);
}
-static const char *path_basename(const char *path)
-{
- const char *p = path;
- while (*p)
- p++;
- p--;
-
- /* Trailing slashes. */
- while ((p != path - 1) && *p == '/')
- p--;
-
- while ((p != path - 1) && *p != '/')
- p--;
-
- return p + 1;
-}
-
-
static int verify_image_exists(int image)
{
if (image == WIM_NO_IMAGE) {
*/
void free_dentry(struct dentry *dentry)
{
- wimlib_assert(dentry);
- struct inode *inode;
-
+ wimlib_assert(dentry != NULL);
FREE(dentry->file_name);
FREE(dentry->file_name_utf8);
FREE(dentry->short_name);
void put_dentry(struct dentry *dentry)
{
- wimlib_assert(dentry);
- wimlib_assert(dentry->refcnt);
+ wimlib_assert(dentry != NULL);
+ wimlib_assert(dentry->refcnt != 0);
if (--dentry->refcnt == 0)
free_dentry(dentry);
WARNING("The following lookup table entry "
"has a reference count of %u, but",
lte->refcnt);
- WARNING("We found %zu references to it",
+ WARNING("We found %u references to it",
lte->real_refcnt);
WARNING("(One dentry referencing it is at `%s')",
first_dentry->full_path_utf8);
/* Run some miscellaneous verifications on a WIM dentry */
int verify_dentry(struct dentry *dentry, void *wim)
{
- const WIMStruct *w = wim;
- const struct inode *inode = dentry->d_inode;
int ret;
if (!dentry->d_inode->verified) {
- ret = verify_inode(dentry->d_inode, w);
+ ret = verify_inode(dentry->d_inode, wim);
if (ret != 0)
return ret;
}
"short_name_len = %hu, file_name_len = %hu)",
calculated_size, dentry->length,
short_name_len, file_name_len);
- return WIMLIB_ERR_INVALID_DENTRY;
+ ret = WIMLIB_ERR_INVALID_DENTRY;
+ goto out_free_inode;
}
/* Read the filename if present. Note: if the filename is empty, there
if (!file_name) {
ERROR("Failed to allocate %hu bytes for dentry file name",
file_name_len);
- return WIMLIB_ERR_NOMEM;
+ ret = WIMLIB_ERR_NOMEM;
+ goto out_free_inode;
}
p = get_bytes(p, file_name_len, file_name);
calculated_size, dentry->length);
}
u64 lengths_to_try[3] = {calculated_size,
- dentry->length + 7 & ~7,
+ (dentry->length + 7) & ~7,
dentry->length};
ret = WIMLIB_ERR_INVALID_DENTRY;
for (size_t i = 0; i < ARRAY_LEN(lengths_to_try); i++) {
# endif
#endif
-static inline void array_cpu_to_le32(uint32_t *p, uint64_t n)
+static inline void array_cpu_to_le32(uint32_t *p, size_t n)
{
- while (n--)
- *p++ = cpu_to_le32(*p);
+ for (size_t i = 0; i < n; i++)
+ p[i] = cpu_to_le32(p[i]);
}
-static inline void array_le32_to_cpu(uint32_t *p, uint64_t n)
+static inline void array_le32_to_cpu(uint32_t *p, size_t n)
{
- while (n--)
- *p++ = le32_to_cpu(*p);
+ for (size_t i = 0; i < n; i++)
+ p[i] = le32_to_cpu(p[i]);
}
-static inline void array_cpu_to_le64(uint64_t *p, uint64_t n)
+static inline void array_cpu_to_le64(uint64_t *p, size_t n)
{
- while (n--)
- *p++ = cpu_to_le64(*p);
+ for (size_t i = 0; i < n; i++)
+ p[i] = cpu_to_le64(p[i]);
}
-static inline void array_le64_to_cpu(uint64_t *p, uint64_t n)
+static inline void array_le64_to_cpu(uint64_t *p, size_t n)
{
- while (n--)
- *p++ = le64_to_cpu(*p);
+ for (size_t i = 0; i < n; i++)
+ p[i] = le64_to_cpu(p[i]);
}
+
#endif /* _WIMLIB_ENDIANNESS_H */
static int
fix_nominal_inode(struct inode *inode, struct hlist_head *inode_list)
{
- struct dentry *dentry, *ref_dentry;
+ struct dentry *dentry;
struct hlist_node *cur, *tmp;
int ret;
size_t num_true_inodes;
if (list_empty(&dentries_with_data_streams)) {
#ifdef ENABLE_DEBUG
if (inode->link_count > 1) {
- DEBUG("Found link group of size %zu without "
+ DEBUG("Found link group of size %u without "
"any data streams:", inode->link_count);
print_inode_dentries(inode);
DEBUG("We are going to interpret it as true "
WIMLIBAPI int wimlib_join(const char **swm_names, unsigned num_swms,
const char *output_path, int flags)
{
- int i;
int ret;
- int part_idx;
int write_flags = 0;
WIMStruct *joined_wim = NULL;
WIMStruct *swms[num_swms];
- int ctype;
- u8 *guid;
-
if (num_swms < 1)
return WIMLIB_ERR_INVALID_PARAM;
ZERO_ARRAY(swms);
- for (i = 0; i < num_swms; i++) {
+ for (unsigned i = 0; i < num_swms; i++) {
ret = wimlib_open_wim(swm_names[i],
flags | WIMLIB_OPEN_FLAG_SPLIT_OK, &swms[i]);
if (ret != 0)
out:
/* out_fp is the same in all the swms and joined_wim. And it was
* already closed in the call to finish_write(). */
- for (i = 0; i < num_swms; i++) {
+ for (unsigned i = 0; i < num_swms; i++) {
swms[i]->out_fp = NULL;
wimlib_free(swms[i]);
}
}
break;
#endif
+ default:
+ break;
}
return new;
out_free:
if (!imd) {
ERROR("Failed to allocate memory for new image metadata array");
- return WIMLIB_ERR_NOMEM;
+ goto err;
}
memcpy(imd, w->image_metadata,
metadata_lte = new_lookup_table_entry();
if (!metadata_lte)
- goto out_free_imd;
+ goto err_free_imd;
metadata_lte->resource_entry.flags = WIM_RESHDR_FLAG_METADATA;
random_hash(metadata_lte->hash);
ret = select_wim_image(w, w->hdr.image_count);
wimlib_assert(ret == 0);
return ret;
-out_free_metadata_lte:
- FREE(metadata_lte);
-out_free_imd:
+err_free_imd:
FREE(imd);
+err:
return WIMLIB_ERR_NOMEM;
}
* */
wimlib_assert(old_lte->refcnt > inode->link_count);
DEBUG("Splitting lookup table entry "
- "(inode->link_count = %zu, old_lte->refcnt = %u)",
+ "(inode->link_count = %u, old_lte->refcnt = %u)",
inode->link_count, old_lte->refcnt);
}
j++;
}
}
- DEBUG("%zu fd's were already opened to the file we extracted",
+ DEBUG("%hu fd's were already opened to the file we extracted",
new_lte->num_opened_fds);
if (old_lte) {
old_lte->num_opened_fds -= new_lte->num_opened_fds;
j++;
}
}
-out_free_new_lte:
free_lookup_table_entry(new_lte);
out_delete_staging_file:
unlink(staging_file_name);
status = 0;
if (ctx->mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
if (commit) {
- if (chdir(ctx->working_directory)) {
+ ret = chdir(ctx->working_directory);
+ if (ret == 0) {
+ status = rebuild_wim(ctx, (check_integrity != 0));
+ } else {
ERROR_WITH_ERRNO("chdir()");
status = WIMLIB_ERR_NOTDIR;
- goto out;
}
- status = rebuild_wim(ctx, (check_integrity != 0));
}
ret = delete_staging_dir(ctx);
if (ret != 0) {
} else {
DEBUG("Read-only mount");
}
-out:
DEBUG("Sending status %hhd", status);
ret = mq_send(ctx->daemon_to_unmount_mq, &status, 1, 1);
if (ret == -1)
ERROR_WITH_ERRNO("Failed to send status to unmount process");
-out_free_mailbox:
FREE(mailbox);
out_close_message_queues:
close_message_queues(ctx);
#ifdef ENABLE_XATTR
static int wimfs_listxattr(const char *path, char *list, size_t size)
{
- int ret;
size_t needed_size;
- unsigned i;
struct inode *inode;
struct wimfs_context *ctx = wimfs_get_context();
if (size == 0) {
needed_size = 0;
- for (i = 0; i < inode->num_ads; i++)
+ for (u16 i = 0; i < inode->num_ads; i++)
needed_size += inode->ads_entries[i].stream_name_utf8_len + 6;
return needed_size;
} else {
char *p = list;
- for (i = 0; i < inode->num_ads; i++) {
+ for (u16 i = 0; i < inode->num_ads; i++) {
needed_size = inode->ads_entries[i].stream_name_utf8_len + 6;
if (needed_size > size)
return -ERANGE;
{
struct dentry *dentry;
struct lookup_table_entry *lte;
- struct inode *inode;
int ret;
u16 stream_idx;
- unsigned i;
struct wimfs_context *ctx = wimfs_get_context();
ret = lookup_resource(ctx->w, path, get_lookup_flags(ctx),
sd = wim_const_security_data(w);
wimlib_assert(dentry->d_inode->security_id < sd->num_entries);
- descriptor = sd->descriptors[dentry->d_inode->security_id];
+ descriptor = (const char *)sd->descriptors[dentry->d_inode->security_id];
DEBUG("Applying security descriptor %d to `%s'",
dentry->d_inode->security_id, dentry->full_path_utf8);
if (inode->attributes & FILE_ATTRIBUTE_DIRECTORY) {
type = S_IFDIR;
} else {
- struct dentry *other;
-
/* Apply hard-linked directory in same directory with DOS name
* (if there is one) before this dentry */
if (dentry->short_name_len == 0) {
CASE_SENSITIVE, 0, NULL, 0, actx))
{
char *stream_name_utf8;
- size_t stream_name_utf16_len;
u32 reparse_tag;
u64 data_size = ntfs_get_attribute_value_length(actx->attr);
u64 name_length = actx->attr->name_length;
{
u32 attributes;
int mrec_flags;
- u32 sd_size = 0;
int ret;
char dos_name_utf8[64];
struct dentry *root;
wimlib_assert(lte->ntfs_loc != NULL);
wimlib_assert(lte->attr != NULL);
{
- u64 adjusted_offset;
if (lte->ntfs_loc->is_reparse_point)
- adjusted_offset = offset + 8;
- else
- adjusted_offset = offset;
+ offset += 8;
if (ntfs_attr_pread(lte->attr, offset, size, buf) != size) {
ERROR_WITH_ERRNO("Error reading NTFS attribute "
"at `%s'",
if (ret != 0)
goto out_free_buf;
- dentry_offset = imd->security_data->total_length + 7 & ~7;
+ dentry_offset = (imd->security_data->total_length + 7) & ~7;
if (dentry_offset == 0) {
ERROR("Integer overflow while reading metadata resource");
* entries anyway; however this ensures that that the security descriptors pass
* the validation in libntfs-3g.
*/
-static void empty_sacl_fixup(char *descr, u64 *size_p)
+static void empty_sacl_fixup(u8 *descr, u64 *size_p)
{
if (*size_p >= sizeof(SecurityDescriptor)) {
SecurityDescriptor *sd = (SecurityDescriptor*)descr;
empty_sacl_fixup(sd->descriptors[i], &sd->sizes[i]);
}
wimlib_assert(total_len <= 0xffffffff);
- if ((total_len + 7 & ~7) != ((sd->total_length + 7) & ~7)) {
+ if (((total_len + 7) & ~7) != ((sd->total_length + 7) & ~7)) {
ERROR("Expected security data total length = %u, but "
- "calculated %u", sd->total_length, total_len);
+ "calculated %u", sd->total_length, (unsigned)total_len);
goto out_invalid_sd;
}
sd->total_length = total_len;
void xml_update_image_info(WIMStruct *w, int image)
{
struct image_info *image_info;
- struct dentry *root;
char *flags_save;
DEBUG("Updating the image info for image %d", image);
* */
void print_image_info(const struct wim_info *wim_info, int image)
{
- uint i;
const struct image_info *image_info;
const char *desc;
- int start;
- int end;
time_t time;
char *p;