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