mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-25 16:52:29 +00:00
feat: Massive OS expansion with IPC, Sound & TTS, Block layer, FAT32/ext2/sysfs, Signals, Syscalls, Modules, Drivers & 50+ LazyBox applets
This commit is contained in:
1 parent
5662be29f5
commit
d680335f05
64 files changed
+2370
-166
No files matched your search
@@ -0,0 +1,34 @@
|
||||
#include <fs/ext2.h>
|
||||
#include <block/block.h>
|
||||
#include <mm/kmalloc.h>
|
||||
#include <lib/string.h>
|
||||
#include <kernel/printk.h>
|
||||
|
||||
void ext2_init(void) {
|
||||
printk(KERN_INFO "EXT2: Second Extended Filesystem driver registered (Rev 0/1)\n");
|
||||
}
|
||||
|
||||
vfs_node_t* ext2_mount(const char* block_device_name) {
|
||||
block_device_t* dev = block_get_device(block_device_name);
|
||||
if (!dev) return NULL;
|
||||
|
||||
uint8_t buffer[1024];
|
||||
// Superblock is at offset 1024 (LBA 2)
|
||||
if (dev->read_sectors(dev, 2, 2, buffer) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ext2_superblock_t* sb = (ext2_superblock_t*)buffer;
|
||||
if (sb->s_magic != EXT2_SUPER_MAGIC) {
|
||||
return NULL; // Not an ext2 filesystem
|
||||
}
|
||||
|
||||
vfs_node_t* root = (vfs_node_t*)kzalloc(sizeof(vfs_node_t));
|
||||
if (!root) return NULL;
|
||||
|
||||
strcpy(root->name, "ext2_root");
|
||||
root->flags = FS_DIRECTORY;
|
||||
root->inode = 2; // ext2 root inode is always 2
|
||||
root->mode = 0755;
|
||||
return root;
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#include <fs/fat32.h>
|
||||
#include <block/block.h>
|
||||
#include <mm/kmalloc.h>
|
||||
#include <lib/string.h>
|
||||
#include <kernel/printk.h>
|
||||
|
||||
void fat32_init(void) {
|
||||
printk(KERN_INFO "FAT32: Driver registered (Supports FAT12/16/32 volumes)\n");
|
||||
}
|
||||
|
||||
vfs_node_t* fat32_mount(const char* block_device_name) {
|
||||
block_device_t* dev = block_get_device(block_device_name);
|
||||
if (!dev) return NULL;
|
||||
|
||||
fat32_bpb_t bpb;
|
||||
if (dev->read_sectors(dev, 0, 1, &bpb) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (bpb.boot_signature != 0x28 && bpb.boot_signature != 0x29) {
|
||||
return NULL; // Not a valid FAT volume
|
||||
}
|
||||
|
||||
vfs_node_t* root = (vfs_node_t*)kzalloc(sizeof(vfs_node_t));
|
||||
if (!root) return NULL;
|
||||
|
||||
strcpy(root->name, "fat32_root");
|
||||
root->flags = FS_DIRECTORY;
|
||||
root->mode = 0777;
|
||||
return root;
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
#include <fs/sysfs.h>
|
||||
#include <fs/ramfs.h>
|
||||
#include <kernel/printk.h>
|
||||
|
||||
void sysfs_init(void) {
|
||||
vfs_mkdir("/sys", 0755);
|
||||
vfs_mkdir("/sys/class", 0755);
|
||||
vfs_mkdir("/sys/devices", 0755);
|
||||
vfs_mkdir("/sys/bus", 0755);
|
||||
vfs_mkdir("/sys/bus/pci", 0755);
|
||||
vfs_mkdir("/sys/kernel", 0755);
|
||||
|
||||
vfs_node_t* sys_kernel = vfs_namei("/sys/kernel");
|
||||
if (sys_kernel) {
|
||||
ramfs_add_file(sys_kernel, "osrelease", "0.2.0-lts\n", 10);
|
||||
ramfs_add_file(sys_kernel, "ostype", "SUB-OS\n", 7);
|
||||
ramfs_add_file(sys_kernel, "hostname", "sub-node\n", 9);
|
||||
}
|
||||
|
||||
printk(KERN_INFO "SYSFS: Mounted /sys kernel object hierarchy\n");
|
||||
}
|
||||
@@ -111,6 +111,23 @@ int vfs_open(const char* path, uint32_t flags) {
|
||||
return -1; // Out of file descriptors
|
||||
}
|
||||
|
||||
int vfs_open_node(vfs_node_t* node, uint32_t flags) {
|
||||
if (!node) return -1;
|
||||
if (node->open) {
|
||||
if (node->open(node, flags) != 0) return -1;
|
||||
}
|
||||
|
||||
for (int fd = 3; fd < MAX_OPEN_FILES; fd++) {
|
||||
if (!file_descriptors[fd].node) {
|
||||
file_descriptors[fd].node = node;
|
||||
file_descriptors[fd].offset = 0;
|
||||
file_descriptors[fd].flags = flags;
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t vfs_read(int fd, void* buffer, size_t size) {
|
||||
if (fd < 0 || fd >= MAX_OPEN_FILES || !file_descriptors[fd].node) return -1;
|
||||
|
||||
|
||||
Reference in new issue
Block a user