#include "vfs.h"
#include "uart.h"
#include "string.h"
typedef struct {
    const char* path;
    vfs_read_fn fn;
} vfile_t;
vfile_t vtab[8];
int vcount=0;
void vfs_init(void){ vcount=0; }
void vfs_register_virtual(const char* path,vfs_read_fn fn){
    if(vcount<8) vtab[vcount++] = (vfile_t){path,fn};
}
void vfs_ls(void){
    for(int i=0;i<vcount;i++){ uart_puts(vtab[i].path); uart_puts("\n"); }
}
void vfs_cat(const char* path){
    for(int i=0;i<vcount;i++) if(strcmp(vtab[i].path,path)==0){
        char buf[64]; int r;
        while((r=vtab[i].fn(buf,sizeof(buf)))>0)
            for(int j=0;j<r;j++) uart_putc(buf[j]);
        return;
    }
    uart_puts("Not found\n");
}