1#include "fastboot.h" 2#include "make_ext4fs.h" 3#include "make_f2fs.h" 4#include "fs.h" 5 6#include <errno.h> 7#include <stdio.h> 8#include <stdlib.h> 9#include <stdarg.h> 10#include <stdbool.h> 11#include <string.h> 12#include <sys/stat.h> 13#include <sys/types.h> 14#include <sparse/sparse.h> 15#include <unistd.h> 16 17#ifdef USE_MINGW 18#include <fcntl.h> 19#else 20#include <sys/mman.h> 21#endif 22 23 24 25static int generate_ext4_image(int fd, long long partSize) 26{ 27 make_ext4fs_sparse_fd(fd, partSize, NULL, NULL); 28 29 return 0; 30} 31 32#ifdef USE_F2FS 33static int generate_f2fs_image(int fd, long long partSize) 34{ 35 return make_f2fs_sparse_fd(fd, partSize, NULL, NULL); 36} 37#endif 38 39static const struct fs_generator { 40 41 char *fs_type; //must match what fastboot reports for partition type 42 int (*generate)(int fd, long long partSize); //returns 0 or error value 43 44} generators[] = { 45 { "ext4", generate_ext4_image}, 46#ifdef USE_F2FS 47 { "f2fs", generate_f2fs_image}, 48#endif 49}; 50 51const struct fs_generator* fs_get_generator(const char *fs_type) 52{ 53 unsigned i; 54 55 for (i = 0; i < sizeof(generators) / sizeof(*generators); i++) 56 if (!strcmp(generators[i].fs_type, fs_type)) 57 return generators + i; 58 59 return NULL; 60} 61 62int fs_generator_generate(const struct fs_generator* gen, int tmpFileNo, long long partSize) 63{ 64 return gen->generate(tmpFileNo, partSize); 65} 66