Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions createfs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if ! command -v "mcopy" >/dev/null 2>&1; then
exit 1
fi

if ! command -v "mkfs.fat" >/dev/null 2>&1; then
if ! command -v "/usr/sbin/mkfs.fat" >/dev/null 2>&1; then
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These paths should not be hardcoded. Check your $PATH to ensure you have them there, as this will break for other users

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My development operating system is OpenSUSE TW and that's why I use it that way, but I'll migrate to Manjaro in a few days. After that, I shouldn't have the problem anymore.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to switch distros to make this work, just need to add /usr/sbin to your path like:

export PATH="$PATH:/usr/sbin"

for when doing development, or put that in your ~/.bashrc or equivalent to make it happen automatically. You could probably also just symlink /usr/sbin/mkfs.fat into a directory that is in your PATH if you didn't want to accidentally be able to run other stuff from /usr/sbin, though it shouldn't matter since you'd need to be root to do anything dangerous anyway.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @codebrainz.
I known this issue regarding mkfs.fat, but i have other issue with QEMU and SDL options in OpenSUSE TW.
That's why I would like to change to Manjaro.

echo "Error: this script depends on dosfstools. Please install it" >&2
exit 1
fi
Expand Down Expand Up @@ -40,6 +40,6 @@ fi

dd if=/dev/zero of=$IMAGE bs=1M count=$SIZE_MB

mkfs.fat -F 32 -n "$VOLUME_LABEL" $IMAGE
/usr/sbin/mkfs.fat -F 32 -n "$VOLUME_LABEL" $IMAGE

