Line data Source code
1 0 : /*
2 : * Copyright (c) 2016 Intel Corporation.
3 : * Copyright (c) 2020-2024 Nordic Semiconductor ASA
4 : *
5 : * SPDX-License-Identifier: Apache-2.0
6 : */
7 :
8 : #ifndef ZEPHYR_INCLUDE_FS_FS_H_
9 : #define ZEPHYR_INCLUDE_FS_FS_H_
10 :
11 : #include <sys/types.h>
12 :
13 : #include <zephyr/sys/dlist.h>
14 : #include <zephyr/fs/fs_interface.h>
15 :
16 : #ifdef __cplusplus
17 : extern "C" {
18 : #endif
19 :
20 : /**
21 : * @brief File System APIs
22 : * @defgroup file_system_api File System APIs
23 : * @since 1.5
24 : * @version 1.0.0
25 : * @ingroup os_services
26 : * @{
27 : */
28 : struct fs_file_system_t;
29 :
30 : /**
31 : * @brief Enumeration for directory entry types
32 : */
33 1 : enum fs_dir_entry_type {
34 : /** Identifier for file entry */
35 : FS_DIR_ENTRY_FILE = 0,
36 : /** Identifier for directory entry */
37 : FS_DIR_ENTRY_DIR
38 : };
39 :
40 : /** @brief Enumeration to uniquely identify file system types.
41 : *
42 : * Zephyr supports in-tree file systems and external ones. Each
43 : * requires a unique identifier used to register the file system
44 : * implementation and to associate a mount point with the file system
45 : * type. This anonymous enum defines global identifiers for the
46 : * in-tree file systems.
47 : *
48 : * External file systems should be registered using unique identifiers
49 : * starting at @c FS_TYPE_EXTERNAL_BASE. It is the responsibility of
50 : * applications that use external file systems to ensure that these
51 : * identifiers are unique if multiple file system implementations are
52 : * used by the application.
53 : */
54 1 : enum {
55 : /** Identifier for in-tree FatFS file system. */
56 : FS_FATFS = 0,
57 :
58 : /** Identifier for in-tree LittleFS file system. */
59 : FS_LITTLEFS,
60 :
61 : /** Identifier for in-tree Ext2 file system. */
62 : FS_EXT2,
63 :
64 : /** Identifier for in-tree Virtiofs file system. */
65 : FS_VIRTIOFS,
66 :
67 : /** Base identifier for external file systems. */
68 : FS_TYPE_EXTERNAL_BASE,
69 : };
70 :
71 : /** Flag prevents formatting device if requested file system not found */
72 1 : #define FS_MOUNT_FLAG_NO_FORMAT BIT(0)
73 : /** Flag makes mounted file system read-only */
74 1 : #define FS_MOUNT_FLAG_READ_ONLY BIT(1)
75 : /** Flag used in pre-defined mount structures that are to be mounted
76 : * on startup.
77 : *
78 : * This flag has no impact in user-defined mount structures.
79 : */
80 1 : #define FS_MOUNT_FLAG_AUTOMOUNT BIT(2)
81 : /** Flag requests file system driver to use Disk Access API. When the flag is
82 : * set to the fs_mount_t.flags prior to fs_mount call, a file system
83 : * needs to use the Disk Access API, otherwise mount callback for the driver
84 : * should return -ENOTSUP; when the flag is not set the file system driver
85 : * should use Flash API by default, unless it only supports Disc Access API.
86 : * When file system will use Disk Access API and the flag is not set, the mount
87 : * callback for the file system should set the flag on success.
88 : */
89 1 : #define FS_MOUNT_FLAG_USE_DISK_ACCESS BIT(3)
90 :
91 : /**
92 : * @brief File system mount info structure
93 : */
94 1 : struct fs_mount_t {
95 : /** Entry for the fs_mount_list list */
96 1 : sys_dnode_t node;
97 : /** File system type */
98 1 : int type;
99 : /** Mount point directory name (ex: "/fatfs") */
100 1 : const char *mnt_point;
101 : /** Pointer to file system specific data */
102 1 : void *fs_data;
103 : /** Pointer to backend storage device */
104 1 : void *storage_dev;
105 : /* The following fields are filled by file system core */
106 : /** Length of Mount point string */
107 1 : size_t mountp_len;
108 : /** Pointer to File system interface of the mount point */
109 1 : const struct fs_file_system_t *fs;
110 : /** Mount flags */
111 1 : uint8_t flags;
112 : };
113 :
114 : /**
115 : * @brief Structure to receive file or directory information
116 : *
117 : * Used in functions that read the directory entries to get
118 : * file or directory information.
119 : */
120 1 : struct fs_dirent {
121 : /**
122 : * File/directory type (FS_DIR_ENTRY_FILE or FS_DIR_ENTRY_DIR)
123 : */
124 1 : enum fs_dir_entry_type type;
125 : /** Name of file or directory */
126 1 : char name[MAX_FILE_NAME + 1];
127 : /** Size of file (0 if directory). */
128 1 : size_t size;
129 : };
130 :
131 : /**
132 : * @brief Structure to receive volume statistics
133 : *
134 : * Used to retrieve information about total and available space
135 : * in the volume.
136 : */
137 1 : struct fs_statvfs {
138 : /** Optimal transfer block size */
139 1 : unsigned long f_bsize;
140 : /** Allocation unit size */
141 1 : unsigned long f_frsize;
142 : /** Size of FS in f_frsize units */
143 1 : unsigned long f_blocks;
144 : /** Number of free blocks */
145 1 : unsigned long f_bfree;
146 : };
147 :
148 :
149 : /**
150 : * @name fs_open open and creation mode flags
151 : * @{
152 : */
153 : /** Open for read flag */
154 1 : #define FS_O_READ 0x01
155 : /** Open for write flag */
156 1 : #define FS_O_WRITE 0x02
157 : /** Open for read-write flag combination */
158 1 : #define FS_O_RDWR (FS_O_READ | FS_O_WRITE)
159 : /** Bitmask for read and write flags */
160 1 : #define FS_O_MODE_MASK 0x03
161 :
162 : /** Create file if it does not exist */
163 1 : #define FS_O_CREATE 0x10
164 : /** Open/create file for append */
165 1 : #define FS_O_APPEND 0x20
166 : /** Truncate the file while opening */
167 1 : #define FS_O_TRUNC 0x40
168 : /** Bitmask for open/create flags */
169 1 : #define FS_O_FLAGS_MASK 0x70
170 :
171 :
172 : /** Bitmask for open flags */
173 1 : #define FS_O_MASK (FS_O_MODE_MASK | FS_O_FLAGS_MASK)
174 : /**
175 : * @}
176 : */
177 :
178 : /**
179 : * @name fs_seek whence parameter values
180 : * @{
181 : */
182 : #ifndef FS_SEEK_SET
183 : /** Seek from the beginning of file */
184 1 : #define FS_SEEK_SET 0
185 : #endif
186 : #ifndef FS_SEEK_CUR
187 : /** Seek from a current position */
188 1 : #define FS_SEEK_CUR 1
189 : #endif
190 : #ifndef FS_SEEK_END
191 : /** Seek from the end of file */
192 1 : #define FS_SEEK_END 2
193 : #endif
194 : /**
195 : * @}
196 : */
197 :
198 : /**
199 : * @brief Get the common mount flags for an fstab entry.
200 :
201 : * @param node_id the node identifier for a child entry in a
202 : * zephyr,fstab node.
203 : * @return a value suitable for initializing an fs_mount_t flags
204 : * member.
205 : */
206 1 : #define FSTAB_ENTRY_DT_MOUNT_FLAGS(node_id) \
207 : ((DT_PROP(node_id, automount) ? FS_MOUNT_FLAG_AUTOMOUNT : 0) \
208 : | (DT_PROP(node_id, read_only) ? FS_MOUNT_FLAG_READ_ONLY : 0) \
209 : | (DT_PROP(node_id, no_format) ? FS_MOUNT_FLAG_NO_FORMAT : 0) \
210 : | (DT_PROP(node_id, disk_access) ? FS_MOUNT_FLAG_USE_DISK_ACCESS : 0))
211 :
212 : /**
213 : * @brief The name under which a zephyr,fstab entry mount structure is
214 : * defined.
215 : *
216 : * @param node_id the node identifier for a child entry in a zephyr,fstab node.
217 : */
218 1 : #define FS_FSTAB_ENTRY(node_id) _CONCAT(z_fsmp_, node_id)
219 :
220 : /**
221 : * @brief Generate a declaration for the externally defined fstab
222 : * entry.
223 : *
224 : * This will evaluate to the name of a struct fs_mount_t object.
225 : *
226 : * @param node_id the node identifier for a child entry in a zephyr,fstab node.
227 : */
228 1 : #define FS_FSTAB_DECLARE_ENTRY(node_id) \
229 : extern struct fs_mount_t FS_FSTAB_ENTRY(node_id)
230 :
231 : /**
232 : * @brief Initialize fs_file_t object
233 : *
234 : * Initializes the fs_file_t object; the function needs to be invoked
235 : * on object before first use with fs_open.
236 : *
237 : * @param zfp Pointer to file object
238 : *
239 : */
240 1 : static inline void fs_file_t_init(struct fs_file_t *zfp)
241 : {
242 : zfp->filep = NULL;
243 : zfp->mp = NULL;
244 : zfp->flags = 0;
245 : }
246 :
247 : /**
248 : * @brief Initialize fs_dir_t object
249 : *
250 : * Initializes the fs_dir_t object; the function needs to be invoked
251 : * on object before first use with fs_opendir.
252 : *
253 : * @param zdp Pointer to file object
254 : *
255 : */
256 1 : static inline void fs_dir_t_init(struct fs_dir_t *zdp)
257 : {
258 : zdp->dirp = NULL;
259 : zdp->mp = NULL;
260 : }
261 :
262 : /**
263 : * @brief Open or create file
264 : *
265 : * Opens or possibly creates a file and associates a stream with it.
266 : * Successfully opened file, when no longer in use, should be closed
267 : * with fs_close().
268 : *
269 : * @details
270 : * @p flags can be 0 or a binary combination of one or more of the following
271 : * identifiers:
272 : * - @c FS_O_READ open for read
273 : * - @c FS_O_WRITE open for write
274 : * - @c FS_O_RDWR open for read/write (<tt>FS_O_READ | FS_O_WRITE</tt>)
275 : * - @c FS_O_CREATE create file if it does not exist
276 : * - @c FS_O_APPEND move to end of file before each write
277 : * - @c FS_O_TRUNC truncate the file
278 : *
279 : * @warning If @p flags are set to 0 the function will open file, if it exists
280 : * and is accessible, but you will have no read/write access to it.
281 : *
282 : * @param zfp Pointer to a file object
283 : * @param file_name The name of a file to open
284 : * @param flags The mode flags
285 : *
286 : * @retval 0 on success;
287 : * @retval -EBUSY when zfp is already used;
288 : * @retval -EINVAL when a bad file name is given;
289 : * @retval -EROFS when opening read-only file for write, or attempting to
290 : * create a file on a system that has been mounted with the
291 : * FS_MOUNT_FLAG_READ_ONLY flag;
292 : * @retval -ENOENT when the file does not exist at the path;
293 : * @retval -ENOTSUP when not implemented by underlying file system driver;
294 : * @retval -EACCES when trying to truncate a file without opening it for write.
295 : * @retval <0 an other negative errno code, depending on a file system back-end.
296 : */
297 1 : int fs_open(struct fs_file_t *zfp, const char *file_name, fs_mode_t flags);
298 :
299 : /**
300 : * @brief Close file
301 : *
302 : * Flushes the associated stream and closes the file.
303 : *
304 : * @param zfp Pointer to the file object
305 : *
306 : * @retval 0 on success;
307 : * @retval -ENOTSUP when not implemented by underlying file system driver;
308 : * @retval <0 a negative errno code on error.
309 : */
310 1 : int fs_close(struct fs_file_t *zfp);
311 :
312 : /**
313 : * @brief Unlink file
314 : *
315 : * Deletes the specified file or directory
316 : *
317 : * @param path Path to the file or directory to delete
318 : *
319 : * @retval 0 on success;
320 : * @retval -EINVAL when a bad file name is given;
321 : * @retval -EROFS if file is read-only, or when file system has been mounted
322 : * with the FS_MOUNT_FLAG_READ_ONLY flag;
323 : * @retval -ENOTSUP when not implemented by underlying file system driver;
324 : * @retval <0 an other negative errno code on error.
325 : */
326 1 : int fs_unlink(const char *path);
327 :
328 : /**
329 : * @brief Rename file or directory
330 : *
331 : * Performs a rename and / or move of the specified source path to the
332 : * specified destination. The source path can refer to either a file or a
333 : * directory. All intermediate directories in the destination path must
334 : * already exist. If the source path refers to a file, the destination path
335 : * must contain a full filename path, rather than just the new parent
336 : * directory. If an object already exists at the specified destination path,
337 : * this function causes it to be unlinked prior to the rename (i.e., the
338 : * destination gets clobbered).
339 : * @note Current implementation does not allow moving files between mount
340 : * points.
341 : *
342 : * @param from The source path
343 : * @param to The destination path
344 : *
345 : * @retval 0 on success;
346 : * @retval -EINVAL when a bad file name is given, or when rename would cause move
347 : * between mount points;
348 : * @retval -EROFS if file is read-only, or when file system has been mounted
349 : * with the FS_MOUNT_FLAG_READ_ONLY flag;
350 : * @retval -ENOTSUP when not implemented by underlying file system driver;
351 : * @retval <0 an other negative errno code on error.
352 : */
353 1 : int fs_rename(const char *from, const char *to);
354 :
355 : /**
356 : * @brief Read file
357 : *
358 : * Reads up to @p size bytes of data to @p ptr pointed buffer, returns number
359 : * of bytes read. A returned value may be lower than @p size if there were
360 : * fewer bytes available than requested.
361 : *
362 : * @param zfp Pointer to the file object
363 : * @param ptr Pointer to the data buffer
364 : * @param size Number of bytes to be read
365 : *
366 : * @retval >=0 a number of bytes read, on success;
367 : * @retval -EBADF when invoked on zfp that represents unopened/closed file;
368 : * @retval -ENOTSUP when not implemented by underlying file system driver;
369 : * @retval <0 a negative errno code on error.
370 : */
371 1 : ssize_t fs_read(struct fs_file_t *zfp, void *ptr, size_t size);
372 :
373 : /**
374 : * @brief Write file
375 : *
376 : * Attempts to write @p size number of bytes to the specified file.
377 : * If a negative value is returned from the function, the file pointer has not
378 : * been advanced.
379 : * If the function returns a non-negative number that is lower than @p size,
380 : * the global @c errno variable should be checked for an error code,
381 : * as the device may have no free space for data.
382 : *
383 : * @param zfp Pointer to the file object
384 : * @param ptr Pointer to the data buffer
385 : * @param size Number of bytes to be written
386 : *
387 : * @retval >=0 a number of bytes written, on success;
388 : * @retval -EBADF when invoked on zfp that represents unopened/closed file;
389 : * @retval -ENOTSUP when not implemented by underlying file system driver;
390 : * @retval <0 an other negative errno code on error.
391 : */
392 1 : ssize_t fs_write(struct fs_file_t *zfp, const void *ptr, size_t size);
393 :
394 : /**
395 : * @brief Seek file
396 : *
397 : * Moves the file position to a new location in the file. The @p offset is added
398 : * to file position based on the @p whence parameter.
399 : *
400 : * @param zfp Pointer to the file object
401 : * @param offset Relative location to move the file pointer to
402 : * @param whence Relative location from where offset is to be calculated.
403 : * - @c FS_SEEK_SET for the beginning of the file;
404 : * - @c FS_SEEK_CUR for the current position;
405 : * - @c FS_SEEK_END for the end of the file.
406 : *
407 : * @retval 0 on success;
408 : * @retval -EBADF when invoked on zfp that represents unopened/closed file;
409 : * @retval -ENOTSUP if not supported by underlying file system driver;
410 : * @retval <0 an other negative errno code on error.
411 : */
412 1 : int fs_seek(struct fs_file_t *zfp, off_t offset, int whence);
413 :
414 : /**
415 : * @brief Get current file position.
416 : *
417 : * Retrieves and returns the current position in the file stream.
418 : *
419 : * @param zfp Pointer to the file object
420 : *
421 : * @retval >= 0 a current position in file;
422 : * @retval -EBADF when invoked on zfp that represents unopened/closed file;
423 : * @retval -ENOTSUP if not supported by underlying file system driver;
424 : * @retval <0 an other negative errno code on error.
425 : *
426 : * The current revision does not validate the file object.
427 : */
428 1 : off_t fs_tell(struct fs_file_t *zfp);
429 :
430 : /**
431 : * @brief Truncate or extend an open file to a given size
432 : *
433 : * Truncates the file to the new length if it is shorter than the current
434 : * size of the file. Expands the file if the new length is greater than the
435 : * current size of the file. The expanded region would be filled with zeroes.
436 : *
437 : * @note In the case of expansion, if the volume got full during the
438 : * expansion process, the function will expand to the maximum possible length
439 : * and return success. Caller should check if the expanded size matches the
440 : * requested length.
441 : *
442 : * @param zfp Pointer to the file object
443 : * @param length New size of the file in bytes
444 : *
445 : * @retval 0 on success;
446 : * @retval -EBADF when invoked on zfp that represents unopened/closed file;
447 : * @retval -ENOTSUP when not implemented by underlying file system driver;
448 : * @retval <0 an other negative errno code on error.
449 : */
450 1 : int fs_truncate(struct fs_file_t *zfp, off_t length);
451 :
452 : /**
453 : * @brief Flush cached write data buffers of an open file
454 : *
455 : * The function flushes the cache of an open file; it can be invoked to ensure
456 : * data gets written to the storage media immediately, e.g. to avoid data loss
457 : * in case if power is removed unexpectedly.
458 : * @note Closing a file will cause caches to be flushed correctly so the
459 : * function need not be called when the file is being closed.
460 : *
461 : * @param zfp Pointer to the file object
462 : *
463 : * @retval 0 on success;
464 : * @retval -EBADF when invoked on zfp that represents unopened/closed file;
465 : * @retval -ENOTSUP when not implemented by underlying file system driver;
466 : * @retval <0 a negative errno code on error.
467 : */
468 1 : int fs_sync(struct fs_file_t *zfp);
469 :
470 : /**
471 : * @brief Directory create
472 : *
473 : * Creates a new directory using specified path.
474 : *
475 : * @param path Path to the directory to create
476 : *
477 : * @retval 0 on success;
478 : * @retval -EEXIST if entry of given name exists;
479 : * @retval -EROFS if @p path is within read-only directory, or when
480 : * file system has been mounted with the FS_MOUNT_FLAG_READ_ONLY flag;
481 : * @retval -ENOTSUP when not implemented by underlying file system driver;
482 : * @retval <0 an other negative errno code on error
483 : */
484 1 : int fs_mkdir(const char *path);
485 :
486 : /**
487 : * @brief Directory open
488 : *
489 : * Opens an existing directory specified by the path.
490 : *
491 : * @param zdp Pointer to the directory object
492 : * @param path Path to the directory to open
493 : *
494 : * @retval 0 on success;
495 : * @retval -EINVAL when a bad directory path is given;
496 : * @retval -EBUSY when zdp is already used;
497 : * @retval -ENOTSUP when not implemented by underlying file system driver;
498 : * @retval <0 a negative errno code on error.
499 : */
500 1 : int fs_opendir(struct fs_dir_t *zdp, const char *path);
501 :
502 : /**
503 : * @brief Directory read entry
504 : *
505 : * Reads directory entries of an open directory. In end-of-dir condition,
506 : * the function will return 0 and set the <tt>entry->name[0]</tt> to 0.
507 : *
508 : * @note: Most existing underlying file systems do not generate POSIX
509 : * special directory entries "." or "..". For consistency the
510 : * abstraction layer will remove these from lower layer results so
511 : * higher layers see consistent results.
512 : *
513 : * @param zdp Pointer to the directory object
514 : * @param entry Pointer to zfs_dirent structure to read the entry into
515 : *
516 : * @retval 0 on success or end-of-dir;
517 : * @retval -ENOENT when no such directory found;
518 : * @retval -ENOTSUP when not implemented by underlying file system driver;
519 : * @retval <0 a negative errno code on error.
520 : */
521 1 : int fs_readdir(struct fs_dir_t *zdp, struct fs_dirent *entry);
522 :
523 : /**
524 : * @brief Directory close
525 : *
526 : * Closes an open directory.
527 : *
528 : * @param zdp Pointer to the directory object
529 : *
530 : * @retval 0 on success;
531 : * @retval -ENOTSUP when not implemented by underlying file system driver;
532 : * @retval <0 a negative errno code on error.
533 : */
534 1 : int fs_closedir(struct fs_dir_t *zdp);
535 :
536 : /**
537 : * @brief Mount filesystem
538 : *
539 : * Perform steps needed for mounting a file system like
540 : * calling the file system specific mount function and adding
541 : * the mount point to mounted file system list.
542 : *
543 : * @note Current implementation of ELM FAT driver allows only following mount
544 : * points: "/RAM:","/NAND:","/CF:","/SD:","/SD2:","/USB:","/USB2:","/USB3:"
545 : * or mount points that consist of single digit, e.g: "/0:", "/1:" and so forth.
546 : *
547 : * @param mp Pointer to the fs_mount_t structure. Referenced object
548 : * is not changed if the mount operation failed.
549 : * A reference is captured in the fs infrastructure if the
550 : * mount operation succeeds, and the application must not
551 : * mutate the structure contents until fs_unmount is
552 : * successfully invoked on the same pointer.
553 : *
554 : * @retval 0 on success;
555 : * @retval -ENOENT when file system type has not been registered;
556 : * @retval -ENOTSUP when not supported by underlying file system driver;
557 : * when @c FS_MOUNT_FLAG_USE_DISK_ACCESS is set but driver does not
558 : * support it.
559 : * @retval -EROFS if system requires formatting but @c FS_MOUNT_FLAG_READ_ONLY
560 : * has been set;
561 : * @retval <0 an other negative errno code on error.
562 : */
563 1 : int fs_mount(struct fs_mount_t *mp);
564 :
565 : /**
566 : * @brief Unmount filesystem
567 : *
568 : * Perform steps needed to unmount a file system like
569 : * calling the file system specific unmount function and removing
570 : * the mount point from mounted file system list.
571 : *
572 : * @param mp Pointer to the fs_mount_t structure
573 : *
574 : * @retval 0 on success;
575 : * @retval -EINVAL if no system has been mounted at given mount point;
576 : * @retval -ENOTSUP when not supported by underlying file system driver;
577 : * @retval <0 an other negative errno code on error.
578 : */
579 1 : int fs_unmount(struct fs_mount_t *mp);
580 :
581 : /**
582 : * @brief Get path of mount point at index
583 : *
584 : * This function iterates through the list of mount points and returns
585 : * the directory name of the mount point at the given @p index.
586 : * On success @p index is incremented and @p name is set to the mount directory
587 : * name. If a mount point with the given @p index does not exist, @p name will
588 : * be set to @c NULL.
589 : *
590 : * @param index Pointer to mount point index
591 : * @param name Pointer to pointer to path name
592 : *
593 : * @retval 0 on success;
594 : * @retval -ENOENT if there is no mount point with given index.
595 : */
596 1 : int fs_readmount(int *index, const char **name);
597 :
598 : /**
599 : * @brief File or directory status
600 : *
601 : * Checks the status of a file or directory specified by the @p path.
602 : * @note The file on a storage device may not be updated until it is closed.
603 : *
604 : * @param path Path to the file or directory
605 : * @param entry Pointer to the zfs_dirent structure to fill if the file or
606 : * directory exists.
607 : *
608 : * @retval 0 on success;
609 : * @retval -EINVAL when a bad directory or file name is given;
610 : * @retval -ENOENT when no such directory or file is found;
611 : * @retval -ENOTSUP when not supported by underlying file system driver;
612 : * @retval <0 negative errno code on error.
613 : */
614 1 : int fs_stat(const char *path, struct fs_dirent *entry);
615 :
616 : /**
617 : * @brief Retrieves statistics of the file system volume
618 : *
619 : * Returns the total and available space in the file system volume.
620 : *
621 : * @param path Path to the mounted directory
622 : * @param stat Pointer to the zfs_statvfs structure to receive the fs
623 : * statistics.
624 : *
625 : * @retval 0 on success;
626 : * @retval -EINVAL when a bad path to a directory, or a file, is given;
627 : * @retval -ENOTSUP when not implemented by underlying file system driver;
628 : * @retval <0 an other negative errno code on error.
629 : */
630 1 : int fs_statvfs(const char *path, struct fs_statvfs *stat);
631 :
632 : /**
633 : * @brief Create fresh file system
634 : *
635 : * @param fs_type Type of file system to create.
636 : * @param dev_id Id of storage device.
637 : * @param cfg Backend dependent init object. If NULL then default configuration is used.
638 : * @param flags Additional flags for file system implementation.
639 : *
640 : * @retval 0 on success;
641 : * @retval <0 negative errno code on error.
642 : */
643 1 : int fs_mkfs(int fs_type, uintptr_t dev_id, void *cfg, int flags);
644 :
645 : /**
646 : * @brief Register a file system
647 : *
648 : * Register file system with virtual file system.
649 : * Number of allowed file system types to be registered is controlled with the
650 : * CONFIG_FILE_SYSTEM_MAX_TYPES Kconfig option.
651 : *
652 : * @param type Type of file system (ex: @c FS_FATFS)
653 : * @param fs Pointer to File system
654 : *
655 : * @retval 0 on success;
656 : * @retval -EALREADY when a file system of a given type has already been registered;
657 : * @retval -ENOSCP when there is no space left, in file system registry, to add
658 : * this file system type.
659 : */
660 1 : int fs_register(int type, const struct fs_file_system_t *fs);
661 :
662 : /**
663 : * @brief Unregister a file system
664 : *
665 : * Unregister file system from virtual file system.
666 : *
667 : * @param type Type of file system (ex: @c FS_FATFS)
668 : * @param fs Pointer to File system
669 : *
670 : * @retval 0 on success;
671 : * @retval -EINVAL when file system of a given type has not been registered.
672 : */
673 1 : int fs_unregister(int type, const struct fs_file_system_t *fs);
674 :
675 : /**
676 : * @}
677 : */
678 :
679 :
680 : #ifdef __cplusplus
681 : }
682 : #endif
683 :
684 : #endif /* ZEPHYR_INCLUDE_FS_FS_H_ */
|