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> |
Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 9 | #include <string.h> |
| 10 | #include <sys/stat.h> |
| 11 | #include <sys/types.h> |
Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 12 | #include <unistd.h> |
| 13 | |
Elliott Hughes | fc79767 | 2015-04-07 20:12:50 -0700 | [diff] [blame] | 14 | #include <sparse/sparse.h> |
Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 15 | |
| 16 | static int generate_ext4_image(int fd, long long partSize) |
| 17 | { |
| 18 | make_ext4fs_sparse_fd(fd, partSize, NULL, NULL); |
| 19 | |
| 20 | return 0; |
| 21 | } |
| 22 | |
JP Abgrall | 6bd72be | 2014-06-17 23:43:18 -0700 | [diff] [blame] | 23 | #ifdef USE_F2FS |
| 24 | static int generate_f2fs_image(int fd, long long partSize) |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 25 | { |
JP Abgrall | 6bd72be | 2014-06-17 23:43:18 -0700 | [diff] [blame] | 26 | return make_f2fs_sparse_fd(fd, partSize, NULL, NULL); |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 27 | } |
JP Abgrall | 6bd72be | 2014-06-17 23:43:18 -0700 | [diff] [blame] | 28 | #endif |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 29 | |
Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 30 | static const struct fs_generator { |
| 31 | |
Elliott Hughes | b3748de | 2015-06-23 20:27:58 -0700 | [diff] [blame] | 32 | const char* fs_type; //must match what fastboot reports for partition type |
Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 33 | int (*generate)(int fd, long long partSize); //returns 0 or error value |
| 34 | |
| 35 | } generators[] = { |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 36 | { "ext4", generate_ext4_image}, |
JP Abgrall | 6bd72be | 2014-06-17 23:43:18 -0700 | [diff] [blame] | 37 | #ifdef USE_F2FS |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 38 | { "f2fs", generate_f2fs_image}, |
JP Abgrall | 6bd72be | 2014-06-17 23:43:18 -0700 | [diff] [blame] | 39 | #endif |
Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
Elliott Hughes | 8ab9a32 | 2015-11-02 14:05:57 -0800 | [diff] [blame^] | 42 | const struct fs_generator* fs_get_generator(const std::string& fs_type) { |
Elliott Hughes | fc79767 | 2015-04-07 20:12:50 -0700 | [diff] [blame] | 43 | for (size_t i = 0; i < sizeof(generators) / sizeof(*generators); i++) { |
Elliott Hughes | 8ab9a32 | 2015-11-02 14:05:57 -0800 | [diff] [blame^] | 44 | if (fs_type == generators[i].fs_type) { |
Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 45 | return generators + i; |
Elliott Hughes | fc79767 | 2015-04-07 20:12:50 -0700 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | return nullptr; |
Dmitry Grinberg | e6f3e9b | 2014-03-11 18:28:15 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | int fs_generator_generate(const struct fs_generator* gen, int tmpFileNo, long long partSize) |
| 52 | { |
| 53 | return gen->generate(tmpFileNo, partSize); |
| 54 | } |