diff options
author | Tom Marshall <tdm.code@gmail.com> | 2017-09-06 23:31:21 +0000 |
---|---|---|
committer | Rashed Abdel-Tawab <rashed@linux.com> | 2017-12-05 15:40:39 -0800 |
commit | 60ac66e515acfdf3c5b4ee49b74e3b76029436c5 (patch) | |
tree | 07d79da760a48375e9c7ba108df6e312d4abdb19 | |
parent | cc14070d645fb56fe909989fb6c4c719ecc68a8f (diff) | |
download | android_external_e2fsprogs-60ac66e515acfdf3c5b4ee49b74e3b76029436c5.tar.gz android_external_e2fsprogs-60ac66e515acfdf3c5b4ee49b74e3b76029436c5.tar.bz2 android_external_e2fsprogs-60ac66e515acfdf3c5b4ee49b74e3b76029436c5.zip |
e2fsprogs: Prepare for adding and using static libs
* Convert misc utils to inline. This needed to avoid duplicate
symbols when linking multiple e2fsprogs libs into an executable.
* Ensure macros are set properly in blkid_types.h. __bitwise and
__force are defined in uapi headers, so we must ensure they are
undefined in order to build against code that uses any libc or
kernel headers.
* Add BUILD_AS_LIB guards to main() and program_name where needed,
following the existing style in misc/tune2fs.c.
Change-Id: I1e82ccdce2cba86d79b454fa5810d99986012fcc
-rw-r--r-- | lib/blkid/blkid_types.h | 7 | ||||
-rw-r--r-- | misc/Android.bp | 2 | ||||
-rw-r--r-- | misc/Android.mk | 1 | ||||
-rw-r--r-- | misc/mke2fs.c | 8 | ||||
-rw-r--r-- | misc/tune2fs.c | 4 | ||||
-rw-r--r-- | misc/util.c | 291 | ||||
-rw-r--r-- | misc/util.h | 299 |
7 files changed, 302 insertions, 310 deletions
diff --git a/lib/blkid/blkid_types.h b/lib/blkid/blkid_types.h index 9c3f7149..8a8093ea 100644 --- a/lib/blkid/blkid_types.h +++ b/lib/blkid/blkid_types.h @@ -23,6 +23,13 @@ typedef __signed__ long long __s64; #ifndef EXT2_ENDIAN_H_ #define EXT2_ENDIAN_H_ +#ifdef __bitwise +#undef __bitwise +#endif +#ifdef __force +#undef __force +#endif + #ifdef __CHECKER__ #define __bitwise __attribute__((bitwise)) #define __force __attribute__((force)) diff --git a/misc/Android.bp b/misc/Android.bp index e2c3d11b..c4387369 100644 --- a/misc/Android.bp +++ b/misc/Android.bp @@ -34,7 +34,6 @@ cc_binary { srcs: [ "mke2fs.c", - "util.c", "mk_hugefiles.c", "default_profile.c", ], @@ -87,7 +86,6 @@ cc_defaults { name: "tune2fs-defaults", srcs: [ "tune2fs.c", - "util.c", ], cflags: [ "-W", diff --git a/misc/Android.mk b/misc/Android.mk index d3bb8207..b8d7544c 100644 --- a/misc/Android.mk +++ b/misc/Android.mk @@ -4,7 +4,6 @@ LOCAL_PATH := $(call my-dir) # Build statically linked mke2fs for recovery mke2fs_src_files := \ mke2fs.c \ - util.c \ mk_hugefiles.c \ default_profile.c \ create_inode.c \ diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 9ba16b91..2b7b6d3b 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -76,7 +76,11 @@ extern int optind; extern int isatty(int); extern FILE *fpopen(const char *cmd, const char *mode); +#ifndef BUILD_AS_LIB const char * program_name = "mke2fs"; +#else +extern const char *program_name; +#endif static const char * device_name /* = NULL */; /* Command line options */ @@ -2778,7 +2782,11 @@ try_user: return 0; } +#ifndef BUILD_AS_LIB int main (int argc, char *argv[]) +#else +int mke2fs_main(int argc, char *argv[]) +#endif { errcode_t retval = 0; ext2_filsys fs; diff --git a/misc/tune2fs.c b/misc/tune2fs.c index 09e65baf..dcaafc1c 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -72,7 +72,11 @@ extern int optind; extern int ask_yn(const char *string, int def); +#ifndef BUILD_AS_LIB const char *program_name = "tune2fs"; +#else +extern const char *program_name; +#endif char *device_name; char *new_label, *new_last_mounted, *new_UUID; char *io_options; diff --git a/misc/util.c b/misc/util.c deleted file mode 100644 index fabc9d17..00000000 --- a/misc/util.c +++ /dev/null @@ -1,291 +0,0 @@ -/* - * util.c --- helper functions used by tune2fs and mke2fs - * - * Copyright 1995, 1996, 1997, 1998, 1999, 2000 by Theodore Ts'o. - * - * %Begin-Header% - * This file may be redistributed under the terms of the GNU Public - * License. - * %End-Header% - */ - -#ifndef _LARGEFILE_SOURCE -#define _LARGEFILE_SOURCE -#endif -#ifndef _LARGEFILE64_SOURCE -#define _LARGEFILE64_SOURCE -#endif - -#include "config.h" -#include <fcntl.h> -#include <setjmp.h> -#include <signal.h> -#include <stdio.h> -#include <string.h> -#ifdef HAVE_ERRNO_H -#include <errno.h> -#endif -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#ifdef HAVE_LINUX_MAJOR_H -#include <linux/major.h> -#endif -#include <sys/types.h> -#ifdef HAVE_SYS_STAT_H -#include <sys/stat.h> -#endif -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <time.h> - -#include "et/com_err.h" -#include "e2p/e2p.h" -#include "ext2fs/ext2_fs.h" -#include "ext2fs/ext2fs.h" -#include "support/nls-enable.h" -#include "blkid/blkid.h" -#include "util.h" - -char *journal_location_string = NULL; - -#ifndef HAVE_STRCASECMP -int strcasecmp (char *s1, char *s2) -{ - while (*s1 && *s2) { - int ch1 = *s1++, ch2 = *s2++; - if (isupper (ch1)) - ch1 = tolower (ch1); - if (isupper (ch2)) - ch2 = tolower (ch2); - if (ch1 != ch2) - return ch1 - ch2; - } - return *s1 ? 1 : *s2 ? -1 : 0; -} -#endif - -/* - * Given argv[0], return the program name. - */ -char *get_progname(char *argv_zero) -{ - char *cp; - - cp = strrchr(argv_zero, '/'); - if (!cp ) - return argv_zero; - else - return cp+1; -} - -static jmp_buf alarm_env; - -static void alarm_signal(int signal EXT2FS_ATTR((unused))) -{ - longjmp(alarm_env, 1); -} - -void proceed_question(int delay) -{ - char buf[256]; - const char *short_yes = _("yY"); - - fflush(stdout); - fflush(stderr); - if (delay > 0) { - if (setjmp(alarm_env)) { - signal(SIGALRM, SIG_IGN); - printf("%s", _("<proceeding>\n")); - return; - } - signal(SIGALRM, alarm_signal); - printf(_("Proceed anyway (or wait %d seconds) ? (y,n) "), - delay); - alarm(delay); - } else - fputs(_("Proceed anyway? (y,n) "), stdout); - buf[0] = 0; - if (!fgets(buf, sizeof(buf), stdin) || - strchr(short_yes, buf[0]) == 0) { - putc('\n', stdout); - exit(1); - } - signal(SIGALRM, SIG_IGN); -} - -void check_mount(const char *device, int force, const char *type) -{ - errcode_t retval; - int mount_flags; - - retval = ext2fs_check_if_mounted(device, &mount_flags); - if (retval) { - com_err("ext2fs_check_if_mount", retval, - _("while determining whether %s is mounted."), - device); - return; - } - if (mount_flags & EXT2_MF_MOUNTED) { - fprintf(stderr, _("%s is mounted; "), device); - if (force >= 2) { - fputs(_("mke2fs forced anyway. Hope /etc/mtab is " - "incorrect.\n"), stderr); - return; - } - abort_mke2fs: - fprintf(stderr, _("will not make a %s here!\n"), type); - exit(1); - } - if (mount_flags & EXT2_MF_BUSY) { - fprintf(stderr, _("%s is apparently in use by the system; "), - device); - if (force >= 2) { - fputs(_("mke2fs forced anyway.\n"), stderr); - return; - } - goto abort_mke2fs; - } -} - -void parse_journal_opts(const char *opts) -{ - char *buf, *token, *next, *p, *arg; - int len; - int journal_usage = 0; - - len = strlen(opts); - buf = malloc(len+1); - if (!buf) { - fputs(_("Couldn't allocate memory to parse journal " - "options!\n"), stderr); - exit(1); - } - strcpy(buf, opts); - for (token = buf; token && *token; token = next) { - p = strchr(token, ','); - next = 0; - if (p) { - *p = 0; - next = p+1; - } - arg = strchr(token, '='); - if (arg) { - *arg = 0; - arg++; - } -#if 0 - printf("Journal option=%s, argument=%s\n", token, - arg ? arg : "NONE"); -#endif - if (strcmp(token, "device") == 0) { - journal_device = blkid_get_devname(NULL, arg, NULL); - if (!journal_device) { - if (arg) - fprintf(stderr, _("\nCould not find " - "journal device matching %s\n"), - arg); - journal_usage++; - continue; - } - } else if (strcmp(token, "size") == 0) { - if (!arg) { - journal_usage++; - continue; - } - journal_size = strtoul(arg, &p, 0); - if (*p) - journal_usage++; - } else if (!strcmp(token, "location")) { - if (!arg) { - journal_usage++; - continue; - } - journal_location_string = strdup(arg); - } else if (strcmp(token, "v1_superblock") == 0) { - journal_flags |= EXT2_MKJOURNAL_V1_SUPER; - continue; - } else - journal_usage++; - } - if (journal_usage) { - fputs(_("\nBad journal options specified.\n\n" - "Journal options are separated by commas, " - "and may take an argument which\n" - "\tis set off by an equals ('=') sign.\n\n" - "Valid journal options are:\n" - "\tsize=<journal size in megabytes>\n" - "\tdevice=<journal device>\n" - "\tlocation=<journal location>\n\n" - "The journal size must be between " - "1024 and 10240000 filesystem blocks.\n\n"), stderr); - free(buf); - exit(1); - } - free(buf); -} - -/* - * Determine the number of journal blocks to use, either via - * user-specified # of megabytes, or via some intelligently selected - * defaults. - * - * Find a reasonable journal file size (in blocks) given the number of blocks - * in the filesystem. For very small filesystems, it is not reasonable to - * have a journal that fills more than half of the filesystem. - */ -unsigned int figure_journal_size(int size, ext2_filsys fs) -{ - int j_blocks; - - j_blocks = ext2fs_default_journal_size(ext2fs_blocks_count(fs->super)); - if (j_blocks < 0) { - fputs(_("\nFilesystem too small for a journal\n"), stderr); - return 0; - } - - if (size > 0) { - j_blocks = size * 1024 / (fs->blocksize / 1024); - if (j_blocks < 1024 || j_blocks > 10240000) { - fprintf(stderr, _("\nThe requested journal " - "size is %d blocks; it must be\n" - "between 1024 and 10240000 blocks. " - "Aborting.\n"), - j_blocks); - exit(1); - } - if ((unsigned) j_blocks > ext2fs_free_blocks_count(fs->super) / 2) { - fputs(_("\nJournal size too big for filesystem.\n"), - stderr); - exit(1); - } - } - return j_blocks; -} - -void print_check_message(int mnt, unsigned int check) -{ - if (mnt < 0) - mnt = 0; - if (!mnt && !check) - return; - printf(_("This filesystem will be automatically " - "checked every %d mounts or\n" - "%g days, whichever comes first. " - "Use tune2fs -c or -i to override.\n"), - mnt, ((double) check) / (3600 * 24)); -} - -void dump_mmp_msg(struct mmp_struct *mmp, const char *msg) -{ - - if (msg) - printf("MMP check failed: %s\n", msg); - if (mmp) { - time_t t = mmp->mmp_time; - - printf("MMP error info: last update: %s node: %s device: %s\n", - ctime(&t), mmp->mmp_nodename, mmp->mmp_bdevname); - } -} diff --git a/misc/util.h b/misc/util.h index 49b4b9c1..5362860d 100644 --- a/misc/util.h +++ b/misc/util.h @@ -1,8 +1,7 @@ /* - * util.h --- header file defining prototypes for helper functions - * used by tune2fs and mke2fs + * util.c --- helper functions used by tune2fs and mke2fs * - * Copyright 2000 by Theodore Ts'o. + * Copyright 1995, 1996, 1997, 1998, 1999, 2000 by Theodore Ts'o. * * %Begin-Header% * This file may be redistributed under the terms of the GNU Public @@ -10,18 +9,286 @@ * %End-Header% */ -extern int journal_size; -extern int journal_flags; -extern char *journal_device; -extern char *journal_location_string; +#ifndef _LARGEFILE_SOURCE +#define _LARGEFILE_SOURCE +#endif +#ifndef _LARGEFILE64_SOURCE +#define _LARGEFILE64_SOURCE +#endif + +#include "config.h" +#include <fcntl.h> +#include <setjmp.h> +#include <signal.h> +#include <stdio.h> +#include <string.h> +#ifdef HAVE_ERRNO_H +#include <errno.h> +#endif +#if HAVE_UNISTD_H +#include <unistd.h> +#endif +#ifdef HAVE_LINUX_MAJOR_H +#include <linux/major.h> +#endif +#include <sys/types.h> +#ifdef HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif +#include <time.h> + +#include "et/com_err.h" +#include "e2p/e2p.h" +#include "ext2fs/ext2_fs.h" +#include "ext2fs/ext2fs.h" +#include "support/nls-enable.h" +#include "blkid/blkid.h" + +extern int journal_size; +extern int journal_flags; +extern char *journal_device; + +static char *journal_location_string = NULL; #ifndef HAVE_STRCASECMP -extern int strcasecmp (char *s1, char *s2); -#endif -extern char *get_progname(char *argv_zero); -extern void proceed_question(int delay); -extern void parse_journal_opts(const char *opts); -extern void check_mount(const char *device, int force, const char *type); -extern unsigned int figure_journal_size(int size, ext2_filsys fs); -extern void print_check_message(int, unsigned int); -extern void dump_mmp_msg(struct mmp_struct *mmp, const char *msg); +int strcasecmp (char *s1, char *s2) +{ + while (*s1 && *s2) { + int ch1 = *s1++, ch2 = *s2++; + if (isupper (ch1)) + ch1 = tolower (ch1); + if (isupper (ch2)) + ch2 = tolower (ch2); + if (ch1 != ch2) + return ch1 - ch2; + } + return *s1 ? 1 : *s2 ? -1 : 0; +} +#endif + +/* + * Given argv[0], return the program name. + */ +static inline char *get_progname(char *argv_zero) +{ + char *cp; + + cp = strrchr(argv_zero, '/'); + if (!cp ) + return argv_zero; + else + return cp+1; +} + +static jmp_buf alarm_env; + +static void alarm_signal(int signal EXT2FS_ATTR((unused))) +{ + longjmp(alarm_env, 1); +} + +static inline void proceed_question(int delay) +{ + char buf[256]; + const char *short_yes = _("yY"); + + fflush(stdout); + fflush(stderr); + if (delay > 0) { + if (setjmp(alarm_env)) { + signal(SIGALRM, SIG_IGN); + printf("%s", _("<proceeding>\n")); + return; + } + signal(SIGALRM, alarm_signal); + printf(_("Proceed anyway (or wait %d seconds) ? (y,n) "), + delay); + alarm(delay); + } else + fputs(_("Proceed anyway? (y,n) "), stdout); + buf[0] = 0; + if (!fgets(buf, sizeof(buf), stdin) || + strchr(short_yes, buf[0]) == 0) { + putc('\n', stdout); + exit(1); + } + signal(SIGALRM, SIG_IGN); +} + +static inline void check_mount(const char *device, int force, const char *type) +{ + errcode_t retval; + int mount_flags; + + retval = ext2fs_check_if_mounted(device, &mount_flags); + if (retval) { + com_err("ext2fs_check_if_mount", retval, + _("while determining whether %s is mounted."), + device); + return; + } + if (mount_flags & EXT2_MF_MOUNTED) { + fprintf(stderr, _("%s is mounted; "), device); + if (force >= 2) { + fputs(_("mke2fs forced anyway. Hope /etc/mtab is " + "incorrect.\n"), stderr); + return; + } + abort_mke2fs: + fprintf(stderr, _("will not make a %s here!\n"), type); + exit(1); + } + if (mount_flags & EXT2_MF_BUSY) { + fprintf(stderr, _("%s is apparently in use by the system; "), + device); + if (force >= 2) { + fputs(_("mke2fs forced anyway.\n"), stderr); + return; + } + goto abort_mke2fs; + } +} + +static inline void parse_journal_opts(const char *opts) +{ + char *buf, *token, *next, *p, *arg; + int len; + int journal_usage = 0; + + len = strlen(opts); + buf = malloc(len+1); + if (!buf) { + fputs(_("Couldn't allocate memory to parse journal " + "options!\n"), stderr); + exit(1); + } + strcpy(buf, opts); + for (token = buf; token && *token; token = next) { + p = strchr(token, ','); + next = 0; + if (p) { + *p = 0; + next = p+1; + } + arg = strchr(token, '='); + if (arg) { + *arg = 0; + arg++; + } +#if 0 + printf("Journal option=%s, argument=%s\n", token, + arg ? arg : "NONE"); +#endif + if (strcmp(token, "device") == 0) { + journal_device = blkid_get_devname(NULL, arg, NULL); + if (!journal_device) { + if (arg) + fprintf(stderr, _("\nCould not find " + "journal device matching %s\n"), + arg); + journal_usage++; + continue; + } + } else if (strcmp(token, "size") == 0) { + if (!arg) { + journal_usage++; + continue; + } + journal_size = strtoul(arg, &p, 0); + if (*p) + journal_usage++; + } else if (!strcmp(token, "location")) { + if (!arg) { + journal_usage++; + continue; + } + journal_location_string = strdup(arg); + } else if (strcmp(token, "v1_superblock") == 0) { + journal_flags |= EXT2_MKJOURNAL_V1_SUPER; + continue; + } else + journal_usage++; + } + if (journal_usage) { + fputs(_("\nBad journal options specified.\n\n" + "Journal options are separated by commas, " + "and may take an argument which\n" + "\tis set off by an equals ('=') sign.\n\n" + "Valid journal options are:\n" + "\tsize=<journal size in megabytes>\n" + "\tdevice=<journal device>\n" + "\tlocation=<journal location>\n\n" + "The journal size must be between " + "1024 and 10240000 filesystem blocks.\n\n"), stderr); + free(buf); + exit(1); + } + free(buf); +} + +/* + * Determine the number of journal blocks to use, either via + * user-specified # of megabytes, or via some intelligently selected + * defaults. + * + * Find a reasonable journal file size (in blocks) given the number of blocks + * in the filesystem. For very small filesystems, it is not reasonable to + * have a journal that fills more than half of the filesystem. + */ +static inline unsigned int figure_journal_size(int size, ext2_filsys fs) +{ + int j_blocks; + + j_blocks = ext2fs_default_journal_size(ext2fs_blocks_count(fs->super)); + if (j_blocks < 0) { + fputs(_("\nFilesystem too small for a journal\n"), stderr); + return 0; + } + + if (size > 0) { + j_blocks = size * 1024 / (fs->blocksize / 1024); + if (j_blocks < 1024 || j_blocks > 10240000) { + fprintf(stderr, _("\nThe requested journal " + "size is %d blocks; it must be\n" + "between 1024 and 10240000 blocks. " + "Aborting.\n"), + j_blocks); + exit(1); + } + if ((unsigned) j_blocks > ext2fs_free_blocks_count(fs->super) / 2) { + fputs(_("\nJournal size too big for filesystem.\n"), + stderr); + exit(1); + } + } + return j_blocks; +} + +static inline void print_check_message(int mnt, unsigned int check) +{ + if (mnt < 0) + mnt = 0; + if (!mnt && !check) + return; + printf(_("This filesystem will be automatically " + "checked every %d mounts or\n" + "%g days, whichever comes first. " + "Use tune2fs -c or -i to override.\n"), + mnt, ((double) check) / (3600 * 24)); +} + +static inline void dump_mmp_msg(struct mmp_struct *mmp, const char *msg) +{ + + if (msg) + printf("MMP check failed: %s\n", msg); + if (mmp) { + time_t t = mmp->mmp_time; + + printf("MMP error info: last update: %s node: %s device: %s\n", + ctime(&t), mmp->mmp_nodename, mmp->mmp_bdevname); + } +} |