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

📄 2.2.t

📁 早期freebsd实现
💻 T
📖 第 1 页 / 共 2 页
字号:
The \fIstat\fP structure includes the filetype, protection, ownership, access times,size, and a count of hard links.If the file is a symbolic link, then the status of the linkitself (rather than the file the link references)may be found using the \fIlstat\fP call:.DSlstat(path, stb);char *path; result struct stat *stb;.DE.PPNewly created files are assigned the user id of theprocess that created it and the group id of the directoryin which it was created.  The ownership of a file maybe changed by either of the calls.DSchown(path, owner, group);char *path; int owner, group;fchown(fd, owner, group);int fd, owner, group;.DE.PPIn addition to ownership, each file has three levels of accessprotection associated with it.  These levels are owner relative,group relative, and global (all users and groups).  Each levelof access has separate indicators for read permission, writepermission, and execute permission.The protection bits associated with a file may be set by eitherof the calls:.DSchmod(path, mode);char *path; int mode;fchmod(fd, mode);int fd, mode;.DEwhere \fImode\fP is a value indicating the new protectionof the file, as listed in section 2.2.3.2..PPFinally, the access and modify times on a file may be set by the call:.DSutimes(path, tvp)char *path; struct timeval *tvp[2];.DEThis is particularly useful when moving files between media, topreserve relationships between the times the file was modified..NH 3Links and renaming.PPLinks allow multiple names for a fileto exist.  Links exist independently of the file linked to..PPTwo types of links exist, \fIhard\fP links and \fIsymbolic\fPlinks.  A hard link is a reference counting mechanism thatallows a file to have multiple names within the same filesystem.  Symbolic links cause string substitutionduring the pathname interpretation process..PPHard links and symbolic links have differentproperties.  A hard link insures the targetfile will always be accessible, even after its originaldirectory entry is removed; no such guarantee exists for a symbolic link.Symbolic links can span file systems boundaries..PPThe following calls create a new link, named \fIpath2\fP,to \fIpath1\fP:.DSlink(path1, path2);char *path1, *path2;symlink(path1, path2);char *path1, *path2;.DEThe \fIunlink\fP primitive may be used to removeeither type of link. .PPIf a file is a symbolic link, the ``value'' of thelink may be read with the \fIreadlink\fP call,.DSlen = readlink(path, buf, bufsize);result int len; result char *path, *buf; int bufsize;.DEThis call returns, in \fIbuf\fP, the null-terminated stringsubstituted into pathnames passing through \fIpath\fP\|..PPAtomic renaming of file system resident objects is possiblewith the \fIrename\fP call:.DSrename(oldname, newname);char *oldname, *newname;.DEwhere both \fIoldname\fP and \fInewname\fP must bein the same file system.If \fInewname\fP exists and is a directory, then it must be empty..NH 3Extension and truncation.PPFiles are created with zero length and may be extendedsimply by writing or appending to them.  While a file isopen the system maintains a pointer into the fileindicating the current location in the file associated withthe descriptor.  This pointer may be moved about in thefile in a random access fashion.To set the current offset into a file, the \fIlseek\fPcall may be used,.DSoldoffset = lseek(fd, offset, type);result off_t oldoffset; int fd; off_t offset; int type;.DEwhere \fItype\fP is given in \fI<sys/file.h>\fP as one of:.DS._d#define	L_SET	0	/* set absolute file offset */#define	L_INCR	1	/* set file offset relative to current position */#define	L_XTND	2	/* set offset relative to end-of-file */.DEThe call ``lseek(fd, 0, L_INCR)''returns the current offset into the file..PPFiles may have ``holes'' in them.  Holes are void areas in thelinear extent of the file where data has never beenwritten.  These may be created by seeking toa location in a file past the current end-of-file and writing.Holes are treated by the system as zero valued bytes..PPA file may be truncated with either of the calls:.DStruncate(path, length);char *path; int length;ftruncate(fd, length);int fd, length;.DEreducing the size of the specified file to \fIlength\fP bytes..NH 3Checking accessibility.PPA process running withdifferent real and effective user idsmay interrogate the accessibility of a file to thereal user by usingthe \fIaccess\fP call:.DSaccessible = access(path, how);result int accessible; char *path; int how;.DEHere \fIhow\fP is constructed by or'ing the following bits, definedin \fI<sys/file.h>\fP:.DS._d#define	F_OK	0	/* file exists */#define	X_OK	1	/* file is executable */#define	W_OK	2	/* file is writable */#define	R_OK	4	/* file is readable */.DEThe presence or absence of advisory locks does not affect theresult of \fIaccess\fP\|..NH 3Locking.PPThe file system provides basic facilities that allow cooperating processesto synchronize their access to shared files.  A process mayplace an advisory \fIread\fP or \fIwrite\fP lock on a file,so that other cooperating processes may avoid interferingwith the process' access.  This simple mechanismprovides locking with file granularity.  More granularlocking can be built using the IPC facilities to provide a lockmanager.The system does not force processes to obey the locks;they are of an advisory nature only..PPLocking is performed after an \fIopen\fP call by applying the\fIflock\fP primitive,.DSflock(fd, how);int fd, how;.DEwhere the \fIhow\fP parameter is formed from bits defined in \fI<sys/file.h>\fP:.DS._d#define	LOCK_SH	1	/* shared lock */#define	LOCK_EX	2	/* exclusive lock */#define	LOCK_NB	4	/* don't block when locking */#define	LOCK_UN	8	/* unlock */.DESuccessive lock calls may be used to increase ordecrease the level of locking.  If an object is currentlylocked by another process when a \fIflock\fP call is made,the caller will be blocked until the current lock ownerreleases the lock; this may be avoided by including LOCK_NBin the \fIhow\fP parameter.Specifying LOCK_UN removes all locks associated with the descriptor.Advisory locks held by a process are automatically deleted whenthe process terminates..NH 3Disk quotas.PPAs an optional facility, each file system may be requested toimpose limits on a user's disk usage.Two quantities are limited: the total amount of disk space whicha user may allocate in a file system and the total number of filesa user may create in a file system.  Quotas are expressed as\fIhard\fP limits and \fIsoft\fP limits.  A hard limit isalways imposed; if a user would exceed a hard limit, the operationwhich caused the resource request will fail.  A soft limit resultsin the user receiving a warning message, but with allocation succeeding.Facilities are provided to turn soft limits into hard limits if auser has exceeded a soft limit for an unreasonable period of time..PPTo enable disk quotas on a file system the \fIsetquota\fP callis used:.DSsetquota(special, file)char *special, *file;.DEwhere \fIspecial\fP refers to a structured device file wherea mounted file system exists, and\fIfile\fP refers to a disk quota file (residing on the filesystem associated with \fIspecial\fP) from which user quotasshould be obtained.  The format of the disk quota file is implementation dependent..PPTo manipulate disk quotas the \fIquota\fP call is provided:.DS#include <sys/quota.h>quota(cmd, uid, arg, addr)int cmd, uid, arg; caddr_t addr;.DEThe indicated \fIcmd\fP is applied to the user ID \fIuid\fP.The parameters \fIarg\fP and \fIaddr\fP are command specific.The file \fI<sys/quota.h>\fP contains definitions pertinent to theuse of this call.

⌨️ 快捷键说明

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