Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Colin Cross | 33f96c6 | 2010-12-22 18:40:14 -0800 | [diff] [blame] | 17 | #include "make_ext4fs.h" |
Colin Cross | 33f96c6 | 2010-12-22 18:40:14 -0800 | [diff] [blame] | 18 | #include "ext4_utils.h" |
| 19 | #include "allocate.h" |
| 20 | #include "contents.h" |
Colin Cross | dc5abee | 2012-04-23 23:20:48 -0700 | [diff] [blame] | 21 | #include "wipe.h" |
| 22 | |
| 23 | #include <sparse/sparse.h> |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 24 | |
Raphael Moll | 4605b3f | 2012-02-03 23:02:33 -0800 | [diff] [blame] | 25 | #include <assert.h> |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 26 | #include <dirent.h> |
Anatol Pomazau | 0349bd9 | 2012-01-11 15:12:27 -0800 | [diff] [blame] | 27 | #include <fcntl.h> |
Colin Cross | af07234 | 2014-01-23 13:19:27 -0800 | [diff] [blame] | 28 | #include <inttypes.h> |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 29 | #include <libgen.h> |
Colin Cross | 881cca2 | 2010-06-20 23:57:06 -0700 | [diff] [blame] | 30 | #include <stdio.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <string.h> |
| 33 | #include <unistd.h> |
| 34 | #include <sys/stat.h> |
| 35 | #include <sys/types.h> |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 36 | |
Raphael Moll | 4605b3f | 2012-02-03 23:02:33 -0800 | [diff] [blame] | 37 | #ifdef USE_MINGW |
| 38 | |
| 39 | #include <winsock2.h> |
| 40 | |
| 41 | /* These match the Linux definitions of these flags. |
| 42 | L_xx is defined to avoid conflicting with the win32 versions. |
| 43 | */ |
| 44 | #define L_S_IRUSR 00400 |
| 45 | #define L_S_IWUSR 00200 |
| 46 | #define L_S_IXUSR 00100 |
| 47 | #define S_IRWXU (L_S_IRUSR | L_S_IWUSR | L_S_IXUSR) |
| 48 | #define S_IRGRP 00040 |
| 49 | #define S_IWGRP 00020 |
| 50 | #define S_IXGRP 00010 |
| 51 | #define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) |
| 52 | #define S_IROTH 00004 |
| 53 | #define S_IWOTH 00002 |
| 54 | #define S_IXOTH 00001 |
| 55 | #define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) |
| 56 | #define S_ISUID 0004000 |
| 57 | #define S_ISGID 0002000 |
| 58 | #define S_ISVTX 0001000 |
| 59 | |
Anatol Pomazau | 0349bd9 | 2012-01-11 15:12:27 -0800 | [diff] [blame] | 60 | #else |
| 61 | |
Colin Cross | 9652986 | 2013-01-23 15:38:57 -0800 | [diff] [blame] | 62 | #include <selinux/selinux.h> |
| 63 | #include <selinux/label.h> |
Colin Cross | 9652986 | 2013-01-23 15:38:57 -0800 | [diff] [blame] | 64 | |
Anatol Pomazau | 0349bd9 | 2012-01-11 15:12:27 -0800 | [diff] [blame] | 65 | #define O_BINARY 0 |
| 66 | |
Raphael Moll | 4605b3f | 2012-02-03 23:02:33 -0800 | [diff] [blame] | 67 | #endif |
| 68 | |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 69 | /* TODO: Not implemented: |
| 70 | Allocating blocks in the same block group as the file inode |
| 71 | Hash or binary tree directories |
Colin Cross | 7a8bee7 | 2010-06-20 14:53:14 -0700 | [diff] [blame] | 72 | Special files: sockets, devices, fifos |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 73 | */ |
| 74 | |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 75 | static int filter_dot(const struct dirent *d) |
| 76 | { |
| 77 | return (strcmp(d->d_name, "..") && strcmp(d->d_name, ".")); |
| 78 | } |
| 79 | |
Stephen Smalley | 7907ac7 | 2014-04-25 14:57:55 -0400 | [diff] [blame] | 80 | static u32 build_default_directory_structure(const char *dir_path, |
| 81 | struct selabel_handle *sehnd) |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 82 | { |
| 83 | u32 inode; |
| 84 | u32 root_inode; |
| 85 | struct dentry dentries = { |
| 86 | .filename = "lost+found", |
| 87 | .file_type = EXT4_FT_DIR, |
| 88 | .mode = S_IRWXU, |
| 89 | .uid = 0, |
Colin Cross | de61f98 | 2010-08-04 15:06:09 -0700 | [diff] [blame] | 90 | .gid = 0, |
| 91 | .mtime = 0, |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 92 | }; |
| 93 | root_inode = make_directory(0, 1, &dentries, 1); |
| 94 | inode = make_directory(root_inode, 0, NULL, 0); |
| 95 | *dentries.inode = inode; |
Ken Sumrall | 75249ed | 2010-08-13 16:04:49 -0700 | [diff] [blame] | 96 | inode_set_permissions(inode, dentries.mode, |
| 97 | dentries.uid, dentries.gid, dentries.mtime); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 98 | |
Stephen Smalley | 7907ac7 | 2014-04-25 14:57:55 -0400 | [diff] [blame] | 99 | #ifndef USE_MINGW |
| 100 | if (sehnd) { |
| 101 | char *path = NULL; |
| 102 | char *secontext = NULL; |
| 103 | |
| 104 | asprintf(&path, "%slost+found", dir_path); |
| 105 | if (selabel_lookup(sehnd, &secontext, path, S_IFDIR) < 0) { |
| 106 | error("cannot lookup security context for %s", path); |
| 107 | } else { |
| 108 | inode_set_selinux(inode, secontext); |
| 109 | freecon(secontext); |
| 110 | } |
| 111 | free(path); |
| 112 | } |
| 113 | #endif |
| 114 | |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 115 | return root_inode; |
| 116 | } |
| 117 | |
Raphael Moll | 4605b3f | 2012-02-03 23:02:33 -0800 | [diff] [blame] | 118 | #ifndef USE_MINGW |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 119 | /* Read a local directory and create the same tree in the generated filesystem. |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 120 | Calls itself recursively with each directory in the given directory. |
| 121 | full_path is an absolute or relative path, with a trailing slash, to the |
| 122 | directory on disk that should be copied, or NULL if this is a directory |
| 123 | that does not exist on disk (e.g. lost+found). |
| 124 | dir_path is an absolute path, with trailing slash, to the same directory |
| 125 | if the image were mounted at the specified mount point */ |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 126 | static u32 build_directory_structure(const char *full_path, const char *dir_path, |
Kenny Root | 2e5c523 | 2012-03-30 20:38:32 -0700 | [diff] [blame] | 127 | u32 dir_inode, fs_config_func_t fs_config_func, |
Doug Zongker | 9526680 | 2013-12-05 15:51:28 -0800 | [diff] [blame] | 128 | struct selabel_handle *sehnd, int verbose, time_t fixed_time) |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 129 | { |
| 130 | int entries = 0; |
| 131 | struct dentry *dentries; |
Colin Cross | c18120d | 2012-11-20 19:41:42 -0800 | [diff] [blame] | 132 | struct dirent **namelist = NULL; |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 133 | struct stat stat; |
| 134 | int ret; |
| 135 | int i; |
| 136 | u32 inode; |
| 137 | u32 entry_inode; |
| 138 | u32 dirs = 0; |
Colin Cross | c18120d | 2012-11-20 19:41:42 -0800 | [diff] [blame] | 139 | bool needs_lost_and_found = false; |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 140 | |
Colin Cross | c18120d | 2012-11-20 19:41:42 -0800 | [diff] [blame] | 141 | if (full_path) { |
| 142 | entries = scandir(full_path, &namelist, filter_dot, (void*)alphasort); |
| 143 | if (entries < 0) { |
Mihai Serban | 04f4839 | 2015-01-07 12:44:24 +0200 | [diff] [blame] | 144 | #ifdef __GLIBC__ |
| 145 | /* The scandir function implemented in glibc has a bug that makes it |
| 146 | erroneously fail with ENOMEM under certain circumstances. |
| 147 | As a workaround we can retry the scandir call with the same arguments. |
| 148 | GLIBC BZ: https://sourceware.org/bugzilla/show_bug.cgi?id=17804 */ |
| 149 | if (errno == ENOMEM) |
| 150 | entries = scandir(full_path, &namelist, filter_dot, (void*)alphasort); |
| 151 | #endif |
| 152 | if (entries < 0) { |
| 153 | error_errno("scandir"); |
| 154 | return EXT4_ALLOCATE_FAILED; |
| 155 | } |
Colin Cross | c18120d | 2012-11-20 19:41:42 -0800 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
| 159 | if (dir_inode == 0) { |
| 160 | /* root directory, check if lost+found already exists */ |
| 161 | for (i = 0; i < entries; i++) |
| 162 | if (strcmp(namelist[i]->d_name, "lost+found") == 0) |
| 163 | break; |
| 164 | if (i == entries) |
| 165 | needs_lost_and_found = true; |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | dentries = calloc(entries, sizeof(struct dentry)); |
| 169 | if (dentries == NULL) |
| 170 | critical_error_errno("malloc"); |
| 171 | |
| 172 | for (i = 0; i < entries; i++) { |
| 173 | dentries[i].filename = strdup(namelist[i]->d_name); |
| 174 | if (dentries[i].filename == NULL) |
| 175 | critical_error_errno("strdup"); |
| 176 | |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 177 | asprintf(&dentries[i].path, "%s%s", dir_path, namelist[i]->d_name); |
| 178 | asprintf(&dentries[i].full_path, "%s%s", full_path, namelist[i]->d_name); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 179 | |
| 180 | free(namelist[i]); |
| 181 | |
| 182 | ret = lstat(dentries[i].full_path, &stat); |
| 183 | if (ret < 0) { |
| 184 | error_errno("lstat"); |
| 185 | i--; |
| 186 | entries--; |
| 187 | continue; |
| 188 | } |
| 189 | |
| 190 | dentries[i].size = stat.st_size; |
| 191 | dentries[i].mode = stat.st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO); |
Doug Zongker | 9526680 | 2013-12-05 15:51:28 -0800 | [diff] [blame] | 192 | if (fixed_time == -1) { |
| 193 | dentries[i].mtime = stat.st_mtime; |
| 194 | } else { |
| 195 | dentries[i].mtime = fixed_time; |
| 196 | } |
Nick Kralevich | 4df62f3 | 2013-02-07 14:21:34 -0800 | [diff] [blame] | 197 | uint64_t capabilities; |
Kenny Root | 68e3dfd | 2012-03-29 14:43:22 -0700 | [diff] [blame] | 198 | if (fs_config_func != NULL) { |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 199 | #ifdef ANDROID |
| 200 | unsigned int mode = 0; |
| 201 | unsigned int uid = 0; |
| 202 | unsigned int gid = 0; |
| 203 | int dir = S_ISDIR(stat.st_mode); |
Nick Kralevich | 4df62f3 | 2013-02-07 14:21:34 -0800 | [diff] [blame] | 204 | fs_config_func(dentries[i].path, dir, &uid, &gid, &mode, &capabilities); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 205 | dentries[i].mode = mode; |
| 206 | dentries[i].uid = uid; |
| 207 | dentries[i].gid = gid; |
Nick Kralevich | 4df62f3 | 2013-02-07 14:21:34 -0800 | [diff] [blame] | 208 | dentries[i].capabilities = capabilities; |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 209 | #else |
| 210 | error("can't set android permissions - built without android support"); |
| 211 | #endif |
| 212 | } |
Kenny Root | 723f1c7 | 2012-10-10 11:13:13 -0700 | [diff] [blame] | 213 | #ifndef USE_MINGW |
Stephen Smalley | b4eca4b | 2012-01-13 09:00:56 -0500 | [diff] [blame] | 214 | if (sehnd) { |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 215 | if (selabel_lookup(sehnd, &dentries[i].secon, dentries[i].path, stat.st_mode) < 0) { |
| 216 | error("cannot lookup security context for %s", dentries[i].path); |
Stephen Smalley | b4eca4b | 2012-01-13 09:00:56 -0500 | [diff] [blame] | 217 | } |
William Roberts | 2057370 | 2013-01-17 13:24:27 -0800 | [diff] [blame] | 218 | |
| 219 | if (dentries[i].secon && verbose) |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 220 | printf("Labeling %s as %s\n", dentries[i].path, dentries[i].secon); |
Stephen Smalley | b4eca4b | 2012-01-13 09:00:56 -0500 | [diff] [blame] | 221 | } |
| 222 | #endif |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 223 | |
| 224 | if (S_ISREG(stat.st_mode)) { |
| 225 | dentries[i].file_type = EXT4_FT_REG_FILE; |
| 226 | } else if (S_ISDIR(stat.st_mode)) { |
| 227 | dentries[i].file_type = EXT4_FT_DIR; |
| 228 | dirs++; |
| 229 | } else if (S_ISCHR(stat.st_mode)) { |
| 230 | dentries[i].file_type = EXT4_FT_CHRDEV; |
| 231 | } else if (S_ISBLK(stat.st_mode)) { |
| 232 | dentries[i].file_type = EXT4_FT_BLKDEV; |
| 233 | } else if (S_ISFIFO(stat.st_mode)) { |
| 234 | dentries[i].file_type = EXT4_FT_FIFO; |
| 235 | } else if (S_ISSOCK(stat.st_mode)) { |
| 236 | dentries[i].file_type = EXT4_FT_SOCK; |
| 237 | } else if (S_ISLNK(stat.st_mode)) { |
| 238 | dentries[i].file_type = EXT4_FT_SYMLINK; |
| 239 | dentries[i].link = calloc(info.block_size, 1); |
| 240 | readlink(dentries[i].full_path, dentries[i].link, info.block_size - 1); |
| 241 | } else { |
| 242 | error("unknown file type on %s", dentries[i].path); |
| 243 | i--; |
| 244 | entries--; |
| 245 | } |
| 246 | } |
| 247 | free(namelist); |
| 248 | |
Colin Cross | c18120d | 2012-11-20 19:41:42 -0800 | [diff] [blame] | 249 | if (needs_lost_and_found) { |
| 250 | /* insert a lost+found directory at the beginning of the dentries */ |
| 251 | struct dentry *tmp = calloc(entries + 1, sizeof(struct dentry)); |
| 252 | memset(tmp, 0, sizeof(struct dentry)); |
| 253 | memcpy(tmp + 1, dentries, entries * sizeof(struct dentry)); |
| 254 | dentries = tmp; |
| 255 | |
| 256 | dentries[0].filename = strdup("lost+found"); |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 257 | asprintf(&dentries[0].path, "%slost+found", dir_path); |
Colin Cross | c18120d | 2012-11-20 19:41:42 -0800 | [diff] [blame] | 258 | dentries[0].full_path = NULL; |
| 259 | dentries[0].size = 0; |
| 260 | dentries[0].mode = S_IRWXU; |
| 261 | dentries[0].file_type = EXT4_FT_DIR; |
| 262 | dentries[0].uid = 0; |
| 263 | dentries[0].gid = 0; |
Colin Cross | a532ecf | 2012-11-26 16:32:16 -0800 | [diff] [blame] | 264 | if (sehnd) { |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 265 | if (selabel_lookup(sehnd, &dentries[0].secon, dentries[0].path, dentries[0].mode) < 0) |
Colin Cross | a532ecf | 2012-11-26 16:32:16 -0800 | [diff] [blame] | 266 | error("cannot lookup security context for %s", dentries[0].path); |
Colin Cross | a532ecf | 2012-11-26 16:32:16 -0800 | [diff] [blame] | 267 | } |
Colin Cross | c18120d | 2012-11-20 19:41:42 -0800 | [diff] [blame] | 268 | entries++; |
| 269 | dirs++; |
| 270 | } |
| 271 | |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 272 | inode = make_directory(dir_inode, entries, dentries, dirs); |
| 273 | |
| 274 | for (i = 0; i < entries; i++) { |
| 275 | if (dentries[i].file_type == EXT4_FT_REG_FILE) { |
| 276 | entry_inode = make_file(dentries[i].full_path, dentries[i].size); |
| 277 | } else if (dentries[i].file_type == EXT4_FT_DIR) { |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 278 | char *subdir_full_path = NULL; |
| 279 | char *subdir_dir_path; |
| 280 | if (dentries[i].full_path) { |
| 281 | ret = asprintf(&subdir_full_path, "%s/", dentries[i].full_path); |
| 282 | if (ret < 0) |
| 283 | critical_error_errno("asprintf"); |
| 284 | } |
| 285 | ret = asprintf(&subdir_dir_path, "%s/", dentries[i].path); |
| 286 | if (ret < 0) |
| 287 | critical_error_errno("asprintf"); |
| 288 | entry_inode = build_directory_structure(subdir_full_path, |
Doug Zongker | 9526680 | 2013-12-05 15:51:28 -0800 | [diff] [blame] | 289 | subdir_dir_path, inode, fs_config_func, sehnd, verbose, fixed_time); |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 290 | free(subdir_full_path); |
| 291 | free(subdir_dir_path); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 292 | } else if (dentries[i].file_type == EXT4_FT_SYMLINK) { |
Nick Kralevich | 5446bde | 2013-02-19 19:05:47 -0800 | [diff] [blame] | 293 | entry_inode = make_link(dentries[i].link); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 294 | } else { |
| 295 | error("unknown file type on %s", dentries[i].path); |
| 296 | entry_inode = 0; |
| 297 | } |
| 298 | *dentries[i].inode = entry_inode; |
| 299 | |
| 300 | ret = inode_set_permissions(entry_inode, dentries[i].mode, |
Colin Cross | de61f98 | 2010-08-04 15:06:09 -0700 | [diff] [blame] | 301 | dentries[i].uid, dentries[i].gid, |
| 302 | dentries[i].mtime); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 303 | if (ret) |
| 304 | error("failed to set permissions on %s\n", dentries[i].path); |
Nick Kralevich | 4df62f3 | 2013-02-07 14:21:34 -0800 | [diff] [blame] | 305 | |
| 306 | /* |
| 307 | * It's important to call inode_set_selinux() before |
| 308 | * inode_set_capabilities(). Extended attributes need to |
| 309 | * be stored sorted order, and we guarantee this by making |
| 310 | * the calls in the proper order. |
| 311 | * Please see xattr_assert_sane() in contents.c |
| 312 | */ |
Stephen Smalley | b4eca4b | 2012-01-13 09:00:56 -0500 | [diff] [blame] | 313 | ret = inode_set_selinux(entry_inode, dentries[i].secon); |
| 314 | if (ret) |
| 315 | error("failed to set SELinux context on %s\n", dentries[i].path); |
Nick Kralevich | 4df62f3 | 2013-02-07 14:21:34 -0800 | [diff] [blame] | 316 | ret = inode_set_capabilities(entry_inode, dentries[i].capabilities); |
| 317 | if (ret) |
| 318 | error("failed to set capability on %s\n", dentries[i].path); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 319 | |
| 320 | free(dentries[i].path); |
| 321 | free(dentries[i].full_path); |
| 322 | free(dentries[i].link); |
| 323 | free((void *)dentries[i].filename); |
Stephen Smalley | b4eca4b | 2012-01-13 09:00:56 -0500 | [diff] [blame] | 324 | free(dentries[i].secon); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | free(dentries); |
| 328 | return inode; |
| 329 | } |
Raphael Moll | 4605b3f | 2012-02-03 23:02:33 -0800 | [diff] [blame] | 330 | #endif |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 331 | |
| 332 | static u32 compute_block_size() |
| 333 | { |
| 334 | return 4096; |
| 335 | } |
| 336 | |
Colin Cross | e4b5ae8 | 2010-08-03 14:10:07 -0700 | [diff] [blame] | 337 | static u32 compute_journal_blocks() |
| 338 | { |
| 339 | u32 journal_blocks = DIV_ROUND_UP(info.len, info.block_size) / 64; |
| 340 | if (journal_blocks < 1024) |
| 341 | journal_blocks = 1024; |
| 342 | if (journal_blocks > 32768) |
| 343 | journal_blocks = 32768; |
| 344 | return journal_blocks; |
| 345 | } |
| 346 | |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 347 | static u32 compute_blocks_per_group() |
| 348 | { |
| 349 | return info.block_size * 8; |
| 350 | } |
| 351 | |
| 352 | static u32 compute_inodes() |
| 353 | { |
| 354 | return DIV_ROUND_UP(info.len, info.block_size) / 4; |
| 355 | } |
| 356 | |
| 357 | static u32 compute_inodes_per_group() |
| 358 | { |
| 359 | u32 blocks = DIV_ROUND_UP(info.len, info.block_size); |
| 360 | u32 block_groups = DIV_ROUND_UP(blocks, info.blocks_per_group); |
Colin Cross | 96cc54a | 2011-04-29 16:45:48 -0700 | [diff] [blame] | 361 | u32 inodes = DIV_ROUND_UP(info.inodes, block_groups); |
Paul Lawrence | 40ce87a | 2014-03-03 10:51:58 -0800 | [diff] [blame] | 362 | inodes = EXT4_ALIGN(inodes, (info.block_size / info.inode_size)); |
Ken Sumrall | 107a9f1 | 2011-06-29 20:28:30 -0700 | [diff] [blame] | 363 | |
| 364 | /* After properly rounding up the number of inodes/group, |
| 365 | * make sure to update the total inodes field in the info struct. |
| 366 | */ |
| 367 | info.inodes = inodes * block_groups; |
| 368 | |
| 369 | return inodes; |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Colin Cross | 22742ce | 2010-12-22 16:01:52 -0800 | [diff] [blame] | 372 | static u32 compute_bg_desc_reserve_blocks() |
| 373 | { |
| 374 | u32 blocks = DIV_ROUND_UP(info.len, info.block_size); |
| 375 | u32 block_groups = DIV_ROUND_UP(blocks, info.blocks_per_group); |
| 376 | u32 bg_desc_blocks = DIV_ROUND_UP(block_groups * sizeof(struct ext2_group_desc), |
| 377 | info.block_size); |
| 378 | |
| 379 | u32 bg_desc_reserve_blocks = |
| 380 | DIV_ROUND_UP(block_groups * 1024 * sizeof(struct ext2_group_desc), |
| 381 | info.block_size) - bg_desc_blocks; |
| 382 | |
| 383 | if (bg_desc_reserve_blocks > info.block_size / sizeof(u32)) |
| 384 | bg_desc_reserve_blocks = info.block_size / sizeof(u32); |
| 385 | |
| 386 | return bg_desc_reserve_blocks; |
| 387 | } |
| 388 | |
Doug Zongker | 263eefd | 2010-06-29 17:23:14 -0700 | [diff] [blame] | 389 | void reset_ext4fs_info() { |
Doug Zongker | 9526680 | 2013-12-05 15:51:28 -0800 | [diff] [blame] | 390 | // Reset all the global data structures used by make_ext4fs so it |
| 391 | // can be called again. |
| 392 | memset(&info, 0, sizeof(info)); |
| 393 | memset(&aux_info, 0, sizeof(aux_info)); |
Colin Cross | f0ee37f | 2012-04-24 17:48:43 -0700 | [diff] [blame] | 394 | |
Colin Cross | 3843c14 | 2014-01-31 09:38:20 -0800 | [diff] [blame] | 395 | if (ext4_sparse_file) { |
| 396 | sparse_file_destroy(ext4_sparse_file); |
| 397 | ext4_sparse_file = NULL; |
Doug Zongker | 9526680 | 2013-12-05 15:51:28 -0800 | [diff] [blame] | 398 | } |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Colin Cross | 9652986 | 2013-01-23 15:38:57 -0800 | [diff] [blame] | 401 | int make_ext4fs_sparse_fd(int fd, long long len, |
Doug Zongker | 9526680 | 2013-12-05 15:51:28 -0800 | [diff] [blame] | 402 | const char *mountpoint, struct selabel_handle *sehnd) |
Colin Cross | 03ad99c | 2013-01-23 15:25:29 -0800 | [diff] [blame] | 403 | { |
| 404 | reset_ext4fs_info(); |
| 405 | info.len = len; |
| 406 | |
Jeff Sharkey | 7538cc9 | 2015-04-06 22:29:04 -0700 | [diff] [blame] | 407 | return make_ext4fs_internal(fd, NULL, mountpoint, NULL, 0, 1, 0, 0, 0, sehnd, 0, -1, NULL); |
Colin Cross | 03ad99c | 2013-01-23 15:25:29 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Colin Cross | 9652986 | 2013-01-23 15:38:57 -0800 | [diff] [blame] | 410 | int make_ext4fs(const char *filename, long long len, |
Doug Zongker | 9526680 | 2013-12-05 15:51:28 -0800 | [diff] [blame] | 411 | const char *mountpoint, struct selabel_handle *sehnd) |
Ken Sumrall | 983fb19 | 2011-01-19 17:15:42 -0800 | [diff] [blame] | 412 | { |
Anatol Pomazau | 0349bd9 | 2012-01-11 15:12:27 -0800 | [diff] [blame] | 413 | int fd; |
| 414 | int status; |
| 415 | |
| 416 | reset_ext4fs_info(); |
| 417 | info.len = len; |
| 418 | |
| 419 | fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); |
| 420 | if (fd < 0) { |
| 421 | error_errno("open"); |
| 422 | return EXIT_FAILURE; |
| 423 | } |
| 424 | |
Jeff Sharkey | 7538cc9 | 2015-04-06 22:29:04 -0700 | [diff] [blame] | 425 | status = make_ext4fs_internal(fd, NULL, mountpoint, NULL, 0, 0, 0, 1, 0, sehnd, 0, -1, NULL); |
Anatol Pomazau | 0349bd9 | 2012-01-11 15:12:27 -0800 | [diff] [blame] | 426 | close(fd); |
| 427 | |
| 428 | return status; |
Ken Sumrall | 983fb19 | 2011-01-19 17:15:42 -0800 | [diff] [blame] | 429 | } |
| 430 | |
Colin Cross | 5b89a4a | 2012-12-21 11:17:58 -0800 | [diff] [blame] | 431 | /* return a newly-malloc'd string that is a copy of str. The new string |
| 432 | is guaranteed to have a trailing slash. If absolute is true, the new string |
| 433 | is also guaranteed to have a leading slash. |
| 434 | */ |
| 435 | static char *canonicalize_slashes(const char *str, bool absolute) |
| 436 | { |
| 437 | char *ret; |
| 438 | int len = strlen(str); |
| 439 | int newlen = len; |
| 440 | char *ptr; |
| 441 | |
Benoit Fradin | 7b4448d | 2013-08-28 14:44:32 +0200 | [diff] [blame] | 442 | if (len == 0) { |
| 443 | if (absolute) |
| 444 | return strdup("/"); |
| 445 | else |
| 446 | return strdup(""); |
Colin Cross | 5b89a4a | 2012-12-21 11:17:58 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | if (str[0] != '/' && absolute) { |
| 450 | newlen++; |
| 451 | } |
| 452 | if (str[len - 1] != '/') { |
| 453 | newlen++; |
| 454 | } |
| 455 | ret = malloc(newlen + 1); |
| 456 | if (!ret) { |
| 457 | critical_error("malloc"); |
| 458 | } |
| 459 | |
| 460 | ptr = ret; |
| 461 | if (str[0] != '/' && absolute) { |
| 462 | *ptr++ = '/'; |
| 463 | } |
| 464 | |
| 465 | strcpy(ptr, str); |
| 466 | ptr += len; |
| 467 | |
| 468 | if (str[len - 1] != '/') { |
| 469 | *ptr++ = '/'; |
| 470 | } |
| 471 | |
| 472 | if (ptr != ret + newlen) { |
| 473 | critical_error("assertion failed\n"); |
| 474 | } |
| 475 | |
| 476 | *ptr = '\0'; |
| 477 | |
| 478 | return ret; |
| 479 | } |
| 480 | |
| 481 | static char *canonicalize_abs_slashes(const char *str) |
| 482 | { |
| 483 | return canonicalize_slashes(str, true); |
| 484 | } |
| 485 | |
| 486 | static char *canonicalize_rel_slashes(const char *str) |
| 487 | { |
| 488 | return canonicalize_slashes(str, false); |
| 489 | } |
| 490 | |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 491 | int make_ext4fs_internal(int fd, const char *_directory, |
Doug Zongker | 9526680 | 2013-12-05 15:51:28 -0800 | [diff] [blame] | 492 | const char *_mountpoint, fs_config_func_t fs_config_func, int gzip, |
Jeff Sharkey | 7538cc9 | 2015-04-06 22:29:04 -0700 | [diff] [blame] | 493 | int sparse, int crc, int wipe, int real_uuid, |
Doug Zongker | bec598e | 2014-08-12 11:35:37 -0700 | [diff] [blame] | 494 | struct selabel_handle *sehnd, int verbose, time_t fixed_time, |
| 495 | FILE* block_list_file) |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 496 | { |
Anatol Pomazau | 0349bd9 | 2012-01-11 15:12:27 -0800 | [diff] [blame] | 497 | u32 root_inode_num; |
| 498 | u16 root_mode; |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 499 | char *mountpoint; |
| 500 | char *directory = NULL; |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 501 | |
Ken Sumrall | 2ae7663 | 2011-03-23 22:08:53 -0700 | [diff] [blame] | 502 | if (setjmp(setjmp_env)) |
| 503 | return EXIT_FAILURE; /* Handle a call to longjmp() */ |
| 504 | |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 505 | if (_mountpoint == NULL) { |
| 506 | mountpoint = strdup(""); |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 507 | } else { |
Colin Cross | 5b89a4a | 2012-12-21 11:17:58 -0800 | [diff] [blame] | 508 | mountpoint = canonicalize_abs_slashes(_mountpoint); |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | if (_directory) { |
Colin Cross | 5b89a4a | 2012-12-21 11:17:58 -0800 | [diff] [blame] | 512 | directory = canonicalize_rel_slashes(_directory); |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 513 | } |
| 514 | |
Ken Sumrall | 435a8b6 | 2011-01-14 18:33:06 -0800 | [diff] [blame] | 515 | if (info.len <= 0) |
Anatol Pomazau | 0349bd9 | 2012-01-11 15:12:27 -0800 | [diff] [blame] | 516 | info.len = get_file_size(fd); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 517 | |
| 518 | if (info.len <= 0) { |
| 519 | fprintf(stderr, "Need size of filesystem\n"); |
Anatol Pomazau | 0349bd9 | 2012-01-11 15:12:27 -0800 | [diff] [blame] | 520 | return EXIT_FAILURE; |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 523 | if (info.block_size <= 0) |
| 524 | info.block_size = compute_block_size(); |
| 525 | |
Ken Sumrall | 88833a6 | 2011-07-13 17:27:07 -0700 | [diff] [blame] | 526 | /* Round down the filesystem length to be a multiple of the block size */ |
| 527 | info.len &= ~((u64)info.block_size - 1); |
| 528 | |
Colin Cross | e4b5ae8 | 2010-08-03 14:10:07 -0700 | [diff] [blame] | 529 | if (info.journal_blocks == 0) |
| 530 | info.journal_blocks = compute_journal_blocks(); |
| 531 | |
| 532 | if (info.no_journal == 0) |
| 533 | info.feat_compat = EXT4_FEATURE_COMPAT_HAS_JOURNAL; |
| 534 | else |
| 535 | info.journal_blocks = 0; |
| 536 | |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 537 | if (info.blocks_per_group <= 0) |
| 538 | info.blocks_per_group = compute_blocks_per_group(); |
| 539 | |
| 540 | if (info.inodes <= 0) |
| 541 | info.inodes = compute_inodes(); |
| 542 | |
| 543 | if (info.inode_size <= 0) |
| 544 | info.inode_size = 256; |
| 545 | |
| 546 | if (info.label == NULL) |
| 547 | info.label = ""; |
| 548 | |
| 549 | info.inodes_per_group = compute_inodes_per_group(); |
| 550 | |
| 551 | info.feat_compat |= |
Nick Kralevich | 4df62f3 | 2013-02-07 14:21:34 -0800 | [diff] [blame] | 552 | EXT4_FEATURE_COMPAT_RESIZE_INODE | |
| 553 | EXT4_FEATURE_COMPAT_EXT_ATTR; |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 554 | |
| 555 | info.feat_ro_compat |= |
| 556 | EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER | |
Colin Cross | 56497f2 | 2013-02-04 00:44:55 -0800 | [diff] [blame] | 557 | EXT4_FEATURE_RO_COMPAT_LARGE_FILE | |
| 558 | EXT4_FEATURE_RO_COMPAT_GDT_CSUM; |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 559 | |
| 560 | info.feat_incompat |= |
| 561 | EXT4_FEATURE_INCOMPAT_EXTENTS | |
| 562 | EXT4_FEATURE_INCOMPAT_FILETYPE; |
| 563 | |
| 564 | |
Colin Cross | 22742ce | 2010-12-22 16:01:52 -0800 | [diff] [blame] | 565 | info.bg_desc_reserve_blocks = compute_bg_desc_reserve_blocks(); |
| 566 | |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 567 | printf("Creating filesystem with parameters:\n"); |
Colin Cross | af07234 | 2014-01-23 13:19:27 -0800 | [diff] [blame] | 568 | printf(" Size: %"PRIu64"\n", info.len); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 569 | printf(" Block size: %d\n", info.block_size); |
| 570 | printf(" Blocks per group: %d\n", info.blocks_per_group); |
| 571 | printf(" Inodes per group: %d\n", info.inodes_per_group); |
| 572 | printf(" Inode size: %d\n", info.inode_size); |
Colin Cross | e4b5ae8 | 2010-08-03 14:10:07 -0700 | [diff] [blame] | 573 | printf(" Journal blocks: %d\n", info.journal_blocks); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 574 | printf(" Label: %s\n", info.label); |
| 575 | |
| 576 | ext4_create_fs_aux_info(); |
| 577 | |
Colin Cross | af07234 | 2014-01-23 13:19:27 -0800 | [diff] [blame] | 578 | printf(" Blocks: %"PRIu64"\n", aux_info.len_blocks); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 579 | printf(" Block groups: %d\n", aux_info.groups); |
Colin Cross | 22742ce | 2010-12-22 16:01:52 -0800 | [diff] [blame] | 580 | printf(" Reserved block group size: %d\n", info.bg_desc_reserve_blocks); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 581 | |
Colin Cross | 782879a | 2014-01-23 13:08:16 -0800 | [diff] [blame] | 582 | ext4_sparse_file = sparse_file_new(info.block_size, info.len); |
Colin Cross | f0ee37f | 2012-04-24 17:48:43 -0700 | [diff] [blame] | 583 | |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 584 | block_allocator_init(); |
| 585 | |
Jeff Sharkey | 7538cc9 | 2015-04-06 22:29:04 -0700 | [diff] [blame] | 586 | ext4_fill_in_sb(real_uuid); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 587 | |
| 588 | if (reserve_inodes(0, 10) == EXT4_ALLOCATE_FAILED) |
| 589 | error("failed to reserve first 10 inodes"); |
| 590 | |
| 591 | if (info.feat_compat & EXT4_FEATURE_COMPAT_HAS_JOURNAL) |
| 592 | ext4_create_journal_inode(); |
| 593 | |
| 594 | if (info.feat_compat & EXT4_FEATURE_COMPAT_RESIZE_INODE) |
| 595 | ext4_create_resize_inode(); |
| 596 | |
Raphael Moll | 4605b3f | 2012-02-03 23:02:33 -0800 | [diff] [blame] | 597 | #ifdef USE_MINGW |
| 598 | // Windows needs only 'create an empty fs image' functionality |
| 599 | assert(!directory); |
Stephen Smalley | 7907ac7 | 2014-04-25 14:57:55 -0400 | [diff] [blame] | 600 | root_inode_num = build_default_directory_structure(mountpoint, sehnd); |
Raphael Moll | 4605b3f | 2012-02-03 23:02:33 -0800 | [diff] [blame] | 601 | #else |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 602 | if (directory) |
Kenny Root | 2e5c523 | 2012-03-30 20:38:32 -0700 | [diff] [blame] | 603 | root_inode_num = build_directory_structure(directory, mountpoint, 0, |
Doug Zongker | bec598e | 2014-08-12 11:35:37 -0700 | [diff] [blame] | 604 | fs_config_func, sehnd, verbose, fixed_time); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 605 | else |
Stephen Smalley | 7907ac7 | 2014-04-25 14:57:55 -0400 | [diff] [blame] | 606 | root_inode_num = build_default_directory_structure(mountpoint, sehnd); |
Raphael Moll | 4605b3f | 2012-02-03 23:02:33 -0800 | [diff] [blame] | 607 | #endif |
Doug Zongker | 263eefd | 2010-06-29 17:23:14 -0700 | [diff] [blame] | 608 | |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 609 | root_mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
Colin Cross | de61f98 | 2010-08-04 15:06:09 -0700 | [diff] [blame] | 610 | inode_set_permissions(root_inode_num, root_mode, 0, 0, 0); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 611 | |
Kenny Root | 723f1c7 | 2012-10-10 11:13:13 -0700 | [diff] [blame] | 612 | #ifndef USE_MINGW |
Stephen Smalley | b4eca4b | 2012-01-13 09:00:56 -0500 | [diff] [blame] | 613 | if (sehnd) { |
Stephen Smalley | b4eca4b | 2012-01-13 09:00:56 -0500 | [diff] [blame] | 614 | char *secontext = NULL; |
Stephen Smalley | 6ece708 | 2012-02-09 14:19:24 -0500 | [diff] [blame] | 615 | |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 616 | if (selabel_lookup(sehnd, &secontext, mountpoint, S_IFDIR) < 0) { |
| 617 | error("cannot lookup security context for %s", mountpoint); |
Stephen Smalley | b4eca4b | 2012-01-13 09:00:56 -0500 | [diff] [blame] | 618 | } |
Robert Craig | 2929313 | 2013-01-30 12:54:46 -0500 | [diff] [blame] | 619 | if (secontext) { |
| 620 | if (verbose) { |
| 621 | printf("Labeling %s as %s\n", mountpoint, secontext); |
| 622 | } |
Stephen Smalley | b4eca4b | 2012-01-13 09:00:56 -0500 | [diff] [blame] | 623 | inode_set_selinux(root_inode_num, secontext); |
| 624 | } |
Stephen Smalley | b4eca4b | 2012-01-13 09:00:56 -0500 | [diff] [blame] | 625 | freecon(secontext); |
| 626 | } |
| 627 | #endif |
| 628 | |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 629 | ext4_update_free(); |
| 630 | |
Colin Cross | b781330 | 2010-12-22 18:41:13 -0800 | [diff] [blame] | 631 | ext4_queue_sb(); |
| 632 | |
Doug Zongker | bec598e | 2014-08-12 11:35:37 -0700 | [diff] [blame] | 633 | if (block_list_file) { |
| 634 | size_t dirlen = directory ? strlen(directory) : 0; |
| 635 | struct block_allocation* p = get_saved_allocation_chain(); |
| 636 | while (p) { |
| 637 | if (directory && strncmp(p->filename, directory, dirlen) == 0) { |
| 638 | // substitute mountpoint for the leading directory in the filename, in the output file |
| 639 | fprintf(block_list_file, "%s%s", mountpoint, p->filename + dirlen); |
| 640 | } else { |
| 641 | fprintf(block_list_file, "%s", p->filename); |
| 642 | } |
| 643 | print_blocks(block_list_file, p); |
| 644 | struct block_allocation* pn = p->next; |
| 645 | free_alloc(p); |
| 646 | p = pn; |
| 647 | } |
| 648 | } |
| 649 | |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 650 | printf("Created filesystem with %d/%d inodes and %d/%d blocks\n", |
| 651 | aux_info.sb->s_inodes_count - aux_info.sb->s_free_inodes_count, |
| 652 | aux_info.sb->s_inodes_count, |
| 653 | aux_info.sb->s_blocks_count_lo - aux_info.sb->s_free_blocks_count_lo, |
| 654 | aux_info.sb->s_blocks_count_lo); |
| 655 | |
David 'Digit' Turner | eb5fcc3 | 2014-06-12 20:54:50 +0200 | [diff] [blame] | 656 | if (wipe && WIPE_IS_SUPPORTED) { |
Colin Cross | dc5abee | 2012-04-23 23:20:48 -0700 | [diff] [blame] | 657 | wipe_block_device(fd, info.len); |
David 'Digit' Turner | eb5fcc3 | 2014-06-12 20:54:50 +0200 | [diff] [blame] | 658 | } |
Colin Cross | dc5abee | 2012-04-23 23:20:48 -0700 | [diff] [blame] | 659 | |
| 660 | write_ext4_image(fd, gzip, sparse, crc); |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 661 | |
Colin Cross | 782879a | 2014-01-23 13:08:16 -0800 | [diff] [blame] | 662 | sparse_file_destroy(ext4_sparse_file); |
| 663 | ext4_sparse_file = NULL; |
Colin Cross | f0ee37f | 2012-04-24 17:48:43 -0700 | [diff] [blame] | 664 | |
Colin Cross | a446014 | 2012-12-20 01:00:33 -0800 | [diff] [blame] | 665 | free(mountpoint); |
| 666 | free(directory); |
| 667 | |
Colin Cross | ec0a2e8 | 2010-06-11 14:21:37 -0700 | [diff] [blame] | 668 | return 0; |
| 669 | } |