Cleanups, documentation.

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2639 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
Meep-Eep
2006-12-31 13:22:16 +00:00
parent 28cdc3c777
commit bf50240944
12 changed files with 77 additions and 69 deletions
+4 -3
View File
@@ -5,16 +5,17 @@ This file describes the various conventions used in the source.
uio_Thing *uio_Thing_new(args) uio_Thing *uio_Thing_new(args)
Allocates the structure, and initialises it from the arguments. Allocates the structure, and initialises it from the arguments.
(was: uio_newThing()) Arguments are always used as-is; if they are reference-counted,
and the caller still needs a reference, it is up to the caller
to increment the reference counter.
void uio_Thing_delete(uio_Thing *thing) void uio_Thing_delete(uio_Thing *thing)
Frees the structure and all sub-structures. Frees the structure and all sub-structures.
Decrements references to shared structures. Decrements reference counters to shared structures.
uio_Thing *uio_Thing_alloc() uio_Thing *uio_Thing_alloc()
Allocates memory for a new structure. Allocates memory for a new structure.
Could be omited for standard allocators. Could be omited for standard allocators.
Particularly relevant when a non-standard allocation scheme is Particularly relevant when a non-standard allocation scheme is
used (for instance, allocation from a pool of pre-allocated strucures). used (for instance, allocation from a pool of pre-allocated strucures).
(was: uio_allocThing())
void uio_Thing_free(Thing *thing) void uio_Thing_free(Thing *thing)
Frees the memory allocated for thing (reverse of uio_Thing_alloc). Frees the memory allocated for thing (reverse of uio_Thing_alloc).
Could be omited for standard deallocators. Could be omited for standard deallocators.
+3 -5
View File
@@ -24,14 +24,12 @@ Documentation:
The physical close function should delete its own data. It's called The physical close function should delete its own data. It's called
Will cleanup the general Handle. Will cleanup the general Handle.
Analogous for mount/unmount with PRoot Analogous for mount/unmount with PRoot
- (internal) arguments for uio_Bla_new are always copied as-is.
If they are ref-counted, the counter should be incremented by the caller,
if the caller does not need the reference itself.
The uio_Bla_delete function decrements the ref counter of the ref-counted
fields.
- No need to store MountHandles. They will be automatically freed - No need to store MountHandles. They will be automatically freed
when the repository is closed. when the repository is closed.
- You can use mount stuff from other repositories. - You can use mount stuff from other repositories.
- ".." works by nullifying one path component, not by following the ".." link
in the directory. "/a/../b" will always be functionally equivalent to
"/b", even when "/a" is a symlink.
Bugs: Bugs:
- 'openDir(repository, "dir/")' will have the trailing '/' - 'openDir(repository, "dir/")' will have the trailing '/'
+7 -7
View File
@@ -24,9 +24,9 @@
#include <errno.h> #include <errno.h>
static uio_FileBlock *uio_newFileBlock(uio_Handle *handle, int flags, static uio_FileBlock *uio_FileBlock_new(uio_Handle *handle, int flags,
off_t offset, size_t blockSize, char *buffer, size_t bufSize); off_t offset, size_t blockSize, char *buffer, size_t bufSize);
static inline uio_FileBlock *uio_allocFileBlock(void); static inline uio_FileBlock *uio_FileBlock_alloc(void);
static void uio_freeFileBlock(uio_FileBlock *block); static void uio_freeFileBlock(uio_FileBlock *block);
@@ -44,7 +44,7 @@ uio_openFileBlock(uio_Handle *handle) {
return NULL; return NULL;
} }
uio_Handle_ref(handle); uio_Handle_ref(handle);
return uio_newFileBlock(handle, 0, 0, statBuf.st_size, NULL, 0); return uio_FileBlock_new(handle, 0, 0, statBuf.st_size, NULL, 0);
} }
uio_FileBlock * uio_FileBlock *
@@ -61,7 +61,7 @@ uio_openFileBlock2(uio_Handle *handle, off_t offset, size_t size) {
if (statBuf.st_size > if (statBuf.st_size >
#endif #endif
uio_Handle_ref(handle); uio_Handle_ref(handle);
return uio_newFileBlock(handle, 0, offset, size, NULL, 0); return uio_FileBlock_new(handle, 0, offset, size, NULL, 0);
} }
// block remains usable until the next call to uio_accessFileBlock // block remains usable until the next call to uio_accessFileBlock
@@ -157,11 +157,11 @@ uio_closeFileBlock(uio_FileBlock *block) {
// caller should uio_refHandle(handle) (unless it doesn't need it's own // caller should uio_refHandle(handle) (unless it doesn't need it's own
// reference anymore). // reference anymore).
static uio_FileBlock * static uio_FileBlock *
uio_newFileBlock(uio_Handle *handle, int flags, off_t offset, uio_FileBlock_new(uio_Handle *handle, int flags, off_t offset,
size_t blockSize, char *buffer, size_t bufSize) { size_t blockSize, char *buffer, size_t bufSize) {
uio_FileBlock *result; uio_FileBlock *result;
result = uio_allocFileBlock(); result = uio_FileBlock_alloc();
result->handle = handle; result->handle = handle;
result->flags = flags; result->flags = flags;
result->offset = offset; result->offset = offset;
@@ -172,7 +172,7 @@ uio_newFileBlock(uio_Handle *handle, int flags, off_t offset,
} }
static inline uio_FileBlock * static inline uio_FileBlock *
uio_allocFileBlock(void) { uio_FileBlock_alloc(void) {
return uio_malloc(sizeof (uio_FileBlock)); return uio_malloc(sizeof (uio_FileBlock));
} }
+6 -6
View File
@@ -32,11 +32,11 @@
static uio_bool uio_validFileSystemHandler(uio_FileSystemHandler *handler); static uio_bool uio_validFileSystemHandler(uio_FileSystemHandler *handler);
static uio_FileSystemInfo *uio_newFileSystemInfo(uio_FileSystemID id, static uio_FileSystemInfo *uio_FileSystemInfo_new(uio_FileSystemID id,
uio_FileSystemHandler *handler, char *name); uio_FileSystemHandler *handler, char *name);
static uio_FileSystemInfo **uio_getFileSystemInfoPtr(uio_FileSystemID id); static uio_FileSystemInfo **uio_getFileSystemInfoPtr(uio_FileSystemID id);
static inline uio_FileSystemInfo *uio_allocFileSystemInfo(void); static inline uio_FileSystemInfo *uio_FileSystemInfo_alloc(void);
static inline void uio_freeFileSystemInfo(uio_FileSystemInfo *fileSystemInfo); static inline void uio_freeFileSystemInfo(uio_FileSystemInfo *fileSystemInfo);
@@ -142,7 +142,7 @@ uio_registerFileSystem(uio_FileSystemID wantedID, const char *name,
{ {
uio_FileSystemInfo *newInfo; uio_FileSystemInfo *newInfo;
newInfo = uio_newFileSystemInfo(wantedID, handler, uio_strdup(name)); newInfo = uio_FileSystemInfo_new(wantedID, handler, uio_strdup(name));
newInfo->next = *ptr; newInfo->next = *ptr;
*ptr = newInfo; *ptr = newInfo;
return wantedID; return wantedID;
@@ -234,11 +234,11 @@ uio_getFileSystemInfoPtr(uio_FileSystemID id) {
// sets ref to 1 // sets ref to 1
static uio_FileSystemInfo * static uio_FileSystemInfo *
uio_newFileSystemInfo(uio_FileSystemID id, uio_FileSystemHandler *handler, uio_FileSystemInfo_new(uio_FileSystemID id, uio_FileSystemHandler *handler,
char *name) { char *name) {
uio_FileSystemInfo *result; uio_FileSystemInfo *result;
result = uio_allocFileSystemInfo(); result = uio_FileSystemInfo_alloc();
result->id = id; result->id = id;
result->handler = handler; result->handler = handler;
result->name = name; result->name = name;
@@ -249,7 +249,7 @@ uio_newFileSystemInfo(uio_FileSystemID id, uio_FileSystemHandler *handler,
// *** Allocators *** // *** Allocators ***
static inline uio_FileSystemInfo * static inline uio_FileSystemInfo *
uio_allocFileSystemInfo(void) { uio_FileSystemInfo_alloc(void) {
uio_FileSystemInfo *result = uio_malloc(sizeof (uio_FileSystemInfo)); uio_FileSystemInfo *result = uio_malloc(sizeof (uio_FileSystemInfo));
#ifdef uio_MEM_DEBUG #ifdef uio_MEM_DEBUG
uio_MemDebug_debugAlloc(uio_FileSystemInfo, (void *) result); uio_MemDebug_debugAlloc(uio_FileSystemInfo, (void *) result);
+9 -9
View File
@@ -89,7 +89,7 @@ uio_unInit(void) {
uio_Repository * uio_Repository *
uio_openRepository(int flags) { uio_openRepository(int flags) {
return uio_newRepository(flags); return uio_Repository_new(flags);
} }
void void
@@ -270,7 +270,7 @@ uio_mountDir(uio_Repository *destRep, const char *mountPoint,
// InPath is a copy with the paths fixed. // InPath is a copy with the paths fixed.
uio_free(unixPath); uio_free(unixPath);
#endif #endif
mountInfo = uio_newMountInfo(fsType, NULL, endDirHandle, dirName, mountInfo = uio_MountInfo_new(fsType, NULL, endDirHandle, dirName,
autoMount, NULL, flags); autoMount, NULL, flags);
uio_repositoryAddMount(destRep, mountInfo, uio_repositoryAddMount(destRep, mountInfo,
flags & uio_MOUNT_LOCATION_MASK, relativeInfo); flags & uio_MOUNT_LOCATION_MASK, relativeInfo);
@@ -1015,11 +1015,11 @@ static uio_DirList *uio_getDirListMulti(uio_PDirHandle **pDirHandles,
int numPDirHandles, const char *pattern, match_MatchType matchType); int numPDirHandles, const char *pattern, match_MatchType matchType);
static uio_DirList *uio_makeDirList(const char **newNames, static uio_DirList *uio_makeDirList(const char **newNames,
const char * const *names, int numNames); const char * const *names, int numNames);
static uio_DirList *uio_newDirList(const char **names, int numNames, static uio_DirList *uio_DirList_new(const char **names, int numNames,
char *buffer); char *buffer);
static void uio_collectDirEntries(uio_PDirHandle *pDirHandle, static void uio_collectDirEntries(uio_PDirHandle *pDirHandle,
uio_DirBufferLink **linkPtr, int *numEntries); uio_DirBufferLink **linkPtr, int *numEntries);
static inline uio_DirList *uio_allocDirList(void); static inline uio_DirList *uio_DirList_alloc(void);
static void uio_filterNames(const char * const *names, int numNames, static void uio_filterNames(const char * const *names, int numNames,
const char **newNames, int *numNewNames, const char **newNames, int *numNewNames,
match_MatchContext *matchContext); match_MatchContext *matchContext);
@@ -1054,7 +1054,7 @@ uio_getDirList(uio_DirHandle *dirHandle, const char *path, const char *pattern,
if (numPDirHandles == 0) { if (numPDirHandles == 0) {
assert(pDirHandles == NULL); assert(pDirHandles == NULL);
// nothing to free // nothing to free
return uio_newDirList(NULL, 0, NULL); return uio_DirList_new(NULL, 0, NULL);
} }
result = uio_getDirListMulti(pDirHandles, numPDirHandles, pattern, result = uio_getDirListMulti(pDirHandles, numPDirHandles, pattern,
@@ -1210,7 +1210,7 @@ uio_makeDirList(const char **newNames, const char * const *names,
totLen += numNames; totLen += numNames;
// for the \0's // for the \0's
result = uio_newDirList(newNames, numNames, uio_malloc(totLen)); result = uio_DirList_new(newNames, numNames, uio_malloc(totLen));
bufPtr = result->buffer; bufPtr = result->buffer;
for (i = 0; i < numNames; i++) { for (i = 0; i < numNames; i++) {
@@ -1373,10 +1373,10 @@ uio_freeDirBufferChain(uio_DirBufferLink *dirBufferLink) {
} }
static uio_DirList * static uio_DirList *
uio_newDirList(const char **names, int numNames, char *buffer) { uio_DirList_new(const char **names, int numNames, char *buffer) {
uio_DirList *result; uio_DirList *result;
result = uio_allocDirList(); result = uio_DirList_alloc();
result->names = names; result->names = names;
result->numNames = numNames; result->numNames = numNames;
result->buffer = buffer; result->buffer = buffer;
@@ -1384,7 +1384,7 @@ uio_newDirList(const char **names, int numNames, char *buffer) {
} }
static uio_DirList * static uio_DirList *
uio_allocDirList(void) { uio_DirList_alloc(void) {
return uio_malloc(sizeof (uio_DirList)); return uio_malloc(sizeof (uio_DirList));
} }
+6 -4
View File
@@ -37,7 +37,7 @@ static int copyError(int error,
* Follow a path starting from a specified physical dir as long as possible. * Follow a path starting from a specified physical dir as long as possible.
* When you can get no further, 'endPDirHandle' will be filled in with a * When you can get no further, 'endPDirHandle' will be filled in with a
* reference to the dir where you ended up, and 'pathRest' will point into * reference to the dir where you ended up, and 'pathRest' will point into
* the original path. to the beginning of the part that was not matched. * the original path to the beginning of the part that was not matched.
* It is allowed to have endPDirHandle point to pDirHandle and/or restPath * It is allowed to have endPDirHandle point to pDirHandle and/or restPath
* point to path when calling this function. Just take care to keep a * point to path when calling this function. Just take care to keep a
* reference to the original so you can decrement the ref counter. * reference to the original so you can decrement the ref counter.
@@ -725,7 +725,9 @@ uio_verifyPath(uio_DirHandle *dirHandle, const char *path,
// Get the absolute path pointed to by 'path' relative to 'dirHandle' // Get the absolute path pointed to by 'path' relative to 'dirHandle'
// The new path will be put in '*destPath', which will be newly allocated. // The new path will be put in '*destPath', which will be newly allocated.
// It will be \0-terminated, and the length will be returned. // It will be \0-terminated, and will not have a '/' as first or last
// character.
// The length of '*destPath' will be returned.
// On error, -1 will be returned, and errno will be set. // On error, -1 will be returned, and errno will be set.
ssize_t ssize_t
uio_resolvePath(uio_DirHandle *dirHandle, const char *path, size_t pathLen, uio_resolvePath(uio_DirHandle *dirHandle, const char *path, size_t pathLen,
@@ -828,7 +830,7 @@ uio_resolvePath(uio_DirHandle *dirHandle, const char *path, size_t pathLen,
endBufPtr--; endBufPtr--;
*endBufPtr = '/'; *endBufPtr = '/';
} else { } else {
// We're already done. Might as well take advantage of // We're already done. We might as well take advantage of
// the fact that we know that and exit immediatly: // the fact that we know that and exit immediatly:
*destPath = buffer; *destPath = buffer;
return len; return len;
@@ -853,7 +855,7 @@ uio_resolvePath(uio_DirHandle *dirHandle, const char *path, size_t pathLen,
endBufPtr--; endBufPtr--;
*endBufPtr = '/'; *endBufPtr = '/';
} else { } else {
// We're already done. Might as well take advantage of // We're already done. We might as well take advantage of
// the fact that we know that and exit immediatly: // the fact that we know that and exit immediatly:
break; break;
} }
+2 -1
View File
@@ -53,7 +53,8 @@ struct uio_DirHandle {
int ref; int ref;
struct uio_Repository *repository; struct uio_Repository *repository;
char *path; char *path;
// does not contain any '.' or '..' // does not contain any '.' or '..'; does not start or end
// with a /
char *rootEnd; char *rootEnd;
// points to the end of the part of path that is considered // points to the end of the part of path that is considered
// the root dir. (you can't use '..' to get above the root dir) // the root dir. (you can't use '..' to get above the root dir)
+4 -4
View File
@@ -32,7 +32,7 @@
#endif #endif
static void uio_deleteRepository(uio_Repository *repository); static void uio_deleteRepository(uio_Repository *repository);
static uio_Repository *uio_allocRepository(void); static uio_Repository *uio_Repository_alloc(void);
static void uio_freeRepository(uio_Repository *repository); static void uio_freeRepository(uio_Repository *repository);
@@ -119,10 +119,10 @@ uio_repositoryRemoveMount(uio_Repository *repository, uio_MountInfo *mountInfo)
// sets ref to 1 // sets ref to 1
uio_Repository * uio_Repository *
uio_newRepository(int flags) { uio_Repository_new(int flags) {
uio_Repository *result; uio_Repository *result;
result = uio_allocRepository(); result = uio_Repository_alloc();
result->ref = 1; result->ref = 1;
result->flags = flags; result->flags = flags;
result->numMounts = 0; result->numMounts = 0;
@@ -141,7 +141,7 @@ uio_Repository_unref(uio_Repository *repository) {
} }
static uio_Repository * static uio_Repository *
uio_allocRepository(void) { uio_Repository_alloc(void) {
uio_Repository *result = uio_malloc(sizeof (uio_Repository)); uio_Repository *result = uio_malloc(sizeof (uio_Repository));
#ifdef uio_MEM_DEBUG #ifdef uio_MEM_DEBUG
uio_MemDebug_debugAlloc(uio_Repository, (void *) result); uio_MemDebug_debugAlloc(uio_Repository, (void *) result);
+1 -1
View File
@@ -49,7 +49,7 @@ struct uio_Repository {
#define lockRepository(repository, prot) #define lockRepository(repository, prot)
#define unlockRepository(repository) #define unlockRepository(repository)
uio_Repository *uio_newRepository(int flags); uio_Repository *uio_Repository_new(int flags);
void uio_Repository_unref(uio_Repository *repository); void uio_Repository_unref(uio_Repository *repository);
void uio_repositoryAddMount(uio_Repository *repository, void uio_repositoryAddMount(uio_Repository *repository,
uio_MountInfo *mountInfo, uio_MountLocation location, uio_MountInfo *mountInfo, uio_MountLocation location,
+26 -26
View File
@@ -69,21 +69,21 @@ static uio_PathComp *uio_makePathComps(const char *path,
uio_PathComp *upComp); uio_PathComp *upComp);
static void uio_printMount(FILE *outStream, const uio_MountInfo *mountInfo); static void uio_printMount(FILE *outStream, const uio_MountInfo *mountInfo);
static inline uio_MountTree * uio_newMountTree(uio_MountTree *subTrees, static inline uio_MountTree * uio_MountTree_new(uio_MountTree *subTrees,
uio_MountTreeItem *pLocs, uio_MountTree *upTree, uio_PathComp uio_MountTreeItem *pLocs, uio_MountTree *upTree, uio_PathComp
*comps, uio_PathComp *lastComp, uio_MountTree *next); *comps, uio_PathComp *lastComp, uio_MountTree *next);
static inline uio_MountTreeItem *uio_newMountTreeItem( static inline uio_MountTreeItem *uio_MountTree_newItem(
uio_MountInfo *mountInfo, int depth, uio_MountTreeItem *next); uio_MountInfo *mountInfo, int depth, uio_MountTreeItem *next);
static inline uio_PathComp *uio_newPathComp(char *name, size_t nameLen, static inline uio_PathComp *uio_PathComp_new(char *name, size_t nameLen,
uio_PathComp *upComp); uio_PathComp *upComp);
static inline void uio_deleteMountTreeItem(uio_MountTreeItem *item); static inline void uio_deleteMountTreeItem(uio_MountTreeItem *item);
static inline void uio_deletePathComp(uio_PathComp *pathComp); static inline void uio_deletePathComp(uio_PathComp *pathComp);
static inline uio_MountTree *uio_allocMountTree(void); static inline uio_MountTree *uio_MountTree_alloc(void);
static inline uio_MountTreeItem *uio_allocMountTreeItem(void); static inline uio_MountTreeItem *uio_MountTreeItem_alloc(void);
static inline uio_MountInfo *uio_allocMountInfo(void); static inline uio_MountInfo *uio_MountInfo_alloc(void);
static inline uio_PathComp *uio_allocPathComp(void); static inline uio_PathComp *uio_PathComp_alloc(void);
static inline void uio_freeMountTree(uio_MountTree *mountTree); static inline void uio_freeMountTree(uio_MountTree *mountTree);
static inline void uio_freeMountTreeItem(uio_MountTreeItem *mountTreeItem); static inline void uio_freeMountTreeItem(uio_MountTreeItem *mountTreeItem);
@@ -94,7 +94,7 @@ static inline void uio_freePathComp(uio_PathComp *pathComp);
// make the root mount Tree // make the root mount Tree
uio_MountTree * uio_MountTree *
uio_makeRootMountTree(void) { uio_makeRootMountTree(void) {
return uio_newMountTree(NULL, NULL, NULL, NULL, NULL, NULL); return uio_MountTree_new(NULL, NULL, NULL, NULL, NULL, NULL);
} }
// Add a MountInfo structure to a MountTree in the place pointed // Add a MountInfo structure to a MountTree in the place pointed
@@ -222,7 +222,7 @@ uio_mountTreeAddMountInfoLocAll(uio_Repository *repository, uio_MountTree *tree,
int compCount; int compCount;
// Add a new PLoc to this mountTree // Add a new PLoc to this mountTree
newPLoc = uio_newMountTreeItem(mountInfo, depth, NULL); newPLoc = uio_MountTree_newItem(mountInfo, depth, NULL);
uio_addMountTreeItem(repository, &tree->pLocs, newPLoc, location, relative); uio_addMountTreeItem(repository, &tree->pLocs, newPLoc, location, relative);
// Recurse for subtrees // Recurse for subtrees
@@ -292,7 +292,7 @@ uio_copyMountTreeItems(uio_MountTreeItem *item, int extraDepth) {
resPtr = &result; resPtr = &result;
while (item != NULL) { while (item != NULL) {
newItem = uio_newMountTreeItem( newItem = uio_MountTree_newItem(
item->mountInfo, item->depth + extraDepth, NULL); item->mountInfo, item->depth + extraDepth, NULL);
*resPtr = newItem; *resPtr = newItem;
resPtr = &newItem->next; resPtr = &newItem->next;
@@ -318,12 +318,12 @@ uio_mountTreeAddNewSubTree(uio_Repository *repository, uio_MountTree *tree,
compList = uio_makePathComps(path, upComp); compList = uio_makePathComps(path, upComp);
compCount = uio_countPathComps(compList); compCount = uio_countPathComps(compList);
lastComp = uio_lastPathComp(compList); lastComp = uio_lastPathComp(compList);
item = uio_newMountTreeItem(mountInfo, 0, NULL); item = uio_MountTree_newItem(mountInfo, 0, NULL);
item->next = NULL; item->next = NULL;
items = uio_copyMountTreeItems(tree->pLocs, compCount); items = uio_copyMountTreeItems(tree->pLocs, compCount);
uio_addMountTreeItem(repository, &items, item, location, uio_addMountTreeItem(repository, &items, item, location,
relative); relative);
newTree = uio_newMountTree( newTree = uio_MountTree_new(
NULL /* subTrees */, NULL /* subTrees */,
items /* pLocs */, items /* pLocs */,
tree /* upTree */, tree /* upTree */,
@@ -357,7 +357,7 @@ uio_splitMountTree(uio_MountTree **tree, uio_PathComp *lastComp, int depth) {
uio_MountTreeItem *items; uio_MountTreeItem *items;
items = uio_copyMountTreeItems((*tree)->upTree->pLocs, depth); items = uio_copyMountTreeItems((*tree)->upTree->pLocs, depth);
newTree = uio_newMountTree( newTree = uio_MountTree_new(
*tree /* subTrees */, *tree /* subTrees */,
items /* pLocs */, items /* pLocs */,
(*tree)->upTree /* upTree */, (*tree)->upTree /* upTree */,
@@ -535,7 +535,7 @@ uio_makePathComps(const char *path, uio_PathComp *upComp) {
memcpy(str, start, end - start); memcpy(str, start, end - start);
str[end - start] = '\0'; str[end - start] = '\0';
*compPtr = uio_newPathComp(str, end - start, upComp); *compPtr = uio_PathComp_new(str, end - start, upComp);
upComp = *compPtr; upComp = *compPtr;
compPtr = &(*compPtr)->next; compPtr = &(*compPtr)->next;
getNextPath0Component(&start, &end); getNextPath0Component(&start, &end);
@@ -741,12 +741,12 @@ uio_printMounts(FILE *outStream, const uio_Repository *repository) {
// *** uio_MountTree*** // // *** uio_MountTree*** //
static inline uio_MountTree * static inline uio_MountTree *
uio_newMountTree(uio_MountTree *subTrees, uio_MountTreeItem *pLocs, uio_MountTree_new(uio_MountTree *subTrees, uio_MountTreeItem *pLocs,
uio_MountTree *upTree, uio_PathComp *comps, uio_PathComp *lastComp, uio_MountTree *upTree, uio_PathComp *comps, uio_PathComp *lastComp,
uio_MountTree *next) { uio_MountTree *next) {
uio_MountTree *result; uio_MountTree *result;
result = uio_allocMountTree(); result = uio_MountTree_alloc();
result->subTrees = subTrees; result->subTrees = subTrees;
result->pLocs = pLocs; result->pLocs = pLocs;
result->upTree = upTree; result->upTree = upTree;
@@ -782,7 +782,7 @@ uio_deleteMountTree(uio_MountTree *tree) {
} }
static inline uio_MountTree * static inline uio_MountTree *
uio_allocMountTree(void) { uio_MountTree_alloc(void) {
uio_MountTree *result = uio_malloc(sizeof (uio_MountTree)); uio_MountTree *result = uio_malloc(sizeof (uio_MountTree));
#ifdef uio_MEM_DEBUG #ifdef uio_MEM_DEBUG
uio_MemDebug_debugAlloc(uio_MountTree, (void *) result); uio_MemDebug_debugAlloc(uio_MountTree, (void *) result);
@@ -802,11 +802,11 @@ uio_freeMountTree(uio_MountTree *mountTree) {
// *** uio_MountTreeItem *** // // *** uio_MountTreeItem *** //
static inline uio_MountTreeItem * static inline uio_MountTreeItem *
uio_newMountTreeItem(uio_MountInfo *mountInfo, int depth, uio_MountTree_newItem(uio_MountInfo *mountInfo, int depth,
uio_MountTreeItem *next) { uio_MountTreeItem *next) {
uio_MountTreeItem *result; uio_MountTreeItem *result;
result = uio_allocMountTreeItem(); result = uio_MountTreeItem_alloc();
result->mountInfo = mountInfo; result->mountInfo = mountInfo;
result->depth = depth; result->depth = depth;
result->next = next; result->next = next;
@@ -819,7 +819,7 @@ uio_deleteMountTreeItem(uio_MountTreeItem *item) {
} }
static inline uio_MountTreeItem * static inline uio_MountTreeItem *
uio_allocMountTreeItem(void) { uio_MountTreeItem_alloc(void) {
uio_MountTreeItem *result = uio_malloc(sizeof (uio_MountTreeItem)); uio_MountTreeItem *result = uio_malloc(sizeof (uio_MountTreeItem));
#ifdef uio_MEM_DEBUG #ifdef uio_MEM_DEBUG
uio_MemDebug_debugAlloc(uio_MountTreeItem, (void *) result); uio_MemDebug_debugAlloc(uio_MountTreeItem, (void *) result);
@@ -839,12 +839,12 @@ uio_freeMountTreeItem(uio_MountTreeItem *mountTreeItem) {
// *** uio_MountInfo *** // // *** uio_MountInfo *** //
uio_MountInfo * uio_MountInfo *
uio_newMountInfo(uio_FileSystemID fsID, uio_MountTree *mountTree, uio_MountInfo_new(uio_FileSystemID fsID, uio_MountTree *mountTree,
uio_PDirHandle *pDirHandle, char *dirName, uio_AutoMount **autoMount, uio_PDirHandle *pDirHandle, char *dirName, uio_AutoMount **autoMount,
uio_MountHandle *mountHandle, int flags) { uio_MountHandle *mountHandle, int flags) {
uio_MountInfo *result; uio_MountInfo *result;
result = uio_allocMountInfo(); result = uio_MountInfo_alloc();
result->fsID = fsID; result->fsID = fsID;
result->mountTree = mountTree; result->mountTree = mountTree;
result->pDirHandle = pDirHandle; result->pDirHandle = pDirHandle;
@@ -863,7 +863,7 @@ uio_deleteMountInfo(uio_MountInfo *mountInfo) {
} }
static inline uio_MountInfo * static inline uio_MountInfo *
uio_allocMountInfo(void) { uio_MountInfo_alloc(void) {
uio_MountInfo *result = uio_malloc(sizeof (uio_MountInfo)); uio_MountInfo *result = uio_malloc(sizeof (uio_MountInfo));
#ifdef uio_MEM_DEBUG #ifdef uio_MEM_DEBUG
uio_MemDebug_debugAlloc(uio_MountInfo, (void *) result); uio_MemDebug_debugAlloc(uio_MountInfo, (void *) result);
@@ -886,10 +886,10 @@ uio_freeMountInfo(uio_MountInfo *mountInfo) {
// no copy is made. // no copy is made.
// 'namelen' should be the length of 'name' // 'namelen' should be the length of 'name'
static inline uio_PathComp * static inline uio_PathComp *
uio_newPathComp(char *name, size_t nameLen, uio_PathComp *upComp) { uio_PathComp_new(char *name, size_t nameLen, uio_PathComp *upComp) {
uio_PathComp *result; uio_PathComp *result;
result = uio_allocPathComp(); result = uio_PathComp_alloc();
result->name = name; result->name = name;
result->nameLen = nameLen; result->nameLen = nameLen;
result->up = upComp; result->up = upComp;
@@ -909,7 +909,7 @@ uio_deletePathComp(uio_PathComp *pathComp) {
} }
static inline uio_PathComp * static inline uio_PathComp *
uio_allocPathComp(void) { uio_PathComp_alloc(void) {
uio_PathComp *result = uio_malloc(sizeof (uio_PathComp)); uio_PathComp *result = uio_malloc(sizeof (uio_PathComp));
#ifdef uio_MEM_DEBUG #ifdef uio_MEM_DEBUG
uio_MemDebug_debugAlloc(uio_PathComp, (void *) result); uio_MemDebug_debugAlloc(uio_PathComp, (void *) result);
+3 -2
View File
@@ -194,8 +194,9 @@ void uio_findMountTree(uio_MountTree *top, const char *path,
char *uio_mountTreeItemRestPath(const uio_MountTreeItem *item, char *uio_mountTreeItemRestPath(const uio_MountTreeItem *item,
uio_PathComp *endComp, const char *path); uio_PathComp *endComp, const char *path);
int uio_mountTreeCountPLocs(const uio_MountTree *tree); int uio_mountTreeCountPLocs(const uio_MountTree *tree);
uio_MountInfo *uio_newMountInfo(uio_FileSystemID fsID, uio_MountTree *mountTree, uio_MountInfo *uio_MountInfo_new(uio_FileSystemID fsID,
uio_PDirHandle *pDirHandle, char *dirName, uio_AutoMount **autoMount, uio_MountTree *mountTree, uio_PDirHandle *pDirHandle,
char *dirName, uio_AutoMount **autoMount,
uio_MountHandle *mountHandle, int flags); uio_MountHandle *mountHandle, int flags);
void uio_deleteMountInfo(uio_MountInfo *mountInfo); void uio_deleteMountInfo(uio_MountInfo *mountInfo);
void uio_printMountTree(FILE *outStream, const uio_MountTree *tree, int indent); void uio_printMountTree(FILE *outStream, const uio_MountTree *tree, int indent);
+6 -1
View File
@@ -174,7 +174,7 @@ joinPaths(const char *first, const char *second) {
return result; return result;
} }
// Combine two parts of a paths into a new path, // Combine two parts of a paths into a new path.
// The new path will always start with a '/'. // The new path will always start with a '/'.
// The first path may (but doesn't have to) end on a '/', or may be empty. // The first path may (but doesn't have to) end on a '/', or may be empty.
// Pre: the second path doesn't start with a '/' // Pre: the second path doesn't start with a '/'
@@ -215,6 +215,11 @@ joinPathsAbsolute(const char *first, const char *second) {
return result; return result;
} }
// Returns 'false' if
// - one of the path components is empty, or
// - one of the path components is ".", or
// - one of the path components is ".."
// and 'true' otherwise.
uio_bool uio_bool
validPathName(const char *path, size_t len) { validPathName(const char *path, size_t len) {
const char *pathEnd; const char *pathEnd;