int main(int argc, char **argv) { e2fsck_t ctx; struct string s; putenv("TZ=EST+5:00"); e2fsck_allocate_context(&ctx); expand_logfn(ctx, "e2fsck-%N.%h.%u.%D-%T", &s); printf("%s\n", s.s); free(s.s); expand_logfn(ctx, "e2fsck-%N.%h.%u.%Y%m%d-%H%M%S", &s); printf("%s\n", s.s); free(s.s); return 0; }
static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx) { int flush = 0; int c, fd; #ifdef MTRACE extern void *mallwatch; #endif e2fsck_t ctx; errcode_t retval; #ifdef HAVE_SIGNAL_H struct sigaction sa; #endif char *extended_opts = 0; char *cp; int res; /* result of sscanf */ #ifdef CONFIG_JBD_DEBUG char *jbd_debug; #endif retval = e2fsck_allocate_context(&ctx); if (retval) return retval; *ret_ctx = ctx; setvbuf(stdout, NULL, _IONBF, BUFSIZ); setvbuf(stderr, NULL, _IONBF, BUFSIZ); if (isatty(0) && isatty(1)) { ctx->interactive = 1; } else { ctx->start_meta[0] = '\001'; ctx->stop_meta[0] = '\002'; } memset(bar, '=', sizeof(bar)-1); memset(spaces, ' ', sizeof(spaces)-1); add_error_table(&et_ext2_error_table); add_error_table(&et_prof_error_table); blkid_get_cache(&ctx->blkid, NULL); if (argc && *argv) ctx->program_name = *argv; else ctx->program_name = "e2fsck"; while ((c = getopt (argc, argv, "panyrcC:B:dE:fvtFVM:b:I:j:P:l:L:N:SsDk")) != EOF) switch (c) { case 'C': ctx->progress = e2fsck_update_progress; res = sscanf(optarg, "%d", &ctx->progress_fd); if (res != 1) goto sscanf_err; if (ctx->progress_fd < 0) { ctx->progress = 0; ctx->progress_fd = ctx->progress_fd * -1; } if (!ctx->progress_fd) break; /* Validate the file descriptor to avoid disasters */ fd = dup(ctx->progress_fd); if (fd < 0) { fprintf(stderr, _("Error validating file descriptor %d: %s\n"), ctx->progress_fd, error_message(errno)); fatal_error(ctx, _("Invalid completion information file descriptor")); } else close(fd); break; case 'D': ctx->options |= E2F_OPT_COMPRESS_DIRS; break; case 'E': extended_opts = optarg; break; case 'p': case 'a': if (ctx->options & (E2F_OPT_YES|E2F_OPT_NO)) { conflict_opt: fatal_error(ctx, _("Only one of the options -p/-a, -n or -y may be specified.")); } ctx->options |= E2F_OPT_PREEN; break; case 'n': if (ctx->options & (E2F_OPT_YES|E2F_OPT_PREEN)) goto conflict_opt; ctx->options |= E2F_OPT_NO; break; case 'y': if (ctx->options & (E2F_OPT_PREEN|E2F_OPT_NO)) goto conflict_opt; ctx->options |= E2F_OPT_YES; break; case 't': #ifdef RESOURCE_TRACK if (ctx->options & E2F_OPT_TIME) ctx->options |= E2F_OPT_TIME2; else ctx->options |= E2F_OPT_TIME; #else fprintf(stderr, _("The -t option is not " "supported on this version of e2fsck.\n")); #endif break; case 'c': if (cflag++) ctx->options |= E2F_OPT_WRITECHECK; ctx->options |= E2F_OPT_CHECKBLOCKS; break; case 'r': /* What we do by default, anyway! */ break; case 'b': res = sscanf(optarg, "%u", &ctx->use_superblock); if (res != 1) goto sscanf_err; ctx->flags |= E2F_FLAG_SB_SPECIFIED; break; case 'B': ctx->blocksize = atoi(optarg); break; case 'I': res = sscanf(optarg, "%d", &ctx->inode_buffer_blocks); if (res != 1) goto sscanf_err; break; case 'j': ctx->journal_name = blkid_get_devname(ctx->blkid, optarg, NULL); if (!ctx->journal_name) { com_err(ctx->program_name, 0, _("Unable to resolve '%s'"), optarg); fatal_error(ctx, 0); } break; case 'P': res = sscanf(optarg, "%d", &ctx->process_inode_size); if (res != 1) goto sscanf_err; break; case 'L': replace_bad_blocks++; case 'l': bad_blocks_file = string_copy(ctx, optarg, 0); break; case 'd': ctx->options |= E2F_OPT_DEBUG; break; case 'f': ctx->options |= E2F_OPT_FORCE; break; case 'F': flush = 1; break; case 'v': verbose = 1; break; case 'V': show_version_only = 1; break; #ifdef MTRACE case 'M': mallwatch = (void *) strtol(optarg, NULL, 0); break; #endif case 'N': ctx->device_name = string_copy(ctx, optarg, 0); break; case 'k': keep_bad_blocks++; break; default: usage(ctx); } if (show_version_only) return 0; if (optind != argc - 1) usage(ctx); if ((ctx->options & E2F_OPT_NO) && (ctx->options & E2F_OPT_COMPRESS_DIRS)) { com_err(ctx->program_name, 0, _("The -n and -D options are incompatible.")); fatal_error(ctx, 0); } if ((ctx->options & E2F_OPT_NO) && cflag) { com_err(ctx->program_name, 0, _("The -n and -c options are incompatible.")); fatal_error(ctx, 0); } if ((ctx->options & E2F_OPT_NO) && bad_blocks_file) { com_err(ctx->program_name, 0, _("The -n and -l/-L options are incompatible.")); fatal_error(ctx, 0); } if (ctx->options & E2F_OPT_NO) ctx->options |= E2F_OPT_READONLY; ctx->io_options = strchr(argv[optind], '?'); if (ctx->io_options) *ctx->io_options++ = 0; ctx->filesystem_name = blkid_get_devname(ctx->blkid, argv[optind], 0); if (!ctx->filesystem_name) { com_err(ctx->program_name, 0, _("Unable to resolve '%s'"), argv[optind]); fatal_error(ctx, 0); } if (extended_opts) parse_extended_opts(ctx, extended_opts); if ((cp = getenv("E2FSCK_CONFIG")) != NULL) config_fn[0] = cp; profile_set_syntax_err_cb(syntax_err_report); profile_init(config_fn, &ctx->profile); if (flush) { fd = open(ctx->filesystem_name, O_RDONLY, 0); if (fd < 0) { com_err("open", errno, _("while opening %s for flushing"), ctx->filesystem_name); fatal_error(ctx, 0); } if ((retval = ext2fs_sync_device(fd, 1))) { com_err("ext2fs_sync_device", retval, _("while trying to flush %s"), ctx->filesystem_name); fatal_error(ctx, 0); } close(fd); } if (cflag && bad_blocks_file) { fprintf(stderr, _("The -c and the -l/-L options may " "not be both used at the same time.\n")); exit(FSCK_USAGE); } #ifdef HAVE_SIGNAL_H /* * Set up signal action */ memset(&sa, 0, sizeof(struct sigaction)); sa.sa_handler = signal_cancel; sigaction(SIGINT, &sa, 0); sigaction(SIGTERM, &sa, 0); #ifdef SA_RESTART sa.sa_flags = SA_RESTART; #endif e2fsck_global_ctx = ctx; sa.sa_handler = signal_progress_on; sigaction(SIGUSR1, &sa, 0); sa.sa_handler = signal_progress_off; sigaction(SIGUSR2, &sa, 0); #endif /* Update our PATH to include /sbin if we need to run badblocks */ if (cflag) { char *oldpath = getenv("PATH"); char *newpath; int len = sizeof(PATH_SET) + 1; if (oldpath) len += strlen(oldpath); newpath = malloc(len); if (!newpath) fatal_error(ctx, "Couldn't malloc() newpath"); strcpy(newpath, PATH_SET); if (oldpath) { strcat(newpath, ":"); strcat(newpath, oldpath); } putenv(newpath); } #ifdef CONFIG_JBD_DEBUG jbd_debug = getenv("E2FSCK_JBD_DEBUG"); if (jbd_debug) { res = sscanf(jbd_debug, "%d", &journal_enable_debug); if (res != 1) { fprintf(stderr, _("E2FSCK_JBD_DEBUG \"%s\" not an integer\n\n"), jbd_debug); exit (1); } } #endif return 0; sscanf_err: fprintf(stderr, _("\nInvalid non-numeric argument to -%c (\"%s\")\n\n"), c, optarg); exit (1); }