Узбекистан, Бухара, Бухарский институт высоких технологий, 2013 |
Tapes, backups and floppy disks
File systems on floppy
It's possible to use floppies as file systems under FreeBSD. You can create a UFS file system on a floppy just like on a hard disk. This is not necessarily a good idea: the UFS file system is designed for performance, not maximum capacity. By default, it doesn't use the last 8% of disk space, and it includes a lot of structure information that further reduces the space available on the disk. Here's an example of creating a file system, mounting it on the directory /A , and listing the remaining space available on an empty 3,5" floppy. Since release 5, FreeBSD no longer requires a partition table on a floppy, so you don't need to run bsdlabel (the replacement for the older disklabel program).
# newfs -O1 /dev/fd0 create a new file system /dev/fd0: 1.4MB (2880 sectors) block size 16384, fragment size 2048 using 2 cylinder groups of 1.00MB, 64 blks, 128 inodes. super-block backups (for fsck -b #) at: 32, 2080 # mount /dev/fd0 /A mount the floppy on /A # df -k /A display the space available Filesystem 1024-blocks Used Avail Capacity Mounted on /dev/fd0 1326 2 1218 0% /A
Let's look at this in a little more detail:
- newfs creates the UFS file system on the floppy. We use the -O1 fag to force the older UFS1 format, which leaves more usable space than the default UFS2.
- We have already seen mount on page 192. In this case, we use it to mount the floppy on the file system /A.
- The df program shows the maximum and available space on a file system. By default, df displays usage in blocks of 512 bytes, an inconvenient size. In this example we use the -k option to display it in kilobytes. You can set a default block size via the environment variable BLOCKSIZE. If it had been set to 1024, we would see the same output without the -k option. See page 128 for more details of environment variables.
The output of df looks terrible! Our fbppy only has 1218 kB left for normal user data, even though there is nothing on it and even df claims that it can really store 1326 kB. This is because UFS keeps a default of 8% of the space free for performance reasons. You can change this, however, with tunefs, the file system tune program1 To quote the man page: You can tune a file system, but you can’t tune a fish:
# umount /A first unmount the floppy # tunefs -m 0 /dev/fd0 and changethe minimum free to 0 tunefs: minimum percentage of free space changes from 8% to 0% tunefs: should optimize for space with minfree < 8% # tunefs -o space /dev/fd0 changethe optimization tunefs: optimization preference changes from time to space # mount /dev/fd0 /A mount the file system again # df /A and takeanother look Filesystem 1024-blocks Used Avail Capacity Mounted on /dev/fd0 1326 2 1324 0% /A
Still, this is a far cry from the claimed data storage of a Microsoft disk. In fact, Microsoft disks can't store the full 1.4 MB either: they also need space for storing directories and allocation tables. The moral of the story: only use file systems on floppy if you don't have any alternative.
Microsoft file systems
To create a Microsoft FAT12, FAT16 or FAT32 file system, use the newfs_msdos command:
$ newfs_msdos -f 1440 /dev/fd0
The specification -f 1440 tells newfs_msdos that this is a 1.4 MB floppy. Alternatively, you can use the mformat command:
$ mformat A:
You can specify the number of tracks with the -t option, and the number of sectors with the -s option. To explicitly specify a fbppy with 80 tracks and 18 sectors (a standard 3,5" 1.44 MB floppy), you could enter:
$ mformat -t 80 -s 18 A:
mformat is one of the mtools that we look at in the next section.
Other uses of floppies
Well, you could take the disks out of the cover and use them as a kind of frisbee. But there is one other useful thing you can do with floppies: as an archive medium, they don't need a file system on them. They just need to be low-level formatted. For example, to write the contents of the current directory onto a floppy, you could enter:
$ tar cvfM /dev/fd0. ./ .xfmrc .x6530mcdkey .uwmrc .twmrc .rnsoft .rnlast ...etc Prepare volume #2 for /dev/fd0 and hit return:
Note also the solitary dot (.) at the end of the command line. That's the name of the current directory, and that's what you're backing up. Note also the option M, which is short for --multi-volume. There's a very good chance that you'll run out of space on a floppy, and this option says that you have a sufficient supply of floppies to perform the complete backup.
To extract the data again, use tar with the x option:
$ tar xvfM /dev/fd0. ./ .xfmrc .x6530modkey .uwmrc ...etc
See the man page tar(1) for other things you can do with tar.
Accessing Microsoft floppies
Of course, most of the time you get data on a floppy, it's not in tar format: it has a Microsoft file system on it. We've already seen the Microsoft file system type on page 190, but that's a bit of overkill if you just want to copy files from floppy. In this case, use the mtools package from the Ports Collection. mtools is an implementation of the MS-DOS programs ATTRIB, CD, COPY, DEL, DIR, FORMAT, LABEL, MD, RD, READ, REN, and TYPE under UNIX. To avoid confusion with existing utilities, the UNIX versions of these commands start with the letter m. They are also written in lower case. For example, to list the contents of a floppy and copy one of the files to the current (FreeBSD) directory, you might enter:
$ mdir list the current directory on A Volume in drive A is MESSED OS Directory for A:/ Directory for A:/ IO SYS 33430 4-09-91 5:00a MSDOS SYS 37394 4-09-91 5:00a COMMAND COM 47845 12-23-92 5:22p NFS <DIR> 12-24-92 11:03a DOSEDIT COM 1728 10-07-83 7:40a CONFIG SYS 792 10-07-94 7:31p AUTOEXEC BAT 191 12-24-92 11:10a MOUSE <DIR> 12-24-92 11:09a 12 File(s) 82944 bytes free $ mcd nfs change to directory A:\NFS $ mdir and list the directory Volume in drive A is MESSED OS Directory for A:/NFS . <DIR> 12-24-92 11:03a .. <DIR> 12-24-92 11:03a HOSTS 5985 10-07-94 7:34p NETWORK BAT 103 12-24-92 12:28p DRIVES BAT 98 11-07-94 5:24p and many more 51 File(s) 82944 bytes free $ mtype drives.bat type the contents of DRIVES.BAT Net use c: presto:/usr/dos C: Cd\nfs #net use f:Porsche:/dos #net use g:Porsche:/usr $ mcopy a:hosts. Copying HOSTS $ ls-l hosts and list it -rw-rw-rw- 1 root wheel 5985 Jan 28 18:04 hosts
You must specify the drive letter to mcopy, because it uses this indication to decide whether the file name is a UNIX or a Microsoft file name. You can copy files from FreeBSD to the floppy as well, of course.
A word of warning. UNIX uses a different text data format from Microsoft: in UNIX, lines end with a single character, called New line, and represented by the characters \n in the C programming language. It corresponds to the ASCII character Line Feed (represented by ^J). Microsoft uses two characters, a Carriage Return (^M) followed by a Line Feed. This unfortunate difference causes a number of unexpected compatibility problems, since both characters are usually invisible on the screen.
In FreeBSD, you won't normally have many problems. Occasionally a program complains about non-printable characters in an input line. Some, like Emacs, show them. For example, Emacs shows our last file, drives.bat, like this:
net use c: presto:/usr/dos~M c:M cd \nfs"M #net use f: porsche:/dos~M #net use g: porsche:/usr~M
This may seem relatively harmless, but it confuses some programs, including the C compiler and pagers like more, which may react in confusing ways. You can remove them with the -t option of mcopy:
$ mcopy -t a:drives.bat
Transferring files in the other direction is more likely to cause problems. For example, you might edit this file under FreeBSD and then copy it back to the diskette. The results depend on the editor, but assuming we changed all occurrences of the word porsche to freedom, and then copied the file back to the diskette, Microsoft might then find:
C:> type drives.bat net use c: presto:/usr/dos c: cd \nfs #net use f: freedom:/dos #net use g: freedom:/usr
This is a typical result of removing the Carriage Return characters. The -t option to mcopy can help here, too. If you use it when copying to a Microsoft file system, it reinserts the Carriage Return characters.