| 1 |
'\" |
| 2 |
'\" Copyright (c) 2001 Vincent Darley |
| 3 |
'\" Copyright (c) 2008-2010 Donal K. Fellows |
| 4 |
'\" |
| 5 |
'\" See the file "license.terms" for information on usage and redistribution |
| 6 |
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 7 |
'\" |
| 8 |
.TH Filesystem 3 8.4 Tcl "Tcl Library Procedures" |
| 9 |
.so man.macros |
| 10 |
.BS |
| 11 |
.SH NAME |
| 12 |
Tcl_FSRegister, Tcl_FSUnregister, Tcl_FSData, Tcl_FSMountsChanged, Tcl_FSGetFileSystemForPath, Tcl_FSGetPathType, Tcl_FSCopyFile, Tcl_FSCopyDirectory, Tcl_FSCreateDirectory, Tcl_FSDeleteFile, Tcl_FSRemoveDirectory, Tcl_FSRenameFile, Tcl_FSListVolumes, Tcl_FSEvalFile, Tcl_FSEvalFileEx, Tcl_FSLoadFile, Tcl_FSUnloadFile, Tcl_FSMatchInDirectory, Tcl_FSLink, Tcl_FSLstat, Tcl_FSUtime, Tcl_FSFileAttrsGet, Tcl_FSFileAttrsSet, Tcl_FSFileAttrStrings, Tcl_FSStat, Tcl_FSAccess, Tcl_FSOpenFileChannel, Tcl_FSGetCwd, Tcl_FSChdir, Tcl_FSPathSeparator, Tcl_FSJoinPath, Tcl_FSSplitPath, Tcl_FSEqualPaths, Tcl_FSGetNormalizedPath, Tcl_FSJoinToPath, Tcl_FSConvertToPathType, Tcl_FSGetInternalRep, Tcl_FSGetTranslatedPath, Tcl_FSGetTranslatedStringPath, Tcl_FSNewNativePath, Tcl_FSGetNativePath, Tcl_FSFileSystemInfo, Tcl_GetAccessTimeFromStat, Tcl_GetBlockSizeFromStat, Tcl_GetBlocksFromStat, Tcl_GetChangeTimeFromStat, Tcl_GetDeviceTypeFromStat, Tcl_GetFSDeviceFromStat, Tcl_GetFSInodeFromStat, Tcl_GetGroupIdFromStat, Tcl_GetLinkCountFromStat, Tcl_GetModeFromStat, Tcl_GetModificationTimeFromStat, Tcl_GetSizeFromStat, Tcl_GetUserIdFromStat, Tcl_AllocStatBuf \- procedures to interact with any filesystem |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
\fB#include <tcl.h>\fR |
| 16 |
.sp |
| 17 |
int |
| 18 |
\fBTcl_FSRegister\fR(\fIclientData, fsPtr\fR) |
| 19 |
.sp |
| 20 |
int |
| 21 |
\fBTcl_FSUnregister\fR(\fIfsPtr\fR) |
| 22 |
.sp |
| 23 |
void * |
| 24 |
\fBTcl_FSData\fR(\fIfsPtr\fR) |
| 25 |
.sp |
| 26 |
\fBTcl_FSMountsChanged\fR(\fIfsPtr\fR) |
| 27 |
.sp |
| 28 |
const Tcl_Filesystem * |
| 29 |
\fBTcl_FSGetFileSystemForPath\fR(\fIpathPtr\fR) |
| 30 |
.sp |
| 31 |
Tcl_PathType |
| 32 |
\fBTcl_FSGetPathType\fR(\fIpathPtr\fR) |
| 33 |
.sp |
| 34 |
int |
| 35 |
\fBTcl_FSCopyFile\fR(\fIsrcPathPtr, destPathPtr\fR) |
| 36 |
.sp |
| 37 |
int |
| 38 |
\fBTcl_FSCopyDirectory\fR(\fIsrcPathPtr, destPathPtr, errorPtr\fR) |
| 39 |
.sp |
| 40 |
int |
| 41 |
\fBTcl_FSCreateDirectory\fR(\fIpathPtr\fR) |
| 42 |
.sp |
| 43 |
int |
| 44 |
\fBTcl_FSDeleteFile\fR(\fIpathPtr\fR) |
| 45 |
.sp |
| 46 |
int |
| 47 |
\fBTcl_FSRemoveDirectory\fR(\fIpathPtr, recursive, errorPtr\fR) |
| 48 |
.sp |
| 49 |
int |
| 50 |
\fBTcl_FSRenameFile\fR(\fIsrcPathPtr, destPathPtr\fR) |
| 51 |
.sp |
| 52 |
Tcl_Obj * |
| 53 |
\fBTcl_FSListVolumes\fR(\fIvoid\fR) |
| 54 |
.sp |
| 55 |
int |
| 56 |
\fBTcl_FSEvalFileEx\fR(\fIinterp, pathPtr, encodingName\fR) |
| 57 |
.sp |
| 58 |
int |
| 59 |
\fBTcl_FSEvalFile\fR(\fIinterp, pathPtr\fR) |
| 60 |
.sp |
| 61 |
int |
| 62 |
\fBTcl_FSLoadFile\fR(\fIinterp, pathPtr, sym1, sym2, proc1Ptr, proc2Ptr, |
| 63 |
loadHandlePtr, unloadProcPtr\fR) |
| 64 |
.sp |
| 65 |
.VS 8.6 |
| 66 |
int |
| 67 |
\fBTcl_FSUnloadFile\fR(\fIinterp, loadHandle\fR) |
| 68 |
.VE 8.6 |
| 69 |
.sp |
| 70 |
int |
| 71 |
\fBTcl_FSMatchInDirectory\fR(\fIinterp, resultPtr, pathPtr, pattern, types\fR) |
| 72 |
.sp |
| 73 |
Tcl_Obj * |
| 74 |
\fBTcl_FSLink\fR(\fIlinkNamePtr, toPtr, linkAction\fR) |
| 75 |
.sp |
| 76 |
int |
| 77 |
\fBTcl_FSLstat\fR(\fIpathPtr, statPtr\fR) |
| 78 |
.sp |
| 79 |
int |
| 80 |
\fBTcl_FSUtime\fR(\fIpathPtr, tval\fR) |
| 81 |
.sp |
| 82 |
int |
| 83 |
\fBTcl_FSFileAttrsGet\fR(\fIinterp, index, pathPtr, objPtrRef\fR) |
| 84 |
.sp |
| 85 |
int |
| 86 |
\fBTcl_FSFileAttrsSet\fR(\fIinterp, index, pathPtr, objPtr\fR) |
| 87 |
.sp |
| 88 |
const char *const * |
| 89 |
\fBTcl_FSFileAttrStrings\fR(\fIpathPtr, objPtrRef\fR) |
| 90 |
.sp |
| 91 |
int |
| 92 |
\fBTcl_FSStat\fR(\fIpathPtr, statPtr\fR) |
| 93 |
.sp |
| 94 |
int |
| 95 |
\fBTcl_FSAccess\fR(\fIpathPtr, mode\fR) |
| 96 |
.sp |
| 97 |
Tcl_Channel |
| 98 |
\fBTcl_FSOpenFileChannel\fR(\fIinterp, pathPtr, modeString, permissions\fR) |
| 99 |
.sp |
| 100 |
Tcl_Obj * |
| 101 |
\fBTcl_FSGetCwd\fR(\fIinterp\fR) |
| 102 |
.sp |
| 103 |
int |
| 104 |
\fBTcl_FSChdir\fR(\fIpathPtr\fR) |
| 105 |
.sp |
| 106 |
Tcl_Obj * |
| 107 |
\fBTcl_FSPathSeparator\fR(\fIpathPtr\fR) |
| 108 |
.sp |
| 109 |
Tcl_Obj * |
| 110 |
\fBTcl_FSJoinPath\fR(\fIlistObj, elements\fR) |
| 111 |
.sp |
| 112 |
Tcl_Obj * |
| 113 |
\fBTcl_FSSplitPath\fR(\fIpathPtr, lenPtr\fR) |
| 114 |
.sp |
| 115 |
int |
| 116 |
\fBTcl_FSEqualPaths\fR(\fIfirstPtr, secondPtr\fR) |
| 117 |
.sp |
| 118 |
Tcl_Obj * |
| 119 |
\fBTcl_FSGetNormalizedPath\fR(\fIinterp, pathPtr\fR) |
| 120 |
.sp |
| 121 |
Tcl_Obj * |
| 122 |
\fBTcl_FSJoinToPath\fR(\fIbasePtr, objc, objv\fR) |
| 123 |
.sp |
| 124 |
int |
| 125 |
\fBTcl_FSConvertToPathType\fR(\fIinterp, pathPtr\fR) |
| 126 |
.sp |
| 127 |
void * |
| 128 |
\fBTcl_FSGetInternalRep\fR(\fIpathPtr, fsPtr\fR) |
| 129 |
.sp |
| 130 |
Tcl_Obj * |
| 131 |
\fBTcl_FSGetTranslatedPath\fR(\fIinterp, pathPtr\fR) |
| 132 |
.sp |
| 133 |
const char * |
| 134 |
\fBTcl_FSGetTranslatedStringPath\fR(\fIinterp, pathPtr\fR) |
| 135 |
.sp |
| 136 |
Tcl_Obj * |
| 137 |
\fBTcl_FSNewNativePath\fR(\fIfsPtr, clientData\fR) |
| 138 |
.sp |
| 139 |
const void * |
| 140 |
\fBTcl_FSGetNativePath\fR(\fIpathPtr\fR) |
| 141 |
.sp |
| 142 |
Tcl_Obj * |
| 143 |
\fBTcl_FSFileSystemInfo\fR(\fIpathPtr\fR) |
| 144 |
.sp |
| 145 |
Tcl_StatBuf * |
| 146 |
\fBTcl_AllocStatBuf\fR() |
| 147 |
.sp |
| 148 |
.VS 8.6 |
| 149 |
Tcl_WideInt |
| 150 |
\fBTcl_GetAccessTimeFromStat\fR(\fIstatPtr\fR) |
| 151 |
.sp |
| 152 |
unsigned |
| 153 |
\fBTcl_GetBlockSizeFromStat\fR(\fIstatPtr\fR) |
| 154 |
.sp |
| 155 |
Tcl_WideUInt |
| 156 |
\fBTcl_GetBlocksFromStat\fR(\fIstatPtr\fR) |
| 157 |
.sp |
| 158 |
Tcl_WideInt |
| 159 |
\fBTcl_GetChangeTimeFromStat\fR(\fIstatPtr\fR) |
| 160 |
.sp |
| 161 |
int |
| 162 |
\fBTcl_GetDeviceTypeFromStat\fR(\fIstatPtr\fR) |
| 163 |
.sp |
| 164 |
unsigned |
| 165 |
\fBTcl_GetFSDeviceFromStat\fR(\fIstatPtr\fR) |
| 166 |
.sp |
| 167 |
unsigned |
| 168 |
\fBTcl_GetFSInodeFromStat\fR(\fIstatPtr\fR) |
| 169 |
.sp |
| 170 |
int |
| 171 |
\fBTcl_GetGroupIdFromStat\fR(\fIstatPtr\fR) |
| 172 |
.sp |
| 173 |
int |
| 174 |
\fBTcl_GetLinkCountFromStat\fR(\fIstatPtr\fR) |
| 175 |
.sp |
| 176 |
unsigned |
| 177 |
\fBTcl_GetModeFromStat\fR(\fIstatPtr\fR) |
| 178 |
.sp |
| 179 |
Tcl_WideInt |
| 180 |
\fBTcl_GetModificationTimeFromStat\fR(\fIstatPtr\fR) |
| 181 |
.sp |
| 182 |
Tcl_WideUInt |
| 183 |
\fBTcl_GetSizeFromStat\fR(\fIstatPtr\fR) |
| 184 |
.sp |
| 185 |
int |
| 186 |
\fBTcl_GetUserIdFromStat\fR(\fIstatPtr\fR) |
| 187 |
.VE 8.6 |
| 188 |
.SH ARGUMENTS |
| 189 |
.AS Tcl_GlobTypeData **srcPathPtr out |
| 190 |
.AP "const Tcl_Filesystem" *fsPtr in |
| 191 |
Points to a structure containing the addresses of procedures that |
| 192 |
can be called to perform the various filesystem operations. |
| 193 |
.AP Tcl_Obj *pathPtr in |
| 194 |
The path represented by this value is used for the operation in |
| 195 |
question. If the value does not already have an internal \fBpath\fR |
| 196 |
representation, it will be converted to have one. |
| 197 |
.AP Tcl_Obj *srcPathPtr in |
| 198 |
As for \fIpathPtr\fR, but used for the source file for a copy or |
| 199 |
rename operation. |
| 200 |
.AP Tcl_Obj *destPathPtr in |
| 201 |
As for \fIpathPtr\fR, but used for the destination filename for a copy or |
| 202 |
rename operation. |
| 203 |
.AP int recursive in |
| 204 |
Whether to remove subdirectories and their contents as well. |
| 205 |
.AP "const char" *encodingName in |
| 206 |
The encoding of the data stored in the |
| 207 |
file identified by \fIpathPtr\fR and to be evaluated. |
| 208 |
.AP "const char" *pattern in |
| 209 |
Only files or directories matching this pattern will be returned. |
| 210 |
.AP Tcl_GlobTypeData *types in |
| 211 |
Only files or directories matching the type descriptions contained in |
| 212 |
this structure will be returned. This parameter may be NULL. |
| 213 |
.AP Tcl_Interp *interp in |
| 214 |
Interpreter to use either for results, evaluation, or reporting error |
| 215 |
messages. |
| 216 |
.AP void *clientData in |
| 217 |
The native description of the path value to create. |
| 218 |
.AP Tcl_Obj *firstPtr in |
| 219 |
The first of two path values to compare. The value may be converted |
| 220 |
to \fBpath\fR type. |
| 221 |
.AP Tcl_Obj *secondPtr in |
| 222 |
The second of two path values to compare. The value may be converted |
| 223 |
to \fBpath\fR type. |
| 224 |
.AP Tcl_Obj *listObj in |
| 225 |
The list of path elements to operate on with a \fBjoin\fR operation. |
| 226 |
.AP int elements in |
| 227 |
The number of elements in the \fIlistObj\fR which should |
| 228 |
be joined together. If negative, then all elements are joined. |
| 229 |
.AP Tcl_Obj **errorPtr out |
| 230 |
In the case of an error, filled with a value containing the name of |
| 231 |
the file which caused an error in the various copy/rename operations. |
| 232 |
.AP int index in |
| 233 |
The index of the attribute in question. |
| 234 |
.AP Tcl_Obj *objPtr in |
| 235 |
The value to set in the operation. |
| 236 |
.AP Tcl_Obj **objPtrRef out |
| 237 |
Filled with a value containing the result of the operation. |
| 238 |
.AP Tcl_Obj *resultPtr out |
| 239 |
Preallocated value in which to store (using |
| 240 |
\fBTcl_ListObjAppendElement\fR) the list of |
| 241 |
files or directories which are successfully matched. |
| 242 |
.AP int mode in |
| 243 |
Mask consisting of one or more of R_OK, W_OK, X_OK and F_OK. R_OK, |
| 244 |
W_OK and X_OK request checking whether the file exists and has read, |
| 245 |
write and execute permissions, respectively. F_OK just requests |
| 246 |
checking for the existence of the file. |
| 247 |
.AP Tcl_StatBuf *statPtr out |
| 248 |
The structure that contains the result of a stat or lstat operation. |
| 249 |
.AP "const char" *sym1 in |
| 250 |
Name of a procedure to look up in the file's symbol table |
| 251 |
.AP "const char" *sym2 in |
| 252 |
Name of a procedure to look up in the file's symbol table |
| 253 |
.AP Tcl_PackageInitProc **proc1Ptr out |
| 254 |
Filled with the init function for this code. |
| 255 |
.AP Tcl_PackageInitProc **proc2Ptr out |
| 256 |
Filled with the safe-init function for this code. |
| 257 |
.AP void **clientDataPtr out |
| 258 |
Filled with the clientData value to pass to this code's unload |
| 259 |
function when it is called. |
| 260 |
.AP Tcl_LoadHandle *loadHandlePtr out |
| 261 |
Filled with an abstract token representing the loaded file. |
| 262 |
.AP Tcl_FSUnloadFileProc **unloadProcPtr out |
| 263 |
Filled with the function to use to unload this piece of code. |
| 264 |
.AP Tcl_LoadHandle loadHandle in |
| 265 |
Handle to the loaded library to be unloaded. |
| 266 |
.AP utimbuf *tval in |
| 267 |
The access and modification times in this structure are read and |
| 268 |
used to set those values for a given file. |
| 269 |
.AP "const char" *modeString in |
| 270 |
Specifies how the file is to be accessed. May have any of the values |
| 271 |
allowed for the \fImode\fR argument to the Tcl \fBopen\fR command. |
| 272 |
.AP int permissions in |
| 273 |
POSIX-style permission flags such as 0644. If a new file is created, these |
| 274 |
permissions will be set on the created file. |
| 275 |
.AP int *lenPtr out |
| 276 |
If non-NULL, filled with the number of elements in the split path. |
| 277 |
.AP Tcl_Obj *basePtr in |
| 278 |
The base path on to which to join the given elements. May be NULL. |
| 279 |
.AP int objc in |
| 280 |
The number of elements in \fIobjv\fR. |
| 281 |
.AP "Tcl_Obj *const" objv[] in |
| 282 |
The elements to join to the given base path. |
| 283 |
.AP Tcl_Obj *linkNamePtr in |
| 284 |
The name of the link to be created or read. |
| 285 |
.AP Tcl_Obj *toPtr in |
| 286 |
What the link called \fIlinkNamePtr\fR should be linked to, or NULL if |
| 287 |
the symbolic link specified by \fIlinkNamePtr\fR is to be read. |
| 288 |
.AP int linkAction in |
| 289 |
OR-ed combination of flags indicating what kind of link should be |
| 290 |
created (will be ignored if \fItoPtr\fR is NULL). Valid bits to set |
| 291 |
are \fBTCL_CREATE_SYMBOLIC_LINK\fR and \fBTCL_CREATE_HARD_LINK\fR. |
| 292 |
When both flags are set and the underlying filesystem can do either, |
| 293 |
symbolic links are preferred. |
| 294 |
.BE |
| 295 |
.SH DESCRIPTION |
| 296 |
.PP |
| 297 |
There are several reasons for calling the \fBTcl_FS\fR API functions |
| 298 |
(e.g.\ \fBTcl_FSAccess\fR and \fBTcl_FSStat\fR) |
| 299 |
rather than calling system level functions like \fBaccess\fR and |
| 300 |
\fBstat\fR directly. First, they will work cross-platform, so an |
| 301 |
extension which calls them should work unmodified on Unix and |
| 302 |
Windows. Second, the Windows implementation of some of these functions |
| 303 |
fixes some bugs in the system level calls. Third, these function calls |
| 304 |
deal with any |
| 305 |
.QW "Utf to platform-native" |
| 306 |
path conversions which may be |
| 307 |
required (and may cache the results of such conversions for greater |
| 308 |
efficiency on subsequent calls). Fourth, and perhaps most importantly, |
| 309 |
all of these functions are |
| 310 |
.QW "virtual filesystem aware" . |
| 311 |
Any virtual filesystem (VFS for short) which has been registered (through |
| 312 |
\fBTcl_FSRegister\fR) may reroute file access to alternative |
| 313 |
media or access methods. This means that all of these functions (and |
| 314 |
therefore the corresponding \fBfile\fR, \fBglob\fR, \fBpwd\fR, \fBcd\fR, |
| 315 |
\fBopen\fR, etc.\ Tcl commands) may be operate on |
| 316 |
.QW files |
| 317 |
which are not |
| 318 |
native files in the native filesystem. This also means that any Tcl |
| 319 |
extension which accesses the filesystem (FS for short) through this API is |
| 320 |
automatically |
| 321 |
.QW "virtual filesystem aware" . |
| 322 |
Of course, if an extension |
| 323 |
accesses the native filesystem directly (through platform-specific |
| 324 |
APIs, for example), then Tcl cannot intercept such calls. |
| 325 |
.PP |
| 326 |
If appropriate VFSes have been registered, the |
| 327 |
.QW files |
| 328 |
may, to give two |
| 329 |
examples, be remote (e.g.\ situated on a remote ftp server) or archived |
| 330 |
(e.g.\ lying inside a .zip archive). Such registered filesystems provide |
| 331 |
a lookup table of functions to implement all or some of the functionality |
| 332 |
listed here. Finally, the \fBTcl_FSStat\fR and \fBTcl_FSLstat\fR calls |
| 333 |
abstract away from what the |
| 334 |
.QW "struct stat" |
| 335 |
buffer is actually |
| 336 |
declared to be, allowing the same code to be used both on systems with |
| 337 |
and systems without support for files larger than 2GB in size. |
| 338 |
.PP |
| 339 |
The \fBTcl_FS\fR API is \fBTcl_Obj\fR-ified and may cache internal |
| 340 |
representations and other path-related strings (e.g.\ the current working |
| 341 |
directory). One side-effect of this is that one must not pass in values |
| 342 |
with a reference count of zero to any of these functions. If such calls were |
| 343 |
handled, they might result |
| 344 |
in memory leaks (under some circumstances, the filesystem code may wish |
| 345 |
to retain a reference to the passed in value, and so one must not assume |
| 346 |
that after any of these calls return, the value still has a reference count of |
| 347 |
zero - it may have been incremented) or in a direct segmentation fault |
| 348 |
(or other memory access error) |
| 349 |
due to the value being freed part way through the complex value |
| 350 |
manipulation required to ensure that the path is fully normalized and |
| 351 |
absolute for filesystem determination. The practical lesson to learn |
| 352 |
from this is that |
| 353 |
.PP |
| 354 |
.CS |
| 355 |
Tcl_Obj *path = Tcl_NewStringObj(...); |
| 356 |
Tcl_FS\fIWhatever\fR(path); |
| 357 |
Tcl_DecrRefCount(path); |
| 358 |
.CE |
| 359 |
.PP |
| 360 |
is wrong, and may cause memory errors. The \fIpath\fR must have its |
| 361 |
reference count incremented before passing it in, or |
| 362 |
decrementing it. For this reason, values with a reference count of zero are |
| 363 |
considered not to be valid filesystem paths and calling any Tcl_FS API |
| 364 |
function with such a value will result in no action being taken. |
| 365 |
.SS "FS API FUNCTIONS" |
| 366 |
\fBTcl_FSCopyFile\fR attempts to copy the file given by \fIsrcPathPtr\fR to the |
| 367 |
path name given by \fIdestPathPtr\fR. If the two paths given lie in the same |
| 368 |
filesystem (according to \fBTcl_FSGetFileSystemForPath\fR) then that |
| 369 |
filesystem's |
| 370 |
.QW "copy file" |
| 371 |
function is called (if it is non-NULL). |
| 372 |
Otherwise the function returns -1 and sets the \fBerrno\fR global C |
| 373 |
variable to the |
| 374 |
.QW EXDEV |
| 375 |
POSIX error code (which signifies a |
| 376 |
.QW "cross-domain link" ). |
| 377 |
.PP |
| 378 |
\fBTcl_FSCopyDirectory\fR attempts to copy the directory given by |
| 379 |
\fIsrcPathPtr\fR to the |
| 380 |
path name given by \fIdestPathPtr\fR. If the two paths given lie in the same |
| 381 |
filesystem (according to \fBTcl_FSGetFileSystemForPath\fR) then that |
| 382 |
filesystem's |
| 383 |
.QW "copy file" |
| 384 |
function is called (if it is non-NULL). |
| 385 |
Otherwise the function returns -1 and sets the \fBerrno\fR global C |
| 386 |
variable to the |
| 387 |
.QW EXDEV |
| 388 |
POSIX error code (which signifies a |
| 389 |
.QW "cross-domain link" ). |
| 390 |
.PP |
| 391 |
\fBTcl_FSCreateDirectory\fR attempts to create the directory given by |
| 392 |
\fIpathPtr\fR by calling the owning filesystem's |
| 393 |
.QW "create directory" |
| 394 |
function. |
| 395 |
.PP |
| 396 |
\fBTcl_FSDeleteFile\fR attempts to delete the file given by |
| 397 |
\fIpathPtr\fR by calling the owning filesystem's |
| 398 |
.QW "delete file" |
| 399 |
function. |
| 400 |
.PP |
| 401 |
\fBTcl_FSRemoveDirectory\fR attempts to remove the directory given by |
| 402 |
\fIpathPtr\fR by calling the owning filesystem's |
| 403 |
.QW "remove directory" |
| 404 |
function. |
| 405 |
.PP |
| 406 |
\fBTcl_FSRenameFile\fR attempts to rename the file or directory given by |
| 407 |
\fIsrcPathPtr\fR to the path name given by \fIdestPathPtr\fR. If the two paths |
| 408 |
given lie in the same filesystem (according to |
| 409 |
\fBTcl_FSGetFileSystemForPath\fR) then that filesystem's |
| 410 |
.QW "rename file" |
| 411 |
function is called (if it is non-NULL). Otherwise the function returns -1 |
| 412 |
and sets the \fBerrno\fR global C variable to the |
| 413 |
.QW EXDEV |
| 414 |
POSIX error code (which signifies a |
| 415 |
.QW "cross-domain link" ). |
| 416 |
.PP |
| 417 |
\fBTcl_FSListVolumes\fR calls each filesystem which has a non-NULL |
| 418 |
.QW "list volumes" |
| 419 |
function and asks them to return their list of root volumes. It |
| 420 |
accumulates the return values in a list which is returned to the |
| 421 |
caller (with a reference count of 0). |
| 422 |
.PP |
| 423 |
\fBTcl_FSEvalFileEx\fR reads the file given by \fIpathPtr\fR using |
| 424 |
the encoding identified by \fIencodingName\fR and evaluates |
| 425 |
its contents as a Tcl script. It returns the same information as |
| 426 |
\fBTcl_EvalObjEx\fR. |
| 427 |
If \fIencodingName\fR is NULL, the system encoding is used for |
| 428 |
reading the file contents. |
| 429 |
If the file could not be read then a Tcl error is returned to describe |
| 430 |
why the file could not be read. |
| 431 |
The eofchar for files is |
| 432 |
.QW \ex1A |
| 433 |
(^Z) for all platforms. |
| 434 |
If you require a |
| 435 |
.QW ^Z |
| 436 |
in code for string comparison, you can use |
| 437 |
.QW \ex1A , |
| 438 |
which will be safely substituted by the Tcl interpreter into |
| 439 |
.QW ^Z . |
| 440 |
\fBTcl_FSEvalFile\fR is a simpler version of |
| 441 |
\fBTcl_FSEvalFileEx\fR that always uses the system encoding |
| 442 |
when reading the file. |
| 443 |
.PP |
| 444 |
\fBTcl_FSLoadFile\fR dynamically loads a binary code file into memory and |
| 445 |
returns the addresses of two procedures within that file, if they are |
| 446 |
defined. The appropriate function for the filesystem to which \fIpathPtr\fR |
| 447 |
belongs will be called. If that filesystem does not implement this |
| 448 |
function (most virtual filesystems will not, because of OS limitations |
| 449 |
in dynamically loading binary code), Tcl will attempt to copy the file |
| 450 |
to a temporary directory and load that temporary file. |
| 451 |
.VS 8.6 |
| 452 |
\fBTcl_FSUnloadFile\fR reverses the operation, asking for the library |
| 453 |
indicated by the \fIloadHandle\fR to be removed from the process. Note that, |
| 454 |
unlike with the \fBunload\fR command, this does not give the library any |
| 455 |
opportunity to clean up. |
| 456 |
.VE 8.6 |
| 457 |
.PP |
| 458 |
Both the above functions return a standard Tcl completion code. If an error |
| 459 |
occurs, an error message is left in the \fIinterp\fR's result. |
| 460 |
.PP |
| 461 |
.VS 8.6 |
| 462 |
The token provided via the variable indicated by \fIloadHandlePtr\fR may be |
| 463 |
used with \fBTcl_FindSymbol\fR. |
| 464 |
.VE 8.6 |
| 465 |
.PP |
| 466 |
\fBTcl_FSMatchInDirectory\fR is used by the globbing code to search a |
| 467 |
directory for all files which match a given pattern. The appropriate |
| 468 |
function for the filesystem to which \fIpathPtr\fR belongs will be called. |
| 469 |
.PP |
| 470 |
The return value is a standard Tcl result indicating whether an error |
| 471 |
occurred in globbing. Error messages are placed in interp (unless |
| 472 |
interp is NULL, which is allowed), but good results are placed in the |
| 473 |
resultPtr given. |
| 474 |
.PP |
| 475 |
Note that the \fBglob\fR code implements recursive patterns internally, so |
| 476 |
this function will only ever be passed simple patterns, which can be |
| 477 |
matched using the logic of \fBstring match\fR. To handle recursion, Tcl |
| 478 |
will call this function frequently asking only for directories to be |
| 479 |
returned. A special case of being called with a NULL pattern indicates |
| 480 |
that the path needs to be checked only for the correct type. |
| 481 |
.PP |
| 482 |
\fBTcl_FSLink\fR replaces the library version of \fBreadlink\fR, and |
| 483 |
extends it to support the creation of links. The appropriate function |
| 484 |
for the filesystem to which \fIlinkNamePtr\fR belongs will be called. |
| 485 |
.PP |
| 486 |
If the \fItoPtr\fR is NULL, a |
| 487 |
.QW "read link" |
| 488 |
action is performed. The result |
| 489 |
is a Tcl_Obj specifying the contents of the symbolic link given by |
| 490 |
\fIlinkNamePtr\fR, or NULL if the link could not be read. The result is owned |
| 491 |
by the caller, which should call \fBTcl_DecrRefCount\fR when the result is no |
| 492 |
longer needed. If the \fItoPtr\fR is not NULL, Tcl should create a link |
| 493 |
of one of the types passed in in the \fIlinkAction\fR flag. |
| 494 |
This flag is an OR'ed combination of \fBTCL_CREATE_SYMBOLIC_LINK\fR |
| 495 |
and \fBTCL_CREATE_HARD_LINK\fR. |
| 496 |
Where a choice exists (i.e.\ more than one flag is passed in), the Tcl |
| 497 |
convention is to prefer symbolic links. When a link is successfully |
| 498 |
created, the return value should be \fItoPtr\fR (which is therefore |
| 499 |
already owned by the caller). If unsuccessful, NULL is returned. |
| 500 |
.PP |
| 501 |
\fBTcl_FSLstat\fR fills the \fITcl_StatBuf\fR structure \fIstatPtr\fR with |
| 502 |
information about the specified file. You do not need any access rights to the |
| 503 |
file to get this information but you need search rights to all |
| 504 |
directories named in the path leading to the file. The \fITcl_StatBuf\fR |
| 505 |
structure includes info regarding device, inode (always 0 on Windows), |
| 506 |
privilege mode, nlink (always 1 on Windows), user id (always 0 on |
| 507 |
Windows), group id (always 0 on Windows), rdev (same as device on |
| 508 |
Windows), size, last access time, last modification time, and |
| 509 |
last metadata change time. |
| 510 |
See \fBPORTABLE STAT RESULT API\fR for a description of how to write |
| 511 |
portable code to allocate and access the \fITcl_StatBuf\fR structure. |
| 512 |
.PP |
| 513 |
If \fIpath\fR exists, \fBTcl_FSLstat\fR returns 0 and the stat structure |
| 514 |
is filled with data. Otherwise, -1 is returned, and no stat info is |
| 515 |
given. |
| 516 |
.PP |
| 517 |
\fBTcl_FSUtime\fR replaces the library version of utime. |
| 518 |
.PP |
| 519 |
This returns 0 on success and -1 on error (as per the \fButime\fR |
| 520 |
documentation). If successful, the function |
| 521 |
will update the |
| 522 |
.QW atime |
| 523 |
and |
| 524 |
.QW mtime |
| 525 |
values of the file given. |
| 526 |
.PP |
| 527 |
\fBTcl_FSFileAttrsGet\fR implements read access for the hookable \fBfile |
| 528 |
attributes\fR subcommand. The appropriate function for the filesystem to |
| 529 |
which \fIpathPtr\fR belongs will be called. |
| 530 |
.PP |
| 531 |
If the result is \fBTCL_OK\fR, then a value was placed in |
| 532 |
\fIobjPtrRef\fR, which |
| 533 |
will only be temporarily valid (unless \fBTcl_IncrRefCount\fR is called). |
| 534 |
.PP |
| 535 |
\fBTcl_FSFileAttrsSet\fR implements write access for the hookable \fBfile |
| 536 |
attributes\fR subcommand. The appropriate function for the filesystem to |
| 537 |
which \fIpathPtr\fR belongs will be called. |
| 538 |
.PP |
| 539 |
\fBTcl_FSFileAttrStrings\fR implements part of the hookable \fBfile |
| 540 |
attributes\fR subcommand. The appropriate function for the filesystem |
| 541 |
to which \fIpathPtr\fR belongs will be called. |
| 542 |
.PP |
| 543 |
The called procedure may either return an array of strings, or may |
| 544 |
instead return NULL and place a Tcl list into the given \fIobjPtrRef\fR. Tcl |
| 545 |
will take that list and first increment its reference count before using it. |
| 546 |
On completion of that use, Tcl will decrement its reference count. Hence if |
| 547 |
the list should be disposed of by Tcl when done, it should have a |
| 548 |
reference count of zero, and if the list should not be disposed of, the |
| 549 |
filesystem should ensure it retains a reference count to the value. |
| 550 |
.PP |
| 551 |
\fBTcl_FSAccess\fR checks whether the process would be allowed to read, |
| 552 |
write or test for existence of the file (or other filesystem object) |
| 553 |
whose name is \fIpathname\fR. If \fIpathname\fR is a symbolic link on Unix, |
| 554 |
then permissions of the file referred by this symbolic link are |
| 555 |
tested. |
| 556 |
.PP |
| 557 |
On success (all requested permissions granted), zero is returned. On |
| 558 |
error (at least one bit in mode asked for a permission that is denied, |
| 559 |
or some other error occurred), -1 is returned. |
| 560 |
.PP |
| 561 |
\fBTcl_FSStat\fR fills the \fITcl_StatBuf\fR structure \fIstatPtr\fR with |
| 562 |
information about the specified file. You do not need any access rights to the |
| 563 |
file to get this information but you need search rights to all |
| 564 |
directories named in the path leading to the file. The \fITcl_StatBuf\fR |
| 565 |
structure includes info regarding device, inode (always 0 on Windows), |
| 566 |
privilege mode, nlink (always 1 on Windows), user id (always 0 on |
| 567 |
Windows), group id (always 0 on Windows), rdev (same as device on |
| 568 |
Windows), size, last access time, last modification time, and |
| 569 |
last metadata change time. |
| 570 |
See \fBPORTABLE STAT RESULT API\fR for a description of how to write |
| 571 |
portable code to allocate and access the \fITcl_StatBuf\fR structure. |
| 572 |
.PP |
| 573 |
If \fIpath\fR exists, \fBTcl_FSStat\fR returns 0 and the stat structure |
| 574 |
is filled with data. Otherwise, -1 is returned, and no stat info is |
| 575 |
given. |
| 576 |
.PP |
| 577 |
\fBTcl_FSOpenFileChannel\fR opens a file specified by \fIpathPtr\fR and |
| 578 |
returns a channel handle that can be used to perform input and output on |
| 579 |
the file. This API is modeled after the \fBfopen\fR procedure of |
| 580 |
the Unix standard I/O library. |
| 581 |
The syntax and meaning of all arguments is similar to those |
| 582 |
given in the Tcl \fBopen\fR command when opening a file. |
| 583 |
If an error occurs while opening the channel, \fBTcl_FSOpenFileChannel\fR |
| 584 |
returns NULL and records a POSIX error code that can be |
| 585 |
retrieved with \fBTcl_GetErrno\fR. |
| 586 |
In addition, if \fIinterp\fR is non-NULL, \fBTcl_FSOpenFileChannel\fR |
| 587 |
leaves an error message in \fIinterp\fR's result after any error. |
| 588 |
.PP |
| 589 |
The newly created channel is not registered in the supplied interpreter; to |
| 590 |
register it, use \fBTcl_RegisterChannel\fR. |
| 591 |
If one of the standard channels, \fBstdin\fR, \fBstdout\fR or \fBstderr\fR was |
| 592 |
previously closed, the act of creating the new channel also assigns it as a |
| 593 |
replacement for the standard channel. |
| 594 |
.PP |
| 595 |
\fBTcl_FSGetCwd\fR replaces the library version of \fBgetcwd\fR. |
| 596 |
.PP |
| 597 |
It returns the Tcl library's current working directory. This may be |
| 598 |
different to the native platform's working directory, which happens when |
| 599 |
the current working directory is not in the native filesystem. |
| 600 |
.PP |
| 601 |
The result is a pointer to a Tcl_Obj specifying the current directory, |
| 602 |
or NULL if the current directory could not be determined. If NULL is |
| 603 |
returned, an error message is left in the \fIinterp\fR's result. |
| 604 |
.PP |
| 605 |
The result already has its reference count incremented for the caller. When |
| 606 |
it is no longer needed, that reference count should be decremented. This is |
| 607 |
needed for thread-safety purposes, to allow multiple threads to access |
| 608 |
this and related functions, while ensuring the results are always |
| 609 |
valid. |
| 610 |
.PP |
| 611 |
\fBTcl_FSChdir\fR replaces the library version of \fBchdir\fR. The path is |
| 612 |
normalized and then passed to the filesystem which claims it. If that |
| 613 |
filesystem does not implement this function, Tcl will fallback to a |
| 614 |
combination of \fBstat\fR and \fBaccess\fR to check whether the directory |
| 615 |
exists and has appropriate permissions. |
| 616 |
.PP |
| 617 |
For results, see \fBchdir\fR documentation. If successful, we keep a |
| 618 |
record of the successful path in \fIcwdPathPtr\fR for subsequent calls to |
| 619 |
\fBTcl_FSGetCwd\fR. |
| 620 |
.PP |
| 621 |
\fBTcl_FSPathSeparator\fR returns the separator character to be used for |
| 622 |
most specific element of the path specified by \fIpathPtr\fR (i.e.\ the last |
| 623 |
part of the path). |
| 624 |
.PP |
| 625 |
The separator is returned as a Tcl_Obj containing a string of length |
| 626 |
1. If the path is invalid, NULL is returned. |
| 627 |
.PP |
| 628 |
\fBTcl_FSJoinPath\fR takes the given Tcl_Obj, which must be a valid |
| 629 |
list (which is allowed to have a reference count of zero), and returns the path |
| 630 |
value given by considering the first \fIelements\fR elements as valid path |
| 631 |
segments (each path segment may be a complete path, a partial path or |
| 632 |
just a single possible directory or file name). If any path segment is |
| 633 |
actually an absolute path, then all prior path segments are discarded. |
| 634 |
If \fIelements\fR is less than 0, we use the entire list. |
| 635 |
.PP |
| 636 |
It is possible that the returned value is actually an element |
| 637 |
of the given list, so the caller should be careful to increment the |
| 638 |
reference count of the result before freeing the list. |
| 639 |
.PP |
| 640 |
The returned value, typically with a reference count of zero (but it |
| 641 |
could be shared |
| 642 |
under some conditions), contains the joined path. The caller must |
| 643 |
add a reference count to the value before using it. In particular, the |
| 644 |
returned value could be an element of the given list, so freeing the |
| 645 |
list might free the value prematurely if no reference count has been taken. |
| 646 |
If the number of elements is zero, then the returned value will be |
| 647 |
an empty-string Tcl_Obj. |
| 648 |
.PP |
| 649 |
\fBTcl_FSSplitPath\fR takes the given Tcl_Obj, which should be a valid path, |
| 650 |
and returns a Tcl list value containing each segment of that path as |
| 651 |
an element. |
| 652 |
It returns a list value with a reference count of zero. If the |
| 653 |
passed in \fIlenPtr\fR is non-NULL, the variable it points to will be |
| 654 |
updated to contain the number of elements in the returned list. |
| 655 |
.PP |
| 656 |
\fBTcl_FSEqualPaths\fR tests whether the two paths given represent the same |
| 657 |
filesystem object. |
| 658 |
It returns 1 if the paths are equal, and 0 if they are different. If |
| 659 |
either path is NULL, 0 is always returned. |
| 660 |
.PP |
| 661 |
\fBTcl_FSGetNormalizedPath\fR attempts to extract |
| 662 |
from the given Tcl_Obj a unique normalized path representation, whose |
| 663 |
string value can be used as a unique identifier for the file. |
| 664 |
.PP |
| 665 |
It returns the normalized path value, owned by Tcl, or NULL if the path |
| 666 |
was invalid or could otherwise not be successfully converted. |
| 667 |
Extraction of absolute, normalized paths is very efficient (because the |
| 668 |
filesystem operates on these representations internally), although the |
| 669 |
result when the filesystem contains numerous symbolic links may not be |
| 670 |
the most user-friendly version of a path. The return value is owned by |
| 671 |
Tcl and has a lifetime equivalent to that of the \fIpathPtr\fR passed in |
| 672 |
(unless that is a relative path, in which case the normalized path |
| 673 |
value may be freed any time the cwd changes) - the caller can of |
| 674 |
course increment the reference count if it wishes to maintain a copy for longer. |
| 675 |
.PP |
| 676 |
\fBTcl_FSJoinToPath\fR takes the given value, which should usually be a |
| 677 |
valid path or NULL, and joins onto it the array of paths segments |
| 678 |
given. |
| 679 |
.PP |
| 680 |
Returns a value, typically with reference count of zero (but it could be shared |
| 681 |
under some conditions), containing the joined path. The caller must |
| 682 |
add a reference count to the value before using it. If any of the values |
| 683 |
passed into this function (\fIpathPtr\fR or \fIpath\fR elements) have |
| 684 |
a reference count |
| 685 |
of zero, they will be freed when this function returns. |
| 686 |
.PP |
| 687 |
\fBTcl_FSConvertToPathType\fR tries to convert the given Tcl_Obj to a valid |
| 688 |
Tcl path type, taking account of the fact that the cwd may have changed |
| 689 |
even if this value is already supposedly of the correct type. |
| 690 |
The filename may begin with |
| 691 |
.QW ~ |
| 692 |
(to indicate current user's home directory) or |
| 693 |
.QW ~<user> |
| 694 |
(to indicate any user's home directory). |
| 695 |
.PP |
| 696 |
If the conversion succeeds (i.e.\ the value is a valid path in one of |
| 697 |
the current filesystems), then \fBTCL_OK\fR is returned. Otherwise |
| 698 |
\fBTCL_ERROR\fR is returned, and an error message may |
| 699 |
be left in the interpreter. |
| 700 |
.PP |
| 701 |
\fBTcl_FSGetInternalRep\fR extracts the internal representation of a given |
| 702 |
path value, in the given filesystem. If the path value belongs to a |
| 703 |
different filesystem, we return NULL. If the internal representation is |
| 704 |
currently NULL, we attempt to generate it, by calling the filesystem's |
| 705 |
\fBTcl_FSCreateInternalRepProc\fR. |
| 706 |
.PP |
| 707 |
Returns NULL or a valid internal path representation. This internal |
| 708 |
representation is cached, so that repeated calls to this function will |
| 709 |
not require additional conversions. |
| 710 |
.PP |
| 711 |
\fBTcl_FSGetTranslatedPath\fR attempts to extract the translated path |
| 712 |
from the given Tcl_Obj. |
| 713 |
.PP |
| 714 |
If the translation succeeds (i.e.\ the value is a valid path), then it is |
| 715 |
returned. Otherwise NULL will be returned, and an error message may be |
| 716 |
left in the interpreter. A |
| 717 |
.QW translated |
| 718 |
path is one which contains no |
| 719 |
.QW ~ |
| 720 |
or |
| 721 |
.QW ~user |
| 722 |
sequences (these have been expanded to their current |
| 723 |
representation in the filesystem). The value returned is owned by the |
| 724 |
caller, which must store it or call \fBTcl_DecrRefCount\fR to ensure memory is |
| 725 |
freed. This function is of little practical use, and |
| 726 |
\fBTcl_FSGetNormalizedPath\fR or \fBTcl_FSGetNativePath\fR are usually |
| 727 |
better functions to use for most purposes. |
| 728 |
.PP |
| 729 |
\fBTcl_FSGetTranslatedStringPath\fR does the same as |
| 730 |
\fBTcl_FSGetTranslatedPath\fR, but returns a character string or NULL. |
| 731 |
The string returned is dynamically allocated and owned by the caller, |
| 732 |
which must store it or call \fBckfree\fR to ensure it is freed. Again, |
| 733 |
\fBTcl_FSGetNormalizedPath\fR or \fBTcl_FSGetNativePath\fR are usually |
| 734 |
better functions to use for most purposes. |
| 735 |
.PP |
| 736 |
\fBTcl_FSNewNativePath\fR performs something like the reverse of the |
| 737 |
usual obj->path->nativerep conversions. If some code retrieves a path |
| 738 |
in native form (from, e.g.\ \fBreadlink\fR or a native dialog), and that path |
| 739 |
is to be used at the Tcl level, then calling this function is an |
| 740 |
efficient way of creating the appropriate path value type. |
| 741 |
.PP |
| 742 |
The resulting value is a pure |
| 743 |
.QW path |
| 744 |
value, which will only receive |
| 745 |
a UTF-8 string representation if that is required by some Tcl code. |
| 746 |
.PP |
| 747 |
\fBTcl_FSGetNativePath\fR is for use by the Win/Unix native |
| 748 |
filesystems, so that they can easily retrieve the native (char* or |
| 749 |
TCHAR*) representation of a path. This function is a convenience |
| 750 |
wrapper around \fBTcl_FSGetInternalRep\fR. It may be desirable in the |
| 751 |
future to have non-string-based native representations (for example, |
| 752 |
on macOS, a representation using a fileSpec of FSRef structure would |
| 753 |
probably be more efficient). On Windows a full Unicode representation |
| 754 |
would allow for paths of unlimited length. Currently the representation |
| 755 |
is simply a character string which may contain either the relative path |
| 756 |
or a complete, absolute normalized path in the native encoding (complex |
| 757 |
conditions dictate which of these will be provided, so neither can be |
| 758 |
relied upon, unless the path is known to be absolute). If you need a |
| 759 |
native path which must be absolute, then you should ask for the native |
| 760 |
version of a normalized path. If for some reason a non-absolute, |
| 761 |
non-normalized version of the path is needed, that must be constructed |
| 762 |
separately (e.g.\ using \fBTcl_FSGetTranslatedPath\fR). |
| 763 |
.PP |
| 764 |
The native representation is cached so that repeated calls to this |
| 765 |
function will not require additional conversions. The return value is |
| 766 |
owned by Tcl and has a lifetime equivalent to that of the \fIpathPtr\fR |
| 767 |
passed in (unless that is a relative path, in which case the native |
| 768 |
representation may be freed any time the cwd changes). |
| 769 |
.PP |
| 770 |
\fBTcl_FSFileSystemInfo\fR returns a list of two elements. The first |
| 771 |
element is the name of the filesystem (e.g. |
| 772 |
.QW native , |
| 773 |
.QW vfs , |
| 774 |
.QW zip , |
| 775 |
or |
| 776 |
.QW prowrap , |
| 777 |
perhaps), and the second is the particular type of the |
| 778 |
given path within that filesystem (which is filesystem dependent). The |
| 779 |
second element may be empty if the filesystem does not provide a |
| 780 |
further categorization of files. |
| 781 |
.PP |
| 782 |
A valid list value is returned, unless the path value is not |
| 783 |
recognized, when NULL will be returned. |
| 784 |
.PP |
| 785 |
\fBTcl_FSGetFileSystemForPath\fR returns a pointer to the |
| 786 |
\fBTcl_Filesystem\fR which accepts this path as valid. |
| 787 |
.PP |
| 788 |
If no filesystem will accept the path, NULL is returned. |
| 789 |
.PP |
| 790 |
\fBTcl_FSGetPathType\fR determines whether the given path is relative |
| 791 |
to the current directory, relative to the current volume, or |
| 792 |
absolute. |
| 793 |
.PP |
| 794 |
It returns one of \fBTCL_PATH_ABSOLUTE\fR, \fBTCL_PATH_RELATIVE\fR, or |
| 795 |
\fBTCL_PATH_VOLUME_RELATIVE\fR |
| 796 |
.SS "PORTABLE STAT RESULT API" |
| 797 |
.PP |
| 798 |
\fBTcl_AllocStatBuf\fR allocates a \fITcl_StatBuf\fR on the system heap (which |
| 799 |
may be deallocated by being passed to \fBckfree\fR). This allows extensions to |
| 800 |
invoke \fBTcl_FSStat\fR and \fBTcl_FSLstat\fR without being dependent on the |
| 801 |
size of the buffer. That in turn depends on the flags used to build Tcl. |
| 802 |
.PP |
| 803 |
.VS 8.6 |
| 804 |
The portable fields of a \fITcl_StatBuf\fR may be read using the following |
| 805 |
functions, each of which returns the value of the corresponding field listed |
| 806 |
in the table below. Note that on some platforms there may be other fields in |
| 807 |
the \fITcl_StatBuf\fR as it is an alias for a suitable system structure, but |
| 808 |
only the portable ones are made available here. See your system documentation |
| 809 |
for a full description of these fields. |
| 810 |
.DS |
| 811 |
.ta \w'\fBTcl_GetModificationTimeFromStat\fR\0\0\0\0'u |
| 812 |
\fIAccess Function\fR \fIField\fR |
| 813 |
\fBTcl_GetFSDeviceFromStat\fR st_dev |
| 814 |
\fBTcl_GetFSInodeFromStat\fR st_ino |
| 815 |
\fBTcl_GetModeFromStat\fR st_mode |
| 816 |
\fBTcl_GetLinkCountFromStat\fR st_nlink |
| 817 |
\fBTcl_GetUserIdFromStat\fR st_uid |
| 818 |
\fBTcl_GetGroupIdFromStat\fR st_gid |
| 819 |
\fBTcl_GetDeviceTypeFromStat\fR st_rdev |
| 820 |
\fBTcl_GetAccessTimeFromStat\fR st_atime |
| 821 |
\fBTcl_GetModificationTimeFromStat\fR st_mtime |
| 822 |
\fBTcl_GetChangeTimeFromStat\fR st_ctime |
| 823 |
\fBTcl_GetSizeFromStat\fR st_size |
| 824 |
\fBTcl_GetBlocksFromStat\fR st_blocks |
| 825 |
\fBTcl_GetBlockSizeFromStat\fR st_blksize |
| 826 |
.DE |
| 827 |
.VE 8.6 |
| 828 |
.SH "THE VIRTUAL FILESYSTEM API" |
| 829 |
.PP |
| 830 |
A filesystem provides a \fBTcl_Filesystem\fR structure that contains |
| 831 |
pointers to functions that implement the various operations on a |
| 832 |
filesystem; these operations are invoked as needed by the generic |
| 833 |
layer, which generally occurs through the functions listed above. |
| 834 |
.PP |
| 835 |
The \fBTcl_Filesystem\fR structures are manipulated using the following |
| 836 |
methods. |
| 837 |
.PP |
| 838 |
\fBTcl_FSRegister\fR takes a pointer to a filesystem structure and an |
| 839 |
optional piece of data to associated with that filesystem. On calling |
| 840 |
this function, Tcl will attach the filesystem to the list of known |
| 841 |
filesystems, and it will become fully functional immediately. Tcl does |
| 842 |
not check if the same filesystem is registered multiple times (and in |
| 843 |
general that is not a good thing to do). \fBTCL_OK\fR will be returned. |
| 844 |
.PP |
| 845 |
\fBTcl_FSUnregister\fR removes the given filesystem structure from |
| 846 |
the list of known filesystems, if it is known, and returns \fBTCL_OK\fR. If |
| 847 |
the filesystem is not currently registered, \fBTCL_ERROR\fR is returned. |
| 848 |
.PP |
| 849 |
\fBTcl_FSData\fR will return the clientData associated with the given |
| 850 |
filesystem, if that filesystem is registered. Otherwise it will |
| 851 |
return NULL. |
| 852 |
.PP |
| 853 |
\fBTcl_FSMountsChanged\fR is used to inform the Tcl's core that |
| 854 |
the set of mount points for the given (already registered) filesystem |
| 855 |
have changed, and that cached file representations may therefore no |
| 856 |
longer be correct. |
| 857 |
.SS "THE TCL_FILESYSTEM STRUCTURE" |
| 858 |
.PP |
| 859 |
The \fBTcl_Filesystem\fR structure contains the following fields: |
| 860 |
.PP |
| 861 |
.CS |
| 862 |
typedef struct Tcl_Filesystem { |
| 863 |
const char *\fItypeName\fR; |
| 864 |
int \fIstructureLength\fR; |
| 865 |
Tcl_FSVersion \fIversion\fR; |
| 866 |
Tcl_FSPathInFilesystemProc *\fIpathInFilesystemProc\fR; |
| 867 |
Tcl_FSDupInternalRepProc *\fIdupInternalRepProc\fR; |
| 868 |
Tcl_FSFreeInternalRepProc *\fIfreeInternalRepProc\fR; |
| 869 |
Tcl_FSInternalToNormalizedProc *\fIinternalToNormalizedProc\fR; |
| 870 |
Tcl_FSCreateInternalRepProc *\fIcreateInternalRepProc\fR; |
| 871 |
Tcl_FSNormalizePathProc *\fInormalizePathProc\fR; |
| 872 |
Tcl_FSFilesystemPathTypeProc *\fIfilesystemPathTypeProc\fR; |
| 873 |
Tcl_FSFilesystemSeparatorProc *\fIfilesystemSeparatorProc\fR; |
| 874 |
Tcl_FSStatProc *\fIstatProc\fR; |
| 875 |
Tcl_FSAccessProc *\fIaccessProc\fR; |
| 876 |
Tcl_FSOpenFileChannelProc *\fIopenFileChannelProc\fR; |
| 877 |
Tcl_FSMatchInDirectoryProc *\fImatchInDirectoryProc\fR; |
| 878 |
Tcl_FSUtimeProc *\fIutimeProc\fR; |
| 879 |
Tcl_FSLinkProc *\fIlinkProc\fR; |
| 880 |
Tcl_FSListVolumesProc *\fIlistVolumesProc\fR; |
| 881 |
Tcl_FSFileAttrStringsProc *\fIfileAttrStringsProc\fR; |
| 882 |
Tcl_FSFileAttrsGetProc *\fIfileAttrsGetProc\fR; |
| 883 |
Tcl_FSFileAttrsSetProc *\fIfileAttrsSetProc\fR; |
| 884 |
Tcl_FSCreateDirectoryProc *\fIcreateDirectoryProc\fR; |
| 885 |
Tcl_FSRemoveDirectoryProc *\fIremoveDirectoryProc\fR; |
| 886 |
Tcl_FSDeleteFileProc *\fIdeleteFileProc\fR; |
| 887 |
Tcl_FSCopyFileProc *\fIcopyFileProc\fR; |
| 888 |
Tcl_FSRenameFileProc *\fIrenameFileProc\fR; |
| 889 |
Tcl_FSCopyDirectoryProc *\fIcopyDirectoryProc\fR; |
| 890 |
Tcl_FSLstatProc *\fIlstatProc\fR; |
| 891 |
Tcl_FSLoadFileProc *\fIloadFileProc\fR; |
| 892 |
Tcl_FSGetCwdProc *\fIgetCwdProc\fR; |
| 893 |
Tcl_FSChdirProc *\fIchdirProc\fR; |
| 894 |
} \fBTcl_Filesystem\fR; |
| 895 |
.CE |
| 896 |
.PP |
| 897 |
Except for the first three fields in this structure which contain |
| 898 |
simple data elements, all entries contain addresses of functions called |
| 899 |
by the generic filesystem layer to perform the complete range of |
| 900 |
filesystem related actions. |
| 901 |
.PP |
| 902 |
The many functions in this structure are broken down into three |
| 903 |
categories: infrastructure functions (almost all of which must be |
| 904 |
implemented), operational functions (which must be implemented if a |
| 905 |
complete filesystem is provided), and efficiency functions (which need |
| 906 |
only be implemented if they can be done so efficiently, or if they have |
| 907 |
side-effects which are required by the filesystem; Tcl has less |
| 908 |
efficient emulations it can fall back on). It is important to note |
| 909 |
that, in the current version of Tcl, most of these fallbacks are only |
| 910 |
used to handle commands initiated in Tcl, not in C. What this means is, |
| 911 |
that if a \fBfile rename\fR command is issued in Tcl, and the relevant |
| 912 |
filesystem(s) do not implement their \fITcl_FSRenameFileProc\fR, Tcl's |
| 913 |
core will instead fallback on a combination of other filesystem |
| 914 |
functions (it will use \fITcl_FSCopyFileProc\fR followed by |
| 915 |
\fITcl_FSDeleteFileProc\fR, and if \fITcl_FSCopyFileProc\fR is not |
| 916 |
implemented there is a further fallback). However, if a |
| 917 |
\fITcl_FSRenameFileProc\fR command is issued at the C level, no such |
| 918 |
fallbacks occur. This is true except for the last four entries in the |
| 919 |
filesystem table (\fBlstat\fR, \fBload\fR, \fBgetcwd\fR and \fBchdir\fR) |
| 920 |
for which fallbacks do in fact occur at the C level. |
| 921 |
.PP |
| 922 |
Any functions which take path names in Tcl_Obj form take |
| 923 |
those names in UTF\-8 form. The filesystem infrastructure API is |
| 924 |
designed to support efficient, cached conversion of these UTF\-8 paths |
| 925 |
to other native representations. |
| 926 |
.SS "EXAMPLE FILESYSTEM DEFINITION" |
| 927 |
.PP |
| 928 |
Here is the filesystem lookup table used by the |
| 929 |
.QW vfs |
| 930 |
extension which allows filesystem actions to be implemented in Tcl. |
| 931 |
.PP |
| 932 |
.CS |
| 933 |
static Tcl_Filesystem vfsFilesystem = { |
| 934 |
"tclvfs", |
| 935 |
sizeof(Tcl_Filesystem), |
| 936 |
TCL_FILESYSTEM_VERSION_1, |
| 937 |
&VfsPathInFilesystem, |
| 938 |
&VfsDupInternalRep, |
| 939 |
&VfsFreeInternalRep, |
| 940 |
/* No internal to normalized, since we don't create |
| 941 |
* any pure 'internal' Tcl_Obj path representations */ |
| 942 |
NULL, |
| 943 |
/* No create native rep function, since we don't use |
| 944 |
* it and don't choose to support uses of |
| 945 |
* Tcl_FSNewNativePath */ |
| 946 |
NULL, |
| 947 |
/* Normalize path isn't needed - we assume paths only |
| 948 |
* have one representation */ |
| 949 |
NULL, |
| 950 |
&VfsFilesystemPathType, |
| 951 |
&VfsFilesystemSeparator, |
| 952 |
&VfsStat, |
| 953 |
&VfsAccess, |
| 954 |
&VfsOpenFileChannel, |
| 955 |
&VfsMatchInDirectory, |
| 956 |
&VfsUtime, |
| 957 |
/* We choose not to support symbolic links inside our |
| 958 |
* VFS's */ |
| 959 |
NULL, |
| 960 |
&VfsListVolumes, |
| 961 |
&VfsFileAttrStrings, |
| 962 |
&VfsFileAttrsGet, |
| 963 |
&VfsFileAttrsSet, |
| 964 |
&VfsCreateDirectory, |
| 965 |
&VfsRemoveDirectory, |
| 966 |
&VfsDeleteFile, |
| 967 |
/* No copy file; use the core fallback mechanism */ |
| 968 |
NULL, |
| 969 |
/* No rename file; use the core fallback mechanism */ |
| 970 |
NULL, |
| 971 |
/* No copy directory; use the core fallback mechanism */ |
| 972 |
NULL, |
| 973 |
/* Core will use stat for lstat */ |
| 974 |
NULL, |
| 975 |
/* No load; use the core fallback mechanism */ |
| 976 |
NULL, |
| 977 |
/* We don't need a getcwd or chdir; the core's own |
| 978 |
* internal value is suitable */ |
| 979 |
NULL, |
| 980 |
NULL |
| 981 |
}; |
| 982 |
.CE |
| 983 |
.SH "FILESYSTEM INFRASTRUCTURE" |
| 984 |
.PP |
| 985 |
These fields contain basic information about the filesystem structure |
| 986 |
and addresses of functions which are used to associate |
| 987 |
a particular filesystem with a file path, and deal with the internal |
| 988 |
handling of path representations, for example copying and freeing such |
| 989 |
representations. |
| 990 |
.SS TYPENAME |
| 991 |
.PP |
| 992 |
The \fItypeName\fR field contains a null-terminated string that |
| 993 |
identifies the type of the filesystem implemented, e.g. |
| 994 |
.QW native , |
| 995 |
.QW zip |
| 996 |
or |
| 997 |
.QW vfs . |
| 998 |
.SS "STRUCTURE LENGTH" |
| 999 |
.PP |
| 1000 |
The \fIstructureLength\fR field is generally implemented as |
| 1001 |
\fIsizeof(Tcl_Filesystem)\fR, and is there to allow easier |
| 1002 |
binary backwards compatibility if the size of the structure |
| 1003 |
changes in a future Tcl release. |
| 1004 |
.SS VERSION |
| 1005 |
.PP |
| 1006 |
The \fIversion\fR field should be set to \fBTCL_FILESYSTEM_VERSION_1\fR. |
| 1007 |
.SS PATHINFILESYSTEMPROC |
| 1008 |
.PP |
| 1009 |
The \fIpathInFilesystemProc\fR field contains the address of a function |
| 1010 |
which is called to determine whether a given path value belongs to this |
| 1011 |
filesystem or not. Tcl will only call the rest of the filesystem |
| 1012 |
functions with a path for which this function has returned \fBTCL_OK\fR. |
| 1013 |
If the path does not belong, -1 should be returned (the behavior of Tcl |
| 1014 |
for any other return value is not defined). If \fBTCL_OK\fR is returned, |
| 1015 |
then the optional \fIclientDataPtr\fR output parameter can be used to |
| 1016 |
return an internal (filesystem specific) representation of the path, |
| 1017 |
which will be cached inside the path value, and may be retrieved |
| 1018 |
efficiently by the other filesystem functions. Tcl will simultaneously |
| 1019 |
cache the fact that this path belongs to this filesystem. Such caches |
| 1020 |
are invalidated when filesystem structures are added or removed from |
| 1021 |
Tcl's internal list of known filesystems. |
| 1022 |
.PP |
| 1023 |
.CS |
| 1024 |
typedef int \fBTcl_FSPathInFilesystemProc\fR( |
| 1025 |
Tcl_Obj *\fIpathPtr\fR, |
| 1026 |
ClientData *\fIclientDataPtr\fR); |
| 1027 |
.CE |
| 1028 |
.SS DUPINTERNALREPPROC |
| 1029 |
.PP |
| 1030 |
This function makes a copy of a path's internal representation, and is |
| 1031 |
called when Tcl needs to duplicate a path value. If NULL, Tcl will |
| 1032 |
simply not copy the internal representation, which may then need to be |
| 1033 |
regenerated later. |
| 1034 |
.PP |
| 1035 |
.CS |
| 1036 |
typedef ClientData \fBTcl_FSDupInternalRepProc\fR( |
| 1037 |
ClientData \fIclientData\fR); |
| 1038 |
.CE |
| 1039 |
.SS FREEINTERNALREPPROC |
| 1040 |
Free the internal representation. This must be implemented if internal |
| 1041 |
representations need freeing (i.e.\ if some memory is allocated when an |
| 1042 |
internal representation is generated), but may otherwise be NULL. |
| 1043 |
.PP |
| 1044 |
.CS |
| 1045 |
typedef void \fBTcl_FSFreeInternalRepProc\fR( |
| 1046 |
ClientData \fIclientData\fR); |
| 1047 |
.CE |
| 1048 |
.SS INTERNALTONORMALIZEDPROC |
| 1049 |
.PP |
| 1050 |
Function to convert internal representation to a normalized path. Only |
| 1051 |
required if the filesystem creates pure path values with no string/path |
| 1052 |
representation. The return value is a Tcl value whose string |
| 1053 |
representation is the normalized path. |
| 1054 |
.PP |
| 1055 |
.CS |
| 1056 |
typedef Tcl_Obj *\fBTcl_FSInternalToNormalizedProc\fR( |
| 1057 |
ClientData \fIclientData\fR); |
| 1058 |
.CE |
| 1059 |
.SS CREATEINTERNALREPPROC |
| 1060 |
.PP |
| 1061 |
Function to take a path value, and calculate an internal |
| 1062 |
representation for it, and store that native representation in the |
| 1063 |
value. May be NULL if paths have no internal representation, or if |
| 1064 |
the \fITcl_FSPathInFilesystemProc\fR for this filesystem always |
| 1065 |
immediately creates an internal representation for paths it accepts. |
| 1066 |
.PP |
| 1067 |
.CS |
| 1068 |
typedef ClientData \fBTcl_FSCreateInternalRepProc\fR( |
| 1069 |
Tcl_Obj *\fIpathPtr\fR); |
| 1070 |
.CE |
| 1071 |
.SS NORMALIZEPATHPROC |
| 1072 |
.PP |
| 1073 |
Function to normalize a path. Should be implemented for all |
| 1074 |
filesystems which can have multiple string representations for the same |
| 1075 |
path value. In Tcl, every |
| 1076 |
.QW path |
| 1077 |
must have a single unique |
| 1078 |
.QW normalized |
| 1079 |
string representation. Depending on the filesystem, |
| 1080 |
there may be more than one unnormalized string representation which |
| 1081 |
refers to that path (e.g.\ a relative path, a path with different |
| 1082 |
character case if the filesystem is case insensitive, a path contain a |
| 1083 |
reference to a home directory such as |
| 1084 |
.QW ~ , |
| 1085 |
a path containing symbolic |
| 1086 |
links, etc). If the very last component in the path is a symbolic |
| 1087 |
link, it should not be converted into the value it points to (but |
| 1088 |
its case or other aspects should be made unique). All other path |
| 1089 |
components should be converted from symbolic links. This one |
| 1090 |
exception is required to agree with Tcl's semantics with \fBfile |
| 1091 |
delete\fR, \fBfile rename\fR, \fBfile copy\fR operating on symbolic links. |
| 1092 |
This function may be called with \fInextCheckpoint\fR either |
| 1093 |
at the beginning of the path (i.e.\ zero), at the end of the path, or |
| 1094 |
at any intermediate file separator in the path. It will never |
| 1095 |
point to any other arbitrary position in the path. In the last of |
| 1096 |
the three valid cases, the implementation can assume that the path |
| 1097 |
up to and including the file separator is known and normalized. |
| 1098 |
.PP |
| 1099 |
.CS |
| 1100 |
typedef int \fBTcl_FSNormalizePathProc\fR( |
| 1101 |
Tcl_Interp *\fIinterp\fR, |
| 1102 |
Tcl_Obj *\fIpathPtr\fR, |
| 1103 |
int \fInextCheckpoint\fR); |
| 1104 |
.CE |
| 1105 |
.SH "FILESYSTEM OPERATIONS" |
| 1106 |
.PP |
| 1107 |
The fields in this section of the structure contain addresses of |
| 1108 |
functions which are called to carry out the basic filesystem |
| 1109 |
operations. A filesystem which expects to be used with the complete |
| 1110 |
standard Tcl command set must implement all of these. If some of |
| 1111 |
them are not implemented, then certain Tcl commands may fail when |
| 1112 |
operating on paths within that filesystem. However, in some instances |
| 1113 |
this may be desirable (for example, a read-only filesystem should not |
| 1114 |
implement the last four functions, and a filesystem which does not |
| 1115 |
support symbolic links need not implement the \fBreadlink\fR function, |
| 1116 |
etc. The Tcl core expects filesystems to behave in this way). |
| 1117 |
.SS FILESYSTEMPATHTYPEPROC |
| 1118 |
.PP |
| 1119 |
Function to determine the type of a path in this filesystem. May be |
| 1120 |
NULL, in which case no type information will be available to users of |
| 1121 |
the filesystem. The |
| 1122 |
.QW type |
| 1123 |
is used only for informational purposes, |
| 1124 |
and should be returned as the string representation of the Tcl_Obj |
| 1125 |
which is returned. A typical return value might be |
| 1126 |
.QW networked , |
| 1127 |
.QW zip |
| 1128 |
or |
| 1129 |
.QW ftp . |
| 1130 |
The Tcl_Obj result is owned by the filesystem and so Tcl will |
| 1131 |
increment the reference count of that value if it wishes to retain a reference |
| 1132 |
to it. |
| 1133 |
.PP |
| 1134 |
.CS |
| 1135 |
typedef Tcl_Obj *\fBTcl_FSFilesystemPathTypeProc\fR( |
| 1136 |
Tcl_Obj *\fIpathPtr\fR); |
| 1137 |
.CE |
| 1138 |
.SS FILESYSTEMSEPARATORPROC |
| 1139 |
.PP |
| 1140 |
Function to return the separator character(s) for this filesystem. |
| 1141 |
This need only be implemented if the filesystem wishes to use a |
| 1142 |
different separator than the standard string |
| 1143 |
.QW / . |
| 1144 |
Amongst other |
| 1145 |
uses, it is returned by the \fBfile separator\fR command. The |
| 1146 |
return value should be a value with reference count of zero. |
| 1147 |
.PP |
| 1148 |
.CS |
| 1149 |
typedef Tcl_Obj *\fBTcl_FSFilesystemSeparatorProc\fR( |
| 1150 |
Tcl_Obj *\fIpathPtr\fR); |
| 1151 |
.CE |
| 1152 |
.SS STATPROC |
| 1153 |
.PP |
| 1154 |
Function to process a \fBTcl_FSStat\fR call. Must be implemented for any |
| 1155 |
reasonable filesystem, since many Tcl level commands depend crucially |
| 1156 |
upon it (e.g.\ \fBfile atime\fR, \fBfile isdirectory\fR, \fBfile size\fR, |
| 1157 |
\fBglob\fR). |
| 1158 |
.PP |
| 1159 |
.CS |
| 1160 |
typedef int \fBTcl_FSStatProc\fR( |
| 1161 |
Tcl_Obj *\fIpathPtr\fR, |
| 1162 |
Tcl_StatBuf *\fIstatPtr\fR); |
| 1163 |
.CE |
| 1164 |
.PP |
| 1165 |
The \fBTcl_FSStatProc\fR fills the stat structure \fIstatPtr\fR with |
| 1166 |
information about the specified file. You do not need any access |
| 1167 |
rights to the file to get this information but you need search rights |
| 1168 |
to all directories named in the path leading to the file. The stat |
| 1169 |
structure includes info regarding device, inode (always 0 on Windows), |
| 1170 |
privilege mode, nlink (always 1 on Windows), user id (always 0 on |
| 1171 |
Windows), group id (always 0 on Windows), rdev (same as device on |
| 1172 |
Windows), size, last access time, last modification time, and |
| 1173 |
last metadata change time. |
| 1174 |
.PP |
| 1175 |
If the file represented by \fIpathPtr\fR exists, the |
| 1176 |
\fBTcl_FSStatProc\fR returns 0 and the stat structure is filled with |
| 1177 |
data. Otherwise, -1 is returned, and no stat info is given. |
| 1178 |
.SS ACCESSPROC |
| 1179 |
.PP |
| 1180 |
Function to process a \fBTcl_FSAccess\fR call. Must be implemented for |
| 1181 |
any reasonable filesystem, since many Tcl level commands depend crucially |
| 1182 |
upon it (e.g.\ \fBfile exists\fR, \fBfile readable\fR). |
| 1183 |
.PP |
| 1184 |
.CS |
| 1185 |
typedef int \fBTcl_FSAccessProc\fR( |
| 1186 |
Tcl_Obj *\fIpathPtr\fR, |
| 1187 |
int \fImode\fR); |
| 1188 |
.CE |
| 1189 |
.PP |
| 1190 |
The \fBTcl_FSAccessProc\fR checks whether the process would be allowed |
| 1191 |
to read, write or test for existence of the file (or other filesystem |
| 1192 |
object) whose name is in \fIpathPtr\fR. If the pathname refers to a |
| 1193 |
symbolic link, then the |
| 1194 |
permissions of the file referred by this symbolic link should be tested. |
| 1195 |
.PP |
| 1196 |
On success (all requested permissions granted), zero is returned. On |
| 1197 |
error (at least one bit in mode asked for a permission that is denied, |
| 1198 |
or some other error occurred), -1 is returned. |
| 1199 |
.SS OPENFILECHANNELPROC |
| 1200 |
.PP |
| 1201 |
Function to process a \fBTcl_FSOpenFileChannel\fR call. Must be |
| 1202 |
implemented for any reasonable filesystem, since any operations |
| 1203 |
which require open or accessing a file's contents will use it |
| 1204 |
(e.g.\ \fBopen\fR, \fBencoding\fR, and many Tk commands). |
| 1205 |
.PP |
| 1206 |
.CS |
| 1207 |
typedef Tcl_Channel \fBTcl_FSOpenFileChannelProc\fR( |
| 1208 |
Tcl_Interp *\fIinterp\fR, |
| 1209 |
Tcl_Obj *\fIpathPtr\fR, |
| 1210 |
int \fImode\fR, |
| 1211 |
int \fIpermissions\fR); |
| 1212 |
.CE |
| 1213 |
.PP |
| 1214 |
The \fBTcl_FSOpenFileChannelProc\fR opens a file specified by |
| 1215 |
\fIpathPtr\fR and returns a channel handle that can be used to perform |
| 1216 |
input and output on the file. This API is modeled after the \fBfopen\fR |
| 1217 |
procedure of the Unix standard I/O library. The syntax and meaning of |
| 1218 |
all arguments is similar to those given in the Tcl \fBopen\fR command |
| 1219 |
when opening a file, where the \fImode\fR argument is a combination of |
| 1220 |
the POSIX flags O_RDONLY, O_WRONLY, etc. If an error occurs while |
| 1221 |
opening the channel, the \fBTcl_FSOpenFileChannelProc\fR returns NULL and |
| 1222 |
records a POSIX error code that can be retrieved with \fBTcl_GetErrno\fR. |
| 1223 |
In addition, if \fIinterp\fR is non-NULL, the |
| 1224 |
\fBTcl_FSOpenFileChannelProc\fR leaves an error message in \fIinterp\fR's |
| 1225 |
result after any error. |
| 1226 |
.PP |
| 1227 |
The newly created channel must not be registered in the supplied interpreter |
| 1228 |
by a \fBTcl_FSOpenFileChannelProc\fR; that task is up to the caller of |
| 1229 |
\fBTcl_FSOpenFileChannel\fR (if necessary). If one of |
| 1230 |
the standard channels, \fBstdin\fR, \fBstdout\fR or \fBstderr\fR was |
| 1231 |
previously closed, the act of creating the new channel also assigns it |
| 1232 |
as a replacement for the standard channel. |
| 1233 |
.SS MATCHINDIRECTORYPROC |
| 1234 |
.PP |
| 1235 |
Function to process a \fBTcl_FSMatchInDirectory\fR call. If not |
| 1236 |
implemented, then glob and recursive copy functionality will be lacking |
| 1237 |
in the filesystem (and this may impact commands like \fBencoding names\fR |
| 1238 |
which use glob functionality internally). |
| 1239 |
.PP |
| 1240 |
.CS |
| 1241 |
typedef int \fBTcl_FSMatchInDirectoryProc\fR( |
| 1242 |
Tcl_Interp *\fIinterp\fR, |
| 1243 |
Tcl_Obj *\fIresultPtr\fR, |
| 1244 |
Tcl_Obj *\fIpathPtr\fR, |
| 1245 |
const char *\fIpattern\fR, |
| 1246 |
Tcl_GlobTypeData *\fItypes\fR); |
| 1247 |
.CE |
| 1248 |
.PP |
| 1249 |
The function should return all files or directories (or other filesystem |
| 1250 |
objects) which match the given pattern and accord with the \fItypes\fR |
| 1251 |
specification given. There are two ways in which this function may be |
| 1252 |
called. If \fIpattern\fR is NULL, then \fIpathPtr\fR is a full path |
| 1253 |
specification of a single file or directory which should be checked for |
| 1254 |
existence and correct type. Otherwise, \fIpathPtr\fR is a directory, the |
| 1255 |
contents of which the function should search for files or directories |
| 1256 |
which have the correct type. In either case, \fIpathPtr\fR can be |
| 1257 |
assumed to be both non-NULL and non-empty. It is not currently |
| 1258 |
documented whether \fIpathPtr\fR will have a file separator at its end of |
| 1259 |
not, so code should be flexible to both possibilities. |
| 1260 |
.PP |
| 1261 |
The return value is a standard Tcl result indicating whether an error |
| 1262 |
occurred in the matching process. Error messages are placed in |
| 1263 |
\fIinterp\fR, unless \fIinterp\fR in NULL in which case no error |
| 1264 |
message need be generated; on a \fBTCL_OK\fR result, results should be |
| 1265 |
added to the \fIresultPtr\fR value given (which can be assumed to be a |
| 1266 |
valid unshared Tcl list). The matches added |
| 1267 |
to \fIresultPtr\fR should include any path prefix given in \fIpathPtr\fR |
| 1268 |
(this usually means they will be absolute path specifications). |
| 1269 |
Note that if no matches are found, that simply leads to an empty |
| 1270 |
result; errors are only signaled for actual file or filesystem |
| 1271 |
problems which may occur during the matching process. |
| 1272 |
.PP |
| 1273 |
The \fBTcl_GlobTypeData\fR structure passed in the \fItypes\fR |
| 1274 |
parameter contains the following fields: |
| 1275 |
.PP |
| 1276 |
.CS |
| 1277 |
typedef struct Tcl_GlobTypeData { |
| 1278 |
/* Corresponds to bcdpfls as in 'find -t' */ |
| 1279 |
int \fItype\fR; |
| 1280 |
/* Corresponds to file permissions */ |
| 1281 |
int \fIperm\fR; |
| 1282 |
/* Acceptable mac type */ |
| 1283 |
Tcl_Obj *\fImacType\fR; |
| 1284 |
/* Acceptable mac creator */ |
| 1285 |
Tcl_Obj *\fImacCreator\fR; |
| 1286 |
} \fBTcl_GlobTypeData\fR; |
| 1287 |
.CE |
| 1288 |
.PP |
| 1289 |
There are two specific cases which it is important to handle correctly, |
| 1290 |
both when \fItypes\fR is non-NULL. The two cases are when \fItypes->types |
| 1291 |
& TCL_GLOB_TYPE_DIR\fR or \fItypes->types & TCL_GLOB_TYPE_MOUNT\fR are |
| 1292 |
true (and in particular when the other flags are false). In the first of |
| 1293 |
these cases, the function must list the contained directories. Tcl uses |
| 1294 |
this to implement recursive globbing, so it is critical that filesystems |
| 1295 |
implement directory matching correctly. In the second of these cases, |
| 1296 |
with \fBTCL_GLOB_TYPE_MOUNT\fR, the filesystem must list the mount points |
| 1297 |
which lie within the given \fIpathPtr\fR (and in this case, \fIpathPtr\fR |
| 1298 |
need not lie within the same filesystem - different to all other cases in |
| 1299 |
which this function is called). Support for this is critical if Tcl is |
| 1300 |
to have seamless transitions between from one filesystem to another. |
| 1301 |
.SS UTIMEPROC |
| 1302 |
.PP |
| 1303 |
Function to process a \fBTcl_FSUtime\fR call. Required to allow setting |
| 1304 |
(not reading) of times with \fBfile mtime\fR, \fBfile atime\fR and the |
| 1305 |
open-r/open-w/fcopy implementation of \fBfile copy\fR. |
| 1306 |
.PP |
| 1307 |
.CS |
| 1308 |
typedef int \fBTcl_FSUtimeProc\fR( |
| 1309 |
Tcl_Obj *\fIpathPtr\fR, |
| 1310 |
struct utimbuf *\fItval\fR); |
| 1311 |
.CE |
| 1312 |
.PP |
| 1313 |
The access and modification times of the file specified by \fIpathPtr\fR |
| 1314 |
should be changed to the values given in the \fItval\fR structure. |
| 1315 |
.PP |
| 1316 |
The return value should be 0 on success and -1 on an error, as |
| 1317 |
with the system \fButime\fR. |
| 1318 |
.SS LINKPROC |
| 1319 |
.PP |
| 1320 |
Function to process a \fBTcl_FSLink\fR call. Should be implemented |
| 1321 |
only if the filesystem supports links, and may otherwise be NULL. |
| 1322 |
.PP |
| 1323 |
.CS |
| 1324 |
typedef Tcl_Obj *\fBTcl_FSLinkProc\fR( |
| 1325 |
Tcl_Obj *\fIlinkNamePtr\fR, |
| 1326 |
Tcl_Obj *\fItoPtr\fR, |
| 1327 |
int \fIlinkAction\fR); |
| 1328 |
.CE |
| 1329 |
.PP |
| 1330 |
If \fItoPtr\fR is NULL, the function is being asked to read the |
| 1331 |
contents of a link. The result is a Tcl_Obj specifying the contents of |
| 1332 |
the link given by \fIlinkNamePtr\fR, or NULL if the link could |
| 1333 |
not be read. The result is owned by the caller (and should therefore |
| 1334 |
have its ref count incremented before being returned). Any callers |
| 1335 |
should call \fBTcl_DecrRefCount\fR on this result when it is no longer needed. |
| 1336 |
If \fItoPtr\fR is not NULL, the function should attempt to create a link. |
| 1337 |
The result in this case should be \fItoPtr\fR if the link was successful |
| 1338 |
and NULL otherwise. In this case the result is not owned by the caller |
| 1339 |
(i.e.\ no reference count manipulations on either end are needed). See |
| 1340 |
the documentation for \fBTcl_FSLink\fR for the correct interpretation |
| 1341 |
of the \fIlinkAction\fR flags. |
| 1342 |
.SS LISTVOLUMESPROC |
| 1343 |
.PP |
| 1344 |
Function to list any filesystem volumes added by this filesystem. |
| 1345 |
Should be implemented only if the filesystem adds volumes at the head |
| 1346 |
of the filesystem, so that they can be returned by \fBfile volumes\fR. |
| 1347 |
.PP |
| 1348 |
.CS |
| 1349 |
typedef Tcl_Obj *\fBTcl_FSListVolumesProc\fR(void); |
| 1350 |
.CE |
| 1351 |
.PP |
| 1352 |
The result should be a list of volumes added by this filesystem, or |
| 1353 |
NULL (or an empty list) if no volumes are provided. The result value |
| 1354 |
is considered to be owned by the filesystem (not by Tcl's core), but |
| 1355 |
should be given a reference count for Tcl. Tcl will use the contents of the |
| 1356 |
list and then decrement that reference count. This allows filesystems to |
| 1357 |
choose whether they actually want to retain a |
| 1358 |
.QW "global list" |
| 1359 |
of volumes |
| 1360 |
or not (if not, they generate the list on the fly and pass it to Tcl |
| 1361 |
with a reference count of 1 and then forget about the list, if yes, then |
| 1362 |
they simply increment the reference count of their global list and pass it |
| 1363 |
to Tcl which will copy the contents and then decrement the count back |
| 1364 |
to where it was). |
| 1365 |
.PP |
| 1366 |
Therefore, Tcl considers return values from this proc to be read-only. |
| 1367 |
.SS FILEATTRSTRINGSPROC |
| 1368 |
.PP |
| 1369 |
Function to list all attribute strings which are valid for this |
| 1370 |
filesystem. If not implemented the filesystem will not support |
| 1371 |
the \fBfile attributes\fR command. This allows arbitrary additional |
| 1372 |
information to be attached to files in the filesystem. If it is |
| 1373 |
not implemented, there is no need to implement the \fBget\fR and \fBset\fR |
| 1374 |
methods. |
| 1375 |
.PP |
| 1376 |
.CS |
| 1377 |
typedef const char *const *\fBTcl_FSFileAttrStringsProc\fR( |
| 1378 |
Tcl_Obj *\fIpathPtr\fR, |
| 1379 |
Tcl_Obj **\fIobjPtrRef\fR); |
| 1380 |
.CE |
| 1381 |
.PP |
| 1382 |
The called function may either return an array of strings, or may |
| 1383 |
instead return NULL and place a Tcl list into the given \fIobjPtrRef\fR. Tcl |
| 1384 |
will take that list and first increment its reference count before using it. |
| 1385 |
On completion of that use, Tcl will decrement its reference count. Hence if |
| 1386 |
the list should be disposed of by Tcl when done, it should have a |
| 1387 |
reference count of zero, and if the list should not be disposed of, the |
| 1388 |
filesystem should ensure it returns a value with a reference count |
| 1389 |
of at least one. |
| 1390 |
.SS FILEATTRSGETPROC |
| 1391 |
.PP |
| 1392 |
Function to process a \fBTcl_FSFileAttrsGet\fR call, used by \fBfile |
| 1393 |
attributes\fR. |
| 1394 |
.PP |
| 1395 |
.CS |
| 1396 |
typedef int \fBTcl_FSFileAttrsGetProc\fR( |
| 1397 |
Tcl_Interp *\fIinterp\fR, |
| 1398 |
int \fIindex\fR, |
| 1399 |
Tcl_Obj *\fIpathPtr\fR, |
| 1400 |
Tcl_Obj **\fIobjPtrRef\fR); |
| 1401 |
.CE |
| 1402 |
.PP |
| 1403 |
Returns a standard Tcl return code. The attribute value retrieved, |
| 1404 |
which corresponds to the \fIindex\fR'th element in the list returned by |
| 1405 |
the \fBTcl_FSFileAttrStringsProc\fR, is a Tcl_Obj placed in \fIobjPtrRef\fR |
| 1406 |
(if \fBTCL_OK\fR was returned) and is likely to have a reference count of |
| 1407 |
zero. Either way we must either store it somewhere (e.g.\ the Tcl result), |
| 1408 |
or Incr/Decr its reference count to ensure it is properly freed. |
| 1409 |
.SS FILEATTRSSETPROC |
| 1410 |
.PP |
| 1411 |
Function to process a \fBTcl_FSFileAttrsSet\fR call, used by \fBfile |
| 1412 |
attributes\fR. If the filesystem is read-only, there is no need |
| 1413 |
to implement this. |
| 1414 |
.PP |
| 1415 |
.CS |
| 1416 |
typedef int \fBTcl_FSFileAttrsSetProc\fR( |
| 1417 |
Tcl_Interp *\fIinterp\fR, |
| 1418 |
int \fIindex\fR, |
| 1419 |
Tcl_Obj *\fIpathPtr\fR, |
| 1420 |
Tcl_Obj *\fIobjPtr\fR); |
| 1421 |
.CE |
| 1422 |
.PP |
| 1423 |
The attribute value of the \fIindex\fR'th element in the list returned by |
| 1424 |
the Tcl_FSFileAttrStringsProc should be set to the \fIobjPtr\fR given. |
| 1425 |
.SS CREATEDIRECTORYPROC |
| 1426 |
.PP |
| 1427 |
Function to process a \fBTcl_FSCreateDirectory\fR call. Should be |
| 1428 |
implemented unless the FS is read-only. |
| 1429 |
.PP |
| 1430 |
.CS |
| 1431 |
typedef int \fBTcl_FSCreateDirectoryProc\fR( |
| 1432 |
Tcl_Obj *\fIpathPtr\fR); |
| 1433 |
.CE |
| 1434 |
.PP |
| 1435 |
The return value is a standard Tcl result indicating whether an error |
| 1436 |
occurred in the process. If successful, a new directory should have |
| 1437 |
been added to the filesystem in the location specified by |
| 1438 |
\fIpathPtr\fR. |
| 1439 |
.SS REMOVEDIRECTORYPROC |
| 1440 |
.PP |
| 1441 |
Function to process a \fBTcl_FSRemoveDirectory\fR call. Should be |
| 1442 |
implemented unless the FS is read-only. |
| 1443 |
.PP |
| 1444 |
.CS |
| 1445 |
typedef int \fBTcl_FSRemoveDirectoryProc\fR( |
| 1446 |
Tcl_Obj *\fIpathPtr\fR, |
| 1447 |
int \fIrecursive\fR, |
| 1448 |
Tcl_Obj **\fIerrorPtr\fR); |
| 1449 |
.CE |
| 1450 |
.PP |
| 1451 |
The return value is a standard Tcl result indicating whether an error |
| 1452 |
occurred in the process. If successful, the directory specified by |
| 1453 |
\fIpathPtr\fR should have been removed from the filesystem. If the |
| 1454 |
\fIrecursive\fR flag is given, then a non-empty directory should be |
| 1455 |
deleted without error. If this flag is not given, then and the |
| 1456 |
directory is non-empty a POSIX |
| 1457 |
.QW EEXIST |
| 1458 |
error should be signaled. If an |
| 1459 |
error does occur, the name of the file or directory which caused the |
| 1460 |
error should be placed in \fIerrorPtr\fR. |
| 1461 |
.SS DELETEFILEPROC |
| 1462 |
.PP |
| 1463 |
Function to process a \fBTcl_FSDeleteFile\fR call. Should be implemented |
| 1464 |
unless the FS is read-only. |
| 1465 |
.PP |
| 1466 |
.CS |
| 1467 |
typedef int \fBTcl_FSDeleteFileProc\fR( |
| 1468 |
Tcl_Obj *\fIpathPtr\fR); |
| 1469 |
.CE |
| 1470 |
.PP |
| 1471 |
The return value is a standard Tcl result indicating whether an error |
| 1472 |
occurred in the process. If successful, the file specified by |
| 1473 |
\fIpathPtr\fR should have been removed from the filesystem. Note that, |
| 1474 |
if the filesystem supports symbolic links, Tcl will always call this |
| 1475 |
function and not Tcl_FSRemoveDirectoryProc when needed to delete them |
| 1476 |
(even if they are symbolic links to directories). |
| 1477 |
.SH "FILESYSTEM EFFICIENCY" |
| 1478 |
.PP |
| 1479 |
These functions need not be implemented for a particular filesystem |
| 1480 |
because the core has a fallback implementation available. See each |
| 1481 |
individual description for the consequences of leaving the field NULL. |
| 1482 |
.SS LSTATPROC |
| 1483 |
.PP |
| 1484 |
Function to process a \fBTcl_FSLstat\fR call. If not implemented, Tcl |
| 1485 |
will attempt to use the \fIstatProc\fR defined above instead. Therefore |
| 1486 |
it need only be implemented if a filesystem can differentiate between |
| 1487 |
\fBstat\fR and \fBlstat\fR calls. |
| 1488 |
.PP |
| 1489 |
.CS |
| 1490 |
typedef int \fBTcl_FSLstatProc\fR( |
| 1491 |
Tcl_Obj *\fIpathPtr\fR, |
| 1492 |
Tcl_StatBuf *\fIstatPtr\fR); |
| 1493 |
.CE |
| 1494 |
.PP |
| 1495 |
The behavior of this function is very similar to that of the |
| 1496 |
\fBTcl_FSStatProc\fR defined above, except that if it is applied |
| 1497 |
to a symbolic link, it returns information about the link, not |
| 1498 |
about the target file. |
| 1499 |
.SS COPYFILEPROC |
| 1500 |
.PP |
| 1501 |
Function to process a \fBTcl_FSCopyFile\fR call. If not implemented Tcl |
| 1502 |
will fall back on \fBopen\fR-r, \fBopen\fR-w and \fBfcopy\fR as a |
| 1503 |
copying mechanism. |
| 1504 |
Therefore it need only be implemented if the filesystem can perform |
| 1505 |
that action more efficiently. |
| 1506 |
.PP |
| 1507 |
.CS |
| 1508 |
typedef int \fBTcl_FSCopyFileProc\fR( |
| 1509 |
Tcl_Obj *\fIsrcPathPtr\fR, |
| 1510 |
Tcl_Obj *\fIdestPathPtr\fR); |
| 1511 |
.CE |
| 1512 |
.PP |
| 1513 |
The return value is a standard Tcl result indicating whether an error |
| 1514 |
occurred in the copying process. Note that, \fIdestPathPtr\fR is the |
| 1515 |
name of the file which should become the copy of \fIsrcPathPtr\fR. It |
| 1516 |
is never the name of a directory into which \fIsrcPathPtr\fR could be |
| 1517 |
copied (i.e.\ the function is much simpler than the Tcl level \fBfile |
| 1518 |
copy\fR subcommand). Note that, |
| 1519 |
if the filesystem supports symbolic links, Tcl will always call this |
| 1520 |
function and not \fIcopyDirectoryProc\fR when needed to copy them |
| 1521 |
(even if they are symbolic links to directories). Finally, if the |
| 1522 |
filesystem determines it cannot support the \fBfile copy\fR action, |
| 1523 |
calling \fBTcl_SetErrno(EXDEV)\fR and returning a non-\fBTCL_OK\fR |
| 1524 |
result will tell Tcl to use its standard fallback mechanisms. |
| 1525 |
.SS RENAMEFILEPROC |
| 1526 |
.PP |
| 1527 |
Function to process a \fBTcl_FSRenameFile\fR call. If not implemented, |
| 1528 |
Tcl will fall back on a copy and delete mechanism. Therefore it need |
| 1529 |
only be implemented if the filesystem can perform that action more |
| 1530 |
efficiently. |
| 1531 |
.PP |
| 1532 |
.CS |
| 1533 |
typedef int \fBTcl_FSRenameFileProc\fR( |
| 1534 |
Tcl_Obj *\fIsrcPathPtr\fR, |
| 1535 |
Tcl_Obj *\fIdestPathPtr\fR); |
| 1536 |
.CE |
| 1537 |
.PP |
| 1538 |
The return value is a standard Tcl result indicating whether an error |
| 1539 |
occurred in the renaming process. If the |
| 1540 |
filesystem determines it cannot support the \fBfile rename\fR action, |
| 1541 |
calling \fBTcl_SetErrno(EXDEV)\fR and returning a non-\fBTCL_OK\fR |
| 1542 |
result will tell Tcl to use its standard fallback mechanisms. |
| 1543 |
.SS COPYDIRECTORYPROC |
| 1544 |
.PP |
| 1545 |
Function to process a \fBTcl_FSCopyDirectory\fR call. If not |
| 1546 |
implemented, Tcl will fall back on a recursive \fBfile mkdir\fR, \fBfile copy\fR |
| 1547 |
mechanism. Therefore it need only be implemented if the filesystem can |
| 1548 |
perform that action more efficiently. |
| 1549 |
.PP |
| 1550 |
.CS |
| 1551 |
typedef int \fBTcl_FSCopyDirectoryProc\fR( |
| 1552 |
Tcl_Obj *\fIsrcPathPtr\fR, |
| 1553 |
Tcl_Obj *\fIdestPathPtr\fR, |
| 1554 |
Tcl_Obj **\fIerrorPtr\fR); |
| 1555 |
.CE |
| 1556 |
.PP |
| 1557 |
The return value is a standard Tcl result indicating whether an error |
| 1558 |
occurred in the copying process. If an error does occur, the name of |
| 1559 |
the file or directory which caused the error should be placed in |
| 1560 |
\fIerrorPtr\fR. Note that, \fIdestPathPtr\fR is the name of the |
| 1561 |
directory-name which should become the mirror-image of |
| 1562 |
\fIsrcPathPtr\fR. It is not the name of a directory into which |
| 1563 |
\fIsrcPathPtr\fR should be copied (i.e.\ the function is much simpler |
| 1564 |
than the Tcl level \fBfile copy\fR subcommand). Finally, if the |
| 1565 |
filesystem determines it cannot support the directory copy action, |
| 1566 |
calling \fBTcl_SetErrno(EXDEV)\fR and returning a non-\fBTCL_OK\fR |
| 1567 |
result will tell Tcl to use its standard fallback mechanisms. |
| 1568 |
.SS LOADFILEPROC |
| 1569 |
.PP |
| 1570 |
Function to process a \fBTcl_FSLoadFile\fR call. If not implemented, Tcl |
| 1571 |
will fall back on a copy to native-temp followed by a \fBTcl_FSLoadFile\fR on |
| 1572 |
that temporary copy. Therefore it need only be implemented if the |
| 1573 |
filesystem can load code directly, or it can be implemented simply to |
| 1574 |
return \fBTCL_ERROR\fR to disable load functionality in this filesystem |
| 1575 |
entirely. |
| 1576 |
.PP |
| 1577 |
.CS |
| 1578 |
typedef int \fBTcl_FSLoadFileProc\fR( |
| 1579 |
Tcl_Interp *\fIinterp\fR, |
| 1580 |
Tcl_Obj *\fIpathPtr\fR, |
| 1581 |
Tcl_LoadHandle *\fIhandlePtr\fR, |
| 1582 |
Tcl_FSUnloadFileProc *\fIunloadProcPtr\fR); |
| 1583 |
.CE |
| 1584 |
.PP |
| 1585 |
Returns a standard Tcl completion code. If an error occurs, an error |
| 1586 |
message is left in the \fIinterp\fR's result. The function dynamically loads a |
| 1587 |
binary code file into memory. On a successful load, the \fIhandlePtr\fR |
| 1588 |
should be filled with a token for the dynamically loaded file, and the |
| 1589 |
\fIunloadProcPtr\fR should be filled in with the address of a procedure. |
| 1590 |
The unload procedure will be called with the given \fBTcl_LoadHandle\fR as its |
| 1591 |
only parameter when Tcl needs to unload the file. For example, for the |
| 1592 |
native filesystem, the \fBTcl_LoadHandle\fR returned is currently a token |
| 1593 |
which can be used in the private \fBTclpFindSymbol\fR to access functions |
| 1594 |
in the new code. Each filesystem is free to define the |
| 1595 |
\fBTcl_LoadHandle\fR as it requires. Finally, if the |
| 1596 |
filesystem determines it cannot support the file load action, |
| 1597 |
calling \fBTcl_SetErrno(EXDEV)\fR and returning a non-\fBTCL_OK\fR |
| 1598 |
result will tell Tcl to use its standard fallback mechanisms. |
| 1599 |
.SS UNLOADFILEPROC |
| 1600 |
.PP |
| 1601 |
Function to unload a previously successfully loaded file. If load was |
| 1602 |
implemented, then this should also be implemented, if there is any |
| 1603 |
cleanup action required. |
| 1604 |
.PP |
| 1605 |
.CS |
| 1606 |
typedef void \fBTcl_FSUnloadFileProc\fR( |
| 1607 |
Tcl_LoadHandle \fIloadHandle\fR); |
| 1608 |
.CE |
| 1609 |
.SS GETCWDPROC |
| 1610 |
.PP |
| 1611 |
Function to process a \fBTcl_FSGetCwd\fR call. Most filesystems need not |
| 1612 |
implement this. It will usually only be called once, if \fBgetcwd\fR is |
| 1613 |
called before \fBchdir\fR. May be NULL. |
| 1614 |
.PP |
| 1615 |
.CS |
| 1616 |
typedef Tcl_Obj *\fBTcl_FSGetCwdProc\fR( |
| 1617 |
Tcl_Interp *\fIinterp\fR); |
| 1618 |
.CE |
| 1619 |
.PP |
| 1620 |
If the filesystem supports a native notion of a current working |
| 1621 |
directory (which might perhaps change independent of Tcl), this |
| 1622 |
function should return that cwd as the result, or NULL if the current |
| 1623 |
directory could not be determined (e.g.\ the user does not have |
| 1624 |
appropriate permissions on the cwd directory). If NULL is returned, an |
| 1625 |
error message is left in the \fIinterp\fR's result. |
| 1626 |
.SS CHDIRPROC |
| 1627 |
.PP |
| 1628 |
Function to process a \fBTcl_FSChdir\fR call. If filesystems do not |
| 1629 |
implement this, it will be emulated by a series of directory access |
| 1630 |
checks. Otherwise, virtual filesystems which do implement it need only |
| 1631 |
respond with a positive return result if the \fIpathPtr\fR is a valid, |
| 1632 |
accessible directory in their filesystem. They need not remember the |
| 1633 |
result, since that will be automatically remembered for use by |
| 1634 |
\fBTcl_FSGetCwd\fR. |
| 1635 |
Real filesystems should carry out the correct action (i.e.\ call the |
| 1636 |
correct system \fBchdir\fR API). |
| 1637 |
.PP |
| 1638 |
.CS |
| 1639 |
typedef int \fBTcl_FSChdirProc\fR( |
| 1640 |
Tcl_Obj *\fIpathPtr\fR); |
| 1641 |
.CE |
| 1642 |
.PP |
| 1643 |
The \fBTcl_FSChdirProc\fR changes the applications current working |
| 1644 |
directory to the value specified in \fIpathPtr\fR. The function returns |
| 1645 |
-1 on error or 0 on success. |
| 1646 |
.SH "SEE ALSO" |
| 1647 |
cd(n), file(n), filename(n), load(n), open(n), pwd(n), source(n), unload(n) |
| 1648 |
.SH KEYWORDS |
| 1649 |
stat, access, filesystem, vfs, virtual filesystem |