📄 fsinterface.ms
字号:
For creation or deletion requests, the parameters to the filesystem operationto complete the request are also passed in this same structure.The form of the \fInameidata\fP structure is:.br.ne 2i.ID.nf.ta .5i +\w'caddr_t\0\0\0'u +\w'struct\0\0'u +\w'vnode *nc_prevdir;\0\0\0\0\0'u/* * Encapsulation of namei parameters. * One of these is located in the u. area to * minimize space allocated on the kernel stack * and to retain per-process context. */struct nameidata { /* arguments to namei and related context: */ caddr_t ni_dirp; /* pathname pointer */ enum uio_seg ni_seg; /* location of pathname */ short ni_nameiop; /* see below */ struct vnode *ni_cdir; /* current directory */ struct vnode *ni_rdir; /* root directory, if not normal root */ struct ucred *ni_cred; /* credentials */ /* shared between namei, lookup routines and commit routines: */ caddr_t ni_pnbuf; /* pathname buffer */ char *ni_ptr; /* current location in pathname */ int ni_pathlen; /* remaining chars in path */ short ni_more; /* more left to translate in pathname */ short ni_loopcnt; /* count of symlinks encountered */ /* results: */ struct vnode *ni_vp; /* vnode of result */ struct vnode *ni_dvp; /* vnode of intermediate directory *//* BEGIN UFS SPECIFIC */ struct diroffcache { /* last successful directory search */ struct vnode *nc_prevdir; /* terminal directory */ long nc_id; /* directory's unique id */ off_t nc_prevoffset; /* where last entry found */ } ni_nc;/* END UFS SPECIFIC */};.DE.DS.ta \w'#define\0\0'u +\w'WANTPARENT\0\0'u +\w'0x40\0\0\0\0\0\0\0'u/* * namei operations and modifiers */#define LOOKUP 0 /* perform name lookup only */#define CREATE 1 /* setup for file creation */#define DELETE 2 /* setup for file deletion */#define WANTPARENT 0x10 /* return parent directory vnode also */#define NOCACHE 0x20 /* name must not be left in cache */#define FOLLOW 0x40 /* follow symbolic links */#define NOFOLLOW 0x0 /* don't follow symbolic links (pseudo) */.DEAs in current systems other than Sun's VFS, \fInamei\fP is calledwith an operation request, one of LOOKUP, CREATE or DELETE.For a LOOKUP, the operation is exactly like the lookup in VFS.CREATE and DELETE allow the filesystem to ensure consistencyby locking the parent inode (private to the filesystem),and (for the local filesystem) to avoid duplicate directory scansby storing the new directory entry and its offset in the directoryin the \fIndirinfo\fP structure.This is intended to be opaque to the filesystem-independent levels.Not all lookups for creation or deletion are actually followedby the intended operation; permission may be denied, the filesystemmay be read-only, etc.Therefore, an entry point to the filesystem is providedto abort a creation or deletion operationand allow release of any locked internal data.After a \fInamei\fP with a CREATE or DELETE flag, the pathname pointeris set to point to the last filename component.Filesystems that choose to implement creation or deletion entirelywithin the subsequent call to a create or delete entryare thus free to do so..PPThe \fInameidata\fP is used to store context used during name translation.The current and root directories for the translation are stored here.For the local filesystem, the per-process directory offset cacheis also kept here.A file server could leave the directory offset cache empty,could use a single cache for all clients,or could hold caches for several recent clients..PPSeveral other data structures are used in the filesystem operations.One is the \fIucred\fP structure which describes a client's credentialsto the filesystem.This is modified slightly from the Sun structure;the ``accounting'' group ID has been merged into the groups array.The actual number of groups in the array is given explicitlyto avoid use of a reserved group ID as a terminator.Also, typedefs introduced in 4.3BSD for user and group ID's have been used.The \fIucred\fP structure is thus:.DS.ta .5i +\w'caddr_t\0\0\0'u +\w'struct\0\0'u +\w'vnode *nc_prevdir;\0\0\0\0\0'u/* * Credentials. */struct ucred { u_short cr_ref; /* reference count */ uid_t cr_uid; /* effective user id */ short cr_ngroups; /* number of groups */ gid_t cr_groups[NGROUPS]; /* groups */ /* * The following either should not be here, * or should be treated as opaque. */ uid_t cr_ruid; /* real user id */ gid_t cr_svgid; /* saved set-group id */};.DE.PPA final structure used by the filesystem interface is the \fIuio\fPstructure mentioned earlier.This structure describes the source or destination of an I/Ooperation, with provision for scatter/gather I/O.It is used in the read and write entries to the filesystem.The \fIuio\fP structure presented here is modified from the oneused in 4.2BSD to specify the location of each vector of the operation(user or kernel space)and to allow an alternate function to be used to implement the data movement.The alternate function might perform page remapping rather than a copy,for example..DS.ta .5i +\w'caddr_t\0\0\0'u +\w'struct\0\0'u +\w'vnode *nc_prevdir;\0\0\0\0\0'u/* * Description of an I/O operation which potentially * involves scatter-gather, with individual sections * described by iovec, below. uio_resid is initially * set to the total size of the operation, and is * decremented as the operation proceeds. uio_offset * is incremented by the amount of each operation. * uio_iov is incremented and uio_iovcnt is decremented * after each vector is processed. */struct uio { struct iovec *uio_iov; int uio_iovcnt; off_t uio_offset; int uio_resid; enum uio_rw uio_rw;};enum uio_rw { UIO_READ, UIO_WRITE };.DE.DS.ta .5i +\w'caddr_t\0\0\0'u +\w'vnode *nc_prevdir;\0\0\0\0\0'u/* * Description of a contiguous section of an I/O operation. * If iov_op is non-null, it is called to implement the copy * operation, possibly by remapping, with the call * (*iov_op)(from, to, count); * where from and to are caddr_t and count is int. * Otherwise, the copy is done in the normal way, * treating base as a user or kernel virtual address * according to iov_segflg. */struct iovec { caddr_t iov_base; int iov_len; enum uio_seg iov_segflg; int (*iov_op)();};.DE.DS.ta .5i +\w'UIO_USERISPACE\0\0\0\0\0'u/* * Segment flag values. */enum uio_seg { UIO_USERSPACE, /* from user data space */ UIO_SYSSPACE, /* from system space */ UIO_USERISPACE /* from user I space */};.DE.SHFile and filesystem operations.PPWith the introduction of the data structures used by the filesystemoperations, the complete list of filesystem entry points may be listed.As noted, they derive mostly from the Sun VFS interface.Lines marked with \fB+\fP are additions to the Sun definitions;lines marked with \fB!\fP are modified from VFS..PPThe structure describing the externally-visible features of a mountedfilesystem, \fIvfs\fP, is:.DS.ta .5i +\w'struct vfsops\0\0\0'u +\w'*vfs_vnodecovered;\0\0\0\0\0'u/* * Structure per mounted file system. * Each mounted file system has an array of * operations and an instance record. * The file systems are put on a doubly linked list. */struct vfs { struct vfs *vfs_next; /* next vfs in vfs list */\fB+\fP struct vfs *vfs_prev; /* prev vfs in vfs list */ struct vfsops *vfs_op; /* operations on vfs */ struct vnode *vfs_vnodecovered; /* vnode we mounted on */ int vfs_flag; /* flags */\fB!\fP int vfs_fsize; /* fundamental block size */\fB+\fP int vfs_bsize; /* optimal transfer size */\fB!\fP uid_t vfs_exroot; /* exported fs uid 0 mapping */ short vfs_exflags; /* exported fs flags */ caddr_t vfs_data; /* private data */};.DE.DS.ta \w'\fB+\fP 'u +\w'#define\0\0'u +\w'VFS_EXPORTED\0\0'u +\w'0x40\0\0\0\0\0'u /* * vfs flags. * VFS_MLOCK lock the vfs so that name lookup cannot proceed past the vfs. * This keeps the subtree stable during mounts and unmounts. */ #define VFS_RDONLY 0x01 /* read only vfs */\fB+\fP #define VFS_NOEXEC 0x02 /* can't exec from filesystem */ #define VFS_MLOCK 0x04 /* lock vfs so that subtree is stable */ #define VFS_MWAIT 0x08 /* someone is waiting for lock */ #define VFS_NOSUID 0x10 /* don't honor setuid bits on vfs */ #define VFS_EXPORTED 0x20 /* file system is exported (NFS) */ /* * exported vfs flags. */ #define EX_RDONLY 0x01 /* exported read only */.DE.LPThe operations supported by the filesystem-specific layeron an individual filesystem are:.DS.ta .5i +\w'struct vfsops\0\0\0'u +\w'*vfs_vnodecovered;\0\0\0\0\0'u/* * Operations supported on virtual file system. */struct vfsops {\fB!\fP int (*vfs_mount)( /* vfs, path, data, datalen */ );\fB!\fP int (*vfs_unmount)( /* vfs, forcibly */ );\fB+\fP int (*vfs_mountroot)(); int (*vfs_root)( /* vfs, vpp */ );\fB!\fP int (*vfs_statfs)( /* vfs, vp, sbp */ );\fB!\fP int (*vfs_sync)( /* vfs, waitfor */ );\fB+\fP int (*vfs_fhtovp)( /* vfs, fhp, vpp */ );\fB+\fP int (*vfs_vptofh)( /* vp, fhp */ );};.DE.LPThe \fIvfs_statfs\fP entry returns a structure of the form:.DS.ta .5i +\w'struct vfsops\0\0\0'u +\w'*vfs_vnodecovered;\0\0\0\0\0'u/* * file system statistics */struct statfs {\fB!\fP short f_type; /* type of filesystem */\fB+\fP short f_flags; /* copy of vfs (mount) flags */\fB!\fP long f_fsize; /* fundamental file system block size */\fB+\fP long f_bsize; /* optimal transfer block size */ long f_blocks; /* total data blocks in file system */ long f_bfree; /* free blocks in fs */ long f_bavail; /* free blocks avail to non-superuser */ long f_files; /* total file nodes in file system */ long f_ffree; /* free file nodes in fs */ fsid_t f_fsid; /* file system id */\fB+\fP char *f_mntonname; /* directory on which mounted */\fB+\fP char *f_mntfromname; /* mounted filesystem */ long f_spare[7]; /* spare for later */};typedef long fsid_t[2]; /* file system id type */.DE.LPThe modifications to Sun's interface at this level are minor.Additional arguments are present for the \fIvfs_mount\fP and \fIvfs_umount\fPentries.\fIvfs_statfs\fP accepts a vnode as well as filesystem identifier,as the information may not be uniform throughout a filesystem.For example,if a client may mount a file tree that spans multiple physicalfilesystems on a server, different sections may have different amountsof free space.(NFS does not allow remotely-mounted file trees to span physical filesystemson the server.)The final additions are the entries that support file handles.\fIvfs_vptofh\fP is provided for the use of file servers,which need to obtain an opaquefile handle to represent the current vnode for transmission to clients.This file handle may later be used to relocate the vnode using \fIvfs_fhtovp\fPwithout requiring the vnode to remain in memory..PPFinally, the external form of a filesystem object, the \fIvnode\fP, is:.DS.ta .5i +\w'struct vnodeops\0\0'u +\w'*v_vfsmountedhere;\0\0\0'u/* * vnode types. VNON means no type.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -