48int open(
const char *file,
int flags, ...)
60 if ((
flags & O_CREAT) || (
flags & O_TMPFILE) == O_TMPFILE)
64 mode = va_arg(ap, mode_t);
75 rt_set_errno(-RT_ERROR);
92#define AT_FDCWD (-100)
110int openat(
int dirfd,
const char *path,
int flag, ...)
118 rt_set_errno(-EBADF);
122 fullpath = (
char*)path;
131 rt_set_errno(-EBADF);
138 rt_set_errno(-ENOMEM);
144 fd =
open(fullpath, flag, 0);
146 if (fullpath != path)
154int utimensat(
int __fd,
const char *__path,
const struct timespec __times[2],
int __flags)
170 if (__path[0] ==
'/' || __fd ==
AT_FDCWD)
172 if (
stat(__path, &buffer) < 0)
178 fullpath = (
char*)__path;
194 rt_set_errno(-ENOMEM);
205 attr.
ia_atime.tv_sec = current_time;
209 attr.
ia_atime.tv_sec = __times[0].tv_sec;
218 attr.
ia_mtime.tv_sec = current_time;
222 attr.
ia_mtime.tv_sec = __times[1].tv_sec;
270int creat(
const char *path, mode_t mode)
272 return open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
292 rt_set_errno(-EBADF);
300 rt_set_errno(result);
322#if defined(RT_USING_NEWLIB) && defined(_EXFUN)
323_READ_WRITE_RETURN_TYPE _EXFUN(
read, (
int fd,
void *buf,
size_t len))
325ssize_t
read(
int fd,
void *buf,
size_t len)
333 rt_set_errno(-EBADF);
340 rt_set_errno(-EBADF);
348 rt_set_errno(result);
367#if defined(RT_USING_NEWLIB) && defined(_EXFUN)
368_READ_WRITE_RETURN_TYPE _EXFUN(
write, (
int fd,
const void *buf,
size_t len))
370ssize_t
write(
int fd,
const void *buf,
size_t len)
378 rt_set_errno(-EBADF);
385 rt_set_errno(-EBADF);
393 rt_set_errno(result);
420off_t
lseek(
int fd, off_t offset,
int whence)
428 rt_set_errno(-EBADF);
436 rt_set_errno(-EPERM);
456int rename(
const char *old_file,
const char *new_file)
460 if (old_file == NULL || new_file == NULL)
462 rt_set_errno(-EBADF);
469 rt_set_errno(result);
491 if (pathname == NULL)
493 rt_set_errno(-EBADF);
498 if (result == 0 && S_ISDIR(
stat.st_mode))
500 rt_set_errno(-RT_ERROR);
508 rt_set_errno(result);
530 if (file == NULL || buf == NULL)
539 rt_set_errno(-result);
561 rt_set_errno(-EBADF);
569 rt_set_errno(-EBADF);
602 rt_set_errno(-EBADF);
643 arg = va_arg(ap,
void *);
685 arg = va_arg(ap,
void *);
689 return fcntl(fildes, cmd, arg);
711 rt_set_errno(-EBADF);
718 rt_set_errno(-EINVAL);
726 rt_set_errno(result);
748 if (path == NULL || buf == NULL)
750 rt_set_errno(-EBADF);
757 rt_set_errno(result);
782 rt_set_errno(-EBADF);
790 rt_set_errno(-EBADF);
820 rt_set_errno(-EBADF);
826 rt_set_errno(-EEXIST);
840 rt_set_errno(result);
870 rt_set_errno(-EPERM);
877 struct dirent *dirent;
884 if (rt_strcmp(
".", dirent->d_name) != 0 &&
885 rt_strcmp(
"..", dirent->d_name) != 0)
895 rt_set_errno(-EPERM);
902 if (S_ISLNK(
stat.st_mode))
904 rt_set_errno(-EPERM);
912 rt_set_errno(result);
936 rt_set_errno(-RT_ERROR);
947 rt_set_errno(-RT_ERROR);
951 result =
dfs_file_open(file, name, O_RDONLY | O_DIRECTORY, 0);
963 rt_memset(t, 0,
sizeof(DIR));
972 rt_set_errno(result);
990 struct dirent *dirent = NULL;
994 rt_set_errno(-EBADF);
1002 struct dirent *dirent_ptr;
1003 dirent_ptr = (
struct dirent *)&d->buf[d->cur];
1004 d->cur += dirent_ptr->d_reclen;
1007 if (!d->num || d->cur >= d->num)
1011 (
struct dirent *)d->buf,
1012 sizeof(d->buf) - 1);
1015 rt_set_errno(result);
1024 dirent = (
struct dirent *)(d->buf + d->cur);
1025 if (rt_strcmp(
".", dirent->d_name) != 0 &&
1026 rt_strcmp(
"..", dirent->d_name) != 0)
1051 rt_set_errno(-EBADF);
1058 rt_set_errno(-EBADF);
1063 result = file->
fpos - d->num + d->cur;
1082 rt_set_errno(-EBADF);
1089 rt_set_errno(-EBADF);
1096 if (file->
fpos > offset)
1100 d->num = d->cur = 0;
1103 while(file->
fpos < offset)
1126 d->num = d->cur = 0;
1146 rt_set_errno(-EBADF);
1153 rt_set_errno(-EBADF);
1160 rt_set_errno(result);
1174#ifdef DFS_USING_WORKDIR
1183int chdir(
const char *path)
1191#ifdef DFS_USING_WORKDIR
1196 rt_set_errno(-ENOTDIR);
1202 rt_set_errno(-ENOTDIR);
1208 if (fullpath == NULL)
1210 rt_set_errno(-ENOTDIR);
1223 rt_set_errno(-ENOTDIR);
1229#ifdef RT_USING_SMART
1231 lwp_setcwd(fullpath);
1244#ifdef RT_USING_FINSH
1264 rt_set_errno(-EINVAL);
1268 if (
stat(path, &st) < 0)
1270 rt_set_errno(-ENOENT);
1279 if ((amode & R_OK) && !(st.st_mode & S_IRUSR))
1281 rt_set_errno(-EACCES);
1285 if ((amode & W_OK) && !(st.st_mode & S_IWUSR))
1287 rt_set_errno(-EACCES);
1291 if ((amode & X_OK) && !(st.st_mode & S_IXUSR))
1293 rt_set_errno(-EACCES);
1310 rt_set_errno(-EBADF);
1314#ifdef DFS_USING_WORKDIR
1316#ifdef RT_USING_SMART
1343 rt_set_errno(-EBADF);
1347#ifdef DFS_USING_WORKDIR
1352#ifdef RT_USING_SMART
1353 dir_buf = lwp_getcwd();
1361 rt_strncpy(buf, dir_buf, size);
1385ssize_t
pread(
int fd,
void *buf,
size_t len, off_t offset)
1393 rt_set_errno(-EBADF);
1400 rt_set_errno(-EBADF);
1412 rt_set_errno(result);
1432ssize_t
pwrite(
int fd,
const void *buf,
size_t len, off_t offset)
1440 rt_set_errno(-EBADF);
1447 rt_set_errno(-EBADF);
1458 rt_set_errno(result);
#define AT_SYMLINK_NOFOLLOW
char * dfs_dentry_full_path(struct dfs_dentry *dentry)
int dfs_file_getdents(struct dfs_file *file, struct dirent *dirp, size_t nbytes)
int dfs_file_lstat(const char *path, struct stat *buf)
off_t dfs_file_get_fpos(struct dfs_file *file)
int dfs_file_unlink(const char *path)
int dfs_file_ftruncate(struct dfs_file *file, off_t length)
void dfs_file_init(struct dfs_file *file)
ssize_t dfs_file_pwrite(struct dfs_file *file, const void *buf, size_t len, off_t offset)
off_t dfs_file_lseek(struct dfs_file *file, off_t offset, int wherece)
int dfs_file_setattr(const char *path, struct dfs_attr *attr)
int dfs_file_ioctl(struct dfs_file *file, int cmd, void *args)
ssize_t dfs_file_read(struct dfs_file *file, void *buf, size_t len)
ssize_t dfs_file_pread(struct dfs_file *file, void *buf, size_t len, off_t offset)
int dfs_file_fsync(struct dfs_file *file)
int dfs_file_fcntl(int fd, int cmd, unsigned long arg)
int dfs_file_isdir(const char *path)
int dfs_file_close(struct dfs_file *file)
int dfs_file_readlink(const char *path, char *buf, int bufsize)
int dfs_file_open(struct dfs_file *file, const char *path, int oflags, mode_t mode)
void dfs_file_set_fpos(struct dfs_file *file, off_t fpos)
void dfs_file_deinit(struct dfs_file *file)
int dfs_file_stat(const char *path, struct stat *buf)
int dfs_file_rename(const char *old_file, const char *new_file)
ssize_t dfs_file_write(struct dfs_file *file, const void *buf, size_t len)
int dfs_statfs(const char *path, struct statfs *buffer)
int dfs_is_mounted(struct dfs_mnt *mnt)
char * dfs_normalize_path(const char *directory, const char *filename)
struct dfs_file * fd_get(int fd)
ssize_t write(int fd, const void *buf, size_t len)
int openat(int dirfd, const char *path, int flag,...)
Opens a file relative to a directory file descriptor.
int ftruncate(int fd, off_t length)
ssize_t read(int fd, void *buf, size_t len)
int rename(const char *old_file, const char *new_file)
struct dirent * readdir(DIR *d)
DIR * opendir(const char *name)
int mkdir(const char *path, mode_t mode)
int rmdir(const char *pathname)
void seekdir(DIR *d, long offset)
int fstatfs(int fildes, struct statfs *buf)
int ioctl(int fildes, int cmd,...)
off_t lseek(int fd, off_t offset, int whence)
int open(const char *file, int flags,...)
int utimensat(int __fd, const char *__path, const struct timespec __times[2], int __flags)
int access(const char *path, int amode)
int fstat(int fildes, struct stat *buf)
int stat(const char *file, struct stat *buf)
char * getcwd(char *buf, size_t size)
int fcntl(int fildes, int cmd,...)
ssize_t pwrite(int fd, const void *buf, size_t len, off_t offset)
int statfs(const char *path, struct statfs *buf)
ssize_t pread(int fd, void *buf, size_t len, off_t offset)
int unlink(const char *pathname)
int creat(const char *path, mode_t mode)
rt_weak void rt_free(void *ptr)
This function will release the previously allocated memory block by rt_malloc. The released memory bl...
rt_weak void * rt_malloc(rt_size_t size)
Allocate a block of memory with a minimum of 'size' bytes.
#define FINSH_FUNCTION_EXPORT_ALIAS(name, alias, desc)
#define FINSH_FUNCTION_EXPORT(name, desc)
#define RTM_EXPORT(symbol)
struct dfs_dentry * dentry
int(* statfs)(struct dfs_mnt *mnt, struct statfs *buf)
int(* stat)(struct dfs_dentry *dentry, struct stat *buf)
const struct dfs_filesystem_ops * fs_ops