blob: 11e391b8217a85facea6e2b0ded7586fb50eb6e9 [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 Abgrall12351582014-06-17 17:01:14 -070032int generate_f2fs_image(int fd, long long partSize)
33{
34 make_f2fs_sparse_fd(fd, partSize, NULL, NULL);
35 return 0;
36}
37
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070038static const struct fs_generator {
39
40 char *fs_type; //must match what fastboot reports for partition type
41 int (*generate)(int fd, long long partSize); //returns 0 or error value
42
43} generators[] = {
JP Abgrall12351582014-06-17 17:01:14 -070044 { "ext4", generate_ext4_image},
45 { "f2fs", generate_f2fs_image},
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070046};
47
JP Abgrall7e859742014-05-06 15:14:15 -070048const struct fs_generator* fs_get_generator(const char *fs_type)
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070049{
50 unsigned i;
51
52 for (i = 0; i < sizeof(generators) / sizeof(*generators); i++)
JP Abgrall7e859742014-05-06 15:14:15 -070053 if (!strcmp(generators[i].fs_type, fs_type))
Dmitry Grinberge6f3e9b2014-03-11 18:28:15 -070054 return generators + i;
55
56 return NULL;
57}
58
59int fs_generator_generate(const struct fs_generator* gen, int tmpFileNo, long long partSize)
60{
61 return gen->generate(tmpFileNo, partSize);
62}