|
From: kosmirror <kos...@us...> - 2025-07-29 20:01:28
|
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 e9c9785d358d78f1cc0b42011bbfe6ac713486ee (commit)
via 2031e8a1dabde221aa355827a4b52c3f683341c1 (commit)
via 4dc76d1541bb354cb27069f49053f52f8dc5963a (commit)
via 1a7a5f412dde5f2879a42b1c1625dae6ae00265e (commit)
via 5987e2609587c7828b2cea91b3fb23e2c2361204 (commit)
via f7de8a4049d971f473c60549cf1a045bfb4cb540 (commit)
via 7f391369c9789c519b14707104d7d74abf1a07e2 (commit)
via 0ea314e7e4882b8ddc5860d8987452cbea4f594a (commit)
via 776d84b647cf047a85df054a445efd9501d3d8dd (commit)
from c62573617e4718d48f0ac3fe0cb02d60b78bed32 (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 e9c9785d358d78f1cc0b42011bbfe6ac713486ee
Author: QuzarDC <qu...@co...>
Date: Mon Jul 28 20:36:57 2025 -0400
fs_romdisk: Free dangling FDs on shutdown.
It's just polite.
commit 2031e8a1dabde221aa355827a4b52c3f683341c1
Author: QuzarDC <qu...@co...>
Date: Mon Jul 28 15:49:55 2025 -0400
fs_romdisk: Dynamically allocated FD tracking.
As with #973 remove the static table and pass a pointer
to the FD object out rather than index.
This additionally means that the define for the max files
can be removed. While there I removed the one for CDFS
that should have been removed when it was obsoleted.
commit 4dc76d1541bb354cb27069f49053f52f8dc5963a
Author: QuzarDC <qu...@co...>
Date: Mon Jul 28 03:32:28 2025 -0400
fs_romdisk: Deduplicate fd validity checks.
For all but the two checks in open/close, this is
just an identical replica of what was happening.
In open, if the fd is in bounds, then index must have
already be set to `FH_INDEX_RESERVED` so it can't
make a difference. In close, if it's invalid because
it's already set to `FH_INDEX_FREE` then there's nothing
to be done anyways.
commit 1a7a5f412dde5f2879a42b1c1625dae6ae00265e
Author: QuzarDC <qu...@co...>
Date: Mon Jul 28 02:49:20 2025 -0400
fs_romdisk: Tidy romdisk_find.
Was strangely using a nested else{if/else} rather than elseif/else.
commit 5987e2609587c7828b2cea91b3fb23e2c2361204
Author: QuzarDC <qu...@co...>
Date: Mon Jul 28 02:07:31 2025 -0400
fs_romdisk: Refactor romdisk unmounting/shutdown.
`fs_romdisk_shutdown` was effectively duplicating
`fs_romdisk_unmount` in a loop over all entries in
the `romdisks` list. Should be functionally identical
except for now `fs_romdisk_shutdown` both locks the
list mutex while working on it and removes the entries
from the list.
commit f7de8a4049d971f473c60549cf1a045bfb4cb540
Author: QuzarDC <qu...@co...>
Date: Mon Jul 28 00:33:57 2025 -0400
fs_romdisk: Refactor `fs_romdisk_unmount`
Use the newer scoped mutex lock, reduce nesting, deduplicate
the own_buffer check, and remove unneded `rv`.
commit 7f391369c9789c519b14707104d7d74abf1a07e2
Author: QuzarDC <qu...@co...>
Date: Sun Jul 27 21:33:33 2025 -0400
fs_romdisk: Remove header pointer from internal image struct.
This is always simply the start of the image, and on top of
that it is never used. So just removing it. Cleaned up the
access to the magic string from the header as well.
commit 0ea314e7e4882b8ddc5860d8987452cbea4f594a
Author: QuzarDC <qu...@co...>
Date: Sun Jul 27 21:17:47 2025 -0400
fs_romdisk: Update param to `bool`.
commit 776d84b647cf047a85df054a445efd9501d3d8dd
Author: QuzarDC <qu...@co...>
Date: Sun Jul 27 20:27:02 2025 -0400
fs_romdisk: Replace arch/types with stdint.
Additionally correct minor whitespace issues around
var declarations or casts.
-----------------------------------------------------------------------
Summary of changes:
include/kos/fs_romdisk.h | 11 +-
include/kos/opts.h | 10 -
kernel/arch/dreamcast/kernel/init.c | 2 +-
kernel/fs/fs_romdisk.c | 383 +++++++++++++++++-------------------
4 files changed, 192 insertions(+), 214 deletions(-)
diff --git a/include/kos/fs_romdisk.h b/include/kos/fs_romdisk.h
index 274d00a5..3eb2d952 100644
--- a/include/kos/fs_romdisk.h
+++ b/include/kos/fs_romdisk.h
@@ -50,9 +50,10 @@
#define __KOS_FS_ROMDISK_H
#include <sys/cdefs.h>
+#include <stdbool.h>
+#include <stdint.h>
__BEGIN_DECLS
-#include <arch/types.h>
#include <kos/fs.h>
/** \defgroup vfs_romdisk Romdisk
@@ -81,22 +82,22 @@ void fs_romdisk_shutdown(void);
\param mountpoint The directory to mount this romdisk on
\param img The ROMFS image
- \param own_buffer If 0, you are still responsible for img, and must
- free it if appropriate. If non-zero, img will be
+ \param own_buffer If false, you are still responsible for img, and
+ must free it if appropriate. If true, img will be
freed when it is unmounted
\retval 0 On success
\retval -1 If fs_romdisk_init not called
\retval -2 If img is invalid
\retval -3 If a malloc fails
*/
-int fs_romdisk_mount(const char * mountpoint, const uint8 *img, int own_buffer);
+int fs_romdisk_mount(const char * mountpoint, const uint8_t *img, bool own_buffer);
/** \brief Unmount a ROMFS image.
This function unmounts a ROMFS image that has been previously mounted with
fs_romdisk_mount(). This function does not check for open files on the fs,
so make sure that all files have been closed before calling it. If the VFS
- owns the buffer (own_buffer was non-zero when you called the mount function)
+ owns the buffer (own_buffer was true when you called the mount function)
then this function will also free the buffer.
\param mountpoint The ROMFS to unmount
diff --git a/include/kos/opts.h b/include/kos/opts.h
index 66eedea2..8000da10 100644
--- a/include/kos/opts.h
+++ b/include/kos/opts.h
@@ -114,16 +114,6 @@ __BEGIN_DECLS
#define VMUFS_DEBUG 1
#endif
-/** \brief The maximum number of cd files that can be open at a time. */
-#ifndef FS_CD_MAX_FILES
-#define FS_CD_MAX_FILES 8
-#endif
-
-/** \brief The maximum number of romdisk files that can be open at a time. */
-#ifndef FS_ROMDISK_MAX_FILES
-#define FS_ROMDISK_MAX_FILES 16
-#endif
-
/** \brief The maximum number of ramdisk files that can be open at a time. */
#ifndef FS_RAMDISK_MAX_FILES
#define FS_RAMDISK_MAX_FILES 8
diff --git a/kernel/arch/dreamcast/kernel/init.c b/kernel/arch/dreamcast/kernel/init.c
index 7f75feb7..9ad3b7e9 100644
--- a/kernel/arch/dreamcast/kernel/init.c
+++ b/kernel/arch/dreamcast/kernel/init.c
@@ -107,7 +107,7 @@ void vmu_fs_shutdown(void) {
/* Mount the built-in romdisk to /rd. */
void fs_romdisk_mount_builtin(void) {
- fs_romdisk_mount("/rd", __kos_romdisk, 0);
+ fs_romdisk_mount("/rd", __kos_romdisk, false);
}
void fs_romdisk_mount_builtin_legacy(void) {
diff --git a/kernel/fs/fs_romdisk.c b/kernel/fs/fs_romdisk.c
index d8516892..b2bc3784 100644
--- a/kernel/fs/fs_romdisk.c
+++ b/kernel/fs/fs_romdisk.c
@@ -16,7 +16,6 @@ on sunsite.unc.edu in /pub/Linux/system/recovery/, or as a package under Debian
*/
-#include <arch/types.h>
#include <kos/thread.h>
#include <kos/mutex.h>
#include <kos/fs_romdisk.h>
@@ -50,26 +49,26 @@ on sunsite.unc.edu in /pub/Linux/system/recovery/, or as a package under Debian
clever and made this header a variable length depending on the size of
the volume name *groan*. Its size will be a multiple of 16 bytes though. */
typedef struct {
- char magic[8]; /* Should be "-rom1fs-" */
- uint32 full_size; /* Full size of the file system */
- uint32 checksum; /* Checksum */
- char volume_name[RD_VN_MAX]; /* Volume name (zero-terminated) */
+ char magic[8]; /* Should be "-rom1fs-" */
+ uint32_t full_size; /* Full size of the file system */
+ uint32_t checksum; /* Checksum */
+ char volume_name[RD_VN_MAX]; /* Volume name (zero-terminated) */
} romdisk_hdr_t;
/* File header info; note that this header plus filename must be a multiple of
16 bytes, and the following file data must also be a multiple of 16 bytes. */
typedef struct {
- uint32 next_header; /* Offset of next header */
- uint32 spec_info; /* Spec info */
- uint32 size; /* Data size */
- uint32 checksum; /* File checksum */
- char filename[RD_FN_MAX]; /* File name (zero-terminated) */
+ uint32_t next_header; /* Offset of next header */
+ uint32_t spec_info; /* Spec info */
+ uint32_t size; /* Data size */
+ uint32_t checksum; /* File checksum */
+ char filename[RD_FN_MAX]; /* File name (zero-terminated) */
} romdisk_file_t;
-/* Util function to reverse the byte order of a uint32 */
-static uint32 ntohl_32(const void *data) {
- const uint8 *d = (const uint8*)data;
+/* Util function to reverse the byte order of a uint32_t */
+static uint32_t ntohl_32(const void *data) {
+ const uint8_t *d = (const uint8_t *)data;
return (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3] << 0);
}
@@ -84,11 +83,10 @@ typedef LIST_HEAD(rdi_list, rd_image) rdi_list_t;
typedef struct rd_image {
LIST_ENTRY(rd_image) list_ent; /* List entry */
- int own_buffer; /* Do we own the memory? */
- const uint8 * image; /* The actual image */
- const romdisk_hdr_t * hdr; /* Pointer to the header */
- uint32 files; /* Offset in the image to the files area */
- vfs_handler_t * vfsh; /* Our VFS mount struct */
+ bool own_buffer; /* Do we own the memory? */
+ const uint8_t *image; /* The actual image */
+ uint32_t files; /* Offset in the image to the files area */
+ vfs_handler_t *vfsh; /* Our VFS mount struct */
} rd_image_t;
/* Global list of mounted romdisks */
@@ -97,33 +95,41 @@ static rdi_list_t romdisks;
/********************************************************************************/
/* File primitives */
-/* File handles.. I could probably do this with a linked list, but I'm just
- too lazy right now. =) */
-static struct {
- uint32 index; /* romfs image index */
- bool dir; /* true if a directory */
- uint32 ptr; /* Current read position in bytes */
- uint32 size; /* Length of file in bytes */
- dirent_t dirent; /* A static dirent to pass back to clients */
- rd_image_t * mnt; /* Which mount instance are we using? */
-} fh[FS_ROMDISK_MAX_FILES];
+/* Entries in the fd list. Pointers of this type are passed out to ref files. */
+typedef struct rd_fd {
+ uint32_t index; /* romfs image index */
+ bool dir; /* true if a directory */
+ uint32_t ptr; /* Current read position in bytes */
+ uint32_t size; /* Length of file in bytes */
+ dirent_t dirent; /* A static dirent to pass back to clients */
+ rd_image_t *mnt; /* Which mount instance are we using? */
+ TAILQ_ENTRY(rd_fd) next; /* Next handle in the linked list */
+} rd_fd_t;
+
+static TAILQ_HEAD(rd_fd_queue, rd_fd) rd_fd_queue;
#define FH_INDEX_FREE 0
#define FH_INDEX_RESERVED -1
+/* Test if an fd is invalid */
+static inline bool romdisk_fd_invalid(rd_fd_t *fd) {
+ return (!fd || (fd->index == FH_INDEX_FREE));
+}
+
/* File type */
#define ROMFH_DIR 1
#define ROMFH_MASK 3
/* Mutex for file handles */
+/* We use it for both the files list and the images list. */
static mutex_t fh_mutex;
/* Given a filename and a starting romdisk directory listing (byte offset),
search for the entry in the directory and return the byte offset to its
entry. */
static uint32_t romdisk_find_object(rd_image_t *mnt, const char *fn, size_t fnlen, bool dir, uint32_t offset) {
- uint32 i, ni, type;
+ uint32_t i, ni, type;
const romdisk_file_t *fhdr;
i = offset;
@@ -181,7 +187,7 @@ static uint32_t romdisk_find_object(rd_image_t *mnt, const char *fn, size_t fnle
It will return an offset in the romdisk image for the object. */
static uint32_t romdisk_find(rd_image_t *mnt, const char *fn, bool dir) {
const char *cur;
- uint32 i;
+ uint32_t i;
const romdisk_file_t *fhdr;
/* If the object is in a sub-tree, traverse the trees looking
@@ -202,22 +208,18 @@ static uint32_t romdisk_find(rd_image_t *mnt, const char *fn, bool dir) {
}
/* Locate the file in the resulting directory */
- if(*fn) {
- i = romdisk_find_object(mnt, fn, strlen(fn), dir, i);
+ if(*fn)
+ return romdisk_find_object(mnt, fn, strlen(fn), dir, i);
+ else if(!dir)
+ return 0;
+ else
return i;
- }
- else {
- if(!dir)
- return 0;
- else
- return i;
- }
}
/* Open a file or directory */
-static void * romdisk_open(vfs_handler_t * vfs, const char *fn, int mode) {
- file_t fd;
- uint32 filehdr;
+static void * romdisk_open(vfs_handler_t *vfs, const char *fn, int mode) {
+ rd_fd_t *fd;
+ uint32_t filehdr;
const romdisk_file_t *fhdr;
rd_image_t *mnt = (rd_image_t *)vfs->privdata;
@@ -239,62 +241,58 @@ static void * romdisk_open(vfs_handler_t * vfs, const char *fn, int mode) {
return NULL;
}
- /* Find a free file handle */
- mutex_lock(&fh_mutex);
-
- for(fd = 0; fd < FS_ROMDISK_MAX_FILES; fd++)
- if(fh[fd].index == FH_INDEX_FREE) {
- fh[fd].index = FH_INDEX_RESERVED;
- break;
- }
-
- mutex_unlock(&fh_mutex);
-
- if(fd >= FS_ROMDISK_MAX_FILES) {
- errno = ENFILE;
+ /* Allocate the fd */
+ fd = malloc(sizeof(rd_fd_t));
+ if(!fd) {
+ errno = ENOMEM;
return NULL;
}
/* Fill the fd structure */
fhdr = (const romdisk_file_t *)(mnt->image + filehdr);
- fh[fd].index = filehdr + sizeof(romdisk_file_t) + (strlen(fhdr->filename) / RD_FN_MAX) * RD_FN_MAX;
- fh[fd].dir = ((mode & O_DIR) != 0);
- fh[fd].ptr = 0;
- fh[fd].size = ntohl_32(&fhdr->size);
- fh[fd].mnt = mnt;
+ fd->index = filehdr + sizeof(romdisk_file_t) + (strlen(fhdr->filename) / RD_FN_MAX) * RD_FN_MAX;
+ fd->dir = ((mode & O_DIR) != 0);
+ fd->ptr = 0;
+ fd->size = ntohl_32(&fhdr->size);
+ fd->mnt = mnt;
+
+ /* Lock before modifying the queue. */
+ mutex_lock_scoped(&fh_mutex);
+
+ TAILQ_INSERT_TAIL(&rd_fd_queue, fd, next);
return (void *)fd;
}
/* Close a file or directory */
-static int romdisk_close(void * h) {
- file_t fd = (file_t)h;
+static int romdisk_close(void *h) {
+ rd_fd_t *fd = (rd_fd_t *)h;
+
+ /* Lock before modifying the queue. */
+ mutex_lock_scoped(&fh_mutex);
+ TAILQ_REMOVE(&rd_fd_queue, fd, next);
+ free(fd);
- /* Check that the fd is valid */
- if(fd < FS_ROMDISK_MAX_FILES) {
- /* No need to lock the mutex: this is an atomic op */
- fh[fd].index = FH_INDEX_FREE;
- }
return 0;
}
/* Read from a file */
-static ssize_t romdisk_read(void * h, void *buf, size_t bytes) {
- file_t fd = (file_t)h;
+static ssize_t romdisk_read(void *h, void *buf, size_t bytes) {
+ rd_fd_t *fd = (rd_fd_t *)h;
/* Check that the fd is valid */
- if(fd >= FS_ROMDISK_MAX_FILES || fh[fd].index == FH_INDEX_FREE || fh[fd].dir) {
+ if(romdisk_fd_invalid(fd) || fd->dir) {
errno = EINVAL;
return -1;
}
/* Is there enough left? */
- if((fh[fd].ptr + bytes) > fh[fd].size)
- bytes = fh[fd].size - fh[fd].ptr;
+ if((fd->ptr + bytes) > fd->size)
+ bytes = fd->size - fd->ptr;
/* Copy out the requested amount */
- memcpy(buf, fh[fd].mnt->image + fh[fd].index + fh[fd].ptr, bytes);
- fh[fd].ptr += bytes;
+ memcpy(buf, fd->mnt->image + fd->index + fd->ptr, bytes);
+ fd->ptr += bytes;
return bytes;
}
@@ -310,11 +308,11 @@ static ssize_t romdisk_write(void *h, const void *buf, size_t bytes) {
}
/* Seek elsewhere in a file */
-static off_t romdisk_seek(void * h, off_t offset, int whence) {
- file_t fd = (file_t)h;
+static off_t romdisk_seek(void *h, off_t offset, int whence) {
+ rd_fd_t *fd = (rd_fd_t *)h;
/* Check that the fd is valid */
- if(fd >= FS_ROMDISK_MAX_FILES || fh[fd].index == FH_INDEX_FREE || fh[fd].dir) {
+ if(romdisk_fd_invalid(fd) || fd->dir) {
errno = EBADF;
return -1;
}
@@ -327,25 +325,25 @@ static off_t romdisk_seek(void * h, off_t offset, int whence) {
return -1;
}
- fh[fd].ptr = offset;
+ fd->ptr = offset;
break;
case SEEK_CUR:
- if(offset < 0 && ((uint32)-offset) > fh[fd].ptr) {
+ if(offset < 0 && ((uint32_t)-offset) > fd->ptr) {
errno = EINVAL;
return -1;
}
- fh[fd].ptr += offset;
+ fd->ptr += offset;
break;
case SEEK_END:
- if(offset < 0 && ((uint32)-offset) > fh[fd].size) {
+ if(offset < 0 && ((uint32_t)-offset) > fd->size) {
errno = EINVAL;
return -1;
}
- fh[fd].ptr = fh[fd].size + offset;
+ fd->ptr = fd->size + offset;
break;
default:
@@ -354,80 +352,80 @@ static off_t romdisk_seek(void * h, off_t offset, int whence) {
}
/* Check bounds */
- if(fh[fd].ptr > fh[fd].size) fh[fd].ptr = fh[fd].size;
+ if(fd->ptr > fd->size) fd->ptr = fd->size;
- return fh[fd].ptr;
+ return fd->ptr;
}
/* Tell where in the file we are */
-static off_t romdisk_tell(void * h) {
- file_t fd = (file_t)h;
+static off_t romdisk_tell(void *h) {
+ rd_fd_t *fd = (rd_fd_t *)h;
- if(fd >= FS_ROMDISK_MAX_FILES || fh[fd].index == FH_INDEX_FREE || fh[fd].dir) {
+ if(romdisk_fd_invalid(fd) || fd->dir) {
errno = EINVAL;
return -1;
}
- return fh[fd].ptr;
+ return fd->ptr;
}
/* Tell how big the file is */
-static size_t romdisk_total(void * h) {
- file_t fd = (file_t)h;
+static size_t romdisk_total(void *h) {
+ rd_fd_t *fd = (rd_fd_t *)h;
- if(fd >= FS_ROMDISK_MAX_FILES || fh[fd].index == FH_INDEX_FREE || fh[fd].dir) {
+ if(romdisk_fd_invalid(fd) || fd->dir) {
errno = EINVAL;
return -1;
}
- return fh[fd].size;
+ return fd->size;
}
/* Read a directory entry */
-static dirent_t *romdisk_readdir(void * h) {
+static dirent_t *romdisk_readdir(void *h) {
romdisk_file_t *fhdr;
int type;
- file_t fd = (file_t)h;
+ rd_fd_t *fd = (rd_fd_t *)h;
- if(fd >= FS_ROMDISK_MAX_FILES || fh[fd].index == FH_INDEX_FREE || !fh[fd].dir) {
+ if(romdisk_fd_invalid(fd) || !fd->dir) {
errno = EBADF;
return NULL;
}
/* This happens if we hit the end of the directory on advancing the pointer
last time through. */
- if(fh[fd].ptr == (uint32)-1)
+ if(fd->ptr == (uint32_t)-1)
return NULL;
/* Get the current file header */
- fhdr = (romdisk_file_t *)(fh[fd].mnt->image + fh[fd].index + fh[fd].ptr);
+ fhdr = (romdisk_file_t *)(fd->mnt->image + fd->index + fd->ptr);
/* Update the pointer */
- fh[fd].ptr = ntohl_32(&fhdr->next_header);
- type = fh[fd].ptr & 0x0f;
- fh[fd].ptr = fh[fd].ptr & 0xfffffff0;
+ fd->ptr = ntohl_32(&fhdr->next_header);
+ type = fd->ptr & 0x0f;
+ fd->ptr = fd->ptr & 0xfffffff0;
- if(fh[fd].ptr != 0)
- fh[fd].ptr = fh[fd].ptr - fh[fd].index;
+ if(fd->ptr != 0)
+ fd->ptr = fd->ptr - fd->index;
else
- fh[fd].ptr = (uint32)-1;
+ fd->ptr = (uint32_t)-1;
/* Copy out the requested data */
- strcpy(fh[fd].dirent.name, fhdr->filename);
- fh[fd].dirent.time = 0;
+ strcpy(fd->dirent.name, fhdr->filename);
+ fd->dirent.time = 0;
if((type & ROMFH_MASK) == ROMFH_DIR ||
- strcmp(fh[fd].dirent.name, ".") == 0 ||
- strcmp(fh[fd].dirent.name, "..") == 0) {
- fh[fd].dirent.attr = O_DIR;
- fh[fd].dirent.size = -1;
+ strcmp(fd->dirent.name, ".") == 0 ||
+ strcmp(fd->dirent.name, "..") == 0) {
+ fd->dirent.attr = O_DIR;
+ fd->dirent.size = -1;
}
else {
- fh[fd].dirent.attr = 0;
- fh[fd].dirent.size = ntohl_32(&fhdr->size);
+ fd->dirent.attr = 0;
+ fd->dirent.size = ntohl_32(&fhdr->size);
}
- return &fh[fd].dirent;
+ return &fd->dirent;
}
/* Just to get the errno that might be better recognized upstream. */
@@ -439,16 +437,16 @@ static int romdisk_unlink(vfs_handler_t *vfs, const char *fn) {
return -1;
}
-static void *romdisk_mmap(void * h) {
- file_t fd = (file_t)h;
+static void *romdisk_mmap(void *h) {
+ rd_fd_t *fd = (rd_fd_t *)h;
- if(fd >= FS_ROMDISK_MAX_FILES || fh[fd].index == FH_INDEX_FREE) {
+ if(romdisk_fd_invalid(fd)) {
errno = EINVAL;
return NULL;
}
/* Can't really help the loss of "const" here */
- return (void *)(fh[fd].mnt->image + fh[fd].index);
+ return (void *)(fd->mnt->image + fd->index);
}
static int romdisk_stat(vfs_handler_t *vfs, const char *path, struct stat *st,
...<truncated>...
hooks/post-receive
--
A pseudo Operating System for the Dreamcast.
|