1 |
/* vi: set sw=4 ts=4: */ |
/* vi: set sw=4 ts=4: */ |
2 |
/* fdformat.c - Low-level formats a floppy disk - Werner Almesberger */ |
/* fdformat.c - Low-level formats a floppy disk - Werner Almesberger */ |
3 |
|
|
4 |
/* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL> |
/* 5 July 2003 -- modified for Busybox by Erik Andersen |
|
* - added Native Language Support |
|
|
* 1999-03-20 Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
|
|
* - more i18n/nls translatable strings marked |
|
|
* |
|
|
* 5 July 2003 -- modified for Busybox by Erik Andersen |
|
5 |
*/ |
*/ |
6 |
|
|
7 |
#include "busybox.h" |
#include "libbb.h" |
8 |
|
|
9 |
|
|
10 |
/* Stuff extracted from linux/fd.h */ |
/* Stuff extracted from linux/fd.h */ |
40 |
#define FDGETPRM _IOR(2, 0x04, struct floppy_struct) |
#define FDGETPRM _IOR(2, 0x04, struct floppy_struct) |
41 |
#define FD_FILL_BYTE 0xF6 /* format fill byte. */ |
#define FD_FILL_BYTE 0xF6 /* format fill byte. */ |
42 |
|
|
43 |
static void xioctl(int fd, int request, void *argp, const char *string) |
int fdformat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
44 |
{ |
int fdformat_main(int argc UNUSED_PARAM, char **argv) |
|
if (ioctl(fd, request, argp) < 0) { |
|
|
bb_perror_msg_and_die(string); |
|
|
} |
|
|
} |
|
|
|
|
|
int fdformat_main(int argc,char **argv) |
|
45 |
{ |
{ |
46 |
int fd, n, cyl, read_bytes, verify; |
int fd, n, cyl, read_bytes, verify; |
47 |
unsigned char *data; |
unsigned char *data; |
49 |
struct floppy_struct param; |
struct floppy_struct param; |
50 |
struct format_descr descr; |
struct format_descr descr; |
51 |
|
|
52 |
if (argc < 2) { |
opt_complementary = "=1"; /* must have 1 param */ |
53 |
bb_show_usage(); |
verify = !getopt32(argv, "n"); |
|
} |
|
|
verify = !getopt32(argc, argv, "n"); |
|
54 |
argv += optind; |
argv += optind; |
55 |
|
|
56 |
xstat(*argv, &st); |
xstat(*argv, &st); |
63 |
fd = xopen(*argv, O_RDWR); |
fd = xopen(*argv, O_RDWR); |
64 |
|
|
65 |
/* original message was: "Could not determine current format type" */ |
/* original message was: "Could not determine current format type" */ |
66 |
xioctl(fd, FDGETPRM, ¶m, "FDGETPRM"); |
xioctl(fd, FDGETPRM, ¶m); |
67 |
|
|
68 |
printf("%s-sided, %d tracks, %d sec/track. Total capacity %d kB\n", |
printf("%s-sided, %d tracks, %d sec/track. Total capacity %d kB\n", |
69 |
(param.head == 2) ? "Double" : "Single", |
(param.head == 2) ? "Double" : "Single", |
71 |
|
|
72 |
/* FORMAT */ |
/* FORMAT */ |
73 |
printf("Formatting... "); |
printf("Formatting... "); |
74 |
xioctl(fd, FDFMTBEG, NULL, "FDFMTBEG"); |
xioctl(fd, FDFMTBEG, NULL); |
75 |
|
|
76 |
/* n == track */ |
/* n == track */ |
77 |
for (n = 0; n < param.track; n++) { |
for (n = 0; n < param.track; n++) { |
78 |
descr.head = 0; |
descr.head = 0; |
79 |
descr.track = n; |
descr.track = n; |
80 |
xioctl(fd, FDFMTTRK, &descr, "FDFMTTRK"); |
xioctl(fd, FDFMTTRK, &descr); |
81 |
printf("%3d\b\b\b", n); |
printf("%3d\b\b\b", n); |
82 |
if (param.head == 2) { |
if (param.head == 2) { |
83 |
descr.head = 1; |
descr.head = 1; |
84 |
xioctl(fd, FDFMTTRK, &descr, "FDFMTTRK"); |
xioctl(fd, FDFMTTRK, &descr); |
85 |
} |
} |
86 |
} |
} |
87 |
|
|
88 |
xioctl(fd, FDFMTEND, NULL, "FDFMTEND"); |
xioctl(fd, FDFMTEND, NULL); |
89 |
printf("done\n"); |
printf("done\n"); |
90 |
|
|
91 |
/* VERIFY */ |
/* VERIFY */ |
109 |
/* Check backwards so we don't need a counter */ |
/* Check backwards so we don't need a counter */ |
110 |
while (--read_bytes >= 0) { |
while (--read_bytes >= 0) { |
111 |
if (data[read_bytes] != FD_FILL_BYTE) { |
if (data[read_bytes] != FD_FILL_BYTE) { |
112 |
printf("bad data in cyl %d\nContinuing... ",cyl); |
printf("bad data in cyl %d\nContinuing... ", cyl); |
113 |
} |
} |
114 |
} |
} |
115 |
} |
} |