コード例 #1
0
ファイル: io.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
int
uio_stat(uio_DirHandle *dir, const char *path, struct stat *statBuf) {
	uio_PDirHandle *pReadDir;
	uio_MountInfo *readMountInfo;
	char *name;
	int result;

	if (uio_getPhysicalAccess(dir, path, O_RDONLY, 0,
			&readMountInfo, &pReadDir, NULL,
			NULL, NULL, NULL, &name) == -1) {
		if (uio_statDir(dir, path, statBuf) == -1) {
			// errno is set
			return -1;
		}
		return 0;
	}

	if (pReadDir->pRoot->handler->stat == NULL) {
		uio_PDirHandle_unref(pReadDir);
		uio_free(name);
		errno = ENOSYS;
		return -1;
	}

	result = (pReadDir->pRoot->handler->stat)(pReadDir, name, statBuf);
	uio_PDirHandle_unref(pReadDir);
	uio_free(name);
	return result;
}
コード例 #2
0
ファイル: debug.c プロジェクト: ptaoussanis/urquan-masters
static int
listOneDir(DebugContext *debugContext, const char *arg) {
    uio_DirList *dirList;
    int i;
    const char *pattern;
    const char *cpath;
    char *buf = NULL;

    if (arg[0] == '\0') {
        cpath = arg;
        pattern = "*";
    } else {
        pattern = strrchr(arg, '/');
        if (pattern == NULL) {
            // No directory component in 'arg'.
            cpath = "";
            pattern = arg;
        } else if (pattern[1] == '\0') {
            // 'arg' ends on /
            cpath = arg;
            pattern = "*";
        } else {
            if (pattern == arg) {
                cpath = "/";
            } else {
                buf = uio_malloc(pattern - arg + 1);
                memcpy(buf, arg, pattern - arg);
                buf[pattern - arg] = '\0';
                cpath = buf;
            }
            pattern++;
        }
    }
#ifdef HAVE_GLOB
    dirList = uio_getDirList(debugContext->cwd, cpath, pattern,
                             match_MATCH_GLOB);
#else
    if (pattern[0] == '*' && pattern[1] == '\0') {
        dirList = uio_getDirList(debugContext->cwd, cpath, "",
                                 match_MATCH_PREFIX);
    } else {
        dirList = uio_getDirList(debugContext->cwd, cpath, pattern,
                                 match_MATCH_LITERAL);
    }
#endif
    if (dirList == NULL) {
        fprintf(debugContext->out, "Error in uio_getDirList(): %s.\n",
                strerror(errno));
        if (buf != NULL)
            uio_free(buf);
        return 1;
    }
    for (i = 0; i < dirList->numNames; i++)
        fprintf(debugContext->out, "%s\n", dirList->names[i]);
    uio_DirList_free(dirList);
    if (buf != NULL)
        uio_free(buf);
    return 0;
}
コード例 #3
0
ファイル: io.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
void
uio_DirList_free(uio_DirList *dirList) {
	if (dirList->buffer)
		uio_free(dirList->buffer);
	if (dirList->names)
		uio_free((void *) dirList->names);
	uio_free(dirList);
}
コード例 #4
0
ファイル: utils.c プロジェクト: Serosis/UQM-MegaMod
static inline void
uio_StdioAccessHandle_delete(uio_StdioAccessHandle *handle) {
	if (handle->tempDir != NULL)
		uio_DirHandle_unref(handle->tempDir);
	if (handle->fileName != NULL)
		uio_free(handle->fileName);
	if (handle->tempRoot != NULL)
		uio_DirHandle_unref(handle->tempRoot);
	if (handle->tempDirName != NULL)
		uio_free(handle->tempDirName);
	uio_free(handle->stdioPath);
	uio_StdioAccessHandle_free(handle);
}
コード例 #5
0
ファイル: debug.c プロジェクト: ptaoussanis/urquan-masters
void
uio_debugInteractive(FILE *in, FILE *out, FILE *err) {
    char lineBuf[LINEBUFLEN];
    size_t lineLen;
    int argc;
    char **argv;
    DebugContext debugContext;
    uio_bool interactive;

    memset(&debugContext, '\0', sizeof (DebugContext));
    debugContext.exit = false;
    debugContext.in = in;
    debugContext.out = out;
    debugContext.err = err;
    debugContext.cwd = uio_openDir(repository, "/", 0);
    if (debugContext.cwd == NULL) {
        fprintf(err, "Fatal: Could not open working dir.\n");
        abort();
    }

    interactive = isatty(fileno(in));
    do {
        if (interactive)
            fprintf(out, "> ");
        if (fgets(lineBuf, LINEBUFLEN, in) == NULL) {
            if (feof(in)) {
                // user pressed ^D
                break;
            }
            // error occured
            clearerr(in);
            continue;
        }
        lineLen = strlen(lineBuf);
        if (lineBuf[lineLen - 1] != '\n' && lineBuf[lineLen - 1] != '\r') {
            fprintf(err, "Too long command line.\n");
            // TODO: read until EOL
            continue;
        }
        makeArgs(lineBuf, &argc, &argv);
        if (argc == 0) {
            uio_free(argv);
            continue;
        }
        debugCallCommand(&debugContext, argc, argv);
        uio_free(argv);
    } while (!debugContext.exit);
    if (interactive)
        fprintf(out, "\n");
    uio_closeDir(debugContext.cwd);
}
コード例 #6
0
ファイル: gphys.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
static inline void
uio_GPFile_free(uio_GPFile *gPFile) {
	uio_free(gPFile);
#ifdef uio_MEM_DEBUG
	uio_MemDebug_debugFree(uio_GPFile, (void *) gPFile);
#endif
}
コード例 #7
0
ファイル: gphys.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
static void
uio_GPRoot_free(uio_GPRoot *gPRoot) {
#ifdef uio_MEM_DEBUG
	uio_MemDebug_debugFree(uio_GPRoot, (void *) gPRoot);
#endif
	uio_free(gPRoot);
}
コード例 #8
0
ファイル: gphys.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
static inline void
uio_GPDir_free(uio_GPDir *gPDir) {
#ifdef uio_MEM_DEBUG
	uio_MemDebug_debugFree(uio_GPDir, (void *) gPDir);
#endif
	uio_free(gPDir);
}
コード例 #9
0
ファイル: io.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
static inline void
uio_PFileHandle_free(uio_PFileHandle *pFileHandle) {
#ifdef uio_MEM_DEBUG
	uio_MemDebug_debugFree(uio_PFileHandle, (void *) pFileHandle);
#endif
	uio_free(pFileHandle);
}
コード例 #10
0
ファイル: fstypes.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
int
uio_unRegisterFileSystem(uio_FileSystemID id) {
	uio_FileSystemInfo **ptr;
	uio_FileSystemInfo *temp;

	ptr = uio_getFileSystemInfoPtr(id);
	if (ptr == NULL) {
		errno = EINVAL;
		return -1;
	}
	if ((*ptr)->ref > 1) {
		errno = EBUSY;
		return -1;
	}

	if ((*ptr)->handler->unInit != NULL &&
			((*ptr)->handler->unInit() == -1)) {
		// errno is set
		return -1;
	}
	
	temp = *ptr;
	*ptr = (*ptr)->next;

//	uio_FileSystemHandler_unref(temp->handler);
	uio_free(temp->name);
	uio_FileSystemInfo_free(temp);
	
	return 0;	
}
コード例 #11
0
ファイル: io.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
static inline void
uio_DirHandle_free(uio_DirHandle *dirHandle) {
#ifdef uio_MEM_DEBUG
	uio_MemDebug_debugFree(uio_DirHandle, (void *) dirHandle);
#endif
	uio_free(dirHandle);
}
コード例 #12
0
ファイル: fileblock.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
// Call if you want the memory used by the fileblock to be released, but
// still want to use the fileblock later. If you don't need the fileblock,
// call uio_closeFileBlock() instead.
void
uio_clearFileBlockBuffers(uio_FileBlock *block) {
	if (block->buffer != NULL) {
		uio_free(block->buffer);
		block->buffer = NULL;
	}
}
コード例 #13
0
ファイル: spl-vnode.c プロジェクト: rottegift/spl
int zfs_vn_rdwr(enum uio_rw rw, struct vnode *vp, caddr_t base, ssize_t len,
                offset_t offset, enum uio_seg seg, int ioflag, rlim64_t ulimit,
                cred_t *cr, ssize_t *residp)
{
    uio_t *auio;
    int spacetype;
    int error=0;
    vfs_context_t vctx;

    spacetype = UIO_SEG_IS_USER_SPACE(seg) ? UIO_USERSPACE32 : UIO_SYSSPACE;

    vctx = vfs_context_create((vfs_context_t)0);
    auio = uio_create(1, 0, spacetype, rw);
    uio_reset(auio, offset, spacetype, rw);
    uio_addiov(auio, (uint64_t)(uintptr_t)base, len);

    if (rw == UIO_READ) {
        error = VNOP_READ(vp, auio, ioflag, vctx);
    } else {
        error = VNOP_WRITE(vp, auio, ioflag, vctx);
    }

    if (residp) {
        *residp = uio_resid(auio);
    } else {
        if (uio_resid(auio) && error == 0)
            error = EIO;
    }

    uio_free(auio);
    vfs_context_rele(vctx);

    return (error);
}
コード例 #14
0
ファイル: fstypes.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
static inline void
uio_FileSystemInfo_free(uio_FileSystemInfo *fileSystemInfo) {
#ifdef uio_MEM_DEBUG
	uio_MemDebug_debugFree(uio_FileSystemInfo, (void *) fileSystemInfo);
#endif
	uio_free(fileSystemInfo);
}
コード例 #15
0
ファイル: io.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
static inline void
uio_Handle_free(uio_Handle *handle) {
#ifdef uio_MEM_DEBUG
	uio_MemDebug_debugFree(uio_Handle, (void *) handle);
#endif
	uio_free(handle);
}
コード例 #16
0
static inline void
uio_MountInfo_free(uio_MountInfo *mountInfo) {
#ifdef uio_MEM_DEBUG
	uio_MemDebug_debugFree(uio_MountInfo, (void *) mountInfo);
#endif
	uio_free(mountInfo);
}
コード例 #17
0
static inline void
uio_MountTreeItem_free(uio_MountTreeItem *mountTreeItem) {
#ifdef uio_MEM_DEBUG
	uio_MemDebug_debugFree(uio_MountTreeItem, (void *) mountTreeItem);
#endif
	uio_free(mountTreeItem);
}
コード例 #18
0
ファイル: utils.c プロジェクト: Serosis/UQM-MegaMod
/*
 * Closes srcHandle if it's not -1.
 * Closes dstHandle if it's not -1.
 * Removes unlinkpath from the unlinkHandle dir if it's not NULL.
 * Frees 'buf' if not NULL.
 * Always returns -1.
 * errno is what was before the call.
 */
static int
uio_copyError(uio_Handle *srcHandle, uio_Handle *dstHandle,
		uio_DirHandle *unlinkHandle, const char *unlinkPath, uio_uint8 *buf) {
	int savedErrno;

	savedErrno = errno;

#ifdef DEBUG
	fprintf(stderr, "Error while copying: %s\n", strerror(errno));
#endif

	if (srcHandle != NULL)
		uio_close(srcHandle);
	
	if (dstHandle != NULL)
		uio_close(dstHandle);
	
	if (unlinkPath != NULL)
		uio_unlink(unlinkHandle, unlinkPath);
	
	if (buf != NULL)
		uio_free(buf);
	
	errno = savedErrno;
	return -1;
}
コード例 #19
0
ファイル: paths.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
static inline void
uio_PathComp_free(uio_PathComp *pathComp) {
#ifdef uio_MEM_DEBUG
	uio_MemDebug_debugFree(uio_PathComp, (void *) pathComp);
#endif
	uio_free(pathComp);
}
コード例 #20
0
ファイル: match.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
void
match_freeRegex(match_RegexContext *context) {
	regfree(&context->native);
	if (context->errorString)
		uio_free(context->errorString);
	match_freeRegexContext(context);
}
コード例 #21
0
ファイル: io.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
static inline void
uio_MountHandle_free(uio_MountHandle *mountHandle) {
#ifdef uio_MEM_DEBUG
	uio_MemDebug_debugFree(uio_MountHandle, (void *) mountHandle);
#endif
	uio_free(mountHandle);
}
コード例 #22
0
ファイル: vnops.c プロジェクト: aredridel/mac9p
static int
vnop_strategy_9p(struct vnop_strategy_args *ap)
{
	mount_t mp;
	struct buf *bp;
	node_9p *np;
	caddr_t addr;
	uio_t uio;
	int e, flags;

	TRACE();
	bp = ap->a_bp;
	np = NTO9P(buf_vnode(bp));
	flags = buf_flags(bp);
	uio = NULL;
	addr = NULL;

	mp = vnode_mount(buf_vnode(bp));
	if (mp == NULL)
		return ENXIO;

	if ((e=buf_map(bp, &addr)))
		goto error;

	uio = uio_create(1, buf_blkno(bp) * vfs_statfs(mp)->f_bsize, UIO_SYSSPACE,
					 ISSET(flags, B_READ)? UIO_READ: UIO_WRITE);
	if (uio == NULL) {
		e = ENOMEM;
		goto error;
	}
	
	uio_addiov(uio, CAST_USER_ADDR_T(addr), buf_count(bp));
	if (ISSET(flags, B_READ)) {
		if((e=nread_9p(np, uio)))
			goto error;
		/* zero the rest of the page if we reached EOF */
		if (uio_resid(uio) > 0) {
			bzero(addr+buf_count(bp)-uio_resid(uio), uio_resid(uio));
			uio_update(uio, uio_resid(uio));
		}
	} else {
		if ((e=nwrite_9p(np, uio)))
			goto error;
	}
	buf_setresid(bp, uio_resid(uio));
error:
	if (uio)
		uio_free(uio);
	if (addr)
		buf_unmap(bp);
	buf_seterror(bp, e);
	buf_biodone(bp);
	return e;
}
コード例 #23
0
ファイル: paths.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
void
uio_PathComp_delete(uio_PathComp *pathComp) {
	uio_PathComp *next;

	while (pathComp != NULL) {
		next = pathComp->next;
		uio_free(pathComp->name);
		uio_PathComp_free(pathComp);
		pathComp = next;
	}
}
コード例 #24
0
ファイル: uio_object.c プロジェクト: varphone/libuio
UIO_API uio_object_destroy(uio_object_t obj)
{
    assert(obj);
    struct UioObject* Obj = uio_Object_of(obj);
    assert(Obj->ref_count == 0);
    if (Obj->name) {
        uio_free(Obj->name);
        Obj->name = 0;
    }
    if (Obj->parent) {
        uio_object_drop(Obj->parent);
        Obj->parent = 0;
    }
    if (Obj->priv_size) {
        uio_free(Obj->priv_data);
        Obj->priv_data = 0;
        Obj->Priv_size = 0;
    }
    uio_free(Obj);
    return 0;
}
コード例 #25
0
ファイル: zfs_vnops_osx_lib.c プロジェクト: RJVB/zfs
void getfinderinfo(znode_t *zp, cred_t *cr, finderinfo_t *fip)
{
	vnode_t	*xdvp = NULLVP;
	vnode_t	*xvp = NULLVP;
	struct uio		*auio = NULL;
	struct componentname  cn;
	int		error;
    uint64_t xattr = 0;

    if (sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zp->z_zfsvfs),
                   &xattr, sizeof(xattr)) ||
        (xattr == 0)) {
        goto nodata;
    }

	auio = uio_create(1, 0, UIO_SYSSPACE, UIO_READ);
	if (auio == NULL) {
		goto nodata;
	}
	uio_addiov(auio, CAST_USER_ADDR_T(fip), sizeof (finderinfo_t));

	/*
	 * Grab the hidden attribute directory vnode.
	 *
	 * XXX - switch to embedded Finder Info when it becomes available
	 */
	if ((error = zfs_get_xattrdir(zp, &xdvp, cr, 0))) {
		goto out;
	}

	bzero(&cn, sizeof (cn));
	cn.cn_nameiop = LOOKUP;
	cn.cn_flags = ISLASTCN;
	cn.cn_nameptr = XATTR_FINDERINFO_NAME;
	cn.cn_namelen = strlen(cn.cn_nameptr);

	if ((error = zfs_dirlook(VTOZ(xdvp), cn.cn_nameptr, &xvp, 0, NULL, &cn))) {
		goto out;
	}
	error = dmu_read_uio(zp->z_zfsvfs->z_os, VTOZ(xvp)->z_id, auio,
	                     sizeof (finderinfo_t));
