2011-10-08 22:50:08 +08:00
|
|
|
/*
|
2023-06-10 21:35:25 +08:00
|
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
2011-10-08 22:50:08 +08:00
|
|
|
*
|
2018-10-29 11:06:58 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2011-10-08 22:50:08 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2005-02-22 Bernard The first version.
|
2023-06-10 21:35:25 +08:00
|
|
|
* 2023-05-05 Bernard change to dfs v2.0
|
2011-10-08 22:50:08 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DFS_H__
|
|
|
|
#define __DFS_H__
|
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2011-10-08 22:50:08 +08:00
|
|
|
#include <string.h>
|
2023-06-10 21:35:25 +08:00
|
|
|
#include "../../libc/compilers/common/include/dirent.h"
|
2021-09-11 11:07:51 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/stat.h>
|
2021-09-12 03:34:59 +08:00
|
|
|
#include <sys/statfs.h>
|
2021-08-31 10:27:09 +08:00
|
|
|
#include <sys/time.h>
|
2023-06-10 21:35:25 +08:00
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <rtatomic.h>
|
2017-10-15 22:44:53 +08:00
|
|
|
#include <rtdevice.h>
|
|
|
|
|
2024-03-28 23:42:56 +08:00
|
|
|
#ifndef ATTR_MODE_SET
|
|
|
|
#define ATTR_MODE_SET (1 << 6)
|
|
|
|
#endif
|
|
|
|
|
2023-10-13 19:21:49 +08:00
|
|
|
#ifndef ATTR_ATIME_SET
|
|
|
|
#define ATTR_ATIME_SET (1 << 7)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ATTR_MTIME_SET
|
|
|
|
#define ATTR_MTIME_SET (1 << 8)
|
|
|
|
#endif
|
|
|
|
|
2024-03-28 23:42:56 +08:00
|
|
|
#ifndef ATTR_UID_SET
|
|
|
|
#define ATTR_UID_SET (1 << 9)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ATTR_GID_SET
|
|
|
|
#define ATTR_GID_SET (1 << 10)
|
|
|
|
#endif
|
|
|
|
|
2023-10-13 19:21:49 +08:00
|
|
|
#ifndef AT_SYMLINK_NOFOLLOW
|
|
|
|
#define AT_SYMLINK_NOFOLLOW 0x100
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef UTIME_NOW
|
|
|
|
#define UTIME_NOW 0x3fffffff
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef UTIME_OMIT
|
|
|
|
#define UTIME_OMIT 0x3ffffffe
|
|
|
|
#endif
|
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
#ifndef DFS_FD_MAX
|
2021-09-01 21:28:16 +08:00
|
|
|
#define DFS_FD_MAX 16
|
2017-10-15 22:44:53 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* skip stdin/stdout/stderr normally
|
|
|
|
*/
|
2022-12-03 12:07:44 +08:00
|
|
|
#ifndef DFS_STDIO_OFFSET
|
2023-11-28 17:16:21 +08:00
|
|
|
#define DFS_STDIO_OFFSET 3
|
2017-10-15 22:44:53 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DFS_PATH_MAX
|
2023-11-28 17:16:21 +08:00
|
|
|
#define DFS_PATH_MAX 4096
|
2017-10-15 22:44:53 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SECTOR_SIZE
|
2023-11-28 17:16:21 +08:00
|
|
|
#define SECTOR_SIZE 512
|
2017-10-15 22:44:53 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */
|
|
|
|
#define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */
|
|
|
|
|
|
|
|
/* File flags */
|
2023-06-10 21:35:25 +08:00
|
|
|
#define DFS_F_FREAD 0x01
|
|
|
|
#define DFS_F_FWRITE 0x02
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rt_inline int dfs_fflags(int oflags)
|
|
|
|
{
|
|
|
|
int rw = oflags & O_ACCMODE;
|
|
|
|
|
|
|
|
oflags &= ~O_ACCMODE;
|
|
|
|
return (rw + 1) | oflags;
|
|
|
|
}
|
|
|
|
|
|
|
|
rt_inline int dfs_oflags(int fflags)
|
|
|
|
{
|
|
|
|
int rw = fflags & (DFS_F_FREAD | DFS_F_FWRITE);
|
|
|
|
|
|
|
|
fflags &= ~(DFS_F_FREAD | DFS_F_FWRITE);
|
|
|
|
return (rw - 1) | fflags;
|
|
|
|
}
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2018-06-10 17:57:34 +08:00
|
|
|
struct dfs_fdtable
|
|
|
|
{
|
|
|
|
uint32_t maxfd;
|
2023-04-08 22:25:51 +08:00
|
|
|
struct dfs_file **fds;
|
2018-06-10 17:57:34 +08:00
|
|
|
};
|
|
|
|
|
2017-10-15 22:44:53 +08:00
|
|
|
/* Initialization of dfs */
|
|
|
|
int dfs_init(void);
|
2013-06-23 07:53:19 +08:00
|
|
|
|
2011-12-23 10:11:55 +08:00
|
|
|
char *dfs_normalize_path(const char *directory, const char *filename);
|
|
|
|
const char *dfs_subdir(const char *directory, const char *filename);
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2023-06-10 21:35:25 +08:00
|
|
|
rt_err_t dfs_lock(void);
|
2017-10-15 22:44:53 +08:00
|
|
|
void dfs_unlock(void);
|
|
|
|
|
2023-06-10 21:35:25 +08:00
|
|
|
rt_err_t dfs_file_lock(void);
|
2023-04-08 22:25:51 +08:00
|
|
|
void dfs_file_unlock(void);
|
2022-12-03 12:07:44 +08:00
|
|
|
|
2023-12-12 18:05:39 +08:00
|
|
|
int dfs_fdtable_dup(struct dfs_fdtable *fdt_dst, struct dfs_fdtable *fdt_src, int fd_src);
|
|
|
|
int dfs_fdtable_drop_fd(struct dfs_fdtable *fdtab, int fd);
|
|
|
|
|
2021-11-16 00:22:49 +08:00
|
|
|
#ifdef DFS_USING_POSIX
|
2011-10-08 22:50:08 +08:00
|
|
|
/* FD APIs */
|
2022-12-03 12:07:44 +08:00
|
|
|
int fdt_fd_new(struct dfs_fdtable *fdt);
|
2023-12-16 18:06:47 +08:00
|
|
|
struct dfs_file *fdt_get_file(struct dfs_fdtable* fdt, int fd);
|
2022-12-03 12:07:44 +08:00
|
|
|
void fdt_fd_release(struct dfs_fdtable* fdt, int fd);
|
2011-10-08 22:50:08 +08:00
|
|
|
int fd_new(void);
|
2023-12-16 18:06:47 +08:00
|
|
|
int fdt_fd_associate_file(struct dfs_fdtable *fdt, int fd, struct dfs_file *file);
|
2023-04-08 22:25:51 +08:00
|
|
|
struct dfs_file *fd_get(int fd);
|
2022-12-03 12:07:44 +08:00
|
|
|
void fd_release(int fd);
|
|
|
|
|
2023-04-08 22:25:51 +08:00
|
|
|
void fd_init(struct dfs_file *fd);
|
2022-12-03 12:07:44 +08:00
|
|
|
|
|
|
|
struct dfs_fdtable *dfs_fdtable_get(void);
|
|
|
|
struct dfs_fdtable *dfs_fdtable_get_global(void);
|
2023-06-10 21:35:25 +08:00
|
|
|
int dfs_dup(int oldfd, int startfd);
|
2021-11-16 00:22:49 +08:00
|
|
|
#endif /* DFS_USING_POSIX */
|
2018-06-10 17:57:34 +08:00
|
|
|
|
2011-10-08 22:50:08 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|