summaryrefslogtreecommitdiff
path: root/ufs-fsck
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1995-10-18 17:15:56 +0000
committerMiles Bader <miles@gnu.org>1995-10-18 17:15:56 +0000
commitc064e7040d30925ce706e6193d91ee3d512d60f2 (patch)
tree7ac83188e31cdd31cd5e2bc572a5bb4a1baf6561 /ufs-fsck
parent6bf0d7402fe2df7172912328591b161de98b025f (diff)
(main): Only print section headers if not in preen mode.
(main): Use getopt to parse command line options. (usage): New function. (options): New variable. (lfname, lfmode): Variables moved here from setup.c. (lfname): Made into a char* so that we can change it. (lfmode): Get rid of IFDIR; it's added when necessary.
Diffstat (limited to 'ufs-fsck')
-rw-r--r--ufs-fsck/main.c90
1 files changed, 76 insertions, 14 deletions
diff --git a/ufs-fsck/main.c b/ufs-fsck/main.c
index 65f60453..5fbabc76 100644
--- a/ufs-fsck/main.c
+++ b/ufs-fsck/main.c
@@ -18,43 +18,105 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+#include <errno.h>
+#include <getopt.h>
+
#include "fsck.h"
-/* Pretty primitive, I'm afraid. */
+char *lfname = "lost+found";
+mode_t lfmode = 0755;
+
+#define USAGE "Usage: %s [OPTION...] DEVICE\n"
+
+static void
+usage(int status)
+{
+ if (status != 0)
+ fprintf(stderr, "Try `%s --help' for more information.\n",
+ program_invocation_name);
+ else
+ {
+ printf(USAGE, program_invocation_name);
+ printf("\
+\n\
+ -p, --preen Terse automatic mode\n\
+ -y, --yes Automatically answer yes to all questions\n\
+ -n, --no Automatically answer no to all questions\n\
+ -l, --lost+found=NAME The name of the lost+found directory in /\n\
+ -m, --lf-mode=MODE The name of the lost+found directory in /\n\
+ --help Give this usage message\n\
+");
+ }
+
+ exit(status);
+}
+
+#define SHORT_OPTIONS "pynlm&"
+
+static struct option options[] =
+{
+ {"preen", no_argument, 0, 'p'},
+ {"yes", no_argument, 0, 'y'},
+ {"no", no_argument, 0, 'n'},
+ {"lost+found", required_argument, 0, 'l'},
+ {"lf-mode", required_argument, 0, 'm'},
+ {"help", no_argument, 0, '&'},
+ {0, 0, 0, 0}
+};
int
main (int argc, char **argv)
{
- if (argc != 2)
+ int opt;
+
+ preen = nowrite = noquery = 0;
+
+ while ((opt = getopt_long (argc, argv, SHORT_OPTIONS, options, 0)) != EOF)
+ switch (opt)
+ {
+ case 'p': preen = 1; break;
+ case 'y': noquery = 1; break;
+ case 'n': nowrite = 1; break;
+ case 'l': lfname = optarg; break;
+ case 'm': lfmode = strtol (optarg, 0, 8); break;
+ case '&': usage(0);
+ default: usage(1);
+ }
+
+ if (argv[optind] == 0 || argv[optind + 1] != 0)
{
- fprintf (stderr, "Usage: %s device", argv[0]);
- exit (1);
+ fprintf(stderr, USAGE, program_invocation_name);
+ usage (1);
}
-
- preen = 0;
-
- if (!setup (argv[1]))
+
+ if (!setup (argv[optind]))
exit (1);
- printf ("** Phase 1 -- Check Blocks and Sizes\n");
+ if (!preen)
+ printf ("** Phase 1 -- Check Blocks and Sizes\n");
pass1 ();
if (duplist)
{
- printf ("** Phase 1b -- Rescan for More Duplicates\n");
+ if (!preen)
+ printf ("** Phase 1b -- Rescan for More Duplicates\n");
pass1b ();
}
- printf ("** Phase 2 -- Check Pathnames\n");
+ if (!preen)
+ printf ("** Phase 2 -- Check Pathnames\n");
pass2 ();
- printf ("** Phase 3 -- Check Connectivity\n");
+ if (!preen)
+ printf ("** Phase 3 -- Check Connectivity\n");
pass3 ();
- printf ("** Phase 4 -- Check Reference Counts\n");
+ if (!preen)
+ printf ("** Phase 4 -- Check Reference Counts\n");
pass4 ();
- printf ("** Phase 5 -- Check Cyl Groups\n");
+ if (!preen)
+ printf ("** Phase 5 -- Check Cyl Groups\n");
pass5 ();
if (fsmodified)