int main(int argc,char **argv) { int ctrl; int verify; struct stat st; char *progname, *p; progname = argv[0]; if ((p = strrchr(progname, '/')) != NULL) progname = p+1; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); if (argc == 2 && (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) { printf(_("%s from %s\n"), progname, util_linux_version); exit(0); } verify = 1; if (argc > 1 && argv[1][0] == '-') { if (argv[1][1] != 'n') usage(progname); verify = 0; argc--; argv++; } if (argc != 2) usage(progname); if (stat(argv[1],&st) < 0) PERROR(argv[1]); if (!S_ISBLK(st.st_mode)) { fprintf(stderr,_("%s: not a block device\n"),argv[1]); exit(1); /* do not test major - perhaps this was an USB floppy */ } if (access(argv[1],W_OK) < 0) PERROR(argv[1]); ctrl = open(argv[1],O_WRONLY); if (ctrl < 0) PERROR(argv[1]); if (ioctl(ctrl,FDGETPRM,(long) ¶m) < 0) PERROR(_("Could not determine current format type")); printf(_("%s-sided, %d tracks, %d sec/track. Total capacity %d kB.\n"), (param.head == 2) ? _("Double") : _("Single"), param.track, param.sect,param.size >> 1); format_disk(ctrl, argv[1]); close(ctrl); if (verify) verify_disk(argv[1]); return 0; }
main(int argc,char **argv) { int verify; char *name; name = argv[0]; verify = 1; if (argc > 1 && argv[1][0] == '-') { if (argv[1][1] != 'n') usage(name); verify = 0; argc--; argv++; } if (argc != 2) usage(name); if ((ctrl = open(argv[1],3)) < 0) PERROR(argv[1]); if (ioctl(ctrl,FDGETPRM,(int) ¶m) < 0) PERROR("ioctl(FDGETPRM)"); printf("%sle-sided, %d tracks, %d sec/track. Total capacity %d kB.\n", param.head ? "Doub" : "Sing",param.track,param.sect,param.size >> 1); format_disk(argv[1]); if (verify) verify_disk(argv[1]); }
int fdformat_main(int argc,char **argv) { int ctrl; int verify; struct stat st; struct floppy_struct param; if (argc < 2) { bb_show_usage(); } verify != bb_getopt_ulflags(argc, argv, "n"); argv += optind; if (stat(*argv,&st) < 0 || access(*argv,W_OK) < 0) { bb_perror_msg_and_die(*argv); } if (!S_ISBLK(st.st_mode)) { bb_error_msg_and_die("%s: not a block device",*argv); /* do not test major - perhaps this was an USB floppy */ } ctrl = bb_xopen(*argv,O_WRONLY); if (ioctl(ctrl,FDGETPRM,(long) ¶m) < 0) { bb_perror_msg_and_die("Could not determine current format type"); } printf("%s-sided, %d tracks, %d sec/track. Total capacity %d kB.\n", (param.head == 2) ? "Double" : "Single", param.track, param.sect,param.size >> 1); format_disk(ctrl, *argv, ¶m); close(ctrl); if (verify) { verify_disk(*argv, ¶m); } return EXIT_SUCCESS; }
int main(int argc, char **argv) { int ch; int ctrl; int verify = 1; struct stat st; static const struct option longopts[] = { {"no-verify", no_argument, NULL, 'n'}, {"version", no_argument, NULL, 'V'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0} }; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); while ((ch = getopt_long(argc, argv, "nVh", longopts, NULL)) != -1) switch (ch) { case 'n': verify = 0; break; case 'V': printf(_("%s from %s\n"), program_invocation_short_name, PACKAGE_STRING); exit(EXIT_SUCCESS); case 'h': usage(stdout); default: usage(stderr); } argc -= optind; argv += optind; if (argc < 1) usage(stderr); if (stat(argv[0], &st) < 0) err(EXIT_FAILURE, _("cannot stat file %s"), argv[0]); if (!S_ISBLK(st.st_mode)) /* do not test major - perhaps this was an USB floppy */ errx(EXIT_FAILURE, _("%s: not a block device"), argv[0]); if (access(argv[0], W_OK) < 0) err(EXIT_FAILURE, _("cannot access file %s"), argv[0]); ctrl = open(argv[0], O_WRONLY); if (ctrl < 0) err(EXIT_FAILURE, _("cannot open file %s"), argv[0]); if (ioctl(ctrl, FDGETPRM, (long)¶m) < 0) err(EXIT_FAILURE, _("Could not determine current format type")); printf(_("%s-sided, %d tracks, %d sec/track. Total capacity %d kB.\n"), (param.head == 2) ? _("Double") : _("Single"), param.track, param.sect, param.size >> 1); format_disk(ctrl); close(ctrl); if (verify) verify_disk(argv[0]); return EXIT_SUCCESS; }