diff options
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ext4/ext4_common.c | 5 | ||||
-rw-r--r-- | fs/ext4/ext4_journal.c | 2 | ||||
-rw-r--r-- | fs/ext4/ext4_write.c | 20 | ||||
-rw-r--r-- | fs/zfs/dev.c | 2 | ||||
-rw-r--r-- | fs/zfs/zfs.c | 30 |
5 files changed, 46 insertions, 13 deletions
diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c index 365c5147c4b..2ff0dca2495 100644 --- a/fs/ext4/ext4_common.c +++ b/fs/ext4/ext4_common.c @@ -765,11 +765,6 @@ int ext4fs_get_parent_inode_num(const char *dirname, char *dname, int flags) struct ext2_inode *first_inode = NULL; struct ext2_inode temp_inode; - if (*dirname != '/') { - printf("Please supply Absolute path\n"); - return -1; - } - /* TODO: input validation make equivalent to linux */ depth_dirname = zalloc(strlen(dirname) + 1); if (!depth_dirname) diff --git a/fs/ext4/ext4_journal.c b/fs/ext4/ext4_journal.c index 1a340b4764c..e80f797c8dc 100644 --- a/fs/ext4/ext4_journal.c +++ b/fs/ext4/ext4_journal.c @@ -430,7 +430,7 @@ int ext4fs_check_journal_state(int recovery_flag) printf("Recovery required\n"); } else { if (recovery_flag == RECOVER) - printf("File System is consistent\n"); + log_debug("File System is consistent\n"); goto end; } diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c index ea4c5d4157c..d057f6b5a79 100644 --- a/fs/ext4/ext4_write.c +++ b/fs/ext4/ext4_write.c @@ -847,6 +847,7 @@ int ext4fs_write(const char *fname, const char *buffer, { int ret = 0; struct ext2_inode *file_inode = NULL; + struct ext2_inode *existing_file_inode = NULL; unsigned char *inode_buffer = NULL; int parent_inodeno; int inodeno; @@ -900,6 +901,15 @@ int ext4fs_write(const char *fname, const char *buffer, /* check if the filename is already present in root */ existing_file_inodeno = ext4fs_filename_unlink(filename); if (existing_file_inodeno != -1) { + existing_file_inode = (struct ext2_inode *)zalloc(fs->inodesz); + if (!existing_file_inode) + goto fail; + ret = ext4fs_iget(existing_file_inodeno, existing_file_inode); + if (ret) { + free(existing_file_inode); + goto fail; + } + ret = ext4fs_delete_file(existing_file_inodeno); fs->first_pass_bbmap = 0; fs->curr_blkno = 0; @@ -948,9 +958,15 @@ int ext4fs_write(const char *fname, const char *buffer, sizebytes = 0; } } else { - file_inode->mode = cpu_to_le16(S_IFREG | S_IRWXU | S_IRGRP | - S_IROTH | S_IXGRP | S_IXOTH); + if (existing_file_inode) { + file_inode->mode = existing_file_inode->mode; + } else { + file_inode->mode = cpu_to_le16(S_IFREG | S_IRWXU | S_IRGRP | + S_IROTH | S_IXGRP | S_IXOTH); + } } + if (existing_file_inode) + free(existing_file_inode); /* ToDo: Update correct time */ file_inode->mtime = cpu_to_le32(timestamp); file_inode->atime = cpu_to_le32(timestamp); diff --git a/fs/zfs/dev.c b/fs/zfs/dev.c index 251e7d1f74f..fcd9893b3ac 100644 --- a/fs/zfs/dev.c +++ b/fs/zfs/dev.c @@ -26,5 +26,5 @@ void zfs_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info) int zfs_devread(int sector, int byte_offset, int byte_len, char *buf) { return fs_devread(zfs_blk_desc, part_info, sector, byte_offset, - byte_len, buf); + byte_len, buf) ? 0 : 1; } diff --git a/fs/zfs/zfs.c b/fs/zfs/zfs.c index 1fec96cd5ce..bfc11fa6676 100644 --- a/fs/zfs/zfs.c +++ b/fs/zfs/zfs.c @@ -655,7 +655,7 @@ dmu_read(dnode_end_t *dn, uint64_t blkid, void **buf, dn->endian) << SPA_MINBLOCKSHIFT; *buf = malloc(size); - if (*buf) { + if (!*buf) { err = ZFS_ERR_OUT_OF_MEMORY; break; } @@ -1559,6 +1559,10 @@ nvlist_find_value(char *nvlist, char *name, int valtype, char **val, return 0; } +int is_word_aligned_ptr(void *ptr) { + return ((uintptr_t)ptr & (sizeof(void *) - 1)) == 0; +} + int zfs_nvlist_lookup_uint64(char *nvlist, char *name, uint64_t *out) { @@ -1574,6 +1578,20 @@ zfs_nvlist_lookup_uint64(char *nvlist, char *name, uint64_t *out) return ZFS_ERR_BAD_FS; } + /* On arm64, calling be64_to_cpu() on a value stored at a memory address + * that's not 8-byte aligned causes the CPU to reset. Avoid that by copying the + * value somewhere else if needed. + */ + if (!is_word_aligned_ptr((void *)nvpair)) { + uint64_t *alignedptr = malloc(sizeof(uint64_t)); + if (!alignedptr) + return 0; + memcpy(alignedptr, nvpair, sizeof(uint64_t)); + *out = be64_to_cpu(*alignedptr); + free(alignedptr); + return 1; + } + *out = be64_to_cpu(*(uint64_t *) nvpair); return 1; } @@ -1617,6 +1635,11 @@ zfs_nvlist_lookup_nvlist(char *nvlist, char *name) &size, 0); if (!found) return 0; + + /* Allocate 12 bytes in addition to the nvlist size: One uint32 before the + * nvlist to hold the encoding method, and two zero uint32's after the + * nvlist as the NULL terminator. + */ ret = calloc(1, size + 3 * sizeof(uint32_t)); if (!ret) return 0; @@ -2112,7 +2135,7 @@ zfs_read(zfs_file_t file, char *buf, uint64_t len) * Find requested blkid and the offset within that block. */ uint64_t blkid = file->offset + red; - blkid = do_div(blkid, blksz); + uint64_t blkoff = do_div(blkid, blksz); free(data->file_buf); data->file_buf = 0; @@ -2127,8 +2150,7 @@ zfs_read(zfs_file_t file, char *buf, uint64_t len) movesize = min(length, data->file_end - (int)file->offset - red); - memmove(buf, data->file_buf + file->offset + red - - data->file_start, movesize); + memmove(buf, data->file_buf + blkoff, movesize); buf += movesize; length -= movesize; red += movesize; |