import RT-Thread@9217865c without bsp, libcpu and components/net
This commit is contained in:
commit
e2376a3709
1414 changed files with 390370 additions and 0 deletions
117
components/dfs/dfs_v2/include/dfs.h
Normal file
117
components/dfs/dfs_v2/include/dfs.h
Normal file
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2005-02-22 Bernard The first version.
|
||||
*/
|
||||
|
||||
#ifndef __DFS_H__
|
||||
#define __DFS_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef DFS_FILESYSTEMS_MAX
|
||||
#define DFS_FILESYSTEMS_MAX 4
|
||||
#endif
|
||||
|
||||
#ifndef DFS_FD_MAX
|
||||
#define DFS_FD_MAX 16
|
||||
#endif
|
||||
|
||||
/*
|
||||
* skip stdin/stdout/stderr normally
|
||||
*/
|
||||
#ifndef DFS_STDIO_OFFSET
|
||||
#define DFS_STDIO_OFFSET 3
|
||||
#endif
|
||||
|
||||
#ifndef DFS_PATH_MAX
|
||||
#define DFS_PATH_MAX DIRENT_NAME_MAX
|
||||
#endif
|
||||
|
||||
#ifndef SECTOR_SIZE
|
||||
#define SECTOR_SIZE 512
|
||||
#endif
|
||||
|
||||
#ifndef DFS_FILESYSTEM_TYPES_MAX
|
||||
#define DFS_FILESYSTEM_TYPES_MAX 2
|
||||
#endif
|
||||
|
||||
#define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */
|
||||
#define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */
|
||||
|
||||
/* File types */
|
||||
#define FT_REGULAR 0 /* regular file */
|
||||
#define FT_SOCKET 1 /* socket file */
|
||||
#define FT_DIRECTORY 2 /* directory */
|
||||
#define FT_USER 3 /* user defined */
|
||||
#define FT_DEVICE 4 /* device */
|
||||
|
||||
/* File flags */
|
||||
#define DFS_F_OPEN 0x01000000
|
||||
#define DFS_F_DIRECTORY 0x02000000
|
||||
#define DFS_F_EOF 0x04000000
|
||||
#define DFS_F_ERR 0x08000000
|
||||
|
||||
struct dfs_fdtable
|
||||
{
|
||||
uint32_t maxfd;
|
||||
struct dfs_file **fds;
|
||||
};
|
||||
|
||||
/* Initialization of dfs */
|
||||
int dfs_init(void);
|
||||
|
||||
char *dfs_normalize_path(const char *directory, const char *filename);
|
||||
const char *dfs_subdir(const char *directory, const char *filename);
|
||||
|
||||
int fd_is_open(const char *pathname);
|
||||
struct dfs_fdtable *dfs_fdtable_get(void);
|
||||
|
||||
void dfs_lock(void);
|
||||
void dfs_unlock(void);
|
||||
|
||||
void dfs_file_lock(void);
|
||||
void dfs_file_unlock(void);
|
||||
|
||||
void dfs_fm_lock(void);
|
||||
void dfs_fm_unlock(void);
|
||||
|
||||
#ifdef DFS_USING_POSIX
|
||||
/* FD APIs */
|
||||
int fdt_fd_new(struct dfs_fdtable *fdt);
|
||||
struct dfs_file *fdt_fd_get(struct dfs_fdtable* fdt, int fd);
|
||||
void fdt_fd_release(struct dfs_fdtable* fdt, int fd);
|
||||
int fd_new(void);
|
||||
int fd_associate(struct dfs_fdtable *fdt, int fd, struct dfs_file *file);
|
||||
struct dfs_file *fd_get(int fd);
|
||||
int fd_get_fd_index(struct dfs_file *file);
|
||||
void fd_release(int fd);
|
||||
|
||||
void fd_init(struct dfs_file *fd);
|
||||
|
||||
struct dfs_fdtable *dfs_fdtable_get(void);
|
||||
struct dfs_fdtable *dfs_fdtable_get_global(void);
|
||||
#endif /* DFS_USING_POSIX */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
104
components/dfs/dfs_v2/include/dfs_file.h
Normal file
104
components/dfs/dfs_v2/include/dfs_file.h
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2005-01-26 Bernard The first version.
|
||||
*/
|
||||
|
||||
#ifndef __DFS_FILE_H__
|
||||
#define __DFS_FILE_H__
|
||||
|
||||
#include <dfs.h>
|
||||
#include <dfs_fs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct rt_pollreq;
|
||||
|
||||
struct dfs_file_ops
|
||||
{
|
||||
int (*open) (struct dfs_file *fd);
|
||||
int (*close) (struct dfs_file *fd);
|
||||
int (*ioctl) (struct dfs_file *fd, int cmd, void *args);
|
||||
int (*read) (struct dfs_file *fd, void *buf, size_t count);
|
||||
int (*write) (struct dfs_file *fd, const void *buf, size_t count);
|
||||
int (*flush) (struct dfs_file *fd);
|
||||
int (*lseek) (struct dfs_file *fd, off_t offset);
|
||||
int (*getdents) (struct dfs_file *fd, struct dirent *dirp, uint32_t count);
|
||||
|
||||
int (*poll) (struct dfs_file *fd, struct rt_pollreq *req);
|
||||
};
|
||||
|
||||
/* file descriptor */
|
||||
#define DFS_FD_MAGIC 0xfdfd
|
||||
|
||||
struct dfs_vnode
|
||||
{
|
||||
uint16_t type; /* Type (regular or socket) */
|
||||
|
||||
char *path; /* Name (below mount point) */
|
||||
char *fullpath; /* Full path is hash key */
|
||||
int ref_count; /* Descriptor reference count */
|
||||
rt_list_t list; /* The node of vnode hash table */
|
||||
|
||||
struct dfs_filesystem *fs;
|
||||
const struct dfs_file_ops *fops;
|
||||
uint32_t flags; /* self flags, is dir etc.. */
|
||||
|
||||
size_t size; /* Size in bytes */
|
||||
void *data; /* Specific file system data */
|
||||
};
|
||||
|
||||
struct dfs_file
|
||||
{
|
||||
uint16_t magic; /* file descriptor magic number */
|
||||
uint32_t flags; /* Descriptor flags */
|
||||
int ref_count; /* Descriptor reference count */
|
||||
off_t pos; /* Current file position */
|
||||
struct dfs_vnode *vnode; /* file node struct */
|
||||
void *data; /* Specific fd data */
|
||||
};
|
||||
|
||||
struct dfs_mmap2_args
|
||||
{
|
||||
void *addr;
|
||||
size_t length;
|
||||
int prot;
|
||||
int flags;
|
||||
off_t pgoffset;
|
||||
|
||||
void *ret;
|
||||
};
|
||||
|
||||
void dfs_vnode_mgr_init(void);
|
||||
int dfs_file_is_open(const char *pathname);
|
||||
int dfs_file_open(struct dfs_file *fd, const char *path, int flags);
|
||||
int dfs_file_close(struct dfs_file *fd);
|
||||
int dfs_file_ioctl(struct dfs_file *fd, int cmd, void *args);
|
||||
int dfs_file_read(struct dfs_file *fd, void *buf, size_t len);
|
||||
int dfs_file_getdents(struct dfs_file *fd, struct dirent *dirp, size_t nbytes);
|
||||
int dfs_file_unlink(const char *path);
|
||||
int dfs_file_write(struct dfs_file *fd, const void *buf, size_t len);
|
||||
int dfs_file_flush(struct dfs_file *fd);
|
||||
int dfs_file_lseek(struct dfs_file *fd, off_t offset);
|
||||
|
||||
int dfs_file_stat(const char *path, struct stat *buf);
|
||||
int dfs_file_rename(const char *oldpath, const char *newpath);
|
||||
int dfs_file_ftruncate(struct dfs_file *fd, off_t length);
|
||||
int dfs_file_mmap2(struct dfs_file *fd, struct dfs_mmap2_args *mmap2);
|
||||
|
||||
/* 0x5254 is just a magic number to make these relatively unique ("RT") */
|
||||
#define RT_FIOFTRUNCATE 0x52540000U
|
||||
#define RT_FIOGETADDR 0x52540001U
|
||||
#define RT_FIOMMAP2 0x52540002U
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
102
components/dfs/dfs_v2/include/dfs_fs.h
Normal file
102
components/dfs/dfs_v2/include/dfs_fs.h
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2005-02-22 Bernard The first version.
|
||||
*/
|
||||
|
||||
#ifndef __DFS_FS_H__
|
||||
#define __DFS_FS_H__
|
||||
|
||||
#include <dfs.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Pre-declaration */
|
||||
struct dfs_filesystem;
|
||||
struct dfs_file;
|
||||
|
||||
/* 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 dev_id, const char *fs_name);
|
||||
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);
|
||||
int dfs_unmount_device(rt_device_t dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
28
components/dfs/dfs_v2/include/dfs_private.h
Normal file
28
components/dfs/dfs_v2/include/dfs_private.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
|
||||
#ifndef DFS_PRIVATE_H__
|
||||
#define DFS_PRIVATE_H__
|
||||
|
||||
#include <dfs.h>
|
||||
|
||||
#define DBG_TAG "DFS"
|
||||
#define DBG_LVL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
#define NO_WORKING_DIR "system does not support working directory\n"
|
||||
|
||||
/* extern variable */
|
||||
extern const struct dfs_filesystem_ops *filesystem_operation_table[];
|
||||
extern struct dfs_filesystem filesystem_table[];
|
||||
extern const struct dfs_mount_tbl mount_table[];
|
||||
|
||||
extern char working_directory[];
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue