2014-03-12 09:28:15 +08:00
|
|
|
#include "fastboot.h"
|
|
|
|
#include "make_ext4fs.h"
|
2014-06-18 08:01:14 +08:00
|
|
|
#include "make_f2fs.h"
|
2014-03-12 09:28:15 +08:00
|
|
|
#include "fs.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sparse/sparse.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#ifdef USE_MINGW
|
|
|
|
#include <fcntl.h>
|
|
|
|
#else
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int generate_ext4_image(int fd, long long partSize)
|
|
|
|
{
|
|
|
|
make_ext4fs_sparse_fd(fd, partSize, NULL, NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-18 14:43:18 +08:00
|
|
|
#ifdef USE_F2FS
|
|
|
|
static int generate_f2fs_image(int fd, long long partSize)
|
2014-06-18 08:01:14 +08:00
|
|
|
{
|
2014-06-18 14:43:18 +08:00
|
|
|
return make_f2fs_sparse_fd(fd, partSize, NULL, NULL);
|
2014-06-18 08:01:14 +08:00
|
|
|
}
|
2014-06-18 14:43:18 +08:00
|
|
|
#endif
|
2014-06-18 08:01:14 +08:00
|
|
|
|
2014-03-12 09:28:15 +08:00
|
|
|
static const struct fs_generator {
|
|
|
|
|
|
|
|
char *fs_type; //must match what fastboot reports for partition type
|
|
|
|
int (*generate)(int fd, long long partSize); //returns 0 or error value
|
|
|
|
|
|
|
|
} generators[] = {
|
2014-06-18 08:01:14 +08:00
|
|
|
{ "ext4", generate_ext4_image},
|
2014-06-18 14:43:18 +08:00
|
|
|
#ifdef USE_F2FS
|
2014-06-18 08:01:14 +08:00
|
|
|
{ "f2fs", generate_f2fs_image},
|
2014-06-18 14:43:18 +08:00
|
|
|
#endif
|
2014-03-12 09:28:15 +08:00
|
|
|
};
|
|
|
|
|
2014-05-07 06:14:15 +08:00
|
|
|
const struct fs_generator* fs_get_generator(const char *fs_type)
|
2014-03-12 09:28:15 +08:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(generators) / sizeof(*generators); i++)
|
2014-05-07 06:14:15 +08:00
|
|
|
if (!strcmp(generators[i].fs_type, fs_type))
|
2014-03-12 09:28:15 +08:00
|
|
|
return generators + i;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fs_generator_generate(const struct fs_generator* gen, int tmpFileNo, long long partSize)
|
|
|
|
{
|
|
|
|
return gen->generate(tmpFileNo, partSize);
|
|
|
|
}
|