Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 1 | #include "fastboot.h" |
| 2 | #include "make_ext4fs.h" |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 3 | #include "make_f2fs.h" |
Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 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 | |
| 25 | static 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 | |
JP Abgrall | 6bd72be | 2014-06-17 23:43:18 -0700 | [diff] [blame] | 32 | #ifdef USE_F2FS |
| 33 | static int generate_f2fs_image(int fd, long long partSize) |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 34 | { |
JP Abgrall | 6bd72be | 2014-06-17 23:43:18 -0700 | [diff] [blame] | 35 | return make_f2fs_sparse_fd(fd, partSize, NULL, NULL); |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 36 | } |
JP Abgrall | 6bd72be | 2014-06-17 23:43:18 -0700 | [diff] [blame] | 37 | #endif |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 38 | |
Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 39 | static 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[] = { |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 45 | { "ext4", generate_ext4_image}, |
JP Abgrall | 6bd72be | 2014-06-17 23:43:18 -0700 | [diff] [blame] | 46 | #ifdef USE_F2FS |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 47 | { "f2fs", generate_f2fs_image}, |
JP Abgrall | 6bd72be | 2014-06-17 23:43:18 -0700 | [diff] [blame] | 48 | #endif |
Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
JP Abgrall | 7e85974 | 2014-05-06 15:14:15 -0700 | [diff] [blame] | 51 | const struct fs_generator* fs_get_generator(const char *fs_type) |
Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 52 | { |
| 53 | unsigned i; |
| 54 | |
| 55 | for (i = 0; i < sizeof(generators) / sizeof(*generators); i++) |
JP Abgrall | 7e85974 | 2014-05-06 15:14:15 -0700 | [diff] [blame] | 56 | if (!strcmp(generators[i].fs_type, fs_type)) |
Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 57 | return generators + i; |
| 58 | |
| 59 | return NULL; |
| 60 | } |
| 61 | |
| 62 | int fs_generator_generate(const struct fs_generator* gen, int tmpFileNo, long long partSize) |
| 63 | { |
| 64 | return gen->generate(tmpFileNo, partSize); |
| 65 | } |