From 264a5adff5ef0775a6f7f70a3245cbfd4e62e178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 29 Mar 2004 12:28:34 +0000 Subject: [PATCH] NewOS read/write hooks return ssize_t, but on BeOS, they return status_t and the number of bytes read/written in an argument. Until now, we had a buggy mix between those two solutions. Courtesy of Jack Burton. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7101 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/drivers/arch/x86/console/console.c | 107 ++++++++++++------ src/kernel/drivers/fb_console/fb_console.c | 59 +++++++--- 2 files changed, 114 insertions(+), 52 deletions(-) diff --git a/src/kernel/drivers/arch/x86/console/console.c b/src/kernel/drivers/arch/x86/console/console.c index efbefedf4f..de2a32f817 100755 --- a/src/kernel/drivers/arch/x86/console/console.c +++ b/src/kernel/drivers/arch/x86/console/console.c @@ -51,7 +51,8 @@ static unsigned char attr=0x07; static mutex console_lock; static int keyboard_fd = -1; -static void update_cursor(unsigned int x, unsigned int y) +static void +update_cursor(unsigned int x, unsigned int y) { short int pos = y*columns + x; @@ -61,7 +62,9 @@ static void update_cursor(unsigned int x, unsigned int y) out8((char)(pos >> 8), TEXT_DATA); } -static void gotoxy(unsigned int new_x,unsigned int new_y) + +static void +gotoxy(unsigned int new_x,unsigned int new_y) { if (new_x>=columns || new_y>=lines) return; @@ -70,7 +73,9 @@ static void gotoxy(unsigned int new_x,unsigned int new_y) pos = origin+((y*columns+x)<<1); } -static void scrup(void) + +static void +scrup(void) { unsigned long i; @@ -86,7 +91,9 @@ static void scrup(void) } } -static void lf(void) + +static void +lf(void) { if (y+1 0) { pos -= 2; @@ -111,23 +121,30 @@ static void del(void) } } -static int saved_x=0; -static int saved_y=0; -static void save_cur(void) +static int saved_x = 0; +static int saved_y = 0; + + +static void +save_cur(void) { saved_x=x; saved_y=y; } -static void restore_cur(void) + +static void +restore_cur(void) { x=saved_x; y=saved_y; pos=origin+((y*columns+x)<<1); } -static char console_putch(const char c) + +static char +console_putch(const char c) { if(++x>=COLUMNS) { cr(); @@ -142,7 +159,9 @@ static char console_putch(const char c) return c; } -static void tab(void) + +static void +tab(void) { x = (x + TAB_SIZE) & ~TAB_MASK; if (x >= COLUMNS) { @@ -152,39 +171,49 @@ static void tab(void) pos = origin + ((y * columns + x) << 1); } -static status_t console_open(const char *name, uint32 flags, void **cookie) + +static status_t +console_open(const char *name, uint32 flags, void **cookie) { // dprintf("console_open\n"); - return 0; + return B_OK; } -static status_t console_freecookie(void * cookie) + +static status_t +console_freecookie(void * cookie) { - return 0; + return B_OK; } -static status_t console_close(void * cookie) + +static status_t +console_close(void * cookie) { // dprintf("console_close: entry\n"); - return 0; + return B_OK; } -static ssize_t console_read(void *cookie, off_t pos, void *buf, size_t *len) + +static status_t +console_read(void *cookie, off_t pos, void *buf, size_t *len) { /* XXX - optimistic!! */ *len = sys_read(keyboard_fd, 0, buf, *len); - return 0; + return B_OK; } -static ssize_t _console_write(const void *buf, size_t len) + +static ssize_t +_console_write(const void *buf, size_t len) { size_t i; const char *c; - for(i=0; i 0) + if(_console_write(((char *)buf) + 2 * sizeof(int), len - 2 * sizeof(int)) > 0) err = 0; // we're okay else err = EIO; @@ -257,6 +291,7 @@ static status_t console_ioctl(void * cookie, uint32 op, void *buf, size_t len) return err; } + device_hooks console_hooks = { &console_open, &console_close, @@ -270,7 +305,9 @@ device_hooks console_hooks = { NULL }; -int console_dev_init(kernel_args *ka) + +int +console_dev_init(kernel_args *ka) { if (!ka->fb.enabled) { dprintf("con_init: mapping vid mem\n"); diff --git a/src/kernel/drivers/fb_console/fb_console.c b/src/kernel/drivers/fb_console/fb_console.c index 3da4df969f..4aea80eadd 100755 --- a/src/kernel/drivers/fb_console/fb_console.c +++ b/src/kernel/drivers/fb_console/fb_console.c @@ -77,7 +77,8 @@ struct console_desc { static struct console_desc console; -static void render_line16(char *line, int line_num) +static void +render_line16(char *line, int line_num) { int x; int y; @@ -106,7 +107,9 @@ static void render_line16(char *line, int line_num) } } -static void render_line32(char *line, int line_num) + +static void +render_line32(char *line, int line_num) { int x; int y; @@ -136,8 +139,10 @@ static void render_line32(char *line, int line_num) } } + // scans through the lines, seeing if any needs to be repainted -static void repaint() +static void +repaint() { int i; int line_num; @@ -154,7 +159,9 @@ static void repaint() } } -static void scrup(void) + +static void +scrup(void) { int i; int line_num; @@ -176,7 +183,9 @@ static void scrup(void) console.lines[last_line][0] = 0; } -static void lf(void) + +static void +lf(void) { if(console.y + 1 < console.rows) { console.y++; @@ -185,12 +194,16 @@ static void lf(void) scrup(); } -static void cr(void) + +static void +cr(void) { console.x = 0; } -static void del(void) + +static void +del(void) { int target_line = WRAP(console.first_line + console.y, console.num_lines); @@ -201,19 +214,25 @@ static void del(void) } } -static void save_cur(void) + +static void +save_cur(void) { console.saved_x = console.x; console.saved_y = console.y; } -static void restore_cur(void) + +static void +restore_cur(void) { console.x = console.saved_x; console.y = console.saved_y; } -static char console_putch(const char c) + +static char +console_putch(const char c) { int target_line; @@ -266,14 +285,20 @@ console_close(void * cookie) } -static -ssize_t console_read(void * cookie, off_t pos, void *buffer, size_t *len) +static status_t +console_read(void * cookie, off_t pos, void *buffer, size_t *_length) { - return sys_read(console.keyboard_fd, 0, buffer, *len); + ssize_t bytesRead = sys_read(console.keyboard_fd, 0, buffer, *_length); + if (bytesRead >= 0) { + *_length = bytesRead; + return B_OK; + } + + return bytesRead; } -static ssize_t +static status_t _console_write(const void *buf, size_t *len) { size_t i; @@ -301,14 +326,14 @@ _console_write(const void *buf, size_t *len) console_putch(*c); } } - return 0; + return B_OK; } -static ssize_t +static status_t console_write(void * cookie, off_t pos, const void *buffer, size_t *len) { - ssize_t err; + status_t err; // dprintf("console_write: entry, len = %d\n", len);