Changes In Branch add-inode Through [5aadfc2b05] Excluding Merge-Ins
This is equivalent to a diff from d17d8bb449 to 5aadfc2b05
2020-04-13
| ||
20:25 | Merged in trunk Leaf check-in: a178887263 user: rkeene tags: add-inode | |
19:19 | Added MSan/ASan targets check-in: 7d5fcf4486 user: rkeene tags: trunk | |
17:58 | Ensure inode lookups are within bounds check-in: 5aadfc2b05 user: rkeene tags: add-inode | |
17:11 | Added start of ABI change to allow lookups by inode as an optimization check-in: 142a373444 user: rkeene tags: add-inode | |
15:50 | Fixed typo in last commit check-in: d17d8bb449 user: rkeene tags: trunk | |
15:47 | Added an "--static-init" option to creation to make the Xvfs_fsName_Init function static, if needed to be included into a .c file check-in: 717062426a user: rkeene tags: trunk | |
Modified lib/xvfs/xvfs.c.rvt from [2be0a65534] to [6cafb9a4b1].
︙ | ︙ | |||
78 79 80 81 82 83 84 | pathLen = strlen(path); <?= [dict get $hashTable body] ?> return(XVFS_NAME_LOOKUP_ERROR); } | | < > > > > > > > > > > | | | | | | > | < | > > > > > > > > > > > | | | | | | > | 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | pathLen = strlen(path); <?= [dict get $hashTable body] ?> return(XVFS_NAME_LOOKUP_ERROR); } static const char **xvfs_<?= $::xvfs::fsName ?>_getChildren(const char *path, long inode, Tcl_WideInt *count) { const struct xvfs_file_data *fileInfo; /* * Validate input parameters */ if (count == NULL) { return(NULL); } /* * Use user-supplied inode, or look up the path */ if (inode != XVFS_INODE_NULL) { if (inode >= <?= [llength $::xvfs::outputFiles] ?> || inode < 0) { inode = XVFS_INODE_NULL; path = NULL; } } if (inode == XVFS_INODE_NULL) { /* * Get the inode from the lookup function */ inode = xvfs_<?= $::xvfs::fsName ?>_nameToIndex(path); if (inode == XVFS_NAME_LOOKUP_ERROR) { *count = XVFS_RV_ERR_ENOENT; return(NULL); } } fileInfo = &xvfs_<?= $::xvfs::fsName ?>_data[inode]; /* * Ensure this is a directory */ if (fileInfo->type != XVFS_FILE_TYPE_DIR) { *count = XVFS_RV_ERR_ENOTDIR; return(NULL); } *count = fileInfo->size; return(fileInfo->data.dirChildren); } static const unsigned char *xvfs_<?= $::xvfs::fsName ?>_getData(const char *path, long inode, Tcl_WideInt start, Tcl_WideInt *length) { const struct xvfs_file_data *fileInfo; Tcl_WideInt resultLength; /* * Validate input parameters */ if (length == NULL) { return(NULL); } if (start < 0) { *length = XVFS_RV_ERR_EINVAL; return(NULL); } if (*length < 0) { *length = XVFS_RV_ERR_EINVAL; return(NULL); } /* * Use user-supplied inode, or look up the path */ if (inode != XVFS_INODE_NULL) { if (inode >= <?= [llength $::xvfs::outputFiles] ?> || inode < 0) { inode = XVFS_INODE_NULL; path = NULL; } } if (inode == XVFS_INODE_NULL) { /* * Get the inode from the lookup function */ inode = xvfs_<?= $::xvfs::fsName ?>_nameToIndex(path); if (inode == XVFS_NAME_LOOKUP_ERROR) { *length = XVFS_RV_ERR_ENOENT; return(NULL); } } fileInfo = &xvfs_<?= $::xvfs::fsName ?>_data[inode]; /* * Ensure this is a file that can be read */ |
︙ | ︙ | |||
174 175 176 177 178 179 180 | /* * Return the data */ return(fileInfo->data.fileContents + start); } | | < > > > > > > > > > > | | | | | > | 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | /* * Return the data */ return(fileInfo->data.fileContents + start); } static int xvfs_<?= $::xvfs::fsName ?>_getStat(const char *path, long inode, Tcl_StatBuf *statBuf) { const struct xvfs_file_data *fileInfo; /* * Validate input parameters */ if (!statBuf) { return(XVFS_RV_ERR_EINVAL); } /* * Use user-supplied inode, or look up the path */ if (inode != XVFS_INODE_NULL) { if (inode >= <?= [llength $::xvfs::outputFiles] ?> || inode < 0) { inode = XVFS_INODE_NULL; path = NULL; } } if (inode == XVFS_INODE_NULL) { /* * Get the inode from the lookup function */ inode = xvfs_<?= $::xvfs::fsName ?>_nameToIndex(path); if (inode == XVFS_NAME_LOOKUP_ERROR) { return(XVFS_RV_ERR_ENOENT); } } fileInfo = &xvfs_<?= $::xvfs::fsName ?>_data[inode]; statBuf->st_dev = <?= [zlib adler32 $::xvfs::fsName 0] ?>; statBuf->st_rdev = <?= [zlib adler32 $::xvfs::fsName 0] ?>; statBuf->st_ino = inode; |
︙ | ︙ |
Modified xvfs-core.c from [acc58f104b] to [49217ccb09].
︙ | ︙ | |||
197 198 199 200 201 202 203 | /* * Xvfs Memory Channel */ struct xvfs_tclfs_channel_id { Tcl_Channel channel; struct xvfs_tclfs_instance_info *fsInstanceInfo; | | | 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | /* * Xvfs Memory Channel */ struct xvfs_tclfs_channel_id { Tcl_Channel channel; struct xvfs_tclfs_instance_info *fsInstanceInfo; long inode; Tcl_WideInt currentOffset; Tcl_WideInt fileSize; int eofMarked; int queuedEvents; int closed; }; struct xvfs_tclfs_channel_event { |
︙ | ︙ | |||
220 221 222 223 224 225 226 | Tcl_StatBuf fileInfo; Tcl_Obj *channelName; int statRet; XVFS_DEBUG_ENTER; XVFS_DEBUG_PRINTF("Opening file \"%s\" ...", Tcl_GetString(path)); | | | 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | Tcl_StatBuf fileInfo; Tcl_Obj *channelName; int statRet; XVFS_DEBUG_ENTER; XVFS_DEBUG_PRINTF("Opening file \"%s\" ...", Tcl_GetString(path)); statRet = instanceInfo->fsInfo->getStatProc(Tcl_GetString(path), XVFS_INODE_NULL, &fileInfo); if (statRet < 0) { XVFS_DEBUG_PRINTF("... failed: %s", xvfs_strerror(statRet)); xvfs_setresults_error(interp, XVFS_RV_ERR_ENOENT); XVFS_DEBUG_LEAVE; return(NULL); |
︙ | ︙ | |||
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | channelInstanceData = (struct xvfs_tclfs_channel_id *) Tcl_Alloc(sizeof(*channelInstanceData)); channelInstanceData->currentOffset = 0; channelInstanceData->eofMarked = 0; channelInstanceData->queuedEvents = 0; channelInstanceData->closed = 0; channelInstanceData->channel = NULL; channelName = Tcl_ObjPrintf("xvfs0x%llx", (unsigned long long) channelInstanceData); if (!channelName) { XVFS_DEBUG_PUTS("... failed"); Tcl_Free((char *) channelInstanceData); XVFS_DEBUG_LEAVE; return(NULL); } Tcl_IncrRefCount(channelName); channelInstanceData->fsInstanceInfo = instanceInfo; channelInstanceData->fileSize = fileInfo.st_size; | > < < | 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | channelInstanceData = (struct xvfs_tclfs_channel_id *) Tcl_Alloc(sizeof(*channelInstanceData)); channelInstanceData->currentOffset = 0; channelInstanceData->eofMarked = 0; channelInstanceData->queuedEvents = 0; channelInstanceData->closed = 0; channelInstanceData->channel = NULL; channelInstanceData->inode = fileInfo.st_ino; channelName = Tcl_ObjPrintf("xvfs0x%llx", (unsigned long long) channelInstanceData); if (!channelName) { XVFS_DEBUG_PUTS("... failed"); Tcl_Free((char *) channelInstanceData); XVFS_DEBUG_LEAVE; return(NULL); } Tcl_IncrRefCount(channelName); channelInstanceData->fsInstanceInfo = instanceInfo; channelInstanceData->fileSize = fileInfo.st_size; channel = Tcl_CreateChannel(&xvfs_tclfs_channelType, Tcl_GetString(channelName), channelInstanceData, TCL_READABLE); Tcl_DecrRefCount(channelName); if (!channel) { XVFS_DEBUG_PUTS("... failed"); Tcl_DecrRefCount(path); |
︙ | ︙ | |||
324 325 326 327 328 329 330 | Tcl_QueueEvent((Tcl_Event *) event, TCL_QUEUE_TAIL); XVFS_DEBUG_LEAVE; return(0); } | < | | | | 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | Tcl_QueueEvent((Tcl_Event *) event, TCL_QUEUE_TAIL); XVFS_DEBUG_LEAVE; return(0); } Tcl_Free((char *) channelInstanceData); XVFS_DEBUG_PUTS("... ok"); XVFS_DEBUG_LEAVE; return(0); } static int xvfs_tclfs_readChannel(ClientData channelInstanceData_p, char *buf, int bufSize, int *errorCodePtr) { struct xvfs_tclfs_channel_id *channelInstanceData; const unsigned char *data; Tcl_WideInt offset, length; long inode; channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p; /* * If we are already at the end of the file we can skip * attempting to read it */ if (channelInstanceData->eofMarked) { return(0); } inode = channelInstanceData->inode; offset = channelInstanceData->currentOffset; length = bufSize; data = channelInstanceData->fsInstanceInfo->fsInfo->getDataProc(NULL, inode, offset, &length); if (length < 0) { *errorCodePtr = xvfs_errorToErrno(length); return(-1); } |
︙ | ︙ | |||
516 517 518 519 520 521 522 | XVFS_DEBUG_PRINTF("Getting stat() on \"%s\" ...", Tcl_GetString(path)); path = xvfs_absolutePath(path); pathStr = xvfs_relativePath(path, instanceInfo); | | | 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 | XVFS_DEBUG_PRINTF("Getting stat() on \"%s\" ...", Tcl_GetString(path)); path = xvfs_absolutePath(path); pathStr = xvfs_relativePath(path, instanceInfo); retval = instanceInfo->fsInfo->getStatProc(pathStr, XVFS_INODE_NULL, statBuf); if (retval < 0) { XVFS_DEBUG_PRINTF("... failed: %s", xvfs_strerror(retval)); Tcl_SetErrno(xvfs_errorToErrno(retval)); retval = -1; } else { |
︙ | ︙ | |||
561 562 563 564 565 566 567 | Tcl_DecrRefCount(path); XVFS_DEBUG_LEAVE; return(-1); } | | | 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | Tcl_DecrRefCount(path); XVFS_DEBUG_LEAVE; return(-1); } statRetVal = instanceInfo->fsInfo->getStatProc(pathStr, XVFS_INODE_NULL, &fileInfo); if (statRetVal < 0) { XVFS_DEBUG_PUTS("... no (not statable)"); Tcl_DecrRefCount(path); XVFS_DEBUG_LEAVE; return(-1); |
︙ | ︙ | |||
763 764 765 766 767 768 769 | xvfs_setresults_error(interp, XVFS_RV_ERR_ENOENT); XVFS_DEBUG_LEAVE; return(TCL_OK); } childrenCount = 0; | | | 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 | xvfs_setresults_error(interp, XVFS_RV_ERR_ENOENT); XVFS_DEBUG_LEAVE; return(TCL_OK); } childrenCount = 0; children = instanceInfo->fsInfo->getChildrenProc(pathStr, XVFS_INODE_NULL, &childrenCount); if (childrenCount < 0) { XVFS_DEBUG_PRINTF("... error: %s", xvfs_strerror(childrenCount)); Tcl_DecrRefCount(path); xvfs_setresults_error(interp, childrenCount); |
︙ | ︙ |
Modified xvfs-core.h from [8640d3027d] to [601afdbb27].
1 2 3 4 5 6 7 | #ifndef XVFS_CORE_H_1B4B28D60EBAA11D5FF85642FA7CA22C29E8E817 #define XVFS_CORE_H_1B4B28D60EBAA11D5FF85642FA7CA22C29E8E817 1 #include <tcl.h> #define XVFS_PROTOCOL_VERSION 1 | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #ifndef XVFS_CORE_H_1B4B28D60EBAA11D5FF85642FA7CA22C29E8E817 #define XVFS_CORE_H_1B4B28D60EBAA11D5FF85642FA7CA22C29E8E817 1 #include <tcl.h> #define XVFS_PROTOCOL_VERSION 1 typedef const char **(*xvfs_proc_getChildren_t)(const char *path, long inode, Tcl_WideInt *count); typedef const unsigned char *(*xvfs_proc_getData_t)(const char *path, long inode, Tcl_WideInt start, Tcl_WideInt *length); typedef int (*xvfs_proc_getStat_t)(const char *path, long inode, Tcl_StatBuf *statBuf); /* * Interface for the filesystem to fill out before registering. * The protocolVersion is provided first so that if this * needs to change over time it can be appropriately handled. */ struct Xvfs_FSInfo { |
︙ | ︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #define XVFS_RV_ERR_EINVAL (-8193) #define XVFS_RV_ERR_EISDIR (-8194) #define XVFS_RV_ERR_ENOTDIR (-8195) #define XVFS_RV_ERR_EFAULT (-8196) #define XVFS_RV_ERR_EROFS (-8197) #define XVFS_RV_ERR_INTERNAL (-16383) #define XVFS_REGISTER_INTERFACE(name) int name(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo); #if defined(XVFS_MODE_STANDALONE) /* * In standalone mode, we just redefine calls to * Xvfs_Register() to go to the xvfs_standalone_register() * function | > > > > > > > | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #define XVFS_RV_ERR_EINVAL (-8193) #define XVFS_RV_ERR_EISDIR (-8194) #define XVFS_RV_ERR_ENOTDIR (-8195) #define XVFS_RV_ERR_EFAULT (-8196) #define XVFS_RV_ERR_EROFS (-8197) #define XVFS_RV_ERR_INTERNAL (-16383) /* * Functions allow user to specify either a path or a inode. * If a path is specified, the inode must be specified as * XVFS_INODE_NULL. */ #define XVFS_INODE_NULL (-1) #define XVFS_REGISTER_INTERFACE(name) int name(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo); #if defined(XVFS_MODE_STANDALONE) /* * In standalone mode, we just redefine calls to * Xvfs_Register() to go to the xvfs_standalone_register() * function |
︙ | ︙ |
Modified xvfs-create-c.c from [56b4842ff2] to [3e031870d5].
︙ | ︙ | |||
313 314 315 316 317 318 319 320 321 322 323 324 325 326 | fprintf(outfp, "static const struct xvfs_file_data xvfs_"); fprintf(outfp, "%s", options->name); fprintf(outfp, "_data[] = {\n"); parse_xvfs_minirivet_directory(outfp, xvfs_state, options->directory, ""); fprintf(outfp, "};\n"); } else if (strcmp(buffer_p, "[zlib adler32 $::xvfs::fsName 0]") == 0) { fprintf(outfp, "%lu", adler32(0, (unsigned char *) options->name, strlen(options->name))); } else if (strcmp(buffer_p, "$hashTableHeader") == 0) { parse_xvfs_minirivet_hashtable_header(outfp, xvfs_state); } else if (strcmp(buffer_p, "[dict get $hashTable body]") == 0) { parse_xvfs_minirivet_hashtable_body(outfp, xvfs_state); } else { fprintf(outfp, "@INVALID@%s@INVALID@", buffer_p); } | > > | 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | fprintf(outfp, "static const struct xvfs_file_data xvfs_"); fprintf(outfp, "%s", options->name); fprintf(outfp, "_data[] = {\n"); parse_xvfs_minirivet_directory(outfp, xvfs_state, options->directory, ""); fprintf(outfp, "};\n"); } else if (strcmp(buffer_p, "[zlib adler32 $::xvfs::fsName 0]") == 0) { fprintf(outfp, "%lu", adler32(0, (unsigned char *) options->name, strlen(options->name))); } else if (strcmp(buffer_p, "[llength $::xvfs::outputFiles]") == 0) { fprintf(outfp, "%lu", xvfs_state->child_count); } else if (strcmp(buffer_p, "$hashTableHeader") == 0) { parse_xvfs_minirivet_hashtable_header(outfp, xvfs_state); } else if (strcmp(buffer_p, "[dict get $hashTable body]") == 0) { parse_xvfs_minirivet_hashtable_body(outfp, xvfs_state); } else { fprintf(outfp, "@INVALID@%s@INVALID@", buffer_p); } |
︙ | ︙ |