⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2.2.t

📁 早期freebsd实现
💻 T
📖 第 1 页 / 共 2 页
字号:
.\" Copyright (c) 1983, 1993.\"	The Regents of the University of California.  All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\"    notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\"    notice, this list of conditions and the following disclaimer in the.\"    documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\"    must display the following acknowledgement:.\"	This product includes software developed by the University of.\"	California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\"    may be used to endorse or promote products derived from this software.\"    without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\"	@(#)2.2.t	8.1 (Berkeley) 6/8/93.\".sh "File system.NH 3Overview.PPThe file system abstraction provides access to a hierarchicalfile system structure.The file system contains directories (each of which may containother sub-directories) as well as files and references to otherobjects such as devices and inter-process communications sockets..PPEach file is organized as a linear array of bytes.  No recordboundaries or system related information is present ina file.Files may be read and written in a random-access fashion.The user may read the data in a directory as thoughit were an ordinary file to determine the names of the contained files,but only the system may write into the directories.The file system stores only a small amount of ownership, protection and usageinformation with a file..NH 3Naming.PPThe file system calls take \fIpath name\fP arguments.These consist of a zero or more component \fIfile names\fPseparated by ``/\^'' characters, where each file nameis up to 255 ASCII characters excluding null and ``/\^''..PPEach process always has two naming contexts: one for theroot directory of the file system and one for thecurrent working directory.  These are usedby the system in the filename translation process.If a path name begins with a ``/\^'', it is calleda full path name and interpreted relative to the root directory context.If the path name does not begin with a ``/\^'' it is calleda relative path name and interpreted relative to the current directorycontext..PPThe system limitsthe total length of a path name to 1024 characters..PPThe file name ``..'' in each directory refers tothe parent directory of that directory.The parent directory of the root of the file system is always that directory..PPThe calls.DSchdir(path);char *path;chroot(path)char *path;.DEchange the current working directory and root directory context of a process.Only the super-user can change the root directory context of a process..NH 3Creation and removal.PPThe file system allows directories, files, special devices,and ``portals'' to be created and removed from the file system..NH 4Directory creation and removal.PPA directory is created with the \fImkdir\fP system call:.DSmkdir(path, mode);char *path; int mode;.DEwhere the mode is defined as for files (see below).Directories are removed with the \fIrmdir\fP system call:.DSrmdir(path);char *path;.DEA directory must be empty if it is to be deleted..NH 4File creation.PPFiles are created with the \fIopen\fP system call,.DSfd = open(path, oflag, mode);result int fd; char *path; int oflag, mode;.DEThe \fIpath\fP parameter specifies the name of thefile to be created.  The \fIoflag\fP parameter mustinclude O_CREAT from below to cause the file to be created.Bits for \fIoflag\fP aredefined in \fI<sys/file.h>\fP:.DS._d#define	O_RDONLY	000	/* open for reading */#define	O_WRONLY	001	/* open for writing */#define	O_RDWR	002	/* open for read & write */#define	O_NDELAY	004 	/* non-blocking open */#define	O_APPEND	010	/* append on each write */#define	O_CREAT	01000	/* open with file create */#define	O_TRUNC	02000	/* open with truncation */#define	O_EXCL	04000	/* error on create if file exists */.DE.PPOne of O_RDONLY, O_WRONLY and O_RDWR should be specified,indicating what types of operations are desired to be performedon the open file.  The operations will be checked against the user'saccess rights to the file before allowing the \fIopen\fP to succeed.Specifying O_APPEND causes writes to automatically append to thefile.The flag O_CREAT causes the file to be created if it does notexist, owned by the current userand the group of the containing directory.The protection for the new file is specified in \fImode\fP.The file mode is used as a three digit octal number.Each digit encodes read access as 4, write access as 2 and executeaccess as 1, or'ed together.  The 0700 bits describe owneraccess, the 070 bits describe the access rights for processes in the samegroup as the file, and the 07 bits describe the access rightsfor other processes..PPIf the open specifies to create the file with O_EXCLand the file already exists, then the \fIopen\fP will failwithout affecting the file in any way.  This provides asimple exclusive access facility.If the file exists but is a symbolic link, the open will failregardless of the existence of the file specified by the link..NH 4Creating references to devices.PPThe file system allows entries which reference peripheral devices.Peripherals are distinguished as \fIblock\fP or \fIcharacter\fPdevices according by their ability to support block-orientedoperations.Devices are identified by their ``major'' and ``minor''device numbers.  The major device number determines the kindof peripheral it is, while the minor device number indicatesone of possibly many peripherals of that kind.Structured devices have all operations performed internallyin ``block'' quantities whileunstructured devices often have a number ofspecial \fIioctl\fP operations, and may have input and outputperformed in varying units.The \fImknod\fP call creates special entries:.DSmknod(path, mode, dev);char *path; int mode, dev;.DEwhere \fImode\fP is formed from the object typeand access permissions.  The parameter \fIdev\fP is a configurationdependent parameter used to identify specific character orblock I/O devices..NH 4Portal creation\(dg.PP.FS\(dg The \fIportal\fP call is not implemented in 4.3BSD..FEThe call.DSfd = portal(name, server, param, dtype, protocol, domain, socktype)result int fd; char *name, *server, *param; int dtype, protocol;int domain, socktype;.DEplaces a \fIname\fP in the file system name space that causes connection to aserver process when the name is used.The portal call returns an active portal in \fIfd\fP as though anaccess had occurred to activate an inactive portal, as now described..PPWhen an inactive portal is accessed, the system sets up a socketof the specified \fIsocktype\fP in the specified communications\fIdomain\fP (see section 2.3), and creates the \fIserver\fP process,giving it the specified \fIparam\fP as argument to help it identifythe portal, and also giving it the newly created socket as descriptornumber 0.  The accessor of the portal will create a socket in the same\fIdomain\fP and \fIconnect\fP to the server.  The user will then\fIwrap\fP the socket in the specified \fIprotocol\fP to create an object ofthe required descriptor type \fIdtype\fP and proceed with theoperation which was in progress before the portal was encountered..PPWhile the server process holds the socket (which it received as \fIfd\fPfrom the \fIportal\fP call on descriptor 0 at activation) further referenceswill result in connections being made to the same socket..NH 4File, device, and portal removal.PPA reference to a file, special device or portal may be removed with the\fIunlink\fP call,.DSunlink(path);char *path;.DEThe caller must have write access to the directory in whichthe file is located for this call to be successful..NH 3Reading and modifying file attributes.PPDetailed information about the attributes of a filemay be obtained with the calls:.DS#include <sys/stat.h>stat(path, stb);char *path; result struct stat *stb;fstat(fd, stb);int fd; result struct stat *stb;.DE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -