From 17bfb0ef0a48330b1d54e61fe3c30d83528d2d90 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Wed, 25 Jan 2023 20:16:22 +0100 Subject: style: typedef structs, shorter namespaces I've wanted to do this for a while, and since I've just had a relatively large refactor commit (pcpy), this is as good of a time as any. Typedefing structs was mostly inspired by Plan 9's coding style. It makes some lines of code much shorter at basically no expense. Everything related to userland kept old-style struct definitions, so as not to force that style onto other people. I also considered changing SCREAMING_ENUM_FIELDS to NicerLookingCamelcase, but I didn't, just in case that'd be confusing. --- src/kernel/arch/amd64/driver/fsroot.c | 4 ++-- src/kernel/arch/amd64/driver/pata.c | 4 ++-- src/kernel/arch/amd64/driver/ps2.c | 8 ++++---- src/kernel/arch/amd64/driver/rtl8139.c | 10 +++++----- src/kernel/arch/amd64/driver/serial.c | 6 +++--- src/kernel/arch/amd64/driver/util.c | 12 ++++++------ src/kernel/arch/amd64/driver/util.h | 10 +++++----- src/kernel/arch/amd64/driver/video.c | 8 ++++---- src/kernel/arch/amd64/driver/video.h | 4 ++-- 9 files changed, 33 insertions(+), 33 deletions(-) (limited to 'src/kernel/arch/amd64/driver') diff --git a/src/kernel/arch/amd64/driver/fsroot.c b/src/kernel/arch/amd64/driver/fsroot.c index 6217e29..6d3676d 100644 --- a/src/kernel/arch/amd64/driver/fsroot.c +++ b/src/kernel/arch/amd64/driver/fsroot.c @@ -8,7 +8,7 @@ #include #include -static int handle(struct vfs_request *req) { +static int handle(VfsReq *req) { // TODO document directory read format // TODO don't hardcode const char dir[] = @@ -31,7 +31,7 @@ static int handle(struct vfs_request *req) { } } -static void accept(struct vfs_request *req) { +static void accept(VfsReq *req) { vfsreq_finish_short(req, handle(req)); } diff --git a/src/kernel/arch/amd64/driver/pata.c b/src/kernel/arch/amd64/driver/pata.c index 6928b4e..b0ed592 100644 --- a/src/kernel/arch/amd64/driver/pata.c +++ b/src/kernel/arch/amd64/driver/pata.c @@ -11,13 +11,13 @@ static const int root_id = 100; -static void accept(struct vfs_request *req); +static void accept(VfsReq *req); void pata_init(void) { ata_init(); vfs_root_register("/ata", accept); } -static void accept(struct vfs_request *req) { +static void accept(VfsReq *req) { int ret; long id = (long __force)req->id; char wbuf[4096]; diff --git a/src/kernel/arch/amd64/driver/ps2.c b/src/kernel/arch/amd64/driver/ps2.c index d0629e6..cdcbf19 100644 --- a/src/kernel/arch/amd64/driver/ps2.c +++ b/src/kernel/arch/amd64/driver/ps2.c @@ -17,10 +17,10 @@ static volatile ring_t kb_backlog = {(void*)kb_buf, sizeof kb_buf, 0, 0}; static volatile uint8_t mouse_buf[64]; static volatile ring_t mouse_backlog = {(void*)mouse_buf, sizeof mouse_buf, 0, 0}; -static void accept(struct vfs_request *req); +static void accept(VfsReq *req); -static struct vfs_request *kb_queue = NULL; -static struct vfs_request *mouse_queue = NULL; +static VfsReq *kb_queue = NULL; +static VfsReq *mouse_queue = NULL; static void wait_out(void) { while ((port_in8(PS2 + 4) & 2) != 0); @@ -77,7 +77,7 @@ enum { H_MOUSE, }; -static void accept(struct vfs_request *req) { +static void accept(VfsReq *req) { // when you fix something here go also fix it in the COM1 driver int ret; switch (req->type) { diff --git a/src/kernel/arch/amd64/driver/rtl8139.c b/src/kernel/arch/amd64/driver/rtl8139.c index 1face38..dd11102 100644 --- a/src/kernel/arch/amd64/driver/rtl8139.c +++ b/src/kernel/arch/amd64/driver/rtl8139.c @@ -10,8 +10,8 @@ #define WAIT -1000 -static void accept(struct vfs_request *req); -static struct vfs_request *blocked_on = NULL; +static void accept(VfsReq *req); +static VfsReq *blocked_on = NULL; enum { @@ -105,7 +105,7 @@ void rtl8139_irq(void) { port_out16(iobase + INTRSTATUS, status); } -static int try_rx(struct process *proc, void __user *dest, size_t dlen) { +static int try_rx(Proc *proc, void __user *dest, size_t dlen) { uint16_t flags, size; /* bit 0 - Rx Buffer Empty */ if (port_in8(iobase + CMD) & 1) return WAIT; @@ -140,7 +140,7 @@ static int try_rx(struct process *proc, void __user *dest, size_t dlen) { return size; } -static int try_tx(struct process *proc, const void __user *src, size_t slen) { +static int try_tx(Proc *proc, const void __user *src, size_t slen) { static uint8_t desc = 0; if (slen > 0xFFF) return -1; @@ -164,7 +164,7 @@ static int try_tx(struct process *proc, const void __user *src, size_t slen) { return slen; } -static void accept(struct vfs_request *req) { +static void accept(VfsReq *req) { if (!req->caller) { vfsreq_finish_short(req, -1); return; diff --git a/src/kernel/arch/amd64/driver/serial.c b/src/kernel/arch/amd64/driver/serial.c index 12c4151..6fe4500 100644 --- a/src/kernel/arch/amd64/driver/serial.c +++ b/src/kernel/arch/amd64/driver/serial.c @@ -14,8 +14,8 @@ static volatile ring_t backlog = {(void*)backlog_buf, sizeof backlog_buf, 0, 0}; static const int COM1 = 0x3f8; -static void accept(struct vfs_request *req); -static struct vfs_request *hung_reads = NULL; +static void accept(VfsReq *req); +static VfsReq *hung_reads = NULL; void serial_init(void) { vfs_root_register("/com1", accept); } @@ -59,7 +59,7 @@ void serial_write(const char *buf, size_t len) { serial_putchar(buf[i]); } -static void accept(struct vfs_request *req) { +static void accept(VfsReq *req) { int ret; bool valid; switch (req->type) { diff --git a/src/kernel/arch/amd64/driver/util.c b/src/kernel/arch/amd64/driver/util.c index b2c33c6..957005c 100644 --- a/src/kernel/arch/amd64/driver/util.c +++ b/src/kernel/arch/amd64/driver/util.c @@ -5,7 +5,7 @@ #include #include -int req_readcopy(struct vfs_request *req, const void *buf, size_t len) { +int req_readcopy(VfsReq *req, const void *buf, size_t len) { if (!req->caller) return -1; assert(req->type == VFSOP_READ); fs_normslice(&req->offset, &req->output.len, len, false); @@ -14,7 +14,7 @@ int req_readcopy(struct vfs_request *req, const void *buf, size_t len) { return req->output.len; } -void postqueue_join(struct vfs_request **queue, struct vfs_request *req) { +void postqueue_join(VfsReq **queue, VfsReq *req) { if (req->postqueue_next) panic_invalid_state(); @@ -23,16 +23,16 @@ void postqueue_join(struct vfs_request **queue, struct vfs_request *req) { *queue = req; } -bool postqueue_pop(struct vfs_request **queue, void (*accept)(struct vfs_request *)) { - struct vfs_request *req = *queue; +bool postqueue_pop(VfsReq **queue, void (*accept)(VfsReq *)) { + VfsReq *req = *queue; if (req == NULL) return false; *queue = req->postqueue_next; accept(req); return true; } -void postqueue_ringreadall(struct vfs_request **queue, ring_t *r) { - struct vfs_request *req; +void postqueue_ringreadall(VfsReq **queue, ring_t *r) { + VfsReq *req; char tmp[64]; size_t mlen = 0; if (ring_used(r) == 0) return; diff --git a/src/kernel/arch/amd64/driver/util.h b/src/kernel/arch/amd64/driver/util.h index 06ca672..5827fa9 100644 --- a/src/kernel/arch/amd64/driver/util.h +++ b/src/kernel/arch/amd64/driver/util.h @@ -1,10 +1,10 @@ #pragma once +#include #include #include #include -struct vfs_request; -int req_readcopy(struct vfs_request *req, const void *buf, size_t len); +int req_readcopy(VfsReq *req, const void *buf, size_t len); /* compare request path. path MUST be a static string */ #define reqpathcmp(req, path) _reqpathcmp(req, ""path"", sizeof(path) - 1) @@ -13,9 +13,9 @@ int req_readcopy(struct vfs_request *req, const void *buf, size_t len); req->input.len == plen && \ memcmp(req->input.buf_kern, path, plen) == 0) -void postqueue_join(struct vfs_request **queue, struct vfs_request *req); -bool postqueue_pop(struct vfs_request **queue, void (*accept)(struct vfs_request *)); +void postqueue_join(VfsReq **queue, VfsReq *req); +bool postqueue_pop(VfsReq **queue, void (*accept)(VfsReq *)); /** If there are any pending read requests, and the ring buffer isn't empty, fulfill them * all with a single read. */ -void postqueue_ringreadall(struct vfs_request **queue, ring_t *r); +void postqueue_ringreadall(VfsReq **queue, ring_t *r); diff --git a/src/kernel/arch/amd64/driver/video.c b/src/kernel/arch/amd64/driver/video.c index 4cd6b0b..d7046b4 100644 --- a/src/kernel/arch/amd64/driver/video.c +++ b/src/kernel/arch/amd64/driver/video.c @@ -9,7 +9,7 @@ #include #include -static struct fb_info fb; +static GfxInfo fb; static char namebuf[64]; static size_t namelen; @@ -18,7 +18,7 @@ enum { H_FB, }; -static int handle(struct vfs_request *req) { +static int handle(VfsReq *req) { switch (req->type) { case VFSOP_OPEN: if (!req->input.kern) panic_invalid_state(); @@ -54,7 +54,7 @@ static int handle(struct vfs_request *req) { } } -static void accept(struct vfs_request *req) { +static void accept(VfsReq *req) { if (req->caller) { vfsreq_finish_short(req, handle(req)); } else { @@ -62,7 +62,7 @@ static void accept(struct vfs_request *req) { } } -void video_init(struct fb_info fb_) { +void video_init(GfxInfo fb_) { fb = fb_; snprintf(namebuf, sizeof namebuf, "%ux%ux%u", fb.width, fb.height, fb.bpp); namelen = strlen(namebuf); diff --git a/src/kernel/arch/amd64/driver/video.h b/src/kernel/arch/amd64/driver/video.h index dfc1710..e9dd8ae 100644 --- a/src/kernel/arch/amd64/driver/video.h +++ b/src/kernel/arch/amd64/driver/video.h @@ -1,7 +1,7 @@ #pragma once #include -struct fb_info { +struct GfxInfo { char *b; uint32_t width, height; uint32_t pitch; /* width in bytes of a single scanline */ @@ -9,4 +9,4 @@ struct fb_info { uint8_t bpp; }; -void video_init(struct fb_info); +void video_init(GfxInfo); -- cgit v1.2.3