1 /* 2 * Copyright (c) 2016 Intel Corporation. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_INCLUDE_FS_FS_INTERFACE_H_ 8 #define ZEPHYR_INCLUDE_FS_FS_INTERFACE_H_ 9 10 #include <stdint.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 #if defined(CONFIG_FILE_SYSTEM_MAX_FILE_NAME) && (CONFIG_FILE_SYSTEM_MAX_FILE_NAME - 0) > 0 17 18 /* No in-tree file system supports name longer than 255 characters */ 19 #if (CONFIG_FILE_SYSTEM_LITTLEFS || CONFIG_FAT_FILESYSTEM_ELM || \ 20 CONFIG_FILE_SYSTEM_EXT2) && (CONFIG_FILE_SYSTEM_MAX_FILE_NAME > 255) 21 #error "Max allowed CONFIG_FILE_SYSTEM_MAX_FILE_NAME is 255 characters, when any in-tree FS enabled" 22 #endif 23 24 /* Enabled FAT driver, without LFN, restricts name length to 12 characters */ 25 #if defined(CONFIG_FAT_FILESYSTEM_ELM) && !(CONFIG_FS_FATFS_LFN) && \ 26 (CONFIG_FILE_SYSTEM_MAX_FILE_NAME > 12) 27 #error "CONFIG_FILE_SYSTEM_MAX_FILE_NAME can not be > 12 if FAT is enabled without LFN" 28 #endif 29 30 #define MAX_FILE_NAME CONFIG_FILE_SYSTEM_MAX_FILE_NAME 31 32 #else 33 /* Select from enabled file systems */ 34 35 #if defined(CONFIG_FAT_FILESYSTEM_ELM) 36 37 #if defined(CONFIG_FS_FATFS_LFN) 38 #define MAX_FILE_NAME CONFIG_FS_FATFS_MAX_LFN 39 #else /* CONFIG_FS_FATFS_LFN */ 40 #define MAX_FILE_NAME 12 /* Uses 8.3 SFN */ 41 #endif /* CONFIG_FS_FATFS_LFN */ 42 43 #endif 44 45 #if !defined(MAX_FILE_NAME) && defined(CONFIG_FILE_SYSTEM_EXT2) 46 #define MAX_FILE_NAME 255 47 #endif 48 49 #if !defined(MAX_FILE_NAME) && defined(CONFIG_FILE_SYSTEM_LITTLEFS) 50 #define MAX_FILE_NAME 255 51 #endif 52 53 #if !defined(MAX_FILE_NAME) /* filesystem selection */ 54 /* Use standard 8.3 when no filesystem is explicitly selected */ 55 #define MAX_FILE_NAME 12 56 #endif /* filesystem selection */ 57 58 #endif /* CONFIG_FILE_SYSTEM_MAX_FILE_NAME */ 59 60 61 /* Type for fs_open flags */ 62 typedef uint8_t fs_mode_t; 63 64 struct fs_mount_t; 65 66 /** 67 * @addtogroup file_system_api 68 * @{ 69 */ 70 71 /** 72 * @brief File object representing an open file 73 * 74 * The object needs to be initialized with fs_file_t_init(). 75 */ 76 struct fs_file_t { 77 /** Pointer to file object structure */ 78 void *filep; 79 /** Pointer to mount point structure */ 80 const struct fs_mount_t *mp; 81 /** Open/create flags */ 82 fs_mode_t flags; 83 }; 84 85 /** 86 * @brief Directory object representing an open directory 87 * 88 * The object needs to be initialized with fs_dir_t_init(). 89 */ 90 struct fs_dir_t { 91 /** Pointer to directory object structure */ 92 void *dirp; 93 /** Pointer to mount point structure */ 94 const struct fs_mount_t *mp; 95 }; 96 97 /** 98 * @} 99 */ 100 101 #ifdef __cplusplus 102 } 103 #endif 104 105 #endif /* ZEPHYR_INCLUDE_FS_FS_INTERFACE_H_ */ 106