out:
	if (auio)
		uio_free(auio);
	if (xvp)
		vnode_put(xvp);
	if (xdvp)
		vnode_put(xdvp);
	if (error == 0)
		return;
nodata:
	bzero(fip, sizeof (finderinfo_t));
}
コード例 #26
0
ファイル: osi_file.c プロジェクト: chanke/openafs-osd
/* Generic read interface */
int
afs_osi_Read(struct osi_file *afile, int offset, void *aptr,
	     afs_int32 asize)
{
    afs_ucred_t *oldCred;
    afs_size_t resid;
    afs_int32 code;
#ifdef AFS_DARWIN80_ENV
    uio_t uio;
#endif
    AFS_STATCNT(osi_Read);

    /**
      * If the osi_file passed in is NULL, panic only if AFS is not shutting
      * down. No point in crashing when we are already shutting down
      */
    if (!afile) {
	if (afs_shuttingdown == AFS_RUNNING)
	    osi_Panic("osi_Read called with null param");
	else
	    return -EIO;
    }

    if (offset != -1)
	afile->offset = offset;
    AFS_GUNLOCK();
#ifdef AFS_DARWIN80_ENV
    uio=uio_create(1, afile->offset, AFS_UIOSYS, UIO_READ);
    uio_addiov(uio, CAST_USER_ADDR_T(aptr), asize);
    code = VNOP_READ(afile->vnode, uio, IO_UNIT, afs_osi_ctxtp);
    resid = AFS_UIO_RESID(uio);
    uio_free(uio);
#else
    code =
	gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
		 AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid);
