Compare commits

...

4 Commits

Author SHA1 Message Date
858e55118b CE Improve ls entry type hint
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m36s
2026-03-01 14:12:41 +01:00
6313191b9b CE fix amout of chars printed to file in redirection 2026-03-01 14:10:36 +01:00
a4c485587e FatFS add dir checks 2026-03-01 14:03:03 +01:00
1571469685 rename VD to TEMP 2026-03-01 13:46:39 +01:00
4 changed files with 32 additions and 15 deletions

16
ce/ce.c
View File

@@ -58,11 +58,15 @@ void cprintf (struct context* context, const char* fmt, ...) {
return; return;
} }
vsnprintf (buf, CPRINTF_BUF_MAX, fmt, args); int len = vsnprintf (buf, CPRINTF_BUF_MAX, fmt, args);
va_end (args); va_end (args);
strbuf_append_str (&context->strbuf, buf); if (len > 0) {
for (int i = 0; i < len; i++)
strbuf_append (&context->strbuf, buf[i]);
}
free (buf); free (buf);
} }
@@ -431,10 +435,14 @@ static void ls (struct context* context, const char* path_string) {
cprintf (context, "\n"); cprintf (context, "\n");
for (size_t entry_num = 0; entry_num < entries; entry_num++) { for (size_t entry_num = 0; entry_num < entries; entry_num++) {
memset (&desc, 0, sizeof (desc));
memset (&entry, 0, sizeof (entry));
read_dir_entry (path, &entry, entry_num); read_dir_entry (path, &entry, entry_num);
describe (entry.path, &desc); describe (entry.path, &desc);
cprintf (context, "%-40s%c %-40zu\n", entry.path, (desc.type == FS_DIR ? '*' : ' '), desc.size); cprintf (context, "%c %-40s %-40zu\n", (desc.type == FS_DIR ? 'D' : 'F'), entry.path,
desc.size);
} }
volume_close (); volume_close ();
@@ -489,7 +497,7 @@ static void execute_redir (struct ast_redir* redir, struct context* context) {
} }
create_file (path); create_file (path);
write_file (path, 0, (uint8_t*)context->strbuf.items, context->strbuf.count); write_file (path, 0, (uint8_t*)context->strbuf.items, context->strbuf.count - 1);
volume_close (); volume_close ();
} }

View File

@@ -61,11 +61,11 @@ void bootmain (void) {
struct device* ramdisk = device_find ("RD"); struct device* ramdisk = device_find ("RD");
vfs_create_volume ("RD", VFS_TARFS, ramdisk, false); vfs_create_volume ("RD", VFS_TARFS, ramdisk, false);
struct device* vdisk = device_find ("VD"); struct device* temp = device_find ("TEMP");
device_probe_partitions (vdisk); device_probe_partitions (temp);
struct device* vdp0 = device_find ("VDp0"); struct device* tempp0 = device_find ("TEMPp0");
vfs_create_volume ("VD", VFS_FAT32, vdp0, true); vfs_create_volume ("TEMP", VFS_FAT32, tempp0, true);
proc_pid_alloc_init (); proc_pid_alloc_init ();
procgroup_pgid_alloc_init (); procgroup_pgid_alloc_init ();

View File

@@ -119,7 +119,7 @@ void ramdisk_device_init (void) {
device_create ("RD", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init); device_create ("RD", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init);
} }
void vdisk_device_init (void) { void temp_device_init (void) {
device_op_func_t ops[] = { device_op_func_t ops[] = {
[XDRV_GET_SIZE] = &ramdrv_get_size, [XDRV_GET_SIZE] = &ramdrv_get_size,
[XDRV_GET_SECTOR_SIZE] = &ramdrv_get_sector_size, [XDRV_GET_SECTOR_SIZE] = &ramdrv_get_sector_size,
@@ -142,15 +142,15 @@ void vdisk_device_init (void) {
mbr.ptes[0].start_lba = 1; mbr.ptes[0].start_lba = 1;
mbr.ptes[0].sector_count = div_align_up (init.total_size, init.sector_size) - 1; mbr.ptes[0].sector_count = div_align_up (init.total_size, init.sector_size) - 1;
struct device* vdisk = struct device* temp =
device_create ("VD", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init); device_create ("TEMP", ops, lengthof (ops), &ramdrv_init, &ramdrv_fini, &init);
size_t sector = 0; size_t sector = 0;
size_t sector_count = 1; size_t sector_count = 1;
spin_lock (&vdisk->lock); spin_lock (&temp->lock);
device_op (vdisk, XDRV_WRITE, NULL, NULL, &sector, &sector_count, &mbr); device_op (temp, XDRV_WRITE, NULL, NULL, &sector, &sector_count, &mbr);
spin_unlock (&vdisk->lock); spin_unlock (&temp->lock);
} }
#if defined(__x86_64__) #if defined(__x86_64__)
@@ -167,7 +167,7 @@ void devices_init (void) {
terminal_device_init (); terminal_device_init ();
ramdisk_device_init (); ramdisk_device_init ();
vdisk_device_init (); temp_device_init ();
#if defined(__x86_64__) #if defined(__x86_64__)
ps2kb_device_init (); ps2kb_device_init ();

View File

@@ -179,6 +179,9 @@ int fatfs_read_file (struct vfs_volume* volume, const char* path, uint8_t* buffe
size_t size) { size_t size) {
struct fatfs_ctx* fatfs_ctx = volume->udata; struct fatfs_ctx* fatfs_ctx = volume->udata;
if (fl_is_dir (fatfs_ctx, path))
return -ST_NOT_FOUND;
FL_FILE* file = fl_fopen (fatfs_ctx, path, "wb+"); FL_FILE* file = fl_fopen (fatfs_ctx, path, "wb+");
if (file == NULL) if (file == NULL)
@@ -196,6 +199,9 @@ int fatfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buff
size_t size) { size_t size) {
struct fatfs_ctx* fatfs_ctx = volume->udata; struct fatfs_ctx* fatfs_ctx = volume->udata;
if (fl_is_dir (fatfs_ctx, path))
return -ST_NOT_FOUND;
FL_FILE* file = fl_fopen (fatfs_ctx, path, "wb+"); FL_FILE* file = fl_fopen (fatfs_ctx, path, "wb+");
if (file == NULL) if (file == NULL)
@@ -214,6 +220,9 @@ int fatfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct di
struct fatfs_ctx* fatfs_ctx = volume->udata; struct fatfs_ctx* fatfs_ctx = volume->udata;
FL_DIR dir; FL_DIR dir;
if (!fl_is_dir (fatfs_ctx, path))
return -ST_NOT_FOUND;
if (fl_opendir (fatfs_ctx, path, &dir) == NULL) if (fl_opendir (fatfs_ctx, path, &dir) == NULL)
return -ST_NOT_FOUND; return -ST_NOT_FOUND;