fdread.c (78857) | fdread.c (79110) |
---|---|
1/* 2 * Copyright (c) 2001 Joerg Wunsch 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 9 unchanged lines hidden (view full) --- 18 * IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * | 1/* 2 * Copyright (c) 2001 Joerg Wunsch 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 9 unchanged lines hidden (view full) --- 18 * IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/usr.sbin/fdread/fdread.c 78857 2001-06-26 22:17:21Z joerg $ | 26 * $FreeBSD: head/usr.sbin/fdread/fdread.c 79110 2001-07-02 21:21:58Z joerg $ |
27 */ 28 29#include <sys/types.h> 30#include <sys/stat.h> 31#include <sys/fdcio.h> 32 33#include <err.h> 34#include <errno.h> 35#include <fcntl.h> 36#include <paths.h> 37#include <stdio.h> 38#include <stdlib.h> 39#include <string.h> 40#include <sysexits.h> 41#include <unistd.h> 42 43#include <dev/ic/nec765.h> 44 | 27 */ 28 29#include <sys/types.h> 30#include <sys/stat.h> 31#include <sys/fdcio.h> 32 33#include <err.h> 34#include <errno.h> 35#include <fcntl.h> 36#include <paths.h> 37#include <stdio.h> 38#include <stdlib.h> 39#include <string.h> 40#include <sysexits.h> 41#include <unistd.h> 42 43#include <dev/ic/nec765.h> 44 |
45#include "fdutil.h" 46 |
|
45int quiet, recover; 46unsigned char fillbyte = 0xf0; /* "foo" */ 47 48int doread(int fd, FILE *of, const char *devname); 49int doreadid(int fd, unsigned int numids, unsigned int trackno); | 47int quiet, recover; 48unsigned char fillbyte = 0xf0; /* "foo" */ 49 50int doread(int fd, FILE *of, const char *devname); 51int doreadid(int fd, unsigned int numids, unsigned int trackno); |
50void printstatus(struct fdc_status *fdcsp); | |
51void usage(void); 52 53void 54usage(void) 55{ 56 57 errx(EX_USAGE, 58 "usage: fdread [-qr] [-d device] [-f fillbyte]\n" --- 172 unchanged lines hidden (view full) --- 231 } 232 if (ioctl(fd, FD_GSTAT, &fdcs) == -1) 233 errx(EX_IOERR, 234 "floppy IO error, but no FDC status"); 235 nerrs++; 236 recoverable = fdcs.status[2] & 237 NE7_ST2_DD; 238 if (!quiet) { | 52void usage(void); 53 54void 55usage(void) 56{ 57 58 errx(EX_USAGE, 59 "usage: fdread [-qr] [-d device] [-f fillbyte]\n" --- 172 unchanged lines hidden (view full) --- 232 } 233 if (ioctl(fd, FD_GSTAT, &fdcs) == -1) 234 errx(EX_IOERR, 235 "floppy IO error, but no FDC status"); 236 nerrs++; 237 recoverable = fdcs.status[2] & 238 NE7_ST2_DD; 239 if (!quiet) { |
239 printstatus(&fdcs); | 240 printstatus(&fdcs, 0); |
240 fputs(" (", stderr); 241 if (!recoverable) 242 fputs("not ", stderr); 243 fputs("recoverable)", stderr); 244 } 245 if (!recover) { 246 if (!quiet) 247 putc('\n', stderr); --- 43 unchanged lines hidden (view full) --- 291 if (nerrs) 292 fprintf(stderr, "%d error%s\n", 293 nerrs, nerrs > 1? "s": ""); 294 } 295 296 return (nerrs? EX_IOERR: EX_OK); 297} 298 | 241 fputs(" (", stderr); 242 if (!recoverable) 243 fputs("not ", stderr); 244 fputs("recoverable)", stderr); 245 } 246 if (!recover) { 247 if (!quiet) 248 putc('\n', stderr); --- 43 unchanged lines hidden (view full) --- 292 if (nerrs) 293 fprintf(stderr, "%d error%s\n", 294 nerrs, nerrs > 1? "s": ""); 295 } 296 297 return (nerrs? EX_IOERR: EX_OK); 298} 299 |
299void 300printstatus(struct fdc_status *fdcsp) 301{ 302 char msgbuf[100]; 303 304 fprintf(stderr, 305 "\nFDC status ST0=%#x ST1=%#x ST2=%#x C=%u H=%u R=%u N=%u:\n", 306 fdcsp->status[0] & 0xff, 307 fdcsp->status[1] & 0xff, 308 fdcsp->status[2] & 0xff, 309 fdcsp->status[3] & 0xff, 310 fdcsp->status[4] & 0xff, 311 fdcsp->status[5] & 0xff, 312 fdcsp->status[6] & 0xff); 313 314 if ((fdcsp->status[0] & NE7_ST0_IC_RC) != NE7_ST0_IC_AT) { 315 sprintf(msgbuf, "unexcpted interrupt code %#x", 316 fdcsp->status[0] & NE7_ST0_IC_RC); 317 } else { 318 strcpy(msgbuf, "unexpected error code in ST1/ST2"); 319 320 if (fdcsp->status[1] & NE7_ST1_EN) 321 strcpy(msgbuf, "end of cylinder (wrong format)"); 322 else if (fdcsp->status[1] & NE7_ST1_DE) { 323 if (fdcsp->status[2] & NE7_ST2_DD) 324 strcpy(msgbuf, "CRC error in data field"); 325 else 326 strcpy(msgbuf, "CRC error in ID field"); 327 } else if (fdcsp->status[1] & NE7_ST1_MA) { 328 if (fdcsp->status[2] & NE7_ST2_MD) 329 strcpy(msgbuf, "no address mark in data field"); 330 else 331 strcpy(msgbuf, "no address mark in ID field"); 332 } else if (fdcsp->status[2] & NE7_ST2_WC) 333 strcpy(msgbuf, "wrong cylinder (format mismatch)"); 334 else if (fdcsp->status[1] & NE7_ST1_ND) 335 strcpy(msgbuf, "no data (sector not found)"); 336 } 337 fputs(msgbuf, stderr); 338} 339 | |
340int 341doreadid(int fd, unsigned int numids, unsigned int trackno) 342{ 343 int rv = 0, status, fdopts; 344 unsigned int i; 345 struct fdc_readid info; 346 struct fdc_status fdcs; 347 struct fd_type fdt; --- 14 unchanged lines hidden (view full) --- 362 } else { 363 if (errno != EIO) { 364 perror("non-IO error"); 365 return (EX_OSERR); 366 } 367 if (ioctl(fd, FD_GSTAT, &fdcs) == -1) 368 errx(EX_IOERR, 369 "floppy IO error, but no FDC status"); | 300int 301doreadid(int fd, unsigned int numids, unsigned int trackno) 302{ 303 int rv = 0, status, fdopts; 304 unsigned int i; 305 struct fdc_readid info; 306 struct fdc_status fdcs; 307 struct fd_type fdt; --- 14 unchanged lines hidden (view full) --- 322 } else { 323 if (errno != EIO) { 324 perror("non-IO error"); 325 return (EX_OSERR); 326 } 327 if (ioctl(fd, FD_GSTAT, &fdcs) == -1) 328 errx(EX_IOERR, 329 "floppy IO error, but no FDC status"); |
370 printstatus(&fdcs); | 330 printstatus(&fdcs, 0); |
371 putc('\n', stderr); 372 rv = EX_IOERR; 373 } 374 } 375 376 return (rv); 377} | 331 putc('\n', stderr); 332 rv = EX_IOERR; 333 } 334 } 335 336 return (rv); 337} |