1 /*
2  * Copyright (c) 2020 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_INCLUDE_FS_FS_SYS_H_
8 #define ZEPHYR_INCLUDE_FS_FS_SYS_H_
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 /**
15  * @ingroup file_system_api
16  * @{
17  */
18 
19 /**
20  * @brief File System interface structure
21  *
22  * @param open Opens or creates a file, depending on flags given
23  * @param read Reads nbytes number of bytes
24  * @param write Writes nbytes number of bytes
25  * @param lseek Moves the file position to a new location in the file
26  * @param tell Retrieves the current position in the file
27  * @param truncate Truncates/expands the file to the new length
28  * @param sync Flushes the cache of an open file
29  * @param close Flushes the associated stream and closes the file
30  * @param opendir Opens an existing directory specified by the path
31  * @param readdir Reads directory entries of an open directory
32  * @param closedir Closes an open directory
33  * @param mount Mounts a file system
34  * @param unmount Unmounts a file system
35  * @param unlink Deletes the specified file or directory
36  * @param rename Renames a file or directory
37  * @param mkdir Creates a new directory using specified path
38  * @param stat Checks the status of a file or directory specified by the path
39  * @param statvfs Returns the total and available space on the file system
40  *        volume
41  * @param mkfs Formats a device to specified file system type. Note that this
42  *        operation destroys existing data on a target device.
43  */
44 struct fs_file_system_t {
45 	/* File operations */
46 	int (*open)(struct fs_file_t *filp, const char *fs_path,
47 		    fs_mode_t flags);
48 	ssize_t (*read)(struct fs_file_t *filp, void *dest, size_t nbytes);
49 	ssize_t (*write)(struct fs_file_t *filp,
50 					const void *src, size_t nbytes);
51 	int (*lseek)(struct fs_file_t *filp, off_t off, int whence);
52 	off_t (*tell)(struct fs_file_t *filp);
53 	int (*truncate)(struct fs_file_t *filp, off_t length);
54 	int (*sync)(struct fs_file_t *filp);
55 	int (*close)(struct fs_file_t *filp);
56 	/* Directory operations */
57 	int (*opendir)(struct fs_dir_t *dirp, const char *fs_path);
58 	int (*readdir)(struct fs_dir_t *dirp, struct fs_dirent *entry);
59 	int (*closedir)(struct fs_dir_t *dirp);
60 	/* File system level operations */
61 	int (*mount)(struct fs_mount_t *mountp);
62 	int (*unmount)(struct fs_mount_t *mountp);
63 	int (*unlink)(struct fs_mount_t *mountp, const char *name);
64 	int (*rename)(struct fs_mount_t *mountp, const char *from,
65 					const char *to);
66 	int (*mkdir)(struct fs_mount_t *mountp, const char *name);
67 	int (*stat)(struct fs_mount_t *mountp, const char *path,
68 					struct fs_dirent *entry);
69 	int (*statvfs)(struct fs_mount_t *mountp, const char *path,
70 					struct fs_statvfs *stat);
71 #if defined(CONFIG_FILE_SYSTEM_MKFS)
72 	int (*mkfs)(uintptr_t dev_id, void *cfg, int flags);
73 #endif
74 };
75 
76 /**
77  * @}
78  */
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif /* ZEPHYR_INCLUDE_FS_FS_SYS_H_ */
85