Опубликован: 06.08.2012 | Доступ: свободный | Студентов: 1189 / 25 | Оценка: 5.00 / 5.00 | Длительность: 53:41:00
Лекция 10:

File systems and devices

< Лекция 9 || Лекция 10: 1234 || Лекция 11 >
Unmounting file systems

When you mount a file system, the system assumes it is going to stay there, and in the interests of efficiency it delays writing data back to the file system. This is also the reason why you can't just turn the power off when you shut down the system. If you want to stop using a file system, you must tell the system about it so that it can flush any remaining data. You do this with the umount command. Note the spelling of this command—there's no n in the command name.

You need to do this even with read-only media such as CD-ROMs: the system assumes it can access the data from a mounted file system, and it gets quite unhappy if it can't. Where possible, it locks removable media so that you can't remove them from the device until you unmount them.

Using umount is straightforward: just tell it what to unmount, either the device name or the directory name. For example, to unmount the CD-ROM we mounted in the example above, you could enter one of these commands:

# umount /dev/cdla
# umount /cdl

Before unmounting a file system, umount checks that nobody is using it. If somebody is using it, it refuses to unmount it with a message like umount: /cdl: Device busy. This message often occurs because you have changed your directory to a directory on the file system you want to remove. For example (which also shows the usefulness of having directory names in the prompt):

=== root@freebie (/dev/ttyp2)  /cdl 16 -> umount /cdl
umount: /cd1: Device busy
=== root@freebie (/dev/ttyp2)  /cd1 17 -> cd
=== root@freebie (/dev/ttyp2)  ~ 18 -> umount /cdl
=== root@freebie (/dev/ttyp2)  ~ 19 ->

After unmounting a vnode file system, don't forget to unconfigure the file:

# umount /mnt
# mdconfig -d -u 0

The parameter 0 refers to md device 0, in other words /dev/md0.

FreeBSD devices

UNIX refers to devices in the same manner as it refers to normal files. By contrast to normal ("regular") files, they are called special files. They're not really files at all: they're information about device support in the kernel, and the term device node is more accurate. Conventionally, they are stored in the directory /dev. Some devices don't have device nodes, for example Ethernet interfaces: they are treated differently by the ifconfig program.

Traditional UNIX systems distinguish two types of device, blockdevices and character devices. FreeBSD no longer has block devices; we discussed the reasons for this on page 36.

In traditional UNIX systems, including FreeBSD up to Release 4, it was necessary to create device nodes manually. This caused a number of problems when they didn't match what was in the system. Release 5 of FreeBSD has solved this problem with the device file system, also known as devfs. devfs is a pseudo-file system that dynamically creates device nodes for exactly those devices that are in the kernel, which makes it unnecessary to manually create devices.

Overview of FreeBSD devices

Every UNIX system has its own peculiarities when it comes to device names and usage. Even if you're used to UNIX, you'll find the following table useful.

