[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH v3 07/23] lib/vfscore: remove obvious c++isms and irrelevant code
Some c++isms are keep because bigger pieces needed to be redone around them. Some code is just disabled with #if 0, as we will make use of it later Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx> Reviewed-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx> --- lib/vfscore/fops.c | 91 +----- lib/vfscore/include/vfscore/dentry.h | 16 - lib/vfscore/include/vfscore/mount.h | 26 -- lib/vfscore/include/vfscore/prex.h | 6 - lib/vfscore/include/vfscore/uio.h | 26 -- lib/vfscore/include/vfscore/vnode.h | 4 - lib/vfscore/lookup.c | 51 ++- lib/vfscore/main.c | 469 +++------------------------ lib/vfscore/mount.c | 47 +-- lib/vfscore/syscalls.c | 118 ++++--- lib/vfscore/task.c | 17 - lib/vfscore/vfs.h | 23 -- lib/vfscore/vnode.c | 3 +- 13 files changed, 155 insertions(+), 742 deletions(-) diff --git a/lib/vfscore/fops.c b/lib/vfscore/fops.c index a94ca452..f1c161e7 100644 --- a/lib/vfscore/fops.c +++ b/lib/vfscore/fops.c @@ -42,14 +42,8 @@ #include <osv/mmu.hh> #include <osv/pagecache.hh> -vfs_file::vfs_file(unsigned flags) - : file(flags, DTYPE_VNODE) +int vfs_close(struct vfscore_file *fp) { -} - -int vfs_file::close() -{ - auto fp = this; struct vnode *vp = fp->f_dentry->d_vnode; int error; @@ -60,13 +54,14 @@ int vfs_file::close() if (error) return error; - fp->f_dentry.reset(); + /* Dentry stays forever in the dentry cache. Unless the + * file/directory it refers to gets deleted/renamed */ + fp->f_dentry = NULL; return 0; } -int vfs_file::read(struct uio *uio, int flags) +int vfs_read(struct vfscore_file *fp, struct uio *uio, int flags) { - auto fp = this; struct vnode *vp = fp->f_dentry->d_vnode; int error; size_t count; @@ -90,9 +85,8 @@ int vfs_file::read(struct uio *uio, int flags) } -int vfs_file::write(struct uio *uio, int flags) +int vfs_write(struct vfscore_file *fp, struct uio *uio, int flags) { - auto fp = this; struct vnode *vp = fp->f_dentry->d_vnode; int ioflags = 0; int error; @@ -122,9 +116,8 @@ int vfs_file::write(struct uio *uio, int flags) return error; } -int vfs_file::ioctl(u_long com, void *data) +int vfs_ioctl(struct vfscore_file *fp, u_long com, void *data) { - auto fp = this; struct vnode *vp = fp->f_dentry->d_vnode; int error; @@ -135,9 +128,8 @@ int vfs_file::ioctl(u_long com, void *data) return error; } -int vfs_file::stat(struct stat *st) +int vfs_stat(struct vfscore_file *fp, struct stat *st) { - auto fp = this; struct vnode *vp = fp->f_dentry->d_vnode; int error; @@ -147,70 +139,3 @@ int vfs_file::stat(struct stat *st) return error; } - -int vfs_file::poll(int events) -{ - return poll_no_poll(events); -} - -int vfs_file::truncate(off_t len) -{ - // somehow this is handled outside file ops - abort(); -} - -int vfs_file::chmod(mode_t mode) -{ - // somehow this is handled outside file ops - abort(); -} - -bool vfs_file::map_page(uintptr_t off, mmu::hw_ptep<0> ptep, mmu::pt_element<0> pte, bool write, bool shared) -{ - return pagecache::get(this, off, ptep, pte, write, shared); -} - -bool vfs_file::put_page(void *addr, uintptr_t off, mmu::hw_ptep<0> ptep) -{ - return pagecache::release(this, addr, off, ptep); -} - -void vfs_file::sync(off_t start, off_t end) -{ - pagecache::sync(this, start, end); -} - -// Locking: VOP_CACHE will call into the filesystem, and that can trigger an -// eviction that will hold the mmu-side lock that protects the mappings -// Always follow that order. We however can't just get rid of the mmu-side lock, -// because not all invalidations will be synchronous. -int vfs_file::get_arcbuf(void* key, off_t offset) -{ - struct vnode *vp = f_dentry->d_vnode; - - iovec io[1]; - - io[0].iov_base = key; - uio data; - data.uio_iov = io; - data.uio_iovcnt = 1; - data.uio_offset = offset; - data.uio_resid = mmu::page_size; - data.uio_rw = UIO_READ; - - vn_lock(vp); - assert(VOP_CACHE(vp, this, &data) == 0); - vn_unlock(vp); - - return (data.uio_resid != 0) ? -1 : 0; -} - -std::unique_ptr<mmu::file_vma> vfs_file::mmap(addr_range range, unsigned flags, unsigned perm, off_t offset) -{ - auto fp = this; - struct vnode *vp = fp->f_dentry->d_vnode; - if (!vp->v_op->vop_cache || (vp->v_size < (off_t)mmu::page_size)) { - return mmu::default_file_mmap(this, range, flags, perm, offset); - } - return mmu::map_file_mmap(this, range, flags, perm, offset); -} diff --git a/lib/vfscore/include/vfscore/dentry.h b/lib/vfscore/include/vfscore/dentry.h index 2d2eaa1b..9cfe8dac 100644 --- a/lib/vfscore/include/vfscore/dentry.h +++ b/lib/vfscore/include/vfscore/dentry.h @@ -54,20 +54,4 @@ struct dentry { LIST_ENTRY(dentry) d_children_link; }; -#ifdef __cplusplus - -#include <boost/intrusive_ptr.hpp> - -using dentry_ref = boost::intrusive_ptr<dentry>; - -extern "C" { - void dref(struct dentry* dp); - void drele(struct dentry* dp); -}; - -inline void intrusive_ptr_add_ref(dentry* dp) { dref(dp); } -inline void intrusive_ptr_release(dentry* dp) { drele(dp); } - -#endif - #endif /* _OSV_DENTRY_H */ diff --git a/lib/vfscore/include/vfscore/mount.h b/lib/vfscore/include/vfscore/mount.h index 0e78929f..b68d3c98 100644 --- a/lib/vfscore/include/vfscore/mount.h +++ b/lib/vfscore/include/vfscore/mount.h @@ -37,8 +37,6 @@ #include <osv/vnode.h> #include <bsd/sys/sys/queue.h> -__BEGIN_DECLS - #ifdef _KERNEL /* @@ -144,28 +142,4 @@ void vfs_unbusy(struct mount *mp); void release_mp_dentries(struct mount *mp); -#endif - -__END_DECLS - -#ifdef __cplusplus - -#include <vector> -#include <string> - -namespace osv { - -struct mount_desc { - std::string special; - std::string path; - std::string type; - std::string options; -}; - -std::vector<mount_desc> current_mounts(); - -} - -#endif - #endif /* !_SYS_MOUNT_H_ */ diff --git a/lib/vfscore/include/vfscore/prex.h b/lib/vfscore/include/vfscore/prex.h index 7b053319..6cbe3130 100644 --- a/lib/vfscore/include/vfscore/prex.h +++ b/lib/vfscore/include/vfscore/prex.h @@ -40,10 +40,6 @@ #include <unistd.h> #include <osv/fcntl.h> -__BEGIN_DECLS - -#define __packed __attribute__((__packed__)) - #define BSIZE 512 /* size of secondary block (bytes) */ #define DO_RDWR 0x2 @@ -57,6 +53,4 @@ size_t strlcpy(char *dst, const char *src, size_t siz); void sys_panic(const char *); -__END_DECLS - #endif /* _OSV_PREX_H */ diff --git a/lib/vfscore/include/vfscore/uio.h b/lib/vfscore/include/vfscore/uio.h index 696b01cf..d7f7fce9 100644 --- a/lib/vfscore/include/vfscore/uio.h +++ b/lib/vfscore/include/vfscore/uio.h @@ -38,8 +38,6 @@ #include <sys/uio.h> #include <limits.h> -__BEGIN_DECLS - enum uio_rw { UIO_READ, UIO_WRITE }; /* @@ -62,28 +60,4 @@ struct uio { int uiomove(void *cp, int n, struct uio *uio); -__END_DECLS - -#ifdef __cplusplus - -template <typename F> -static inline void linearize_uio_write(struct uio *uio, int ioflag, F f) -{ - while (uio->uio_resid > 0) { - struct iovec *iov = uio->uio_iov; - - if (iov->iov_len) { - f(reinterpret_cast<const char *>(iov->iov_base), - iov->iov_len); - } - - uio->uio_iov++; - uio->uio_iovcnt--; - uio->uio_resid -= iov->iov_len; - uio->uio_offset += iov->iov_len; - } -} - -#endif - #endif /* !_UIO_H_ */ diff --git a/lib/vfscore/include/vfscore/vnode.h b/lib/vfscore/include/vfscore/vnode.h index 4874f1b9..d30a9411 100644 --- a/lib/vfscore/include/vfscore/vnode.h +++ b/lib/vfscore/include/vfscore/vnode.h @@ -43,8 +43,6 @@ #include "file.h" #include "dirent.h" -__BEGIN_DECLS - struct vfsops; struct vnops; struct vnode; @@ -242,8 +240,6 @@ static inline void vnode_pager_setsize(struct vnode *vp, off_t size) vp->v_size = size; } -__END_DECLS - #endif #endif /* !_SYS_VNODE_H_ */ diff --git a/lib/vfscore/lookup.c b/lib/vfscore/lookup.c index 0aa5ca3b..f7a38c4f 100644 --- a/lib/vfscore/lookup.c +++ b/lib/vfscore/lookup.c @@ -63,33 +63,31 @@ read_link(struct vnode *vp, char *buf, size_t bufsz, ssize_t *sz) int namei_follow_link(struct dentry *dp, char *node, char *name, char *fp, size_t mountpoint_len) { - std::unique_ptr<char []> link (new char[PATH_MAX]); - std::unique_ptr<char []> t (new char[PATH_MAX]); - char *lp; + char link[PATH_MAX]; + char t[PATH_MAX]; int error; ssize_t sz; char *p; int c; - lp = link.get(); - error = read_link(dp->d_vnode, lp, PATH_MAX, &sz); + error = read_link(dp->d_vnode, link, PATH_MAX, &sz); if (error != 0) { return (error); } - lp[sz] = 0; + link[sz] = 0; p = fp + mountpoint_len + strlen(node); c = strlen(node) - strlen(name) - 1; node[c] = 0; - if (lp[0] == '/') { - strlcat(lp, p, PATH_MAX); - strlcpy(fp, lp, PATH_MAX); + if (link[0] == '/') { + strlcat(link, p, PATH_MAX); + strlcpy(fp, link, PATH_MAX); } else { - strlcpy(t.get(), p, PATH_MAX); + strlcpy(t, p, PATH_MAX); strlcpy(node, fp, mountpoint_len + c + 1); - path_conv(node, lp, fp); - strlcat(fp, t.get(), PATH_MAX); + path_conv(node, link, fp); + strlcat(fp, t, PATH_MAX); } node[0] = 0; name[0] = 0; @@ -107,8 +105,7 @@ namei(const char *path, struct dentry **dpp) char *p; char node[PATH_MAX]; char name[PATH_MAX]; - std::unique_ptr<char []> fp (new char [PATH_MAX]); - std::unique_ptr<char []> t (new char [PATH_MAX]); + char fp[PATH_MAX]; struct mount *mp; struct dentry *dp, *ddp; struct vnode *dvp, *vp; @@ -119,7 +116,7 @@ namei(const char *path, struct dentry **dpp) DPRINTF(VFSDB_VNODE, ("namei: path=%s\n", path)); links_followed = 0; - strlcpy(fp.get(), path, PATH_MAX); + strlcpy(fp, path, PATH_MAX); do { need_continue = false; @@ -127,10 +124,10 @@ namei(const char *path, struct dentry **dpp) * Convert a full path name to its mount point and * the local node in the file system. */ - if (vfs_findroot(fp.get(), &mp, &p)) { + if (vfs_findroot(fp, &mp, &p)) { return ENOTDIR; } - int mountpoint_len = p - fp.get() - 1; + int mountpoint_len = p - fp - 1; strlcpy(node, "/", sizeof(node)); strlcat(node, p, sizeof(node)); dp = dentry_lookup(mp, node); @@ -203,7 +200,7 @@ namei(const char *path, struct dentry **dpp) ddp = dp; if (dp->d_vnode->v_type == VLNK) { - error = namei_follow_link(dp, node, name, fp.get(), mountpoint_len); + error = namei_follow_link(dp, node, name, fp, mountpoint_len); if (error) { drele(dp); return (error); @@ -211,7 +208,7 @@ namei(const char *path, struct dentry **dpp) drele(dp); - p = fp.get(); + p = fp; dp = nullptr; ddp = nullptr; vp = nullptr; @@ -254,7 +251,7 @@ namei_last_nofollow(char *path, struct dentry *ddp, struct dentry **dpp) struct dentry *dp; struct vnode *dvp; struct vnode *vp; - std::unique_ptr<char []> node (new char[PATH_MAX]); + char node[PATH_MAX]; dvp = nullptr; @@ -273,26 +270,26 @@ namei_last_nofollow(char *path, struct dentry *ddp, struct dentry **dpp) return (ENOTDIR); } - strlcpy(node.get(), "/", PATH_MAX); - strlcat(node.get(), p, PATH_MAX); + strlcpy(node, "/", PATH_MAX); + strlcat(node, p, PATH_MAX); // We want to treat things like /tmp/ the same as /tmp. Best way to do that // is to ignore the last character, except when we're stating the root. - auto l = strlen(node.get()) - 1; - if (l && node.get()[l] == '/') { - node.get()[l] = '\0'; + int l = strlen(node) - 1; + if (l && node[l] == '/') { + node[l] = '\0'; } dvp = ddp->d_vnode; vn_lock(dvp); - dp = dentry_lookup(mp, node.get()); + dp = dentry_lookup(mp, node); if (dp == nullptr) { error = VOP_LOOKUP(dvp, name, &vp); if (error != 0) { goto out; } - dp = dentry_alloc(ddp, vp, node.get()); + dp = dentry_alloc(ddp, vp, node); vput(vp); if (dp == nullptr) { diff --git a/lib/vfscore/main.c b/lib/vfscore/main.c index e3004597..74876dc1 100644 --- a/lib/vfscore/main.c +++ b/lib/vfscore/main.c @@ -77,18 +77,16 @@ #include <api/utime.h> #include <chrono> -using namespace std; - #ifdef DEBUG_VFS int vfs_debug = VFSDB_FLAGS; #endif -std::atomic<mode_t> global_umask{S_IWGRP | S_IWOTH}; +static mode_t global_umask = S_IWGRP | S_IWOTH; static inline mode_t apply_umask(mode_t mode) { - return mode & ~global_umask.load(std::memory_order_relaxed); + return mode & ~ukarch_load_n(&global_umask); } TRACEPOINT(trace_vfs_open, "\"%s\" 0x%x 0%0o", const char*, int, mode_t); @@ -97,7 +95,6 @@ TRACEPOINT(trace_vfs_open_err, "%d", int); struct task *main_task; /* we only have a single process */ -extern "C" int open(const char *pathname, int flags, ...) { mode_t mode = 0; @@ -178,8 +175,7 @@ int openat(int dirfd, const char *pathname, int flags, ...) struct vnode *vp = fp->f_dentry->d_vnode; vn_lock(vp); - std::unique_ptr<char []> up (new char[PATH_MAX]); - char *p = up.get(); + char p[PATH_MAX]; /* build absolute path */ strlcpy(p, fp->f_dentry->d_mount->m_path, PATH_MAX); @@ -196,26 +192,6 @@ int openat(int dirfd, const char *pathname, int flags, ...) } LFS64(openat); -// open() has an optional third argument, "mode", which is only needed in -// some cases (when the O_CREAT mode is used). As a safety feature, recent -// versions of Glibc add a feature where open() with two arguments is replaced -// by a call to __open_2(), which verifies it isn't called with O_CREATE. -extern "C" int __open_2(const char *pathname, int flags) -{ - assert(!(flags & O_CREAT)); - return open(pathname, flags, 0); -} - -extern "C" int __open64_2(const char *file, int flags) -{ - if (flags & O_CREAT) { - errno = EINVAL; - return -1; - } - - return open64(file, flags); -} - int creat(const char *pathname, mode_t mode) { return open(pathname, O_CREAT|O_WRONLY|O_TRUNC, mode); @@ -249,7 +225,6 @@ TRACEPOINT(trace_vfs_mknod_ret, ""); TRACEPOINT(trace_vfs_mknod_err, "%d", int); -extern "C" int __xmknod(int ver, const char *pathname, mode_t mode, dev_t *dev) { assert(ver == 0); // On x86-64 Linux, _MKNOD_VER_LINUX is 0. @@ -543,7 +518,6 @@ TRACEPOINT(trace_vfs_fstat, "%d %p", int, struct stat*); TRACEPOINT(trace_vfs_fstat_ret, ""); TRACEPOINT(trace_vfs_fstat_err, "%d", int); -extern "C" int __fxstat(int ver, int fd, struct stat *st) { struct file *fp; @@ -571,7 +545,6 @@ int __fxstat(int ver, int fd, struct stat *st) LFS64(__fxstat); -extern "C" int fstat(int fd, struct stat *st) { return __fxstat(1, fd, st); @@ -579,7 +552,6 @@ int fstat(int fd, struct stat *st) LFS64(fstat); -extern "C" int __fxstatat(int ver, int dirfd, const char *pathname, struct stat *st, int flags) { @@ -606,8 +578,7 @@ int __fxstatat(int ver, int dirfd, const char *pathname, struct stat *st, struct vnode *vp = fp->f_dentry->d_vnode; vn_lock(vp); - std::unique_ptr<char []> up (new char[PATH_MAX]); - char *p = up.get(); + char p[PATH_MAX]; /* build absolute path */ strlcpy(p, fp->f_dentry->d_mount->m_path, PATH_MAX); strlcat(p, fp->f_dentry->d_path, PATH_MAX); @@ -624,7 +595,6 @@ int __fxstatat(int ver, int dirfd, const char *pathname, struct stat *st, LFS64(__fxstatat); -extern "C" int fstatat(int dirfd, const char *path, struct stat *st, int flags) { return __fxstatat(1, dirfd, path, st, flags); @@ -632,7 +602,7 @@ int fstatat(int dirfd, const char *path, struct stat *st, int flags) LFS64(fstatat); -extern "C" int flock(int fd, int operation) +int flock(int fd, int operation) { if (!fileref_from_fd(fd)) { return libc_error(EBADF); @@ -663,14 +633,14 @@ struct __dirstream DIR *opendir(const char *path) { - DIR *dir = new DIR; + DIR *dir = malloc(sizeof(*dir)); if (!dir) - return libc_error_ptr<DIR>(ENOMEM); + return ERR2PTR(-ENOMEM); dir->fd = open(path, O_RDONLY); if (dir->fd < 0) { - delete dir; + free(dir); return nullptr; } return dir; @@ -687,7 +657,11 @@ DIR *fdopendir(int fd) errno = ENOTDIR; return nullptr; } - dir = new DIR; + dir = malloc(sizeof(*dir)); + if (!dir) { + errno = ENOMEM; + return NULL; + } dir->fd = fd; return dir; @@ -705,7 +679,7 @@ int dirfd(DIR *dirp) int closedir(DIR *dir) { close(dir->fd); - delete dir; + free(dir); return 0; } @@ -716,7 +690,7 @@ struct dirent *readdir(DIR *dir) ret = readdir_r(dir, &entry, &result); if (ret) - return libc_error_ptr<struct dirent>(ret); + return ERR2PTR(-ret); errno = 0; return result; @@ -753,18 +727,18 @@ int readdir_r(DIR *dir, struct dirent *entry, struct dirent **result) // FIXME: in 64bit dirent64 and dirent are identical, so it's safe to alias #undef readdir64_r -extern "C" int readdir64_r(DIR *dir, struct dirent64 *entry, +int readdir64_r(DIR *dir, struct dirent64 *entry, struct dirent64 **result) __attribute__((alias("readdir_r"))); #undef readdir64 -extern "C" struct dirent *readdir64(DIR *dir) __attribute__((alias("readdir"))); +struct dirent *readdir64(DIR *dir) __attribute__((alias("readdir"))); void rewinddir(DIR *dirp) { struct file *fp; - auto error = fget(dirp->fd, &fp); + int error = fget(dirp->fd, &fp); if (error) { // POSIX specifies that what rewinddir() does in the case of error // is undefined... @@ -936,23 +910,21 @@ TRACEPOINT(trace_vfs_chdir, "\"%s\"", const char*); TRACEPOINT(trace_vfs_chdir_ret, ""); TRACEPOINT(trace_vfs_chdir_err, "%d", int); -static int replace_cwd(struct task *t, struct file *new_cwdfp, - std::function<int (void)> chdir_func) +static int +__do_fchdir(struct vfscore_file *fp, struct task *t) { struct file *old = nullptr; - if (!t) { - return 0; - } + UK_ASSERT(t); if (t->t_cwdfp) { old = t->t_cwdfp; } /* Do the actual chdir operation here */ - int error = chdir_func(); + int error = sys_fchdir(fp, t->t_cwd); - t->t_cwdfp = new_cwdfp; + t->t_cwdfp = fp; if (old) { fdrop(old); } @@ -981,7 +953,11 @@ int chdir(const char *pathname) goto out_errno; } - replace_cwd(t, fp, [&]() { strlcpy(t->t_cwd, path, sizeof(t->t_cwd)); return 0; }); + error = __do_fchdir(fp, t); + if (error) { + fdrop(fp); + goto out_errno; + } trace_vfs_chdir_ret(); return 0; @@ -1006,7 +982,7 @@ int fchdir(int fd) if (error) goto out_errno; - error = replace_cwd(t, fp, [&]() { return sys_fchdir(fp, t->t_cwd); }); + error = __do_fchdir(fp, t); if (error) { fdrop(fp); goto out_errno; @@ -1114,7 +1090,6 @@ TRACEPOINT(trace_vfs_stat, "\"%s\" %p", const char*, struct stat*); TRACEPOINT(trace_vfs_stat_ret, ""); TRACEPOINT(trace_vfs_stat_err, "%d", int); -extern "C" int __xstat(int ver, const char *pathname, struct stat *st) { struct task *t = main_task; @@ -1151,7 +1126,6 @@ LFS64(stat); TRACEPOINT(trace_vfs_lstat, "pathname=%s, stat=%p", const char*, struct stat*); TRACEPOINT(trace_vfs_lstat_ret, ""); TRACEPOINT(trace_vfs_lstat_err, "errno=%d", int); -extern "C" int __lxstat(int ver, const char *pathname, struct stat *st) { struct task *t = main_task; @@ -1191,7 +1165,6 @@ TRACEPOINT(trace_vfs_statfs, "\"%s\" %p", const char*, struct statfs*); TRACEPOINT(trace_vfs_statfs_ret, ""); TRACEPOINT(trace_vfs_statfs_err, "%d", int); -extern "C" int __statfs(const char *pathname, struct statfs *buf) { trace_vfs_statfs(pathname, buf); @@ -1221,7 +1194,6 @@ TRACEPOINT(trace_vfs_fstatfs, "\"%s\" %p", int, struct statfs*); TRACEPOINT(trace_vfs_fstatfs_ret, ""); TRACEPOINT(trace_vfs_fstatfs_err, "%d", int); -extern "C" int __fstatfs(int fd, struct statfs *buf) { struct file *fp; @@ -1424,11 +1396,11 @@ int dup2(int oldfd, int newfd) */ #define SETFL (O_APPEND | O_ASYNC | O_DIRECT | O_NOATIME | O_NONBLOCK) +#if 0 TRACEPOINT(trace_vfs_fcntl, "%d %d 0x%x", int, int, int); TRACEPOINT(trace_vfs_fcntl_ret, "\"%s\"", int); TRACEPOINT(trace_vfs_fcntl_err, "%d", int); -extern "C" int fcntl(int fd, int cmd, int arg) { struct file *fp; @@ -1509,6 +1481,7 @@ int fcntl(int fd, int cmd, int arg) errno = error; return -1; } +#endif TRACEPOINT(trace_vfs_access, "\"%s\" 0%0o", const char*, int); TRACEPOINT(trace_vfs_access_ret, ""); @@ -1564,8 +1537,7 @@ int faccessat(int dirfd, const char *pathname, int mode, int flags) struct vnode *vp = fp->f_dentry->d_vnode; vn_lock(vp); - std::unique_ptr<char []> up (new char[PATH_MAX]); - char *p = up.get(); + char p[PATH_MAX]; /* build absolute path */ strlcpy(p, fp->f_dentry->d_mount->m_path, PATH_MAX); @@ -1581,7 +1553,6 @@ int faccessat(int dirfd, const char *pathname, int mode, int flags) return error; } -extern "C" int euidaccess(const char *pathname, int mode) { return access(pathname, mode); @@ -1590,54 +1561,6 @@ int euidaccess(const char *pathname, int mode) weak_alias(euidaccess,eaccess); #if 0 -static int -fs_pipe(struct task *t, struct msg *msg) -{ -#ifdef CONFIG_FIFOFS - char path[PATH_MAX]; - file_t rfp, wfp; - int error, rfd, wfd; - - DPRINTF(VFSDB_CORE, ("fs_pipe\n")); - - if ((rfd = task_newfd(t)) == -1) - return EMFILE; - t->t_ofile[rfd] = (file_t)1; /* temp */ - - if ((wfd = task_newfd(t)) == -1) { - t->t_ofile[rfd] = nullptr; - return EMFILE; - } - sprintf(path, "/mnt/fifo/pipe-%x-%d", (u_int)t->t_taskid, rfd); - - if ((error = sys_mknod(path, S_IFIFO)) != 0) - goto out; - if ((error = sys_open(path, O_RDONLY | O_NONBLOCK, 0, &rfp)) != 0) { - goto out; - } - if ((error = sys_open(path, O_WRONLY | O_NONBLOCK, 0, &wfp)) != 0) { - goto out; - } - t->t_ofile[rfd] = rfp; - t->t_ofile[wfd] = wfp; - t->t_nopens += 2; - msg->data[0] = rfd; - msg->data[1] = wfd; - return 0; - out: - t->t_ofile[rfd] = nullptr; - t->t_ofile[wfd] = nullptr; - return error; -#else - return ENOSYS; -#endif -} -#endif - -TRACEPOINT(trace_vfs_isatty, "%d", int); -TRACEPOINT(trace_vfs_isatty_ret, "%d", int); -TRACEPOINT(trace_vfs_isatty_err, "%d", int); - /* * Return if specified file is a tty */ @@ -1663,6 +1586,7 @@ int isatty(int fd) trace_vfs_isatty_ret(istty); return istty; } +#endif TRACEPOINT(trace_vfs_truncate, "\"%s\" 0x%x", const char*, off_t); TRACEPOINT(trace_vfs_truncate_ret, ""); @@ -1784,15 +1708,7 @@ int fallocate(int fd, int mode, loff_t offset, loff_t len) LFS64(fallocate); -TRACEPOINT(trace_vfs_utimes, "\"%s\"", const char*); -TRACEPOINT(trace_vfs_utimes_ret, ""); -TRACEPOINT(trace_vfs_utimes_err, "%d", int); - -int futimes(int fd, const struct timeval times[2]) -{ - return futimesat(fd, nullptr, times); -} - +#if 0 int futimesat(int dirfd, const char *pathname, const struct timeval times[2]) { struct stat st; @@ -1850,12 +1766,12 @@ TRACEPOINT(trace_vfs_utimensat, "\"%s\"", const char*); TRACEPOINT(trace_vfs_utimensat_ret, ""); TRACEPOINT(trace_vfs_utimensat_err, "%d", int); -extern "C" int utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags) { trace_vfs_utimensat(pathname); auto error = sys_utimensat(dirfd, pathname, times, flags); + if (error) { trace_vfs_utimensat_err(error); errno = error; @@ -1870,12 +1786,11 @@ TRACEPOINT(trace_vfs_futimens, "%d", int); TRACEPOINT(trace_vfs_futimens_ret, ""); TRACEPOINT(trace_vfs_futimens_err, "%d", int); -extern "C" int futimens(int fd, const struct timespec times[2]) { trace_vfs_futimens(fd); - auto error = sys_futimens(fd, times); + int error = sys_futimens(fd, times); if (error) { trace_vfs_futimens_err(error); errno = error; @@ -1910,19 +1825,16 @@ static int do_utimes(const char *pathname, const struct timeval times[2], int fl return 0; } -extern "C" int utimes(const char *pathname, const struct timeval times[2]) { return do_utimes(pathname, times, 0); } -extern "C" int lutimes(const char *pathname, const struct timeval times[2]) { return do_utimes(pathname, times, AT_SYMLINK_NOFOLLOW); } -extern "C" int utime(const char *pathname, const struct utimbuf *t) { using namespace std::chrono; @@ -1941,6 +1853,7 @@ int utime(const char *pathname, const struct utimbuf *t) return utimes(pathname, times); } +#endif TRACEPOINT(trace_vfs_chmod, "\"%s\" 0%0o", const char*, mode_t); TRACEPOINT(trace_vfs_chmod_ret, ""); @@ -1973,7 +1886,7 @@ TRACEPOINT(trace_vfs_fchmod_ret, ""); int fchmod(int fd, mode_t mode) { trace_vfs_fchmod(fd, mode); - auto error = sys_fchmod(fd, mode & ALLPERMS); + int error = sys_fchmod(fd, mode & ALLPERMS); trace_vfs_fchmod_ret(); if (error) { errno = error; @@ -2007,6 +1920,7 @@ int lchown(const char *path, uid_t owner, gid_t group) } +#if 0 ssize_t sendfile(int out_fd, int in_fd, off_t *_offset, size_t count) { struct file *in_fp; @@ -2070,7 +1984,7 @@ ssize_t sendfile(int out_fd, int in_fd, off_t *_offset, size_t count) return -1; } - auto ret = write(out_fd, src + (offset % PAGESIZE), count); + int ret = write(out_fd, src + (offset % PAGESIZE), count); if (ret < 0) { return libc_error(errno); @@ -2087,12 +2001,13 @@ ssize_t sendfile(int out_fd, int in_fd, off_t *_offset, size_t count) #undef sendfile64 LFS64(sendfile); +#endif NO_SYS(int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags)); mode_t umask(mode_t newmask) { - return global_umask.exchange(newmask, std::memory_order_relaxed); + return ukarch_exchange_n(&global_umask, newmask); } int @@ -2107,303 +2022,3 @@ int chroot(const char *path) errno = ENOSYS; return -1; } - -// unpack_bootfs() unpacks a collection of files stored as part of the OSv -// executable (in memory location "bootfs_start") into the file system, -// normally the in-memory filesystem ramfs. -// The files are packed in the executable in an ad-hoc format defined here. -// Code in scripts/mkbootfs.py packs files into this format. -#define BOOTFS_PATH_MAX 111 -enum class bootfs_file_type : char { other = 0, symlink = 1 }; -struct bootfs_metadata { - uint64_t size; - uint64_t offset; - // The file's type. Can be "symlink" or "other". A directory is an "other" - // file with its name ending with a "/" (and no content). - bootfs_file_type type; - // name must end with a null. For symlink files, the content must end - // with a null as well. - char name[BOOTFS_PATH_MAX]; -}; - -extern char bootfs_start; - -int ramfs_set_file_data(struct vnode *vp, const void *data, size_t size); -void unpack_bootfs(void) -{ - struct bootfs_metadata *md = (struct bootfs_metadata *)&bootfs_start; - int fd, i; - - for (i = 0; md[i].name[0]; i++) { - int ret; - char *p; - - // mkdir() directories needed for this path name, as necessary - char tmp[BOOTFS_PATH_MAX]; - strlcpy(tmp, md[i].name, BOOTFS_PATH_MAX); - for (p = tmp; *p; ++p) { - if (*p == '/') { - *p = '\0'; - mkdir(tmp, 0666); // silently ignore errors and existing dirs - *p = '/'; - } - } - - if (md[i].type == bootfs_file_type::symlink) { - // This is a symbolic link record. The file's content is the - // target path, and we assume ends with a null. - if (symlink(&bootfs_start + md[i].offset, md[i].name) != 0) { - kprintf("couldn't symlink %s: %d\n", md[i].name, errno); - sys_panic("unpack_bootfs failed"); - } - continue; - } - if (*(p-1) == '/' && md[i].size == 0) { - // This is directory record. Nothing else to do - continue; - } - - fd = creat(md[i].name, 0666); - if (fd < 0) { - kprintf("couldn't create %s: %d\n", - md[i].name, errno); - sys_panic("unpack_bootfs failed"); - } - - struct file *fp; - int error = fget(fd, &fp); - if (error) { - kprintf("couldn't fget %s: %d\n", - md[i].name, error); - sys_panic("unpack_bootfs failed"); - } - - struct vnode *vp = fp->f_dentry->d_vnode; - ret = ramfs_set_file_data(vp, &bootfs_start + md[i].offset, md[i].size); - if (ret) { - kprintf("ramfs_set_file_data failed, ret = %d\n", ret); - sys_panic("unpack_bootfs failed"); - } - - fdrop(fp); - close(fd); - } -} - -void mount_rootfs(void) -{ - int ret; - - ret = sys_mount("", "/", "ramfs", 0, nullptr); - if (ret) - kprintf("failed to mount rootfs, error = %s\n", strerror(ret)); - - if (mkdir("/dev", 0755) < 0) - kprintf("failed to create /dev, error = %s\n", strerror(errno)); - - ret = sys_mount("", "/dev", "devfs", 0, nullptr); - if (ret) - kprintf("failed to mount devfs, error = %s\n", strerror(ret)); -} - -extern "C" -int nmount(struct iovec *iov, unsigned niov, int flags) -{ - struct args { - char* fstype = nullptr; - char* fspath = nullptr; - char* from = nullptr; - }; - static unordered_map<string, char* args::*> argmap { - { "fstype", &args::fstype }, - { "fspath", &args::fspath }, - { "from", &args::from }, - }; - args a; - for (size_t i = 0; i < niov; i += 2) { - std::string s(static_cast<const char*>(iov[i].iov_base)); - if (argmap.count(s)) { - a.*(argmap[s]) = static_cast<char*>(iov[i+1].iov_base); - } - } - return sys_mount(a.from, a.fspath, a.fstype, flags, nullptr); -} - -static void import_extra_zfs_pools(void) -{ - struct stat st; - int ret; - - // The file '/etc/mnttab' is a LibZFS requirement and will not - // exist during cpiod phase. The functionality provided by this - // function isn't needed during that phase, so let's skip it. - if (stat("/etc/mnttab" , &st) != 0) { - return; - } - - // Import extra pools mounting datasets there contained. - // Datasets from osv pool will not be mounted here. - if (access("zpool.so", X_OK) != 0) { - return; - } - vector<string> zpool_args = {"zpool", "import", "-f", "-a" }; - auto ok = osv::run("zpool.so", zpool_args, &ret); - assert(ok); - - if (!ret) { - debug("zfs: extra ZFS pool(s) found.\n"); - } -} - -void pivot_rootfs(const char* path) -{ - int ret = sys_pivot_root(path, "/"); - if (ret) - kprintf("failed to pivot root, error = %s\n", strerror(ret)); - - auto ent = setmntent("/etc/fstab", "r"); - if (!ent) { - return; - } - - struct mntent *m = nullptr; - while ((m = getmntent(ent)) != nullptr) { - if (!strcmp(m->mnt_dir, "/")) { - continue; - } - - if ((m->mnt_opts != nullptr) && strcmp(m->mnt_opts, MNTOPT_DEFAULTS)) { - printf("Warning: opts %s, ignored for fs %s\n", m->mnt_opts, m->mnt_type); - } - - // FIXME: Right now, ignoring mntops. In the future we may have an option parser - ret = sys_mount(m->mnt_fsname, m->mnt_dir, m->mnt_type, 0, nullptr); - if (ret) { - printf("failed to mount %s, error = %s\n", m->mnt_type, strerror(ret)); - } - } - endmntent(ent); -} - -extern "C" void unmount_devfs() -{ - int ret = sys_umount("/dev"); - if (ret) - kprintf("failed to unmount /dev, error = %s\n", strerror(ret)); -} - -extern "C" int mount_rofs_rootfs(bool pivot_root) -{ - int ret; - - if (mkdir("/rofs", 0755) < 0) - kprintf("failed to create /rofs, error = %s\n", strerror(errno)); - - ret = sys_mount("/dev/vblk0.1", "/rofs", "rofs", MNT_RDONLY, 0); - - if (ret) { - kprintf("failed to mount /rofs, error = %s\n", strerror(ret)); - rmdir("/rofs"); - return ret; - } - - if (pivot_root) { - pivot_rootfs("/rofs"); - } - - return 0; -} - -extern "C" void mount_zfs_rootfs(bool pivot_root) -{ - if (mkdir("/zfs", 0755) < 0) - kprintf("failed to create /zfs, error = %s\n", strerror(errno)); - - int ret = sys_mount("/dev/vblk0.1", "/zfs", "zfs", 0, (void *)"osv/zfs"); - - if (ret) - kprintf("failed to mount /zfs, error = %s\n", strerror(ret)); - - if (!pivot_root) { - return; - } - - pivot_rootfs("/zfs"); - - import_extra_zfs_pools(); -} - -extern "C" void unmount_rootfs(void) -{ - int ret; - - sys_umount("/dev"); - - ret = sys_umount("/proc"); - if (ret) { - kprintf("Warning: unmount_rootfs: failed to unmount /proc, " - "error = %s\n", strerror(ret)); - } - - ret = sys_umount2("/", MNT_FORCE); - if (ret) { - kprintf("Warning: unmount_rootfs: failed to unmount /, " - "error = %s\n", strerror(ret)); - } -} - -extern "C" void bio_init(void); -extern "C" void bio_sync(void); - -int vfs_initialized; - -extern "C" -void -vfs_init(void) -{ - const struct vfssw *fs; - - bio_init(); - lookup_init(); - vnode_init(); - task_alloc(&main_task); - - /* - * Initialize each file system. - */ - for (fs = vfssw; fs->vs_name; fs++) { - if (fs->vs_init) { - DPRINTF(VFSDB_CORE, ("VFS: initializing %s\n", - fs->vs_name)); - fs->vs_init(); - } - } - - mount_rootfs(); - unpack_bootfs(); - - // if (open("/dev/console", O_RDWR, 0) != 0) - if (console::open() != 0) - kprintf("failed to open console, error = %d\n", errno); - if (dup(0) != 1) - kprintf("failed to dup console (1)\n"); - if (dup(0) != 2) - kprintf("failed to dup console (2)\n"); - vfs_initialized = 1; -} - -void vfs_exit(void) -{ - /* Free up main_task (stores cwd data) resources */ - replace_cwd(main_task, nullptr, []() { return 0; }); - /* Unmount all file systems */ - unmount_rootfs(); - /* Finish with the bio layer */ - bio_sync(); -} - -void sys_panic(const char *str) -{ - abort("panic: %s", str); -} - diff --git a/lib/vfscore/mount.c b/lib/vfscore/mount.c index 76e2e70c..10c27fad 100644 --- a/lib/vfscore/mount.c +++ b/lib/vfscore/mount.c @@ -83,17 +83,6 @@ fs_getfs(const char *name) return fs; } -const char* -fs_getfsname(vfsops* ops) -{ - for (auto fs = vfssw; fs->vs_name; fs++) { - if (fs->vs_op == ops) { - return fs->vs_name; - } - } - abort(); -} - int sys_mount(const char *dev, const char *dir, const char *fsname, int flags, const void *data) { @@ -141,7 +130,8 @@ sys_mount(const char *dev, const char *dir, const char *fsname, int flags, const /* * Create VFS mount entry. */ - if (!(mp = new mount)) { + mp = malloc(sizeof(struct mount)); + if (!mp) { error = ENOMEM; goto err1; } @@ -214,7 +204,7 @@ sys_mount(const char *dev, const char *dir, const char *fsname, int flags, const if (dp_covered) drele(dp_covered); err2: - delete mp; + free(mp); err1: if (device) device_close(device); @@ -281,7 +271,7 @@ found: if (mp->m_dev) device_close(mp->m_dev); - delete mp; + free(mp); out: return error; } @@ -292,6 +282,7 @@ sys_umount(const char *path) return sys_umount2(path, 0); } +#if 0 int sys_pivot_root(const char *new_root, const char *put_old) { @@ -339,6 +330,7 @@ sys_pivot_root(const char *new_root, const char *put_old) } return 0; } +#endif int sys_sync(void) @@ -450,33 +442,6 @@ vfs_einval(void) return EINVAL; } -namespace osv { - -mount_desc to_mount_desc(mount* m) -{ - mount_desc ret; - ret.special = m->m_special; - ret.path = m->m_path; - ret.type = fs_getfsname(m->m_op); - // FIXME: record options - ret.options = ""; - return ret; -} - -std::vector<mount_desc> -current_mounts() -{ - WITH_LOCK(mount_lock) { - std::vector<mount_desc> ret; - for (auto&& mp : mount_list) { - ret.push_back(to_mount_desc(mp)); - } - return ret; - } -} - -} - #ifdef DEBUG_VFS void mount_dump(void) diff --git a/lib/vfscore/syscalls.c b/lib/vfscore/syscalls.c index 29b14220..4e55337f 100644 --- a/lib/vfscore/syscalls.c +++ b/lib/vfscore/syscalls.c @@ -195,17 +195,17 @@ sys_open(char *path, int flags, mode_t mode, struct file **fpp) goto out_vn_unlock; } - try { - fileref f = make_file<vfs_file>(flags); - fp = f.get(); - fhold(fp); - } catch (int err) { - error = err; + fp = calloc(sizeof(struct vfscore_file), 1); + fhold(fp); + if (!fp) { + error = ENOMEM; goto out_vn_unlock; } + fp->f_flags = flags; + // change to std::move once dp is a dentry_ref - fp->f_dentry = dentry_ref(dp, false); - dp = nullptr; + fp->f_dentry = dp; + dp = NULL; error = VOP_OPEN(vp, fp); if (error) { @@ -213,7 +213,7 @@ sys_open(char *path, int flags, mode_t mode, struct file **fpp) // Note direct delete of fp instead of fdrop(fp). fp was never // returned so cannot be in use, and because it wasn't opened // it cannot be close()ed. - delete fp; + free(fp); return error; } vn_unlock(vp); @@ -241,11 +241,14 @@ int sys_read(struct file *fp, const struct iovec *iov, size_t niov, off_t offset, size_t *count) { + int error = 0; + struct iovec *copy_iov; if ((fp->f_flags & FREAD) == 0) return EBADF; size_t bytes = 0; - auto iovp = iov; + const struct iovec *iovp = iov; + for (unsigned i = 0; i < niov; i++) { if (iovp->iov_len > IOSIZE_MAX - bytes) { return EINVAL; @@ -260,16 +263,27 @@ sys_read(struct file *fp, const struct iovec *iov, size_t niov, } struct uio uio; - // Unfortunately, the current implementation of fp->read zeros the - // iov_len fields when it reads from disk, so we have to copy iov. - std::vector<iovec> copy_iov(iov, iov + niov); - uio.uio_iov = copy_iov.data(); + /* TODO: is it necessary to copy iov within Unikraft? + * OSv did this, mentioning this reason: + * + * "Unfortunately, the current implementation of fp->read + * zeros the iov_len fields when it reads from disk, so we + * have to copy iov. " + */ + copy_iov = calloc(sizeof(struct iovec), niov); + if (!copy_iov) + return ENOMEM; + memcpy(copy_iov, iov, sizeof(struct iovec)*niov); + + uio.uio_iov = copy_iov; uio.uio_iovcnt = niov; uio.uio_offset = offset; uio.uio_resid = bytes; uio.uio_rw = UIO_READ; - auto error = fp->read(&uio, (offset == -1) ? 0 : FOF_OFFSET); + error = vfs_read(fp, &uio, (offset == -1) ? 0 : FOF_OFFSET); *count = bytes - uio.uio_resid; + + free(copy_iov); return error; } @@ -277,11 +291,13 @@ int sys_write(struct file *fp, const struct iovec *iov, size_t niov, off_t offset, size_t *count) { + struct iovec *copy_iov; + int error = 0; if ((fp->f_flags & FWRITE) == 0) return EBADF; size_t bytes = 0; - auto iovp = iov; + const struct iovec *iovp = iov; for (unsigned i = 0; i < niov; i++) { if (iovp->iov_len > IOSIZE_MAX - bytes) { return EINVAL; @@ -296,15 +312,24 @@ sys_write(struct file *fp, const struct iovec *iov, size_t niov, } struct uio uio; - // Unfortunately, the current implementation of fp->write zeros the - // iov_len fields when it writes to disk, so we have to copy iov. - std::vector<iovec> copy_iov(iov, iov + niov); - uio.uio_iov = copy_iov.data(); + + /* TODO: same note as in sys_read. Original comment: + * + * "Unfortunately, the current implementation of fp->write zeros the + * iov_len fields when it writes to disk, so we have to copy iov. + */ + /* std::vector<iovec> copy_iov(iov, iov + niov); */ + copy_iov = calloc(sizeof(struct iovec), niov); + if (!copy_iov) + return ENOMEM; + memcpy(copy_iov, iov, sizeof(struct iovec)*niov); + + uio.uio_iov = copy_iov; uio.uio_iovcnt = niov; uio.uio_offset = offset; uio.uio_resid = bytes; uio.uio_rw = UIO_WRITE; - auto error = fp->write(&uio, (offset == -1) ? 0 : FOF_OFFSET); + vfs_write(fp, &uio, (offset == -1) ? 0 : FOF_OFFSET); *count = bytes - uio.uio_resid; return error; } @@ -355,7 +380,7 @@ sys_ioctl(struct file *fp, u_long request, void *buf) if ((fp->f_flags & (FREAD | FWRITE)) == 0) return EBADF; - error = fp->ioctl(request, buf); + error = vfs_ioctl(fp, request, buf); DPRINTF(VFSDB_SYSCALL, ("sys_ioctl: comp error=%d\n", error)); return error; @@ -386,7 +411,7 @@ sys_fstat(struct file *fp, struct stat *st) DPRINTF(VFSDB_SYSCALL, ("sys_fstat: fp=%x\n", fp)); - error = fp->stat(st); + error = vfs_stat(fp, st); return error; } @@ -815,10 +840,8 @@ sys_symlink(const char *oldpath, const char *newpath) { struct task *t = main_task; int error; - std::unique_ptr<char []> up_op (new char[PATH_MAX]); - char *op = up_op.get(); - std::unique_ptr<char []> up_np (new char[PATH_MAX]); - char *np = up_np.get(); + char op[PATH_MAX]; + char np[PATH_MAX]; struct dentry *newdp; struct dentry *newdirdp; char *name; @@ -1032,17 +1055,17 @@ sys_access(char *path, int mode) int sys_stat(char *path, struct stat *st) { + struct dentry *dp; + int error; + DPRINTF(VFSDB_SYSCALL, ("sys_stat: path=%s\n", path)); - try { - dentry_ref dp = namei(path); - if (!dp) { - return ENOENT; - } - return vn_stat(dp->d_vnode, st); - } catch (error e) { - return e.get(); - } + error = namei(path, &dp); + if (error) + return error; + error = vn_stat(dp->d_vnode, st); + drele(dp); + return error; } int sys_lstat(char *path, struct stat *st) @@ -1074,16 +1097,19 @@ int sys_lstat(char *path, struct stat *st) int sys_statfs(char *path, struct statfs *buf) { + struct dentry *dp; + int error; + memset(buf, 0, sizeof(*buf)); - try { - dentry_ref dp = namei(path); - if (!dp) { - return ENOENT; - } - return VFS_STATFS(dp->d_mount, buf); - } catch (error e) { - return e.get(); - } + + error = namei(path, &dp); + if (error) + return error; + + error = VFS_STATFS(dp->d_mount, buf); + drele(dp); + + return error; } int @@ -1212,6 +1238,7 @@ sys_readlink(char *path, char *buf, size_t bufsize, ssize_t *size) return (0); } +#if 0 /* * Check the validity of the members of a struct timeval. */ @@ -1396,6 +1423,7 @@ sys_futimens(int fd, const struct timespec times[2]) auto error = sys_utimensat(AT_FDCWD, pathname.c_str(), times, 0); return error; } +#endif int sys_fallocate(struct file *fp, int mode, loff_t offset, loff_t len) diff --git a/lib/vfscore/task.c b/lib/vfscore/task.c index 2d34f0df..4ceb123b 100644 --- a/lib/vfscore/task.c +++ b/lib/vfscore/task.c @@ -44,23 +44,6 @@ #include <osv/prex.h> #include "vfs.h" -/* - * Allocate new task. - */ -int -task_alloc(struct task **pt) -{ - struct task *t; - - // FIXME: where do we free task ? - if (!(t = new task)) - return ENOMEM; - memset(t, 0, sizeof(struct task)); - strlcpy(t->t_cwd, "/", sizeof(t->t_cwd)); - - *pt = t; - return 0; -} /* * Convert to full path from the cwd of task and path. diff --git a/lib/vfscore/vfs.h b/lib/vfscore/vfs.h index c130517d..cd940979 100644 --- a/lib/vfscore/vfs.h +++ b/lib/vfscore/vfs.h @@ -89,7 +89,6 @@ struct task { extern const struct vfssw vfssw[]; -__BEGIN_DECLS int sys_open(char *path, int flags, mode_t mode, struct file **fp); int sys_read(struct file *fp, const struct iovec *iov, size_t niov, off_t offset, size_t *count); @@ -167,26 +166,4 @@ void vnode_dump(void); void mount_dump(void); #endif -__END_DECLS - -#ifdef __cplusplus - -// Convert a path to a dentry_ref. Returns an empty -// reference if not found (ENOENT) for efficiency, throws -// an error on other errors. -inline dentry_ref namei(char* path) -{ - dentry* dp; - auto err = namei(path, &dp); - if (err == ENOENT) { - return dentry_ref(); - } else if (err) { - throw make_error(err); - } else { - return dentry_ref(dp, false); - } -} - -#endif - #endif /* !_VFS_H */ diff --git a/lib/vfscore/vnode.c b/lib/vfscore/vnode.c index 3412c6fb..f564577f 100644 --- a/lib/vfscore/vnode.c +++ b/lib/vfscore/vnode.c @@ -187,7 +187,8 @@ vget(struct mount *mp, uint64_t ino, struct vnode **vpp) return 1; } - if (!(vp = new vnode())) { + vp = malloc(sizeof(*vp)); + if (!vp) { VNODE_UNLOCK(); return 0; } -- 2.19.2 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |