Commit Graph

2181 Commits

Author SHA1 Message Date
d3ac590e24 Kernel: Remove the sys_getversion() syscall
User programs can now acquire this information by reading /dev/version.
2022-10-11 21:31:28 +02:00
112e375b5e Kernel: Add a FIXME 2022-10-11 21:21:27 +02:00
c30041b733 fix naming 2022-10-11 21:17:07 +02:00
88a01fcfc7 libc: make perror output to stderr 2022-10-11 21:13:38 +02:00
b67011c626 libc: Use the new write() syscall
The new one is write(fd, buf, count).
The old one was write(buf, count).

So the old one tries to pass buf as a file descriptor, and write() complains that 4000000 is too large of a file descriptor and throws EBADF.

We now use the new syscall, through the wrapper that fwrite() provides us.
2022-10-11 21:12:19 +02:00
0f47f59364 libc: make fprintf actually write to the chosen file
Also, printf now is kind of an alias for fprintf(stdout,...), as it should be.
2022-10-11 21:10:19 +02:00
2f46e46aa4 libc: Implement fwrite()
Now that we have the write() syscall and libc wrapper, fwrite can finally be implemented.
2022-10-11 21:09:30 +02:00
80ab982fe4 libc: make stdout and stderr functional
what were before one extern FILE* without reference now are opened by libc on program initialization, to point to /dev/console by default.
2022-10-11 21:08:46 +02:00
53a4b3b85e libc: Add new flags to open()
Since we now have write support, we can add O_WRONLY and O_RDWR to fcntl.h :)
2022-10-11 21:07:21 +02:00
12cf37d0a7 Kernel/syscalls: Modify sys_write to accept a file descriptor and write to it
Previously, sys_write only wrote to the tty. Now, it uses the VFS interface, as it should.
2022-10-11 21:06:12 +02:00
e764647133 Devices: add a new ConsoleDevice
This new device is the userspace interface to the text console/tty.
2022-10-11 21:04:50 +02:00
b1fcfd0d74 VersionDevice: Ignore offset instead of erroring out + set flags to 0 2022-10-11 21:04:14 +02:00
e67ef7778c VFS: Support writing to files 2022-10-11 21:03:30 +02:00
f6e783ea45 init: do not show 'read n bytes' when printing version
that was to debug why reading /dev/version returned 'versionmoon 0.10-' instead of 'moon 0.10-fffffff'

it works now, so...
2022-10-11 20:13:00 +02:00
8e57df518f apps: build with optimizations enabled 2022-10-11 19:57:24 +02:00
0c451e504e Kernel: Mounting /dev MUST succeed 2022-10-11 19:53:55 +02:00
04da26bff5 kernel: add a few comments 2022-10-11 19:51:24 +02:00
feb8c1c31b libc: Implement strchr() 2022-10-11 19:50:18 +02:00
0131193379 ELFLoader, Scheduler: Transition to use VFS
We should start to drop the old InitRD API, which only allows for files to be loaded from the initrd, and which forces pathnames to be relative (bin/init)
With VFS, we can load any kind of file from any kind of filesystem, and using paths that make sense (/bin/init)
2022-10-11 19:33:48 +02:00
86b50a6aa0 Remove random demos
Cool, but cumbersome in practice: have to continually restart until I get the demo I want.

