#include "file_system_struct.h"
#include <verify_area.h>
#include <kmalloc.h>
#include <segment.h>
#include <errno.h>
#include <consts.h>
#include <sprintf.h>
#include <stddef.h>
#define FILESYSTEM_NAME_MAX 32
extern const struct file_system_struct rootfs;
extern const struct file_system_struct devfs;
extern const struct file_system_struct procfs;
extern const struct file_system_struct vfat;
extern const struct file_system_struct ramfs;
static const struct file_system_struct *file_system_table[] = {
&rootfs,
&devfs,
&procfs,
&vfat,
&ramfs
};
static const unsigned int file_system_table_size = sizeof file_system_table / sizeof *file_system_table;
static inline int fs_strcmp(const char *fs_s1, const char *s2)
{
char c;
while ((c = get_fs_byte(fs_s1)) && c == *s2)
fs_s1++, s2++;
return c - *s2;
}
int get_file_system(const char *fs_type, const struct file_system_struct **file_system)
{
const struct file_system_struct **fs;
if (!verify_str(fs_type, FILESYSTEM_NAME_MAX, NULL))
return -EFAULT;
for (fs = &file_system_table[0]; fs < &file_system_table[file_system_table_size]; fs++)
if (!fs_strcmp(fs_type, (*fs)->name)) {
*file_system = *fs;
return 0;
}
return -ENODEV;
}
int print_file_systems(char *buf, unsigned int size)
{
char *s;
const struct file_system_struct **fs;
unsigned int n;
s = buf;
for (fs = &file_system_table[0]; fs < &file_system_table[file_system_table_size]; fs++) {
n = snprintf(s, size, "%-8s%s\n", (*fs)->type == FT_BLK ? "" : "nodev", (*fs)->name);
s += n;
size = size > n ? size - n : 0;
}
return s - buf;
}