OSDN Git Service

f2fs: adjust change for f2fs-tools v1.8.0
authorJaegeuk Kim <jaegeuk@google.com>
Mon, 5 Jun 2017 16:26:40 +0000 (09:26 -0700)
committerJaegeuk Kim <jaegeuk@google.com>
Mon, 5 Jun 2017 21:10:52 +0000 (14:10 -0700)
Change-Id: I41364cbb0781fa5e30567ce7713ef3a2548fa261
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
f2fs_utils/f2fs_dlutils.c
f2fs_utils/f2fs_ioutils.c
f2fs_utils/f2fs_utils.c

index 2ba3f7c..4b5e13e 100644 (file)
@@ -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;
index d3bc727..c9275ff 100644 (file)
@@ -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;
+}
index 5223680..0aa2f7a 100644 (file)
@@ -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);