📄 fsinterface.ms
字号:
*/enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK };struct vnode { u_short v_flag; /* vnode flags (see below) */ u_short v_count; /* reference count */ u_short v_shlockc; /* count of shared locks */ u_short v_exlockc; /* count of exclusive locks */ struct vfs *v_vfsmountedhere; /* ptr to vfs mounted here */ struct vfs *v_vfsp; /* ptr to vfs we are in */ struct vnodeops *v_op; /* vnode operations */\fB+\fP struct text *v_text; /* text/mapped region */ enum vtype v_type; /* vnode type */ caddr_t v_data; /* private data for fs */};.DE.DS.ta \w'#define\0\0'u +\w'NOFOLLOW\0\0'u +\w'0x40\0\0\0\0\0\0\0'u/* * vnode flags. */#define VROOT 0x01 /* root of its file system */#define VTEXT 0x02 /* vnode is a pure text prototype */#define VEXLOCK 0x10 /* exclusive lock */#define VSHLOCK 0x20 /* shared lock */#define VLWAIT 0x40 /* proc is waiting on shared or excl. lock */.DE.LPThe operations supported by the filesystems on individual \fIvnode\fP\^sare:.DS.ta .5i +\w'int\0\0\0\0\0'u +\w'(*vn_getattr)(\0\0\0\0\0'u/* * Operations on vnodes. */struct vnodeops {\fB!\fP int (*vn_lookup)( /* ndp */ );\fB!\fP int (*vn_create)( /* ndp, vap, fflags */ );\fB+\fP int (*vn_mknod)( /* ndp, vap, fflags */ );\fB!\fP int (*vn_open)( /* vp, fflags, cred */ ); int (*vn_close)( /* vp, fflags, cred */ ); int (*vn_access)( /* vp, fflags, cred */ ); int (*vn_getattr)( /* vp, vap, cred */ ); int (*vn_setattr)( /* vp, vap, cred */ );\fB+\fP int (*vn_read)( /* vp, uiop, offp, ioflag, cred */ );\fB+\fP int (*vn_write)( /* vp, uiop, offp, ioflag, cred */ );\fB!\fP int (*vn_ioctl)( /* vp, com, data, fflag, cred */ ); int (*vn_select)( /* vp, which, cred */ );\fB+\fP int (*vn_mmap)( /* vp, ..., cred */ ); int (*vn_fsync)( /* vp, cred */ );\fB+\fP int (*vn_seek)( /* vp, offp, off, whence */ );\fB!\fP int (*vn_remove)( /* ndp */ );\fB!\fP int (*vn_link)( /* vp, ndp */ );\fB!\fP int (*vn_rename)( /* src ndp, target ndp */ );\fB!\fP int (*vn_mkdir)( /* ndp, vap */ );\fB!\fP int (*vn_rmdir)( /* ndp */ );\fB!\fP int (*vn_symlink)( /* ndp, vap, nm */ ); int (*vn_readdir)( /* vp, uiop, offp, ioflag, cred */ ); int (*vn_readlink)( /* vp, uiop, ioflag, cred */ );\fB+\fP int (*vn_abortop)( /* ndp */ );\fB+\fP int (*vn_lock)( /* vp */ );\fB+\fP int (*vn_unlock)( /* vp */ );\fB!\fP int (*vn_inactive)( /* vp */ );};.DE.DS.ta \w'#define\0\0'u +\w'NOFOLLOW\0\0'u +\w'0x40\0\0\0\0\0'u/* * flags for ioflag */#define IO_UNIT 0x01 /* do io as atomic unit for VOP_RDWR */#define IO_APPEND 0x02 /* append write for VOP_RDWR */#define IO_SYNC 0x04 /* sync io for VOP_RDWR */.DE.LPThe argument types listed in the comments following each operation are:.sp.IP ndp 10A pointer to a \fInameidata\fP structure..IP vapA pointer to a \fIvattr\fP structure (vnode attributes; see below)..IP fflagsFile open flags, possibly including O_APPEND, O_CREAT, O_TRUNC and O_EXCL..IP vpA pointer to a \fIvnode\fP previously obtained with \fIvn_lookup\fP..IP credA pointer to a \fIucred\fP credentials structure..IP uiopA pointer to a \fIuio\fP structure..IP ioflagAny of the IO flags defined above..IP comAn \fIioctl\fP command, with type \fIunsigned long\fP..IP dataA pointer to a character buffer used to pass data to or from an \fIioctl\fP..IP whichOne of FREAD, FWRITE or 0 (select for exceptional conditions)..IP offA file offset of type \fIoff_t\fP..IP offpA pointer to file offset of type \fIoff_t\fP..IP whenceOne of L_SET, L_INCR, or L_XTND..IP fhpA pointer to a file handle buffer..sp.PPSeveral changes have been made to Sun's set of vnode operations.Most obviously, the \fIvn_lookup\fP receives a \fInameidata\fP structurecontaining its arguments and context as described.The same structure is also passed to one of the creation or deletionentries if the lookup operation is for CREATE or DELETE to completean operation, or to the \fIvn_abortop\fP entry if no operationis undertaken.For filesystems that perform no locking between lookup for creationor deletion and the call to implement that action,the final pathname component may be left untranslated by the lookuproutine.In any case, the pathname pointer points at the final name component,and the \fInameidata\fP contains a reference to the vnode of the parentdirectory.The interface is thus flexible enough to accommodate filesystemsthat are fully stateful or fully stateless, while avoiding redundantoperations whenever possible.One operation remains problematical, the \fIvn_rename\fP call.It is tempting to look up the source of the rename for deletionand the target for creation.However, filesystems that lock directories during such lookups must avoiddeadlock if the two paths cross.For that reason, the source is translated for LOOKUP only,with the WANTPARENT flag set;the target is then translated with an operation of CREATE..PPIn addition to the changes concerned with the \fInameidata\fP interface,several other changes were made in the vnode operations.The \fIvn_rdrw\fP entry was split into \fIvn_read\fP and \fIvn_write\fP;frequently, the read/write entry amounts to a routine that checksthe direction flag, then calls either a read routine or a write routine.The two entries may be identical for any given filesystem;the direction flag is contained in the \fIuio\fP given as an argument..PPAll of the read and write operations use a \fIuio\fP to describethe file offset and buffer locations.All of these fields must be updated before return.In particular, the \fIvn_readdir\fP entry uses thisto return a new file offset token for its current location..PPSeveral new operations have been added.The first, \fIvn_seek\fP, is a concession to record-oriented filessuch as directories.It allows the filesystem to verify that a seek leaves a file at a sensibleoffset, or to return a new offset token relative to an earlier one.For most filesystems and files, this operation amounts to performingsimple arithmetic.Another new entry point is \fIvn_mmap\fP, for use in mapping device memoryinto a user process address space.Its semantics are not yet decided.The final additions are the \fIvn_lock\fP and \fIvn_unlock\fP entries.These are used to request that the underlying file be locked againstchanges for short periods of time if the filesystem implementation allows it.They are used to maintain consistencyduring internal operations such as \fIexec\fP,and may not be used to construct atomic operations from other filesystemoperations..PPThe attributes of a vnode are not stored in the vnode,as they might change with time and may need to be read from a remotesource.Attributes have the form:.DS.ta .5i +\w'struct vnodeops\0\0'u +\w'*v_vfsmountedhere;\0\0\0'u/* * Vnode attributes. A field value of -1 * represents a field whose value is unavailable * (getattr) or which is not to be changed (setattr). */struct vattr { enum vtype va_type; /* vnode type (for create) */ u_short va_mode; /* files access mode and type */\fB!\fP uid_t va_uid; /* owner user id */\fB!\fP gid_t va_gid; /* owner group id */ long va_fsid; /* file system id (dev for now) */\fB!\fP long va_fileid; /* file id */ short va_nlink; /* number of references to file */ u_long va_size; /* file size in bytes (quad?) */\fB+\fP u_long va_size1; /* reserved if not quad */ long va_blocksize; /* blocksize preferred for i/o */ struct timeval va_atime; /* time of last access */ struct timeval va_mtime; /* time of last modification */ struct timeval va_ctime; /* time file changed */ dev_t va_rdev; /* device the file represents */ u_long va_bytes; /* bytes of disk space held by file */\fB+\fP u_long va_bytes1; /* reserved if va_bytes not a quad */};.DE.SHConclusions.PPThe Sun VFS filesystem interface is the most widely used genericfilesystem interface.Of the interfaces examined, it creates the cleanest separationbetween the filesystem-independent and -dependent layers and data structures.It has several flaws, but it is felt that certain changes in the interfacecan ameliorate most of them.The interface proposed here includes those changes.The proposed interface is now being implemented by the Computer SystemsResearch Group at Berkeley.If the design succeeds in improving the flexibility and performanceof the filesystem layering, it will be advanced as a model interface..SHAcknowledgements.PPThe filesystem interface described here is derived from Sun's VFS interface.It also includes features similar to those of DEC's GFS interface.We are indebted to members of the Sun and DEC system groupsfor long discussions of the issues involved..br.ne 2i.SHReferences.IP Brownbridge82 \w'Satyanarayanan85\0\0'uBrownbridge, D.R., L.F. Marshall, B. Randell,``The Newcastle Connection, or UNIXes of the World Unite!,''\fISoftware\- Practice and Experience\fP, Vol. 12, pp. 1147-1162, 1982..IP Cole85Cole, C.T., P.B. Flinn, A.B. Atlas,``An Implementation of an Extended File System for UNIX,''\fIUsenix Conference Proceedings\fP,pp. 131-150, June, 1985..IP Kleiman86``Vnodes: An Architecture for Multiple File System Types in Sun UNIX,''\fIUsenix Conference Proceedings\fP,pp. 238-247, June, 1986..IP Leffler84Leffler, S., M.K. McKusick, M. Karels,``Measuring and Improving the Performance of 4.2BSD,''\fIUsenix Conference Proceedings\fP, pp. 237-252, June, 1984..IP McKusick84McKusick, M.K., W.N. Joy, S.J. Leffler, R.S. Fabry,``A Fast File System for UNIX,'' \fITransactions on Computer Systems\fP,Vol. 2, pp. 181-197,ACM, August, 1984..IP McKusick85McKusick, M.K., M. Karels, S. Leffler,``Performance Improvements and Functional Enhancements in 4.3BSD,''\fIUsenix Conference Proceedings\fP, pp. 519-531, June, 1985..IP Rifkin86Rifkin, A.P., M.P. Forbes, R.L. Hamilton, M. Sabrio, S. Shah, and K. Yueh,``RFS Architectural Overview,'' \fIUsenix Conference Proceedings\fP,pp. 248-259, June, 1986..IP Ritchie74Ritchie, D.M. and K. Thompson, ``The Unix Time-Sharing System,''\fICommunications of the ACM\fP, Vol. 17, pp. 365-375, July, 1974..IP Rodriguez86Rodriguez, R., M. Koehler, R. Hyde,``The Generic File System,'' \fIUsenix Conference Proceedings\fP,pp. 260-269, June, 1986..IP Sandberg85Sandberg, R., D. Goldberg, S. Kleiman, D. Walsh, B. Lyon,``Design and Implementation of the Sun Network Filesystem,''\fIUsenix Conference Proceedings\fP,pp. 119-130, June, 1985..IP Satyanarayanan85Satyanarayanan, M., \fIet al.\fP,``The ITC Distributed File System: Principles and Design,''\fIProc. 10th Symposium on Operating Systems Principles\fP, pp. 35-50,ACM, December, 1985..IP Walker85Walker, B.J. and S.H. Kiser, ``The LOCUS Distributed Filesystem,''\fIThe LOCUS Distributed System Architecture\fP,G.J. Popek and B.J. Walker, ed., The MIT Press, Cambridge, MA, 1985..IP Weinberger84Weinberger, P.J., ``The Version 8 Network File System,''\fIUsenix Conference presentation\fP,June, 1984.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -