diff options
author | JP Abgrall <jpa@google.com> | 2014-02-05 19:54:12 -0800 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk.kim@samsung.com> | 2014-04-07 12:14:10 +0900 |
commit | 15ea79b3ae7f0474ade43ba8b6eb328806e01e15 (patch) | |
tree | e6e56a4175fc4b2be445c956e0c8509d278e2e5a /lib | |
parent | af3c6803bd3db784531ff5675c539eef4bae1a15 (diff) | |
download | android_external_f2fs-tools-15ea79b3ae7f0474ade43ba8b6eb328806e01e15.tar.gz android_external_f2fs-tools-15ea79b3ae7f0474ade43ba8b6eb328806e01e15.tar.bz2 android_external_f2fs-tools-15ea79b3ae7f0474ade43ba8b6eb328806e01e15.zip |
further split up lib2fs so that it does not do any IO directly.
This will allow turning mkfs into a libarary more easily.
Signed-off-by: JP Abgrall <jpa@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/libf2fs.c | 32 | ||||
-rw-r--r-- | lib/libf2fs_io.c | 60 |
3 files changed, 61 insertions, 33 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 6498df9..a6b304c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -2,6 +2,6 @@ lib_LTLIBRARIES = libf2fs.la -libf2fs_la_SOURCES = libf2fs.c +libf2fs_la_SOURCES = libf2fs.c libf2fs_io.c libf2fs_la_CFLAGS = -Wall libf2fs_la_CPPFLAGS = -I$(top_srcdir)/include diff --git a/lib/libf2fs.c b/lib/libf2fs.c index 3984697..5fd17fb 100644 --- a/lib/libf2fs.c +++ b/lib/libf2fs.c @@ -26,8 +26,6 @@ #include <f2fs_fs.h> -struct f2fs_configuration config; - void ASCIIToUNICODE(u_int16_t *out_buf, u_int8_t *in_buf) { u_int8_t *pchTempPtr = in_buf; @@ -491,33 +489,3 @@ int f2fs_get_device_info(struct f2fs_configuration *c) return 0; } -/* - * IO interfaces - */ -int dev_read(void *buf, __u64 offset, size_t len) -{ - if (lseek64(config.fd, (off64_t)offset, SEEK_SET) < 0) - return -1; - if (read(config.fd, buf, len) < 0) - return -1; - return 0; -} - -int dev_write(void *buf, __u64 offset, size_t len) -{ - if (lseek64(config.fd, (off64_t)offset, SEEK_SET) < 0) - return -1; - if (write(config.fd, buf, len) < 0) - return -1; - return 0; -} - -int dev_read_block(void *buf, __u64 blk_addr) -{ - return dev_read(buf, blk_addr * F2FS_BLKSIZE, F2FS_BLKSIZE); -} - -int dev_read_blocks(void *buf, __u64 addr, __u32 nr_blks) -{ - return dev_read(buf, addr * F2FS_BLKSIZE, nr_blks * F2FS_BLKSIZE); -} diff --git a/lib/libf2fs_io.c b/lib/libf2fs_io.c new file mode 100644 index 0000000..e48dd1a --- /dev/null +++ b/lib/libf2fs_io.c @@ -0,0 +1,60 @@ +/** + * libf2fs.c + * + * Copyright (c) 2013 Samsung Electronics Co., Ltd. + * http://www.samsung.com/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#define _LARGEFILE64_SOURCE + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <fcntl.h> +#include <mntent.h> +#include <time.h> +#include <sys/stat.h> +#include <sys/mount.h> +#include <sys/ioctl.h> +#include <linux/hdreg.h> +#include <linux/fs.h> + +#include <f2fs_fs.h> + +struct f2fs_configuration config; + +/* + * IO interfaces + */ +int dev_read(void *buf, __u64 offset, size_t len) +{ + if (lseek64(config.fd, (off64_t)offset, SEEK_SET) < 0) + return -1; + if (read(config.fd, buf, len) < 0) + return -1; + return 0; +} + +int dev_write(void *buf, __u64 offset, size_t len) +{ + if (lseek64(config.fd, (off64_t)offset, SEEK_SET) < 0) + return -1; + if (write(config.fd, buf, len) < 0) + return -1; + return 0; +} + +int dev_read_block(void *buf, __u64 blk_addr) +{ + return dev_read(buf, blk_addr * F2FS_BLKSIZE, F2FS_BLKSIZE); +} + +int dev_read_blocks(void *buf, __u64 addr, __u32 nr_blks) +{ + return dev_read(buf, addr * F2FS_BLKSIZE, nr_blks * F2FS_BLKSIZE); +} |