Esempio n. 1
0
File: uxz.c Progetto: lb1a/avfs
static int xz_open(ventry *ve, int flags, avmode_t mode, void **resp)
{
    int res;
    vfile *base;
    struct xznode *nod;
    struct xzhandle *fil;

    if(flags & AVO_DIRECTORY)
        return -ENOTDIR;

    if(AV_ISWRITE(flags))
        return -EROFS;

    res = av_open(ve->mnt->base, AVO_RDONLY, 0, &base);
    if(res < 0)
        return res;

    res = xz_getnode(ve, base, &nod);
    if(res < 0) {
        av_close(base);
        return res;
    }

    AV_NEW(fil);
    if((flags & AVO_ACCMODE) != AVO_NOPERM)
        fil->zfil = av_xzfile_new(base);
    else
        fil->zfil = NULL;

    fil->base = base;
    fil->node = nod;
    
    *resp = fil;
    return 0;
}
Esempio n. 2
0
static int random_proper(void *ret_data, size_t length) {
	int fd, ret = -1;
	ssize_t r = 0;
	const char *const * device;

	av_assert(ret_data);
	av_assert(length > 0);

	device = devices;

	while (*device) {
		ret = 0;

		if ((fd = open(*device, O_RDONLY | O_NOCTTY)) >= 0) {
			if ((r = av_loop_read(fd, ret_data, length, NULL)) < 0 || (size_t) r != length)
				ret = -1;

			av_close(fd);
		} else
			ret = -1;

		if (ret == 0)
			break;

		device++;
	}

	return ret;
}
Esempio n. 3
0
File: uxz.c Progetto: lb1a/avfs
static int xz_close(vfile *vf)
{
    struct xzhandle *fil = (struct xzhandle *) vf->data;

    av_unref_obj(fil->zfil);
    av_unref_obj(fil->node);
    av_close(fil->base);
    av_free(fil);

    return 0;
}