forked from xuos/xiuos
First commit XiUOS
This commit is contained in:
133
fs/shared/include/iot-vfs.h
Normal file
133
fs/shared/include/iot-vfs.h
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
#ifndef _INC_IOT_VFS_H_
|
||||
#define _INC_IOT_VFS_H_
|
||||
|
||||
#include <xiuos.h>
|
||||
#include <bus.h>
|
||||
|
||||
#define MAX_FILE_NAME 255
|
||||
#define MAX_PATH MAX_FILE_NAME
|
||||
|
||||
enum FilesystemType
|
||||
{
|
||||
FSTYPE_FATFS = 0,
|
||||
FSTYPE_IOTDEVICEFILE,
|
||||
FSTYPE_CH376,
|
||||
FSTYPE_END,
|
||||
};
|
||||
|
||||
enum x_FileType
|
||||
{
|
||||
FTYPE_FILE = 0,
|
||||
FTYPE_DIR,
|
||||
FTYPE_SOCKET,
|
||||
FTYPE_END,
|
||||
};
|
||||
|
||||
struct Filesystem;
|
||||
|
||||
struct MountPoint
|
||||
{
|
||||
struct SysDoubleLinklistNode node;
|
||||
enum FilesystemType fs_type;
|
||||
char *mnt_point;
|
||||
size_t mnt_point_len;
|
||||
void *fs_data;
|
||||
BusType bus;
|
||||
HardwareDevType dev;
|
||||
DriverType drv;
|
||||
struct Filesystem *fs;
|
||||
};
|
||||
|
||||
struct FileStat
|
||||
{
|
||||
enum x_FileType type;
|
||||
char name[MAX_FILE_NAME + 1];
|
||||
size_t size;
|
||||
time_t mtime;
|
||||
};
|
||||
|
||||
struct statfs
|
||||
{
|
||||
size_t f_bsize;
|
||||
size_t f_blocks;
|
||||
size_t f_bfree;
|
||||
};
|
||||
|
||||
#define FD_MAX 64
|
||||
#define FD_OFFSET 3
|
||||
|
||||
struct FileDescriptor
|
||||
{
|
||||
char *path;
|
||||
enum x_FileType type;
|
||||
void *data;
|
||||
struct MountPoint *mntp;
|
||||
off_t pos;
|
||||
};
|
||||
|
||||
int NewFileDescriptor(struct FileDescriptor **fdptr);
|
||||
struct FileDescriptor *GetFileDescriptor(int fd);
|
||||
void FreeFileDescriptor(struct FileDescriptor *fdp);
|
||||
|
||||
struct dirent
|
||||
{
|
||||
int d_kind;
|
||||
char d_name[MAX_PATH + 1];
|
||||
};
|
||||
|
||||
/* NOTE: all path arguments must be relative path under mount point */
|
||||
struct Filesystem
|
||||
{
|
||||
int (*open)(struct FileDescriptor *fdp, const char *path);
|
||||
int (*close)(struct FileDescriptor *fdp);
|
||||
ssize_t (*read)(struct FileDescriptor *fdp, void *dst, size_t len);
|
||||
ssize_t (*write)(struct FileDescriptor *fdp, const void *src, size_t len);
|
||||
int (*seek)(struct FileDescriptor *fdp, off_t offset, int whence, off_t *new_offset);
|
||||
off_t (*tell)(struct FileDescriptor *fdp);
|
||||
int (*truncate)(struct FileDescriptor *fdp, off_t length);
|
||||
int (*sync)(struct FileDescriptor *fdp);
|
||||
|
||||
int (*ioctl)(struct FileDescriptor *fdp, int cmd, void *args);
|
||||
int (*poll)(struct FileDescriptor *fdp, struct Pollreq *req);
|
||||
|
||||
int (*opendir)(struct FileDescriptor *fdp, const char *path);
|
||||
int (*closedir)(struct FileDescriptor *fdp);
|
||||
int (*readdir)(struct FileDescriptor *fdp, struct dirent *dirent);
|
||||
int (*seekdir)(struct FileDescriptor *fdp, off_t offset);
|
||||
|
||||
int (*mount)(struct MountPoint *mp);
|
||||
int (*unmount)(struct MountPoint *mp);
|
||||
int (*unlink)(struct MountPoint *mp, const char *path);
|
||||
int (*rename)(struct MountPoint *mp, const char *from,
|
||||
const char *to);
|
||||
int (*mkdir)(struct MountPoint *mp, const char *path);
|
||||
int (*stat)(struct MountPoint *mp, const char *path,
|
||||
struct FileStat *buf);
|
||||
int (*statvfs)(struct MountPoint *mp, const char *path,
|
||||
struct statfs *buf);
|
||||
};
|
||||
|
||||
int RegisterFilesystem(enum FilesystemType fs_type,
|
||||
struct Filesystem *fs);
|
||||
|
||||
int MountFilesystem(const char *bus_name,
|
||||
const char *dev_name, const char *drv_name,
|
||||
enum FilesystemType fs_type, const char *path);
|
||||
|
||||
int UnmountFileSystem(const char *path);
|
||||
|
||||
void SyncOpenedFiles();
|
||||
|
||||
#endif /* _INC_IOT_VFS_H_ */
|
||||
52
fs/shared/include/iot-vfs_posix.h
Normal file
52
fs/shared/include/iot-vfs_posix.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
#ifndef _IOT_VFS_POSIX_H_
|
||||
#define _IOT_VFS_POSIX_H_
|
||||
|
||||
#include <iot-vfs.h>
|
||||
|
||||
typedef void DIR;
|
||||
|
||||
#if defined(LIB_NEWLIB) && defined(_EXFUN)
|
||||
_READ_WRITE_RETURN_TYPE _EXFUN(read, (int __fd, void *__buf, size_t __nbyte));
|
||||
_READ_WRITE_RETURN_TYPE _EXFUN(write, (int __fd, const void *__buf, size_t __nbyte));
|
||||
#else
|
||||
int read(int fd, void *buf, size_t len);
|
||||
int write(int fd, const void *buf, size_t len);
|
||||
#endif
|
||||
|
||||
int open(const char *path, int flags, ...);
|
||||
int close(int fd);
|
||||
int ioctl(int fd, int cmd, void *args);
|
||||
off_t lseek(int fd, off_t offset, int whence);
|
||||
int rename(const char *from, const char *to);
|
||||
int unlink(const char *path);
|
||||
int stat(const char *path, struct stat *buf);
|
||||
int fstat(int fd, struct stat *buf);
|
||||
int fsync(int fd);
|
||||
int ftruncate(int fd, off_t length);
|
||||
|
||||
int mkdir(const char *path, mode_t mode);
|
||||
DIR *opendir(const char *path);
|
||||
int closedir(DIR *dirp);
|
||||
struct dirent *readdir(DIR *dirp);
|
||||
int rmdir(const char *path);
|
||||
int chdir(const char *path);
|
||||
char *getcwd(char *buf, size_t size);
|
||||
long telldir(DIR *dirp);
|
||||
void seekdir(DIR *dirp, off_t offset);
|
||||
void rewinddir(DIR *dirp);
|
||||
|
||||
int statfs(const char *path, struct statfs *buf);
|
||||
|
||||
#endif
|
||||
26
fs/shared/include/vfs_select.h
Normal file
26
fs/shared/include/vfs_select.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
|
||||
#ifndef VFS_SELECT_H__
|
||||
#define VFS_SELECT_H__
|
||||
|
||||
#include <libc.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user