blob: d8f9e165d43caf9ec5f179930a4a3045d2a14089 [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>
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
JP Abgrall6bd72be2014-06-17 23:43:18 -070032#ifdef USE_F2FS
33static int generate_f2fs_image(int fd, long long partSize)
JP Abgrall12351582014-06-17 17:01:14 -070034{
JP Abgrall6bd72be2014-06-17 23:43:18 -070035 return make_f2fs_sparse_fd(fd, partSize, NULL, NULL);
JP Abgrall12351582014-06-17 17:01:14 -070036}
JP Abgrall6bd72be2014-06-17 23:43:18 -070037#endif
JP Abgrall12351582014-06-17 17:01:14 -070038
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070039static const struct fs_generator {
40
Elliott Hughesb3748de2015-06-23 20:27:58 -070041 const char* fs_type; //must match what fastboot reports for partition type
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070042 int (*generate)(int fd, long long partSize); //returns 0 or error value
43
44} generators[] = {
JP Abgrall12351582014-06-17 17:01:14 -070045 { "ext4", generate_ext4_image},
JP Abgrall6bd72be2014-06-17 23:43:18 -070046#ifdef USE_F2FS
JP Abgrall12351582014-06-17 17:01:14 -070047 { "f2fs", generate_f2fs_image},
JP Abgrall6bd72be2014-06-17 23:43:18 -070048#endif
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070049};
50
JP Abgrall7e859742014-05-06 15:14:15 -070051const struct fs_generator* fs_get_generator(const char *fs_type)
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070052{
53 unsigned i;
54
55 for (i = 0; i < sizeof(generators) / sizeof(*generators); i++)
JP Abgrall7e859742014-05-06 15:14:15 -070056 if (!strcmp(generators[i].fs_type, fs_type))
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070057 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}