diff options
-rw-r--r-- | fs_mgr/liblp/Android.bp | 5 | ||||
-rw-r--r-- | fs_mgr/liblp/images.cpp | 28 | ||||
-rw-r--r-- | fs_mgr/liblp/partition_opener.cpp | 5 | ||||
-rw-r--r-- | fs_mgr/liblp/utility.cpp | 2 | ||||
-rw-r--r-- | fs_mgr/liblp/writer.cpp | 4 |
5 files changed, 29 insertions, 15 deletions
diff --git a/fs_mgr/liblp/Android.bp b/fs_mgr/liblp/Android.bp index 5689bdf60..355b7a1f1 100644 --- a/fs_mgr/liblp/Android.bp +++ b/fs_mgr/liblp/Android.bp @@ -39,6 +39,11 @@ cc_library { "libext4_utils", "libz", ], + target: { + windows: { + enabled: true, + }, + }, export_include_dirs: ["include"], } diff --git a/fs_mgr/liblp/images.cpp b/fs_mgr/liblp/images.cpp index 9e64de16a..cae93e8f0 100644 --- a/fs_mgr/liblp/images.cpp +++ b/fs_mgr/liblp/images.cpp @@ -27,6 +27,12 @@ namespace android { namespace fs_mgr { +using android::base::unique_fd; + +#if defined(_WIN32) +static const int O_NOFOLLOW = 0; +#endif + std::unique_ptr<LpMetadata> ReadFromImageFile(int fd) { std::unique_ptr<uint8_t[]> buffer = std::make_unique<uint8_t[]>(LP_METADATA_GEOMETRY_SIZE); if (SeekFile64(fd, 0, SEEK_SET) < 0) { @@ -62,7 +68,7 @@ std::unique_ptr<LpMetadata> ReadFromImageBlob(const void* data, size_t bytes) { } std::unique_ptr<LpMetadata> ReadFromImageFile(const char* file) { - android::base::unique_fd fd(open(file, O_RDONLY | O_CLOEXEC)); + unique_fd fd(open(file, O_RDONLY | O_CLOEXEC)); if (fd < 0) { PERROR << __PRETTY_FUNCTION__ << " open failed: " << file; return nullptr; @@ -84,7 +90,7 @@ bool WriteToImageFile(int fd, const LpMetadata& input) { } bool WriteToImageFile(const char* file, const LpMetadata& input) { - android::base::unique_fd fd(open(file, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC, 0644)); + unique_fd fd(open(file, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC, 0644)); if (fd < 0) { PERROR << __PRETTY_FUNCTION__ << " open failed: " << file; return false; @@ -143,7 +149,7 @@ bool SparseBuilder::IsValid() const { } bool SparseBuilder::Export(const char* file) { - android::base::unique_fd fd(open(file, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC, 0644)); + unique_fd fd(open(file, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC, 0644)); if (fd < 0) { PERROR << "open failed: " << file; return false; @@ -162,19 +168,15 @@ bool SparseBuilder::Export(const char* file) { } bool SparseBuilder::ExportFiles(const std::string& output_dir) { - android::base::unique_fd dir(open(output_dir.c_str(), O_CLOEXEC | O_DIRECTORY | O_NOFOLLOW)); - if (dir < 0) { - PERROR << "open dir failed: " << output_dir; - return false; - } - for (size_t i = 0; i < device_images_.size(); i++) { std::string name = GetBlockDevicePartitionName(metadata_.block_devices[i]); - std::string path = output_dir + "/super_" + name + ".img"; - android::base::unique_fd fd(openat( - dir, path.c_str(), O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC | O_NOFOLLOW, 0644)); + std::string file_name = "super_" + name + ".img"; + std::string file_path = output_dir + "/" + file_name; + + static const int kOpenFlags = O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC | O_NOFOLLOW; + unique_fd fd(open(file_path.c_str(), kOpenFlags, 0644)); if (fd < 0) { - PERROR << "open failed: " << path; + PERROR << "open failed: " << file_path; return false; } // No gzip compression; sparseify; no checksum. diff --git a/fs_mgr/liblp/partition_opener.cpp b/fs_mgr/liblp/partition_opener.cpp index 416f87f2e..898f24127 100644 --- a/fs_mgr/liblp/partition_opener.cpp +++ b/fs_mgr/liblp/partition_opener.cpp @@ -19,8 +19,9 @@ #if defined(__linux__) #include <linux/fs.h> #endif +#if !defined(_WIN32) #include <sys/ioctl.h> -#include <sys/stat.h> +#endif #include <sys/types.h> #include <unistd.h> @@ -84,7 +85,7 @@ bool GetBlockDeviceInfo(const std::string& block_device, BlockDeviceInfo* device unique_fd PartitionOpener::Open(const std::string& partition_name, int flags) const { std::string path = GetPartitionAbsolutePath(partition_name); - return unique_fd{open(path.c_str(), flags)}; + return unique_fd{open(path.c_str(), flags | O_CLOEXEC)}; } bool PartitionOpener::GetInfo(const std::string& partition_name, BlockDeviceInfo* info) const { diff --git a/fs_mgr/liblp/utility.cpp b/fs_mgr/liblp/utility.cpp index 4f20b6bf8..f0a381279 100644 --- a/fs_mgr/liblp/utility.cpp +++ b/fs_mgr/liblp/utility.cpp @@ -29,6 +29,7 @@ namespace android { namespace fs_mgr { bool GetDescriptorSize(int fd, uint64_t* size) { +#if !defined(_WIN32) struct stat s; if (fstat(fd, &s) < 0) { PERROR << __PRETTY_FUNCTION__ << "fstat failed"; @@ -39,6 +40,7 @@ bool GetDescriptorSize(int fd, uint64_t* size) { *size = get_block_device_size(fd); return *size != 0; } +#endif int64_t result = SeekFile64(fd, 0, SEEK_END); if (result == -1) { diff --git a/fs_mgr/liblp/writer.cpp b/fs_mgr/liblp/writer.cpp index e72cdfa16..d8195caef 100644 --- a/fs_mgr/liblp/writer.cpp +++ b/fs_mgr/liblp/writer.cpp @@ -235,6 +235,10 @@ static bool DefaultWriter(int fd, const std::string& blob) { return android::base::WriteFully(fd, blob.data(), blob.size()); } +#if defined(_WIN32) +static const int O_SYNC = 0; +#endif + bool FlashPartitionTable(const IPartitionOpener& opener, const std::string& super_partition, const LpMetadata& metadata) { android::base::unique_fd fd = opener.Open(super_partition, O_RDWR | O_SYNC); |