blob: 90d84742bb9fb1831c4a8361ec511ccf03b7079b [file] [log] [blame]
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -07001#include "fastboot.h"
2#include "make_ext4fs.h"
JP Abgrall12351582014-06-17 17:01:14 -07003#include "make_f2fs.h"
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -07004#include "fs.h"
5
6#include <errno.h>
7#include <stdio.h>
8#include <stdlib.h>
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -07009#include <string.h>
10#include <sys/stat.h>
11#include <sys/types.h>
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070012#include <unistd.h>
13
Elliott Hughesfc797672015-04-07 20:12:50 -070014#include <sparse/sparse.h>
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070015
16static 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 Abgrall6bd72be2014-06-17 23:43:18 -070023#ifdef USE_F2FS
24static int generate_f2fs_image(int fd, long long partSize)
JP Abgrall12351582014-06-17 17:01:14 -070025{
JP Abgrall6bd72be2014-06-17 23:43:18 -070026 return make_f2fs_sparse_fd(fd, partSize, NULL, NULL);
JP Abgrall12351582014-06-17 17:01:14 -070027}
JP Abgrall6bd72be2014-06-17 23:43:18 -070028#endif
JP Abgrall12351582014-06-17 17:01:14 -070029
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070030static const struct fs_generator {
31
Elliott Hughesb3748de2015-06-23 20:27:58 -070032 const char* fs_type; //must match what fastboot reports for partition type
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070033 int (*generate)(int fd, long long partSize); //returns 0 or error value
34
35} generators[] = {
JP Abgrall12351582014-06-17 17:01:14 -070036 { "ext4", generate_ext4_image},
JP Abgrall6bd72be2014-06-17 23:43:18 -070037#ifdef USE_F2FS
JP Abgrall12351582014-06-17 17:01:14 -070038 { "f2fs", generate_f2fs_image},
JP Abgrall6bd72be2014-06-17 23:43:18 -070039#endif
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070040};
41
Elliott Hughes8ab9a322015-11-02 14:05:57 -080042const struct fs_generator* fs_get_generator(const std::string& fs_type) {
Elliott Hughesfc797672015-04-07 20:12:50 -070043 for (size_t i = 0; i < sizeof(generators) / sizeof(*generators); i++) {
Elliott Hughes8ab9a322015-11-02 14:05:57 -080044 if (fs_type == generators[i].fs_type) {
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070045 return generators + i;
Elliott Hughesfc797672015-04-07 20:12:50 -070046 }
47 }
48 return nullptr;
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070049}
50
51int fs_generator_generate(const struct fs_generator* gen, int tmpFileNo, long long partSize)
52{
53 return gen->generate(tmpFileNo, partSize);
54}