Previously in FreeBSD Basics:
In today's article, I'd like to take a look at two utilities from the ports collection that can be used to manipulate data contained on MS-DOS file systems. The suite of DOS-like command line utilities found in
mtools can manipulate MS-DOS data contained on floppies, another partition on your hard drive, Jaz drives, and Zip drives. The program
mfm provides a nice GUI interface to access MS-DOS data on a floppy and to quickly transfer data between your home directory and an MS-DOS formatted floppy.
The nice thing about both utilities is that they allow a user to transparently access this data without having to first mount the filesystem. If you remember from the article on mounting filesystems, only the superuser can mount filesystems. If you are an administrator or have family members using your FreeBSD system, you don't want the hassle of mounting a filesystem every time someone wants to access data on a floppy. Also, as a new user you may still forget to unmount the filesystem before removing your floppy; if you've ever tried this, you have discovered that FreeBSD may panic, reboot, or give you nasty error messages for doing so.
So let's build both utilities and take a look at using them. Both come as either a package or a port, so you can build them either way. I'll demonstrate both methods by building
mtools as a port and
mfm as a package. Become the superuser, ensure that you are connected to the Internet, and enter the build directory for
mtools to build its port:
cd /usr/ports/emulators/mtools make && make install
Once this build is finished, open up your favourite web browser and go to http://www.freebsd.org/x11-fm.html. Scroll down to mfm-1.5 and save the package to a directory on your hard drive; I have created a directory called
/usr/packages for this purpose on my system. Once the download is finished:
cd /usr/packages pkg_add mfm*
Once the package is added, leave the superuser account by typing
exit. If you are using the C shell, type
rehash to make your shell aware of your new programs.
Let's take a look at
mtools. If you just type its name, it will give you a list of the tools that are available for your use:
Supported commands: mattrib, mbadblocks, mcat, mcd, mcopy, mdel, mdeltree, mdir, mdoctorfat, mdu, mformat, minfo, mlabel, mmd, mmount, mpartition, mrd, mread, mmove, mren, mshowfat, mtoolstest, mtype, mwrite, mzip
If you have ever used DOS before, most of these program names should be familiar to you; the only difference is that they all begin with the letter m. Each of these utilities has an associated manpage so you can view its syntax. Sections 1 and 5 of the manual has entries for
Let's see what happens if we type
That doesn't look too bad, as that's the prompt used by MS-DOS to represent your floppy drive. Experienced DOS users will note that the slash is Unix style instead of DOS style. Let's see if we can see the contents of a floppy using the
mdirfd0c: hard error reading fsbn 0 (No status) plain_io: Input/output error init A: could not read boot sector Cannot initialize 'A:'
Oops, I'm so embarrassed; I forgot to put a floppy in the drive. Fortunately for me,
mdir does a sanity check before trying to access the data on the floppy. Let's try again with a floppy in the drive:
mdirCan't open /dev/rfd0: Permission denied Cannot initialize 'A:'
Before we start messing about with permissions, we should first check the
mtools configuration file to see what it is looking for. If you do a:
man 5 mtools
you'll discover that the name of the configuration file is mtools.conf, and it is located in
/usr/local/etc. Let's see who has the right to access this file and make changes to it:
ls -l /usr/local/etcdrwxr-xr-x 9 root wheel 1024 Dec 2 11:57 . -r--r--r-- 1 root wheel 4441 Dec 2 11:50 mtools.conf
Looks like anyone will be able to read this file, but only the superuser will be able to make changes to it. (Forget how permissions work?) Let's take a look at this file first:
more /usr/local/etc/mtools.conf# Example mtools.conf files. Uncomment the lines which correspond to # your architecture and comment out the "SAMPLE FILE" line below # # A note on permissions: a user must have read and # write permissions for the devices named here in # order to access the DOS file systems. You might # give ALL USERS access to ALL FLOPPY DISKS via #the command # # chmod a+rw /dev/*fd* /dev/rfd[0-9]* # # # FreeBSD floppy drives drive a: file="/dev/rfd0" drive b: file="/dev/rfd1"
Looks like we need to give our users permissions to access the floppy device; fortunately, the lines specific to FreeBSD floppy drive device names have already been uncommented for us so we don't need to make any changes to this configuration file.
Let's look at the existing permissions for
/dev/rfd0, which will be seen as "A:" by
ls -l /dev/rfd0crw-r----- 18 root operator 9, 0 Oct 3 08:51 /dev/rfd0
There's our problem. As
mtools.conf stated, users need
rw to access the device, but users only have
r. Since this file is owned by root, we'll have to become the superuser to change its permissions; since I only have one floppy drive, I'll just add
rw to the one device:
chmod a+rw /dev/rfd0
ls -l /dev/rfd0crw-rw-rw- 18 root operator 9, 0 Oct 3 08:51 /dev/rfd0
Leave the superuser account and try your
mdir command again as a regular user; you should be able to see the contents of your floppy drive.
Let's get a little fancier than this. I have a FAT partition at the beginning of my hard drive; let's see if
mtools can access it. There were some lines in
mtools.conf that dealt with hard drives:
more /usr/local/etc/mtools.conf# IDE hard disks # first disk on the first IDE # interface (wd0) slice 1 (s1) drive c: file="/dev/rwd0s1"
Since I'm using a version of FreeBSD higher than 4.0, my first IDE interface is actually called
ad0 instead of
wd0. So I'll need to become the superuser and edit this line to read:
drive c: file="/dev/rad0s1" ^
While I'm superuser, I'll also want to check the permissions on this device:
ls -l /dev/rad0s1crw-r----- 1 root operator 116, 0x00020002 Oct 4 15:58 rad0s1
and change them so users can access the C: drive:
chmod a+rw /dev/rad0s1
Then, as a regular user, I'll see if I can access data on both the A: and C: drives:
mcd a: mdir
Volume in drive A has no label Volume Serial Number is 3505-18E3 Directory for A:/ dru3 txt 2846 11-28-2000 21:46 inetdc~1 txt 13669 10-05-2000 21:22 inetd.conf.txt cisco doc 10752 11-13-2000 18:07 3 files 27 267 bytes 1 428 698 bytes free
mcd c: mdirVolume in drive C has no label Volume Serial Number is 39D0-A67B Directory for C:/ bootsect bsd 512 10-04-2000 15:22 confer~1 <DIR> 11-01-2000 20:39 conferencing server sybex <DIR> 11-10-2000 20:18 Sybex 3 files 512 bytes 492 470 272 bytes free
Now, I know that there are some hidden files on my C: drive; if I take a look at
man mdir, I'll see that
-a will show hidden files. Let's try that command again:
mdir -aVolume in drive C has no label Volume Serial Number is 39D0-A67B Directory for C:/ bootsect dos 512 10-04-2000 15:33 config sys 0 10-04-2000 15:40 autoexec bat 0 10-04-2000 15:40 io sys 0 10-04-2000 15:40 msdos sys 0 10-04-2000 15:40 bootsect bsd 512 10-04-2000 15:22 msdownld tmp <DIR> 10-04-2000 16:10 confer~1 <DIR> 11-01-2000 20:39 conferencing server recycled <DIR> 11-01-2000 21:01 Recycled sybex <DIR> 11-10-2000 20:18 Sybex arcldr exe 148992 12-07-1999 12:00 arcsetup exe 162816 12-07-1999 12:00 ntldr 214416 12-07-1999 12:00 ntdetect com 34468 11-25-2000 21:45 boot ini 214 11-25-2000 20:00 pagefile sys 104857600 11-25-2000 19:51 16 files 105 419 530 bytes 492 470 272 bytes free
Let's see if I can read one of these files:
mtype boot.ini[boot loader] timeout=30 default=multi(0)disk(0)rdisk(0)partition(3)\WINNT [operating systems] multi(0)disk(0)rdisk(0)partition(3)\WINNT="Microsoft Windows 2000 Server" /fastdetect C:\bootsect.bsd="FreeBSD"
Let's see if I can copy this file onto my floppy:
mcopy boot.ini a:
My floppy drive is churning, which is a good sign. Let's double-check that it worked:
mdir a:Volume in drive A has no label Volume Serial Number is 3505-18E3 Directory for A:/ dru3 txt 2846 11-28-2000 21:46 inetdc~1 txt 13669 10-05-2000 21:22 inetd.conf.txt boot ini 214 12-03-2000 11:25 boot.ini cisco doc 10752 11-13-2000 18:07 4 files 27 481 bytes 1 428 484 bytes free
It is nice to be able to easily transfer files from my NT boot partition to a floppy while I'm in my FreeBSD system. I can just as easily send files back and forth between FreeBSD and my C: drive or A: drive.
A few things to note about
mtools. It supplies DOS-like utilities, and DOS is quite limited. For example, I won't be able to read the file on my floppy drive called
cisco.doc as DOS does not recognize the "doc" extension. If you are working in both your A: and C: drives, you'll have to
mcd between them like so:
mcd a:to view and manipulate data on A:
mcd c:to view and manipulate data on C:
Also, make sure you are only trying to access MS-DOS filesystems; that is, don't try to view the contents of a floppy formatted with a Unix filesystem.
Now let's take a look at
mfm. This utility is easier to work with as it has a very intuitive interface; it is also more limited than
mtools, as it can only be used to access MS-DOS data contained on a floppy. Let's see where it was installed:
Since it is a GUI, you will have to run it from an XWindows session. I've placed a shortcut to it in my XFCE toolbar. If you don't know how to create shortcuts in your Windows Manager yet, open up an xterm and type in the path to
whereis -b mfm mfm: /usr/X11R6/bin/mfm
mfm. (There is a link to a screenshot here.)
When the utility opens up, you'll see a window with two panes; by default, both panes will show the contents of your home directory. Directories have a folder icon, and their names and attributes show up in blue type. Files have an icon that looks like a sheet of paper, and their attributes show up in black type. If you click on the Options menu with your mouse, you can "Show dot files" to also view your hidden files.
Insert your floppy; at the menu bar on top of one of the panes, click on the arrow and select a: instead of the default Harddisk. You should now see the contents of your floppy. By highlighting a file on the floppy and clicking on the Copy button with the appropriate arrow, you can copy the file over to your home directory. Or by clicking a file on your home directory, you can quickly copy it over to the floppy.
Click on the File menu just above a pane; here you'll see options to delete, rename, or print the highlighted file. You can also create a new directory using this menu. If you remove a floppy and insert a new one, use the View menu, Refresh option to see the contents of the new floppy.
Though somewhat limited,
mfm is a very quick way to manipulate the contents of your home directory in a visual way. I also find it to be a painless method of sending files back and forth between a floppy and my home directory.
For next week's article, let's continue poking about the neat programs available in the ports collection.
Dru Lavigne is a network and systems administrator, IT instructor, author and international speaker. She has over a decade of experience administering and teaching Netware, Microsoft, Cisco, Checkpoint, SCO, Solaris, Linux, and BSD systems. A prolific author, she pens the popular FreeBSD Basics column for O'Reilly and is author of BSD Hacks and The Best of FreeBSD Basics.
Read more FreeBSD Basics columns.
Discuss this article in the Operating Systems Forum.
Return to the BSD DevCenter.
Copyright © 2009 O'Reilly Media, Inc.