/***************************************************************************** * Copyright (c) 2019, Nations Technologies Inc. * * All rights reserved. * **************************************************************************** * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the disclaimer below. * * Nations' name may not be used to endorse or promote products derived from * this software without specific prior written permission. * * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ /** * @file dfs_fs.h * @author Nations * @version v1.0.0 * * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved. */ #ifndef __DFS_FS_H__ #define __DFS_FS_H__ #include #ifdef __cplusplus extern "C" { #endif /* Pre-declaration */ struct dfs_filesystem; struct dfs_fd; /* File system operations */ struct dfs_filesystem_ops { char *name; uint32_t flags; /* flags for file system operations */ /* operations for file */ const struct dfs_file_ops *fops; /* mount and unmount file system */ int (*mount) (struct dfs_filesystem *fs, unsigned long rwflag, const void *data); int (*unmount) (struct dfs_filesystem *fs); /* make a file system */ int (*mkfs) (rt_device_t devid); int (*statfs) (struct dfs_filesystem *fs, struct statfs *buf); int (*unlink) (struct dfs_filesystem *fs, const char *pathname); int (*stat) (struct dfs_filesystem *fs, const char *filename, struct stat *buf); int (*rename) (struct dfs_filesystem *fs, const char *oldpath, const char *newpath); }; /* Mounted file system */ struct dfs_filesystem { rt_device_t dev_id; /* Attached device */ char *path; /* File system mount point */ const struct dfs_filesystem_ops *ops; /* Operations for file system type */ void *data; /* Specific file system data */ }; /* file system partition table */ struct dfs_partition { uint8_t type; /* file system type */ off_t offset; /* partition start offset */ size_t size; /* partition size */ rt_sem_t lock; }; /* mount table */ struct dfs_mount_tbl { const char *device_name; const char *path; const char *filesystemtype; unsigned long rwflag; const void *data; }; int dfs_register(const struct dfs_filesystem_ops *ops); struct dfs_filesystem *dfs_filesystem_lookup(const char *path); const char *dfs_filesystem_get_mounted_path(struct rt_device *device); int dfs_filesystem_get_partition(struct dfs_partition *part, uint8_t *buf, uint32_t pindex); int dfs_mount(const char *device_name, const char *path, const char *filesystemtype, unsigned long rwflag, const void *data); int dfs_unmount(const char *specialfile); int dfs_mkfs(const char *fs_name, const char *device_name); int dfs_statfs(const char *path, struct statfs *buffer); int dfs_mount_device(rt_device_t dev); #ifdef __cplusplus } #endif #endif