vfs.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* Virtual filesystem: mounts every device with a valid FAT filesystem under
  2. * `/` (e.g. /floppy0, /floppy1, /ide0p1). Provides path resolution so the
  3. * shell commands operate on the right filesystem. */
  4. #ifndef VFS_H
  5. #define VFS_H
  6. #include "fat.h"
  7. typedef struct {
  8. char name[16];
  9. fat_fs_t fs;
  10. int mounted;
  11. } vfs_mount_t;
  12. #define VFS_MAX_MOUNTS 12
  13. #define VFS_PATH_MAX 64
  14. extern vfs_mount_t vfs_mounts[VFS_MAX_MOUNTS];
  15. extern unsigned int vfs_mount_count;
  16. /* Scan devices and mount all detected FAT filesystems. */
  17. void vfs_mount_all(void);
  18. /* Find a mount by name (NULL if not found). */
  19. vfs_mount_t *vfs_find(const char *name);
  20. /* Print the mount list (for `ls /`). */
  21. void vfs_list_root(void);
  22. /* Resolve an absolute path "/<mount>/<path>" into (fs, fs_path). The fs_path
  23. * points into `path` (no copy). Returns 0 on success, -1 on error. */
  24. int vfs_resolve(const char *path, fat_fs_t **fs, const char **fs_path);
  25. /* Join `arg` onto `cwd` (arg may be absolute or relative) and normalize the
  26. * result into `out` as an absolute VFS path. "." and duplicate slashes are
  27. * dropped; ".." pops the previous component (popping the mount name yields
  28. * "/", and ".." at "/" stays "/"). Returns 0 on success, -1 if it doesn't fit. */
  29. int vfs_join_path(const char *cwd, const char *arg, char *out, unsigned int out_size);
  30. /* After a failed vfs_resolve, returns 1 if the path's first component names a
  31. * known block device (i.e. it exists but has no mounted filesystem). */
  32. int vfs_device_known(const char *path);
  33. #endif