]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - disk-utils/setfdprm.c
1 /* setfdprm.c - Sets user-provided floppy disk parameters, re-activates
2 autodetection and switches diagnostic messages. */
4 /* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
5 * - added Native Language Support
13 #include <sys/types.h>
15 #include <sys/ioctl.h>
19 #define FDPRMFILE "/etc/fdprm"
28 result
= strtol(arg
,&end
,0);
31 fprintf(stderr
,_("Invalid number: %s\n"),arg
);
36 cmd_without_param(int cmd
,int fd
) {
37 if (ioctl(fd
,cmd
,NULL
) >= 0)
43 /* set given fd parameters */
45 set_params(int cmd
,int fd
,char **params
) {
46 struct floppy_struct ft
;
48 ft
.size
= convert(params
[0]);
49 ft
.sect
= convert(params
[1]);
50 ft
.head
= convert(params
[2]);
51 ft
.track
= convert(params
[3]);
52 ft
.stretch
= convert(params
[4]);
53 ft
.gap
= convert(params
[5]);
54 ft
.rate
= convert(params
[6]);
55 ft
.spec1
= convert(params
[7]);
56 ft
.fmt_gap
= convert(params
[8]);
58 if (ioctl(fd
,cmd
,&ft
) >= 0) exit(0);
63 /* find parameter set in file, and use it */
65 find_params(int cmd
,int fd
,char *name
) {
67 char line
[MAXLINE
+2],this[MAXLINE
+2],param
[9][MAXLINE
+2];
68 char *params
[9],*start
;
71 if ((file
= fopen(FDPRMFILE
,"r")) == NULL
) {
75 while (fgets(line
,MAXLINE
,file
)) {
76 for (start
= line
; *start
== ' ' || *start
== '\t'; start
++);
77 if (*start
&& *start
!= '\n' && *start
!= '#') {
78 if (sscanf(start
,"%s %s %s %s %s %s %s %s %s %s",this,param
[0],
79 param
[1],param
[2],param
[3],param
[4],param
[5],param
[6],param
[7],
81 fprintf(stderr
,_("Syntax error: '%s'\n"),line
);
84 if (!strcmp(this,name
)) {
85 for (count
= 0; count
< 9; count
++)
86 params
[count
] = param
[count
];
87 set_params(cmd
,fd
,params
);
91 fprintf(stderr
,_("No such parameter set: '%s'\n"),name
);
99 if ((this = strrchr(name
,'/')) != NULL
) name
= this+1;
100 fprintf(stderr
,_("usage: %s [ -p ] dev name\n"),name
);
101 fprintf(stderr
,_(" %s [ -p ] dev size sect heads tracks stretch \
102 gap rate spec1 fmt_gap\n"),name
);
104 fprintf(stderr
,_(" %s [ -c | -y | -n | -d ] dev\n"),name
);
106 fprintf(stderr
,_(" %s [ -c | -y | -n ] dev\n"),name
);
112 main(int argc
, char **argv
) {
118 if ((p
= strrchr(progname
, '/')) != NULL
)
121 setlocale(LC_ALL
, "");
122 bindtextdomain(PACKAGE
, LOCALEDIR
);
126 (!strcmp(argv
[1], "-V") || !strcmp(argv
[1], "--version"))) {
127 printf(_("%s from %s\n"), progname
, util_linux_version
);
134 if (*argv
[1] == '-') {
135 switch (argv
[1][1]) {
159 if ((fd
= open(argv
[1],3)) < 0) { /* O_WRONLY needed in a few kernels */
163 if (cmd
!= FDSETPRM
&& cmd
!= FDDEFPRM
) {
164 if (argc
!= 2) usage(progname
);
165 cmd_without_param(cmd
,fd
);
167 if (argc
!= 11 && argc
!= 3)
170 set_params(cmd
,fd
,&argv
[2]);
172 find_params(cmd
,fd
,argv
[2]);