mcopy -i $IMAGE -s "$FOLDER"/* ::
mcopy -i $IMAGE -s "$FOLDER"/* ::
13 changes: 9 additions & 4 deletions kernel/filesystem/fat32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,21 @@ FS_RESULT FAT32FS::open_file(const char* path, file* descriptor){
if (!buf) return FS_RESULT_NOTFOUND;
descriptor->id = reserve_fd_id();
descriptor->size = buf_ptr.size;
open_files.add(reserve_fd_id(), buf);
open_files.add(descriptor->id, buf);
//TODO: go back to using a linked list, and a static id for the file, ideally global for system
return FS_RESULT_SUCCESS;
}

size_t FAT32FS::read_file(file *descriptor, void* buf, size_t size){
void* file = open_files[descriptor->id];
//TODO: keep track of file size and limit copy to only that or less
memcpy(buf, file, size);
return size;
if (!file) {
kprintf("[FAT32] File not found in open_files for id %x", descriptor->id);
return 0;
}
// Limit to actual file size
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the improvement, but please keep the original TODO comment. We're not guaranteed that descriptor->size is the correct size, since it can be modified externally

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code itself is fine, it's just about remembering to properly implement this later on

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I will return to this section.

size_t read_size = size > descriptor->size ? descriptor->size : size;
memcpy(buf, file, read_size);
return read_size;
}

sizedptr FAT32FS::list_entries_handler(FAT32FS *instance, f32file_entry *entry, char *filename, const char *seek) {
Expand Down
56 changes: 50 additions & 6 deletions kernel/filesystem/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,19 @@ FS_RESULT open_file(const char* path, file* descriptor){
const char *search_path = path;
driver_module *mod = get_module(&search_path);
if (!mod) return FS_RESULT_NOTFOUND;

// Initialize descriptor fields to safe values before calling driver
descriptor->cursor = 0;
descriptor->size = 0;
descriptor->id = 0;

FS_RESULT result = mod->open(search_path, descriptor);

// Ensure cursor is still 0 after driver call
if (descriptor->cursor != 0) {
descriptor->cursor = 0;
}

if (!open_files)
open_files = new LinkedList<open_file_descriptors>();
open_files->push_front({
Expand All @@ -94,13 +106,45 @@ size_t read_file(file *descriptor, char* buf, size_t size){
kprintf("[FS] No open files");
return 0;
}
open_file_descriptors file = open_files->find([descriptor](open_file_descriptors kvp){

// Find the file descriptor
auto found = open_files->find([descriptor](open_file_descriptors kvp){
return descriptor->id == kvp.file_id;
})->data;
if (!file.mod) return 0;
size_t adj_size = min(size,file.file_size);
size_t amount_read = file.mod->read(descriptor, buf, adj_size, 0);
descriptor->cursor += amount_read;
});

if (!found) {
kprintf("[FS] File descriptor not found: %x", descriptor->id);
return 0;
}

open_file_descriptors file = found->data;
if (!file.mod) {
kprintf("[FS] No filesystem module for file");
return 0;
}

if (!file.mod->read) {
kprintf("[FS] No read function in filesystem module");
return 0;
}

// Fix corrupted cursor - reset to 0 for read from beginning
if (descriptor->cursor > file.file_size) {
kprintf("[FS] WARNING: Corrupted cursor %x, resetting to 0", descriptor->cursor);
descriptor->cursor = 0;
}

// Calculate how much we can actually read
size_t available = (descriptor->cursor >= file.file_size) ? 0 : (file.file_size - descriptor->cursor);
size_t read_size = min(size, available);

if (read_size == 0) {
return 0;
}

// Call the driver once for the entire read
size_t amount_read = file.mod->read(descriptor, buf, read_size, 0);

return amount_read;
}

Expand Down
86 changes: 86 additions & 0 deletions kernel/kernel_processes/boot/login_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,66 @@
#include "math/math.h"
#include "std/string.h"
#include "syscalls/syscalls.h"
#include "process/syscall.h" // For SYS_POWEROFF
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments (in the whole PR) are largely unnecessary. The code is self explanatory

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep that comment in mind.

#include "power.h" // For power_off()



// Check if the keypress contains the Ctrl+Alt+Del combination
bool is_ctrl_alt_del(keypress *kp) {
// Check for any CTRL modifier (left or right)
bool has_ctrl = (kp->modifier & (KEY_MOD_LCTRL | KEY_MOD_RCTRL)) != 0;
// Check for any ALT modifier (left or right)
bool has_alt = (kp->modifier & (KEY_MOD_LALT | KEY_MOD_RALT)) != 0;

if (!has_ctrl || !has_alt) {
return false;
}

// Check for Delete key in any of the key slots
for (int i = 0; i < 6; i++) {
if (kp->keys[i] == KEY_DELETE) {
return true;
}
}
return false;
}

// Check if the keypress contains the Ctrl+Alt+ESC combination
bool is_ctrl_alt_esc(keypress *kp) {
// Check for any CTRL modifier (left or right)
bool has_ctrl = (kp->modifier & (KEY_MOD_LCTRL | KEY_MOD_RCTRL)) != 0;
// Check for any ALT modifier (left or right)
bool has_alt = (kp->modifier & (KEY_MOD_LALT | KEY_MOD_RALT)) != 0;

if (!has_ctrl || !has_alt) {
return false;
}

// Check for ESC key in any of the key slots
for (int i = 0; i < 6; i++) {
if (kp->keys[i] == KEY_ESC) {
return true;
}
}
return false;
}

int login_screen(){
sys_focus_current();
sys_set_secure(true);
char* buf = (char*)malloc(256);
int len = 0;
keypress old_kp;
bool ctrl_alt_del_pressed = false;
bool ctrl_alt_esc_pressed = false;
const char* name = BOOTSCREEN_TEXT;
string title = string_l(name);
string subtitle = string_l("Login");
gpu_clear(BG_COLOR);
// Shutdown hint position
int button_padding = 10;

while (1)
{
gpu_size screen_size = gpu_get_screen_size();
Expand All @@ -31,13 +80,50 @@ int login_screen(){
int yo = screen_middle.y;
int height = char_size * 2;

// Draw title and subtitle
gpu_draw_string(title, (gpu_point){screen_middle.x - ((title.length/2) * char_size), yo - char_size*9}, scale, 0xFFFFFFFF);
gpu_draw_string(subtitle, (gpu_point){screen_middle.x - ((subtitle.length/2) * char_size), yo - char_size*6}, scale, 0xFFFFFFFF);

// Draw password input field
gpu_fill_rect((gpu_rect){{xo,yo - char_size/2}, {screen_size.width / 3, height}},BG_COLOR+0x111111);
gpu_draw_string(s, (gpu_point){xo, yo}, scale, 0xFFFFFFFF);

// Draw shutdown hint
string shutdown_hint = string_l("Press Ctrl+Alt+Del to shutdown");
gpu_draw_string(shutdown_hint,
(gpu_point){screen_size.width - (shutdown_hint.length * char_size) - button_padding,
screen_size.height - char_size - button_padding},
1, 0x888888); // Gray text

keypress kp;
if (sys_read_input_current(&kp)){

// Check for Ctrl+Alt+Del to shutdown
if (is_ctrl_alt_del(&kp)) {
if (!ctrl_alt_del_pressed) {
ctrl_alt_del_pressed = true;
kprintf("\nShutting down system...\n");
power_off();
// If power_off() returns (which it shouldn't), just continue
continue;
}
} else {
ctrl_alt_del_pressed = false;
}

// Check for Ctrl+Alt+ESC to reboot
if (is_ctrl_alt_esc(&kp)) {
if (!ctrl_alt_esc_pressed) {
ctrl_alt_esc_pressed = true;
kprintf("\nRebooting system...\n");
reboot();
// If reboot() returns (which it shouldn't), just continue
continue;
}
} else {
ctrl_alt_esc_pressed = false;
}

for (int i = 0; i < 6; i++){
char key = kp.keys[i];
if (hid_keycode_to_char[(uint8_t)key]){
Expand Down
18 changes: 10 additions & 8 deletions kernel/kernel_processes/windows/desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,19 @@ void Desktop::activate_current(){
kprintf("[LAUNCHER] Wrong executable format. Must be .elf");
return;
}
kprintf("[LAUNCHER] File path %s",(uintptr_t)entries[index].path);
file fd;
open_file(entries[index].path, &fd);
char *file = (char*)malloc(fd.size);
if (read_file(&fd, file, fd.size) != fd.size){
kprintf("[LAUNCHER] Failed to read full elf file");
return;
}
active_proc = load_elf_file(entries[index].name, file);
char *file_data = (char*)malloc(fd.size);
size_t bytes_read = read_file(&fd, file_data, fd.size);
if (bytes_read != fd.size){
free(file_data, fd.size);

return; // Skip if read failed
} else {
active_proc = load_elf_file(entries[index].name, file_data);
}

if (!active_proc){
kprintf("[LAUNCHER] Failed to read ELF file");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the error messages shown here, since they're the only indication of what went wrong

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

return;
}
process_active = true;
Expand Down
Loading