1.if \nv .rm CM 2.de UX 3.ie \\n(UX \s-1UNIX\s0\\$1 4.el \{\ 5\s-1UNIX\s0\\$1\(dg 6.FS 7\(dg \s-1UNIX\s0 is a registered trademark of AT&T. 8.FE 9.nr UX 1 10.\} 11.. 12.TL 13Toward a Compatible Filesystem Interface 14.AU 15Michael J. Karels 16Marshall Kirk McKusick 17.AI 18Computer Systems Research Group 19Computer Science Division 20Department of Electrical Engineering and Computer Science 21University of California, Berkeley 22Berkeley, California 94720 23.AB 24.LP 25As network or remote filesystems have been implemented for 26.UX , 27several stylized interfaces between the filesystem implementation 28and the rest of the kernel have been developed. 29Notable among these are Sun Microsystems' Virtual Filesystem interface (VFS) 30using vnodes, Digital Equipment's Generic File System (GFS) architecture, 31and AT&T's File System Switch (FSS). 32Each design attempts to isolate filesystem-dependent details 33below a generic interface and to provide a framework within which 34new filesystems may be incorporated. 35However, each of these interfaces is different from 36and incompatible with the others. 37Each of them addresses somewhat different design goals. 38Each was based on a different starting version of 39.UX , 40targetted a different set of filesystems with varying characteristics, 41and uses a different set of primitive operations provided by the filesystem. 42The current study compares the various filesystem interfaces. 43Criteria for comparison include generality, completeness, robustness, 44efficiency and esthetics. 45Several of the underlying design issues are examined in detail. 46As a result of this comparison, a proposal for a new filesystem interface 47is advanced that includes the best features of the existing implementations. 48The proposal adopts the calling convention for name lookup introduced 49in 4.3BSD, but is otherwise closely related to Sun's VFS. 50A prototype implementation is now being developed at Berkeley. 51This proposal and the rationale underlying its development 52have been presented to major software vendors 53as an early step toward convergence on a compatible filesystem interface. 54.AE 55.SH 56Introduction 57.PP 58As network communications and workstation environments 59became common elements in 60.UX 61systems, several vendors of 62.UX 63systems have designed and built network file systems 64that allow client process on one 65.UX 66machine to access files on a server machine. 67Examples include Sun's Network File System, NFS [Sandberg85], 68AT&T's recently-announced Remote File Sharing, RFS [Rifkin86], 69the LOCUS distributed filesystem [Walker85], 70and Masscomp's extended filesystem [Cole85]. 71Other remote filesystems have been implemented in research or university groups 72for internal use, notably the network filesystem in the Eighth Edition 73.UX 74system [Weinberger84] and two different filesystems used at Carnegie-Mellon 75University [Satyanarayanan85]. 76Numerous other remote file access methods have been devised for use 77within individual 78.UX 79processes, 80many of them by modifications to the C I/O library 81similar to those in the Newcastle Connection [Brownbridge82]. 82.PP 83Multiple network filesystems may frequently 84be found in use within a single organization. 85These circumstances make it highly desirable to be able to transport filesystem 86implementations from one system to another. 87Such portability is considerably enhanced by the use of a stylized interface 88with carefully-defined entry points to separate the filesystem from the rest 89of the operating system. 90This interface should be similar to the interface between device drivers 91and the kernel. 92Although varying somewhat among the common versions of 93.UX , 94the device driver interfaces are sufficiently similar that device drivers 95may be moved from one system to another without major problems. 96A clean, well-defined interface to the filesystem also allows a single 97system to support multiple local filesystem types. 98.PP 99For reasons such as these, several filesystem interfaces have been used 100when integrating new filesystems into the system. 101The best-known of these are Sun Microsystems' Virtual File System interface, 102VFS [Kleiman86], and AT&T's File System Switch, FSS. 103Another interface, known as the Generic File System, GFS, 104has been implemented for the ULTRIX\(dd 105.FS 106\(dd ULTRIX is a trademark of Digital Equipment Corp. 107.FE 108system by Digital [Rodriguez86]. 109There are numerous differences among these designs. 110The differences may be understood from the varying philosophies 111and design goals of the groups involved, from the systems under which 112the implementations were done, and from the filesystems originally targetted 113by the designs. 114These differences are summarized in the following sections 115within the limitations of the published specifications. 116.SH 117Design goals 118.PP 119There are several design goals which, in varying degrees, 120have driven the various designs. 121Each attempts to divide the filesystem into a filesystem-type-independent 122layer and individual filesystem implementations. 123The division between these layers occurs at somewhat different places 124in these systems, reflecting different views of the diversity and types 125of the filesystems that may be accommodated. 126Compatibility with existing local filesystems has varying importance; 127at the user-process level, each attempts to be completely transparent 128except for a few filesystem-related system management programs. 129The AT&T interface also makes a major effort to retain familiar internal 130system interfaces, and even to retain object-file-level binary compatibility 131with operating system modules such as device drivers. 132Both Sun and DEC were willing to change internal data structures and interfaces 133so that other operating system modules might require recompilation 134or source-code modification. 135.PP 136AT&T's interface both allows and requires filesystems to support the full 137and exact semantics of their previous filesystem, 138including interruptions of system calls on slow operations. 139System calls that deal with remote files are encapsulated 140with their environment and sent to a server where execution continues. 141The system call may be aborted by either client or server, returning 142control to the client. 143Most system calls that descend into the file-system dependent layer 144of a filesystem other than the standard local filesystem do not return 145to the higher-level kernel calling routines. 146Instead, the filesystem-dependent code completes the requested 147operation and then executes a non-local goto (\fIlongjmp\fP) to exit the 148system call. 149These efforts to avoid modification of main-line kernel code 150indicate a far greater emphasis on internal compatibility than on modularity, 151clean design, or efficiency. 152.PP 153In contrast, the Sun VFS interface makes major modifications to the internal 154interfaces in the kernel, with a very clear separation 155of filesystem-independent and -dependent data structures and operations. 156The semantics of the filesystem are largely retained for local operations, 157although this is achieved at some expense where it does not fit the internal 158structuring well. 159The filesystem implementations are not required to support the same 160semantics as local 161.UX 162filesystems. 163Several historical features of 164.UX 165filesystem behavior are difficult to achieve using the VFS interface, 166including the atomicity of file and link creation and the use of open files 167whose names have been removed. 168.PP 169A major design objective of Sun's network filesystem, 170statelessness, 171permeates the VFS interface. 172No locking may be done in the filesystem-independent layer, 173and locking in the filesystem-dependent layer may occur only during 174a single call into that layer. 175.PP 176A final design goal of most implementors is performance. 177For remote filesystems, 178this goal tends to be in conflict with the goals of complete semantic 179consistency, compatibility and modularity. 180Sun has chosen performance over modularity in some areas, 181but has emphasized clean separation of the layers within the filesystem 182at the expense of performance. 183Although the performance of RFS is yet to be seen, 184AT&T seems to have considered compatibility far more important than modularity 185or performance. 186.SH 187Differences among filesystem interfaces 188.PP 189The existing filesystem interfaces may be characterized 190in several ways. 191Each system is centered around a few data structures or objects, 192along with a set of primitives for performing operations upon these objects. 193In the original 194.UX 195filesystem [Ritchie74], 196the basic object used by the filesystem is the inode, or index node. 197The inode contains all of the information about a file except its name: 198its type, identification, ownership, permissions, timestamps and location. 199Inodes are identified by the filesystem device number and the index within 200the filesystem. 201The major entry points to the filesystem are \fInamei\fP, 202which translates a filesystem pathname into the underlying inode, 203and \fIiget\fP, which locates an inode by number and installs it in the in-core 204inode table. 205\fINamei\fP performs name translation by iterative lookup 206of each component name in its directory to find its inumber, 207then using \fIiget\fP to return the actual inode. 208If the last component has been reached, this inode is returned; 209otherwise, the inode describes the next directory to be searched. 210The inode returned may be used in various ways by the caller; 211it may be examined, the file may be read or written, 212types and access may be checked, and fields may be modified. 213Modified inodes are automatically written back the the filesystem 214on disk when the last reference is released with \fIiput\fP. 215Although the details are considerably different, 216the same general scheme is used in the faster filesystem in 4.2BSD 217.UX 218[Mckusick85]. 219.PP 220Both the AT&T interface and, to a lesser extent, the DEC interface 221attempt to preserve the inode-oriented interface. 222Each modify the inode to allow different varieties of the structure 223for different filesystem types by separating the filesystem-dependent 224parts of the inode into a separate structure or one arm of a union. 225Both interfaces allow operations 226equivalent to the \fInamei\fP and \fIiget\fP operations 227of the old filesystem to be performed in the filesystem-independent 228layer, with entry points to the individual filesystem implementations to support 229the type-specific parts of these operations. Implicit in this interface 230is that files may be conveniently be named by and located using a single 231index within a filesystem. 232The GFS provides specific entry points to the filesystems 233to change most file properties rather than allowing arbitrary changes 234to be made to the generic part of the inode. 235.PP 236In contrast, the Sun VFS interface replaces the inode as the primary object 237with the vnode. 238The vnode contains no filesystem-dependent fields except the pointer 239to the set of operations implemented by the filesystem. 240Properties of a vnode that might be transient, such as the ownership, 241permissions, size and timestamps, are maintained by the lower layer. 242These properties may be presented in a generic format upon request; 243callers are expected not to hold this information for any length of time, 244as they may not be up-to-date later on. 245The vnode operations do not include a corollary for \fIiget\fP; 246the only external interface for obtaining vnodes for specific files 247is the name lookup operation. 248(Separate procedures are provided outside of this interface 249that obtain a ``file handle'' for a vnode which may be given 250to a client by a server, such that the vnode may be retrieved 251upon later presentation of the file handle.) 252.SH 253Name translation issues 254.PP 255Each of the systems described include a mechanism for performing 256pathname-to-internal-representation translation. 257The style of the name translation function is very different in all 258three systems. 259As described above, the AT&T and DEC systems retain the \fInamei\fP function. 260The two are quite different, however, as the ULTRIX interface uses 261the \fInamei\fP calling convention introduced in 4.3BSD. 262The parameters and context for the name lookup operation 263are collected in a \fInameidata\fP structure which is passed to \fInamei\fP 264for operation. 265Intent to create or delete the named file is declared in advance, 266so that the final directory scan in \fInamei\fP may retain information 267such as the offset in the directory at which the modification will be made. 268Filesystems that use such mechanisms to avoid redundant work 269must therefore lock the directory to be modified so that it may not 270be modified by another process before completion. 271In the System V filesystem, as in previous versions of 272.UX , 273this information is stored in the per-process \fIuser\fP structure 274by \fInamei\fP for use by a low-level routine called after performing 275the actual creation or deletion of the file itself. 276In 4.3BSD and in the GFS interface, these side effects of \fInamei\fP 277are stored in the \fInameidata\fP structure given as argument to \fInamei\fP, 278which is also presented to the routine implementing file creation or deletion. 279.PP 280The ULTRIX \fInamei\fP routine is responsible for the generic 281parts of the name translation process, such as copying the name into 282an internal buffer, validating it, interpolating 283the contents of symbolic links, and indirecting at mount points. 284As in 4.3BSD, the name is copied into the buffer in a single call, 285according to the location of the name. 286After determining the type of the filesystem at the start of translation 287(the current directory or root directory), it calls the filesystem's 288\fInamei\fP entry with the same structure it received from its caller. 289The filesystem-specific routine translates the name, component by component, 290as long as no mount points are reached. 291It may return after any number of components have been processed. 292\fINamei\fP performs any processing at mount points, then calls 293the correct translation routine for the next filesystem. 294Network filesystems may pass the remaining pathname to a server for translation, 295or they may look up the pathname components one at a time. 296The former strategy would be more efficient, 297but the latter scheme allows mount points within a remote filesystem 298without server knowledge of all client mounts. 299.PP 300The AT&T \fInamei\fP interface is presumably the same as that in previous 301.UX 302systems, accepting the name of a routine to fetch pathname characters 303and an operation (one of: lookup, lookup for creation, or lookup for deletion). 304It translates, component by component, as before. 305If it detects that a mount point crosses to a remote filesystem, 306it passes the remainder of the pathname to the remote server. 307A pathname-oriented request other than open may be completed 308within the \fInamei\fP call, 309avoiding return to the (unmodified) system call handler 310that called \fInamei\fP. 311.PP 312In contrast to the first two systems, Sun's VFS interface has replaced 313\fInamei\fP with \fIlookupname\fP. 314This routine simply calls a new pathname-handling module to allocate 315a pathname buffer and copy in the pathname (copying a character per call), 316then calls \fIlookuppn\fP. 317\fILookuppn\fP performs the iteration over the directories leading 318to the destination file; it copies each pathname component to a local buffer, 319then calls the filesystem \fIlookup\fP entry to locate the vnode 320for that file in the current directory. 321Per-filesystem \fIlookup\fP routines may translate only one component 322per call. 323For creation and deletion of new files, the lookup operation is unmodified; 324the lookup of the final component only serves to check for the existence 325of the file. 326The subsequent creation or deletion call, if any, must repeat the final 327name translation and associated directory scan. 328For new file creation in particular, this is rather inefficient, 329as file creation requires two complete scans of the directory. 330.PP 331Several of the important performance improvements in 4.3BSD 332were related to the name translation process [McKusick85][Leffler84]. 333The following changes were made: 334.IP 1. 4 335A system-wide cache of recent translations is maintained. 336The cache is separate from the inode cache, so that multiple names 337for a file may be present in the cache. 338The cache does not hold ``hard'' references to the inodes, 339so that the normal reference pattern is not disturbed. 340.IP 2. 341A per-process cache is kept of the directory and offset 342at which the last successful name lookup was done. 343This allows sequential lookups of all the entries in a directory to be done 344in linear time. 345.IP 3. 346The entire pathname is copied into a kernel buffer in a single operation, 347rather than using two subroutine calls per character. 348.IP 4. 349A pool of pathname buffers are held by \fInamei\fP, avoiding allocation 350overhead. 351.LP 352All of these performance improvements from 4.3BSD are well worth using 353within a more generalized filesystem framework. 354The generalization of the structure may otherwise make an already-expensive 355function even more costly. 356Most of these improvements are present in the GFS system, as it derives 357from the beta-test version of 4.3BSD. 358The Sun system uses a name-translation cache generally like that in 4.3BSD. 359The name cache is a filesystem-independent facility provided for the use 360of the filesystem-specific lookup routines. 361The Sun cache, like that first used at Berkeley but unlike that in 4.3, 362holds a ``hard'' reference to the vnode (increments the reference count). 363The ``soft'' reference scheme in 4.3BSD cannot be used with the current 364NFS implementation, as NFS allocates vnodes dynamically and frees them 365when the reference count returns to zero rather than caching them. 366As a result, fewer names may be held in the cache 367than (local filesystem) vnodes, and the cache distorts the normal reference 368patterns otherwise seen by the LRU cache. 369As the name cache references overflow the local filesystem inode table, 370the name cache must be purged to make room in the inode table. 371Also, to determine whether a vnode is in use (for example, 372before mounting upon it), the cache must be flushed to free any 373cache reference. 374These problems should be corrected 375by the use of the soft cache reference scheme. 376.PP 377A final observation on the efficiency of name translation in the current 378Sun VFS architecture is that the number of subroutine calls used 379by a multi-component name lookup is dramatically larger 380than in the other systems. 381The name lookup scheme in GFS suffers from this problem much less, 382at no expense in violation of layering. 383.PP 384A final problem to be considered is synchronization and consistency. 385As the filesystem operations are more stylized and broken into separate 386entry points for parts of operations, it is more difficult to guarantee 387consistency throughout an operation and/or to synchronize with other 388processes using the same filesystem objects. 389The Sun interface suffers most severely from this, 390as it forbids the filesystems from locking objects across calls 391to the filesystem. 392It is possible that a file may be created between the time that a lookup 393is performed and a subsequent creation is requested. 394Perhaps more strangely, after a lookup fails to find the target 395of a creation attempt, the actual creation might find that the target 396now exists and is a symbolic link. 397The call will either fail unexpectedly, as the target is of the wrong type, 398or the generic creation routine will have to note the error 399and restart the operation from the lookup. 400This problem will always exist in a stateless filesystem, 401but the VFS interface forces all filesystems to share the problem. 402This restriction against locking between calls also 403forces duplication of work during file creation and deletion. 404This is considered unacceptable. 405.SH 406Support facilities and other interactions 407.PP 408Several support facilities are used by the current 409.UX 410filesystem and require generalization for use by other filesystem types. 411For filesystem implementations to be portable, 412it is desirable that these modified support facilities 413should also have a uniform interface and 414behave in a consistent manner in target systems. 415A prominent example is the filesystem buffer cache. 416The buffer cache in a standard (System V or 4.3BSD) 417.UX 418system contains physical disk blocks with no reference to the files containing 419them. 420This works well for the local filesystem, but has obvious problems 421for remote filesystems. 422Sun has modified the buffer cache routines to describe buffers by vnode 423rather than by device. 424For remote files, the vnode used is that of the file, and the block 425numbers are virtual data blocks. 426For local filesystems, a vnode for the block device is used for cache reference, 427and the block numbers are filesystem physical blocks. 428Use of per-file cache description does not easily accommodate 429caching of indirect blocks, inode blocks, superblocks or cylinder group blocks. 430However, the vnode describing the block device for the cache 431is one created internally, 432rather than the vnode for the device looked up when mounting, 433and it is located by searching a private list of vnodes 434rather than by holding it in the mount structure. 435Although the Sun modification makes it possible to use the buffer 436cache for data blocks of remote files, a better generalization 437of the buffer cache is needed. 438.PP 439The RFS filesystem used by AT&T does not currently cache data blocks 440on client systems, thus the buffer cache is probably unmodified. 441The form of the buffer cache in ULTRIX is unknown to us. 442.PP 443Another subsystem that has a large interaction with the filesystem 444is the virtual memory system. 445The virtual memory system must read data from the filesystem 446to satisfy fill-on-demand page faults. 447For efficiency, this read call is arranged to place the data directly 448into the physical pages assigned to the process (a ``raw'' read) to avoid 449copying the data. 450Although the read operation normally bypasses the filesystem buffer cache, 451consistency must be maintained by checking the buffer cache and copying 452or flushing modified data not yet stored on disk. 453The 4.2BSD virtual memory system, like that of Sun and ULTRIX, 454maintains its own cache of reusable text pages. 455This creates additional complications. 456As the virtual memory systems are redesigned, these problems should be 457resolved by reading through the buffer cache, then mapping the cached 458data into the user address space. 459If the buffer cache or the process pages are changed while the other reference 460remains, the data would have to be copied (``copy-on-write''). 461.PP 462In the meantime, the current virtual memory systems must be used 463with the new filesystem framework. 464Both the Sun and AT&T filesystem interfaces 465provide entry points to the filesystem for optimization of the virtual 466memory system by performing logical-to-physical block number translation 467when setting up a fill-on-demand image for a process. 468The VFS provides a vnode operation analogous to the \fIbmap\fP function of the 469.UX 470filesystem. 471Given a vnode and logical block number, it returns a vnode and block number 472which may be read to obtain the data. 473If the filesystem is local, it returns the private vnode for the block device 474and the physical block number. 475As the \fIbmap\fP operations are all performed at one time, during process 476startup, any indirect blocks for the file will remain in the cache 477after they are once read. 478In addition, the interface provides a \fIstrategy\fP entry that may be used 479for ``raw'' reads from a filesystem device, 480used to read data blocks into an address space without copying. 481This entry uses a buffer header (\fIbuf\fP structure) 482to describe the I/O operation 483instead of a \fIuio\fP structure. 484The buffer-style interface is the same as that used by disk drivers internally. 485This difference allows the current \fIuio\fP primitives to be avoided, 486as they copy all data to/from the current user process address space. 487Instead, for local filesystems these operations could be done internally 488with the standard raw disk read routines, 489which use a \fIuio\fP interface. 490When loading from a remote filesystems, 491the data will be received in a network buffer. 492If network buffers are suitably aligned, 493the data may be mapped into the process address space by a page swap 494without copying. 495In either case, it should be possible to use the standard filesystem 496read entry from the virtual memory system. 497.PP 498Other issues that must be considered in devising a portable 499filesystem implementation include kernel memory allocation, 500the implicit use of user-structure global context, 501which may create problems with reentrancy, 502the style of the system call interface, 503and the conventions for synchronization 504(sleep/wakeup, handling of interrupted system calls, semaphores). 505.SH 506The Berkeley Proposal 507.PP 508The Sun VFS interface has been most widely used of the three described here. 509It is also the most general of the three, in that filesystem-specific 510data and operations are best separated from the generic layer. 511Although it has several disadvantages which were described above, 512most of them may be corrected with minor changes to the interface 513(and, in a few areas, philosophical changes). 514The DEC GFS has other advantages, in particular the use of the 4.3BSD 515\fInamei\fP interface and optimizations. 516It allows single or multiple components of a pathname 517to be translated in a single call to the specific filesystem 518and thus accommodates filesystems with either preference. 519The FSS is least well understood, as there is little public information 520about the interface. 521However, the design goals are the least consistent with those of the Berkeley 522research groups. 523Accordingly, a new filesystem interface has been devised to avoid 524some of the problems in the other systems. 525The proposed interface derives directly from Sun's VFS, 526but, like GFS, uses a 4.3BSD-style name lookup interface. 527Additional context information has been moved from the \fIuser\fP structure 528to the \fInameidata\fP structure so that name translation may be independent 529of the global context of a user process. 530This is especially desired in any system where kernel-mode servers 531operate as light-weight or interrupt-level processes, 532or where a server may store or cache context for several clients. 533This calling interface has the additional advantage 534that the call parameters need not all be pushed onto the stack for each call 535through the filesystem interface, 536and they may be accessed using short offsets from a base pointer 537(unlike global variables in the \fIuser\fP structure). 538.PP 539The proposed filesystem interface is described very tersely here. 540For the most part, data structures and procedures are analogous 541to those used by VFS, and only the changes will be be treated here. 542See [Kleiman86] for complete descriptions of the vfs and vnode operations 543in Sun's interface. 544.PP 545The central data structure for name translation is the \fInameidata\fP 546structure. 547The same structure is used to pass parameters to \fInamei\fP, 548to pass these same parameters to filesystem-specific lookup routines, 549to communicate completion status from the lookup routines back to \fInamei\fP, 550and to return completion status to the calling routine. 551For creation or deletion requests, the parameters to the filesystem operation 552to complete the request are also passed in this same structure. 553The form of the \fInameidata\fP structure is: 554.br 555.ne 2i 556.ID 557.nf 558.ta .5i +\w'caddr_t\0\0\0'u +\w'struct\0\0'u +\w'vnode *nc_prevdir;\0\0\0\0\0'u 559/* 560 * Encapsulation of namei parameters. 561 * One of these is located in the u. area to 562 * minimize space allocated on the kernel stack 563 * and to retain per-process context. 564 */ 565struct nameidata { 566 /* arguments to namei and related context: */ 567 caddr_t ni_dirp; /* pathname pointer */ 568 enum uio_seg ni_seg; /* location of pathname */ 569 short ni_nameiop; /* see below */ 570 struct vnode *ni_cdir; /* current directory */ 571 struct vnode *ni_rdir; /* root directory, if not normal root */ 572 struct ucred *ni_cred; /* credentials */ 573 574 /* shared between namei, lookup routines and commit routines: */ 575 caddr_t ni_pnbuf; /* pathname buffer */ 576 char *ni_ptr; /* current location in pathname */ 577 int ni_pathlen; /* remaining chars in path */ 578 short ni_more; /* more left to translate in pathname */ 579 short ni_loopcnt; /* count of symlinks encountered */ 580 581 /* results: */ 582 struct vnode *ni_vp; /* vnode of result */ 583 struct vnode *ni_dvp; /* vnode of intermediate directory */ 584 585/* BEGIN UFS SPECIFIC */ 586 struct diroffcache { /* last successful directory search */ 587 struct vnode *nc_prevdir; /* terminal directory */ 588 long nc_id; /* directory's unique id */ 589 off_t nc_prevoffset; /* where last entry found */ 590 } ni_nc; 591/* END UFS SPECIFIC */ 592}; 593.DE 594.DS 595.ta \w'#define\0\0'u +\w'WANTPARENT\0\0'u +\w'0x40\0\0\0\0\0\0\0'u 596/* 597 * namei operations and modifiers 598 */ 599#define LOOKUP 0 /* perform name lookup only */ 600#define CREATE 1 /* setup for file creation */ 601#define DELETE 2 /* setup for file deletion */ 602#define WANTPARENT 0x10 /* return parent directory vnode also */ 603#define NOCACHE 0x20 /* name must not be left in cache */ 604#define FOLLOW 0x40 /* follow symbolic links */ 605#define NOFOLLOW 0x0 /* don't follow symbolic links (pseudo) */ 606.DE 607As in current systems other than Sun's VFS, \fInamei\fP is called 608with an operation request, one of LOOKUP, CREATE or DELETE. 609For a LOOKUP, the operation is exactly like the lookup in VFS. 610CREATE and DELETE allow the filesystem to ensure consistency 611by locking the parent inode (private to the filesystem), 612and (for the local filesystem) to avoid duplicate directory scans 613by storing the new directory entry and its offset in the directory 614in the \fIndirinfo\fP structure. 615This is intended to be opaque to the filesystem-independent levels. 616Not all lookups for creation or deletion are actually followed 617by the intended operation; permission may be denied, the filesystem 618may be read-only, etc. 619Therefore, an entry point to the filesystem is provided 620to abort a creation or deletion operation 621and allow release of any locked internal data. 622After a \fInamei\fP with a CREATE or DELETE flag, the pathname pointer 623is set to point to the last filename component. 624Filesystems that choose to implement creation or deletion entirely 625within the subsequent call to a create or delete entry 626are thus free to do so. 627.PP 628The \fInameidata\fP is used to store context used during name translation. 629The current and root directories for the translation are stored here. 630For the local filesystem, the per-process directory offset cache 631is also kept here. 632A file server could leave the directory offset cache empty, 633could use a single cache for all clients, 634or could hold caches for several recent clients. 635.PP 636Several other data structures are used in the filesystem operations. 637One is the \fIucred\fP structure which describes a client's credentials 638to the filesystem. 639This is modified slightly from the Sun structure; 640the ``accounting'' group ID has been merged into the groups array. 641The actual number of groups in the array is given explicitly 642to avoid use of a reserved group ID as a terminator. 643Also, typedefs introduced in 4.3BSD for user and group ID's have been used. 644The \fIucred\fP structure is thus: 645.DS 646.ta .5i +\w'caddr_t\0\0\0'u +\w'struct\0\0'u +\w'vnode *nc_prevdir;\0\0\0\0\0'u 647/* 648 * Credentials. 649 */ 650struct ucred { 651 u_short cr_ref; /* reference count */ 652 uid_t cr_uid; /* effective user id */ 653 short cr_ngroups; /* number of groups */ 654 gid_t cr_groups[NGROUPS]; /* groups */ 655 /* 656 * The following either should not be here, 657 * or should be treated as opaque. 658 */ 659 uid_t cr_ruid; /* real user id */ 660 gid_t cr_svgid; /* saved set-group id */ 661}; 662.DE 663.PP 664A final structure used by the filesystem interface is the \fIuio\fP 665structure mentioned earlier. 666This structure describes the source or destination of an I/O 667operation, with provision for scatter/gather I/O. 668It is used in the read and write entries to the filesystem. 669The \fIuio\fP structure presented here is modified from the one 670used in 4.2BSD to specify the location of each vector of the operation 671(user or kernel space) 672and to allow an alternate function to be used to implement the data movement. 673The alternate function might perform page remapping rather than a copy, 674for example. 675.DS 676.ta .5i +\w'caddr_t\0\0\0'u +\w'struct\0\0'u +\w'vnode *nc_prevdir;\0\0\0\0\0'u 677/* 678 * Description of an I/O operation which potentially 679 * involves scatter-gather, with individual sections 680 * described by iovec, below. uio_resid is initially 681 * set to the total size of the operation, and is 682 * decremented as the operation proceeds. uio_offset 683 * is incremented by the amount of each operation. 684 * uio_iov is incremented and uio_iovcnt is decremented 685 * after each vector is processed. 686 */ 687struct uio { 688 struct iovec *uio_iov; 689 int uio_iovcnt; 690 off_t uio_offset; 691 int uio_resid; 692 enum uio_rw uio_rw; 693}; 694 695enum uio_rw { UIO_READ, UIO_WRITE }; 696.DE 697.DS 698.ta .5i +\w'caddr_t\0\0\0'u +\w'vnode *nc_prevdir;\0\0\0\0\0'u 699/* 700 * Description of a contiguous section of an I/O operation. 701 * If iov_op is non-null, it is called to implement the copy 702 * operation, possibly by remapping, with the call 703 * (*iov_op)(from, to, count); 704 * where from and to are caddr_t and count is int. 705 * Otherwise, the copy is done in the normal way, 706 * treating base as a user or kernel virtual address 707 * according to iov_segflg. 708 */ 709struct iovec { 710 caddr_t iov_base; 711 int iov_len; 712 enum uio_seg iov_segflg; 713 int (*iov_op)(); 714}; 715.DE 716.DS 717.ta .5i +\w'UIO_USERISPACE\0\0\0\0\0'u 718/* 719 * Segment flag values. 720 */ 721enum uio_seg { 722 UIO_USERSPACE, /* from user data space */ 723 UIO_SYSSPACE, /* from system space */ 724 UIO_USERISPACE /* from user I space */ 725}; 726.DE 727.SH 728File and filesystem operations 729.PP 730With the introduction of the data structures used by the filesystem 731operations, the complete list of filesystem entry points may be listed. 732As noted, they derive mostly from the Sun VFS interface. 733Lines marked with \fB+\fP are additions to the Sun definitions; 734lines marked with \fB!\fP are modified from VFS. 735.PP 736The structure describing the externally-visible features of a mounted 737filesystem, \fIvfs\fP, is: 738.DS 739.ta .5i +\w'struct vfsops\0\0\0'u +\w'*vfs_vnodecovered;\0\0\0\0\0'u 740/* 741 * Structure per mounted file system. 742 * Each mounted file system has an array of 743 * operations and an instance record. 744 * The file systems are put on a doubly linked list. 745 */ 746struct vfs { 747 struct vfs *vfs_next; /* next vfs in vfs list */ 748\fB+\fP struct vfs *vfs_prev; /* prev vfs in vfs list */ 749 struct vfsops *vfs_op; /* operations on vfs */ 750 struct vnode *vfs_vnodecovered; /* vnode we mounted on */ 751 int vfs_flag; /* flags */ 752\fB!\fP int vfs_fsize; /* fundamental block size */ 753\fB+\fP int vfs_bsize; /* optimal transfer size */ 754\fB!\fP uid_t vfs_exroot; /* exported fs uid 0 mapping */ 755 short vfs_exflags; /* exported fs flags */ 756 caddr_t vfs_data; /* private data */ 757}; 758.DE 759.DS 760.ta \w'\fB+\fP 'u +\w'#define\0\0'u +\w'VFS_EXPORTED\0\0'u +\w'0x40\0\0\0\0\0'u 761 /* 762 * vfs flags. 763 * VFS_MLOCK lock the vfs so that name lookup cannot proceed past the vfs. 764 * This keeps the subtree stable during mounts and unmounts. 765 */ 766 #define VFS_RDONLY 0x01 /* read only vfs */ 767\fB+\fP #define VFS_NOEXEC 0x02 /* can't exec from filesystem */ 768 #define VFS_MLOCK 0x04 /* lock vfs so that subtree is stable */ 769 #define VFS_MWAIT 0x08 /* someone is waiting for lock */ 770 #define VFS_NOSUID 0x10 /* don't honor setuid bits on vfs */ 771 #define VFS_EXPORTED 0x20 /* file system is exported (NFS) */ 772 773 /* 774 * exported vfs flags. 775 */ 776 #define EX_RDONLY 0x01 /* exported read only */ 777.DE 778.LP 779The operations supported by the filesystem-specific layer 780on an individual filesystem are: 781.DS 782.ta .5i +\w'struct vfsops\0\0\0'u +\w'*vfs_vnodecovered;\0\0\0\0\0'u 783/* 784 * Operations supported on virtual file system. 785 */ 786struct vfsops { 787\fB!\fP int (*vfs_mount)( /* vfs, path, data, datalen */ ); 788\fB!\fP int (*vfs_unmount)( /* vfs, forcibly */ ); 789\fB+\fP int (*vfs_mountroot)(); 790 int (*vfs_root)( /* vfs, vpp */ ); 791\fB!\fP int (*vfs_statfs)( /* vfs, vp, sbp */ ); 792\fB!\fP int (*vfs_sync)( /* vfs, waitfor */ ); 793\fB+\fP int (*vfs_fhtovp)( /* vfs, fhp, vpp */ ); 794\fB+\fP int (*vfs_vptofh)( /* vp, fhp */ ); 795}; 796.DE 797.LP 798The \fIvfs_statfs\fP entry returns a structure of the form: 799.DS 800.ta .5i +\w'struct vfsops\0\0\0'u +\w'*vfs_vnodecovered;\0\0\0\0\0'u 801/* 802 * file system statistics 803 */ 804struct statfs { 805\fB!\fP short f_type; /* type of filesystem */ 806\fB+\fP short f_flags; /* copy of vfs (mount) flags */ 807\fB!\fP long f_fsize; /* fundamental file system block size */ 808\fB+\fP long f_bsize; /* optimal transfer block size */ 809 long f_blocks; /* total data blocks in file system */ 810 long f_bfree; /* free blocks in fs */ 811 long f_bavail; /* free blocks avail to non-superuser */ 812 long f_files; /* total file nodes in file system */ 813 long f_ffree; /* free file nodes in fs */ 814 fsid_t f_fsid; /* file system id */ 815\fB+\fP char *f_mntonname; /* directory on which mounted */ 816\fB+\fP char *f_mntfromname; /* mounted filesystem */ 817 long f_spare[7]; /* spare for later */ 818}; 819 820typedef long fsid_t[2]; /* file system id type */ 821.DE 822.LP 823Finally, the external form of a filesystem object, the \fIvnode\fP, is: 824.DS 825.ta .5i +\w'struct vnodeops\0\0'u +\w'*v_vfsmountedhere;\0\0\0'u 826/* 827 * vnode types. VNON means no type. 828 */ 829enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK }; 830 831struct vnode { 832 u_short v_flag; /* vnode flags (see below) */ 833 u_short v_count; /* reference count */ 834 u_short v_shlockc; /* count of shared locks */ 835 u_short v_exlockc; /* count of exclusive locks */ 836 struct vfs *v_vfsmountedhere; /* ptr to vfs mounted here */ 837 struct vfs *v_vfsp; /* ptr to vfs we are in */ 838 struct vnodeops *v_op; /* vnode operations */ 839\fB+\fP struct text *v_text; /* text/mapped region */ 840 enum vtype v_type; /* vnode type */ 841 caddr_t v_data; /* private data for fs */ 842}; 843.DE 844.DS 845.ta \w'#define\0\0'u +\w'NOFOLLOW\0\0'u +\w'0x40\0\0\0\0\0\0\0'u 846/* 847 * vnode flags. 848 */ 849#define VROOT 0x01 /* root of its file system */ 850#define VTEXT 0x02 /* vnode is a pure text prototype */ 851#define VEXLOCK 0x10 /* exclusive lock */ 852#define VSHLOCK 0x20 /* shared lock */ 853#define VLWAIT 0x40 /* proc is waiting on shared or excl. lock */ 854.DE 855.LP 856The operations supported by the filesystems on individual \fIvnode\fP\^s 857are: 858.DS 859.ta .5i +\w'int\0\0\0\0\0'u +\w'(*vn_getattr)(\0\0\0\0\0'u 860/* 861 * Operations on vnodes. 862 */ 863struct vnodeops { 864\fB!\fP int (*vn_lookup)( /* ndp */ ); 865\fB!\fP int (*vn_create)( /* ndp, vap, fflags */ ); 866\fB+\fP int (*vn_mknod)( /* ndp, vap, fflags */ ); 867\fB!\fP int (*vn_open)( /* vp, fflags, cred */ ); 868 int (*vn_close)( /* vp, fflags, cred */ ); 869 int (*vn_access)( /* vp, fflags, cred */ ); 870 int (*vn_getattr)( /* vp, vap, cred */ ); 871 int (*vn_setattr)( /* vp, vap, cred */ ); 872 873\fB+\fP int (*vn_read)( /* vp, uiop, offp, ioflag, cred */ ); 874\fB+\fP int (*vn_write)( /* vp, uiop, offp, ioflag, cred */ ); 875\fB!\fP int (*vn_ioctl)( /* vp, com, data, fflag, cred */ ); 876 int (*vn_select)( /* vp, which, cred */ ); 877\fB+\fP int (*vn_mmap)( /* vp, ..., cred */ ); 878 int (*vn_fsync)( /* vp, cred */ ); 879\fB+\fP int (*vn_seek)( /* vp, offp, off, whence */ ); 880 881\fB!\fP int (*vn_remove)( /* ndp */ ); 882\fB!\fP int (*vn_link)( /* vp, ndp */ ); 883\fB!\fP int (*vn_rename)( /* src ndp, target ndp */ ); 884\fB!\fP int (*vn_mkdir)( /* ndp, vap */ ); 885\fB!\fP int (*vn_rmdir)( /* ndp */ ); 886\fB!\fP int (*vn_symlink)( /* ndp, vap, nm */ ); 887 int (*vn_readdir)( /* vp, uiop, offp, ioflag, cred */ ); 888 int (*vn_readlink)( /* vp, uiop, ioflag, cred */ ); 889 890\fB+\fP int (*vn_abortop)( /* ndp */ ); 891\fB!\fP int (*vn_inactive)( /* vp */ ); 892}; 893.DE 894.DS 895.ta \w'#define\0\0'u +\w'NOFOLLOW\0\0'u +\w'0x40\0\0\0\0\0'u 896/* 897 * flags for ioflag 898 */ 899#define IO_UNIT 0x01 /* do io as atomic unit for VOP_RDWR */ 900#define IO_APPEND 0x02 /* append write for VOP_RDWR */ 901#define IO_SYNC 0x04 /* sync io for VOP_RDWR */ 902.DE 903.LP 904The argument types listed in the comments following each operation are: 905.sp 906.IP ndp 10 907A pointer to a \fInameidata\fP structure. 908.IP vap 909A pointer to a \fIvattr\fP structure (vnode attributes; see below). 910.IP fflags 911File open flags, possibly including O_APPEND, O_CREAT, O_TRUNC and O_EXCL. 912.IP vp 913A pointer to a \fIvnode\fP previously obtained with \fIvn_lookup\fP. 914.IP cred 915A pointer to a \fIucred\fP credentials structure. 916.IP uiop 917A pointer to a \fIuio\fP structure. 918.IP ioflag 919Any of the IO flags defined above. 920.IP com 921An \fIioctl\fP command, with type \fIunsigned long\fP. 922.IP data 923A pointer to a character buffer used to pass data to or from an \fIioctl\fP. 924.IP which 925One of FREAD, FWRITE or 0 (select for exceptional conditions). 926.IP off 927A file offset of type \fIoff_t\fP. 928.IP offp 929A pointer to file offset of type \fIoff_t\fP. 930.IP whence 931One of L_SET, L_INCR, or L_XTND. 932.IP fhp 933A pointer to a file handle buffer. 934.sp 935.PP 936Several changes have been made to Sun's set of vnode operations. 937Most obviously, the \fIvn_lookup\fP receives a \fInameidata\fP structure 938containing its arguments and context as described. 939The same structure is also passed to one of the creation or deletion 940entries if the lookup operation is for CREATE or DELETE to complete 941an operation, or to the \fIvn_abortop\fP entry if no operation 942is undertaken. 943For filesystems that perform no locking between lookup for creation 944or deletion and the call to implement that action, 945the final pathname component may be left untranslated by the lookup 946routine. 947In any case, the pathname pointer points at the final name component, 948and the \fInameidata\fP contains a reference to the vnode of the parent 949directory. 950The interface is thus flexible enough to accommodate filesystems 951that are fully stateful or fully stateless, while avoiding redundant 952operations whenever possible. 953One operation remains problematical, the \fIvn_rename\fP call. 954It is tempting to look up the source of the rename for deletion 955and the target for creation. 956However, filesystems that lock directories during such lookups must avoid 957deadlock if the two paths cross. 958For that reason, the source is translated for LOOKUP only, 959with the WANTPARENT flag set; 960the target is then translated with an operation of CREATE. 961.PP 962In addition to the changes concerned with the \fInameidata\fP interface, 963several other changes were made in the vnode operations. 964The \fIvn_rdrw\fP entry was split into \fIvn_read\fP and \fIvn_write\fP; 965frequently, the read/write entry amounts to a routine that checks 966the direction flag, then calls either a read routine or a write routine. 967The two entries may be identical for any given filesystem; 968the direction flag is contained in the \fIuio\fP given as an argument. 969.PP 970All of the read and write operations use a \fIuio\fP to describe 971the file offset and buffer locations. 972All of these fields must be updated before return. 973In particular, the \fIvn_readdir\fP entry uses this 974to return a new file offset token for its current location. 975.PP 976Several new operations have been added. 977The first, \fIvn_seek\fP, is a concession to record-oriented files 978such as directories. 979It allows the filesystem to verify that a seek leaves a file at a sensible 980offset, or to return a new offset token relative to an earlier one. 981For most filesystems and files, this operation amounts to performing 982simple arithmetic. 983Another new entry point is \fIvn_mmap\fP, for use in mapping device memory 984into a user process address space. 985Its semantics are not yet decided. 986The final addition is the \fIvn_vptofh\fP entry. 987It is provided for the use of file servers, which need to obtain an opaque 988file handle to represent the current vnode for transmission to clients. 989This file handle may later be used to relocate the vnode using the vfs 990entry \fIvfs_fhtovp\fP. 991.PP 992The attributes of a vnode are not stored in the vnode, 993as they might change with time and may need to be read from a remote 994source. 995Attributes have the form: 996.DS 997.ta .5i +\w'struct vnodeops\0\0'u +\w'*v_vfsmountedhere;\0\0\0'u 998/* 999 * Vnode attributes. A field value of -1 1000 * represents a field whose value is unavailable 1001 * (getattr) or which is not to be changed (setattr). 1002 */ 1003struct vattr { 1004 enum vtype va_type; /* vnode type (for create) */ 1005 u_short va_mode; /* files access mode and type */ 1006\fB!\fP uid_t va_uid; /* owner user id */ 1007\fB!\fP gid_t va_gid; /* owner group id */ 1008 long va_fsid; /* file system id (dev for now) */ 1009\fB!\fP long va_fileid; /* file id */ 1010 short va_nlink; /* number of references to file */ 1011 u_long va_size; /* file size in bytes (quad?) */ 1012\fB+\fP u_long va_size1; /* reserved if not quad */ 1013 long va_blocksize; /* blocksize preferred for i/o */ 1014 struct timeval va_atime; /* time of last access */ 1015 struct timeval va_mtime; /* time of last modification */ 1016 struct timeval va_ctime; /* time file changed */ 1017 dev_t va_rdev; /* device the file represents */ 1018 u_long va_bytes; /* bytes of disk space held by file */ 1019\fB+\fP u_long va_bytes1; /* reserved if va_bytes not a quad */ 1020}; 1021.DE 1022.SH 1023Conclusions 1024.PP 1025The Sun VFS filesystem interface is the most widely used generic 1026filesystem interface. 1027Of the interfaces examined, it creates the cleanest separation 1028between the filesystem-independent and -dependent layers and data structures. 1029It has several flaws, but it is felt that certain changes in the interface 1030can ameliorate most of them. 1031The interface proposed here includes those changes. 1032The proposed interface is now being implemented by the Computer Systems 1033Research Group at Berkeley. 1034If the design succeeds in improving the flexibility and performance 1035of the filesystem layering, it will be advanced as a model interface. 1036.SH 1037Acknowledgements 1038.PP 1039The filesystem interface described here is derived from Sun's VFS interface. 1040It also includes features similar to those of DEC's GFS interface. 1041We are indebted to members of the Sun and DEC system groups 1042for long discussions of the issues involved. 1043.br 1044.ne 2i 1045.SH 1046References 1047 1048.IP Brownbridge82 \w'Satyanarayanan85\0\0'u 1049Brownbridge, D.R., L.F. Marshall, B. Randell, 1050``The Newcastle Connection, or UNIXes of the World Unite!,'' 1051\fISoftware\- Practice and Experience\fP, Vol. 12, pp. 1147-1162, 1982. 1052 1053.IP Cole85 1054Cole, C.T., P.B. Flinn, A.B. Atlas, 1055``An Implementation of an Extended File System for UNIX,'' 1056\fIUsenix Conference Proceedings\fP, 1057pp. 131-150, June, 1985. 1058 1059.IP Kleiman86 1060``Vnodes: An Architecture for Multiple File System Types in Sun UNIX,'' 1061\fIUsenix Conference Proceedings\fP, 1062pp. 238-247, June, 1986. 1063 1064.IP Leffler84 1065Leffler, S., M.K. McKusick, M. Karels, 1066``Measuring and Improving the Performance of 4.2BSD,'' 1067\fIUsenix Conference Proceedings\fP, pp. 237-252, June, 1984. 1068 1069.IP McKusick84 1070McKusick, M.K., W.N. Joy, S.J. Leffler, R.S. Fabry, 1071``A Fast File System for UNIX,'' \fITransactions on Computer Systems\fP, 1072Vol. 2, pp. 181-197, 1073ACM, August, 1984. 1074 1075.IP McKusick85 1076McKusick, M.K., M. Karels, S. Leffler, 1077``Performance Improvements and Functional Enhancements in 4.3BSD,'' 1078\fIUsenix Conference Proceedings\fP, pp. 519-531, June, 1985. 1079 1080.IP Rifkin86 1081Rifkin, A.P., M.P. Forbes, R.L. Hamilton, M. Sabrio, S. Shah, and K. Yueh, 1082``RFS Architectural Overview,'' \fIUsenix Conference Proceedings\fP, 1083pp. 248-259, June, 1986. 1084 1085.IP Ritchie74 1086Ritchie, D.M. and K. Thompson, ``The Unix Time-Sharing System,'' 1087\fICommunications of the ACM\fP, Vol. 17, pp. 365-375, July, 1974. 1088 1089.IP Rodriguez86 1090Rodriguez, R., M. Koehler, R. Hyde, 1091``The Generic File System,'' \fIUsenix Conference Proceedings\fP, 1092pp. 260-269, June, 1986. 1093 1094.IP Sandberg85 1095Sandberg, R., D. Goldberg, S. Kleiman, D. Walsh, B. Lyon, 1096``Design and Implementation of the Sun Network Filesystem,'' 1097\fIUsenix Conference Proceedings\fP, 1098pp. 119-130, June, 1985. 1099 1100.IP Satyanarayanan85 1101Satyanarayanan, M., \fIet al.\fP, 1102``The ITC Distributed File System: Principles and Design,'' 1103\fIProc. 10th Symposium on Operating Systems Principles\fP, pp. 35-50, 1104ACM, December, 1985. 1105 1106.IP Walker85 1107Walker, B.J. and S.H. Kiser, ``The LOCUS Distributed Filesystem,'' 1108\fIThe LOCUS Distributed System Architecture\fP, 1109G.J. Popek and B.J. Walker, ed., The MIT Press, Cambridge, MA, 1985. 1110 1111.IP Weinberger84 1112Weinberger, P.J., ``The Version 8 Network File System,'' 1113\fIUsenix Conference presentation\fP, 1114June, 1984. 1115