[pipe] Fix write overrun and other issues
This commit is contained in:
parent
339b82e10c
commit
1a2cb28fc1
@ -6,30 +6,33 @@
|
||||
#include <fs.h>
|
||||
#include <pipe.h>
|
||||
|
||||
#define DEBUG_PIPES 0
|
||||
|
||||
uint32_t read_pipe(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer);
|
||||
uint32_t write_pipe(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer);
|
||||
void open_pipe(fs_node_t *node, uint8_t read, uint8_t write);
|
||||
void close_pipe(fs_node_t *node);
|
||||
|
||||
static inline size_t pipe_unread(pipe_device_t * pipe) {
|
||||
if (pipe->read_ptr == pipe->write_ptr) {
|
||||
return 0;
|
||||
}
|
||||
if (pipe->read_ptr > pipe->write_ptr) {
|
||||
return (pipe->size - pipe->read_ptr) + pipe->write_ptr;
|
||||
} else {
|
||||
if (pipe->write_ptr == 0 && pipe->read_ptr == pipe->size - 1) {
|
||||
return 0;
|
||||
}
|
||||
return (pipe->write_ptr - pipe->read_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
static inline size_t pipe_available(pipe_device_t * pipe) {
|
||||
if (pipe->read_ptr > pipe->write_ptr) {
|
||||
return (pipe->read_ptr - pipe->write_ptr);
|
||||
} else {
|
||||
if (pipe->read_ptr == 0 && pipe->write_ptr == pipe->size - 1) {
|
||||
return 0;
|
||||
if (pipe->read_ptr == pipe->write_ptr) {
|
||||
return pipe->size - 1;
|
||||
}
|
||||
return (pipe->size - pipe->write_ptr)+ pipe->read_ptr;
|
||||
|
||||
if (pipe->read_ptr > pipe->write_ptr) {
|
||||
return pipe->read_ptr - pipe->write_ptr - 1;
|
||||
} else {
|
||||
return (pipe->size - pipe->write_ptr) + pipe->read_ptr - 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +56,8 @@ uint32_t read_pipe(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buf
|
||||
/* Retreive the pipe object associated with this file node */
|
||||
pipe_device_t * pipe = (pipe_device_t *)node->inode;
|
||||
|
||||
#if 0
|
||||
#if DEBUG_PIPES
|
||||
if (pipe->size > 300) { /* Ignore small pipes (ie, keyboard) */
|
||||
kprintf("[debug] Call to read from pipe 0x%x\n", node->inode);
|
||||
kprintf(" Unread bytes: %d\n", pipe_unread(pipe));
|
||||
kprintf(" Total size: %d\n", pipe->size);
|
||||
@ -61,6 +65,7 @@ uint32_t read_pipe(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buf
|
||||
kprintf(" Write pointer: %d\n", pipe->write_ptr);
|
||||
kprintf(" Read pointer: %d\n", pipe->read_ptr);
|
||||
kprintf(" Buffer address: 0x%x\n", pipe->buffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t collected = 0;
|
||||
@ -87,7 +92,8 @@ uint32_t write_pipe(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *bu
|
||||
/* Retreive the pipe object associated with this file node */
|
||||
pipe_device_t * pipe = (pipe_device_t *)node->inode;
|
||||
|
||||
#if 0
|
||||
#if DEBUG_PIPES
|
||||
if (pipe->size > 300) { /* Ignore small pipes (ie, keyboard) */
|
||||
kprintf("[debug] Call to write to pipe 0x%x\n", node->inode);
|
||||
kprintf(" Available space: %d\n", pipe_available(pipe));
|
||||
kprintf(" Total size: %d\n", pipe->size);
|
||||
@ -95,6 +101,8 @@ uint32_t write_pipe(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *bu
|
||||
kprintf(" Write pointer: %d\n", pipe->write_ptr);
|
||||
kprintf(" Read pointer: %d\n", pipe->read_ptr);
|
||||
kprintf(" Buffer address: 0x%x\n", pipe->buffer);
|
||||
kprintf(" Write: %s\n", buffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t written = 0;
|
||||
|
@ -137,13 +137,6 @@ int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp)
|
||||
parse_args(cmdline);
|
||||
}
|
||||
|
||||
/* Switch to a userspace page directory */
|
||||
#if 0
|
||||
page_directory_t * directory = clone_directory(kernel_directory);
|
||||
set_process_environment((process_t *)current_process, directory);
|
||||
switch_page_directory(directory);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* XXX: Execute /bin/init
|
||||
*/
|
||||
@ -158,7 +151,7 @@ int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp)
|
||||
while (argv[argc]) {
|
||||
argc++;
|
||||
}
|
||||
system("/bin/terminal", argc, argv);
|
||||
system("/bin/terminal", argc, argv); /* Run init */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ process_t * spawn_init() {
|
||||
/* Set its tree entry pointer so we can keep track
|
||||
* of the process' entry in the process tree. */
|
||||
init->tree_entry = process_tree->root;
|
||||
init->id = 1; /* Init is PID 1 */
|
||||
init->id = 0; /* Init is PID 1 */
|
||||
init->name = "init"; /* Um, duh. */
|
||||
init->user = 0; /* UID 0 */
|
||||
init->group = 0; /* Task group 0 */
|
||||
@ -185,7 +185,7 @@ process_t * spawn_init() {
|
||||
*/
|
||||
pid_t get_next_pid() {
|
||||
/* Terribly naïve, I know, but it works for now */
|
||||
static pid_t next = 2;
|
||||
static pid_t next = 1;
|
||||
return (next++);
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,13 @@ int main(int argc, char ** argv) {
|
||||
while (length > CHUNK_SIZE) {
|
||||
fread( buf, 1, CHUNK_SIZE, fd);
|
||||
fwrite(buf, 1, CHUNK_SIZE, stdout);
|
||||
fflush(stdout);
|
||||
length -= CHUNK_SIZE;
|
||||
}
|
||||
if (length > 0) {
|
||||
fread( buf, 1, length, fd);
|
||||
fwrite(buf, 1, length, stdout);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
|
@ -2813,25 +2813,5 @@ int main(int argc, char ** argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
ansi_print("Hello World!\nThis is a test.\n\033[1;32mHello and thank you\n\033[0mDone.\n");
|
||||
|
||||
#if 0
|
||||
cat("/etc/.vim");
|
||||
|
||||
fgetc(stdin);
|
||||
#endif
|
||||
|
||||
ansi_print("\033[H\033[2J");
|
||||
|
||||
cat("/etc/color-test");
|
||||
|
||||
ansi_print("\033[1m[\033[1;33mklange \033[1;32mpiko \033[1;31m01/23 \033[1;34m22:33:27 \033[1;32mgit\033[1;33m master\033[0m \033[0m~/osdev\033[1m]\033[0m\n\033[1;32m$\033[0m exit");
|
||||
|
||||
ansi_print("\n\033[1mBold \033[0m\033[3mItalic \033[1mBold+Italic\033[0m\033[0m \033[4mUnderline\033[0m \033[9mX-Out\033[0m \033[1;3;4;9mEverything\033[0m\n");
|
||||
|
||||
fgetc(stdin);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user