From: quzar <qu...@us...> - 2024-09-23 16:58:04
|
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 d2d7863864bec6707bd8d440fbdaa2b90014ba8a (commit) via 89b29990c8865f09afe9b7724db3a9a91d8666aa (commit) via a58f25d6ade6d4b7567bcadc4c68e05b1dbe5d1b (commit) via 167288f028c5ad7a8bc5fe57472a89eed2f07b21 (commit) via 3a950dcd33ce6bb850bd2ff3378c05db516229a8 (commit) from 63545378b55b22f02d865ba68617095050fe7b5a (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 d2d7863864bec6707bd8d440fbdaa2b90014ba8a Author: Andy Barajas <and...@gm...> Date: Mon Sep 23 09:55:06 2024 -0700 Replace realpath() for a better license. Added fs_normalize_path() (#648) commit 89b29990c8865f09afe9b7724db3a9a91d8666aa Merge: 63545378 a58f25d6 Author: Donald Haase <qu...@ya...> Date: Mon Sep 23 12:53:42 2024 -0400 Merge pull request #725 from pcercuei/pvr-api * pvr: Constify data source pointers Functions that take one data source pointer and one data destination pointer should have their source pointer const, to explicit that the data pointed to is not modified. This in turn allows calling functions to use const pointers. * pvr: Add and use enum pvr_palfmt Instead of using an opaque 'int' type, which gives zero information about the possible values that can be passed, use an enum. This should not break ABI nor API. * pvr: Add and use enum pvr_dma_type Instead of using an opaque 'int' type, which gives zero information about the possible values that can be passed, use an enum. This should not break ABI nor API. --------- Signed-off-by: Paul Cercueil <pa...@cr...> commit a58f25d6ade6d4b7567bcadc4c68e05b1dbe5d1b Author: Paul Cercueil <pa...@cr...> Date: Thu Aug 22 18:21:51 2024 +0200 pvr: Add and use enum pvr_dma_type Instead of using an opaque 'int' type, which gives zero information about the possible values that can be passed, use an enum. This should not break ABI nor API. Signed-off-by: Paul Cercueil <pa...@cr...> commit 167288f028c5ad7a8bc5fe57472a89eed2f07b21 Author: Paul Cercueil <pa...@cr...> Date: Thu Aug 22 18:18:32 2024 +0200 pvr: Add and use enum pvr_palfmt Instead of using an opaque 'int' type, which gives zero information about the possible values that can be passed, use an enum. This should not break ABI nor API. Signed-off-by: Paul Cercueil <pa...@cr...> commit 3a950dcd33ce6bb850bd2ff3378c05db516229a8 Author: Paul Cercueil <pa...@cr...> Date: Thu Aug 22 18:14:39 2024 +0200 pvr: Constify data source pointers Functions that take one data source pointer and one data destination pointer should have their source pointer const, to explicit that the data pointed to is not modified. This in turn allows calling functions to use const pointers. Signed-off-by: Paul Cercueil <pa...@cr...> ----------------------------------------------------------------------- Summary of changes: AUTHORS | 29 --- doc/CHANGELOG.md | 1 + include/kos/fs.h | 17 ++ kernel/arch/dreamcast/hardware/pvr/pvr_dma.c | 13 +- kernel/arch/dreamcast/hardware/pvr/pvr_palette.c | 2 +- kernel/arch/dreamcast/hardware/pvr/pvr_prim.c | 6 +- kernel/arch/dreamcast/hardware/pvr/pvr_texture.c | 8 +- kernel/arch/dreamcast/include/dc/pvr.h | 73 ++++--- kernel/fs/fs.c | 16 +- kernel/fs/fs_utils.c | 78 +++++++ kernel/libc/koslib/realpath.c | 258 +++++++++++------------ 11 files changed, 277 insertions(+), 224 deletions(-) diff --git a/AUTHORS b/AUTHORS index 1fcace82..5f886980 100644 --- a/AUTHORS +++ b/AUTHORS @@ -71,35 +71,6 @@ include/pthread.h: * */ -kernel/libc/koslib/realpath.c: -/* - * Copyright (c) 2003 Constantin S. Svintsoff <ko...@ic...> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The names of the authors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - kernel/arch/dreamcast/kernel/gdb_stub.c: /* This is originally based on an m68k software stub written by Glenn Engel at HP, but has changed quite a bit. diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index dd111ecd..107191f2 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -5,6 +5,7 @@ Platform-specific changes are prefixed with the platform name, otherwise the cha ## KallistiOS version 2.2.0 - Added pvrtex utility by TapamN to utils [DF == Daniel Fairchild] - Added . & .. directories to filesystems that lack it [AB] +- Replaced previous implementation of realpath() to remove license from AUTHORS [AB] ## KallistiOS version 2.1.0 - Cleaned up generated stubs files on a make clean [Lawrence Sebald == LS] diff --git a/include/kos/fs.h b/include/kos/fs.h index 2cc3924d..a892eac7 100644 --- a/include/kos/fs.h +++ b/include/kos/fs.h @@ -735,6 +735,23 @@ ssize_t fs_load(const char *src, void **out_ptr); */ ssize_t fs_path_append(char *dst, const char *src, size_t len); +/** \brief Normalize the specified path. + This function acts mostly like the function realpath() but it only simplifies + a path by resolving . and .. components and removing redundant slashes. It + doesn't check if the path exists or resolve symbolic links. + \param path The path to normalize. + \param resolved The buffer to store resolved normalized path. It has + to be PATH_MAX bytes in size. + + \return A pointer to the normalized path on success, + or NULL on failure, in which case the path which + caused trouble is left in resolved. + \par Error Conditions: + \em EINVAL - path or resolved is a NULL pointer \n + \em ENAMETOOLONG - the resulting path would be longer than PATH_MAX bytes \n +*/ +char *fs_normalize_path(const char *__RESTRICT path, char *__RESTRICT resolved); + /** \brief Initialize the virtual filesystem. This is normally done for you by default when KOS starts. In general, there diff --git a/kernel/arch/dreamcast/hardware/pvr/pvr_dma.c b/kernel/arch/dreamcast/hardware/pvr/pvr_dma.c index c841ae7a..521a5215 100644 --- a/kernel/arch/dreamcast/hardware/pvr/pvr_dma.c +++ b/kernel/arch/dreamcast/hardware/pvr/pvr_dma.c @@ -66,7 +66,7 @@ static void pvr_dma_irq_hnd(uint32_t code, void *data) { } } -static uintptr_t pvr_dest_addr(uintptr_t dest, int type) { +static uintptr_t pvr_dest_addr(uintptr_t dest, pvr_dma_type_t type) { uintptr_t dest_addr; /* Send the data to the right place */ @@ -95,8 +95,9 @@ static uintptr_t pvr_dest_addr(uintptr_t dest, int type) { return dest_addr; } -int pvr_dma_transfer(void *src, uintptr_t dest, size_t count, int type, - int block, pvr_dma_callback_t callback, void *cbdata) { +int pvr_dma_transfer(const void *src, uintptr_t dest, size_t count, + pvr_dma_type_t type, int block, + pvr_dma_callback_t callback, void *cbdata) { uintptr_t src_addr = ((uintptr_t)src); /* Check for 32-byte alignment */ @@ -196,7 +197,7 @@ void pvr_dma_shutdown(void) { } /* Copies n bytes from src to PVR dest, dest must be 32-byte aligned */ -void *pvr_sq_load(void *dest, const void *src, size_t n, int type) { +void *pvr_sq_load(void *dest, const void *src, size_t n, pvr_dma_type_t type) { void *dma_area_ptr; if(pvr_dma[PVR_DST] != 0) { @@ -212,7 +213,7 @@ void *pvr_sq_load(void *dest, const void *src, size_t n, int type) { } /* Fills n bytes at PVR dest with 16-bit c, dest must be 32-byte aligned */ -void *pvr_sq_set16(void *dest, uint32_t c, size_t n, int type) { +void *pvr_sq_set16(void *dest, uint32_t c, size_t n, pvr_dma_type_t type) { void *dma_area_ptr; if(pvr_dma[PVR_DST] != 0) { @@ -228,7 +229,7 @@ void *pvr_sq_set16(void *dest, uint32_t c, size_t n, int type) { } /* Fills n bytes at PVR dest with 32-bit c, dest must be 32-byte aligned */ -void *pvr_sq_set32(void *dest, uint32_t c, size_t n, int type) { +void *pvr_sq_set32(void *dest, uint32_t c, size_t n, pvr_dma_type_t type) { void *dma_area_ptr; if(pvr_dma[PVR_DST] != 0) { diff --git a/kernel/arch/dreamcast/hardware/pvr/pvr_palette.c b/kernel/arch/dreamcast/hardware/pvr/pvr_palette.c index 6d2bce10..15b77e31 100644 --- a/kernel/arch/dreamcast/hardware/pvr/pvr_palette.c +++ b/kernel/arch/dreamcast/hardware/pvr/pvr_palette.c @@ -17,7 +17,7 @@ */ /* Set the palette format */ -void pvr_set_pal_format(int fmt) { +void pvr_set_pal_format(pvr_palfmt_t fmt) { PVR_SET(PVR_PALETTE_CFG, fmt); } diff --git a/kernel/arch/dreamcast/hardware/pvr/pvr_prim.c b/kernel/arch/dreamcast/hardware/pvr/pvr_prim.c index 7f9385e7..55952e5e 100644 --- a/kernel/arch/dreamcast/hardware/pvr/pvr_prim.c +++ b/kernel/arch/dreamcast/hardware/pvr/pvr_prim.c @@ -20,7 +20,7 @@ */ /* Compile a polygon context into a polygon header */ -void pvr_poly_compile(pvr_poly_hdr_t *dst, pvr_poly_cxt_t *src) { +void pvr_poly_compile(pvr_poly_hdr_t *dst, const pvr_poly_cxt_t *src) { int u, v; uint32_t txr_base; /* Temporary variables we can read-write-modify, since we cannot do so from @@ -337,7 +337,7 @@ void pvr_sprite_cxt_txr(pvr_sprite_cxt_t *dst, pvr_list_t list, dst->txr.format = textureformat; } -void pvr_sprite_compile(pvr_sprite_hdr_t *dst, pvr_sprite_cxt_t *src) { +void pvr_sprite_compile(pvr_sprite_hdr_t *dst, const pvr_sprite_cxt_t *src) { int u, v; uint32_t txr_base; uint32_t cmd, mode[3]; @@ -483,7 +483,7 @@ void pvr_mod_compile(pvr_mod_hdr_t *dst, pvr_list_t list, uint32 mode, /* Compile a polygon context into a polygon header that is affected by modifier volumes */ -void pvr_poly_mod_compile(pvr_poly_mod_hdr_t *dst, pvr_poly_cxt_t *src) { +void pvr_poly_mod_compile(pvr_poly_mod_hdr_t *dst, const pvr_poly_cxt_t *src) { int u, v; uint32_t txr_base; uint32_t cmd, mode1, mode2[2], mode3[2]; diff --git a/kernel/arch/dreamcast/hardware/pvr/pvr_texture.c b/kernel/arch/dreamcast/hardware/pvr/pvr_texture.c index 0b5506dc..49ea049e 100644 --- a/kernel/arch/dreamcast/hardware/pvr/pvr_texture.c +++ b/kernel/arch/dreamcast/hardware/pvr/pvr_texture.c @@ -20,12 +20,12 @@ */ /* Load raw texture data from an SH-4 buffer into PVR RAM */ -void pvr_txr_load(void * src, pvr_ptr_t dst, uint32 count) { +void pvr_txr_load(const void *src, pvr_ptr_t dst, uint32 count) { if(count & 3) { count = (count + 4) & ~3; } - pvr_sq_load((uint32 *)dst, (uint32 *)src, count, PVR_DMA_VRAM64); + pvr_sq_load((uint32 *)dst, (const uint32 *)src, count, PVR_DMA_VRAM64); } /* Linear/iterative twiddling algorithm from Marcus' tatest */ @@ -52,7 +52,7 @@ void pvr_txr_load(void * src, pvr_ptr_t dst, uint32 count) { PVR_TXRLOAD_INVERT */ -void pvr_txr_load_ex(void * src, pvr_ptr_t dst, uint32 w, uint32 h, +void pvr_txr_load_ex(const void *src, pvr_ptr_t dst, uint32 w, uint32 h, uint32 flags) { uint32 x, y, yout, min, mask, bpp, invert; @@ -143,7 +143,7 @@ void pvr_txr_load_ex(void * src, pvr_ptr_t dst, uint32 w, uint32 h, } /* Load a KOS Platform Independent Image (subject to restraint checking) */ -void pvr_txr_load_kimg(kos_img_t *img, pvr_ptr_t dst, uint32 flags) { +void pvr_txr_load_kimg(const kos_img_t *img, pvr_ptr_t dst, uint32 flags) { uint32 fmt, w, h; /* First check and make sure it's a format we can use */ diff --git a/kernel/arch/dreamcast/include/dc/pvr.h b/kernel/arch/dreamcast/include/dc/pvr.h index ecc37286..d925b8e6 100644 --- a/kernel/arch/dreamcast/include/dc/pvr.h +++ b/kernel/arch/dreamcast/include/dc/pvr.h @@ -1537,7 +1537,7 @@ int pvr_get_stats(pvr_stats_t *stat); like the old cheap "worm hole". */ -/** \defgroup pvr_palfmts Formats +/** \defgroup pvr_palfmt Formats \brief Color palette formats of the PowerVR \ingroup pvr_pal_mgmt @@ -1546,10 +1546,12 @@ int pvr_get_stats(pvr_stats_t *stat); @{ */ -#define PVR_PAL_ARGB1555 0 /**< \brief 16-bit ARGB1555 palette format */ -#define PVR_PAL_RGB565 1 /**< \brief 16-bit RGB565 palette format */ -#define PVR_PAL_ARGB4444 2 /**< \brief 16-bit ARGB4444 palette format */ -#define PVR_PAL_ARGB8888 3 /**< \brief 32-bit ARGB8888 palette format */ +typedef enum pvr_palfmt { + PVR_PAL_ARGB1555, /**< \brief 16-bit ARGB1555 palette format */ + PVR_PAL_RGB565, /**< \brief 16-bit RGB565 palette format */ + PVR_PAL_ARGB4444, /**< \brief 16-bit ARGB4444 palette format */ + PVR_PAL_ARGB8888, /**< \brief 32-bit ARGB8888 palette format */ +} pvr_palfmt_t; /** @} */ /** \brief Set the palette format. @@ -1564,9 +1566,9 @@ int pvr_get_stats(pvr_stats_t *stat); paletted textures with ARGB8888 entries in the palette. \param fmt The format to use - \see pvr_palfmts + \see pvr_palfmt_t */ -void pvr_set_pal_format(int fmt); +void pvr_set_pal_format(pvr_palfmt_t fmt); /** \brief Set a palette value. \ingroup pvr_pal_mgmt @@ -2088,7 +2090,7 @@ int pvr_check_ready(void); \param dst Where to store the compiled header. \param src The context to compile. */ -void pvr_poly_compile(pvr_poly_hdr_t *dst, pvr_poly_cxt_t *src); +void pvr_poly_compile(pvr_poly_hdr_t *dst, const pvr_poly_cxt_t *src); /** \defgroup pvr_ctx_init Initialization \brief Functions for initializing PVR polygon contexts @@ -2137,7 +2139,7 @@ void pvr_poly_cxt_txr(pvr_poly_cxt_t *dst, pvr_list_t list, \param src The context to compile. */ void pvr_sprite_compile(pvr_sprite_hdr_t *dst, - pvr_sprite_cxt_t *src); + const pvr_sprite_cxt_t *src); /** \brief Fill in a sprite context for non-textured sprites. \ingroup pvr_ctx_init @@ -2201,7 +2203,7 @@ void pvr_mod_compile(pvr_mod_hdr_t *dst, pvr_list_t list, uint32_t mode, \param dst Where to store the compiled header. \param src The context to compile. */ -void pvr_poly_mod_compile(pvr_poly_mod_hdr_t *dst, pvr_poly_cxt_t *src); +void pvr_poly_mod_compile(pvr_poly_mod_hdr_t *dst, const pvr_poly_cxt_t *src); /** \brief Fill in a polygon context for non-textured polygons affected by a modifier volume. @@ -2265,7 +2267,7 @@ void pvr_poly_cxt_txr_mod(pvr_poly_cxt_t *dst, pvr_list_t list, \param count The size of the texture in bytes (must be a multiple of 32). */ -void pvr_txr_load(void *src, pvr_ptr_t dst, uint32_t count); +void pvr_txr_load(const void *src, pvr_ptr_t dst, uint32_t count); /** \defgroup pvr_txrload_constants Flags \brief Texture loading constants @@ -2313,7 +2315,8 @@ void pvr_txr_load(void *src, pvr_ptr_t dst, uint32_t count); \see pvr_txrload_constants */ -void pvr_txr_load_ex(void *src, pvr_ptr_t dst, uint32_t w, uint32_t h, uint32_t flags); +void pvr_txr_load_ex(const void *src, pvr_ptr_t dst, + uint32_t w, uint32_t h, uint32_t flags); /** \brief Load a KOS Platform Independent Image (subject to constraint checking). @@ -2344,7 +2347,7 @@ void pvr_txr_load_ex(void *src, pvr_ptr_t dst, uint32_t w, uint32_t h, uint32_t from this function if it twiddles the texture while loading. */ -void pvr_txr_load_kimg(kos_img_t *img, pvr_ptr_t dst, uint32_t flags); +void pvr_txr_load_kimg(const kos_img_t *img, pvr_ptr_t dst, uint32_t flags); /* PVR DMA ***********************************************************/ @@ -2365,6 +2368,22 @@ void pvr_txr_load_kimg(kos_img_t *img, pvr_ptr_t dst, uint32_t flags); */ typedef void (*pvr_dma_callback_t)(void *data); +/** \defgroup pvr_dma_type Transfer Modes + \brief Transfer modes with TA/PVR DMA and Store Queues + \ingroup pvr_dma + + @{ +*/ +typedef enum pvr_dma_type { + PVR_DMA_VRAM64, /**< \brief Transfer to VRAM using TA bus */ + PVR_DMA_VRAM32, /**< \brief Transfer to VRAM using TA bus */ + PVR_DMA_TA, /**< \brief Transfer to the tile accelerator */ + PVR_DMA_YUV, /**< \brief Transfer to the YUV converter (TA) */ + PVR_DMA_VRAM32_SB, /**< \brief Transfer to/from VRAM using PVR i/f */ + PVR_DMA_VRAM64_SB, /**< \brief Transfer to/from VRAM using PVR i/f */ +} pvr_dma_type_t; +/** @} */ + /** \brief Perform a DMA transfer to the PVR RAM over 64-bit TA bus. \ingroup pvr_dma @@ -2392,24 +2411,11 @@ typedef void (*pvr_dma_callback_t)(void *data); \em EFAULT - dest is not 32-byte aligned \n \em EIO - I/O error - \see pvr_dma_modes + \see pvr_dma_type_t */ -int pvr_dma_transfer(void *src, uintptr_t dest, size_t count, int type, - int block, pvr_dma_callback_t callback, void *cbdata); - -/** \defgroup pvr_dma_modes Transfer Modes - \brief Transfer modes with TA/PVR DMA and Store Queues - \ingroup pvr_dma - - @{ -*/ -#define PVR_DMA_VRAM64 0 /**< \brief Transfer to VRAM using TA bus */ -#define PVR_DMA_VRAM32 1 /**< \brief Transfer to VRAM using TA bus */ -#define PVR_DMA_TA 2 /**< \brief Transfer to the tile accelerator */ -#define PVR_DMA_YUV 3 /**< \brief Transfer to the YUV converter (TA) */ -#define PVR_DMA_VRAM32_SB 4 /**< \brief Transfer to/from VRAM using PVR i/f */ -#define PVR_DMA_VRAM64_SB 5 /**< \brief Transfer to/from VRAM using PVR i/f */ -/** @} */ +int pvr_dma_transfer(const void *src, uintptr_t dest, size_t count, + pvr_dma_type_t type, int block, + pvr_dma_callback_t callback, void *cbdata); /** \brief Load a texture using TA DMA. \ingroup pvr_dma @@ -2522,7 +2528,8 @@ void pvr_dma_shutdown(void); \sa pvr_sq_set32() */ -void *pvr_sq_load(void *dest, const void *src, size_t n, int type); +void *pvr_sq_load(void *dest, const void *src, + size_t n, pvr_dma_type_t type); /** \brief Set a block of PVR memory to a 16-bit value. \ingroup store_queues @@ -2545,7 +2552,7 @@ void *pvr_sq_load(void *dest, const void *src, size_t n, int type); \sa pvr_sq_set32() */ -void *pvr_sq_set16(void *dest, uint32_t c, size_t n, int type); +void *pvr_sq_set16(void *dest, uint32_t c, size_t n, pvr_dma_type_t type); /** \brief Set a block of PVR memory to a 32-bit value. \ingroup store_queues @@ -2567,7 +2574,7 @@ void *pvr_sq_set16(void *dest, uint32_t c, size_t n, int type); \sa pvr_sq_set16 */ -void *pvr_sq_set32(void *dest, uint32_t c, size_t n, int type); +void *pvr_sq_set32(void *dest, uint32_t c, size_t n, pvr_dma_type_t type); /*********************************************************************/ diff --git a/kernel/fs/fs.c b/kernel/fs/fs.c index da97e840..5969b251 100644 --- a/kernel/fs/fs.c +++ b/kernel/fs/fs.c @@ -106,7 +106,7 @@ static fs_hnd_t * fs_hnd_open(const char *fn, int mode) { fs_hnd_t *hnd; char rfn[PATH_MAX]; - if(!realpath(fn, rfn)) + if(!fs_normalize_path(fn, rfn)) return NULL; /* Are they trying to open the root? */ @@ -609,7 +609,7 @@ int fs_rename(const char *fn1, const char *fn2) { vfs_handler_t *fh1, *fh2; char rfn1[PATH_MAX], rfn2[PATH_MAX]; - if(!realpath(fn1, rfn1) || !realpath(fn2, rfn2)) + if(!fs_normalize_path(fn1, rfn1) || !fs_normalize_path(fn2, rfn2)) return -1; /* Look for handlers */ @@ -645,7 +645,7 @@ int fs_unlink(const char *fn) { vfs_handler_t *cur; char rfn[PATH_MAX]; - if(!realpath(fn, rfn)) + if(!fs_normalize_path(fn, rfn)) return -1; /* Look for a handler */ @@ -664,7 +664,7 @@ int fs_unlink(const char *fn) { int fs_chdir(const char *fn) { char rfn[PATH_MAX]; - if(!realpath(fn, rfn)) + if(!fs_normalize_path(fn, rfn)) return -1; thd_set_pwd(thd_get_current(), rfn); @@ -705,7 +705,7 @@ int fs_mkdir(const char * fn) { vfs_handler_t *cur; char rfn[PATH_MAX]; - if(!realpath(fn, rfn)) + if(!fs_normalize_path(fn, rfn)) return -1; /* Look for a handler */ @@ -725,7 +725,7 @@ int fs_rmdir(const char * fn) { vfs_handler_t *cur; char rfn[PATH_MAX]; - if(!realpath(fn, rfn)) + if(!fs_normalize_path(fn, rfn)) return -1; /* Look for a handler */ @@ -774,7 +774,7 @@ 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)) + if(!fs_normalize_path(path1, rfn1) || !fs_normalize_path(path2, rfn2)) return -1; /* Look for handlers */ @@ -811,7 +811,7 @@ int fs_symlink(const char *path1, const char *path2) { vfs_handler_t *vfs; char rfn[PATH_MAX]; - if(!realpath(path2, rfn)) + if(!fs_normalize_path(path2, rfn)) return -1; /* Look for the handler */ diff --git a/kernel/fs/fs_utils.c b/kernel/fs/fs_utils.c index 9ec83def..12ac71b9 100644 --- a/kernel/fs/fs_utils.c +++ b/kernel/fs/fs_utils.c @@ -180,3 +180,81 @@ ssize_t fs_path_append(char *dst, const char *src, size_t len) { /* Return the current length of the string, including the NUL terminator. */ return (ssize_t)(dlen + slen + 1); } + +char *fs_normalize_path(const char *__restrict path, char *__restrict resolved) { + char temp_path[PATH_MAX]; + char *token; + char *last_slash; + ssize_t len; + + /* Check for invalid params. */ + if(path == NULL || resolved == NULL) { + errno = EINVAL; + return NULL; + } + + /* Too big of a path? */ + len = strlen(path); + if(len >= PATH_MAX) { + errno = ENAMETOOLONG; + return NULL; + } + + /* Handle absolute path. */ + if(path[0] == '/') { + strncpy(temp_path, path, len); + temp_path[len] = '\0'; + } else { ...<truncated>... hooks/post-receive -- A pseudo Operating System for the Dreamcast. |