fs.c revision 1235158c29909132fbe9aa52939061fc81f0800e
1#include "fastboot.h"
2#include "make_ext4fs.h"
3#include "make_f2fs.h"
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
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
32int generate_f2fs_image(int fd, long long partSize)
33{
34    make_f2fs_sparse_fd(fd, partSize, NULL, NULL);
35    return 0;
36}
37
38static 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[] = {
44    { "ext4", generate_ext4_image},
45    { "f2fs", generate_f2fs_image},
46};
47
48const struct fs_generator* fs_get_generator(const char *fs_type)
49{
50    unsigned i;
51
52    for (i = 0; i < sizeof(generators) / sizeof(*generators); i++)
53        if (!strcmp(generators[i].fs_type, fs_type))
54            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}
63