filesystem.3

来自「tcl是工具命令语言」· 3 代码 · 共 1,350 行 · 第 1/4 页

3
1,350
字号
Except for the first three fields in this structure which containsimple data elements, all entries contain addresses of functions calledby the generic filesystem layer to perform the complete range offilesystem related actions..PPThe many functions in this structure are broken down into threecategories: infrastructure functions (almost all of which must beimplemented), operational functions (which must be implemented if acomplete filesystem is provided), and efficiency functions (which needonly be implemented if they can be done so efficiently, or if they haveside-effects which are required by the filesystem; Tcl has lessefficient emulations it can fall back on).  It is important to notethat, in the current version of Tcl, most of these fallbacks are onlyused to handle commands initiated in Tcl, not in C. What this means is,that if a 'file rename' command is issued in Tcl, and the relevantfilesystem(s) do not implement their \fITcl_FSRenameFileProc\fR, Tcl'score will instead fallback on a combination of other filesystemfunctions (it will use \fITcl_FSCopyFileProc\fR followed by\fITcl_FSDeleteFileProc\fR, and if \fITcl_FSCopyFileProc\fR is notimplemented there is a further fallback).  However, if a\fITcl_FSRenameFile\fR command is issued at the C level, no suchfallbacks occur.  This is true except for the last four entries in thefilesystem table (lstat, load, getcwd and chdir)for which fallbacks do in fact occur at the C level..PPAs an example, here is the filesystem lookup table used by the"vfs" extension which allows filesystem actions to be implementedin Tcl..CSstatic Tcl_Filesystem vfsFilesystem = {    "tclvfs",    sizeof(Tcl_Filesystem),    TCL_FILESYSTEM_VERSION_1,    &VfsPathInFilesystem,    &VfsDupInternalRep,    &VfsFreeInternalRep,    /* No internal to normalized, since we don't create any     * pure 'internal' Tcl_Obj path representations */    NULL,    /* No create native rep function, since we don't use it     * and don't choose to support uses of 'Tcl_FSNewNativePath' */    NULL,    /* Normalize path isn't needed - we assume paths only have     * one representation */    NULL,    &VfsFilesystemPathType,    &VfsFilesystemSeparator,    &VfsStat,    &VfsAccess,    &VfsOpenFileChannel,    &VfsMatchInDirectory,    &VfsUtime,    /* We choose not to support symbolic links inside our vfs's */    NULL,    &VfsListVolumes,    &VfsFileAttrStrings,    &VfsFileAttrsGet,    &VfsFileAttrsSet,    &VfsCreateDirectory,    &VfsRemoveDirectory,     &VfsDeleteFile,    /* No copy file - fallback will occur at Tcl level */    NULL,    /* No rename file - fallback will occur at Tcl level */    NULL,    /* No copy directory - fallback will occur at Tcl level */    NULL,     /* Core will use stat for lstat */    NULL,    /* No load - fallback on core implementation */    NULL,    /* We don't need a getcwd or chdir - fallback on Tcl's versions */    NULL,    NULL};.CE.PPAny functions which take path names in Tcl_Obj form takethose names in UTF\-8 form.  The filesystem infrastructure API isdesigned to support efficient, cached conversion of these UTF\-8 pathsto other native representations..SH TYPENAME.PPThe \fItypeName\fR field contains a null-terminated string thatidentifies the type of the filesystem implemented, e.g.\fBnative\fR or \fBzip\fR or \fBvfs\fR..PP.SH "STRUCTURE LENGTH".PPThe \fIstructureLength\fR field is generally implemented as\fIsizeof(Tcl_Filesystem)\fR, and is there to allow easierbinary backwards compatibility if the size of the structurechanges in a future Tcl release..SH VERSION.PPThe \fIversion\fR field should be set to \fBTCL_FILESYSTEM_VERSION_1\fR..SH "FILESYSTEM INFRASTRUCTURE".PPThese fields contain addresses of functions which are used to associatea particular filesystem with a file path, and deal with the internalhandling of path representations, for example copying and freeing suchrepresentations..SH PATHINFILESYSTEMPROC.PPThe \fIpathInFilesystemProc\fR field contains the address of a functionwhich is called to determine whether a given path object belongs tothis filesystem or not.  Tcl will only call the rest of the filesystemfunctions with a path for which this function has returned\fBTCL_OK\fR. If the path does not belong, \fBTCL_ERROR\fR should bereturned.  If \fBTCL_OK\fR is returned, then the optional\fBclientDataPtr\fR output parameter can be used to return an internal(filesystem specific) representation of the path, which will be cachedinside the path object, and may be retrieved efficiently by the otherfilesystem functions.  Tcl will simultaneously cache the fact that thispath belongs to this filesystem.  Such caches are invalidated whenfilesystem structures are added or removed from Tcl's internal list ofknown filesystems..PP.CStypedef int Tcl_FSPathInFilesystemProc(	Tcl_Obj *\fIpathPtr\fR, 	ClientData *\fIclientDataPtr\fR);.CE.SH DUPINTERNALREPPROC.PPThis function makes a copy of a path's internal representation, and iscalled when Tcl needs to duplicate a path object.  If NULL, Tcl willsimply not copy the internal representation, which may then need to beregenerated later..PP.CStypedef ClientData Tcl_FSDupInternalRepProc(	ClientData \fIclientData\fR);.CE.SH FREEINTERNALREPPROCFree the internal representation.  This must be implemented if internalrepresentations need freeing (i.e. if some memory is allocated when aninternal representation is generated), but may otherwise be NULL..PP.CStypedef void Tcl_FSFreeInternalRepProc(	ClientData \fIclientData\fR);.CE.SH INTERNALTONORMALIZEDPROC.PPFunction to convert internal representation to a normalized path.  Onlyrequired if the filesystem creates pure path objects with no string/pathrepresentation.  The return value is a Tcl object whose stringrepresentation is the normalized path..PP.CStypedef Tcl_Obj* Tcl_FSInternalToNormalizedProc(	ClientData \fIclientData\fR);.CE.SH CREATEINTERNALREPPROC.PPFunction to take a path object, and calculate an internalrepresentation for it, and store that native representation in theobject.  May be NULL if paths have no internal representation, or ifthe \fITcl_FSPathInFilesystemProc\fR for this filesystem alwaysimmediately creates an internal representation for paths it accepts..PP.CStypedef ClientData Tcl_FSCreateInternalRepProc(	Tcl_Obj *\fIpathPtr\fR);.CE.SH NORMALIZEPATHPROC       .PPFunction to normalize a path.  Should be implemented for allfilesystems which can have multiple string representations for the samepath object.  In Tcl, every 'path' must have a single unique 'normalized'string representation.  Depending on the filesystem,there may be more than one unnormalized string representation whichrefers to that path (e.g. a relative path, a path with differentcharacter case if the filesystem is case insensitive, a path contain areference to a home directory such as '~', a path containing symboliclinks, etc).  If the very last component in the path is a symboliclink, it should not be converted into the object it points to (butits case or other aspects should be made unique).  All other pathcomponents should be converted from symbolic links.  This oneexception is required to agree with Tcl's semantics with 'filedelete', 'file rename', 'file copy' operating on symbolic links.This function may be called with 'nextCheckpoint' eitherat the beginning of the path (i.e. zero), at the end of the path, orat any intermediate file separator in the path.  It will neverpoint to any other arbitrary position in the path. In the last ofthe three valid cases, the implementation can assume that the path up to and including the file separator is known and normalized..PP.CStypedef int Tcl_FSNormalizePathProc(	Tcl_Interp *\fIinterp\fR, 	Tcl_Obj *\fIpathPtr\fR, 	int \fInextCheckpoint\fR);.CE.SH "FILESYSTEM OPERATIONS".PPThe fields in this section of the structure contain addresses offunctions which are called to carry out the basic filesystemoperations.  A filesystem which expects to be used with the completestandard Tcl command set must implement all of these.  If some ofthem are not implemented, then certain Tcl commands may fail whenoperating on paths within that filesystem.  However, in some instancesthis may be desirable (for example, a read-only filesystem should notimplement the last four functions, and a filesystem which does notsupport symbolic links need not implement the \fBreadlink\fR function,etc.  The Tcl core expects filesystems to behave in this way)..SH FILESYSTEMPATHTYPEPROC.PPFunction to determine the type of a path in this filesystem.  May beNULL, in which case no type information will be available to users ofthe filesystem.  The 'type' is used only for informational purposes,and should be returned as the string representation of the Tcl_Objwhich is returned.  A typical return value might be "networked", "zip"or "ftp".  The Tcl_Obj result is owned by the filesystem and so Tcl will increment the refCount of that object if it wishes to retain a reference to it..PP.CStypedef Tcl_Obj* Tcl_FSFilesystemPathTypeProc(	Tcl_Obj *\fIpathPtr\fR);.CE.SH FILESYSTEMSEPARATORPROC.PPFunction to return the separator character(s) for this filesystem.Must be implemented, otherwise the \fBfile separator\fR command will notfunction correctly.  The usual return value will be a Tcl_Objcontaining the string "/"..PP.CStypedef Tcl_Obj* Tcl_FSFilesystemSeparatorProc(	Tcl_Obj *\fIpathPtr\fR);.CE.SH STATPROC .PPFunction to process a \fBTcl_FSStat()\fR call.  Must be implemented for anyreasonable filesystem, since many Tcl level commands depend crucially upon it (e.g. \fBfile atime\fR, \fBfile isdirectory\fR, \fBfile size\fR,\fBglob\fR)..PP.CStypedef int Tcl_FSStatProc(	Tcl_Obj *\fIpathPtr\fR,	Tcl_StatBuf *\fIstatPtr\fR);.CE.PPThe \fBTcl_FSStatProc\fR fills the stat structure \fIstatPtr\fR withinformation about the specified file.  You do not need any accessrights to the file to get this information but you need search rightsto all directories named in the path leading to the file.  The statstructure includes info regarding device, inode (always 0 on Windows),privilege mode, nlink (always 1 on Windows), user id (always 0 onWindows), group id (always 0 on Windows), rdev (same as device onWindows), size, last access time, last modification time, and creationtime..PPIf the file represented by \fIpathPtr\fR exists, the\fBTcl_FSStatProc\fR returns 0 and the stat structure is filled withdata.  Otherwise, -1 is returned, and no stat info is given..SH ACCESSPROC	    .PPFunction to process a \fBTcl_FSAccess()\fR call.  Must be implemented forany reasonable filesystem, since many Tcl level commands depend crucially upon it (e.g. \fBfile exists\fR, \fBfile readable\fR)..PP.CStypedef int Tcl_FSAccessProc(	Tcl_Obj *\fIpathPtr\fR,	int \fImode\fR);.CE.PPThe \fBTcl_FSAccessProc\fR checks whether the process would be allowedto read, write or test for existence of the file (or other file systemobject) whose name is pathname.  If pathname is a symbolic link, thenpermissions of the file referred by this symbolic link should be tested..PPOn success (all requested permissions granted), zero is returned.  Onerror (at least one bit in mode asked for a permission that is denied,or some other  error occurred), -1 is returned..PP.SH OPENFILECHANNELPROC .PPFunction to process a \fBTcl_FSOpenFileChannel()\fR call.  Must beimplemented for any reasonable filesystem, since any operationswhich require open or accessing a file's contents will use it (e.g. \fBopen\fR, \fBencoding\fR, and many Tk commands)..PP.CStypedef Tcl_Channel Tcl_FSOpenFileChannelProc(	Tcl_Interp *\fIinterp\fR,	Tcl_Obj *\fIpathPtr\fR,	int \fImode\fR,	int \fIpermissions\fR);.CE.PPThe \fBTcl_FSOpenFileChannelProc\fR opens a file specified by\fIpathPtr\fR and returns a channel handle that can be used to performinput and output on the file.  This API is modeled after the \fBfopen\fRprocedure of the Unix standard I/O library.  The syntax and meaning ofall arguments is similar to those given in the Tcl \fBopen\fR commandwhen opening a file, where the \fImode\fR argument is a combination ofthe POSIX flags O_RDONLY, O_WRONLY, etc.  If an error occurs whileopening the channel, the \fBTcl_FSOpenFileChannelProc\fR returns NULL andrecords a POSIX error code that can be retrieved with \fBTcl_GetErrno\fR.In addition, if \fIinterp\fR is non-NULL, the\fBTcl_FSOpenFileChannelProc\fR leaves an error message in \fIinterp\fR'sresult after any error..PPThe newly created channel is not registered in the suppliedinterpreter; to register it, use \fBTcl_RegisterChannel\fR. If one ofthe standard channels, \fBstdin, stdout\fR or \fBstderr\fR waspreviously closed, the act of creating the new channel also assigns itas a replacement for the standard channel..SH MATCHINDIRECTORYPROC  .PPFunction to process a \fBTcl_FSMatchInDirectory()\fR call.  If notimplemented, then glob and recursive copy functionality will be lackingin the filesystem (and this may impact commands like 'encoding names' which use glob functionality internally)..PP.CStypedef int Tcl_FSMatchInDirectoryProc(	Tcl_Interp* \fIinterp\fR, 	Tcl_Obj *\fIresult\fR,	Tcl_Obj *\fIpathPtr\fR, 	CONST char *\fIpattern\fR, 	Tcl_GlobTypeData * \fItypes\fR);.CE.PPThe function should return all files or directories (or other filesystemobjects) which match the given pattern and accord with the \fItypes\fRspecification given.  There are two ways in which this function may becalled.  If \fIpattern\fR is NULL, then \fIpathPtr\fR is a full pathspecification of a single file or directory which should be checked forexistence and correct type.  Otherwise, \fIpathPtr\fR is a directory, thecontents of which the function should search for files or directorieswhich have the correct type.  In either case, \fIpathPtr\fR can beassumed to be both non-NULL and non-empty.  It is not currently

⌨️ 快捷键说明

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