2011-10-08 22:50:08 +08:00
|
|
|
/*
|
2012-12-26 09:12:13 +08:00
|
|
|
* File : dfs_posix.h
|
2011-10-08 22:50:08 +08:00
|
|
|
* This file is part of Device File System in RT-Thread RTOS
|
2012-12-26 09:12:13 +08:00
|
|
|
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
|
2011-10-08 22:50:08 +08:00
|
|
|
*
|
2013-06-26 22:30:40 +08:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2011-10-08 22:50:08 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2009-05-27 Yi.qiu The first version.
|
|
|
|
* 2010-07-18 Bernard add stat and statfs structure definitions.
|
|
|
|
* 2011-05-16 Yi.qiu Change parameter name of rename, "new" is C++ key word.
|
|
|
|
*/
|
2011-12-23 10:11:55 +08:00
|
|
|
|
2011-10-08 22:50:08 +08:00
|
|
|
#ifndef __DFS_POSIX_H__
|
|
|
|
#define __DFS_POSIX_H__
|
|
|
|
|
|
|
|
#include <dfs_file.h>
|
|
|
|
#include <dfs_def.h>
|
|
|
|
|
2015-05-02 22:53:08 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-06-06 23:34:01 +08:00
|
|
|
#if !defined(RT_USING_NEWLIB)
|
2012-12-26 09:12:13 +08:00
|
|
|
#define O_RDONLY DFS_O_RDONLY
|
|
|
|
#define O_WRONLY DFS_O_WRONLY
|
|
|
|
#define O_RDWR DFS_O_RDWR
|
|
|
|
#define O_ACCMODE DFS_O_ACCMODE
|
|
|
|
#define O_CREAT DFS_O_CREAT
|
|
|
|
#define O_EXCL DFS_O_EXCL
|
|
|
|
#define O_TRUNC DFS_O_TRUNC
|
|
|
|
#define O_APPEND DFS_O_APPEND
|
|
|
|
#define O_BINARY DFS_O_BINARY
|
2011-10-08 22:50:08 +08:00
|
|
|
#define O_DIRECTORY DFS_O_DIRECTORY
|
|
|
|
|
2017-06-06 23:34:01 +08:00
|
|
|
#if !defined(_WIN32)
|
2012-12-26 09:12:13 +08:00
|
|
|
#define S_IFMT DFS_S_IFMT
|
|
|
|
#define S_IFSOCK DFS_S_IFSOCK
|
|
|
|
#define S_IFLNK DFS_S_IFLNK
|
|
|
|
#define S_IFREG DFS_S_IFREG
|
|
|
|
#define S_IFBLK DFS_S_IFBLK
|
|
|
|
#define S_IFDIR DFS_S_IFDIR
|
|
|
|
#define S_IFCHR DFS_S_IFCHR
|
|
|
|
#define S_IFIFO DFS_S_IFIFO
|
|
|
|
#define S_ISUID DFS_S_ISUID
|
|
|
|
#define S_ISGID DFS_S_ISGID
|
|
|
|
#define S_ISVTX DFS_S_ISVTX
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2012-12-26 09:12:13 +08:00
|
|
|
#define S_ISLNK(m) (((m) & DFS_S_IFMT) == DFS_S_IFLNK)
|
|
|
|
#define S_ISREG(m) (((m) & DFS_S_IFMT) == DFS_S_IFREG)
|
|
|
|
#define S_ISDIR(m) (((m) & DFS_S_IFMT) == DFS_S_IFDIR)
|
|
|
|
#define S_ISCHR(m) (((m) & DFS_S_IFMT) == DFS_S_IFCHR)
|
|
|
|
#define S_ISBLK(m) (((m) & DFS_S_IFMT) == DFS_S_IFBLK)
|
|
|
|
#define S_ISFIFO(m) (((m) & DFS_S_IFMT) == DFS_S_IFIFO)
|
|
|
|
#define S_ISSOCK(m) (((m) & DFS_S_IFMT) == DFS_S_IFSOCK)
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2012-12-26 09:12:13 +08:00
|
|
|
#define S_IRWXU DFS_S_IRWXU
|
|
|
|
#define S_IRUSR DFS_S_IRUSR
|
|
|
|
#define S_IWUSR DFS_S_IWUSR
|
|
|
|
#define S_IXUSR DFS_S_IXUSR
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2012-12-26 09:12:13 +08:00
|
|
|
#define S_IRWXG DFS_S_IRWXG
|
|
|
|
#define S_IRGRP DFS_S_IRGRP
|
|
|
|
#define S_IWGRP DFS_S_IWGRP
|
|
|
|
#define S_IXGRP DFS_S_IXGRP
|
2011-10-08 22:50:08 +08:00
|
|
|
|
2012-12-26 09:12:13 +08:00
|
|
|
#define S_IRWXO DFS_S_IRWXO
|
|
|
|
#define S_IROTH DFS_S_IROTH
|
|
|
|
#define S_IWOTH DFS_S_IWOTH
|
|
|
|
#define S_IXOTH DFS_S_IXOTH
|
2017-06-06 23:34:01 +08:00
|
|
|
#endif
|
2011-10-08 22:50:08 +08:00
|
|
|
|
|
|
|
#if defined(__CC_ARM)
|
|
|
|
#include <stdio.h>
|
2015-05-02 22:53:08 +08:00
|
|
|
#include <stdlib.h>
|
2012-12-13 10:13:34 +08:00
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
#include <stdio.h>
|
2011-10-08 22:50:08 +08:00
|
|
|
#else
|
2012-12-26 09:12:13 +08:00
|
|
|
#define SEEK_SET DFS_SEEK_SET
|
|
|
|
#define SEEK_CUR DFS_SEEK_CUR
|
|
|
|
#define SEEK_END DFS_SEEK_END
|
2011-10-08 22:50:08 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-12-26 09:12:13 +08:00
|
|
|
int fd; /* directory file */
|
|
|
|
char buf[512];
|
|
|
|
int num;
|
|
|
|
int cur;
|
2011-10-08 22:50:08 +08:00
|
|
|
} DIR;
|
|
|
|
|
|
|
|
/* directory api*/
|
2011-12-23 10:11:55 +08:00
|
|
|
int mkdir(const char *path, mode_t mode);
|
|
|
|
DIR *opendir(const char *name);
|
|
|
|
struct dirent *readdir(DIR *d);
|
2011-10-08 22:50:08 +08:00
|
|
|
long telldir(DIR *d);
|
|
|
|
void seekdir(DIR *d, off_t offset);
|
|
|
|
void rewinddir(DIR *d);
|
|
|
|
int closedir(DIR* d);
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* use newlib header file */
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
|
2015-05-02 22:53:08 +08:00
|
|
|
struct stat;
|
|
|
|
|
2011-10-08 22:50:08 +08:00
|
|
|
/* file api*/
|
|
|
|
int open(const char *file, int flags, int mode);
|
|
|
|
int close(int d);
|
2015-12-22 10:18:36 +08:00
|
|
|
#ifdef RT_USING_NEWLIB
|
|
|
|
_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
|
2011-10-08 22:50:08 +08:00
|
|
|
int read(int fd, void *buf, size_t len);
|
|
|
|
int write(int fd, const void *buf, size_t len);
|
2015-12-22 10:18:36 +08:00
|
|
|
#endif
|
2011-10-08 22:50:08 +08:00
|
|
|
off_t lseek(int fd, off_t offset, int whence);
|
|
|
|
int rename(const char *from, const char *to);
|
|
|
|
int unlink(const char *pathname);
|
|
|
|
int stat(const char *file, struct stat *buf);
|
|
|
|
int fstat(int fildes, struct stat *buf);
|
2015-12-22 10:18:36 +08:00
|
|
|
int fsync(int fildes);
|
|
|
|
int ioctl(int fildes, unsigned long cmd, void *data);
|
2011-10-08 22:50:08 +08:00
|
|
|
|
|
|
|
/* directory api*/
|
|
|
|
int rmdir(const char *path);
|
|
|
|
int chdir(const char *path);
|
|
|
|
char *getcwd(char *buf, size_t size);
|
|
|
|
|
2015-12-22 10:18:36 +08:00
|
|
|
/* file system api */
|
|
|
|
int statfs(const char *path, struct statfs *buf);
|
|
|
|
|
2015-05-02 22:53:08 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2011-10-08 22:50:08 +08:00
|
|
|
#endif
|
|
|
|
|
2015-05-02 22:53:08 +08:00
|
|
|
#endif
|