So let's stick to init for now.
2022-10-11 19:25:19 +02:00
0a7d4a530d VFS, DeviceFS: Implement a device filesystem
For now, we just have a version device. (this will allow us to get rid of sys_getversion!!)
More should be implemented soon.
2022-10-11 19:21:16 +02:00
a198cf8d8d Add initrd_mkdir to registered directories in the initrd 2022-10-11 18:25:11 +02:00
4aa3da8c12 VFS: Add basic mount(), unmount() and mkdir() functions (not accessible to userspace yet) 2022-10-11 18:23:00 +02:00
1278cec065 VFS: Add a 'type' flag to Nodes, implement EISDIR 2022-10-11 17:48:11 +02:00
7a097f16ea apps: add a new example app which does all kinds of stdio misbehaving >.< 2022-10-11 17:31:06 +02:00
667d308fc3 kernel/main.cpp: remove obsolete reference to _userspace 2022-10-11 17:30:40 +02:00
6088031c49 stdio: log stuff more 2022-10-11 17:19:03 +02:00
81815a0bdd Refactor sys/stdio.cpp 2022-10-11 17:10:44 +02:00
2a755fcd93 sys_open(): actually return EMFILE if the process has used all of its file slots 2022-10-11 17:03:16 +02:00
6c51477197 libc: Implement ferror() and feof() 2022-10-11 16:57:08 +02:00
d25e8a43db build system: strip apps 2022-10-10 21:24:21 +02:00
4f2b3ce5d1 fclose: restore errno after call to free() if close() fails 2022-10-10 21:18:24 +02:00
93f6be9319 libc: Implement the start of a FILE* API (the standard, portable C way of doing file stuff) 2022-10-10 21:08:57 +02:00
9e0bd39964 libc: Implement wrappers for sys_{open,read,write}
read() and close() are in unistd.h, but open() in fnctl.h.
I thought only the definitions for O_SOMETHING were in fnctl.h, but it is as it is.
Don't know why, but let's not anger the Unix gods.

The FILE* C API is pending as well.
2022-10-10 20:45:26 +02:00
1b84c443fe Merge branch VFS into main
Reviewed-on: #10
2022-10-10 18:25:43 +00:00
da2ede3450 Kernel, libc, userspace: Implement file descriptors
Kernel: Implement a descriptor struct which stores the opened node and read offset, and give each task 8 of those.
Implement three syscalls: sys_read, sys_open and sys_close (sys_write still writes to the console instead of using a fd, for now)
Implement three new errors: ENOENT, EBADF and EMFILE.

libc: Implement the new errors, and the new syscalls in syscall().
Also fix _RETURN_WITH_ERRNO() to set errno correctly, which was making strerror() return null, thus crashing perror().

userspace: make init demonstrate the new file API.
2022-10-10 20:21:39 +02:00
63b2de4e3c Basic FDs 2022-10-10 19:00:24 +02:00
da84f1713c InitRD: Use get_blocks_from_size() 2022-10-10 18:45:49 +02:00
bbe7c6e658 VFS: Implement resolve_path and form the initial ramdisk's VFS properly
Finally, resolve_path: a function which takes a path (/etc/fstab for example), and walks the VFS:
In this case, it would start with the root FS node, and ask it: "do you have a directory/file named etc?"
The node could say 'yes', 'no', or 'i'm not a directory, I'm a file' (should not be the case for the VFS root, but for the other ones it could be)
If it says yes, we continue and ask the child if it has a file named fstab. Etc...
2022-10-10 18:44:43 +02:00
2be70d0bc1 VFS: Use 64-bit numbers in read()
There is no need for any kind of 32-bit compatibility.
2022-10-09 21:30:38 +02:00
8158ddc94f VFS: be more verbose 2022-10-09 21:19:22 +02:00
b38c52f8c7 more vfs stuff 2022-10-08 21:35:19 +02:00
f3d7e220ac The beginnings of a VFS implementation!! 2022-10-08 21:22:46 +02:00
49c7900407 Add %m to userspace printf
%m as a format specifier is a nonstandard glibc extension, but I like it so I'm implementing it.
What it does is print the value of strerror(errno), without consuming any arguments to printf().
2022-10-08 18:44:14 +02:00
4b74c14f1b Merge branch printf_pointers into main
Reviewed-on: #9
2022-10-08 16:27:37 +00:00
3686e03bb7 Cast %p usage to void*
Apparently, %p only accepts void*, and not any pointer type. Still better than casting a pointer to uint64_t.
2022-10-08 18:27:05 +02:00
3feb7782bc Kernel/mmap, munmap: Use %p in printf 2022-10-08 18:24:05 +02:00
d5f59b666a Kernel/Memory: Use %p in printf 2022-10-08 18:21:02 +02:00
8ce58e9e30 Kernel/InitRD: Use %p with printf() 2022-10-08 18:16:55 +02:00
5fc543c179 Kernel/ACPI: Use printf() with %p 2022-10-08 18:15:08 +02:00