diff options
-rw-r--r-- | contrib/android/perms.c | 16 | ||||
-rw-r--r-- | e2fsck/Android.bp | 1 | ||||
-rw-r--r-- | lib/ext2fs/Android.bp | 14 | ||||
-rw-r--r-- | lib/support/Android.bp | 1 | ||||
-rw-r--r-- | misc/Android.bp | 4 | ||||
-rw-r--r-- | misc/create_inode.c | 97 | ||||
-rw-r--r-- | resize/Android.bp | 1 |
7 files changed, 98 insertions, 36 deletions
diff --git a/contrib/android/perms.c b/contrib/android/perms.c index 3c42e597..9c5ec05b 100644 --- a/contrib/android/perms.c +++ b/contrib/android/perms.c @@ -81,9 +81,10 @@ static errcode_t set_selinux_xattr(ext2_filsys fs, ext2_ino_t ino, retval = selabel_lookup(params->sehnd, &secontext, params->filename, inode.i_mode); if (retval < 0) { - com_err(__func__, retval, + int saved_errno = errno; + com_err(__func__, errno, _("searching for label \"%s\""), params->filename); - return retval; + return saved_errno; } retval = ino_add_xattr(fs, ino, "security." XATTR_SELINUX_SUFFIX, @@ -187,7 +188,7 @@ static errcode_t set_timestamp(ext2_filsys fs, ext2_ino_t ino, } retval = lstat(src_filename, &stat); if (retval < 0) { - com_err(__func__, retval, + com_err(__func__, errno, _("while lstat file %s"), src_filename); goto end; } @@ -339,18 +340,19 @@ errcode_t android_configure_fs(ext2_filsys fs, char *src_dir, char *target_out, if (nopt > 0) { sehnd = selabel_open(SELABEL_CTX_FILE, seopts, nopt); if (!sehnd) { - com_err(__func__, -EINVAL, + int saved_errno = errno; + com_err(__func__, errno, _("while opening file contexts \"%s\""), seopts[0].value); - return -EINVAL; + return saved_errno; } } #else sehnd = selinux_android_file_context_handle(); if (!sehnd) { - com_err(__func__, -EINVAL, + com_err(__func__, EINVAL, _("while opening android file_contexts")); - return -EINVAL; + return EINVAL; } #endif diff --git a/e2fsck/Android.bp b/e2fsck/Android.bp index f3f70a0a..f3443127 100644 --- a/e2fsck/Android.bp +++ b/e2fsck/Android.bp @@ -44,6 +44,7 @@ cc_defaults { e2fsck_libs = [ "libext2fs", "libext2_blkid", + "libext2_com_err", "libext2_uuid", "libext2_quota", "libext2_e2p", diff --git a/lib/ext2fs/Android.bp b/lib/ext2fs/Android.bp index 5d10d3f7..e09ec3fb 100644 --- a/lib/ext2fs/Android.bp +++ b/lib/ext2fs/Android.bp @@ -91,24 +91,14 @@ cc_library { "test_io.c", ], shared_libs: [ + "libext2_com_err", "libsparse", "libz", ], - whole_static_libs: [ - "libext2_com_err" - ], cflags: ["-Wno-unused-parameter"], target: { - host: { - // Consider removing this library as a whole for the host. It is not - // in the android side. - whole_static_libs: ["libext2_com_err"], - }, android: { - shared_libs: [ - "libext2_com_err", - "libext2_uuid", - ], + shared_libs: [ "libext2_uuid" ], }, windows: { enabled: true, diff --git a/lib/support/Android.bp b/lib/support/Android.bp index 894d3357..2bc07b7f 100644 --- a/lib/support/Android.bp +++ b/lib/support/Android.bp @@ -21,6 +21,7 @@ cc_library { shared_libs: [ "libext2fs", "libext2_blkid", + "libext2_com_err", ], target: { diff --git a/misc/Android.bp b/misc/Android.bp index 301ce5d9..dea2f9fe 100644 --- a/misc/Android.bp +++ b/misc/Android.bp @@ -21,8 +21,9 @@ cc_library { ], cflags: ["-Wno-error=format-extra-args"], shared_libs: [ - "libext2_quota", "libext2fs", + "libext2_com_err", + "libext2_quota", ], system_shared_libs: ["libc", "libdl"], export_include_dirs: ["."], @@ -118,6 +119,7 @@ cc_defaults { tune2fs_libs = [ "libext2_blkid", + "libext2_com_err", "libext2_quota", "libext2_uuid", "libext2_e2p", diff --git a/misc/create_inode.c b/misc/create_inode.c index 05aa6363..21ff9f10 100644 --- a/misc/create_inode.c +++ b/misc/create_inode.c @@ -19,6 +19,7 @@ #include <sys/types.h> #include <unistd.h> #include <limits.h> /* for PATH_MAX */ +#include <dirent.h> /* for scandir() and alphasort() */ #if defined HAVE_SYS_XATTR_H #include <sys/xattr.h> #elif defined HAVE_ATTR_XATTR_H @@ -438,8 +439,8 @@ static errcode_t copy_file_chunk(ext2_filsys fs, int fd, ext2_file_t e2_file, ptr += blen; continue; } - err = ext2fs_file_lseek(e2_file, off + bpos, - EXT2_SEEK_SET, NULL); + err = ext2fs_file_llseek(e2_file, off + bpos, + EXT2_SEEK_SET, NULL); if (err) goto fail; while (blen > 0) { @@ -480,8 +481,8 @@ static errcode_t try_lseek_copy(ext2_filsys fs, int fd, struct stat *statbuf, if (hole < 0) return EXT2_ET_UNIMPLEMENTED; - data_blk = data & ~(fs->blocksize - 1); - hole_blk = (hole + (fs->blocksize - 1)) & ~(fs->blocksize - 1); + data_blk = data & ~(off_t)(fs->blocksize - 1); + hole_blk = (hole + (fs->blocksize - 1)) & ~(off_t)(fs->blocksize - 1); err = copy_file_chunk(fs, fd, e2_file, data_blk, hole_blk, buf, zerobuf); if (err) @@ -714,7 +715,69 @@ static errcode_t path_append(struct file_info *target, const char *file) return 0; } -/* Copy files from source_dir to fs */ +#ifdef _WIN32 +static int scandir(const char *dir_name, struct dirent ***name_list, + int (*filter)(const struct dirent*), + int (*compar)(const struct dirent**, const struct dirent**)) { + DIR *dir; + struct dirent *dent; + struct dirent **temp_list = NULL; + size_t temp_list_size = 0; // unit: num of dirent + size_t num_dent = 0; + + dir = opendir(dir_name); + if (dir == NULL) { + return -1; + } + + while ((dent = readdir(dir))) { + if (filter != NULL && !(*filter)(dent)) + continue; + + // re-allocate the list + if (num_dent == temp_list_size) { + size_t new_list_size = temp_list_size + 32; + struct dirent **new_list = (struct dirent**)realloc( + temp_list, new_list_size * sizeof(struct dirent*)); + if (new_list == NULL) { + goto out; + } + temp_list_size = new_list_size; + temp_list = new_list; + } + // add the copy of dirent to the list + temp_list[num_dent] = (struct dirent*)malloc((dent->d_reclen + 3) & ~3); + memcpy(temp_list[num_dent], dent, dent->d_reclen); + num_dent++; + } + + if (compar != NULL) { + qsort(temp_list, num_dent, sizeof(struct dirent*), + (int (*)(const void*, const void*))compar); + } + + // release the temp list + *name_list = temp_list; + temp_list = NULL; + +out: + if (temp_list != NULL) { + while (num_dent > 0) { + free(temp_list[--num_dent]); + } + free(temp_list); + num_dent = -1; + } + closedir(dir); + return num_dent; +} + +static int alphasort(const struct dirent **a, const struct dirent **b) { + return strcoll((*a)->d_name, (*b)->d_name); +} +#endif + +/* Copy files from source_dir to fs in alphabetical order */ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino, const char *source_dir, ext2_ino_t root, struct hdlinks_s *hdlinks, @@ -722,8 +785,7 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino, struct fs_ops_callbacks *fs_callbacks) { const char *name; - DIR *dh; - struct dirent *dent; + struct dirent **dent; struct stat st; char *ln_target = NULL; unsigned int save_inode; @@ -732,6 +794,7 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino, int read_cnt; int hdlink; size_t cur_dir_path_len; + int i, num_dents; if (chdir(source_dir) < 0) { retval = errno; @@ -741,24 +804,25 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino, return retval; } - if (!(dh = opendir("."))) { + num_dents = scandir(".", &dent, NULL, alphasort); + + if (num_dents < 0) { retval = errno; com_err(__func__, retval, - _("while opening directory \"%s\""), source_dir); + _("while scanning directory \"%s\""), source_dir); return retval; } - while ((dent = readdir(dh))) { - if ((!strcmp(dent->d_name, ".")) || - (!strcmp(dent->d_name, ".."))) + for (i = 0; i < num_dents; free(dent[i]), i++) { + name = dent[i]->d_name; + if ((!strcmp(name, ".")) || (!strcmp(name, ".."))) continue; - if (lstat(dent->d_name, &st)) { + if (lstat(name, &st)) { retval = errno; com_err(__func__, retval, _("while lstat \"%s\""), - dent->d_name); + name); goto out; } - name = dent->d_name; /* Check for hardlinks */ save_inode = 0; @@ -950,7 +1014,8 @@ find_lnf: } out: - closedir(dh); + for (; i < num_dents; free(dent[i]), i++); + free(dent); return retval; } diff --git a/resize/Android.bp b/resize/Android.bp index 22d2408d..d55e24c2 100644 --- a/resize/Android.bp +++ b/resize/Android.bp @@ -15,6 +15,7 @@ cc_binary { ], shared_libs: [ "libext2fs", + "libext2_com_err", "libext2_e2p", "libext2_uuid", "libext2_blkid", |