From 2c525ecd43cfee01cffd4d1d289ebdb5935674a5 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 11 Sep 2021 15:34:59 -0400 Subject: [PATCH] =?UTF-8?q?=E5=B0=86dfs=5Fposix.h=E7=9A=84=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=A3=B0=E6=98=8E=E8=BD=AC=E7=A7=BB=E5=88=B0unix?= =?UTF-8?q?=E6=A0=87=E5=87=86=E5=A4=B4=E6=96=87=E4=BB=B6=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dfs/include/dfs.h | 8 +-- components/dfs/include/dfs_posix.h | 41 +---------- .../compilers/common/none-gcc/sys/types.h | 1 + .../compilers/common/none-gcc/sys/unistd.h | 70 +++++-------------- components/libc/compilers/common/sys/statfs.h | 15 ++-- components/libc/compilers/common/sys/vfs.h | 15 ++++ 6 files changed, 46 insertions(+), 104 deletions(-) create mode 100644 components/libc/compilers/common/sys/vfs.h diff --git a/components/dfs/include/dfs.h b/components/dfs/include/dfs.h index 9f112f9656..38f19aa7e7 100644 --- a/components/dfs/include/dfs.h +++ b/components/dfs/include/dfs.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -68,13 +69,6 @@ extern "C" { #define DFS_F_EOF 0x04000000 #define DFS_F_ERR 0x08000000 -struct statfs -{ - size_t f_bsize; /* block size */ - size_t f_blocks; /* total data blocks in file system */ - size_t f_bfree; /* free blocks in file system */ -}; - struct dfs_fdtable { uint32_t maxfd; diff --git a/components/dfs/include/dfs_posix.h b/components/dfs/include/dfs_posix.h index 98da0f854f..ee62cdde82 100644 --- a/components/dfs/include/dfs_posix.h +++ b/components/dfs/include/dfs_posix.h @@ -16,44 +16,9 @@ #define __DFS_POSIX_H__ #include +#include +#include /* rename() */ #include - -#ifdef __cplusplus -extern "C" { -#endif - - -/* file api*/ - -int close(int d); - -#if defined(RT_USING_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 - -off_t lseek(int fd, off_t offset, int whence); -int rename(const char *from, const char *to); -int unlink(const char *pathname); -int fsync(int fildes); -int ftruncate(int fd, off_t length); - -/* directory api*/ -int rmdir(const char *path); -int chdir(const char *path); -char *getcwd(char *buf, size_t size); - -/* file system api */ -int statfs(const char *path, struct statfs *buf); - -int access(const char *path, int amode); -int pipe(int fildes[2]); - -#ifdef __cplusplus -} -#endif +#include /* statfs() */ #endif diff --git a/components/libc/compilers/common/none-gcc/sys/types.h b/components/libc/compilers/common/none-gcc/sys/types.h index e9f44f7762..a7c566f643 100644 --- a/components/libc/compilers/common/none-gcc/sys/types.h +++ b/components/libc/compilers/common/none-gcc/sys/types.h @@ -12,6 +12,7 @@ #define __SYS_TYPES_H__ #include +#include typedef int32_t clockid_t; typedef int32_t key_t; /* Used for interprocess communication. */ diff --git a/components/libc/compilers/common/none-gcc/sys/unistd.h b/components/libc/compilers/common/none-gcc/sys/unistd.h index ea2d674b0f..f86d56282c 100644 --- a/components/libc/compilers/common/none-gcc/sys/unistd.h +++ b/components/libc/compilers/common/none-gcc/sys/unistd.h @@ -6,68 +6,32 @@ * Change Logs: * Date Author Notes * 2020-12-16 Meco Man add usleep + * 2021-09-11 Meco Man move functions from dfs_posix.h to unistd.h */ #ifndef __SYS_UNISTD_H__ #define __SYS_UNISTD_H__ -#include -#include "types.h" - -#ifdef RT_USING_DFS +#include +#include "types.h" /* */ #define STDIN_FILENO 0 /* standard input file descriptor */ #define STDOUT_FILENO 1 /* standard output file descriptor */ #define STDERR_FILENO 2 /* standard error file descriptor */ -#include -#else -#define _FREAD 0x0001 /* read enabled */ -#define _FWRITE 0x0002 /* write enabled */ -#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */ -#define _FMARK 0x0010 /* internal; mark during gc() */ -#define _FDEFER 0x0020 /* internal; defer for next gc pass */ -#define _FASYNC 0x0040 /* signal pgrp when data ready */ -#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */ -#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */ -#define _FCREAT 0x0200 /* open with file create */ -#define _FTRUNC 0x0400 /* open with truncation */ -#define _FEXCL 0x0800 /* error on open if file exists */ -#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */ -#define _FSYNC 0x2000 /* do all writes synchronously */ -#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */ -#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */ -#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */ - - -#ifndef O_RDONLY -#define O_RDONLY 0 /* +1 == FREAD */ -#endif -#ifndef O_WRONLY -#define O_WRONLY 1 /* +1 == FWRITE */ -#endif -#ifndef O_RDWR -#define O_RDWR 2 /* +1 == FREAD|FWRITE */ -#endif -#ifndef O_APPEND -#define O_APPEND _FAPPEND -#endif -#ifndef O_CREAT -#define O_CREAT _FCREAT -#endif -#ifndef O_TRUNC -#define O_TRUNC _FTRUNC -#endif -#ifndef O_EXCL -#define O_EXCL _FEXCL -#endif -#ifndef O_SYNC -#define O_SYNC _FSYNC -#endif - -#endif - -int isatty (int fd); -char * ttyname (int desc); +int read(int fd, void *buf, size_t len); +int write(int fd, const void *buf, size_t len); +off_t lseek(int fd, off_t offset, int whence); +int fsync(int fildes); +int unlink(const char *pathname); +int close(int d); +int ftruncate(int fd, off_t length); +int rmdir(const char *path); +int chdir(const char *path); +char *getcwd(char *buf, size_t size); +int access(const char *path, int amode); +int pipe(int fildes[2]); +int isatty(int fd); +char *ttyname(int desc); unsigned int sleep(unsigned int seconds); int usleep(useconds_t usec); pid_t gettid(void); diff --git a/components/libc/compilers/common/sys/statfs.h b/components/libc/compilers/common/sys/statfs.h index 0996af9a18..0c6dc44df3 100644 --- a/components/libc/compilers/common/sys/statfs.h +++ b/components/libc/compilers/common/sys/statfs.h @@ -6,16 +6,19 @@ * Change Logs: * Date Author Notes */ -#ifndef __RTT_STATFS_H__ -#define __RTT_STATFS_H__ +#ifndef __SYS_STATFS_H__ +#define __SYS_STATFS_H__ -#include +#include struct statfs { - rt_size_t f_bsize; /* block size */ - rt_size_t f_blocks; /* total data blocks in file system */ - rt_size_t f_bfree; /* free blocks in file system */ + size_t f_bsize; /* block size */ + size_t f_blocks; /* total data blocks in file system */ + size_t f_bfree; /* free blocks in file system */ }; +int statfs(const char *path, struct statfs *buf); +int fstatfs(int fd, struct statfs *buf); + #endif diff --git a/components/libc/compilers/common/sys/vfs.h b/components/libc/compilers/common/sys/vfs.h new file mode 100644 index 0000000000..00739ab1c6 --- /dev/null +++ b/components/libc/compilers/common/sys/vfs.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-09-11 Meco Man First version + */ +#ifndef __SYS_VFS_H__ +#define __SYS_VFS_H__ + +#include "statfs.h" /* */ + +#endif -- GitLab