From: Lawrence S. <ljs...@us...> - 2013-05-14 15:45:38
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via fb653a8a3c230e08de16c5cffabd139317ec830b (commit) from 298d30d5690e14dea483ae343b0d2b5a1aa04b69 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit fb653a8a3c230e08de16c5cffabd139317ec830b Author: Lawrence Sebald <ljs...@us...> Date: Tue May 14 11:44:29 2013 -0400 Add fs_link and fs_symlink now that they're somewhat relevant (with libkosext2fs). Note that this doesn't actually add support to libkosext2fs for these two syscalls just yet. ----------------------------------------------------------------------- Summary of changes: addons/libkosext2fs/fs_ext2.c | 4 ++- include/kos/fs.h | 48 +++++++++++++++++++++++++++-- kernel/fs/fs.c | 63 +++++++++++++++++++++++++++++++++++++- kernel/libc/newlib/newlib_link.c | 7 ++-- 4 files changed, 114 insertions(+), 8 deletions(-) diff --git a/addons/libkosext2fs/fs_ext2.c b/addons/libkosext2fs/fs_ext2.c index a016f52..16b868b 100644 --- a/addons/libkosext2fs/fs_ext2.c +++ b/addons/libkosext2fs/fs_ext2.c @@ -1352,7 +1352,9 @@ static vfs_handler_t vh = { fs_ext2_mkdir, /* mkdir */ fs_ext2_rmdir, /* rmdir */ fs_ext2_fcntl, /* fcntl */ - NULL /* poll */ + NULL, /* poll */ + NULL, /* link */ + NULL /* symlink */ }; static int initted = 0; diff --git a/include/kos/fs.h b/include/kos/fs.h index 833aba7..bbdfd8f 100644 --- a/include/kos/fs.h +++ b/include/kos/fs.h @@ -156,7 +156,8 @@ typedef struct vfs_handler { /** \brief "Memory map" a previously opened file */ void *(*mmap)(void *fd); - /** \brief Perform an I/O completion (async I/O) for a previously opened file */ + /** \brief Perform an I/O completion (async I/O) for a previously opened + file */ int (*complete)(void *fd, ssize_t *rv); /** \brief Get status information on a file on the given VFS */ @@ -168,11 +169,18 @@ typedef struct vfs_handler { /** \brief Remove a directory from the given VFS */ int (*rmdir)(struct vfs_handler *vfs, const char *fn); - /** \brief Manipulate file control flags on the given file. */ + /** \brief Manipulate file control flags on the given file */ int (*fcntl)(void *fd, int cmd, va_list ap); - /** \brief Check if an event is pending on the given file. */ + /** \brief Check if an event is pending on the given file */ short (*poll)(void *fd, short events); + + /** \brief Create a hard link */ + int (*link)(struct vfs_handler *vfs, const char *path1, const char *path2); + + /** \brief Create a symbolic link */ + int (*symlink)(struct vfs_handler *vfs, const char *path1, + const char *path2); } vfs_handler_t; /** \brief The number of distinct file descriptors that can be in use at a @@ -426,6 +434,40 @@ int fs_rmdir(const char *fn); */ int fs_fcntl(file_t fd, int cmd, ...); +/** \brief Create a hard link. + + This function implements the POSIX function link(), which creates a hard + link for an existing file. + + \param path1 An existing file to create a new link to. + \param path2 The pathname of the new link to be created. + \return 0 on success, -1 on failure. + + \note Most filesystems in KallistiOS do not support hard + links. Unlike most other VFS functions, this one + does not set errno to ENOSYS in that case, but + rather to EMLINK to preserve existing the original + behavior in KOS. +*/ +int fs_link(const char *path1, const char *path2); + +/** \brief Create a symbolic link. + + This function implements the POSIX function symlink(), which creates a + symbolic link on the filesystem. Symbolic links are not required to point to + an existing file (per POSIX) and may result in circular links if care is not + taken. For now, symbolic links cannot cross filesystem boundaries in KOS. + + \param path1 The content of the link (i.e, what to point at). + \param path2 The pathname of the new link to be created. + \return 0 on success, -1 on failure. + + \note Most filesystems in KallistiOS do not support + symbolic links. Filesystems that do not support + symlinks will simply set errno to ENOSYS. +*/ +int fs_symlink(const char *path1, const char *path2); + /** \brief Duplicate a file descriptor. This function duplicates the specified file descriptor, returning a new file diff --git a/kernel/fs/fs.c b/kernel/fs/fs.c index d2124d7..9d74b63 100644 --- a/kernel/fs/fs.c +++ b/kernel/fs/fs.c @@ -2,7 +2,7 @@ fs.c Copyright (C) 2000, 2001, 2002, 2003 Dan Potter - Copyright (C) 2012 Lawrence Sebald + Copyright (C) 2012, 2013 Lawrence Sebald */ @@ -651,6 +651,67 @@ int fs_fcntl(file_t fd, int cmd, ...) { return rv; } +int fs_link(const char *path1, const char *path2) { + vfs_handler_t *fh1, *fh2; + char rfn1[PATH_MAX], rfn2[PATH_MAX]; + + if(!realpath(path1, rfn1) || !realpath(path2, rfn2)) + return -1; + + /* Look for handlers */ + fh1 = fs_verify_handler(rfn1); + + if(!fh1) { + errno = ENOENT; + return -1; + } + + fh2 = fs_verify_handler(rfn2); + + if(!fh2) { + errno = ENOENT; + return -1; + } + + if(fh1 != fh2) { + errno = EXDEV; + return -1; + } + + if(fh1->link) { + return fh1->link(fh1, rfn1 + strlen(fh1->nmmgr.pathname), + rfn2 + strlen(fh1->nmmgr.pathname)); + } + else { + errno = EMLINK; + return -1; + } +} + +int fs_symlink(const char *path1, const char *path2) { + vfs_handler_t *vfs; + char rfn[PATH_MAX]; + + if(!realpath(path2, rfn)) + return -1; + + /* Look for the handler */ + vfs = fs_verify_handler(rfn); + + if(!vfs) { + errno = ENOENT; + return -1; + } + + if(vfs->symlink) { + return vfs->symlink(vfs, path1, rfn + strlen(vfs->nmmgr.pathname)); + } + else { + errno = ENOSYS; + return -1; + } +} + /* Initialize FS structures */ int fs_init() { return 0; diff --git a/kernel/libc/newlib/newlib_link.c b/kernel/libc/newlib/newlib_link.c index c63414d..4290f35 100644 --- a/kernel/libc/newlib/newlib_link.c +++ b/kernel/libc/newlib/newlib_link.c @@ -1,14 +1,15 @@ /* KallistiOS ##version## newlib_link.c - Copyright (C)2004 Dan Potter + Copyright (C) 2004 Dan Potter + Copyright (C) 2013 Lawrence Sebald */ +#include <kos/fs.h> #include <sys/reent.h> #include <errno.h> int _link_r(struct _reent * reent, const char * oldf, const char * newf) { - reent->_errno = EMLINK; - return -1; + return fs_link(oldf, newf); } hooks/post-receive -- A pseudo Operating System for the Dreamcast. |