Merge "fastboot: use filename instead of fd to generate filesystem image" am: 010f7714b7
am: 104470da0f
am: d195ab0b23
Change-Id: I2a2f103b2743b18ec5dae542c752fb8fcc9e9161
This commit is contained in:
commit
7b36933a83
|
@ -53,6 +53,7 @@
|
|||
#include <android-base/parsenetaddress.h>
|
||||
#include <android-base/stringprintf.h>
|
||||
#include <android-base/strings.h>
|
||||
#include <android-base/test_utils.h>
|
||||
#include <android-base/unique_fd.h>
|
||||
#include <sparse/sparse.h>
|
||||
#include <ziparchive/zip_archive.h>
|
||||
|
@ -1350,7 +1351,8 @@ static void fb_perform_format(Transport* transport,
|
|||
struct fastboot_buffer buf;
|
||||
const char* errMsg = nullptr;
|
||||
const struct fs_generator* gen = nullptr;
|
||||
int fd;
|
||||
TemporaryFile output;
|
||||
unique_fd fd;
|
||||
|
||||
unsigned int limit = INT_MAX;
|
||||
if (target_sparse_limit > 0 && target_sparse_limit < limit) {
|
||||
|
@ -1403,22 +1405,23 @@ static void fb_perform_format(Transport* transport,
|
|||
return;
|
||||
}
|
||||
|
||||
fd = make_temporary_fd();
|
||||
if (fd == -1) return;
|
||||
|
||||
unsigned eraseBlkSize, logicalBlkSize;
|
||||
eraseBlkSize = fb_get_flash_block_size(transport, "erase-block-size");
|
||||
logicalBlkSize = fb_get_flash_block_size(transport, "logical-block-size");
|
||||
|
||||
if (fs_generator_generate(gen, fd, size, initial_dir, eraseBlkSize, logicalBlkSize)) {
|
||||
if (fs_generator_generate(gen, output.path, size, initial_dir,
|
||||
eraseBlkSize, logicalBlkSize)) {
|
||||
fprintf(stderr, "Cannot generate image: %s\n", strerror(errno));
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!load_buf_fd(transport, fd, &buf)) {
|
||||
fd.reset(open(output.path, O_RDONLY));
|
||||
if (fd == -1) {
|
||||
fprintf(stderr, "Cannot open generated image: %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
if (!load_buf_fd(transport, fd.release(), &buf)) {
|
||||
fprintf(stderr, "Cannot read image: %s\n", strerror(errno));
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
flash_buf(partition, &buf);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "make_f2fs.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -11,12 +12,20 @@
|
|||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <android-base/unique_fd.h>
|
||||
#include <ext4_utils/make_ext4fs.h>
|
||||
#include <sparse/sparse.h>
|
||||
|
||||
static int generate_ext4_image(int fd, long long partSize, const std::string& initial_dir,
|
||||
using android::base::unique_fd;
|
||||
|
||||
static int generate_ext4_image(const char* fileName, long long partSize, const std::string& initial_dir,
|
||||
unsigned eraseBlkSize, unsigned logicalBlkSize)
|
||||
{
|
||||
unique_fd fd(open(fileName, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR));
|
||||
if (fd == -1) {
|
||||
fprintf(stderr, "Unable to open output file for EXT4 filesystem: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (initial_dir.empty()) {
|
||||
make_ext4fs_sparse_fd_align(fd, partSize, NULL, NULL, eraseBlkSize, logicalBlkSize);
|
||||
} else {
|
||||
|
@ -27,11 +36,16 @@ static int generate_ext4_image(int fd, long long partSize, const std::string& in
|
|||
}
|
||||
|
||||
#ifdef USE_F2FS
|
||||
static int generate_f2fs_image(int fd, long long partSize, const std::string& initial_dir,
|
||||
static int generate_f2fs_image(const char* fileName, long long partSize, const std::string& initial_dir,
|
||||
unsigned /* unused */, unsigned /* unused */)
|
||||
{
|
||||
if (!initial_dir.empty()) {
|
||||
fprintf(stderr, "Unable to set initial directory on F2FS filesystem\n");
|
||||
fprintf(stderr, "Unable to set initial directory on F2FS filesystem: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
unique_fd fd(open(fileName, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR));
|
||||
if (fd == -1) {
|
||||
fprintf(stderr, "Unable to open output file for F2FS filesystem: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return make_f2fs_sparse_fd(fd, partSize, NULL, NULL);
|
||||
|
@ -42,7 +56,7 @@ static const struct fs_generator {
|
|||
const char* fs_type; //must match what fastboot reports for partition type
|
||||
|
||||
//returns 0 or error value
|
||||
int (*generate)(int fd, long long partSize, const std::string& initial_dir,
|
||||
int (*generate)(const char* fileName, long long partSize, const std::string& initial_dir,
|
||||
unsigned eraseBlkSize, unsigned logicalBlkSize);
|
||||
|
||||
} generators[] = {
|
||||
|
@ -61,8 +75,8 @@ const struct fs_generator* fs_get_generator(const std::string& fs_type) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
int fs_generator_generate(const struct fs_generator* gen, int tmpFileNo, long long partSize,
|
||||
int fs_generator_generate(const struct fs_generator* gen, const char* fileName, long long partSize,
|
||||
const std::string& initial_dir, unsigned eraseBlkSize, unsigned logicalBlkSize)
|
||||
{
|
||||
return gen->generate(tmpFileNo, partSize, initial_dir, eraseBlkSize, logicalBlkSize);
|
||||
return gen->generate(fileName, partSize, initial_dir, eraseBlkSize, logicalBlkSize);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
struct fs_generator;
|
||||
|
||||
const struct fs_generator* fs_get_generator(const std::string& fs_type);
|
||||
int fs_generator_generate(const struct fs_generator* gen, int tmpFileNo, long long partSize,
|
||||
int fs_generator_generate(const struct fs_generator* gen, const char* fileName, long long partSize,
|
||||
const std::string& initial_dir, unsigned eraseBlkSize = 0, unsigned logicalBlkSize = 0);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue