util-linux/util-linux-2.19-floppy-generic.patch
Karel Zak cbffb8f231 2.19-2: fix #682502
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-07 10:55:11 +01:00

104 lines
2.6 KiB
Diff

diff -up util-linux-2.19/floppy-0.18/floppyfloppy.c.kzak util-linux-2.19/floppy-0.18/floppyfloppy.c
--- util-linux-2.19/floppy-0.18/floppyfloppy.c.kzak 2009-09-24 03:36:33.000000000 +0200
+++ util-linux-2.19/floppy-0.18/floppyfloppy.c 2011-03-07 10:40:42.000000000 +0100
@@ -271,6 +271,33 @@ static RETSIGTYPE sighandler(int signum)
#endif
}
+/* -1=error, 1=true, 0=false */
+static int check_generic(const char *dev, int n)
+{
+ struct floppy_struct param;
+ int fd;
+
+ if ((fd=open(dev, O_RDONLY)) < 0)
+ {
+ perror(dev);
+ return -1;
+ }
+ if (ioctl(fd,FDGETPRM,(long) &param) < 0)
+ {
+ perror(dev);
+ close(fd);
+ return -1;
+ }
+ close(fd);
+
+ if (param.sect==floppy_type[n].sectors &&
+ param.head==floppy_type[n].heads &&
+ param.track==floppy_type[n].tracks)
+ /* generic device uses expected format */
+ return 1;
+
+ return 0;
+}
static int do_format(const char *dev, int fmtnum,
int (*fmt_func)(const char *, int), int flags)
@@ -282,6 +309,7 @@ static int do_format(const char *dev, in
struct format_descr curtrack;
int pct;
struct stat stat_buf;
+ int gen = 0;
int i, j;
char *devname;
@@ -304,23 +332,52 @@ static int do_format(const char *dev, in
strcat(strcpy(devname, dev), floppy_type[fmtnum].dev);
+ if (stat(devname, &stat_buf)==-1 && errno==ENOENT)
+ {
+ /* /dev/fd0xxxxx doesn't exist ...try to use generic device
+ *
+ * Note: we needn't size specific device if the generic device uses
+ * right floppy format (FDGETPRM). -- Karel Zak [30/09/2005]
+ */
+ if ((gen = check_generic(dev, fmtnum))==1) /* true */
+ {
+ fprintf(stderr, _("WARNING: size specific device %s doesn't exist, using generic device: %s\n"),
+ devname, dev);
+ strcpy(devname, dev);
+ }
+ else if (gen==0) /* false */
+ {
+ fprintf(stderr, _("ERROR: size specific device %1$s doesn't exist. Use \"MAKEDEV %1$s\" and try it again.\n"), devname);
+ return (1);
+ }
+ else /* error -- no floppy medium or device? */
+ return(1);
+ }
fd=open(devname, O_WRONLY);
if (fd < 0)
{
perror(devname);
return (1);
}
-
- if (fstat(fd, &stat_buf) ||
- !S_ISBLK(stat_buf.st_mode) ||
- MINOR_DEV(stat_buf.st_rdev) != fmtnum)
+ if (fstat(fd, &stat_buf) < 0)
+ {
+ perror(devname);
+ close(fd);
+ return (1);
+ }
+ if (!S_ISBLK(stat_buf.st_mode))
+ {
+ fprintf(stderr,_("%s: not a block device\n"), devname);
+ close(fd);
+ return (1);
+ }
+ if (gen==0 && MINOR_DEV(stat_buf.st_rdev) != fmtnum)
{
errno=EINVAL;
perror(devname);
close(fd);
return (1);
}
-
if (ioctl(fd, FDGETPRM, &geo) < 0)
{
perror(devname);