提交 cfa9a791 编写于 作者: G guozhanxin

同步 elmfs,stm32h750测试通过

上级 0e0e5151
......@@ -5,6 +5,7 @@ config SOC_STM32H750XB
select SOC_SERIES_STM32H7
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
select RT_USING_CACHE
default y
config BOARD_STM32H750_ARTPI
......
......@@ -191,7 +191,7 @@ int dfs_elm_unmount(struct dfs_filesystem *fs)
return RT_EOK;
}
int dfs_elm_mkfs(rt_device_t dev_id)
int dfs_elm_mkfs(rt_device_t dev_id, const char *fs_name)
{
#define FSM_STATUS_INIT 0
#define FSM_STATUS_USE_TEMP_DRIVER 1
......@@ -330,9 +330,21 @@ int dfs_elm_open(struct dfs_fd *file)
#if (FF_VOLUMES > 1)
int vol;
struct dfs_filesystem *fs = (struct dfs_filesystem *)file->data;
struct dfs_filesystem *fs = file->fnode->fs;
extern int elm_get_vol(FATFS * fat);
RT_ASSERT(file->fnode->ref_count > 0);
if (file->fnode->ref_count > 1)
{
if (file->fnode->type == FT_DIRECTORY
&& !(file->flags & O_DIRECTORY))
{
return -ENOENT;
}
file->pos = 0;
return 0;
}
if (fs == NULL)
return -ENOENT;
......@@ -344,9 +356,9 @@ int dfs_elm_open(struct dfs_fd *file)
if (drivers_fn == RT_NULL)
return -ENOMEM;
rt_snprintf(drivers_fn, 256, "%d:%s", vol, file->path);
rt_snprintf(drivers_fn, 256, "%d:%s", vol, file->fnode->path);
#else
drivers_fn = file->path;
drivers_fn = file->fnode->path;
#endif
if (file->flags & O_DIRECTORY)
......@@ -423,7 +435,8 @@ int dfs_elm_open(struct dfs_fd *file)
if (result == FR_OK)
{
file->pos = fd->fptr;
file->size = f_size(fd);
file->fnode->size = f_size(fd);
file->fnode->type = FT_REGULAR;
file->data = fd;
if (file->flags & O_APPEND)
......@@ -448,10 +461,15 @@ int dfs_elm_close(struct dfs_fd *file)
{
FRESULT result;
RT_ASSERT(file->fnode->ref_count > 0);
if (file->fnode->ref_count > 1)
{
return 0;
}
result = FR_OK;
if (file->type == FT_DIRECTORY)
if (file->fnode->type == FT_DIRECTORY)
{
DIR *dir;
DIR *dir = RT_NULL;
dir = (DIR *)(file->data);
RT_ASSERT(dir != RT_NULL);
......@@ -459,9 +477,9 @@ int dfs_elm_close(struct dfs_fd *file)
/* release memory */
rt_free(dir);
}
else if (file->type == FT_REGULAR)
else if (file->fnode->type == FT_REGULAR)
{
FIL *fd;
FIL *fd = RT_NULL;
fd = (FIL *)(file->data);
RT_ASSERT(fd != RT_NULL);
......@@ -504,6 +522,10 @@ int dfs_elm_ioctl(struct dfs_fd *file, int cmd, void *args)
fd->fptr = fptr;
return elm_result_to_dfs(result);
}
case F_GETLK:
return 0;
case F_SETLK:
return 0;
}
return -ENOSYS;
}
......@@ -514,7 +536,7 @@ int dfs_elm_read(struct dfs_fd *file, void *buf, size_t len)
FRESULT result;
UINT byte_read;
if (file->type == FT_DIRECTORY)
if (file->fnode->type == FT_DIRECTORY)
{
return -EISDIR;
}
......@@ -537,7 +559,7 @@ int dfs_elm_write(struct dfs_fd *file, const void *buf, size_t len)
FRESULT result;
UINT byte_write;
if (file->type == FT_DIRECTORY)
if (file->fnode->type == FT_DIRECTORY)
{
return -EISDIR;
}
......@@ -548,7 +570,7 @@ int dfs_elm_write(struct dfs_fd *file, const void *buf, size_t len)
result = f_write(fd, buf, len, &byte_write);
/* update position and file size */
file->pos = fd->fptr;
file->size = f_size(fd);
file->fnode->size = f_size(fd);
if (result == FR_OK)
return byte_write;
......@@ -570,7 +592,7 @@ int dfs_elm_flush(struct dfs_fd *file)
int dfs_elm_lseek(struct dfs_fd *file, rt_off_t offset)
{
FRESULT result = FR_OK;
if (file->type == FT_REGULAR)
if (file->fnode->type == FT_REGULAR)
{
FIL *fd;
......@@ -586,10 +608,10 @@ int dfs_elm_lseek(struct dfs_fd *file, rt_off_t offset)
return fd->fptr;
}
}
else if (file->type == FT_DIRECTORY)
else if (file->fnode->type == FT_DIRECTORY)
{
/* which is a directory */
DIR *dir;
DIR *dir = RT_NULL;
dir = (DIR *)(file->data);
RT_ASSERT(dir != RT_NULL);
......
......@@ -559,12 +559,11 @@ int nfs_read(struct dfs_fd *file, void *buf, size_t count)
nfs_file *fd;
nfs_filesystem *nfs;
if (file->type == FT_DIRECTORY)
if (file->fnode->type == FT_DIRECTORY)
return -EISDIR;
RT_ASSERT(file->data != NULL);
struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->data));
RT_ASSERT(file->fnode->data != NULL);
struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->fnode->data));
nfs = (struct nfs_filesystem *)(dfs_nfs->data);
fd = (nfs_file *)(nfs->data);
RT_ASSERT(fd != NULL);
......@@ -629,11 +628,11 @@ int nfs_write(struct dfs_fd *file, const void *buf, size_t count)
nfs_file *fd;
nfs_filesystem *nfs;
if (file->type == FT_DIRECTORY)
if (file->fnode->type == FT_DIRECTORY)
return -EISDIR;
RT_ASSERT(file->data != NULL);
struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->data));
RT_ASSERT(file->fnode->data != NULL);
struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->fnode->data));
nfs = (struct nfs_filesystem *)(dfs_nfs->data);
fd = (nfs_file *)(nfs->data);
RT_ASSERT(fd != NULL);
......@@ -676,11 +675,10 @@ int nfs_write(struct dfs_fd *file, const void *buf, size_t count)
file->pos = fd->offset;
/* update file size */
if (fd->size < fd->offset) fd->size = fd->offset;
file->size = fd->size;
file->fnode->size = fd->size;
}
xdr_free((xdrproc_t)xdr_WRITE3res, (char *)&res);
}
while (count > 0);
} while (count > 0);
xdr_free((xdrproc_t)xdr_WRITE3res, (char *)&res);
......@@ -692,11 +690,11 @@ int nfs_lseek(struct dfs_fd *file, off_t offset)
nfs_file *fd;
nfs_filesystem *nfs;
if (file->type == FT_DIRECTORY)
if (file->fnode->type == FT_DIRECTORY)
return -EISDIR;
RT_ASSERT(file->data != NULL);
struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->data));
RT_ASSERT(file->fnode->data != NULL);
struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->fnode->data));
nfs = (struct nfs_filesystem *)(dfs_nfs->data);
fd = (nfs_file *)(nfs->data);
RT_ASSERT(fd != NULL);
......@@ -714,11 +712,18 @@ int nfs_lseek(struct dfs_fd *file, off_t offset)
int nfs_close(struct dfs_fd *file)
{
nfs_filesystem *nfs;
RT_ASSERT(file->data != NULL);
struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->data));
RT_ASSERT(file->fnode->data != NULL);
struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->fnode->data));
RT_ASSERT(file->fnode->ref_count > 0);
if (file->fnode->ref_count > 1)
{
return 0;
}
nfs = (struct nfs_filesystem *)(dfs_nfs->data);
if (file->type == FT_DIRECTORY)
if (file->fnode->type == FT_DIRECTORY)
{
struct nfs_dir *dir;
......@@ -727,7 +732,7 @@ int nfs_close(struct dfs_fd *file)
xdr_free((xdrproc_t)xdr_READDIR3res, (char *)&dir->res);
rt_free(dir);
}
else if (file->type == FT_REGULAR)
else if (file->fnode->type == FT_REGULAR)
{
struct nfs_file *fd;
......@@ -744,24 +749,42 @@ int nfs_close(struct dfs_fd *file)
int nfs_open(struct dfs_fd *file)
{
nfs_filesystem *nfs;
RT_ASSERT(file->data != NULL);
struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->data));
RT_ASSERT(file->fnode->data != NULL);
struct dfs_filesystem *dfs_nfs = file->fnode->fs;
nfs = (struct nfs_filesystem *)(dfs_nfs->data);
RT_ASSERT(nfs != NULL);
RT_ASSERT(file->fnode->ref_count > 0);
if (file->fnode->ref_count > 1)
{
if (file->fnode->type == FT_DIRECTORY
&& !(file->flags & O_DIRECTORY))
{
return -ENOENT;
}
file->pos = 0;
return 0;
}
if (file->flags & O_DIRECTORY)
{
nfs_dir *dir;
if (file->flags & O_CREAT)
{
if (nfs_mkdir(nfs, file->path, 0755) < 0)
if (nfs_mkdir(nfs, file->fnode->path, 0755) < 0)
{
return -EAGAIN;
}
}
/* open directory */
dir = nfs_opendir(nfs, file->path);
if (dir == NULL) return -ENOENT;
dir = nfs_opendir(nfs, file->fnode->path);
if (dir == NULL)
{
return -ENOENT;
}
file->fnode->type = FT_DIRECTORY;
nfs->data = dir;
}
else
......@@ -772,8 +795,10 @@ int nfs_open(struct dfs_fd *file)
/* create file */
if (file->flags & O_CREAT)
{
if (nfs_create(nfs, file->path, 0664) < 0)
if (nfs_create(nfs, file->fnode->path, 0664) < 0)
{
return -EAGAIN;
}
}
/* open file (get file handle ) */
......@@ -781,7 +806,7 @@ int nfs_open(struct dfs_fd *file)
if (fp == NULL)
return -ENOMEM;
handle = get_handle(nfs, file->path);
handle = get_handle(nfs, file->fnode->path);
if (handle == NULL)
{
rt_free(fp);
......@@ -805,7 +830,8 @@ int nfs_open(struct dfs_fd *file)
/* set private file */
nfs->data = fp;
file->size = fp->size;
file->fnode->size = fp->size;
file->fnode->type = FT_REGULAR;
}
return 0;
......@@ -1085,9 +1111,8 @@ int nfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count)
nfs_filesystem *nfs;
char *name;
RT_ASSERT(file->data != NULL);
struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->data));
RT_ASSERT(file->fnode->data != NULL);
struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->fnode->data));
nfs = (struct nfs_filesystem *)(dfs_nfs->data);
dir = (nfs_dir *)(nfs->data);
RT_ASSERT(dir != NULL);
......
......@@ -47,7 +47,15 @@
#include <string.h>
#include <stdint.h>
#ifndef RT_USING_MINILIBC
typedef unsigned int u_int;
typedef unsigned char u_char;
typedef unsigned long u_long;
#else
#include <sys/types.h>
#include <stdint.h>
#endif
typedef long long int64_t;
typedef unsigned long long uint64_t;
......@@ -55,6 +63,14 @@ typedef unsigned long long uint64_t;
typedef int bool_t;
typedef int enum_t;
#if !defined(RT_USING_NEWLIB) && !defined(RT_USING_MUSL)
typedef unsigned long dev_t;
#endif
#if !defined(RT_USING_NEWLIB) && !defined(RT_USING_MINILIBC) && !defined(RT_USING_MUSL)
typedef rt_int32_t ssize_t;
#endif
/* This needs to be changed to uint32_t in the future */
typedef unsigned long rpcprog_t;
typedef unsigned long rpcvers_t;
......
......@@ -97,13 +97,13 @@ int dfs_ramfs_read(struct dfs_fd *file, void *buf, size_t count)
rt_size_t length;
struct ramfs_dirent *dirent;
dirent = (struct ramfs_dirent *)file->data;
dirent = (struct ramfs_dirent *)file->fnode->data;
RT_ASSERT(dirent != NULL);
if (count < file->size - file->pos)
if (count < file->fnode->size - file->pos)
length = count;
else
length = file->size - file->pos;
length = file->fnode->size - file->pos;
if (length > 0)
rt_memcpy(buf, &(dirent->data[file->pos]), length);
......@@ -119,13 +119,13 @@ int dfs_ramfs_write(struct dfs_fd *fd, const void *buf, size_t count)
struct ramfs_dirent *dirent;
struct dfs_ramfs *ramfs;
dirent = (struct ramfs_dirent *)fd->data;
dirent = (struct ramfs_dirent *)fd->fnode->data;
RT_ASSERT(dirent != NULL);
ramfs = dirent->fs;
RT_ASSERT(ramfs != NULL);
if (count + fd->pos > fd->size)
if (count + fd->pos > fd->fnode->size)
{
rt_uint8_t *ptr;
ptr = rt_memheap_realloc(&(ramfs->memheap), dirent->data, fd->pos + count);
......@@ -139,7 +139,7 @@ int dfs_ramfs_write(struct dfs_fd *fd, const void *buf, size_t count)
/* update dirent and file size */
dirent->data = ptr;
dirent->size = fd->pos + count;
fd->size = dirent->size;
fd->fnode->size = dirent->size;
}
if (count > 0)
......@@ -153,7 +153,7 @@ int dfs_ramfs_write(struct dfs_fd *fd, const void *buf, size_t count)
int dfs_ramfs_lseek(struct dfs_fd *file, off_t offset)
{
if (offset <= (off_t)file->size)
if (offset <= (off_t)file->fnode->size)
{
file->pos = offset;
......@@ -165,7 +165,13 @@ int dfs_ramfs_lseek(struct dfs_fd *file, off_t offset)
int dfs_ramfs_close(struct dfs_fd *file)
{
file->data = NULL;
RT_ASSERT(file->fnode->ref_count > 0);
if (file->fnode->ref_count > 1)
{
return 0;
}
file->fnode->data = NULL;
return RT_EOK;
}
......@@ -177,7 +183,19 @@ int dfs_ramfs_open(struct dfs_fd *file)
struct ramfs_dirent *dirent;
struct dfs_filesystem *fs;
fs = (struct dfs_filesystem *)file->data;
RT_ASSERT(file->fnode->ref_count > 0);
if (file->fnode->ref_count > 1)
{
if (file->fnode->type == FT_DIRECTORY
&& !(file->flags & O_DIRECTORY))
{
return -ENOENT;
}
file->pos = 0;
return 0;
}
fs = file->fnode->fs;
ramfs = (struct dfs_ramfs *)fs->data;
RT_ASSERT(ramfs != NULL);
......@@ -190,7 +208,7 @@ int dfs_ramfs_open(struct dfs_fd *file)
}
/* open directory */
dirent = dfs_ramfs_lookup(ramfs, file->path, &size);
dirent = dfs_ramfs_lookup(ramfs, file->fnode->path, &size);
if (dirent == NULL)
return -ENOENT;
if (dirent == &(ramfs->root)) /* it's root directory */
......@@ -200,10 +218,11 @@ int dfs_ramfs_open(struct dfs_fd *file)
return -ENOENT;
}
}
file->fnode->type = FT_DIRECTORY;
}
else
{
dirent = dfs_ramfs_lookup(ramfs, file->path, &size);
dirent = dfs_ramfs_lookup(ramfs, file->fnode->path, &size);
if (dirent == &(ramfs->root)) /* it's root directory */
{
return -ENOENT;
......@@ -225,15 +244,18 @@ int dfs_ramfs_open(struct dfs_fd *file)
}
/* remove '/' separator */
name_ptr = file->path;
name_ptr = file->fnode->path;
while (*name_ptr == '/' && *name_ptr)
name_ptr ++;
{
name_ptr++;
}
strncpy(dirent->name, name_ptr, RAMFS_NAME_MAX);
rt_list_init(&(dirent->list));
dirent->data = NULL;
dirent->size = 0;
dirent->fs = ramfs;
file->fnode->type = FT_DIRECTORY;
/* add to the root directory */
rt_list_insert_after(&(ramfs->root.list), &(dirent->list));
......@@ -256,12 +278,16 @@ int dfs_ramfs_open(struct dfs_fd *file)
}
}
file->data = dirent;
file->size = dirent->size;
file->fnode->data = dirent;
file->fnode->size = dirent->size;
if (file->flags & O_APPEND)
file->pos = file->size;
{
file->pos = file->fnode->size;
}
else
{
file->pos = 0;
}
return 0;
}
......@@ -299,7 +325,7 @@ int dfs_ramfs_getdents(struct dfs_fd *file,
struct ramfs_dirent *dirent;
struct dfs_ramfs *ramfs;
dirent = (struct ramfs_dirent *)file->data;
dirent = (struct ramfs_dirent *)file->fnode->data;
ramfs = dirent->fs;
RT_ASSERT(ramfs != RT_NULL);
......
......@@ -34,7 +34,28 @@ int dfs_romfs_unmount(struct dfs_filesystem *fs)
int dfs_romfs_ioctl(struct dfs_fd *file, int cmd, void *args)
{
return -EIO;
int ret = RT_EOK;
struct romfs_dirent *dirent;
dirent = (struct romfs_dirent *)file->fnode->data;
RT_ASSERT(dirent != NULL);
switch (cmd)
{
case RT_FIOGETADDR:
{
*(rt_ubase_t*)args = (rt_ubase_t)dirent->data;
break;
}
case RT_FIOFTRUNCATE:
{
break;
}
default:
ret = -RT_EINVAL;
break;
}
return ret;
}
rt_inline int check_dirent(struct romfs_dirent *dirent)
......@@ -112,9 +133,6 @@ struct romfs_dirent *dfs_romfs_lookup(struct romfs_dirent *root_dirent, const ch
else
{
/* return file dirent */
if (subpath != NULL)
break; /* not the end of path */
return &dirent[index];
}
}
......@@ -133,7 +151,7 @@ int dfs_romfs_read(struct dfs_fd *file, void *buf, size_t count)
rt_size_t length;
struct romfs_dirent *dirent;
dirent = (struct romfs_dirent *)file->data;
dirent = (struct romfs_dirent *)file->fnode->data;
RT_ASSERT(dirent != NULL);
if (check_dirent(dirent) != 0)
......@@ -141,10 +159,10 @@ int dfs_romfs_read(struct dfs_fd *file, void *buf, size_t count)
return -EIO;
}
if (count < file->size - file->pos)
if (count < file->fnode->size - file->pos)
length = count;
else
length = file->size - file->pos;
length = file->fnode->size - file->pos;
if (length > 0)
rt_memcpy(buf, &(dirent->data[file->pos]), length);
......@@ -157,7 +175,7 @@ int dfs_romfs_read(struct dfs_fd *file, void *buf, size_t count)
int dfs_romfs_lseek(struct dfs_fd *file, off_t offset)
{
if (offset >= 0 && (rt_size_t)offset <= file->size)
if (offset <= file->fnode->size)
{
file->pos = offset;
return file->pos;
......@@ -168,7 +186,12 @@ int dfs_romfs_lseek(struct dfs_fd *file, off_t offset)
int dfs_romfs_close(struct dfs_fd *file)
{
file->data = NULL;
RT_ASSERT(file->fnode->ref_count > 0);
if (file->fnode->ref_count > 1)
{
return RT_EOK;
}
file->fnode->data = NULL;
return RT_EOK;
}
......@@ -179,34 +202,63 @@ int dfs_romfs_open(struct dfs_fd *file)
struct romfs_dirent *root_dirent;
struct dfs_filesystem *fs;
fs = (struct dfs_filesystem *)file->data;
if (file->flags & (O_CREAT | O_WRONLY | O_APPEND | O_TRUNC | O_RDWR))
{
return -EINVAL;
}
RT_ASSERT(file->fnode->ref_count > 0);
if (file->fnode->ref_count > 1)
{
if (file->fnode->type == FT_DIRECTORY
&& !(file->flags & O_DIRECTORY))
{
return -ENOENT;
}
file->pos = 0;
return 0;
}
fs = file->fnode->fs;
root_dirent = (struct romfs_dirent *)fs->data;
if (check_dirent(root_dirent) != 0)
{
return -EIO;
}
if (file->flags & (O_CREAT | O_WRONLY | O_APPEND | O_TRUNC | O_RDWR))
{
return -EINVAL;
}
dirent = dfs_romfs_lookup(root_dirent, file->path, &size);
dirent = dfs_romfs_lookup(root_dirent, file->fnode->path, &size);
if (dirent == NULL)
{
return -ENOENT;
}
/* entry is a directory file type */
if (dirent->type == ROMFS_DIRENT_DIR)
{
if (!(file->flags & O_DIRECTORY))
{
return -ENOENT;
}
file->fnode->type = FT_DIRECTORY;
}
else
{
/* entry is a file, but open it as a directory */
if (file->flags & O_DIRECTORY)
{
return -ENOENT;
}
file->fnode->type = FT_REGULAR;
}
file->data = dirent;
file->size = size;
file->fnode->data = dirent;
file->fnode->size = size;
file->pos = 0;
return RT_EOK;
......@@ -222,7 +274,9 @@ int dfs_romfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
dirent = dfs_romfs_lookup(root_dirent, path, &size);
if (dirent == NULL)
{
return -ENOENT;
}
st->st_dev = 0;
st->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH |
......@@ -248,9 +302,11 @@ int dfs_romfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count)
struct dirent *d;
struct romfs_dirent *dirent, *sub_dirent;
dirent = (struct romfs_dirent *)file->data;
dirent = (struct romfs_dirent *)file->fnode->data;
if (check_dirent(dirent) != 0)
{
return -EIO;
}
RT_ASSERT(dirent->type == ROMFS_DIRENT_DIR);
/* enter directory */
......@@ -259,10 +315,12 @@ int dfs_romfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count)
/* make integer count */
count = (count / sizeof(struct dirent));
if (count == 0)
{
return -EINVAL;
}
index = 0;
for (index = 0; index < count && (rt_size_t)file->pos < file->size; index ++)
for (index = 0; index < count && file->pos < file->fnode->size; index++)
{
d = dirp + index;
......
config ARCH_CPU_64BIT
bool
config RT_USING_CACHE
bool
default n
config ARCH_CPU_BIG_ENDIAN
bool
......@@ -33,6 +37,7 @@ config ARCH_ARM_CORTEX_M3
config ARCH_ARM_MPU
bool
depends on ARCH_ARM
select ARCH_MM_MPU
config ARCH_ARM_CORTEX_M4
bool
......
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef CPUPORT_H__
#define CPUPORT_H__
#endif /*CPUPORT_H__*/
......@@ -615,7 +615,7 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
rt_list_for_each(node, &(information->object_list))
{
object = rt_list_entry(node, struct rt_object, list);
if (rt_strncmp(object->name, name, RT_NAME_MAX) == 0)
if (rt_strncmp(object->name, name, RT_NAME_MAX - 1) == 0)
{
/* leave critical */
rt_exit_critical();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册