#endif
    AFS_GLOCK();
    if (code == 0) {
	code = asize - resid;
	afile->offset += code;
	osi_DisableAtimes(afile->vnode);
    } else {
	afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
		   ICL_TYPE_INT32, code);
	if (code > 0) {
	    code *= -1;
	}
    }
    return code;
}
コード例 #27
0
ファイル: io.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
int
uio_mkdir(uio_DirHandle *dir, const char *path, mode_t mode) {
	uio_PDirHandle *pReadDir, *pWriteDir;
	uio_MountInfo *readMountInfo, *writeMountInfo;
	char *name;
	uio_PDirHandle *newDirHandle;

	if (uio_getPhysicalAccess(dir, path, O_WRONLY | O_CREAT | O_EXCL, 0,
			&readMountInfo, &pReadDir, NULL,
			&writeMountInfo, &pWriteDir, NULL, &name) == -1) {
		// errno is set
		if (errno == EISDIR)
			errno = EEXIST;
		return -1;
	}
	uio_PDirHandle_unref(pReadDir);
	
	if (pWriteDir->pRoot->handler->mkdir == NULL) {
		uio_free(name);
		uio_PDirHandle_unref(pWriteDir);
		errno = ENOSYS;
		return -1;
	}

	newDirHandle = (pWriteDir->pRoot->handler->mkdir)(pWriteDir, name, mode);
	if (newDirHandle == NULL) {
		int savedErrno = errno;
		uio_free(name);
		uio_PDirHandle_unref(pWriteDir);
		errno = savedErrno;
		return -1;
	}

	uio_PDirHandle_unref(pWriteDir);
	uio_PDirHandle_unref(newDirHandle);
	uio_free(name);
	return 0;
}
コード例 #28
0
ファイル: fileblock.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
int
uio_closeFileBlock(uio_FileBlock *block) {
	if (block->flags & uio_FB_USE_MMAP) {
#if 0
		if (block->buffer != NULL)
			uio_mmunmap(block->buffer);
#endif
	} else {
		if (block->buffer != NULL)
			uio_free(block->buffer);
	}
	uio_Handle_unref(block->handle);
	uio_FileBlock_free(block);
	return 0;
}
コード例 #29
0
ファイル: match.c プロジェクト: 0xDEC0DE/uqm-0.6.4-ee
const char *
match_errorStringRegex(match_RegexContext *context, int errorCode) {
	size_t errorStringLength;

	if (context->errorString != NULL)
		uio_free(context->errorString);

	errorStringLength = regerror(context->errorCode, &context->native,
			NULL, 0);
	context->errorString = uio_malloc(errorStringLength);
	regerror(context->errorCode, &context->native,
			context->errorString, errorStringLength);
	
	(void) errorCode;
	return context->errorString;
}
コード例 #30
0
ファイル: osi_file.c プロジェクト: chanke/openafs-osd
/* Generic write interface */
int
afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
	      afs_int32 asize)
{
    afs_ucred_t *oldCred;
    afs_size_t resid;
    afs_int32 code;
#ifdef AFS_DARWIN80_ENV
    uio_t uio;
#endif
    AFS_STATCNT(osi_Write);
    if (!afile)
	osi_Panic("afs_osi_Write called with null param");
    if (offset != -1)
	afile->offset = offset;
    {
	AFS_GUNLOCK();
#ifdef AFS_DARWIN80_ENV
        uio=uio_create(1, afile->offset, AFS_UIOSYS, UIO_WRITE);
        uio_addiov(uio, CAST_USER_ADDR_T(aptr), asize);
        code = VNOP_WRITE(afile->vnode, uio, IO_UNIT, afs_osi_ctxtp);
        resid = AFS_UIO_RESID(uio);
        uio_free(uio);
#else
	code =
	    gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
		     afile->offset, AFS_UIOSYS, IO_UNIT, &afs_osi_cred,
		     &resid);
#endif
	AFS_GLOCK();
    }
    if (code == 0) {
	code = asize - resid;
	afile->offset += code;
    } else {
	if (code > 0) {
	    code *= -1;
	}
    }
    if (afile->proc) {
	(*afile->proc) (afile, code);
    }
    return code;
}