Home | History | Annotate | Line # | Download | only in libukfs
ukfs.c revision 1.1
      1  1.1  pooka /*	$NetBSD: ukfs.c,v 1.1 2008/07/29 13:17:41 pooka Exp $	*/
      2  1.1  pooka 
      3  1.1  pooka /*
      4  1.1  pooka  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
      5  1.1  pooka  *
      6  1.1  pooka  * Development of this software was supported by the
      7  1.1  pooka  * Finnish Cultural Foundation.
      8  1.1  pooka  *
      9  1.1  pooka  * Redistribution and use in source and binary forms, with or without
     10  1.1  pooka  * modification, are permitted provided that the following conditions
     11  1.1  pooka  * are met:
     12  1.1  pooka  * 1. Redistributions of source code must retain the above copyright
     13  1.1  pooka  *    notice, this list of conditions and the following disclaimer.
     14  1.1  pooka  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  pooka  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  pooka  *    documentation and/or other materials provided with the distribution.
     17  1.1  pooka  *
     18  1.1  pooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     19  1.1  pooka  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20  1.1  pooka  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     21  1.1  pooka  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     22  1.1  pooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23  1.1  pooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24  1.1  pooka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  1.1  pooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26  1.1  pooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  1.1  pooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  1.1  pooka  * SUCH DAMAGE.
     29  1.1  pooka  */
     30  1.1  pooka 
     31  1.1  pooka /*
     32  1.1  pooka  * This library enables access to files systems directly without
     33  1.1  pooka  * involving system calls.
     34  1.1  pooka  */
     35  1.1  pooka 
     36  1.1  pooka #ifdef __linux__
     37  1.1  pooka #define _XOPEN_SOURCE 500
     38  1.1  pooka #define _BSD_SOURCE
     39  1.1  pooka #define _FILE_OFFSET_BITS 64
     40  1.1  pooka #endif
     41  1.1  pooka 
     42  1.1  pooka #include <sys/stat.h>
     43  1.1  pooka 
     44  1.1  pooka #include <assert.h>
     45  1.1  pooka #include <err.h>
     46  1.1  pooka #include <errno.h>
     47  1.1  pooka #include <pthread.h>
     48  1.1  pooka #include <stdio.h>
     49  1.1  pooka #include <stdlib.h>
     50  1.1  pooka #include <string.h>
     51  1.1  pooka #include <unistd.h>
     52  1.1  pooka #include <stdint.h>
     53  1.1  pooka 
     54  1.1  pooka #include <rump/ukfs.h>
     55  1.1  pooka 
     56  1.1  pooka #include <rump/rump.h>
     57  1.1  pooka #include <rump/rump_syscalls.h>
     58  1.1  pooka 
     59  1.1  pooka #define UKFS_MODE_DEFAULT 0555
     60  1.1  pooka 
     61  1.1  pooka struct ukfs {
     62  1.1  pooka 	struct mount *ukfs_mp;
     63  1.1  pooka 	struct vnode *ukfs_rvp;
     64  1.1  pooka 
     65  1.1  pooka 	pthread_spinlock_t ukfs_spin;
     66  1.1  pooka 	pid_t ukfs_nextpid;
     67  1.1  pooka 	struct vnode *ukfs_cdir;
     68  1.1  pooka };
     69  1.1  pooka 
     70  1.1  pooka struct mount *
     71  1.1  pooka ukfs_getmp(struct ukfs *ukfs)
     72  1.1  pooka {
     73  1.1  pooka 
     74  1.1  pooka 	return ukfs->ukfs_mp;
     75  1.1  pooka }
     76  1.1  pooka 
     77  1.1  pooka struct vnode *
     78  1.1  pooka ukfs_getrvp(struct ukfs *ukfs)
     79  1.1  pooka {
     80  1.1  pooka 	struct vnode *rvp;
     81  1.1  pooka 
     82  1.1  pooka 	rvp = ukfs->ukfs_rvp;
     83  1.1  pooka 	rump_vp_incref(rvp);
     84  1.1  pooka 
     85  1.1  pooka 	return rvp;
     86  1.1  pooka }
     87  1.1  pooka 
     88  1.1  pooka static pid_t
     89  1.1  pooka nextpid(struct ukfs *ukfs)
     90  1.1  pooka {
     91  1.1  pooka 	pid_t npid;
     92  1.1  pooka 
     93  1.1  pooka 	pthread_spin_lock(&ukfs->ukfs_spin);
     94  1.1  pooka 	npid = ukfs->ukfs_nextpid++;
     95  1.1  pooka 	pthread_spin_unlock(&ukfs->ukfs_spin);
     96  1.1  pooka 
     97  1.1  pooka 	return npid;
     98  1.1  pooka }
     99  1.1  pooka 
    100  1.1  pooka static void
    101  1.1  pooka precall(struct ukfs *ukfs)
    102  1.1  pooka {
    103  1.1  pooka 	struct vnode *rvp, *cvp;
    104  1.1  pooka 
    105  1.1  pooka 	rump_setup_curlwp(nextpid(ukfs), 1, 1);
    106  1.1  pooka 	rvp = ukfs_getrvp(ukfs);
    107  1.1  pooka 	pthread_spin_lock(&ukfs->ukfs_spin);
    108  1.1  pooka 	cvp = ukfs->ukfs_cdir;
    109  1.1  pooka 	pthread_spin_unlock(&ukfs->ukfs_spin);
    110  1.1  pooka 	rump_rcvp_set(rvp, cvp); /* takes refs */
    111  1.1  pooka 	rump_vp_rele(rvp);
    112  1.1  pooka }
    113  1.1  pooka 
    114  1.1  pooka static void
    115  1.1  pooka postcall(struct ukfs *ukfs)
    116  1.1  pooka {
    117  1.1  pooka 	struct vnode *rvp;
    118  1.1  pooka 
    119  1.1  pooka 	rvp = ukfs_getrvp(ukfs);
    120  1.1  pooka 	rump_rcvp_set(NULL, rvp);
    121  1.1  pooka 	rump_vp_rele(rvp);
    122  1.1  pooka 	rump_clear_curlwp();
    123  1.1  pooka }
    124  1.1  pooka 
    125  1.1  pooka int
    126  1.1  pooka ukfs_init()
    127  1.1  pooka {
    128  1.1  pooka 
    129  1.1  pooka 	rump_init();
    130  1.1  pooka 
    131  1.1  pooka 	return 0;
    132  1.1  pooka }
    133  1.1  pooka 
    134  1.1  pooka struct ukfs *
    135  1.1  pooka ukfs_mount(const char *vfsname, const char *devpath, const char *mountpath,
    136  1.1  pooka 	int mntflags, void *arg, size_t alen)
    137  1.1  pooka {
    138  1.1  pooka 	struct ukfs *fs = NULL;
    139  1.1  pooka 	struct vfsops *vfsops;
    140  1.1  pooka 	struct mount *mp;
    141  1.1  pooka 	int rv = 0;
    142  1.1  pooka 
    143  1.1  pooka 	vfsops = rump_vfs_getopsbyname(vfsname);
    144  1.1  pooka 	if (vfsops == NULL) {
    145  1.1  pooka 		rv = ENOENT;
    146  1.1  pooka 		goto out;
    147  1.1  pooka 	}
    148  1.1  pooka 
    149  1.1  pooka 	mp = rump_mnt_init(vfsops, mntflags);
    150  1.1  pooka 
    151  1.1  pooka 	fs = malloc(sizeof(struct ukfs));
    152  1.1  pooka 	if (fs == NULL) {
    153  1.1  pooka 		rv = ENOMEM;
    154  1.1  pooka 		goto out;
    155  1.1  pooka 	}
    156  1.1  pooka 	memset(fs, 0, sizeof(struct ukfs));
    157  1.1  pooka 	pthread_spin_init(&fs->ukfs_spin, PTHREAD_PROCESS_SHARED);
    158  1.1  pooka 
    159  1.1  pooka 	rump_fakeblk_register(devpath);
    160  1.1  pooka 	rv = rump_mnt_mount(mp, mountpath, arg, &alen);
    161  1.1  pooka 	rump_fakeblk_deregister(devpath);
    162  1.1  pooka 	if (rv) {
    163  1.1  pooka 		warnx("VFS_MOUNT %d", rv);
    164  1.1  pooka 		goto out;
    165  1.1  pooka 	}
    166  1.1  pooka 	fs->ukfs_mp = mp;
    167  1.1  pooka 
    168  1.1  pooka 	rv = rump_vfs_root(fs->ukfs_mp, &fs->ukfs_rvp, 0);
    169  1.1  pooka 	fs->ukfs_cdir = ukfs_getrvp(fs);
    170  1.1  pooka 
    171  1.1  pooka  out:
    172  1.1  pooka 	if (rv) {
    173  1.1  pooka 		if (fs && fs->ukfs_mp)
    174  1.1  pooka 			rump_mnt_destroy(fs->ukfs_mp);
    175  1.1  pooka 		if (fs)
    176  1.1  pooka 			free(fs);
    177  1.1  pooka 		errno = rv;
    178  1.1  pooka 		fs = NULL;
    179  1.1  pooka 	}
    180  1.1  pooka 
    181  1.1  pooka 	return fs;
    182  1.1  pooka }
    183  1.1  pooka 
    184  1.1  pooka void
    185  1.1  pooka ukfs_release(struct ukfs *fs, int flags)
    186  1.1  pooka {
    187  1.1  pooka 	int rv;
    188  1.1  pooka 
    189  1.1  pooka 	if ((flags & UKFS_RELFLAG_NOUNMOUNT) == 0) {
    190  1.1  pooka 		rump_vp_rele(fs->ukfs_cdir);
    191  1.1  pooka 		rv = rump_vfs_sync(fs->ukfs_mp, 1, NULL);
    192  1.1  pooka 		rump_vp_recycle_nokidding(ukfs_getrvp(fs));
    193  1.1  pooka 		rv |= rump_vfs_unmount(fs->ukfs_mp, 0);
    194  1.1  pooka 		assert(rv == 0);
    195  1.1  pooka 	}
    196  1.1  pooka 
    197  1.1  pooka 	rump_vfs_syncwait(fs->ukfs_mp);
    198  1.1  pooka 	rump_mnt_destroy(fs->ukfs_mp);
    199  1.1  pooka 
    200  1.1  pooka 	pthread_spin_destroy(&fs->ukfs_spin);
    201  1.1  pooka 	free(fs);
    202  1.1  pooka }
    203  1.1  pooka 
    204  1.1  pooka /* don't need vn_lock(), since we don't have VXLOCK */
    205  1.1  pooka #define VLE(a) rump_vp_lock_exclusive(a)
    206  1.1  pooka #define VLS(a) rump_vp_lock_shared(a)
    207  1.1  pooka #define VUL(a) rump_vp_unlock(a)
    208  1.1  pooka #define AUL(a) assert(rump_vp_islocked(a) == 0)
    209  1.1  pooka 
    210  1.1  pooka #define STDCALL(ukfs, thecall)						\
    211  1.1  pooka 	int rv = 0;							\
    212  1.1  pooka 									\
    213  1.1  pooka 	precall(ukfs);							\
    214  1.1  pooka 	thecall;							\
    215  1.1  pooka 	postcall(ukfs);							\
    216  1.1  pooka 	if (rv) {							\
    217  1.1  pooka 		errno = rv;						\
    218  1.1  pooka 		return -1;						\
    219  1.1  pooka 	}								\
    220  1.1  pooka 	return 0;
    221  1.1  pooka 
    222  1.1  pooka int
    223  1.1  pooka ukfs_getdents(struct ukfs *ukfs, const char *dirname, off_t *off,
    224  1.1  pooka 	uint8_t *buf, size_t bufsize)
    225  1.1  pooka {
    226  1.1  pooka 	struct uio *uio;
    227  1.1  pooka 	struct vnode *vp;
    228  1.1  pooka 	size_t resid;
    229  1.1  pooka 	int rv, eofflag;
    230  1.1  pooka 
    231  1.1  pooka 	precall(ukfs);
    232  1.1  pooka 	rv = rump_namei(RUMP_NAMEI_LOOKUP, RUMP_NAMEI_LOCKLEAF, dirname,
    233  1.1  pooka 	    NULL, &vp, NULL);
    234  1.1  pooka 	postcall(ukfs);
    235  1.1  pooka 	if (rv)
    236  1.1  pooka 		goto out;
    237  1.1  pooka 
    238  1.1  pooka 	uio = rump_uio_setup(buf, bufsize, *off, RUMPUIO_READ);
    239  1.1  pooka 	rv = RUMP_VOP_READDIR(vp, uio, NULL, &eofflag, NULL, NULL);
    240  1.1  pooka 	VUL(vp);
    241  1.1  pooka 	*off = rump_uio_getoff(uio);
    242  1.1  pooka 	resid = rump_uio_free(uio);
    243  1.1  pooka 	rump_vp_rele(vp);
    244  1.1  pooka 
    245  1.1  pooka  out:
    246  1.1  pooka 	if (rv) {
    247  1.1  pooka 		errno = rv;
    248  1.1  pooka 		return -1;
    249  1.1  pooka 	}
    250  1.1  pooka 
    251  1.1  pooka 	/* LINTED: not totally correct return type, but follows syscall */
    252  1.1  pooka 	return bufsize - resid;
    253  1.1  pooka }
    254  1.1  pooka 
    255  1.1  pooka ssize_t
    256  1.1  pooka ukfs_read(struct ukfs *ukfs, const char *filename, off_t off,
    257  1.1  pooka 	uint8_t *buf, size_t bufsize)
    258  1.1  pooka {
    259  1.1  pooka 	int fd, rv = 0, dummy;
    260  1.1  pooka 	ssize_t xfer = -1; /* XXXgcc */
    261  1.1  pooka 
    262  1.1  pooka 	precall(ukfs);
    263  1.1  pooka 	fd = rump_sys_open(filename, RUMP_O_RDONLY, 0, &rv);
    264  1.1  pooka 	if (rv)
    265  1.1  pooka 		goto out;
    266  1.1  pooka 
    267  1.1  pooka 	xfer = rump_sys_pread(fd, buf, bufsize, 0, off, &rv);
    268  1.1  pooka 	rump_sys_close(fd, &dummy);
    269  1.1  pooka 
    270  1.1  pooka  out:
    271  1.1  pooka 	postcall(ukfs);
    272  1.1  pooka 	if (rv) {
    273  1.1  pooka 		errno = rv;
    274  1.1  pooka 		return -1;
    275  1.1  pooka 	}
    276  1.1  pooka 	return xfer;
    277  1.1  pooka }
    278  1.1  pooka 
    279  1.1  pooka ssize_t
    280  1.1  pooka ukfs_write(struct ukfs *ukfs, const char *filename, off_t off,
    281  1.1  pooka 	uint8_t *buf, size_t bufsize)
    282  1.1  pooka {
    283  1.1  pooka 	int fd, rv = 0, dummy;
    284  1.1  pooka 	ssize_t xfer = -1; /* XXXgcc */
    285  1.1  pooka 
    286  1.1  pooka 	precall(ukfs);
    287  1.1  pooka 	fd = rump_sys_open(filename, RUMP_O_WRONLY, 0, &rv);
    288  1.1  pooka 	if (rv)
    289  1.1  pooka 		goto out;
    290  1.1  pooka 
    291  1.1  pooka 	/* write and commit */
    292  1.1  pooka 	xfer = rump_sys_pwrite(fd, buf, bufsize, 0, off, &rv);
    293  1.1  pooka 	if (rv == 0)
    294  1.1  pooka 		rump_sys_fsync(fd, &dummy);
    295  1.1  pooka 
    296  1.1  pooka 	rump_sys_close(fd, &dummy);
    297  1.1  pooka 
    298  1.1  pooka  out:
    299  1.1  pooka 	postcall(ukfs);
    300  1.1  pooka 	if (rv) {
    301  1.1  pooka 		errno = rv;
    302  1.1  pooka 		return -1;
    303  1.1  pooka 	}
    304  1.1  pooka 	return xfer;
    305  1.1  pooka }
    306  1.1  pooka 
    307  1.1  pooka int
    308  1.1  pooka ukfs_create(struct ukfs *ukfs, const char *filename, mode_t mode)
    309  1.1  pooka {
    310  1.1  pooka 	int rv, fd, dummy;
    311  1.1  pooka 
    312  1.1  pooka 	precall(ukfs);
    313  1.1  pooka 	fd = rump_sys_open(filename, RUMP_O_WRONLY | RUMP_O_CREAT, mode, &rv);
    314  1.1  pooka 	rump_sys_close(fd, &dummy);
    315  1.1  pooka 
    316  1.1  pooka 	postcall(ukfs);
    317  1.1  pooka 	if (rv) {
    318  1.1  pooka 		errno = rv;
    319  1.1  pooka 		return -1;
    320  1.1  pooka 	}
    321  1.1  pooka 	return 0;
    322  1.1  pooka }
    323  1.1  pooka 
    324  1.1  pooka int
    325  1.1  pooka ukfs_mknod(struct ukfs *ukfs, const char *path, mode_t mode, dev_t dev)
    326  1.1  pooka {
    327  1.1  pooka 
    328  1.1  pooka 	STDCALL(ukfs, rump_sys_mknod(path, mode, dev, &rv));
    329  1.1  pooka }
    330  1.1  pooka 
    331  1.1  pooka int
    332  1.1  pooka ukfs_mkfifo(struct ukfs *ukfs, const char *path, mode_t mode)
    333  1.1  pooka {
    334  1.1  pooka 
    335  1.1  pooka 	STDCALL(ukfs, rump_sys_mkfifo(path, mode, &rv));
    336  1.1  pooka }
    337  1.1  pooka 
    338  1.1  pooka int
    339  1.1  pooka ukfs_mkdir(struct ukfs *ukfs, const char *filename, mode_t mode)
    340  1.1  pooka {
    341  1.1  pooka 
    342  1.1  pooka 	STDCALL(ukfs, rump_sys_mkdir(filename, mode, &rv));
    343  1.1  pooka }
    344  1.1  pooka 
    345  1.1  pooka int
    346  1.1  pooka ukfs_remove(struct ukfs *ukfs, const char *filename)
    347  1.1  pooka {
    348  1.1  pooka 
    349  1.1  pooka 	STDCALL(ukfs, rump_sys_unlink(filename, &rv));
    350  1.1  pooka }
    351  1.1  pooka 
    352  1.1  pooka int
    353  1.1  pooka ukfs_rmdir(struct ukfs *ukfs, const char *filename)
    354  1.1  pooka {
    355  1.1  pooka 
    356  1.1  pooka 	STDCALL(ukfs, rump_sys_rmdir(filename, &rv));
    357  1.1  pooka }
    358  1.1  pooka 
    359  1.1  pooka int
    360  1.1  pooka ukfs_link(struct ukfs *ukfs, const char *filename, const char *f_create)
    361  1.1  pooka {
    362  1.1  pooka 
    363  1.1  pooka 	STDCALL(ukfs, rump_sys_link(filename, f_create, &rv));
    364  1.1  pooka }
    365  1.1  pooka 
    366  1.1  pooka int
    367  1.1  pooka ukfs_symlink(struct ukfs *ukfs, const char *filename, const char *linkname)
    368  1.1  pooka {
    369  1.1  pooka 
    370  1.1  pooka 	STDCALL(ukfs, rump_sys_symlink(filename, linkname, &rv));
    371  1.1  pooka }
    372  1.1  pooka 
    373  1.1  pooka ssize_t
    374  1.1  pooka ukfs_readlink(struct ukfs *ukfs, const char *filename,
    375  1.1  pooka 	char *linkbuf, size_t buflen)
    376  1.1  pooka {
    377  1.1  pooka 	ssize_t rv;
    378  1.1  pooka 	int myerr = 0;
    379  1.1  pooka 
    380  1.1  pooka 	precall(ukfs);
    381  1.1  pooka 	rv = rump_sys_readlink(filename, linkbuf, buflen, &myerr);
    382  1.1  pooka 	postcall(ukfs);
    383  1.1  pooka 	if (myerr) {
    384  1.1  pooka 		errno = rv;
    385  1.1  pooka 		return -1;
    386  1.1  pooka 	}
    387  1.1  pooka 	return rv;
    388  1.1  pooka }
    389  1.1  pooka 
    390  1.1  pooka int
    391  1.1  pooka ukfs_rename(struct ukfs *ukfs, const char *from, const char *to)
    392  1.1  pooka {
    393  1.1  pooka 
    394  1.1  pooka 	STDCALL(ukfs, rump_sys_rename(from, to, &rv));
    395  1.1  pooka }
    396  1.1  pooka 
    397  1.1  pooka int
    398  1.1  pooka ukfs_chdir(struct ukfs *ukfs, const char *path)
    399  1.1  pooka {
    400  1.1  pooka 	struct vnode *newvp, *oldvp;
    401  1.1  pooka 	int rv;
    402  1.1  pooka 
    403  1.1  pooka 	precall(ukfs);
    404  1.1  pooka 	rump_sys_chdir(path, &rv);
    405  1.1  pooka 	if (rv)
    406  1.1  pooka 		goto out;
    407  1.1  pooka 
    408  1.1  pooka 	newvp = rump_cdir_get();
    409  1.1  pooka 	pthread_spin_lock(&ukfs->ukfs_spin);
    410  1.1  pooka 	oldvp = ukfs->ukfs_cdir;
    411  1.1  pooka 	ukfs->ukfs_cdir = newvp;
    412  1.1  pooka 	pthread_spin_unlock(&ukfs->ukfs_spin);
    413  1.1  pooka 	if (oldvp)
    414  1.1  pooka 		rump_vp_rele(oldvp);
    415  1.1  pooka 
    416  1.1  pooka  out:
    417  1.1  pooka 	postcall(ukfs);
    418  1.1  pooka 	if (rv) {
    419  1.1  pooka 		errno = rv;
    420  1.1  pooka 		return -1;
    421  1.1  pooka 	}
    422  1.1  pooka 	return 0;
    423  1.1  pooka }
    424  1.1  pooka 
    425  1.1  pooka int
    426  1.1  pooka ukfs_stat(struct ukfs *ukfs, const char *filename, struct stat *file_stat)
    427  1.1  pooka {
    428  1.1  pooka 
    429  1.1  pooka 	STDCALL(ukfs, rump_sys___stat30(filename, file_stat, &rv));
    430  1.1  pooka }
    431  1.1  pooka 
    432  1.1  pooka int
    433  1.1  pooka ukfs_lstat(struct ukfs *ukfs, const char *filename, struct stat *file_stat)
    434  1.1  pooka {
    435  1.1  pooka 
    436  1.1  pooka 	STDCALL(ukfs, rump_sys___lstat30(filename, file_stat, &rv));
    437  1.1  pooka }
    438  1.1  pooka 
    439  1.1  pooka int
    440  1.1  pooka ukfs_chmod(struct ukfs *ukfs, const char *filename, mode_t mode)
    441  1.1  pooka {
    442  1.1  pooka 
    443  1.1  pooka 	STDCALL(ukfs, rump_sys_chmod(filename, mode, &rv));
    444  1.1  pooka }
    445  1.1  pooka 
    446  1.1  pooka int
    447  1.1  pooka ukfs_lchmod(struct ukfs *ukfs, const char *filename, mode_t mode)
    448  1.1  pooka {
    449  1.1  pooka 
    450  1.1  pooka 	STDCALL(ukfs, rump_sys_lchmod(filename, mode, &rv));
    451  1.1  pooka }
    452  1.1  pooka 
    453  1.1  pooka int
    454  1.1  pooka ukfs_chown(struct ukfs *ukfs, const char *filename, uid_t uid, gid_t gid)
    455  1.1  pooka {
    456  1.1  pooka 
    457  1.1  pooka 	STDCALL(ukfs, rump_sys_chown(filename, uid, gid, &rv));
    458  1.1  pooka }
    459  1.1  pooka 
    460  1.1  pooka int
    461  1.1  pooka ukfs_lchown(struct ukfs *ukfs, const char *filename, uid_t uid, gid_t gid)
    462  1.1  pooka {
    463  1.1  pooka 
    464  1.1  pooka 	STDCALL(ukfs, rump_sys_lchown(filename, uid, gid, &rv));
    465  1.1  pooka }
    466  1.1  pooka 
    467  1.1  pooka int
    468  1.1  pooka ukfs_chflags(struct ukfs *ukfs, const char *filename, u_long flags)
    469  1.1  pooka {
    470  1.1  pooka 
    471  1.1  pooka 	STDCALL(ukfs, rump_sys_chflags(filename, flags, &rv));
    472  1.1  pooka }
    473  1.1  pooka 
    474  1.1  pooka int
    475  1.1  pooka ukfs_lchflags(struct ukfs *ukfs, const char *filename, u_long flags)
    476  1.1  pooka {
    477  1.1  pooka 
    478  1.1  pooka 	STDCALL(ukfs, rump_sys_lchflags(filename, flags, &rv));
    479  1.1  pooka }
    480  1.1  pooka 
    481  1.1  pooka int
    482  1.1  pooka ukfs_utimes(struct ukfs *ukfs, const char *filename, const struct timeval *tptr)
    483  1.1  pooka {
    484  1.1  pooka 
    485  1.1  pooka 	STDCALL(ukfs, rump_sys_utimes(filename, tptr, &rv));
    486  1.1  pooka }
    487  1.1  pooka 
    488  1.1  pooka int
    489  1.1  pooka ukfs_lutimes(struct ukfs *ukfs, const char *filename,
    490  1.1  pooka 	      const struct timeval *tptr)
    491  1.1  pooka {
    492  1.1  pooka 
    493  1.1  pooka 	STDCALL(ukfs, rump_sys_lutimes(filename, tptr, &rv));
    494  1.1  pooka }
    495  1.1  pooka 
    496  1.1  pooka int
    497  1.1  pooka ukfs_util_builddirs(struct ukfs *ukfs, const char *pathname, mode_t mode)
    498  1.1  pooka {
    499  1.1  pooka 	char *f1, *f2;
    500  1.1  pooka 	int rv;
    501  1.1  pooka 	mode_t mask;
    502  1.1  pooka 	bool end;
    503  1.1  pooka 
    504  1.1  pooka 	/*ukfs_umask((mask = ukfs_umask(0)));*/
    505  1.1  pooka 	umask((mask = umask(0)));
    506  1.1  pooka 
    507  1.1  pooka 	f1 = f2 = strdup(pathname);
    508  1.1  pooka 	if (f1 == NULL) {
    509  1.1  pooka 		errno = ENOMEM;
    510  1.1  pooka 		return -1;
    511  1.1  pooka 	}
    512  1.1  pooka 
    513  1.1  pooka 	end = false;
    514  1.1  pooka 	for (;;) {
    515  1.1  pooka 		/* find next component */
    516  1.1  pooka 		f2 += strspn(f2, "/");
    517  1.1  pooka 		f2 += strcspn(f2, "/");
    518  1.1  pooka 		if (*f2 == '\0')
    519  1.1  pooka 			end = true;
    520  1.1  pooka 		else
    521  1.1  pooka 			*f2 = '\0';
    522  1.1  pooka 
    523  1.1  pooka 		rv = ukfs_mkdir(ukfs, f1, mode & ~mask);
    524  1.1  pooka 		if (errno == EEXIST)
    525  1.1  pooka 			rv = 0;
    526  1.1  pooka 
    527  1.1  pooka 		if (rv == -1 || *f2 != '\0' || end)
    528  1.1  pooka 			break;
    529  1.1  pooka 
    530  1.1  pooka 		*f2 = '/';
    531  1.1  pooka 	}
    532  1.1  pooka 
    533  1.1  pooka 	free(f1);
    534  1.1  pooka 
    535  1.1  pooka 	return rv;
    536  1.1  pooka }
    537