diff options
author | Elliott Hughes <enh@google.com> | 2015-06-23 20:27:58 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-06-23 20:56:01 -0700 |
commit | b3748de33f651597259f52e4645571a1da2e32dd (patch) | |
tree | 96ecf31d36bf62db8062b16fbf7b8e3bfced7e6d /fastboot/fs.cpp | |
parent | 21ba889aded6167859c88f51dec54838b8e407a1 (diff) | |
download | core-b3748de33f651597259f52e4645571a1da2e32dd.tar.gz core-b3748de33f651597259f52e4645571a1da2e32dd.tar.bz2 core-b3748de33f651597259f52e4645571a1da2e32dd.zip |
Move fastboot to C++.
Minimal conversion.
Change-Id: I32cbf125be481a8757720d10fa303c38a7fd5e38
Diffstat (limited to 'fastboot/fs.cpp')
-rw-r--r-- | fastboot/fs.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/fastboot/fs.cpp b/fastboot/fs.cpp new file mode 100644 index 000000000..d8f9e165d --- /dev/null +++ b/fastboot/fs.cpp @@ -0,0 +1,65 @@ +#include "fastboot.h" +#include "make_ext4fs.h" +#include "make_f2fs.h" +#include "fs.h" + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <stdbool.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sparse/sparse.h> +#include <unistd.h> + +#ifdef USE_MINGW +#include <fcntl.h> +#else +#include <sys/mman.h> +#endif + + + +static int generate_ext4_image(int fd, long long partSize) +{ + make_ext4fs_sparse_fd(fd, partSize, NULL, NULL); + + return 0; +} + +#ifdef USE_F2FS +static int generate_f2fs_image(int fd, long long partSize) +{ + return make_f2fs_sparse_fd(fd, partSize, NULL, NULL); +} +#endif + +static const struct fs_generator { + + const char* fs_type; //must match what fastboot reports for partition type + int (*generate)(int fd, long long partSize); //returns 0 or error value + +} generators[] = { + { "ext4", generate_ext4_image}, +#ifdef USE_F2FS + { "f2fs", generate_f2fs_image}, +#endif +}; + +const struct fs_generator* fs_get_generator(const char *fs_type) +{ + unsigned i; + + for (i = 0; i < sizeof(generators) / sizeof(*generators); i++) + if (!strcmp(generators[i].fs_type, fs_type)) + return generators + i; + + return NULL; +} + +int fs_generator_generate(const struct fs_generator* gen, int tmpFileNo, long long partSize) +{ + return gen->generate(tmpFileNo, partSize); +} |