Date: Sun, 6 Apr 1997 03:18:36 +1000 (EST) From: Mike McGaughey <mmcg@heraclitus.cs.monash.edu.au> To: FreeBSD-gnats-submit@freebsd.org Subject: ports/3205: Mtools-3.0 fails to WRITE to dos partition under 2.2 (fix supplied) Message-ID: <199704051718.DAA00131@heraclitus.cs.monash.edu.au> Resent-Message-ID: <199704051720.JAA17387@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 3205 >Category: ports >Synopsis: Mtools-3.0 attempts to flock() a disk partition, which fails with `operation not supported' >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-ports >State: open >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Apr 5 09:20:02 PST 1997 >Last-Modified: >Originator: Mike McGaughey >Organization: Mike McGaughey AARNET: mmcg@cs.monash.edu.au >Release: FreeBSD 2.2.1-RELEASE >Environment: P133, 64M, Cheap scsi with CD writer, IDE CD, two IDE hard disks, one of those buggered video cards that only works with PCVT. All of which is irrelevant :) Disks: wd0s1, wd1s1 and wd0s5 are large FAT partitions; I use mtools for writing to wd0s5, as it's some 1.2G. >Description: I installed mtools-3.0 to communicate with the dos partitions. It reads them perfectly, but always fails to write, claiming `/dev/rwd1s1: device busy' (despite /dev/wd1s1 not having been mounted or otherwise touched since boot). On examination, it turns out that rather than using perror(), the mtools source uses the following logic: If flock(device) fails and it's EINVAL Then assume we don't need to lock the device otherwise print `device busy' FreeBSD doesn't return EINVAL for this purpose - it uses EOPNOTSUPP. It may be, of course, that locking's simply not working in 2.2.1 :) >How-To-Repeat: (set up your dos partition descriptions correctly) # mwrite a_file c: (it fails with `plain floppy: device "/dev/wd0s1"busy') >Fix: See description. I didn't unpack the source to the port (just the mtools-3.0 tarball); sorry, but I'm too insanely busy to do this properly. Use at your risk. Here's the patch (I unnecessarily chopped out a bunch of ifdef's): diff -rc mtools-3.0/plain_io.c mtools-3.0.new/plain_io.c *** mtools-3.0/plain_io.c Mon May 13 05:24:19 1996 --- mtools-3.0.new/plain_io.c Sun Apr 6 02:59:48 1997 *************** *** 36,63 **** int lock_dev(int fd) { - #if (defined(HAVE_LOCKF) && defined(F_TLOCK)) - if (lockf(fd, F_TLOCK, 0) < 0) - #else /* LOCKF */ - #if (defined(HAVE_FLOCK) && defined (LOCK_EX) && defined(LOCK_NB)) if (flock(fd, LOCK_EX|LOCK_NB) < 0) - #else /* FLOCK */ - - #if (defined(F_SETLK) && defined(F_WRLCK)) - struct flock flk; - - flk.l_type = F_WRLCK; - flk.l_whence = 0; - flk.l_start = 0L; - flk.l_len = 0L; - - if (fcntl(fd, F_SETLK, &flk) < 0) - #endif /* FCNTL */ - #endif /* FLOCK */ - #endif /* LOCKF */ { ! if(errno == EINVAL) return 0; else return 1; --- 36,46 ---- int lock_dev(int fd) { if (flock(fd, LOCK_EX|LOCK_NB) < 0) { ! if ((errno == EINVAL) ! || (errno == EOPNOTSUPP)) return 0; else return 1; *************** *** 275,280 **** --- 258,264 ---- sprintf(errmsg, "plain floppy: device \"%s\"busy\n:", dev->name); + perror("Plain floppy open:"); return NULL; } >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199704051718.DAA00131>