75 lines
1.1 KiB
C
75 lines
1.1 KiB
C
#include<stdint.h>
|
|
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
#include<string.h>
|
|
#include<time.h>
|
|
#include"fs.h"
|
|
#include"err.h"
|
|
|
|
#define GENID() 0
|
|
|
|
// Global filesystem for OS mounting
|
|
FsHdr filesystem={0};
|
|
|
|
err_t fs_mount_root(FsHdr*fs)
|
|
{
|
|
if(!fs||fs->address==NULL)
|
|
{
|
|
printf("error: cannot mount NULL filesystem\n");
|
|
return ENULL;
|
|
}
|
|
|
|
filesystem=*fs;
|
|
|
|
return EOK;
|
|
}
|
|
|
|
static const char*fs_humanreadable(size_t val)
|
|
{
|
|
static char buffer[1024]={0};
|
|
const char*append="?";
|
|
const char*const prefixes[]={"B","KiB","MiB","GiB","TiB"};
|
|
|
|
for(size_t i=0;i<sizeof(prefixes);++i)
|
|
{
|
|
if(val<1024)
|
|
{
|
|
append=prefixes[i];
|
|
break;
|
|
}
|
|
else
|
|
val/=1024;
|
|
}
|
|
|
|
sprintf(buffer,"%lu%s",val,append);
|
|
|
|
return (const char*)buffer;
|
|
}
|
|
|
|
void fs_print(const FsHdr*const fs)
|
|
{
|
|
if(!fs)
|
|
{
|
|
printf("error: cannot print NULL fs\n");
|
|
return;
|
|
}
|
|
|
|
printf("id: %#08x\n",fs->id);
|
|
printf("address: %p\n",fs->address);
|
|
printf("length: %lu (%s)\n",fs->length,fs_humanreadable(fs->length));
|
|
}
|
|
|
|
err_t fs_pathto_inode(const char*const path)
|
|
{
|
|
if(!path)
|
|
return ENULL;
|
|
return EOK;
|
|
}
|
|
|
|
err_t fs_stat(const char*const path)
|
|
{
|
|
if(!path)
|
|
return ENULL;
|
|
return EOK;
|
|
}
|