Таблица 10.4. FreeBSD device names
acd0 First ata (IDE) CD-ROM drive.
ad0 First ata (IDE or similar) disk drive. See "Chapter 2" , page 38, for a complete list of disk drive names.
bpf0 Berkeley packet filter.
cd0 First SCSI CD-ROM drive.
ch0 SCSI CD-ROM changer (juke box)
console System console, the device that receives console messages. Initially it is /dev/ttyv0, but it can be changed.
cuaa0 First serial port in callout mode.
cuaia0 First serial port in callout mode, initial state. Note the letter i for initial.
cuala0 First serial port in callout mode, lock state. Note the letter l for lock.
da0 First SCSI disk drive. See "Chapter 2" , page 38, for a complete list of disk drive names.
esa0 First SCSI tape drive, eject on close mode.
fd File descriptor pseudo-devices: a directory containing pseudo-devices that, when opened, return a duplicate of the file descriptor with the same number. For example, if you open /dev/fd/0, you get another handle on your stdin stream (file descriptor 0).
fd0 The first floppy disk drive, accessed as a file system.
kmem Kernel virtual memory pseudo-device.
lpt0 First parallel printer.
mem Physical virtual memory pseudo-device.
nsa0 First SCSI tape drive, no-rewind mode.
null The "bit bucket." Send data to this device if you never want to see it again.
psm0 PS/2 mouse.
ptyp0 First master pseudo-terminal. Master pseudo-terminals are named /dev/ptyp0 through /dev/ptypv, /dev/ptyq0 through /dev/ptyqv, /dev/ptyr0 through /dev/ptyrv, /dev/ptys0 through /dev/ptysv, /dev/ptyP0 through /dev/ptyPv, /dev/ptyQ0 through /dev/ptyQv, /dev/ptyR0 through /dev/ptyRv and /dev/ptyS0 through /dev/ptySv.
random Random number generator.
sa0 First SCSI tape drive, rewind on close mode.
sysmouse System mouse, controlled by moused. We’ll look at this again on page 519.
tty Current controlling terminal.
ttyd0 First serial port in callin mode.
ttyid0 First serial port in callin mode, initial state.
ttyld0 First serial port in callin mode, lock state.
ttyp0 First slave pseudo-terminal. Slave pseudo-terminals are named /dev/ttyp0 through /dev/ttypv, /dev/ttyq0 through /dev/ttyqv, /dev/ttyr0 through /dev/ttyrv, /dev/ttys0 through /dev/ttysv, /dev/ttyP0 through /dev/ttyPv, /dev/ttyQ0 through /dev/ttyQv, /dev/ttyR0 through /dev/ttyRv and /dev/ttyS0 through /dev/ttySv. Some processes, such as xterm, only look at /dev/ttyp0 through /dev/ttysv.
ttyv0 First virtual tty. This is the display with which the system starts. Up to 10 virtual ttys can be activated by adding the appropriate getty information in the file /etc/ttys. See "Chapter 19" , page 338, for further details.
ugen0 First generic USB device.
ukbd0 First USB keyboard.
ulpt0 First USB printer.
umass0 First USB mass storage device.
ums0 First USB mouse.
uscanner0 First USB scanner.
vinum Directory for Vinum device nodes. See "Chapter 12" , for further details.
zero Dummy device that always returns the value (binary) 0 when read.

You'll note a number of different modes associated with the serial ports. We'll look at them again in "Chapter 19" .

Virtual terminals

As we have seen, UNIX is a multitasking operating system, but a PC generally only has one screen. FreeBSD solves this problem with virtual terminals. When in text mode, you can change between up to 16 different screens with the combination of the Alt key and a function key. The devices are named /dev/ttyv0 through /dev/ttyv15 and correspond to the keystrokes Alt-Fl through Alt-F16. By default, three virtual terminals are active: /dev/ttyv0 through /dev/ttyv2. The system console is the virtual terminal /dev/ttyv0 and that's what you see when you boot the machine. To activate additional virtual terminals, edit the file /etc/ttys. There you find:

ttyvO  "/usr/libexec/getty Pc"  cons25  on secure
ttyvl  "/usr/libexec/getty Pc"  cons25  on secure
ttyv2  "/usr/libexec/getty Pc"  cons25  on secure
ttyv3  "/usr/libexec/getty Pc"  cons25  off secure

The key words on and off refer to the state of the terminal: to enable one, set its state to on. To enable extra virtual terminals, add a line with the corresponding terminal name, in the range /dev/ttyv4 to /dev/ttyv15. After you have edited /etc/ttys, you need to tell the system to re-read it in order to start the terminals. Do this as root with this command:

# kill -1 1

Process 1 is init —see page 528 for more details.


In addition to virtual terminals, FreeBSD offers an additional class of terminals called pseudo-terminals. They come in pairs: a master device also called a pry (pronounced pity) is used only by processes that use the interface, and has a name like /dev/ptyp0. The slave device looks like a terminal, and has a name like /dev/ttyp0. Any process can open it without any special knowledge of the interface. These terminals are used for network connections such as xterm, telnet and rlogin. You don't need a getty for pseudo-terminals. Since FreeBSD Release 5.0, pseudo-terminals are created as required.

< Лекция 9 || Лекция 10: 1234 || Лекция 11 >