One of the most revolutionary concepts of the UNIX operating system was its file system the way in which it stores data. Although most other operating systems have copied it since then, including Microsoft's platforms, none have come close to the
We've already looked at file naming conventions on page 125. In the next section, we'll look at the file system access, structure and hierarchy, and on page 195 we'll look at how the file system treats
A UNIX system may potentially be used by many people, so UNIX includes a method of protecting data from access by
For example, you might have a program that accesses
Traditionally, the permissions are represented by three groups of rwx: r stands for read permission, w stands for write permission, and x stands for execute permission. The three groups represent the permissions for the owner, the group and others respectively. If the permission is not granted, it is represented by a -). Thus, the permissions for the program I discussed above would be r-x------ (I can read and execute the program, and nobody else can do anything with it). The permissions for the draft document would be rw-r----- (I can read and write, the group can read, and others can't access it).
Typical FreeBSD file rwxr-xr-x for programs and rw-r--r-- for other systcode files. In some cases, however, you'll find that other permissions are required. For example, the file ~/.rhosts, which is used by some network programs for user validation, may contain the user's password in legible form. To help ensure that other people don't read it, the network programs refuse to read it unless its permissions are rw-------. The vast majority of system problems in UNIX can be traced to in correct permissions, so you should pay particular
Apart from these ps command on page 185. ls represents the setuid bit by setting the third letter of the permissions string to s instead of x; similarly, It represents the setgid bit by setting the sixth letter of the permissions string to s instead of x.
In addition to this access information, the permissions contain a character that describes what kind of file it represents. The first letter may be a - (ls(1) for a full list.
To list files and show the permissions, use the ls command with the -l option:
$ ls -l total 2429 -rw-rw-r-- 1 grog wheel 28204 Jan 4 14:17 %backup%? drwxrwxr-x 3 grog wheel 512 Oct 11 15:26 2.1.0-951005-SNAP drwx------ 4 grog wheel 512 Nov 25 17:23 Mail -rw-rw-r-- 1 grog wheel 149 Dec 4 14:18 Makefile -rw-rw-r-- 1 grog wheel 108 Dec 4 12:36 Makefile.bak -rw-rw-r-- 1 grog wheel 108 Dec 4 12:36 Makefile? -rw-rw-r-- 1 grog wheel 0 Dec 4 12:36 depend -rw-rw-r-- 1 daemon wheel 1474560 Dec 14 17:03 deppert.floppy -rwxr-xr-x 1 grog wheel 100 Dec 19 15:24 doio -rwxrwxr-x 1 grog wheel 204 Dec 19 15:25 doiovm -rwxrwxr-x 1 grog wheel 204 Dec 19 15:16 doiovm~ -rwxr-xr-x 1 grog wheel 115 Dec 26 08:42 dovm -rwxr-xr-x 1 grog wheel 114 Dec 19 15:30 dovm~ drwxr-xr-x 2 grog wheel 512 Oct 16 1994 emacs drwxrwxrwx 2 grog wheel 512 Jan 3 14:07 letters
This format shows the following information:
link count. This is the number of hard links to the file. For a regular file, this is normally 1, but directories have at least 2. We look at links on page 186.daemon This was probably an -u, option to ls you can list the last time the file was accessed.A couple of the permissions are of interest. The directories all have the x (execute) permission bit set. This enables accessing (i.e. opening) files in the directory—that's the way the term execute is defined for a directory. If l reset the execute permission, I can still list the names of the files, but I can't access them.
I am the only person who can access the directory Mail This is the normal permission for a mail directory.
Often enough, you may want to
chown. For example, to change the ownership of the file deppert.floppy, which in the list above belongs to dacodeon, root would enter:
# chown grog deppert.floppy
Note that only root may perform this operation.
chgrp, which works in the same way as chown. To change the group ownership to lemis, you would enter:
# chgrp lemis deppert.floppy
chown can also change both the owner and the group. Instead of the two previous examples, you could enter:
# chown grog:lemis deppert.floppy
This changes the owner to grog, as before, and also changes the group to lemis
chmod program. chmod has a number of different formats, but unfortunately the nine-character representation isn't one of the code. Read the man page chmod(1) for the full story, but you can achieve just about anything you want with one of the formats shown in table 10-1 | Specification | Effect |
|---|---|
go-w | Deny write permission to group and others |
=rw,+X | Set the read and write permissions to the usual defaults, but retain any execute permissions that are currently set |
+X | Make a directory or file |
u=rwx,go=rx | Make a file readable/executable by everyone and |
go= | Clear all mode bits for group and others |
g=u-w | Set the group bits equal to the user bits, but clear the group write bit |
None of this tells us what the permissions for new files are going to be. The wrong choice could be disastrous. For example, if files were automatically created with the permissions rwxrwxrwx anybody could access thcode in any way. On the other hand, creating thcode with r-------- could result in a lot of
As if this weren't confusing enough, it's specified in the 0 to 7. Each 0 to 9 and a to f .The original versions of UNIX ran on machines that used the
An example: by default, you want to create files that anybody can read, but only you can write. You set the mask to 022. This corresponds to the binary 000010010
0 is needed to specify that the number is in 0222. Some shells automatically assume that the number is 0, but it's not good practice.
The permissions are allowed where the corresponding bit is 0:
rwxrwxrwx Possible permissions 000010010 umask rwxr-xr-x resultant permissions
By default, files are created without the x bits, whereas directories are created with the allowed x bits, so with this umask a file would be created with the permissions rw-r--r--
umask is a shell command. To set it, just enter:
$ umask 022
It's preferable to set this in your shell initialization file—see page 135 for further details.
Beware of creating a too restrictive umask. For example, you will get into a lot of 377, which creates files that you can only read, and that nobody else can access at all. If you x (executable) bit, you will not be able to access directories you create, and you won't be able to run programs you compile.
File permissions enable one problem that occurs so often that it's worth drawing x bit set. Sometimes this bit gets reset (turned off), for example if you copy it across the Net with ftp. The result looks like this:
$ ps bash: ps: Permission denied $ ls -l /bin/ps -r--r--r-- 1 bin kmem 163840 May 6 06:02 /bin/ps $ su you need to be super user to set ps permission Password: password doesn't echo # chmod +x /bin/ps make it executable # ps now it works PID TT TIME COMMAND 226 p2 0:00.56 su (bash) 239 p2 0:00.02 ps 146 v1 0:00.06 /usr/libexec/getty Pc ttyv1 147 v2 0:00.05 /usr/libexec/getty Pc ttyv2 # ^D exit su $ ps ps: /dev/mem: Permission denied hey! it’s stopped working
Huh? It only worked under su and stopped working when I became a mere mortal again? What's going on here?
There's a second problem with programs like ps: some versions need to be able to access special files, in this case /dev/mem, a special file that addresses the s, which requires becoming super user again:
$ su you need to be super user to set ps permission Password: password doesn't echo # chmod g+s /bin/ps set the setgid bit # ls -l /bin/ps see what it looks like -r-xr-sr-x 1 bin kmem 163840 May 6 06:02 /bin/ps # ^D exit su $ ps now it still works PID TT STAT TIME COMMAND 226 p2 S 0:00.56 su (bash) 239 p2 R+ 0:00.02 ps 146 v1 Is+ 0:00.06 /usr/libexec/getty Pc ttyv1 147 v2 Is+ 0:00.05 /usr/libexec/getty Pc ttyv2
In this example, the permissions in the final result really are the correct permissions for ps. It's impossible to go through the permissions for every standard program. If you suspect that you have the permissions set in correctly, use the permissions of the files on the Live File system CD-ROM as a guideline.
setuid and programs can be a security issue. What happens if the program called ps is really something else, a ps to do its work, and it no longer needs to be set
For some purposes, traditional UNIX permissions are
In UNIX, files are defined by inodes structures on disk that you can't access directly. They contain the meta data, all the information about the file, such as owner, permissions and timestamps. What they don't contain are the things you think of as making up a file: they don't have any data, and they don't have names. Instead, the inode contains information about where the
A directory is simply a special kind of file that contains a list of names and inode numbers: in other words, they assign a name to an Inode, and thus to a file. More than one name can point to the same inode, so files can have more than one name. This connection between a name and an inode is called a link sometimes confusingly hard link. The inode numbers relate to the file system, so files must be in the same file system as the directory that refers to them.
Alternatively, symbolic links sometimes called soft links, are not restricted to the same file system (not even to the same system!), and they refer to another file name, not to the file itself. The difference is most evident if you delete a file: if the file has been hard linked, the other names still exist and you can access the file by them. If you delete a file name that has a
It's not easy to decide which kind of link to use—see UNIX Power Tools (O'Reilly) for more details.
Although Microsoft platforms have a
Nearly every version of UNIX prefers to have at least two file systems, / (the root file system) and /usr even if they only have a single disk. This arrangement is considered more reliable than a single file system: it's possible for a file system to fsck or fsdb to piece them together. We have already discussed this issue on page 68, where I recommend having /usr on the same file system as /.
The physical layout of the file systems does not affect the names or contents of the directories, which are standardized. Table 10-2 gives an over view of the standard FreeBSD directories; see the man page hier(7) for more details.
| Directory name | Usage |
|---|---|
| / | Root file system. Contains a couple of system directories and mount points for other file systems. It should not contain anything else. |
| /bin | |
| /boot | Files used when booting the system, including the kernel and its associated klds. |
| /cdrom | Amount point for |
| /compat | A link to /usr/compat: see below. |
| /dev | Directory of device nodes. The name is an |
| /etc | Configuration files used at system startup. Unlike System V, /etc does not contain kernel build files, which are not needed at system startup. Unlike earlier UNIX versions, it also does not contain executable—they have been moved to /sbin. |
| /home | By convention, put user files here. Despite the name, /usr is for |
| /mnt | A mount point for floppies and other temporary file systems. |
| /proc | The process file system. This directory contains pseudo-files that refer to the |
| /root | The home directory of the user root. In traditional UNIX file systems, root's home directory was /, but this is messy. |
| /sbin | System executable needed at system startup time. These are typically system administration files that used to be stored in /etc. |
| /sys | If present, this is usually a |
| /tmp | A place for |
| /usr | The "second file system." See the discussion above. |
| /usr/XllR6 | The X WindowSystem. |
| /usr/XllR6/bin | Executable X11 programs. |
| /usr/XllR6/include | Header files for X11 programming. |
| /usr/XllR6/lib | Library files for X11. |
| /usr/XllR6/man | Man pages for X11. |
| /usr/bin | Standard |
| /usr/compat | A directory containing code for emulated systems, such as Linux. |
| /usr/games | Games. |
| /usr/include | Header files for programmers. |
| /usr/lib | Library files. FreeBSD does not have a directory /lib. |
| /usr/libexec | Executable files that are not started directly by the user, for example the phases of the C compiler (which are started by /usr/bin/gcc)or the getty program, which is started by init. |
| /usr/libdata | Miscellaneous files used by system utilities. |
| /usr/local | Additional programs that are not part of the operating system. It parallels the /usr directory in having |
| /usr/obj | Object files created when building the system. See Chapter 33 . |
| /usr/ports | The Ports Collection. |
| /usr/sbin | System administration programs that are not needed at system startup. |
| /usr/share | Miscellaneous read-only files, mainly informative. |
| /usr/src | System |
| /var | A file system for data that changes frequently, such as mail, news, and log files. If /var is not a separate file system, you should create a directory on another file system and symlink /var to it. |
| /var/log | Directory with |
| /var/mail | Incoming mail for users on this system |
| /var/spool | Transient data, such as outgoing mail, print data and anonymous ftp. |
| /var/tmp |
FreeBSD supports a number of file system types. The most important are:
mount command and the -t option to specify the file system type. For example:
# mount -t ext2fs /dev/dalsl /linux mount a Linux ext2 file system # mount -t msdos /dev/da2s1 /C: mount a Microsoft FAT file system
Here’s a list of currently supported file systems:
| File system | mount option |
|---|---|
| CD-ROM | cd9660 |
| DVD | udf |
| Linux ext2 | ext2fs |
| Microsoft MS-DOS | msdosfs |
| Microsoft NT | ntfs |
| Novell Netware | nwfs |
| Microsoft CIFS | smbfs |
Soft updates change the way the file –U option when creating the file system. For example:
# newfs -U /dev/da1s2h
If you forget this fag, you can enable them later with tunefs :
# tunefs -n enable /dev/da1s2h
You can't perform this operation on a mounted file system.
One of the problems with backing up file systems is that you don't get a consistent view of the file system: while you copy a file, other programs may be modifying it, so what you get on the tape is not an accurate view of the file at any time. Snapshots are a method to create a unified view of a file system. They maintain a relatively small file in the file system itself containing information on what has changed since the snapshot was taken. When you access the snapshot, you get this data rather than the current data for the parts of the disk which have changed, so you get a view of the file system as it was at the time of the snapshot.
You create snapshots with the mount command and the -o snapshot option. For example, you could enter
# mount -u -o snapshot /var/snapshot/snapl /var
This command creates a snapshot of the /var file
schg fag, you can still remove them.Probably the most useful thing you can do with a snapshot is to take a backup of it. We'll look at backups on page 253.
At the time of writing, snapshots are still under development. It's possible that you might still have
It takes about 30 seconds to create a snapshot of an 8 GB file system. During the last five seconds, file
Microsoft platforms identify partitions by letters that are assigned at /.This flexibility has one problem: you have the choice of where in the overall file mount command. For example, you would typically mount a CD-ROM in the directory /cdrom, but if you have three
# mkdir /cdl only if it doesn't exist # mount -t cd9660 -o ro /dev/cdla /cdl
When the system boots, it calls the startup script /etc/rc, which among other things automatically mounts the file systems. All you need to do is to supply the information: what is to be mounted, and where? This is in the file /etc/fstab. If you come from a System V environment, you'll notice significant difference in format—see the man page fstab(5), for the full story. A typical /etc/fstab might look like:
/dev/ad0s1a / ufs rw 1 1 root file system /dev/ad0s1b none swap sw 0 0 swap /dev/ad0s1e /usr ufs rw 2 2 /usr file system /dev/dalsle /src ufs rw 2 2 additional file system /dev/da2s1 /linux ext2fs rw 2 2 Linux file system /dev/adlsl /C: msdos rw 2 2 Microsoft file system proc /proc procfs rw 0 0 proc pseudo-file system linproc /compat/linux/proc linprocfs rw 0 0 /dev/cd0a /cdrom cd9660 ro 0 0 CD-ROM presto:/ /presto/root nfs rw 0 0 NFS file systems on other systems presto:/usr /presto/usr nfs rw 0 0 presto:/home /presto/home nfs rw 0 0 presto:/S /S nfs rw 0 0 //guestasamba/public /smb smbfs rw,noauto 0 0 SMB file system
The format of the file is reasonably straight forward:
proc or the name of the remote file system for NFS mounts.none.rw for file systems that can be read or written, ro for file systems (like CD-ROM) that can only be read, and sw for swap partitions. It can also contain options like the noauto in the bottom line, which tells the system startup scripts to ignore the line. It's there so that you can use the mount /smb when you want to mount the file system.dump and fsck programs. You won't normally need to change them. Enter 1 for a root file system, 2 for other UFS file systems, and 0 for everything else.So far, our files have all been on devices, also called special files. Sometimes, though, you may want to access the contents of a file as a file system:
In each case, the solution is the same: you mount the files as a device with the md driver.
The md driver creates a number of different kinds of pseudo-device. See the man page md(4).. We use the device, a special file that refers to file md is included in the GENERIC kernel, but if you've built a kernel without the md drive, you can load it as a kld. If you're not sure, try loading the kld anyway.
In the following example, we associate a
# kldload md load the kld module if necessary kldload: can't load md: File exists already loaded or in the kernel # mdconfig -a -t vnode -f iso -image and configure the device md0 this is the name assigned in directory /dev # mount -t cd9660 /dev/md0 /mnt then mount it
After this, you can access the image at /mnt as a normal file system. You specify -t cd9660 in this case because the file system on the image is a CD9660 file system. You don't specify this if you're mounting a UFS file system, for example a snapshot image.
Older versions of FreeBSD used the vn driver, which used different syntax. Linux uses loop mounts, which FreeBSD doesn't support.
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 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
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
# umount /mnt # mdconfig -d -u 0
The parameter 0 refers to md device 0, in other words /dev/md0.
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
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
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.
acd0 | First ata (IDE) |
|---|---|
ad0 | First ata (IDE or similar) |
bpf0 | Berkeley |
cd0 | First SCSI |
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 |
cuaia0 | First i for initial. |
cuala0 | First |
da0 | First SCSI |
esa0 | First SCSI |
fd | 0). |
fd0 | The first |
kmem | Kernel |
lpt0 | First |
mem | Physical |
nsa0 | First SCSI |
null | The "bit |
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 |
sysmouse | System mouse, controlled by moused. We’ll look at this again on page 519. |
tty | Current controlling terminal. |
ttyd0 | First |
ttyid0 | First |
ttyld0 | First |
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 .
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
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 root with this command:
# kill -1 1
Process 1 is init —see page 528 for more details.
In addition to
One of the most revolutionary concepts of the UNIX operating system was its file system the way in which it stores data. Although most other operating systems have copied it since then, including Microsoft's platforms, none have come close to the
We've already looked at file naming conventions on page 125. In the next section, we'll look at the file system access, structure and hierarchy, and on page 195 we'll look at how the file system treats
A UNIX system may potentially be used by many people, so UNIX includes a method of protecting data from access by
For example, you might have a program that accesses
Traditionally, the permissions are represented by three groups of rwx: r stands for read permission, w stands for write permission, and x stands for execute permission. The three groups represent the permissions for the owner, the group and others respectively. If the permission is not granted, it is represented by a -). Thus, the permissions for the program I discussed above would be r-x------ (I can read and execute the program, and nobody else can do anything with it). The permissions for the draft document would be rw-r----- (I can read and write, the group can read, and others can't access it).
Typical FreeBSD file rwxr-xr-x for programs and rw-r--r-- for other systcode files. In some cases, however, you'll find that other permissions are required. For example, the file ~/.rhosts, which is used by some network programs for user validation, may contain the user's password in legible form. To help ensure that other people don't read it, the network programs refuse to read it unless its permissions are rw-------. The vast majority of system problems in UNIX can be traced to in correct permissions, so you should pay particular
Apart from these ps command on page 185. ls represents the setuid bit by setting the third letter of the permissions string to s instead of x; similarly, It represents the setgid bit by setting the sixth letter of the permissions string to s instead of x.
In addition to this access information, the permissions contain a character that describes what kind of file it represents. The first letter may be a - (ls(1) for a full list.
To list files and show the permissions, use the ls command with the -l option:
$ ls -l total 2429 -rw-rw-r-- 1 grog wheel 28204 Jan 4 14:17 %backup%? drwxrwxr-x 3 grog wheel 512 Oct 11 15:26 2.1.0-951005-SNAP drwx------ 4 grog wheel 512 Nov 25 17:23 Mail -rw-rw-r-- 1 grog wheel 149 Dec 4 14:18 Makefile -rw-rw-r-- 1 grog wheel 108 Dec 4 12:36 Makefile.bak -rw-rw-r-- 1 grog wheel 108 Dec 4 12:36 Makefile? -rw-rw-r-- 1 grog wheel 0 Dec 4 12:36 depend -rw-rw-r-- 1 daemon wheel 1474560 Dec 14 17:03 deppert.floppy -rwxr-xr-x 1 grog wheel 100 Dec 19 15:24 doio -rwxrwxr-x 1 grog wheel 204 Dec 19 15:25 doiovm -rwxrwxr-x 1 grog wheel 204 Dec 19 15:16 doiovm~ -rwxr-xr-x 1 grog wheel 115 Dec 26 08:42 dovm -rwxr-xr-x 1 grog wheel 114 Dec 19 15:30 dovm~ drwxr-xr-x 2 grog wheel 512 Oct 16 1994 emacs drwxrwxrwx 2 grog wheel 512 Jan 3 14:07 letters
This format shows the following information:
link count. This is the number of hard links to the file. For a regular file, this is normally 1, but directories have at least 2. We look at links on page 186.daemon This was probably an -u, option to ls you can list the last time the file was accessed.A couple of the permissions are of interest. The directories all have the x (execute) permission bit set. This enables accessing (i.e. opening) files in the directory—that's the way the term execute is defined for a directory. If l reset the execute permission, I can still list the names of the files, but I can't access them.
I am the only person who can access the directory Mail This is the normal permission for a mail directory.
Often enough, you may want to
chown. For example, to change the ownership of the file deppert.floppy, which in the list above belongs to dacodeon, root would enter:
# chown grog deppert.floppy
Note that only root may perform this operation.
chgrp, which works in the same way as chown. To change the group ownership to lemis, you would enter:
# chgrp lemis deppert.floppy
chown can also change both the owner and the group. Instead of the two previous examples, you could enter:
# chown grog:lemis deppert.floppy
This changes the owner to grog, as before, and also changes the group to lemis
chmod program. chmod has a number of different formats, but unfortunately the nine-character representation isn't one of the code. Read the man page chmod(1) for the full story, but you can achieve just about anything you want with one of the formats shown in table 10-1 | Specification | Effect |
|---|---|
go-w | Deny write permission to group and others |
=rw,+X | Set the read and write permissions to the usual defaults, but retain any execute permissions that are currently set |
+X | Make a directory or file |
u=rwx,go=rx | Make a file readable/executable by everyone and |
go= | Clear all mode bits for group and others |
g=u-w | Set the group bits equal to the user bits, but clear the group write bit |
None of this tells us what the permissions for new files are going to be. The wrong choice could be disastrous. For example, if files were automatically created with the permissions rwxrwxrwx anybody could access thcode in any way. On the other hand, creating thcode with r-------- could result in a lot of
As if this weren't confusing enough, it's specified in the 0 to 7. Each 0 to 9 and a to f .The original versions of UNIX ran on machines that used the
An example: by default, you want to create files that anybody can read, but only you can write. You set the mask to 022. This corresponds to the binary 000010010
0 is needed to specify that the number is in 0222. Some shells automatically assume that the number is 0, but it's not good practice.
The permissions are allowed where the corresponding bit is 0:
rwxrwxrwx Possible permissions 000010010 umask rwxr-xr-x resultant permissions
By default, files are created without the x bits, whereas directories are created with the allowed x bits, so with this umask a file would be created with the permissions rw-r--r--
umask is a shell command. To set it, just enter:
$ umask 022
It's preferable to set this in your shell initialization file—see page 135 for further details.
Beware of creating a too restrictive umask. For example, you will get into a lot of 377, which creates files that you can only read, and that nobody else can access at all. If you x (executable) bit, you will not be able to access directories you create, and you won't be able to run programs you compile.
File permissions enable one problem that occurs so often that it's worth drawing x bit set. Sometimes this bit gets reset (turned off), for example if you copy it across the Net with ftp. The result looks like this:
$ ps bash: ps: Permission denied $ ls -l /bin/ps -r--r--r-- 1 bin kmem 163840 May 6 06:02 /bin/ps $ su you need to be super user to set ps permission Password: password doesn't echo # chmod +x /bin/ps make it executable # ps now it works PID TT TIME COMMAND 226 p2 0:00.56 su (bash) 239 p2 0:00.02 ps 146 v1 0:00.06 /usr/libexec/getty Pc ttyv1 147 v2 0:00.05 /usr/libexec/getty Pc ttyv2 # ^D exit su $ ps ps: /dev/mem: Permission denied hey! it’s stopped working
Huh? It only worked under su and stopped working when I became a mere mortal again? What's going on here?
There's a second problem with programs like ps: some versions need to be able to access special files, in this case /dev/mem, a special file that addresses the s, which requires becoming super user again:
$ su you need to be super user to set ps permission Password: password doesn't echo # chmod g+s /bin/ps set the setgid bit # ls -l /bin/ps see what it looks like -r-xr-sr-x 1 bin kmem 163840 May 6 06:02 /bin/ps # ^D exit su $ ps now it still works PID TT STAT TIME COMMAND 226 p2 S 0:00.56 su (bash) 239 p2 R+ 0:00.02 ps 146 v1 Is+ 0:00.06 /usr/libexec/getty Pc ttyv1 147 v2 Is+ 0:00.05 /usr/libexec/getty Pc ttyv2
In this example, the permissions in the final result really are the correct permissions for ps. It's impossible to go through the permissions for every standard program. If you suspect that you have the permissions set in correctly, use the permissions of the files on the Live File system CD-ROM as a guideline.
setuid and programs can be a security issue. What happens if the program called ps is really something else, a ps to do its work, and it no longer needs to be set
For some purposes, traditional UNIX permissions are
In UNIX, files are defined by inodes structures on disk that you can't access directly. They contain the meta data, all the information about the file, such as owner, permissions and timestamps. What they don't contain are the things you think of as making up a file: they don't have any data, and they don't have names. Instead, the inode contains information about where the
A directory is simply a special kind of file that contains a list of names and inode numbers: in other words, they assign a name to an Inode, and thus to a file. More than one name can point to the same inode, so files can have more than one name. This connection between a name and an inode is called a link sometimes confusingly hard link. The inode numbers relate to the file system, so files must be in the same file system as the directory that refers to them.
Alternatively, symbolic links sometimes called soft links, are not restricted to the same file system (not even to the same system!), and they refer to another file name, not to the file itself. The difference is most evident if you delete a file: if the file has been hard linked, the other names still exist and you can access the file by them. If you delete a file name that has a
It's not easy to decide which kind of link to use—see UNIX Power Tools (O'Reilly) for more details.
Although Microsoft platforms have a
Nearly every version of UNIX prefers to have at least two file systems, / (the root file system) and /usr even if they only have a single disk. This arrangement is considered more reliable than a single file system: it's possible for a file system to fsck or fsdb to piece them together. We have already discussed this issue on page 68, where I recommend having /usr on the same file system as /.
The physical layout of the file systems does not affect the names or contents of the directories, which are standardized. Table 10-2 gives an over view of the standard FreeBSD directories; see the man page hier(7) for more details.
| Directory name | Usage |
|---|---|
| / | Root file system. Contains a couple of system directories and mount points for other file systems. It should not contain anything else. |
| /bin | |
| /boot | Files used when booting the system, including the kernel and its associated klds. |
| /cdrom | Amount point for |
| /compat | A link to /usr/compat: see below. |
| /dev | Directory of device nodes. The name is an |
| /etc | Configuration files used at system startup. Unlike System V, /etc does not contain kernel build files, which are not needed at system startup. Unlike earlier UNIX versions, it also does not contain executable—they have been moved to /sbin. |
| /home | By convention, put user files here. Despite the name, /usr is for |
| /mnt | A mount point for floppies and other temporary file systems. |
| /proc | The process file system. This directory contains pseudo-files that refer to the |
| /root | The home directory of the user root. In traditional UNIX file systems, root's home directory was /, but this is messy. |
| /sbin | System executable needed at system startup time. These are typically system administration files that used to be stored in /etc. |
| /sys | If present, this is usually a |
| /tmp | A place for |
| /usr | The "second file system." See the discussion above. |
| /usr/XllR6 | The X WindowSystem. |
| /usr/XllR6/bin | Executable X11 programs. |
| /usr/XllR6/include | Header files for X11 programming. |
| /usr/XllR6/lib | Library files for X11. |
| /usr/XllR6/man | Man pages for X11. |
| /usr/bin | Standard |
| /usr/compat | A directory containing code for emulated systems, such as Linux. |
| /usr/games | Games. |
| /usr/include | Header files for programmers. |
| /usr/lib | Library files. FreeBSD does not have a directory /lib. |
| /usr/libexec | Executable files that are not started directly by the user, for example the phases of the C compiler (which are started by /usr/bin/gcc)or the getty program, which is started by init. |
| /usr/libdata | Miscellaneous files used by system utilities. |
| /usr/local | Additional programs that are not part of the operating system. It parallels the /usr directory in having |
| /usr/obj | Object files created when building the system. See Chapter 33 . |
| /usr/ports | The Ports Collection. |
| /usr/sbin | System administration programs that are not needed at system startup. |
| /usr/share | Miscellaneous read-only files, mainly informative. |
| /usr/src | System |
| /var | A file system for data that changes frequently, such as mail, news, and log files. If /var is not a separate file system, you should create a directory on another file system and symlink /var to it. |
| /var/log | Directory with |
| /var/mail | Incoming mail for users on this system |
| /var/spool | Transient data, such as outgoing mail, print data and anonymous ftp. |
| /var/tmp |
FreeBSD supports a number of file system types. The most important are:
mount command and the -t option to specify the file system type. For example:
# mount -t ext2fs /dev/dalsl /linux mount a Linux ext2 file system # mount -t msdos /dev/da2s1 /C: mount a Microsoft FAT file system
Here’s a list of currently supported file systems:
| File system | mount option |
|---|---|
| CD-ROM | cd9660 |
| DVD | udf |
| Linux ext2 | ext2fs |
| Microsoft MS-DOS | msdosfs |
| Microsoft NT | ntfs |
| Novell Netware | nwfs |
| Microsoft CIFS | smbfs |
Soft updates change the way the file –U option when creating the file system. For example:
# newfs -U /dev/da1s2h
If you forget this fag, you can enable them later with tunefs :
# tunefs -n enable /dev/da1s2h
You can't perform this operation on a mounted file system.
One of the problems with backing up file systems is that you don't get a consistent view of the file system: while you copy a file, other programs may be modifying it, so what you get on the tape is not an accurate view of the file at any time. Snapshots are a method to create a unified view of a file system. They maintain a relatively small file in the file system itself containing information on what has changed since the snapshot was taken. When you access the snapshot, you get this data rather than the current data for the parts of the disk which have changed, so you get a view of the file system as it was at the time of the snapshot.
You create snapshots with the mount command and the -o snapshot option. For example, you could enter
# mount -u -o snapshot /var/snapshot/snapl /var
This command creates a snapshot of the /var file
schg fag, you can still remove them.Probably the most useful thing you can do with a snapshot is to take a backup of it. We'll look at backups on page 253.
At the time of writing, snapshots are still under development. It's possible that you might still have
It takes about 30 seconds to create a snapshot of an 8 GB file system. During the last five seconds, file
Microsoft platforms identify partitions by letters that are assigned at /.This flexibility has one problem: you have the choice of where in the overall file mount command. For example, you would typically mount a CD-ROM in the directory /cdrom, but if you have three
# mkdir /cdl only if it doesn't exist # mount -t cd9660 -o ro /dev/cdla /cdl
When the system boots, it calls the startup script /etc/rc, which among other things automatically mounts the file systems. All you need to do is to supply the information: what is to be mounted, and where? This is in the file /etc/fstab. If you come from a System V environment, you'll notice significant difference in format—see the man page fstab(5), for the full story. A typical /etc/fstab might look like:
/dev/ad0s1a / ufs rw 1 1 root file system /dev/ad0s1b none swap sw 0 0 swap /dev/ad0s1e /usr ufs rw 2 2 /usr file system /dev/dalsle /src ufs rw 2 2 additional file system /dev/da2s1 /linux ext2fs rw 2 2 Linux file system /dev/adlsl /C: msdos rw 2 2 Microsoft file system proc /proc procfs rw 0 0 proc pseudo-file system linproc /compat/linux/proc linprocfs rw 0 0 /dev/cd0a /cdrom cd9660 ro 0 0 CD-ROM presto:/ /presto/root nfs rw 0 0 NFS file systems on other systems presto:/usr /presto/usr nfs rw 0 0 presto:/home /presto/home nfs rw 0 0 presto:/S /S nfs rw 0 0 //guestasamba/public /smb smbfs rw,noauto 0 0 SMB file system
The format of the file is reasonably straight forward:
proc or the name of the remote file system for NFS mounts.none.rw for file systems that can be read or written, ro for file systems (like CD-ROM) that can only be read, and sw for swap partitions. It can also contain options like the noauto in the bottom line, which tells the system startup scripts to ignore the line. It's there so that you can use the mount /smb when you want to mount the file system.dump and fsck programs. You won't normally need to change them. Enter 1 for a root file system, 2 for other UFS file systems, and 0 for everything else.So far, our files have all been on devices, also called special files. Sometimes, though, you may want to access the contents of a file as a file system:
In each case, the solution is the same: you mount the files as a device with the md driver.
The md driver creates a number of different kinds of pseudo-device. See the man page md(4).. We use the device, a special file that refers to file md is included in the GENERIC kernel, but if you've built a kernel without the md drive, you can load it as a kld. If you're not sure, try loading the kld anyway.
In the following example, we associate a
# kldload md load the kld module if necessary kldload: can't load md: File exists already loaded or in the kernel # mdconfig -a -t vnode -f iso -image and configure the device md0 this is the name assigned in directory /dev # mount -t cd9660 /dev/md0 /mnt then mount it
After this, you can access the image at /mnt as a normal file system. You specify -t cd9660 in this case because the file system on the image is a CD9660 file system. You don't specify this if you're mounting a UFS file system, for example a snapshot image.
Older versions of FreeBSD used the vn driver, which used different syntax. Linux uses loop mounts, which FreeBSD doesn't support.
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 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
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
# umount /mnt # mdconfig -d -u 0
The parameter 0 refers to md device 0, in other words /dev/md0.
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
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
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.
acd0 | First ata (IDE) |
|---|---|
ad0 | First ata (IDE or similar) |
bpf0 | Berkeley |
cd0 | First SCSI |
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 |
cuaia0 | First i for initial. |
cuala0 | First |
da0 | First SCSI |
esa0 | First SCSI |
fd | 0). |
fd0 | The first |
kmem | Kernel |
lpt0 | First |
mem | Physical |
nsa0 | First SCSI |
null | The "bit |
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 |
sysmouse | System mouse, controlled by moused. We’ll look at this again on page 519. |
tty | Current controlling terminal. |
ttyd0 | First |
ttyid0 | First |
ttyld0 | First |
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 .
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
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 root with this command:
# kill -1 1
Process 1 is init —see page 528 for more details.
In addition to
Для получения официальных документов о завершении программы дополнительного профессионального образования (удостоверения о повышении квалификации, дипломов о профессиональной переподготовке и MBA) необходимо предоставить:
Внимание! Вы можете не заказывать доставку бумажной версии официального документы, а скачать его в электронном виде и распечатать самостоятельно. Информация о выданном документе в течение 1 месяца загружается в Федеральную информационную систему «Федеральный реестр сведений о документах об образовании и (или) о квалификации, документах об обучении» - ФИС ФРДО.
Доступ на новый сайт осуществляется с использованием адреса электронной почты, который был указан вами при регистрации на "старом". Мы постарались перенести все ваши данные с прежнего ресурса, однако не исключена вероятность потери части информации.
При возникновении проблемы со входом, воспользуйтесь функцией сброса пароля
Если вы обнаружите несоответствия, пожалуйста, сообщите нам.