-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A process can now declare itself to be a terminal with the `maketty` system call. This gives it a new file descriptor corresponding to stdout, that is then inherited by the processes it executes, and the processes those execute, etc... It's the terminal's job to read from stdout (a strange concept, I know) and do something with it. `stdout` is backed by a circular buffer; old content may be overwritten if not read.
- Loading branch information
Showing
14 changed files
with
215 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include <kernel/fs.h> | ||
|
||
typedef struct pipe_t { | ||
inode_t inode; | ||
uint8_t* buf; | ||
uint32_t index; | ||
} pipe_t; | ||
|
||
inode_t* pipe_new(); | ||
inode_t* pipe_clone(inode_t* pipe); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include <kernel/pipe.h> | ||
#include <kernel/sys.h> | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#define PIPE_SIZE 2048 | ||
|
||
typedef struct pipe_fs_t { | ||
fs_t fs; | ||
uint8_t* buf; | ||
uint32_t buf_size; | ||
uint32_t content_start; | ||
uint32_t content_size; | ||
uint32_t refcount; | ||
} pipe_fs_t; | ||
|
||
uint32_t pipe_read(pipe_fs_t* pipe, uint32_t inode, uint32_t offset, uint8_t* buf, uint32_t size) { | ||
UNUSED(inode); // There's only one "file" in this fs, the pipe itself | ||
UNUSED(offset); | ||
|
||
for (uint32_t i = 0; i < size; i++) { | ||
if (!pipe->content_size) { | ||
return i; | ||
} | ||
|
||
buf[i] = pipe->buf[pipe->content_start]; | ||
pipe->content_start = (pipe->content_start + 1) % pipe->buf_size; | ||
pipe->content_size--; | ||
} | ||
|
||
return size; | ||
} | ||
|
||
uint32_t pipe_append(pipe_fs_t* pipe, uint32_t inode, uint8_t* data, uint32_t size) { | ||
UNUSED(inode); | ||
|
||
for (uint32_t i = 0; i < size; i++) { | ||
if (pipe->content_size == PIPE_SIZE) { | ||
pipe->buf[pipe->content_start] = data[i]; | ||
pipe->content_start = (pipe->content_start + 1) % pipe->buf_size; | ||
} else { | ||
pipe->buf[(pipe->content_start + pipe->content_size) % pipe->buf_size] = data[i]; | ||
pipe->content_size++; | ||
} | ||
} | ||
|
||
return size; | ||
} | ||
|
||
int32_t pipe_close(pipe_fs_t* fs, uint32_t ino) { | ||
UNUSED(ino); | ||
|
||
if (--fs->refcount == 0) { | ||
kfree(fs->buf); | ||
kfree(fs->fs.root); | ||
kfree(fs); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
inode_t* pipe_new() { | ||
// TODO: have root inodes not necessarily be folders? | ||
inode_t* p = zalloc(sizeof(folder_inode_t)); | ||
p->fs = zalloc(sizeof(pipe_fs_t)); | ||
|
||
pipe_fs_t* fs = (pipe_fs_t*) p->fs; | ||
fs->buf = zalloc(PIPE_SIZE); | ||
fs->buf_size = PIPE_SIZE; | ||
fs->refcount = 1; | ||
|
||
p->fs->root = (folder_inode_t*) p; | ||
p->fs->read = (fs_read_t) pipe_read; | ||
p->fs->append = (fs_append_t) pipe_append; | ||
p->fs->close = (fs_close_t) pipe_close; | ||
|
||
return p; | ||
} | ||
|
||
inode_t* pipe_clone(inode_t* pipe) { | ||
((pipe_fs_t*) pipe->fs)->refcount++; | ||
|
||
return pipe; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
#pragma once | ||
|
||
#include <stddef.h> | ||
#include <kernel/uapi/uapi_fs.h> | ||
|
||
#define STDOUT_FILENO FS_STDOUT_FILENO | ||
|
||
#ifndef _KERNEL_ | ||
|
||
int chdir(const char* path); | ||
char* getcwd(char* buf, size_t size); | ||
int unlink(const char* path); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.