CardSight 0.1.0
C API reference for the CardSight firmware and application
Loading...
Searching...
No Matches
vfs.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
15
16#ifndef CARDSIGHT_VFS_H
17#define CARDSIGHT_VFS_H
18
19#include <stdbool.h>
20#include <stddef.h>
21#include <stdint.h>
22#include <hal/blkdev.h>
23
25#define VFS_FD_BASE 3
27#define VFS_NAME_MAX 255
29#define VFS_PATH_MAX 512
31#define VFS_BLK_NAME 32
32
34#define VFS_O_READ 0x01
36#define VFS_O_WRITE 0x02
38#define VFS_O_CREATE 0x04
40#define VFS_O_EXCL 0x08
42#define VFS_O_TRUNC 0x10
44#define VFS_O_APPEND 0x20
45
47#define VFS_FS_NODEV 0x1
49#define VFS_FS_READ_ONLY 0x2
51#define VFS_MOUNT_READ_ONLY 0x1
53#define VFS_MOUNT_PROBE 0x2
54
58struct vfs_stat {
59 uint64_t size;
60 uint64_t alloc_size;
61 bool dir;
62 bool read_only;
63 uint16_t date;
64 uint16_t time;
65};
66
70struct vfs_dirent {
71 char name[VFS_NAME_MAX + 1];
72 struct vfs_stat st;
73};
74
79 char fstype[16];
81 uint64_t total_bytes;
82 uint64_t free_bytes;
83 uint64_t used_inodes;
84 uint32_t cluster_bytes;
85 bool read_only;
86};
87
94struct vfs_fs {
95 const char *name;
96 uint32_t flags;
97 int (*mount)(struct block_device *bdev, uint32_t flags, void **priv);
98 int (*umount)(void *priv);
99 int (*sync)(void *priv);
100 int (*format)(struct block_device *bdev, const char *label, uint32_t arg);
101 int (*open)(void *priv, const char *path, uint32_t flags, void **file);
102 int (*read)(void *file, void *buffer, size_t length);
103 int (*write)(void *file, const void *buffer, size_t length);
104 int64_t (*seek)(void *file, int64_t offset, int whence);
105 int (*truncate)(void *file, uint64_t size);
106 int (*flush)(void *file);
107 int (*close)(void *file);
108 int (*fstat)(void *file, struct vfs_stat *st);
109 int (*stat)(void *priv, const char *path, struct vfs_stat *st);
110 int (*mkdir)(void *priv, const char *path);
111 int (*unlink)(void *priv, const char *path);
112 int (*rmdir)(void *priv, const char *path);
113 int (*rename)(void *priv, const char *from, const char *to);
114 int (*opendir)(void *priv, const char *path, void **dir);
115 int (*readdir)(void *dir, struct vfs_dirent *entry);
116 int (*closedir)(void *dir);
117 int (*statfs)(void *priv, uint64_t *total, uint64_t *free_bytes);
118 int (*volume_info)(void *priv, struct vfs_volume_info *info);
119};
120
131int vfs_register(const struct vfs_fs *fs);
140int vfs_unregister(const struct vfs_fs *fs);
141
150int vfs_mount(const char *blk, const char *target, const char *fstype);
168int vfs_mount_ex(const char *blk, const char *target, const char *fstype, uint32_t flags);
179int vfs_umount(const char *target);
180
195int vfs_format(const char *blk, const char *fstype, const char *label, uint32_t arg);
205void vfs_set_format_progress(void (*callback)(void *context, uint64_t done, uint64_t total), void *context);
216void vfs_format_expect(struct block_device *bdev, uint64_t sectors);
226void vfs_format_report_write(struct block_device *bdev, uint64_t sectors);
227
240int vfs_probe(const char *blk, struct vfs_volume_info *info);
241
253int vfs_open(const char *path, uint32_t flags);
262int vfs_read(int descriptor, void *buffer, size_t length);
272int vfs_write(int descriptor, const void *buffer, size_t length);
282int64_t vfs_lseek(int descriptor, int64_t offset, int whence);
292int vfs_close(int descriptor);
300int vfs_fstat(int descriptor, struct vfs_stat *st);
308int vfs_ftruncate(int descriptor, uint64_t size);
315int vfs_fsync(int descriptor);
322int vfs_sync_mount(const char *target);
323
334int vfs_stat(const char *path, struct vfs_stat *st);
343int vfs_statfs(const char *path, uint64_t *total, uint64_t *free_bytes);
350int vfs_mkdir(const char *path);
357int vfs_unlink(const char *path);
364int vfs_rmdir(const char *path);
375int vfs_rename(const char *from, const char *to);
376
378struct vfs_dir;
390struct vfs_dir *vfs_opendir(const char *path, int *error);
398int vfs_readdir(struct vfs_dir *dir, struct vfs_dirent *entry);
404void vfs_closedir(struct vfs_dir *dir);
405
414int vfs_sync(void);
415
422 const char *fstype;
423 uint32_t open_count;
424};
425
434int vfs_mount_get(uint32_t index, struct vfs_mount_info *info);
435
436/* ---- the platform lock and the file system types ---- */
437
439void vfs_os_lock(void);
441void vfs_os_unlock(void);
442
455
456#endif /* CARDSIGHT_VFS_H */
Block devices: disks made by a driver, the partitions found in their table, and the checked transfers...
#define BDEV_LABEL_LEN
Longest partition label in bytes.
Definition blkdev.h:26
One openable view of a disk: the whole disk or one partition.
Definition blkdev.h:60
One directory entry as returned by vfs_readdir().
Definition vfs.h:70
struct vfs_stat st
Definition vfs.h:72
char name[VFS_NAME_MAX+1]
Definition vfs.h:71
Operations a file system type provides to the VFS.
Definition vfs.h:94
int(* statfs)(void *priv, uint64_t *total, uint64_t *free_bytes)
Definition vfs.h:117
int(* umount)(void *priv)
Definition vfs.h:98
int(* format)(struct block_device *bdev, const char *label, uint32_t arg)
Definition vfs.h:100
int(* fstat)(void *file, struct vfs_stat *st)
Definition vfs.h:108
int(* stat)(void *priv, const char *path, struct vfs_stat *st)
Definition vfs.h:109
int(* rename)(void *priv, const char *from, const char *to)
Definition vfs.h:113
int(* unlink)(void *priv, const char *path)
Definition vfs.h:111
int(* volume_info)(void *priv, struct vfs_volume_info *info)
Definition vfs.h:118
int64_t(* seek)(void *file, int64_t offset, int whence)
Definition vfs.h:104
uint32_t flags
Definition vfs.h:96
int(* write)(void *file, const void *buffer, size_t length)
Definition vfs.h:103
int(* opendir)(void *priv, const char *path, void **dir)
Definition vfs.h:114
int(* close)(void *file)
Definition vfs.h:107
int(* flush)(void *file)
Definition vfs.h:106
int(* sync)(void *priv)
Definition vfs.h:99
int(* mkdir)(void *priv, const char *path)
Definition vfs.h:110
int(* open)(void *priv, const char *path, uint32_t flags, void **file)
Definition vfs.h:101
int(* closedir)(void *dir)
Definition vfs.h:116
int(* mount)(struct block_device *bdev, uint32_t flags, void **priv)
Definition vfs.h:97
int(* readdir)(void *dir, struct vfs_dirent *entry)
Definition vfs.h:115
const char * name
Definition vfs.h:95
int(* truncate)(void *file, uint64_t size)
Definition vfs.h:105
int(* rmdir)(void *priv, const char *path)
Definition vfs.h:112
int(* read)(void *file, void *buffer, size_t length)
Definition vfs.h:102
One entry of the mount table.
Definition vfs.h:419
char blk[VFS_BLK_NAME]
Definition vfs.h:421
char target[VFS_NAME_MAX+1]
Definition vfs.h:420
const char * fstype
Definition vfs.h:422
uint32_t open_count
Definition vfs.h:423
Metadata of a file or directory.
Definition vfs.h:58
uint64_t alloc_size
Definition vfs.h:60
uint64_t size
Definition vfs.h:59
bool read_only
Definition vfs.h:62
bool dir
Definition vfs.h:61
uint16_t time
Definition vfs.h:64
uint16_t date
Definition vfs.h:63
Description of a volume found by vfs_probe().
Definition vfs.h:78
uint64_t free_bytes
Definition vfs.h:82
bool read_only
Definition vfs.h:85
char label[BDEV_LABEL_LEN]
Definition vfs.h:80
uint64_t total_bytes
Definition vfs.h:81
uint32_t cluster_bytes
Definition vfs.h:84
uint64_t used_inodes
Definition vfs.h:83
char fstype[16]
Definition vfs.h:79
int64_t vfs_lseek(int descriptor, int64_t offset, int whence)
Move the file position of an open descriptor.
int vfs_probe(const char *blk, struct vfs_volume_info *info)
Probe an unmounted block device.
int vfs_mount(const char *blk, const char *target, const char *fstype)
Mount a block device or a nodev file system at a target with default flags.
int vfs_rename(const char *from, const char *to)
Rename or move an entry.
int vfs_unregister(const struct vfs_fs *fs)
Remove a file system type from the VFS.
struct vfs_dir * vfs_opendir(const char *path, int *error)
Open a directory.
int vfs_mount_get(uint32_t index, struct vfs_mount_info *info)
Report one mount table entry by ordinal.
int vfs_fsync(int descriptor)
Flush an open file to its medium.
int vfs_umount(const char *target)
Unmount the file system at a target.
int vfs_sync_mount(const char *target)
Flush every file on one mount.
int vfs_unlink(const char *path)
Remove a file.
int vfs_rmdir(const char *path)
Remove an empty directory.
int vfs_ext_register(void)
Register the ext types: ext2, ext3, ext4.
#define VFS_NAME_MAX
Longest file name, excluding the terminating zero.
Definition vfs.h:27
void vfs_os_unlock(void)
Release the recursive VFS lock.
int vfs_register(const struct vfs_fs *fs)
Add a file system type to the VFS.
void vfs_set_format_progress(void(*callback)(void *context, uint64_t done, uint64_t total), void *context)
Observe vfs_format() progress.
int vfs_ff_register(void)
Register the FatFs types: fat, fat32, exfat.
int vfs_write(int descriptor, const void *buffer, size_t length)
Write to an open descriptor.
int vfs_mkdir(const char *path)
Create a directory.
int vfs_fstat(int descriptor, struct vfs_stat *st)
Report the metadata of an open file.
int vfs_mount_ex(const char *blk, const char *target, const char *fstype, uint32_t flags)
Mount a block device or a nodev file system at a target.
int vfs_open(const char *path, uint32_t flags)
Open a file and return a VFS descriptor.
int vfs_ftruncate(int descriptor, uint64_t size)
Resize an open file.
int vfs_readdir(struct vfs_dir *dir, struct vfs_dirent *entry)
Read the next entry of an open directory.
int vfs_sync(void)
Write everything out on every mount.
void vfs_format_expect(struct block_device *bdev, uint64_t sectors)
Declare how many sectors the running format will write.
int vfs_stat(const char *path, struct vfs_stat *st)
Report the metadata of a path.
int vfs_close(int descriptor)
Close a descriptor.
int vfs_statfs(const char *path, uint64_t *total, uint64_t *free_bytes)
Report the capacity of the file system holding a path.
int vfs_format(const char *blk, const char *fstype, const char *label, uint32_t arg)
Make a new file system on an unmounted block device.
int vfs_read(int descriptor, void *buffer, size_t length)
Read from an open descriptor.
void vfs_os_lock(void)
Take the recursive VFS lock, waiting without a bound.
#define VFS_BLK_NAME
Longest block device name in a mount description.
Definition vfs.h:31
void vfs_closedir(struct vfs_dir *dir)
Close a directory and free its wrapper.
void vfs_format_report_write(struct block_device *bdev, uint64_t sectors)
Report sectors written by a formatter.