Friday, November 13, 2009

Mounting Foreign File Systems













Mounting Foreign File Systems

For our purposes, any partition that doesn't have an FFS file system is a foreign file system. Fortunately, OpenBSD includes extensive support for these foreign file systems, with the caveat that only those functions supported by the file system will work. FAT doesn't set security permissions, for example. You can set file system security flags on a FAT file system all you want, but they won't change anything.


Each file system has its own unique mount program that handles the vagaries of that file system, and each file system needs support in the kernel. To make your life a little easier, mount(8) can recognize the standard file systems and can call the correct mount program as needed. Also, every file system reliably supported by OpenBSD is in the GENERIC kernel.





Using Foreign Mounts


To mount a foreign file system you need the same information you would need when mounting an FFS file system: a device name and a mount point. You may also need to know the type of file system you'll be mounting.


For example, let's mount a CD-ROM. Our system has one CD-ROM drive, /dev/cd0. A CD-ROM has only partition on it, and that partition takes up the whole disk, so we want the whole-disk partition, or "c." The device name for a CD-ROM partition is /dev/cd0c. We'll let mount(8) try to figure out what sort of file system this is.




# mount_cd9660 /dev/cd0c /cdrom
#



This may take longer than a hard disk mount, simply because the CD-ROM must spin up the disk before the kernel can mount it.


Mount(8) may be smart, but it cannot always guess correctly. It's easy to determine that a file system in a CD-ROM is a CD-ROM file system - the chances that it will be a network file system or a UNIX file system are really pretty slim. Other guesses are not so easy. Here, I'm trying to mount a floppy disk of unknown format.




# mount /dev/fd0c /mnt/
mount_ffs: /dev/fd0c on /mnt: Inappropriate file type or format
#


Mount(8) guessed that this was an FFS floppy, which is apparently not correct. If I explicitly use the program to mount FAT file systems, it works just fine.


No matter what sort of file system you have mounted, umount(8) can unmount it.




# umount /mnt/
#





Vnodes, Foreign File Systems, and FFS


Earlier we discussed inodes and blocks, the building blocks of FFS. This worked well in the early days of UNIX, but as years passed it became normal to swap disks between different machines and different operating systems. CD-ROMs, with their unique file system, became popular; floppy disks converged on FAT32 as a standard; and other UNIXes developed their own file systems. Because BSD needed to speak to all these different systems, another layer of abstraction was needed.


That abstraction was the virtual node, or vnode. You never directly manipulate vnodes, but you'll see references to them throughout the system documentation, so it's important to know what they are. The vnode is a translator between the kernel and whatever sort of file system you have mounted. Every tool that reads and writes to disks actually does so through vnodes, which map the data to the appropriate file system for the underlying media. You'll see references to inodes only when dealing with FFS file systems, but you'll see vnodes when you deal with any file system.


When you write a file to a FFS file system, the vnode talks to an inode. When you write a file to a Microsoft-style FAT32 file system, the vnode talks to the file allocation table. Vnodes are actually used for far more than just interacting with the file system, but we won't get into that here. To learn more about vnodes, read vnode(9).





Foreign File System Types


Here are some of the most commonly used foreign file systems, along with a brief description of each and the appropriate mount command.




MS-DOS


OpenBSD supports FAT, FAT16, and FAT32 file systems, the standard DOS/ Windows format commonly used in dual-boot systems and on floppy disks. You can format a floppy disk in FFS, however, so you cannot assume that all floppy disks are MS-DOS formatted. If you try to mount a floppy disk and it won't work as an MS-DOS disk, try to mount it as an FFS disk. Personally, my only use for floppy disks is to transfer files to and from a Windows machine that I don't control — for example, for taking files to the print shop. I make it my personal standard to always format floppy disks in MS-DOS format.


The mount command is mount_msdos(8).




# mount_msdos /dev/fd0c /mnt


If you work with a lot of MS-DOS file systems check out /usr/ports/sysutils/ mtools, a collection of programs for working with MS-DOS partitions that offers you the ability to access MS-DOS disks without mounting them. While mount_msdos(8) works reliably, if you want a prettier interface this is for you.




ISO-9660


ISO-9660 is the standard data CD-ROM file system. OpenBSD reads CD-ROMs, and also has integrated tools to write to CD-ROM (mkisofs(8)). Just about every CD-ROM you will ever encounter has ISO-9660 format. The mount command is mount_cd9660(8), although mount(8) is very good about autodetecting this file system.




# mount_cd9660 /dev/cd1c /cdrom




ext2fs


The standard Linux filesystem, ext2fs, supports many of the same features as FFS and can safely be written to and read from without any problems. You may need this in a dual-boot Linux/OpenBSD machine, or if you need to get information off of a Linux hard drive. The mount command is mount_ext2fs.




# mount_ext2fs /dev/wd0l /linux/usr






File System Permissions


Different file systems have different permissions schemes. For example, both FFS and ext2fs store permissions in the file system, mapping them to user ID numbers (UIDs). Because ext2fs normally behaves much like FFS, and all the permissions information it needs is available within the file system, OpenBSD respects its permissions. The UIDs might not match up to what you have on your OpenBSD system, which can cause a wide variety of separate problems, but the permissions are respected.



MS-DOS file systems, on the other hand, have no permissions scheme. You can use the "-u" and "-g" flags to set the user and group ownership of mounted MS-DOS file systems. For example, to mount a MS-DOS disk to be owned by the user "phil" and the group "staff," mount it as such.




# mount_msdos -u phil -g staff /dev/fd0c /mnt












No comments: