diff options
-rw-r--r-- | f2fs_utils/f2fs_dlutils.c | 4 | ||||
-rw-r--r-- | f2fs_utils/f2fs_ioutils.c | 62 | ||||
-rw-r--r-- | f2fs_utils/f2fs_utils.c | 13 |
3 files changed, 59 insertions, 20 deletions
diff --git a/f2fs_utils/f2fs_dlutils.c b/f2fs_utils/f2fs_dlutils.c index 2ba3f7cc..4b5e13ea 100644 --- a/f2fs_utils/f2fs_dlutils.c +++ b/f2fs_utils/f2fs_dlutils.c @@ -39,7 +39,6 @@ int (*f2fs_format_device_dl)(void); void (*f2fs_init_configuration_dl)(void); -struct f2fs_configuration *c_dl; int f2fs_format_device(void) { assert(f2fs_format_device_dl); @@ -59,8 +58,7 @@ int dlopenf2fs() { } f2fs_format_device_dl = dlsym(f2fs_lib, "f2fs_format_device"); f2fs_init_configuration_dl = dlsym(f2fs_lib, "f2fs_init_configuration"); - c_dl = dlsym(f2fs_lib, "c"); - if (!f2fs_format_device_dl || !f2fs_init_configuration_dl || !c_dl) { + if (!f2fs_format_device_dl || !f2fs_init_configuration_dl) { return -1; } return 0; diff --git a/f2fs_utils/f2fs_ioutils.c b/f2fs_utils/f2fs_ioutils.c index d3bc727d..c9275ff2 100644 --- a/f2fs_utils/f2fs_ioutils.c +++ b/f2fs_utils/f2fs_ioutils.c @@ -83,7 +83,7 @@ struct selabel_handle; #endif -extern struct f2fs_configuration *c_dl; +struct f2fs_configuration c; struct sparse_file *f2fs_sparse_file; struct buf_item { @@ -94,11 +94,29 @@ struct buf_item { struct buf_item *buf_list; +static int __get_device_fd(__u64 *offset) +{ + __u64 blk_addr = *offset >> F2FS_BLKSIZE_BITS; + int i; + + for (i = 0; i < c.ndevs; i++) { + if (c.devices[i].start_blkaddr <= blk_addr && + c.devices[i].end_blkaddr >= blk_addr) { + *offset -= + c.devices[i].start_blkaddr << F2FS_BLKSIZE_BITS; + return c.devices[i].fd; + } + } + return -1; +} + static int dev_write_fd(void *buf, __u64 offset, size_t len) { - if (lseek64(c_dl->devices[0].fd, (off64_t)offset, SEEK_SET) < 0) + int fd = __get_device_fd(&offset); + + if (lseek64(fd, (off64_t)offset, SEEK_SET) < 0) return -1; - ssize_t written = write(c_dl->devices[0].fd, buf, len); + ssize_t written = write(fd, buf, len); if (written == -1) return -1; if ((size_t)written != len) @@ -138,11 +156,11 @@ static int dev_write_sparse(void *buf, __u64 byte_offset, size_t byte_len) return 0; } -void f2fs_finalize_device() +void f2fs_finalize_device(void) { } -int f2fs_trim_device() +int f2fs_trim_devices(void) { return 0; } @@ -160,24 +178,39 @@ int dev_read(void *buf, __u64 offset, size_t len) return 0; } +int dev_readahead(__u64 offset, size_t len) +{ + return 0; +} + int dev_write(void *buf, __u64 offset, size_t len) { - if (c_dl->devices[0].fd >= 0) { + int fd = __get_device_fd(&offset); + + if (fd >= 0) { return dev_write_fd(buf, offset, len); } else { return dev_write_sparse(buf, offset, len); } } -int dev_write_block(void *buf, __u64 offset) +int dev_write_block(void *buf, __u64 blk_addr) +{ + assert(false); // Must not be invoked. + return 0; +} + +int dev_write_dump(void *buf, __u64 offset, size_t len) { - return dev_write(buf, offset << F2FS_BLKSIZE_BITS, F2FS_BLKSIZE); + assert(false); // Must not be invoked. + return 0; } int dev_fill(void *buf, __u64 offset, size_t len) { + int fd = __get_device_fd(&offset); int ret; - if (c_dl->devices[0].fd >= 0) { + if (fd >= 0) { return dev_write_fd(buf, offset, len); } // sparse file fills with zero by default. @@ -185,6 +218,12 @@ int dev_fill(void *buf, __u64 offset, size_t len) return 0; } +int dev_fill_block(void *buf, __u64 blk_addr) +{ + assert(false); // Must not be invoked. + return 0; +} + int dev_read_block(void *buf, __u64 blk_addr) { assert(false); // Must not be invoked. @@ -197,3 +236,8 @@ int dev_read_blocks(void *buf, __u64 addr, __u32 nr_blks) return 0; } +int dev_reada_block(__u64 blk_addr) +{ + assert(false); // Must not be invoked. + return 0; +} diff --git a/f2fs_utils/f2fs_utils.c b/f2fs_utils/f2fs_utils.c index 52236801..0aa2f7a2 100644 --- a/f2fs_utils/f2fs_utils.c +++ b/f2fs_utils/f2fs_utils.c @@ -42,11 +42,12 @@ struct selabel_handle; extern void flush_sparse_buffs(); -extern struct f2fs_configuration *c_dl; +struct f2fs_configuration c; struct sparse_file *f2fs_sparse_file; extern int dlopenf2fs(); static void reset_f2fs_info() { + memset(&c, 0, sizeof(c)); if (f2fs_sparse_file) { sparse_file_destroy(f2fs_sparse_file); f2fs_sparse_file = NULL; @@ -62,13 +63,9 @@ int make_f2fs_sparse_fd(int fd, long long len, reset_f2fs_info(); f2fs_init_configuration(); len &= ~((__u64)(F2FS_BLKSIZE - 1)); - c_dl->ndevs = 1; - c_dl->devices[0].total_sectors = len / c_dl->devices[0].sector_size; - c_dl->sector_size = c_dl->devices[0].sector_size; - c_dl->sectors_per_blk = F2FS_BLKSIZE / c_dl->sector_size; - c_dl->total_sectors = c_dl->devices[0].total_sectors; - c_dl->start_sector = 0; - c_dl->trim = 0; + c.sector_size = DEFAULT_SECTOR_SIZE; + c.total_sectors = len / c.sector_size; + c.start_sector = 0; f2fs_sparse_file = sparse_file_new(F2FS_BLKSIZE, len); f2fs_format_device(); sparse_file_write(f2fs_sparse_file, fd, /*gzip*/0, /*sparse*/1, /*crc*/0); |