diff options
author | Treehugger Robot | 2017-07-31 21:35:31 -0500 |
---|---|---|
committer | Gerrit Code Review | 2017-07-31 21:35:31 -0500 |
commit | c7ba2bb5a380aa54443814551d22aa48670d7aed (patch) | |
tree | 7f82602cf85cdb2f94cf42bccfdbb267d27b0da7 | |
parent | be4eec05e84036f63e0881519e9505ebee2c67d0 (diff) | |
parent | 29fc859a6de4f5566652c4f5750e91c965d4b97f (diff) | |
download | platform-system-core-c7ba2bb5a380aa54443814551d22aa48670d7aed.tar.gz platform-system-core-c7ba2bb5a380aa54443814551d22aa48670d7aed.tar.xz platform-system-core-c7ba2bb5a380aa54443814551d22aa48670d7aed.zip |
Merge "fastboot: call mke2fs to format ext4 filesystem on windows"
-rw-r--r-- | fastboot/fs.cpp | 60 |
1 files changed, 46 insertions, 14 deletions
diff --git a/fastboot/fs.cpp b/fastboot/fs.cpp index 6058b882d..709f061bd 100644 --- a/fastboot/fs.cpp +++ b/fastboot/fs.cpp | |||
@@ -12,10 +12,14 @@ | |||
12 | #include <sys/types.h> | 12 | #include <sys/types.h> |
13 | #ifndef WIN32 | 13 | #ifndef WIN32 |
14 | #include <sys/wait.h> | 14 | #include <sys/wait.h> |
15 | #else | ||
16 | #include <tchar.h> | ||
17 | #include <windows.h> | ||
15 | #endif | 18 | #endif |
16 | #include <unistd.h> | 19 | #include <unistd.h> |
17 | #include <vector> | 20 | #include <vector> |
18 | 21 | ||
22 | #include <android-base/errors.h> | ||
19 | #include <android-base/file.h> | 23 | #include <android-base/file.h> |
20 | #include <android-base/stringprintf.h> | 24 | #include <android-base/stringprintf.h> |
21 | #include <android-base/unique_fd.h> | 25 | #include <android-base/unique_fd.h> |
@@ -26,21 +30,49 @@ using android::base::StringPrintf; | |||
26 | using android::base::unique_fd; | 30 | using android::base::unique_fd; |
27 | 31 | ||
28 | #ifdef WIN32 | 32 | #ifdef WIN32 |
29 | static int generate_ext4_image(const char* fileName, long long partSize, const std::string& initial_dir, | 33 | static int exec_e2fs_cmd(const char* path, char* const argv[]) { |
30 | unsigned eraseBlkSize, unsigned logicalBlkSize) | 34 | std::string cmd; |
31 | { | 35 | int i = 0; |
32 | unique_fd fd(open(fileName, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR)); | 36 | while (argv[i] != nullptr) { |
33 | if (fd == -1) { | 37 | cmd += argv[i++]; |
34 | fprintf(stderr, "Unable to open output file for EXT4 filesystem: %s\n", strerror(errno)); | 38 | cmd += " "; |
35 | return -1; | ||
36 | } | 39 | } |
37 | if (initial_dir.empty()) { | 40 | cmd = cmd.substr(0, cmd.size() - 1); |
38 | make_ext4fs_sparse_fd_align(fd, partSize, NULL, NULL, eraseBlkSize, logicalBlkSize); | 41 | |
39 | } else { | 42 | STARTUPINFO si; |
40 | make_ext4fs_sparse_fd_directory_align(fd, partSize, NULL, NULL, initial_dir.c_str(), | 43 | PROCESS_INFORMATION pi; |
41 | eraseBlkSize, logicalBlkSize); | 44 | DWORD exit_code = 0; |
45 | |||
46 | ZeroMemory(&si, sizeof(si)); | ||
47 | si.cb = sizeof(si); | ||
48 | ZeroMemory(&pi, sizeof(pi)); | ||
49 | |||
50 | SetEnvironmentVariableA("MKE2FS_CONFIG", ""); | ||
51 | |||
52 | if (!CreateProcessA(nullptr, // No module name (use command line) | ||
53 | const_cast<char*>(cmd.c_str()), // Command line | ||
54 | nullptr, // Process handle not inheritable | ||
55 | nullptr, // Thread handle not inheritable | ||
56 | FALSE, // Set handle inheritance to FALSE | ||
57 | 0, // No creation flags | ||
58 | nullptr, // Use parent's environment block | ||
59 | nullptr, // Use parent's starting directory | ||
60 | &si, // Pointer to STARTUPINFO structure | ||
61 | &pi) // Pointer to PROCESS_INFORMATION structure | ||
62 | ) { | ||
63 | fprintf(stderr, "CreateProcess failed: %s\n", | ||
64 | android::base::SystemErrorCodeToString(GetLastError()).c_str()); | ||
65 | return -1; | ||
42 | } | 66 | } |
43 | return 0; | 67 | |
68 | WaitForSingleObject(pi.hProcess, INFINITE); | ||
69 | |||
70 | GetExitCodeProcess(pi.hProcess, &exit_code); | ||
71 | |||
72 | CloseHandle(pi.hProcess); | ||
73 | CloseHandle(pi.hThread); | ||
74 | |||
75 | return exit_code != 0; | ||
44 | } | 76 | } |
45 | #else | 77 | #else |
46 | static int exec_e2fs_cmd(const char* path, char* const argv[]) { | 78 | static int exec_e2fs_cmd(const char* path, char* const argv[]) { |
@@ -68,6 +100,7 @@ static int exec_e2fs_cmd(const char* path, char* const argv[]) { | |||
68 | } | 100 | } |
69 | return ret; | 101 | return ret; |
70 | } | 102 | } |
103 | #endif | ||
71 | 104 | ||
72 | static int generate_ext4_image(const char* fileName, long long partSize, | 105 | static int generate_ext4_image(const char* fileName, long long partSize, |
73 | const std::string& initial_dir, unsigned eraseBlkSize, | 106 | const std::string& initial_dir, unsigned eraseBlkSize, |
@@ -121,7 +154,6 @@ static int generate_ext4_image(const char* fileName, long long partSize, | |||
121 | 154 | ||
122 | return 0; | 155 | return 0; |
123 | } | 156 | } |
124 | #endif | ||
125 | 157 | ||
126 | #ifdef USE_F2FS | 158 | #ifdef USE_F2FS |
127 | static int generate_f2fs_image(const char* fileName, long long partSize, const std::string& initial_dir, | 159 | static int generate_f2fs_image(const char* fileName, long long partSize, const std::string& initial_dir, |