File: getfdprm.c

package info (click to toggle)
fdutils 5.3-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,004 kB
  • ctags: 621
  • sloc: ansic: 6,098; sh: 2,236; makefile: 279; sed: 4
file content (94 lines) | stat: -rw-r--r-- 1,622 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94


#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "driveprm.h"
#include "printfdprm.h"


struct floppy_struct floppy_type;
extern int errno;

void usage(char *name) __attribute__((noreturn));
void usage(char *name)
{
	fprintf(stderr,"Usage: %s\n", name);
	exit(1);
}

static void myprintf(char *fmt, int value)
{
  printf(fmt, value);
  putchar(' ');
}

void main(int argc,char **argv)
{
	int fd;
	char *name;
	level_t level;
	drivedesc_t drivedesc;

	level = LEV_NONE;
	if (argc > 1 && *argv[1] == '-') {
		switch (argv[1][1]) {
			case 'e':
				level = LEV_EXPL;
				break;
			case 'm':
				level = LEV_MOST;
				break;
			case 'a':
				level = LEV_ALL;
				break;
			case 'o':
				level = LEV_OLD;
				break;
			default:
				usage(argv[0]);
		}
		argc--;
		argv++;
	}	

	if ( argc == 1 )
		name = "/dev/fd0" ;
	else
		name = argv[1];

	fd=open(name,3);
	if ( fd < 0 )
		fd=open(name,O_RDONLY);
	if ( fd < 0 ){
		perror("open");
		exit(1);
	}
	
	if(ioctl(fd,FDGETPRM,&floppy_type)<0){
		perror("get geometry parameters");
		exit(1);
	}

	if(level == LEV_OLD) {
		printf("%4d %2d %d %2d %d 0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x\n",
		       floppy_type.size,
		       floppy_type.sect,
		       floppy_type.head,
		       floppy_type.track,
		       floppy_type.stretch,
		       floppy_type.gap,
		       floppy_type.rate,
		       floppy_type.spec1,
		       floppy_type.fmt_gap);
	} else {
		parse_driveprm(fd, &drivedesc);
		print_params(&drivedesc, &floppy_type, level, 0, 
			     (void(*)(char *,int))myprintf);
	}
	close(fd);
	exit(0);
}