From e1a0a3e304229a625c37f0e845c0c9fff117c8c1 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 11 Feb 2000 05:00:19 +0000 Subject: [PATCH] Many files: chattr.1.in: lsattr.1.in: Change "version" to "version/generation number". chattr.1.in: Fix stupid file vs filesystem typo. tune2fs.c Fix spelling error (spare vs sparse). mke2fs.c (PRS): Add safety check to make sure the number of blocks doesn't exceed 32 bits on a 64 bit machine. chattr.c: Random cleanup; file-only variables are now static. Options for setting/clearings flags put into order, and #ifdef's removed (since we now use a built-in header file). Add error message if user tries to set and reset the same flag. lsattr.c: Random cleanup; file-only variables are now static. The -l "long" listing has been changed to look nicer. Options names have been renamed to be more descriptive. --- misc/ChangeLog | 22 ++++++++ misc/chattr.1.in | 2 +- misc/chattr.c | 133 +++++++++++++++++++--------------------------- misc/lsattr.1.in | 2 +- misc/lsattr.c | 51 ++++++++++-------- misc/mke2fs.c | 6 ++- misc/tune2fs.8.in | 2 +- misc/tune2fs.c | 4 +- 8 files changed, 115 insertions(+), 107 deletions(-) diff --git a/misc/ChangeLog b/misc/ChangeLog index 4a212770..5bcc6019 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,3 +1,25 @@ +2000-02-09 Theodore Ts'o + + * chattr.1.in: + * lsattr.1.in: Change "version" to "version/generation number". + + * chattr.1.in: Fix stupid file vs filesystem typo. + + * tune2fs.c Fix spelling error (spare vs sparse). + + * mke2fs.c (PRS): Add safety check to make sure the number of + blocks doesn't exceed 32 bits on a 64 bit machine. + + * chattr.c: Random cleanup; file-only variables are now static. + Options for setting/clearings flags put into order, and + #ifdef's removed (since we now use a built-in header + file). Add error message if user tries to set and reset + the same flag. + + * lsattr.c: Random cleanup; file-only variables are now static. + The -l "long" listing has been changed to look nicer. + Options names have been renamed to be more descriptive. + 2000-02-06 Theodore Ts'o * badblocks.c, chattr.c, dumpe2fs.c, e2label.c, findsuper.c, diff --git a/misc/chattr.1.in b/misc/chattr.1.in index 90e58aba..376cf815 100644 --- a/misc/chattr.1.in +++ b/misc/chattr.1.in @@ -40,7 +40,7 @@ ignored. Be verbose with chattr's output and print the program version. .TP .BI \-v " version" -Set the filesystem version. +Set the file's version/generation number. .SH ATTRIBUTES When a file with the 'A' attribute set is modified, its atime record is not modified. This avoids a certain amount of disk I/O for laptop diff --git a/misc/chattr.c b/misc/chattr.c index fd5210a6..80b2d36c 100644 --- a/misc/chattr.c +++ b/misc/chattr.c @@ -46,21 +46,21 @@ #include "../version.h" #include "nls-enable.h" -const char * program_name = "chattr"; +static const char * program_name = "chattr"; -int add = 0; -int rem = 0; -int set = 0; -int set_version = 0; +static int add = 0; +static int rem = 0; +static int set = 0; +static int set_version = 0; -unsigned long version; +static unsigned long version; -int recursive = 0; -int verbose = 0; +static int recursive = 0; +static int verbose = 0; -unsigned long af; -unsigned long rf; -unsigned long sf; +static unsigned long af; +static unsigned long rf; +static unsigned long sf; static void fatal_error(const char * fmt_string, int errcode) { @@ -82,6 +82,10 @@ static int decode_arg (int * i, int argc, char ** argv) for (p = &argv[*i][1]; *p; p++) switch (*p) { + case 'A': + rf |= EXT2_NOATIME_FL; + rem = 1; + break; case 'R': recursive = 1; break; @@ -92,34 +96,22 @@ static int decode_arg (int * i, int argc, char ** argv) case 'V': verbose = 1; break; -#ifdef EXT2_APPEND_FL case 'a': rf |= EXT2_APPEND_FL; rem = 1; break; -#endif -#ifdef EXT2_NOATIME_FL - case 'A': - rf |= EXT2_NOATIME_FL; - rem = 1; - break; -#endif case 'c': rf |= EXT2_COMPR_FL; rem = 1; break; -#ifdef EXT2_NODUMP_FL case 'd': rf |= EXT2_NODUMP_FL; rem = 1; break; -#endif -#ifdef EXT2_IMMUTABLE_FL case 'i': rf |= EXT2_IMMUTABLE_FL; rem = 1; break; -#endif case 's': rf |= EXT2_SECRM_FL; rem = 1; @@ -152,32 +144,24 @@ static int decode_arg (int * i, int argc, char ** argv) for (p = &argv[*i][1]; *p; p++) switch (*p) { - case 'S': - af |= EXT2_SYNC_FL; - break; -#ifdef EXT2_APPEND_FL - case 'a': - af |= EXT2_APPEND_FL; - break; -#endif -#ifdef EXT2_NOATIME_FL case 'A': af |= EXT2_NOATIME_FL; break; -#endif + case 'S': + af |= EXT2_SYNC_FL; + break; + case 'a': + af |= EXT2_APPEND_FL; + break; case 'c': af |= EXT2_COMPR_FL; break; -#ifdef EXT2_NODUMP_FL case 'd': af |= EXT2_NODUMP_FL; break; -#endif -#ifdef EXT2_IMMUTABLE_FL case 'i': af |= EXT2_IMMUTABLE_FL; break; -#endif case 's': af |= EXT2_SECRM_FL; break; @@ -193,32 +177,24 @@ static int decode_arg (int * i, int argc, char ** argv) for (p = &argv[*i][1]; *p; p++) switch (*p) { - case 'S': - sf |= EXT2_SYNC_FL; - break; -#ifdef EXT2_APPEND_FL - case 'a': - sf |= EXT2_APPEND_FL; - break; -#endif -#ifdef EXT2_NOATIME_FL case 'A': sf |= EXT2_NOATIME_FL; break; -#endif + case 'S': + sf |= EXT2_SYNC_FL; + break; + case 'a': + sf |= EXT2_APPEND_FL; + break; case 'c': sf |= EXT2_COMPR_FL; break; -#ifdef EXT2_NODUMP_FL case 'd': sf |= EXT2_NODUMP_FL; break; -#endif -#ifdef EXT2_IMMUTABLE_FL case 'i': sf |= EXT2_IMMUTABLE_FL; break; -#endif case 's': sf |= EXT2_SECRM_FL; break; @@ -243,37 +219,40 @@ static void change_attributes (const char * name) unsigned long flags; struct stat st; - if (lstat (name, &st) == -1) - { - com_err (program_name, errno, _("while stating %s"), name); + if (lstat (name, &st) == -1) { + com_err (program_name, errno, _("while trying to stat %s"), + name); return; } if (S_ISLNK(st.st_mode) && recursive) return; - if (set) - { - if (verbose) - { + + /* Don't try to open device files, fifos etc. We probably + ought to display an error if the file was explicitly given + on the command line (whether or not recursive was + requested). */ + if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode) && + !S_ISDIR(st.st_mode)) + return; + + if (set) { + if (verbose) { printf (_("Flags of %s set as "), name); print_flags (stdout, sf, 0); printf ("\n"); } if (fsetflags (name, sf) == -1) perror (name); - } - else - { + } else { if (fgetflags (name, &flags) == -1) com_err (program_name, errno, _("while reading flags on %s"), name); - else - { + else { if (rem) flags &= ~rf; if (add) flags |= af; - if (verbose) - { + if (verbose) { printf (_("Flags of %s set as "), name); print_flags (stdout, flags, 0); printf ("\n"); @@ -283,8 +262,7 @@ static void change_attributes (const char * name) _("while setting flags on %s"), name); } } - if (set_version) - { + if (set_version) { if (verbose) printf (_("Version of %s set as %lu\n"), name, version); if (fsetversion (name, version) == -1) @@ -292,13 +270,13 @@ static void change_attributes (const char * name) _("while setting version on %s"), name); } if (S_ISDIR(st.st_mode) && recursive) - iterate_on_dir (name, chattr_dir_proc, (void *) NULL); + iterate_on_dir (name, chattr_dir_proc, NULL); } -static int chattr_dir_proc (const char * dir_name, struct dirent * de, void * private) +static int chattr_dir_proc (const char * dir_name, struct dirent * de, + void * unused_private) { - if (strcmp (de->d_name, ".") && strcmp (de->d_name, "..")) - { + if (strcmp (de->d_name, ".") && strcmp (de->d_name, "..")) { char *path; path = malloc(strlen (dir_name) + 1 + strlen (de->d_name) + 1); @@ -325,8 +303,7 @@ int main (int argc, char ** argv) if (argc && *argv) program_name = *argv; i = 1; - while (i < argc && !end_arg) - { + while (i < argc && !end_arg) { if (decode_arg (&i, argc, argv) == EOF) end_arg = 1; else @@ -334,13 +311,15 @@ int main (int argc, char ** argv) } if (i >= argc) usage (); - if (set && (add || rem)) - { + if (set && (add || rem)) { fprintf (stderr, _("= is incompatible with - and +\n")); exit (1); } - if (!(add || rem || set || set_version)) - { + if ((rf & af) != 0) { + fprintf (stderr, "Can't both set and unset same flag.\n"); + exit (1); + } + if (!(add || rem || set || set_version)) { fprintf (stderr, _("Must use '-v', =, - or +\n")); exit (1); } diff --git a/misc/lsattr.1.in b/misc/lsattr.1.in index 97f0ab90..ef710bd9 100644 --- a/misc/lsattr.1.in +++ b/misc/lsattr.1.in @@ -28,7 +28,7 @@ List all files in directories, including files that start with `.'. List directories like other files, rather than listing their contents. .TP .B \-v -List the files version. +List the file's version/generation number. .SH AUTHOR .B lsattr has been written by Remy Card , the developer and maintainer diff --git a/misc/lsattr.c b/misc/lsattr.c index 4011d628..9b9dc54a 100644 --- a/misc/lsattr.c +++ b/misc/lsattr.c @@ -43,14 +43,14 @@ extern char *optarg; #include "../version.h" #include "nls-enable.h" -const char * program_name = "lsattr"; +static const char * program_name = "lsattr"; -int all = 0; -int d_opt = 0; -int l_opt = 0; -int recursive = 0; -int verbose = 0; -int v_opt = 0; +static int all = 0; +static int dirs_opt = 0; +static unsigned pf_options = 0; +static int recursive = 0; +static int verbose = 0; +static int generation_opt = 0; static void usage(void) { @@ -61,20 +61,26 @@ static void usage(void) static void list_attributes (const char * name) { unsigned long flags; - unsigned long version; + unsigned long generation; if (fgetflags (name, &flags) == -1) com_err (program_name, errno, _("While reading flags on %s"), name); - else if (fgetversion (name, &version) == -1) + else if (fgetversion (name, &generation) == -1) com_err (program_name, errno, _("While reading version on %s"), name); else { - if (v_opt) - printf ("%5lu ", version); - print_flags (stdout, flags, l_opt); - printf (" %s\n", name); + if (generation_opt) + printf ("%5lu ", generation); + if (pf_options & PFOPT_LONG) { + printf("%-28s ", name); + print_flags(stdout, flags, pf_options); + fputc('\n', stdout); + } else { + print_flags(stdout, flags, pf_options); + printf(" %s\n", name); + } } } @@ -85,11 +91,11 @@ static void lsattr_args (const char * name) struct stat st; if (lstat (name, &st) == -1) - com_err (program_name, errno, _("while stating %s"), name); - else - { - if (S_ISDIR(st.st_mode) && !d_opt) - iterate_on_dir (name, lsattr_dir_proc, (void *) NULL); + com_err (program_name, errno, _("while trying to stat %s"), + name); + else { + if (S_ISDIR(st.st_mode) && !dirs_opt) + iterate_on_dir (name, lsattr_dir_proc, NULL); else list_attributes (name); } @@ -112,8 +118,7 @@ static int lsattr_dir_proc (const char * dir_name, struct dirent * de, void * pr strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) { printf ("\n%s:\n", path); - iterate_on_dir (path, lsattr_dir_proc, - (void *) NULL); + iterate_on_dir (path, lsattr_dir_proc, NULL); printf ("\n"); } } @@ -147,13 +152,13 @@ int main (int argc, char ** argv) all = 1; break; case 'd': - d_opt = 1; + dirs_opt = 1; break; case 'l': - l_opt = 1; + pf_options = PFOPT_LONG; break; case 'v': - v_opt = 1; + generation_opt = 1; break; default: usage(); diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 4464da59..820b9d26 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -905,12 +905,14 @@ static void PRS(int argc, char *argv[]) device_name = argv[optind]; optind++; if (optind < argc) { - param.s_blocks_count = strtoul(argv[optind++], &tmp, 0); - if (*tmp) { + unsigned long tmp2 = strtoul(argv[optind++], &tmp, 0); + + if ((*tmp) || (tmp2 > 0xfffffffful)) { com_err(program_name, 0, _("bad blocks count - %s"), argv[optind - 1]); exit(1); } + param.s_blocks_count = tmp2; } if (optind < argc) usage(); diff --git a/misc/tune2fs.8.in b/misc/tune2fs.8.in index f28fcd05..d19cc49d 100644 --- a/misc/tune2fs.8.in +++ b/misc/tune2fs.8.in @@ -139,7 +139,7 @@ set or clear the indicated filesystem features (options) in the filesystem. .I Feature can be one of the following supported filesystem options: .IR sparse_super , -which cause the filesystem to use sparse superblocks, and +which will cause the filesystem to use sparse superblocks, and .IR filetype , which will cause the filesystem to store file type information in directory entries. After setting or clearing either filesystem feature, diff --git a/misc/tune2fs.c b/misc/tune2fs.c index 78b779a6..6903dc17 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -370,7 +370,7 @@ int main (int argc, char ** argv) if (sb->s_feature_ro_compat & EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) fprintf(stderr, _("\nThe filesystem already" - " has spare superblocks.\n")); + " has sparse superblocks.\n")); else { sb->s_feature_ro_compat |= EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER; @@ -390,7 +390,7 @@ int main (int argc, char ** argv) if (!(sb->s_feature_ro_compat & EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) fprintf(stderr, _("\nThe filesystem already" - " does not support spare superblocks.\n")); + " has sparse superblocks disabled.\n")); else { sb->s_feature_ro_compat &= ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;