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