From 1f37de29c4ee4dac488aa9c4f8f0990263f94c1a Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 13 Dec 2018 14:54:26 +0800 Subject: Fix the value width issue under 32/64 bit arch. --- components/dfs/src/dfs_file.c | 2 +- components/dfs/src/poll.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'components/dfs/src') diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 646ae58e36..e7071522ce 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -171,7 +171,7 @@ int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args) return fd->flags; /* return flags */ case F_SETFL: { - int flags = (int)args; + int flags = (int)(rt_base_t)args; int mask = O_NONBLOCK | O_APPEND; flags &= mask; diff --git a/components/dfs/src/poll.c b/components/dfs/src/poll.c index 6655a8a667..6f83762082 100644 --- a/components/dfs/src/poll.c +++ b/components/dfs/src/poll.c @@ -40,7 +40,7 @@ static int __wqueue_pollwake(struct rt_wqueue_node *wait, void *key) { struct rt_poll_node *pn; - if (key && !((rt_uint32_t)key & wait->key)) + if (key && !((rt_ubase_t)key & wait->key)) return -1; pn = rt_container_of(wait, struct rt_poll_node, wqn); -- cgit v1.3.1 From 0924d277f67258c7c264cab1287671bf04bea231 Mon Sep 17 00:00:00 2001 From: gbcwbz Date: Sun, 23 Dec 2018 19:14:14 +0800 Subject: [dfs] Fix stdio fd error when POSIX api is used POSIX api e.g. poll read write --- components/dfs/src/dfs.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'components/dfs/src') diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index cf0b2b0ef9..12ae8e9d95 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -18,6 +18,10 @@ #include #endif +#ifdef RT_USING_DFS_DEVFS +#include +#endif + /* Global variables */ const struct dfs_filesystem_ops *filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX]; struct dfs_filesystem filesystem_table[DFS_FILESYSTEMS_MAX]; @@ -212,6 +216,11 @@ struct dfs_fd *fd_get(int fd) struct dfs_fd *d; struct dfs_fdtable *fdt; +#ifdef RT_USING_DFS_DEVFS + if ((0 <= fd) && (fd <= 2)) + fd = libc_stdio_get_console(); +#endif + fdt = dfs_fdtable_get(); fd = fd - DFS_FD_OFFSET; if (fd < 0 || fd >= fdt->maxfd) -- cgit v1.3.1 From 5d6c7e0df709c1cde63ce8b21870525706e52ed9 Mon Sep 17 00:00:00 2001 From: MurphyZhao Date: Sat, 5 Jan 2019 12:00:22 +0800 Subject: [components][dfs] Refix #2100 PR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #2100 PR 增加 `#include ` 后,如果定义了 `RT_USING_DFS_DEVFS`,那就必须要开启 LIBC 才可以成功编译,增加了对 RT_USING_LIBC 的依赖。但是,这个修复又是关于开启 POSIX 的时候遇到的问题,因此建议在引入 的地方,加入对 `RT_USING_POSIX` 的依赖。 Signed-off-by: MurphyZhao --- components/dfs/src/dfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'components/dfs/src') diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 12ae8e9d95..1850ac426c 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -18,7 +18,7 @@ #include #endif -#ifdef RT_USING_DFS_DEVFS +#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_POSIX) #include #endif @@ -216,7 +216,7 @@ struct dfs_fd *fd_get(int fd) struct dfs_fd *d; struct dfs_fdtable *fdt; -#ifdef RT_USING_DFS_DEVFS +#if defined(RT_USING_DFS_DEVFS) && defined(RT_USING_POSIX) if ((0 <= fd) && (fd <= 2)) fd = libc_stdio_get_console(); #endif -- cgit v1.3.1 From c16d3de633ef1ef1a92b1a3d377de44a46f93865 Mon Sep 17 00:00:00 2001 From: yangfasheng Date: Wed, 9 Jan 2019 17:40:32 +0800 Subject: update dfs.c dfs_file.c dfs_file.h Signed-off-by: yangfasheng --- components/dfs/include/dfs_file.h | 1 + components/dfs/src/dfs.c | 2 +- components/dfs/src/dfs_file.c | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) (limited to 'components/dfs/src') diff --git a/components/dfs/include/dfs_file.h b/components/dfs/include/dfs_file.h index 7ef681a247..aaff3f6e9c 100644 --- a/components/dfs/include/dfs_file.h +++ b/components/dfs/include/dfs_file.h @@ -44,6 +44,7 @@ struct dfs_fd char *path; /* Name (below mount point) */ int ref_count; /* Descriptor reference count */ + struct dfs_filesystem *fs; const struct dfs_file_ops *fops; uint32_t flags; /* Descriptor flags */ diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 1850ac426c..066c800568 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -320,7 +320,7 @@ int fd_is_open(const char *pathname) fd = fdt->fds[index]; if (fd == NULL || fd->fops == NULL || fd->path == NULL) continue; - if (fd->fops == fs->ops->fops && strcmp(fd->path, mountpath) == 0) + if (fd->fs == fs && strcmp(fd->path, mountpath) == 0) { /* found file in file descriptor table */ rt_free(fullpath); diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index e7071522ce..4505667738 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -66,7 +66,8 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags) } LOG_D("open in filesystem:%s", fs->ops->name); - fd->fops = fs->ops->fops; /* set file ops */ + fd->fs = fs; /* set file system */ + fd->fops = fs->ops->fops; /* set file ops */ /* initialize the fd item */ fd->type = FT_REGULAR; -- cgit v1.3.1 From 3b4a9f51c70ce961a7a575614b3824c89f47bc56 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 24 Jan 2019 20:55:27 +0800 Subject: [DFS] Remove opened file check Remove opened file check in dfs_file_open function. It will be replaced with POSIX flock/fcntl. --- components/dfs/src/dfs_file.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'components/dfs/src') diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 4505667738..b924b00d3f 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -8,6 +8,7 @@ * 2005-02-22 Bernard The first version. * 2011-12-08 Bernard Merges rename patch from iamcacy. * 2015-05-27 Bernard Fix the fd clear issue. + * 2019-01-24 Bernard Remove file repeatedly open check. */ #include @@ -48,14 +49,6 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags) LOG_D("open file:%s", fullpath); - /* Check whether file is already open */ - if (fd_is_open(fullpath) == 0) - { - rt_free(fullpath); /* release path */ - - return -EBUSY; - } - /* find filesystem */ fs = dfs_filesystem_lookup(fullpath); if (fs == NULL) -- cgit v1.3.1 From 7383269905417f9e4f8f5304e164e0ae31d7169a Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Tue, 12 Feb 2019 14:33:45 +0800 Subject: [Kernel] Code cleanup for compiling warning. --- components/dfs/src/dfs.c | 10 +++++----- components/drivers/serial/serial.c | 2 +- src/kservice.c | 2 +- src/mem.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'components/dfs/src') diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 066c800568..6d52129b06 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -123,7 +123,7 @@ static int fd_alloc(struct dfs_fdtable *fdt, int startfd) int idx; /* find an empty fd entry */ - for (idx = startfd; idx < fdt->maxfd; idx++) + for (idx = startfd; idx < (int)fdt->maxfd; idx++) { if (fdt->fds[idx] == RT_NULL) break; @@ -155,7 +155,7 @@ static int fd_alloc(struct dfs_fdtable *fdt, int startfd) } /* allocate 'struct dfs_fd' */ - if (idx < fdt->maxfd &&fdt->fds[idx] == RT_NULL) + if (idx < (int)fdt->maxfd && fdt->fds[idx] == RT_NULL) { fdt->fds[idx] = rt_calloc(1, sizeof(struct dfs_fd)); if (fdt->fds[idx] == RT_NULL) @@ -223,7 +223,7 @@ struct dfs_fd *fd_get(int fd) fdt = dfs_fdtable_get(); fd = fd - DFS_FD_OFFSET; - if (fd < 0 || fd >= fdt->maxfd) + if (fd < 0 || fd >= (int)fdt->maxfd) return NULL; dfs_lock(); @@ -263,7 +263,7 @@ void fd_put(struct dfs_fd *fd) struct dfs_fdtable *fdt; fdt = dfs_fdtable_get(); - for (index = 0; index < fdt->maxfd; index ++) + for (index = 0; index < (int)fdt->maxfd; index ++) { if (fdt->fds[index] == fd) { @@ -531,7 +531,7 @@ int list_fd(void) rt_kprintf("fd type ref magic path\n"); rt_kprintf("-- ------ --- ----- ------\n"); - for (index = 0; index < fd_table->maxfd; index ++) + for (index = 0; index < (int)fd_table->maxfd; index ++) { struct dfs_fd *fd = fd_table->fds[index]; diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index 77f2a645a1..a03e4a719e 100644 --- a/components/drivers/serial/serial.c +++ b/components/drivers/serial/serial.c @@ -478,7 +478,7 @@ rt_inline int _serial_dma_rx(struct rt_serial_device *serial, rt_uint8_t *data, RT_ASSERT(rx_fifo != RT_NULL); - if (length < fifo_recved_len) + if (length < (int)fifo_recved_len) recv_len = length; else recv_len = fifo_recved_len; diff --git a/src/kservice.c b/src/kservice.c index dc7370d58b..b640107a33 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -476,7 +476,7 @@ rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen) { const char *sc; - for (sc = s; *sc != '\0' && sc - s < maxlen; ++sc) /* nothing */ + for (sc = s; *sc != '\0' && sc - s < (int)maxlen; ++sc) /* nothing */ ; return sc - s; diff --git a/src/mem.c b/src/mem.c index ca5329404e..8099b6bb7e 100644 --- a/src/mem.c +++ b/src/mem.c @@ -644,7 +644,7 @@ int memcheck(void) { position = (rt_ubase_t)mem - (rt_ubase_t)heap_ptr; if (position < 0) goto __exit; - if (position > mem_size_aligned) goto __exit; + if (position > (int)mem_size_aligned) goto __exit; if (mem->magic != HEAP_MAGIC) goto __exit; if (mem->used != 0 && mem->used != 1) goto __exit; } -- cgit v1.3.1 From 4f7c06f9232d30e768c1fd4925414e446e4ca585 Mon Sep 17 00:00:00 2001 From: armink Date: Thu, 7 Mar 2019 15:56:39 +0800 Subject: [component][DFS] Change the log level on dfs_file_open() func. --- components/dfs/src/dfs_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/dfs/src') diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index b924b00d3f..b4f115ffc2 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -111,7 +111,7 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags) fd->flags |= DFS_F_DIRECTORY; } - LOG_I("open successful"); + LOG_D("open successful"); return 0; } -- cgit v1.3.1 From e71ec65549db94a88fac1ba7a1f110d8667fd528 Mon Sep 17 00:00:00 2001 From: tangyuxin <462747508@qq.com> Date: Wed, 3 Apr 2019 18:09:52 +0800 Subject: [components][dfs]格式化代码 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dfs/filesystems/devfs/devfs.c | 20 ++-- components/dfs/filesystems/elmfat/dfs_elm.c | 46 +++++---- components/dfs/filesystems/nfs/dfs_nfs.c | 102 ++++++++++--------- components/dfs/filesystems/ramfs/dfs_ramfs.c | 18 ++-- components/dfs/filesystems/ramfs/dfs_ramfs.h | 4 +- components/dfs/filesystems/romfs/dfs_romfs.c | 4 +- components/dfs/filesystems/romfs/dfs_romfs.h | 4 +- components/dfs/filesystems/romfs/romfs.c | 8 +- components/dfs/filesystems/skeleton/skeleton.c | 20 ++-- components/dfs/filesystems/uffs/dfs_uffs.c | 134 ++++++++++++------------- components/dfs/filesystems/uffs/dfs_uffs.h | 2 +- components/dfs/include/dfs.h | 2 +- components/dfs/include/dfs_fs.h | 10 +- components/dfs/include/dfs_posix.h | 2 +- components/dfs/include/dfs_private.h | 4 +- components/dfs/src/dfs.c | 12 +-- components/dfs/src/dfs_file.c | 30 +++--- components/dfs/src/dfs_fs.c | 42 ++++---- components/dfs/src/dfs_posix.c | 16 +-- components/dfs/src/poll.c | 2 +- components/dfs/src/select.c | 4 +- 21 files changed, 248 insertions(+), 238 deletions(-) (limited to 'components/dfs/src') diff --git a/components/dfs/filesystems/devfs/devfs.c b/components/dfs/filesystems/devfs/devfs.c index 3080312874..936b074ce1 100644 --- a/components/dfs/filesystems/devfs/devfs.c +++ b/components/dfs/filesystems/devfs/devfs.c @@ -97,7 +97,7 @@ int dfs_device_fs_close(struct dfs_fd *file) root_dirent = (struct device_dirent *)file->data; RT_ASSERT(root_dirent != RT_NULL); - + /* release dirent */ rt_free(root_dirent); return RT_EOK; @@ -133,7 +133,7 @@ int dfs_device_fs_open(struct dfs_fd *file) struct rt_object_information *information; struct device_dirent *root_dirent; rt_uint32_t count = 0; - + /* lock scheduler */ rt_enter_critical(); @@ -145,8 +145,8 @@ int dfs_device_fs_open(struct dfs_fd *file) count ++; } - root_dirent = (struct device_dirent *)rt_malloc(sizeof(struct device_dirent) + - count * sizeof(rt_device_t)); + root_dirent = (struct device_dirent *)rt_malloc(sizeof(struct device_dirent) + + count * sizeof(rt_device_t)); if (root_dirent != RT_NULL) { root_dirent->devices = (rt_device_t *)(root_dirent + 1); @@ -165,7 +165,7 @@ int dfs_device_fs_open(struct dfs_fd *file) /* set data */ file->data = root_dirent; - + return RT_EOK; } @@ -178,7 +178,7 @@ int dfs_device_fs_open(struct dfs_fd *file) { /* use device fops */ file->fops = device->fops; - file->data = (void*)device; + file->data = (void *)device; /* use fops */ if (file->fops->open) @@ -214,7 +214,7 @@ int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct stat st->st_dev = 0; st->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH | - S_IWUSR | S_IWGRP | S_IWOTH; + S_IWUSR | S_IWGRP | S_IWOTH; st->st_mode &= ~S_IFREG; st->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; @@ -233,7 +233,7 @@ int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct stat st->st_dev = 0; st->st_mode = S_IRUSR | S_IRGRP | S_IROTH | - S_IWUSR | S_IWGRP | S_IWOTH; + S_IWUSR | S_IWGRP | S_IWOTH; if (dev_id->type == RT_Device_Class_Char) st->st_mode |= S_IFCHR; @@ -293,7 +293,7 @@ static int dfs_device_fs_poll(struct dfs_fd *fd, struct rt_pollreq *req) return mask; } -static const struct dfs_file_ops _device_fops = +static const struct dfs_file_ops _device_fops = { dfs_device_fs_open, dfs_device_fs_close, @@ -306,7 +306,7 @@ static const struct dfs_file_ops _device_fops = dfs_device_fs_poll, }; -static const struct dfs_filesystem_ops _device_fs = +static const struct dfs_filesystem_ops _device_fs = { "devfs", DFS_FS_FLAG_DEFAULT, diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index 582333a714..a45c15aa03 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -101,7 +101,7 @@ int dfs_elm_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *d FRESULT result; int index; struct rt_device_blk_geometry geometry; - char logic_nbr[2] = {'0',':'}; + char logic_nbr[2] = {'0', ':'}; /* get an empty position */ index = get_disk(RT_NULL); @@ -129,7 +129,7 @@ int dfs_elm_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *d } /* mount fatfs, always 0 logic driver */ - result = f_mount(fat, (const TCHAR*)logic_nbr, 1); + result = f_mount(fat, (const TCHAR *)logic_nbr, 1); if (result == FR_OK) { char drive[8]; @@ -139,7 +139,7 @@ int dfs_elm_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *d dir = (DIR *)rt_malloc(sizeof(DIR)); if (dir == RT_NULL) { - f_mount(RT_NULL, (const TCHAR*)logic_nbr, 1); + f_mount(RT_NULL, (const TCHAR *)logic_nbr, 1); disk[index] = RT_NULL; rt_free(fat); return -ENOMEM; @@ -157,7 +157,7 @@ int dfs_elm_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *d } __err: - f_mount(RT_NULL, (const TCHAR*)logic_nbr, 1); + f_mount(RT_NULL, (const TCHAR *)logic_nbr, 1); disk[index] = RT_NULL; rt_free(fat); return elm_result_to_dfs(result); @@ -168,7 +168,7 @@ int dfs_elm_unmount(struct dfs_filesystem *fs) FATFS *fat; FRESULT result; int index; - char logic_nbr[2] = {'0',':'}; + char logic_nbr[2] = {'0', ':'}; fat = (FATFS *)fs->data; @@ -180,7 +180,7 @@ int dfs_elm_unmount(struct dfs_filesystem *fs) return -ENOENT; logic_nbr[0] = '0' + index; - result = f_mount(RT_NULL, logic_nbr, (BYTE)1); + result = f_mount(RT_NULL, logic_nbr, (BYTE)1); if (result != FR_OK) return elm_result_to_dfs(result); @@ -200,10 +200,11 @@ int dfs_elm_mkfs(rt_device_t dev_id) int flag; FRESULT result; int index; - char logic_nbr[2] = {'0',':'}; - + char logic_nbr[2] = {'0', ':'}; + work = rt_malloc(_MAX_SS); - if(RT_NULL == work) { + if (RT_NULL == work) + { return -ENOMEM; } @@ -265,14 +266,15 @@ int dfs_elm_mkfs(rt_device_t dev_id) /* [IN] Size of the allocation unit */ /* [-] Working buffer */ /* [IN] Size of working buffer */ - result = f_mkfs(logic_nbr, FM_ANY|FM_SFD, 0, work, _MAX_SS); - rt_free(work); work = RT_NULL; + result = f_mkfs(logic_nbr, FM_ANY | FM_SFD, 0, work, _MAX_SS); + rt_free(work); + work = RT_NULL; /* check flag status, we need clear the temp driver stored in disk[] */ if (flag == FSM_STATUS_USE_TEMP_DRIVER) { rt_free(fat); - f_mount(RT_NULL, logic_nbr,(BYTE)index); + f_mount(RT_NULL, logic_nbr, (BYTE)index); disk[index] = RT_NULL; /* close device */ rt_device_close(dev_id); @@ -778,7 +780,7 @@ int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) return elm_result_to_dfs(result); } -static const struct dfs_file_ops dfs_elm_fops = +static const struct dfs_file_ops dfs_elm_fops = { dfs_elm_open, dfs_elm_close, @@ -834,7 +836,7 @@ DSTATUS disk_status(BYTE drv) } /* Read Sector(s) */ -DRESULT disk_read (BYTE drv, BYTE* buff, DWORD sector, UINT count) +DRESULT disk_read(BYTE drv, BYTE *buff, DWORD sector, UINT count) { rt_size_t result; rt_device_t device = disk[drv]; @@ -849,7 +851,7 @@ DRESULT disk_read (BYTE drv, BYTE* buff, DWORD sector, UINT count) } /* Write Sector(s) */ -DRESULT disk_write (BYTE drv, const BYTE* buff, DWORD sector, UINT count) +DRESULT disk_write(BYTE drv, const BYTE *buff, DWORD sector, UINT count) { rt_size_t result; rt_device_t device = disk[drv]; @@ -916,7 +918,7 @@ DWORD get_fattime(void) { DWORD fat_time = 0; -#ifdef RT_USING_LIBC +#ifdef RT_USING_LIBC time_t now; struct tm *p_tm; struct tm tm_now; @@ -933,12 +935,12 @@ DWORD get_fattime(void) /* unlock scheduler. */ rt_exit_critical(); - fat_time = (DWORD)(tm_now.tm_year - 80) << 25 | - (DWORD)(tm_now.tm_mon + 1) << 21 | - (DWORD)tm_now.tm_mday << 16 | - (DWORD)tm_now.tm_hour << 11 | - (DWORD)tm_now.tm_min << 5 | - (DWORD)tm_now.tm_sec / 2 ; + fat_time = (DWORD)(tm_now.tm_year - 80) << 25 | + (DWORD)(tm_now.tm_mon + 1) << 21 | + (DWORD)tm_now.tm_mday << 16 | + (DWORD)tm_now.tm_hour << 11 | + (DWORD)tm_now.tm_min << 5 | + (DWORD)tm_now.tm_sec / 2 ; #endif /* RT_USING_LIBC */ return fat_time; diff --git a/components/dfs/filesystems/nfs/dfs_nfs.c b/components/dfs/filesystems/nfs/dfs_nfs.c index ea055b73c1..f365314564 100644 --- a/components/dfs/filesystems/nfs/dfs_nfs.c +++ b/components/dfs/filesystems/nfs/dfs_nfs.c @@ -6,7 +6,7 @@ * Change Logs: * Date Author Notes */ - + #include #include #include @@ -65,9 +65,9 @@ typedef struct nfs_dir nfs_dir; nfs_dir *nfs_opendir(nfs_filesystem *nfs, const char *path); -static int nfs_parse_host_export(const char *host_export, +static int nfs_parse_host_export(const char *host_export, char *host, - size_t host_len, + size_t host_len, char *export, size_t export_len) { @@ -99,7 +99,7 @@ static int nfs_parse_host_export(const char *host_export, /* copy export path */ for (index = host_len; index < host_len + export_len; index ++) { - if (host_export[index] == 0) + if (host_export[index] == 0) { export[index - host_len] = '\0'; @@ -133,11 +133,11 @@ static nfs_fh3 *get_handle(nfs_filesystem *nfs, const char *name) char *path; char *init; - init = path = rt_malloc(strlen(name)+1); + init = path = rt_malloc(strlen(name) + 1); if (init == NULL) return NULL; - memcpy(init, name, strlen(name)+1); + memcpy(init, name, strlen(name) + 1); handle = rt_malloc(sizeof(nfs_fh3)); if (handle == NULL) @@ -202,10 +202,10 @@ static nfs_fh3 *get_dir_handle(nfs_filesystem *nfs, const char *name) char *path; char *init; - init = path = rt_malloc(strlen(name)+1); + init = path = rt_malloc(strlen(name) + 1); if (init == NULL) return NULL; - memcpy(init, name, strlen(name)+1); + memcpy(init, name, strlen(name) + 1); handle = rt_malloc(sizeof(nfs_fh3)); if (handle == NULL) @@ -274,7 +274,7 @@ static size_t nfs_get_filesize(nfs_filesystem *nfs, nfs_fh3 *handle) memset(&res, '\0', sizeof(res)); - if ((nfsproc3_getattr_3(args, &res, nfs->nfs_client)!=RPC_SUCCESS) || + if ((nfsproc3_getattr_3(args, &res, nfs->nfs_client) != RPC_SUCCESS) || res.status != NFS3_OK) { rt_kprintf("GetAttr failed: %d\n", res.status); @@ -285,7 +285,7 @@ static size_t nfs_get_filesize(nfs_filesystem *nfs, nfs_fh3 *handle) info = &res.GETATTR3res_u.resok.obj_attributes; size = info->size; xdr_free((xdrproc_t)xdr_GETATTR3res, (char *)&res); - + return size; } @@ -319,7 +319,7 @@ rt_bool_t nfs_is_directory(nfs_filesystem *nfs, const char *name) return RT_FALSE; } - info=&res.GETATTR3res_u.resok.obj_attributes; + info = &res.GETATTR3res_u.resok.obj_attributes; if (info->type == NFS3DIR) result = RT_TRUE; @@ -327,7 +327,7 @@ rt_bool_t nfs_is_directory(nfs_filesystem *nfs, const char *name) xdr_free((xdrproc_t)xdr_GETATTR3res, (char *)&res); xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)handle); rt_free(handle); - + return result; } @@ -427,7 +427,7 @@ int nfs_mkdir(nfs_filesystem *nfs, const char *name, mode_t mode) xdr_free((xdrproc_t)xdr_MKDIR3res, (char *)&res); xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)handle); rt_free(handle); - + return ret; } @@ -441,13 +441,13 @@ int nfs_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data) memset(nfs, 0, sizeof(nfs_filesystem)); if (nfs_parse_host_export((const char *)data, nfs->host, HOST_LENGTH, - nfs->export, EXPORT_PATH_LENGTH) < 0) + nfs->export, EXPORT_PATH_LENGTH) < 0) { rt_kprintf("host or export path error\n"); goto __return; } - nfs->mount_client=clnt_create((char *)nfs->host, MOUNT_PROGRAM, MOUNT_V3, "udp"); + nfs->mount_client = clnt_create((char *)nfs->host, MOUNT_PROGRAM, MOUNT_V3, "udp"); if (nfs->mount_client == NULL) { rt_kprintf("create mount client failed\n"); @@ -465,7 +465,7 @@ int nfs_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data) rt_kprintf("nfs mount failed\n"); goto __return; } - nfs->nfs_client=clnt_create((char *)nfs->host, NFS_PROGRAM, NFS_V3, "udp"); + nfs->nfs_client = clnt_create((char *)nfs->host, NFS_PROGRAM, NFS_V3, "udp"); if (nfs->nfs_client == NULL) { rt_kprintf("creat nfs client failed\n"); @@ -555,7 +555,7 @@ int nfs_read(struct dfs_fd *file, void *buf, size_t count) { READ3args args; READ3res res; - ssize_t bytes, total=0; + ssize_t bytes, total = 0; nfs_file *fd; nfs_filesystem *nfs; @@ -564,8 +564,8 @@ int nfs_read(struct dfs_fd *file, void *buf, size_t count) RT_ASSERT(file->data != NULL); - struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem*)(file->data)); - nfs = (struct nfs_filesystem *)(dfs_nfs->data); + struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->data)); + nfs = (struct nfs_filesystem *)(dfs_nfs->data); fd = (nfs_file *)(nfs->data); RT_ASSERT(fd != NULL); @@ -577,7 +577,8 @@ int nfs_read(struct dfs_fd *file, void *buf, size_t count) return 0; args.file = fd->handle; - do { + do + { args.offset = fd->offset; args.count = count > DFS_NFS_MAX_MTU ? DFS_NFS_MAX_MTU : count; count -= args.count; @@ -612,7 +613,8 @@ int nfs_read(struct dfs_fd *file, void *buf, size_t count) } } xdr_free((xdrproc_t)xdr_READ3res, (char *)&res); - } while(count > 0); + } + while (count > 0); xdr_free((xdrproc_t)xdr_READ3res, (char *)&res); @@ -623,7 +625,7 @@ int nfs_write(struct dfs_fd *file, const void *buf, size_t count) { WRITE3args args; WRITE3res res; - ssize_t bytes, total=0; + ssize_t bytes, total = 0; nfs_file *fd; nfs_filesystem *nfs; @@ -631,8 +633,8 @@ int nfs_write(struct dfs_fd *file, const void *buf, size_t count) return -EISDIR; RT_ASSERT(file->data != NULL); - struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem*)(file->data)); - nfs = (struct nfs_filesystem *)(dfs_nfs->data); + struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->data)); + nfs = (struct nfs_filesystem *)(dfs_nfs->data); fd = (nfs_file *)(nfs->data); RT_ASSERT(fd != NULL); @@ -642,11 +644,12 @@ int nfs_write(struct dfs_fd *file, const void *buf, size_t count) args.file = fd->handle; args.stable = FILE_SYNC; - do { + do + { args.offset = fd->offset; memset(&res, 0, sizeof(res)); - args.data.data_val=(void *)buf; + args.data.data_val = (void *)buf; args.count = count > DFS_NFS_MAX_MTU ? DFS_NFS_MAX_MTU : count; args.data.data_len = args.count; count -= args.count; @@ -676,7 +679,8 @@ int nfs_write(struct dfs_fd *file, const void *buf, size_t count) file->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,8 +696,8 @@ int nfs_lseek(struct dfs_fd *file, off_t offset) return -EISDIR; RT_ASSERT(file->data != NULL); - struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem*)(file->data)); - nfs = (struct nfs_filesystem *)(dfs_nfs->data); + struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->data)); + nfs = (struct nfs_filesystem *)(dfs_nfs->data); fd = (nfs_file *)(nfs->data); RT_ASSERT(fd != NULL); @@ -711,8 +715,8 @@ 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)); - nfs = (struct nfs_filesystem *)(dfs_nfs->data); + struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->data)); + nfs = (struct nfs_filesystem *)(dfs_nfs->data); if (file->type == FT_DIRECTORY) { @@ -741,14 +745,14 @@ 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)); - nfs = (struct nfs_filesystem *)(dfs_nfs->data); + struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->data)); + nfs = (struct nfs_filesystem *)(dfs_nfs->data); if (file->flags & O_DIRECTORY) { nfs_dir *dir; - + if (file->flags & O_CREAT) { if (nfs_mkdir(nfs, file->path, 0755) < 0) @@ -930,7 +934,7 @@ char *nfs_readdir(nfs_filesystem *nfs, nfs_dir *dir) return NULL; dir->cookie = dir->entry->cookie; - strncpy(name, dir->entry->name, NAME_MAX-1); + strncpy(name, dir->entry->name, NAME_MAX - 1); dir->entry = dir->entry->nextentry; name[NAME_MAX - 1] = '\0'; @@ -1013,7 +1017,7 @@ int nfs_unlink(struct dfs_filesystem *fs, const char *path) xdr_free((xdrproc_t)xdr_RMDIR3res, (char *)&res); xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)handle); - rt_free(handle); + rt_free(handle); } return ret; @@ -1083,8 +1087,8 @@ int nfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count) RT_ASSERT(file->data != NULL); - struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem*)(file->data)); - nfs = (struct nfs_filesystem *)(dfs_nfs->data); + struct dfs_filesystem *dfs_nfs = ((struct dfs_filesystem *)(file->data)); + nfs = (struct nfs_filesystem *)(dfs_nfs->data); dir = (nfs_dir *)(nfs->data); RT_ASSERT(dir != NULL); @@ -1118,18 +1122,18 @@ int nfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count) static const struct dfs_file_ops nfs_fops = { - nfs_open, - nfs_close, - nfs_ioctl, - nfs_read, - nfs_write, - NULL, /* flush */ - nfs_lseek, - nfs_getdents, - NULL, /* poll */ + nfs_open, + nfs_close, + nfs_ioctl, + nfs_read, + nfs_write, + NULL, /* flush */ + nfs_lseek, + nfs_getdents, + NULL, /* poll */ }; -static const struct dfs_filesystem_ops _nfs = +static const struct dfs_filesystem_ops _nfs = { "nfs", DFS_FS_FLAG_DEFAULT, @@ -1138,7 +1142,7 @@ static const struct dfs_filesystem_ops _nfs = nfs_unmount, NULL, /* mkfs */ NULL, /* statfs */ - nfs_unlink, + nfs_unlink, nfs_stat, nfs_rename, }; diff --git a/components/dfs/filesystems/ramfs/dfs_ramfs.c b/components/dfs/filesystems/ramfs/dfs_ramfs.c index e851c7ef78..aa85081e1e 100644 --- a/components/dfs/filesystems/ramfs/dfs_ramfs.c +++ b/components/dfs/filesystems/ramfs/dfs_ramfs.c @@ -21,14 +21,14 @@ int dfs_ramfs_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data) { - struct dfs_ramfs* ramfs; + struct dfs_ramfs *ramfs; if (data == NULL) return -EIO; ramfs = (struct dfs_ramfs *)data; fs->data = ramfs; - + return RT_EOK; } @@ -48,8 +48,8 @@ int dfs_ramfs_statfs(struct dfs_filesystem *fs, struct statfs *buf) RT_ASSERT(buf != NULL); buf->f_bsize = 512; - buf->f_blocks = ramfs->memheap.pool_size/512; - buf->f_bfree = ramfs->memheap.available_size/512; + buf->f_blocks = ramfs->memheap.pool_size / 512; + buf->f_bfree = ramfs->memheap.available_size / 512; return RT_EOK; } @@ -119,7 +119,7 @@ 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->data; RT_ASSERT(dirent != NULL); ramfs = dirent->fs; @@ -260,7 +260,7 @@ int dfs_ramfs_open(struct dfs_fd *file) file->size = dirent->size; if (file->flags & O_APPEND) file->pos = file->size; - else + else file->pos = 0; return 0; @@ -381,7 +381,7 @@ int dfs_ramfs_rename(struct dfs_filesystem *fs, return RT_EOK; } -static const struct dfs_file_ops _ram_fops = +static const struct dfs_file_ops _ram_fops = { dfs_ramfs_open, dfs_ramfs_close, @@ -418,7 +418,7 @@ int dfs_ramfs_init(void) } INIT_COMPONENT_EXPORT(dfs_ramfs_init); -struct dfs_ramfs* dfs_ramfs_create(rt_uint8_t *pool, rt_size_t size) +struct dfs_ramfs *dfs_ramfs_create(rt_uint8_t *pool, rt_size_t size) { struct dfs_ramfs *ramfs; rt_uint8_t *data_ptr; @@ -435,7 +435,7 @@ struct dfs_ramfs* dfs_ramfs_create(rt_uint8_t *pool, rt_size_t size) if (result != RT_EOK) return NULL; /* detach this memheap object from the system */ - rt_object_detach((rt_object_t)&(ramfs->memheap)); + rt_object_detach((rt_object_t) & (ramfs->memheap)); /* initialize ramfs object */ ramfs->magic = RAMFS_MAGIC; diff --git a/components/dfs/filesystems/ramfs/dfs_ramfs.h b/components/dfs/filesystems/ramfs/dfs_ramfs.h index 9419784db9..4975ecb332 100644 --- a/components/dfs/filesystems/ramfs/dfs_ramfs.h +++ b/components/dfs/filesystems/ramfs/dfs_ramfs.h @@ -24,7 +24,7 @@ struct ramfs_dirent struct dfs_ramfs *fs; /* file system ref */ char name[RAMFS_NAME_MAX]; /* dirent name */ - rt_uint8_t* data; + rt_uint8_t *data; rt_size_t size; /* file size */ }; @@ -41,7 +41,7 @@ struct dfs_ramfs }; int dfs_ramfs_init(void); -struct dfs_ramfs* dfs_ramfs_create(rt_uint8_t* pool, rt_size_t size); +struct dfs_ramfs *dfs_ramfs_create(rt_uint8_t *pool, rt_size_t size); #endif diff --git a/components/dfs/filesystems/romfs/dfs_romfs.c b/components/dfs/filesystems/romfs/dfs_romfs.c index a953ac72d5..dcc34e5830 100644 --- a/components/dfs/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/filesystems/romfs/dfs_romfs.c @@ -105,7 +105,7 @@ struct romfs_dirent *dfs_romfs_lookup(struct romfs_dirent *root_dirent, const ch if (dirent[index].type == ROMFS_DIRENT_DIR) { /* enter directory */ - dirent = (struct romfs_dirent*)dirent[index].data; + dirent = (struct romfs_dirent *)dirent[index].data; found = 1; break; } @@ -226,7 +226,7 @@ int dfs_romfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) st->st_dev = 0; st->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH | - S_IWUSR | S_IWGRP | S_IWOTH; + S_IWUSR | S_IWGRP | S_IWOTH; if (dirent->type == ROMFS_DIRENT_DIR) { diff --git a/components/dfs/filesystems/romfs/dfs_romfs.h b/components/dfs/filesystems/romfs/dfs_romfs.h index efb6d44caf..ba6a3d7dfa 100644 --- a/components/dfs/filesystems/romfs/dfs_romfs.h +++ b/components/dfs/filesystems/romfs/dfs_romfs.h @@ -13,8 +13,8 @@ #include -#define ROMFS_DIRENT_FILE 0x00 -#define ROMFS_DIRENT_DIR 0x01 +#define ROMFS_DIRENT_FILE 0x00 +#define ROMFS_DIRENT_DIR 0x01 struct romfs_dirent { diff --git a/components/dfs/filesystems/romfs/romfs.c b/components/dfs/filesystems/romfs/romfs.c index 1ea9f21d8e..cfce09a095 100644 --- a/components/dfs/filesystems/romfs/romfs.c +++ b/components/dfs/filesystems/romfs/romfs.c @@ -12,7 +12,7 @@ const static unsigned char _dummy_dummy_txt[] = { - 0x74,0x68,0x69,0x73,0x20,0x69,0x73,0x20,0x61,0x20,0x66,0x69,0x6c,0x65,0x21,0x0d,0x0a, + 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x21, 0x0d, 0x0a, }; const static struct romfs_dirent _dummy[] = @@ -22,17 +22,17 @@ const static struct romfs_dirent _dummy[] = const static unsigned char _dummy_txt[] = { - 0x74,0x68,0x69,0x73,0x20,0x69,0x73,0x20,0x61,0x20,0x66,0x69,0x6c,0x65,0x21,0x0d,0x0a, + 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x21, 0x0d, 0x0a, }; RT_WEAK const struct romfs_dirent _root_dirent[] = { - {ROMFS_DIRENT_DIR, "dummy", (rt_uint8_t *)_dummy, sizeof(_dummy)/sizeof(_dummy[0])}, + {ROMFS_DIRENT_DIR, "dummy", (rt_uint8_t *)_dummy, sizeof(_dummy) / sizeof(_dummy[0])}, {ROMFS_DIRENT_FILE, "dummy.txt", _dummy_txt, sizeof(_dummy_txt)}, }; RT_WEAK const struct romfs_dirent romfs_root = { - ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_root_dirent, sizeof(_root_dirent)/sizeof(_root_dirent[0]) + ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_root_dirent, sizeof(_root_dirent) / sizeof(_root_dirent[0]) }; diff --git a/components/dfs/filesystems/skeleton/skeleton.c b/components/dfs/filesystems/skeleton/skeleton.c index 30f0d4f629..0c20513e82 100644 --- a/components/dfs/filesystems/skeleton/skeleton.c +++ b/components/dfs/filesystems/skeleton/skeleton.c @@ -14,52 +14,52 @@ #include "dfs_skt_fs.h" -int dfs_skt_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* data) +int dfs_skt_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data) { return RT_EOK; } -int dfs_skt_unmount(struct dfs_filesystem* fs) +int dfs_skt_unmount(struct dfs_filesystem *fs) { return RT_EOK; } -int dfs_skt_ioctl(struct dfs_fd* file, int cmd, void* args) +int dfs_skt_ioctl(struct dfs_fd *file, int cmd, void *args) { return -RT_EIO; } -int dfs_skt_read(struct dfs_fd* file, void *buf, rt_size_t count) +int dfs_skt_read(struct dfs_fd *file, void *buf, rt_size_t count) { return count; } -int dfs_skt_lseek(struct dfs_fd* file, rt_off_t offset) +int dfs_skt_lseek(struct dfs_fd *file, rt_off_t offset) { return -RT_EIO; } -int dfs_skt_close(struct dfs_fd* file) +int dfs_skt_close(struct dfs_fd *file) { return RT_EOK; } -int dfs_skt_open(struct dfs_fd* file) +int dfs_skt_open(struct dfs_fd *file) { return RT_EOK; } -int dfs_skt_stat(struct dfs_filesystem* fs, const char *path, struct stat *st) +int dfs_skt_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) { return RT_EOK; } -int dfs_skt_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t count) +int dfs_skt_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint32_t count) { return count * sizeof(struct dirent); } -static const struct dfs_file_ops _skt_fops = +static const struct dfs_file_ops _skt_fops = { dfs_skt_open, dfs_skt_close, diff --git a/components/dfs/filesystems/uffs/dfs_uffs.c b/components/dfs/filesystems/uffs/dfs_uffs.c index b875d1eb00..c89102f3e3 100644 --- a/components/dfs/filesystems/uffs/dfs_uffs.c +++ b/components/dfs/filesystems/uffs/dfs_uffs.c @@ -33,12 +33,12 @@ struct _nand_dev { - struct rt_mtd_nand_device * dev; + struct rt_mtd_nand_device *dev; struct uffs_StorageAttrSt storage; uffs_Device uffs_dev; uffs_MountTable mount_table; char mount_path[UFFS_MOUNT_PATH_MAX]; - void * data; /* when uffs use static buf, it will save ptr here */ + void *data; /* when uffs use static buf, it will save ptr here */ }; /* make sure the following struct var had been initilased to 0! */ static struct _nand_dev nand_part[UFFS_DEVICE_MAX] = {0}; @@ -109,11 +109,11 @@ static URET _device_release(uffs_Device *dev) } static int init_uffs_fs( - struct _nand_dev * nand_part) + struct _nand_dev *nand_part) { - uffs_MountTable * mtb; - struct rt_mtd_nand_device * nand; - struct uffs_StorageAttrSt * flash_storage; + uffs_MountTable *mtb; + struct rt_mtd_nand_device *nand; + struct uffs_StorageAttrSt *flash_storage; mtb = &nand_part->mount_table; nand = nand_part->dev; @@ -123,7 +123,7 @@ static int init_uffs_fs( uffs_setup_storage(flash_storage, nand); /* register mount table */ - if(mtb->dev) + if (mtb->dev) { /* set memory allocator for uffs */ #if CONFIG_USE_SYSTEM_MEMORY_ALLOCATOR > 0 @@ -141,15 +141,15 @@ static int init_uffs_fs( } static int dfs_uffs_mount( - struct dfs_filesystem* fs, + struct dfs_filesystem *fs, unsigned long rwflag, - const void* data) + const void *data) { rt_base_t index; - uffs_MountTable * mount_part; - struct rt_mtd_nand_device * dev; - - RT_ASSERT(rt_strlen(fs->path) < (UFFS_MOUNT_PATH_MAX-1)); + uffs_MountTable *mount_part; + struct rt_mtd_nand_device *dev; + + RT_ASSERT(rt_strlen(fs->path) < (UFFS_MOUNT_PATH_MAX - 1)); dev = RT_MTD_NAND_DEVICE(fs->dev_id); /*1. find a empty entry in partition table */ @@ -184,7 +184,7 @@ static int dfs_uffs_mount( return 0; } -static int dfs_uffs_unmount(struct dfs_filesystem* fs) +static int dfs_uffs_unmount(struct dfs_filesystem *fs) { rt_base_t index; int result; @@ -210,7 +210,7 @@ static int dfs_uffs_mkfs(rt_device_t dev_id) { rt_base_t index; rt_uint32_t block; - struct rt_mtd_nand_device * mtd; + struct rt_mtd_nand_device *mtd; /*1. find the device index */ for (index = 0; index < UFFS_DEVICE_MAX; index++) @@ -249,11 +249,11 @@ static int dfs_uffs_mkfs(rt_device_t dev_id) return RT_EOK; } -static int dfs_uffs_statfs(struct dfs_filesystem* fs, - struct statfs *buf) +static int dfs_uffs_statfs(struct dfs_filesystem *fs, + struct statfs *buf) { rt_base_t index; - struct rt_mtd_nand_device * mtd = RT_MTD_NAND_DEVICE(fs->dev_id); + struct rt_mtd_nand_device *mtd = RT_MTD_NAND_DEVICE(fs->dev_id); RT_ASSERT(mtd != RT_NULL); @@ -265,24 +265,24 @@ static int dfs_uffs_statfs(struct dfs_filesystem* fs, } if (index == UFFS_DEVICE_MAX) return -ENOENT; - - buf->f_bsize = mtd->page_size*mtd->pages_per_block; + + buf->f_bsize = mtd->page_size * mtd->pages_per_block; buf->f_blocks = (mtd->block_end - mtd->block_start + 1); - buf->f_bfree = uffs_GetDeviceFree(&nand_part[index].uffs_dev)/buf->f_bsize ; - + buf->f_bfree = uffs_GetDeviceFree(&nand_part[index].uffs_dev) / buf->f_bsize ; + return 0; } -static int dfs_uffs_open(struct dfs_fd* file) +static int dfs_uffs_open(struct dfs_fd *file) { int fd; int oflag, mode; - char * file_path; + char *file_path; oflag = file->flags; if (oflag & O_DIRECTORY) /* operations about dir */ { - uffs_DIR * dir; + uffs_DIR *dir; if (oflag & O_CREAT) /* create a dir*/ { @@ -291,8 +291,8 @@ static int dfs_uffs_open(struct dfs_fd* file) } /* open dir */ file_path = rt_malloc(FILE_PATH_MAX); - if(file_path == RT_NULL) - return -ENOMEM; + if (file_path == RT_NULL) + return -ENOMEM; if (file->path[0] == '/' && !(file->path[1] == 0)) rt_snprintf(file_path, FILE_PATH_MAX, "%s/", file->path); @@ -306,7 +306,7 @@ static int dfs_uffs_open(struct dfs_fd* file) if (dir == RT_NULL) { - rt_free(file_path); + rt_free(file_path); return uffs_result_to_dfs(uffs_get_error()); } /* save this pointer,will used by dfs_uffs_getdents*/ @@ -349,7 +349,7 @@ static int dfs_uffs_open(struct dfs_fd* file) return 0; } -static int dfs_uffs_close(struct dfs_fd* file) +static int dfs_uffs_close(struct dfs_fd *file) { int oflag; int fd; @@ -372,12 +372,12 @@ static int dfs_uffs_close(struct dfs_fd* file) return uffs_result_to_dfs(uffs_get_error()); } -static int dfs_uffs_ioctl(struct dfs_fd * file, int cmd, void* args) +static int dfs_uffs_ioctl(struct dfs_fd *file, int cmd, void *args) { return -ENOSYS; } -static int dfs_uffs_read(struct dfs_fd * file, void* buf, size_t len) +static int dfs_uffs_read(struct dfs_fd *file, void *buf, size_t len) { int fd; int char_read; @@ -392,9 +392,9 @@ static int dfs_uffs_read(struct dfs_fd * file, void* buf, size_t len) return char_read; } -static int dfs_uffs_write(struct dfs_fd* file, - const void* buf, - size_t len) +static int dfs_uffs_write(struct dfs_fd *file, + const void *buf, + size_t len) { int fd; int char_write; @@ -410,7 +410,7 @@ static int dfs_uffs_write(struct dfs_fd* file, return char_write; } -static int dfs_uffs_flush(struct dfs_fd* file) +static int dfs_uffs_flush(struct dfs_fd *file) { int fd; int result; @@ -418,7 +418,7 @@ static int dfs_uffs_flush(struct dfs_fd* file) fd = (int)(file->data); result = uffs_flush(fd); - if (result < 0 ) + if (result < 0) return uffs_result_to_dfs(uffs_get_error()); return 0; } @@ -427,18 +427,18 @@ int uffs_seekdir(uffs_DIR *dir, long offset) { int i = 0; - while(i < offset) - { + while (i < offset) + { if (uffs_readdir(dir) == RT_NULL) return -1; i++; - } + } return 0; } -static int dfs_uffs_seek(struct dfs_fd* file, - rt_off_t offset) +static int dfs_uffs_seek(struct dfs_fd *file, + rt_off_t offset) { int result; @@ -446,17 +446,17 @@ static int dfs_uffs_seek(struct dfs_fd* file, if (file->type == FT_DIRECTORY) { uffs_rewinddir((uffs_DIR *)(file->data)); - result = uffs_seekdir((uffs_DIR *)(file->data), offset/sizeof(struct dirent)); + result = uffs_seekdir((uffs_DIR *)(file->data), offset / sizeof(struct dirent)); if (result >= 0) { - file->pos = offset; + file->pos = offset; return offset; } } else if (file->type == FT_REGULAR) { result = uffs_seek((int)(file->data), offset, USEEK_SET); - if (result >= 0) + if (result >= 0) return offset; } @@ -465,19 +465,19 @@ static int dfs_uffs_seek(struct dfs_fd* file, /* return the size of struct dirent*/ static int dfs_uffs_getdents( - struct dfs_fd* file, - struct dirent* dirp, + struct dfs_fd *file, + struct dirent *dirp, uint32_t count) { rt_uint32_t index; - char * file_path; - struct dirent* d; - uffs_DIR* dir; - struct uffs_dirent * uffs_d; - - dir = (uffs_DIR*)(file->data); + char *file_path; + struct dirent *d; + uffs_DIR *dir; + struct uffs_dirent *uffs_d; + + dir = (uffs_DIR *)(file->data); RT_ASSERT(dir != RT_NULL); - + /* round count, count is always 1 */ count = (count / sizeof(struct dirent)) * sizeof(struct dirent); if (count == 0) return -EINVAL; @@ -486,13 +486,13 @@ static int dfs_uffs_getdents( file_path = rt_malloc(FILE_PATH_MAX); if (file_path == RT_NULL) return -ENOMEM; - + index = 0; /* usually, the while loop should only be looped only once! */ while (1) { struct uffs_stat s; - + d = dirp + index; uffs_d = uffs_readdir(dir); @@ -507,8 +507,8 @@ static int dfs_uffs_getdents( else rt_strncpy(file_path, uffs_d->d_name, FILE_PATH_MAX); - uffs_stat(file_path, &s); - switch(s.st_mode & US_IFMT) /* file type mark */ + uffs_stat(file_path, &s); + switch (s.st_mode & US_IFMT) /* file type mark */ { case US_IFREG: /* directory */ d->d_type = DT_REG; @@ -533,10 +533,10 @@ static int dfs_uffs_getdents( if (index * sizeof(struct dirent) >= count) break; } - + /* free file name buf */ rt_free(file_path); - + if (index == 0) return uffs_result_to_dfs(uffs_get_error()); @@ -545,7 +545,7 @@ static int dfs_uffs_getdents( return index * sizeof(struct dirent); } -static int dfs_uffs_unlink(struct dfs_filesystem* fs, const char* path) +static int dfs_uffs_unlink(struct dfs_filesystem *fs, const char *path) { int result; struct uffs_stat s; @@ -556,7 +556,7 @@ static int dfs_uffs_unlink(struct dfs_filesystem* fs, const char* path) return uffs_result_to_dfs(uffs_get_error()); } - switch(s.st_mode & US_IFMT) + switch (s.st_mode & US_IFMT) { case US_IFREG: result = uffs_remove(path); @@ -575,12 +575,12 @@ static int dfs_uffs_unlink(struct dfs_filesystem* fs, const char* path) } static int dfs_uffs_rename( - struct dfs_filesystem* fs, - const char* oldpath, - const char* newpath) + struct dfs_filesystem *fs, + const char *oldpath, + const char *newpath) { int result; - + result = uffs_rename(oldpath, newpath); if (result < 0) return uffs_result_to_dfs(uffs_get_error()); @@ -588,7 +588,7 @@ static int dfs_uffs_rename( return 0; } -static int dfs_uffs_stat(struct dfs_filesystem* fs, const char *path, struct stat *st) +static int dfs_uffs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) { int result; struct uffs_stat s; @@ -607,7 +607,7 @@ static int dfs_uffs_stat(struct dfs_filesystem* fs, const char *path, struct sta return 0; } -static const struct dfs_file_ops dfs_uffs_fops = +static const struct dfs_file_ops dfs_uffs_fops = { dfs_uffs_open, dfs_uffs_close, diff --git a/components/dfs/filesystems/uffs/dfs_uffs.h b/components/dfs/filesystems/uffs/dfs_uffs.h index 615d29036d..72f0ee9240 100644 --- a/components/dfs/filesystems/uffs/dfs_uffs.h +++ b/components/dfs/filesystems/uffs/dfs_uffs.h @@ -83,7 +83,7 @@ extern const uffs_FlashOps nand_ops; extern void uffs_setup_storage( struct uffs_StorageAttrSt *attr, - struct rt_mtd_nand_device * nand); + struct rt_mtd_nand_device *nand); extern int dfs_uffs_init(void); #endif /* DFS_UFFS_H_ */ diff --git a/components/dfs/include/dfs.h b/components/dfs/include/dfs.h index 7fdcb1cfda..eb32a4b411 100644 --- a/components/dfs/include/dfs.h +++ b/components/dfs/include/dfs.h @@ -102,7 +102,7 @@ struct dfs_fd *fd_get(int fd); void fd_put(struct dfs_fd *fd); int fd_is_open(const char *pathname); -struct dfs_fdtable* dfs_fdtable_get(void); +struct dfs_fdtable *dfs_fdtable_get(void); #ifdef __cplusplus } diff --git a/components/dfs/include/dfs_fs.h b/components/dfs/include/dfs_fs.h index 711771a137..d3a00fc542 100644 --- a/components/dfs/include/dfs_fs.h +++ b/components/dfs/include/dfs_fs.h @@ -7,7 +7,7 @@ * Date Author Notes * 2005-02-22 Bernard The first version. */ - + #ifndef __DFS_FS_H__ #define __DFS_FS_H__ @@ -60,7 +60,7 @@ struct dfs_partition uint8_t type; /* file system type */ off_t offset; /* partition start offset */ size_t size; /* partition size */ - rt_sem_t lock; + rt_sem_t lock; }; /* mount table */ @@ -75,11 +75,11 @@ struct dfs_mount_tbl int dfs_register(const struct dfs_filesystem_ops *ops); struct dfs_filesystem *dfs_filesystem_lookup(const char *path); -const char* dfs_filesystem_get_mounted_path(struct rt_device* device); +const char *dfs_filesystem_get_mounted_path(struct rt_device *device); int dfs_filesystem_get_partition(struct dfs_partition *part, - uint8_t *buf, - uint32_t pindex); + uint8_t *buf, + uint32_t pindex); int dfs_mount(const char *device_name, const char *path, diff --git a/components/dfs/include/dfs_posix.h b/components/dfs/include/dfs_posix.h index bc8ff1c698..9fd76debe2 100644 --- a/components/dfs/include/dfs_posix.h +++ b/components/dfs/include/dfs_posix.h @@ -36,7 +36,7 @@ struct dirent *readdir(DIR *d); long telldir(DIR *d); void seekdir(DIR *d, off_t offset); void rewinddir(DIR *d); -int closedir(DIR* d); +int closedir(DIR *d); /* file api*/ int open(const char *file, int flags, ...); diff --git a/components/dfs/include/dfs_private.h b/components/dfs/include/dfs_private.h index bfc71b3b35..77dbe8562d 100644 --- a/components/dfs/include/dfs_private.h +++ b/components/dfs/include/dfs_private.h @@ -12,8 +12,8 @@ #include -#define DBG_SECTION_NAME "DFS" -#define DBG_LEVEL DBG_INFO +#define DBG_SECTION_NAME "DFS" +#define DBG_LEVEL DBG_INFO #include #define NO_WORKING_DIR "system does not support working directory\n" diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 6d52129b06..5bddb96930 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -139,7 +139,7 @@ static int fd_alloc(struct dfs_fdtable *fdt, int startfd) /* increase the number of FD with 4 step length */ cnt = fdt->maxfd + 4; - cnt = cnt > DFS_FD_MAX? DFS_FD_MAX : cnt; + cnt = cnt > DFS_FD_MAX ? DFS_FD_MAX : cnt; fds = rt_realloc(fdt->fds, cnt * sizeof(struct dfs_fd *)); if (fds == NULL) goto __exit; /* return fdt->maxfd */ @@ -189,7 +189,7 @@ int fd_new(void) if (idx == fdt->maxfd) { idx = -(1 + DFS_FD_OFFSET); - LOG_E( "DFS fd new is failed! Could not found an empty fd entry."); + LOG_E("DFS fd new is failed! Could not found an empty fd entry."); goto __result; } @@ -400,7 +400,7 @@ char *dfs_normalize_path(const char *directory, const char *filename) /* join path and file name */ rt_snprintf(fullpath, strlen(directory) + strlen(filename) + 2, - "%s/%s", directory, filename); + "%s/%s", directory, filename); } else { @@ -499,7 +499,7 @@ RTM_EXPORT(dfs_normalize_path); /** * This function will get the file descriptor table of current process. */ -struct dfs_fdtable* dfs_fdtable_get(void) +struct dfs_fdtable *dfs_fdtable_get(void) { struct dfs_fdtable *fdt; #ifdef RT_USING_LWP @@ -523,12 +523,12 @@ int list_fd(void) { int index; struct dfs_fdtable *fd_table; - + fd_table = dfs_fdtable_get(); if (!fd_table) return -1; rt_enter_critical(); - + rt_kprintf("fd type ref magic path\n"); rt_kprintf("-- ------ --- ----- ------\n"); for (index = 0; index < (int)fd_table->maxfd; index ++) diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index b4f115ffc2..81cab2ed79 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -2,7 +2,7 @@ * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 - * + * * Change Logs: * Date Author Notes * 2005-02-22 Bernard The first version. @@ -543,7 +543,8 @@ void ls(const char *pathname) rt_kprintf("BAD file: %s\n", dirent.d_name); rt_free(fullpath); } - }while(length > 0); + } + while (length > 0); dfs_file_close(&fd); } @@ -565,7 +566,7 @@ void rm(const char *filename) } FINSH_FUNCTION_EXPORT(rm, remove files or directories); -void cat(const char* filename) +void cat(const char *filename) { uint32_t length; char buffer[81]; @@ -580,12 +581,13 @@ void cat(const char* filename) do { memset(buffer, 0, sizeof(buffer)); - length = dfs_file_read(&fd, buffer, sizeof(buffer)-1 ); + length = dfs_file_read(&fd, buffer, sizeof(buffer) - 1); if (length > 0) { rt_kprintf("%s", buffer); } - }while (length > 0); + } + while (length > 0); dfs_file_close(&fd); } @@ -638,7 +640,8 @@ static void copyfile(const char *src, const char *dst) break; } } - } while (read_bytes > 0); + } + while (read_bytes > 0); dfs_file_close(&src_fd); dfs_file_close(&fd); @@ -646,7 +649,7 @@ static void copyfile(const char *src, const char *dst) } extern int mkdir(const char *path, mode_t mode); -static void copydir(const char * src, const char * dst) +static void copydir(const char *src, const char *dst) { struct dirent dirent; struct stat stat; @@ -665,8 +668,8 @@ static void copydir(const char * src, const char * dst) length = dfs_file_getdents(&cpfd, &dirent, sizeof(struct dirent)); if (length > 0) { - char * src_entry_full = NULL; - char * dst_entry_full = NULL; + char *src_entry_full = NULL; + char *dst_entry_full = NULL; if (strcmp(dirent.d_name, "..") == 0 || strcmp(dirent.d_name, ".") == 0) continue; @@ -703,14 +706,15 @@ static void copydir(const char * src, const char * dst) rt_free(src_entry_full); rt_free(dst_entry_full); } - }while(length > 0); + } + while (length > 0); dfs_file_close(&cpfd); } static const char *_get_path_lastname(const char *path) { - char * ptr; + char *ptr; if ((ptr = strrchr(path, '/')) == NULL) return path; @@ -767,7 +771,7 @@ void copy(const char *src, const char *dst) { if (flag & FLAG_DST_IS_DIR) { - char * fdst; + char *fdst; fdst = dfs_normalize_path(dst, _get_path_lastname(src)); if (fdst == NULL) { @@ -786,7 +790,7 @@ void copy(const char *src, const char *dst) { if (flag & FLAG_DST_IS_DIR) { - char * fdst; + char *fdst; fdst = dfs_normalize_path(dst, _get_path_lastname(src)); if (fdst == NULL) { diff --git a/components/dfs/src/dfs_fs.c b/components/dfs/src/dfs_fs.c index a183e7f124..774d008ce6 100644 --- a/components/dfs/src/dfs_fs.c +++ b/components/dfs/src/dfs_fs.c @@ -38,7 +38,7 @@ int dfs_register(const struct dfs_filesystem_ops *ops) dfs_lock(); /* check if this filesystem was already registered */ for (iter = &filesystem_operation_table[0]; - iter < &filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX]; iter ++) + iter < &filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX]; iter ++) { /* find out an empty filesystem type entry */ if (*iter == NULL) @@ -120,9 +120,9 @@ struct dfs_filesystem *dfs_filesystem_lookup(const char *path) * * @return the mounted path or NULL if none device mounted. */ -const char* dfs_filesystem_get_mounted_path(struct rt_device* device) +const char *dfs_filesystem_get_mounted_path(struct rt_device *device) { - const char* path = NULL; + const char *path = NULL; struct dfs_filesystem *iter; dfs_lock(); @@ -154,8 +154,8 @@ const char* dfs_filesystem_get_mounted_path(struct rt_device* device) * @return RT_EOK on successful or -RT_ERROR on failed. */ int dfs_filesystem_get_partition(struct dfs_partition *part, - uint8_t *buf, - uint32_t pindex) + uint8_t *buf, + uint32_t pindex) { #define DPT_ADDRESS 0x1be /* device partition offset in Boot Sector */ #define DPT_ITEM_SIZE 16 /* partition item size */ @@ -173,28 +173,28 @@ int dfs_filesystem_get_partition(struct dfs_partition *part, return -EIO; /* get partition type */ - type = *(dpt+4); + type = *(dpt + 4); if (type == 0) return -EIO; /* set partition information * size is the number of 512-Byte */ part->type = type; - part->offset = *(dpt+8) | *(dpt+9)<<8 | *(dpt+10)<<16 | *(dpt+11)<<24; - part->size = *(dpt+12) | *(dpt+13)<<8 | *(dpt+14)<<16 | *(dpt+15)<<24; + part->offset = *(dpt + 8) | *(dpt + 9) << 8 | *(dpt + 10) << 16 | *(dpt + 11) << 24; + part->size = *(dpt + 12) | *(dpt + 13) << 8 | *(dpt + 14) << 16 | *(dpt + 15) << 24; rt_kprintf("found part[%d], begin: %d, size: ", - pindex, part->offset*512); - if ((part->size>>11) == 0) - rt_kprintf("%d%s",part->size>>1,"KB\n"); /* KB */ + pindex, part->offset * 512); + if ((part->size >> 11) == 0) + rt_kprintf("%d%s", part->size >> 1, "KB\n"); /* KB */ else { unsigned int part_size; part_size = part->size >> 11; /* MB */ - if ((part_size>>10) == 0) - rt_kprintf("%d.%d%s",part_size,(part->size>>1)&0x3FF,"MB\n"); + if ((part_size >> 10) == 0) + rt_kprintf("%d.%d%s", part_size, (part->size >> 1) & 0x3FF, "MB\n"); else - rt_kprintf("%d.%d%s",part_size>>10,part_size&0x3FF,"GB\n"); + rt_kprintf("%d.%d%s", part_size >> 10, part_size & 0x3FF, "GB\n"); } return RT_EOK; @@ -240,7 +240,7 @@ int dfs_mount(const char *device_name, dfs_lock(); for (ops = &filesystem_operation_table[0]; - ops < &filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX]; ops++) + ops < &filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX]; ops++) if ((*ops != NULL) && (strcmp((*ops)->name, filesystemtype) == 0)) break; @@ -503,13 +503,13 @@ int dfs_mount_table(void) if (mount_table[index].path == NULL) break; if (dfs_mount(mount_table[index].device_name, - mount_table[index].path, - mount_table[index].filesystemtype, - mount_table[index].rwflag, - mount_table[index].data) != 0) + mount_table[index].path, + mount_table[index].filesystemtype, + mount_table[index].rwflag, + mount_table[index].data) != 0) { rt_kprintf("mount fs[%s] on %s failed.\n", mount_table[index].filesystemtype, - mount_table[index].path); + mount_table[index].path); return -RT_ERROR; } @@ -555,7 +555,7 @@ int df(const char *path) } rt_kprintf("disk free: %d.%d %s [ %d block, %d bytes per block ]\n", - (unsigned long)cap, minor, unit_str[unit_index], buffer.f_bfree, buffer.f_bsize); + (unsigned long)cap, minor, unit_str[unit_index], buffer.f_bfree, buffer.f_bsize); return 0; } FINSH_FUNCTION_EXPORT(df, get disk free); diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index f47a60ee5d..6d643e2d4a 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -423,11 +423,11 @@ int fcntl(int fildes, int cmd, ...) d = fd_get(fildes); if (d) { - void* arg; + void *arg; va_list ap; va_start(ap, cmd); - arg = va_arg(ap, void*); + arg = va_arg(ap, void *); va_end(ap); ret = dfs_file_ioctl(d, cmd, arg); @@ -459,11 +459,11 @@ RTM_EXPORT(fcntl); */ int ioctl(int fildes, int cmd, ...) { - void* arg; + void *arg; va_list ap; va_start(ap, cmd); - arg = va_arg(ap, void*); + arg = va_arg(ap, void *); va_end(ap); /* we use fcntl for this API. */ @@ -645,8 +645,8 @@ struct dirent *readdir(DIR *d) if (d->num) { - struct dirent* dirent_ptr; - dirent_ptr = (struct dirent*)&d->buf[d->cur]; + struct dirent *dirent_ptr; + dirent_ptr = (struct dirent *)&d->buf[d->cur]; d->cur += dirent_ptr->d_reclen; } @@ -654,7 +654,7 @@ struct dirent *readdir(DIR *d) { /* get a new entry */ result = dfs_file_getdents(fd, - (struct dirent*)d->buf, + (struct dirent *)d->buf, sizeof(d->buf) - 1); if (result <= 0) { @@ -670,7 +670,7 @@ struct dirent *readdir(DIR *d) fd_put(fd); - return (struct dirent *)(d->buf+d->cur); + return (struct dirent *)(d->buf + d->cur); } RTM_EXPORT(readdir); diff --git a/components/dfs/src/poll.c b/components/dfs/src/poll.c index 6f83762082..aee157eed5 100644 --- a/components/dfs/src/poll.c +++ b/components/dfs/src/poll.c @@ -132,7 +132,7 @@ static int do_pollfd(struct pollfd *pollfd, rt_pollreq_t *req) mask = POLLMASK_DEFAULT; if (f->fops->poll) { - req->_key = pollfd->events | POLLERR| POLLHUP; + req->_key = pollfd->events | POLLERR | POLLHUP; mask = f->fops->poll(f, req); } diff --git a/components/dfs/src/select.c b/components/dfs/src/select.c index b9a444fe44..b20f7cf656 100644 --- a/components/dfs/src/select.c +++ b/components/dfs/src/select.c @@ -18,12 +18,12 @@ static void fdszero(fd_set *set, int nfds) { fd_mask *m; int n; - + /* The 'sizeof(fd_set)' of the system space may differ from user space, so the actual size of the 'fd_set' is determined here with the parameter 'nfds' */ - m = (fd_mask*)set; + m = (fd_mask *)set; for (n = 0; n < nfds; n += (sizeof(fd_mask) * 8)) { rt_memset(m, 0, sizeof(fd_mask)); -- cgit v1.3.1 From 25cdd8bba95499656594a1d3dfd42fd014df1f9f Mon Sep 17 00:00:00 2001 From: HubretXie Date: Tue, 9 Apr 2019 20:11:07 +0800 Subject: fix use printf format bug fix use printf format bug --- components/dfs/src/dfs_fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/dfs/src') diff --git a/components/dfs/src/dfs_fs.c b/components/dfs/src/dfs_fs.c index 774d008ce6..0f69ad2e3e 100644 --- a/components/dfs/src/dfs_fs.c +++ b/components/dfs/src/dfs_fs.c @@ -55,7 +55,7 @@ int dfs_register(const struct dfs_filesystem_ops *ops) if (empty == NULL) { rt_set_errno(-ENOSPC); - LOG_E("There is no space to register this file system (%d).", ops->name); + LOG_E("There is no space to register this file system (%s).", ops->name); ret = -1; } else if (ret == RT_EOK) -- cgit v1.3.1 From 6c92eb40da32c309122667481be68d735f72fede Mon Sep 17 00:00:00 2001 From: armink Date: Fri, 12 Apr 2019 10:39:05 +0800 Subject: [DFS] Update dfs file open log. --- components/dfs/src/dfs_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/dfs/src') diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 81cab2ed79..65fd0c45e8 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -99,7 +99,7 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags) rt_free(fd->path); fd->path = NULL; - LOG_E("open failed"); + LOG_D("%s open failed", fullpath); return result; } -- cgit v1.3.1 From 958d42f32c0ebf5ab6602979d49217245749fd47 Mon Sep 17 00:00:00 2001 From: misonyo Date: Tue, 23 Apr 2019 23:03:34 +0800 Subject: [components/dfs]fix index overflow bug when not filesystem was selected --- components/dfs/src/dfs_fs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'components/dfs/src') diff --git a/components/dfs/src/dfs_fs.c b/components/dfs/src/dfs_fs.c index 0f69ad2e3e..04d862e85d 100644 --- a/components/dfs/src/dfs_fs.c +++ b/components/dfs/src/dfs_fs.c @@ -444,7 +444,7 @@ int dfs_mkfs(const char *fs_name, const char *device_name) /* lock file system */ dfs_lock(); /* find the file system operations */ - for (index = 0; index <= DFS_FILESYSTEM_TYPES_MAX; index ++) + for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX; index ++) { if (filesystem_operation_table[index] != NULL && strcmp(filesystem_operation_table[index]->name, fs_name) == 0) @@ -452,7 +452,7 @@ int dfs_mkfs(const char *fs_name, const char *device_name) } dfs_unlock(); - if (index <= DFS_FILESYSTEM_TYPES_MAX) + if (index < DFS_FILESYSTEM_TYPES_MAX) { /* find file system operation */ const struct dfs_filesystem_ops *ops = filesystem_operation_table[index]; -- cgit v1.3.1 From d8eb0cfc1e119b81290a460883f427a38d572617 Mon Sep 17 00:00:00 2001 From: tyustli <1225613647@qq.com> Date: Tue, 18 Jun 2019 20:09:19 +0800 Subject: fix kernel and framework no cast type error --- components/dfs/filesystems/elmfat/dfs_elm.c | 12 ++++---- components/dfs/filesystems/elmfat/ff.c | 2 +- components/dfs/src/dfs.c | 6 ++-- components/dfs/src/dfs_file.c | 4 +-- components/dfs/src/dfs_posix.c | 4 +-- components/dfs/src/poll.c | 2 +- components/drivers/audio/audio.c | 6 ++-- components/drivers/audio/audio_pipe.c | 12 ++++---- components/drivers/i2c/i2c-bit-ops.c | 12 ++++---- components/drivers/i2c/i2c_dev.c | 4 +-- components/drivers/sensors/sensor.c | 4 +-- components/drivers/sensors/sensor_cmd.c | 10 +++--- components/drivers/serial/serial.c | 12 ++++---- components/drivers/src/pipe.c | 2 +- components/drivers/src/ringblk_buf.c | 46 ++++++++++++++-------------- components/drivers/src/ringbuffer.c | 4 +-- components/drivers/usb/usbdevice/core/core.c | 8 ++--- components/finsh/shell.c | 2 +- src/ipc.c | 10 +++--- src/kservice.c | 18 ++++++----- src/thread.c | 2 +- 21 files changed, 92 insertions(+), 90 deletions(-) (limited to 'components/dfs/src') diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index a45c15aa03..3825fd9108 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -202,7 +202,7 @@ int dfs_elm_mkfs(rt_device_t dev_id) int index; char logic_nbr[2] = {'0', ':'}; - work = rt_malloc(_MAX_SS); + work = (BYTE *)rt_malloc(_MAX_SS); if (RT_NULL == work) { return -ENOMEM; @@ -233,7 +233,7 @@ int dfs_elm_mkfs(rt_device_t dev_id) } else { - fat = rt_malloc(sizeof(FATFS)); + fat = (FATFS *)rt_malloc(sizeof(FATFS)); if (fat == RT_NULL) { rt_free(work); /* release memory */ @@ -340,7 +340,7 @@ int dfs_elm_open(struct dfs_fd *file) vol = elm_get_vol((FATFS *)fs->data); if (vol < 0) return -ENOENT; - drivers_fn = rt_malloc(256); + drivers_fn = (char *)rt_malloc(256); if (drivers_fn == RT_NULL) return -ENOMEM; @@ -648,7 +648,7 @@ int dfs_elm_unlink(struct dfs_filesystem *fs, const char *path) vol = elm_get_vol((FATFS *)fs->data); if (vol < 0) return -ENOENT; - drivers_fn = rt_malloc(256); + drivers_fn = (char *)rt_malloc(256); if (drivers_fn == RT_NULL) return -ENOMEM; @@ -680,7 +680,7 @@ int dfs_elm_rename(struct dfs_filesystem *fs, const char *oldpath, const char *n if (vol < 0) return -ENOENT; - drivers_oldfn = rt_malloc(256); + drivers_oldfn = (char *)rt_malloc(256); if (drivers_oldfn == RT_NULL) return -ENOMEM; drivers_newfn = newpath; @@ -714,7 +714,7 @@ int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) vol = elm_get_vol((FATFS *)fs->data); if (vol < 0) return -ENOENT; - drivers_fn = rt_malloc(256); + drivers_fn = (char *)rt_malloc(256); if (drivers_fn == RT_NULL) return -ENOMEM; diff --git a/components/dfs/filesystems/elmfat/ff.c b/components/dfs/filesystems/elmfat/ff.c index 4a2f0258b6..19df7450e2 100644 --- a/components/dfs/filesystems/elmfat/ff.c +++ b/components/dfs/filesystems/elmfat/ff.c @@ -569,7 +569,7 @@ static WCHAR LfnBuf[_MAX_LFN+1]; /* LFN enabled with static working buffer */ #define FREE_NAMBUF() ff_memfree(lfn) #else #define DEF_NAMBUF WCHAR *lfn; -#define INIT_NAMBUF(fs) { lfn = ff_memalloc((_MAX_LFN+1)*2); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; } +#define INIT_NAMBUF(fs) { lfn = (WCHAR *)ff_memalloc((_MAX_LFN+1)*2); if (!lfn) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); (fs)->lfnbuf = lfn; } #define FREE_NAMBUF() ff_memfree(lfn) #endif diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 5bddb96930..32cbbf643b 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -141,7 +141,7 @@ static int fd_alloc(struct dfs_fdtable *fdt, int startfd) cnt = fdt->maxfd + 4; cnt = cnt > DFS_FD_MAX ? DFS_FD_MAX : cnt; - fds = rt_realloc(fdt->fds, cnt * sizeof(struct dfs_fd *)); + fds = (struct dfs_fd **)rt_realloc(fdt->fds, cnt * sizeof(struct dfs_fd *)); if (fds == NULL) goto __exit; /* return fdt->maxfd */ /* clean the new allocated fds */ @@ -157,7 +157,7 @@ static int fd_alloc(struct dfs_fdtable *fdt, int startfd) /* allocate 'struct dfs_fd' */ if (idx < (int)fdt->maxfd && fdt->fds[idx] == RT_NULL) { - fdt->fds[idx] = rt_calloc(1, sizeof(struct dfs_fd)); + fdt->fds[idx] = (struct dfs_fd *)rt_calloc(1, sizeof(struct dfs_fd)); if (fdt->fds[idx] == RT_NULL) idx = fdt->maxfd; } @@ -393,7 +393,7 @@ char *dfs_normalize_path(const char *directory, const char *filename) if (filename[0] != '/') /* it's a absolute path, use it directly */ { - fullpath = rt_malloc(strlen(directory) + strlen(filename) + 2); + fullpath = (char *)rt_malloc(strlen(directory) + strlen(filename) + 2); if (fullpath == NULL) return NULL; diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 65fd0c45e8..5f090a7f6b 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -600,7 +600,7 @@ static void copyfile(const char *src, const char *dst) rt_uint8_t *block_ptr; rt_int32_t read_bytes; - block_ptr = rt_malloc(BUF_SZ); + block_ptr = (rt_uint8_t *)rt_malloc(BUF_SZ); if (block_ptr == NULL) { rt_kprintf("out of memory\n"); @@ -715,7 +715,7 @@ static void copydir(const char *src, const char *dst) static const char *_get_path_lastname(const char *path) { char *ptr; - if ((ptr = strrchr(path, '/')) == NULL) + if ((ptr = (char *)strrchr(path, '/')) == NULL) return path; /* skip the '/' then return */ diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index 6d643e2d4a..69fe56a84e 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -265,11 +265,11 @@ RTM_EXPORT(lseek); * * note: the old and new file name must be belong to a same file system. */ -int rename(const char *old, const char *new) +int rename(const char *old_file, const char *new_file) { int result; - result = dfs_file_rename(old, new); + result = dfs_file_rename(old_file, new_file); if (result < 0) { rt_set_errno(result); diff --git a/components/dfs/src/poll.c b/components/dfs/src/poll.c index aee157eed5..473b1579d2 100644 --- a/components/dfs/src/poll.c +++ b/components/dfs/src/poll.c @@ -54,7 +54,7 @@ static void _poll_add(rt_wqueue_t *wq, rt_pollreq_t *req) struct rt_poll_table *pt; struct rt_poll_node *node; - node = rt_malloc(sizeof(struct rt_poll_node)); + node = (struct rt_poll_node *)rt_malloc(sizeof(struct rt_poll_node)); if (node == RT_NULL) return; diff --git a/components/drivers/audio/audio.c b/components/drivers/audio/audio.c index 6a5ebc8741..6da0a3da91 100644 --- a/components/drivers/audio/audio.c +++ b/components/drivers/audio/audio.c @@ -157,7 +157,7 @@ static rt_err_t _audio_dev_open(struct rt_device *dev, rt_uint16_t oflag) //init pipe for record { - rt_uint8_t *buf = rt_malloc(CFG_AUDIO_RECORD_PIPE_SIZE); + rt_uint8_t *buf = (rt_uint8_t *)rt_malloc(CFG_AUDIO_RECORD_PIPE_SIZE); if (buf == RT_NULL) { @@ -382,7 +382,7 @@ static rt_err_t _audio_dev_control(struct rt_device *dev, int cmd, void *args) if (desc) { desc->data_size = AUDIO_DEVICE_DECODE_MP_BLOCK_SZ * 2; - desc->data_ptr = rt_mp_alloc(&audio->mp, RT_WAITING_FOREVER); + desc->data_ptr = (rt_uint8_t *)rt_mp_alloc(&audio->mp, RT_WAITING_FOREVER); result = RT_EOK; } @@ -440,7 +440,7 @@ rt_err_t rt_audio_register(struct rt_audio_device *audio, const char *name, rt_u //init memory pool for replay { - rt_uint8_t *mempool = rt_malloc(AUDIO_DEVICE_DECODE_MP_SZ); + rt_uint8_t *mempool = (rt_uint8_t *)rt_malloc(AUDIO_DEVICE_DECODE_MP_SZ); rt_mp_init(&audio->mp, "adu_mp", mempool, AUDIO_DEVICE_DECODE_MP_SZ, AUDIO_DEVICE_DECODE_MP_BLOCK_SZ * 2); } diff --git a/components/drivers/audio/audio_pipe.c b/components/drivers/audio/audio_pipe.c index 4df9fd8a49..d6975e962c 100644 --- a/components/drivers/audio/audio_pipe.c +++ b/components/drivers/audio/audio_pipe.c @@ -50,7 +50,7 @@ static rt_size_t rt_pipe_read(rt_device_t dev, if (!(pipe->flag & RT_PIPE_FLAG_BLOCK_RD)) { level = rt_hw_interrupt_disable(); - read_nbytes = rt_ringbuffer_get(&(pipe->ringbuffer), buffer, size); + read_nbytes = rt_ringbuffer_get(&(pipe->ringbuffer), (rt_uint8_t *)buffer, size); /* if the ringbuffer is empty, there won't be any writer waiting */ if (read_nbytes) @@ -68,7 +68,7 @@ static rt_size_t rt_pipe_read(rt_device_t dev, do { level = rt_hw_interrupt_disable(); - read_nbytes = rt_ringbuffer_get(&(pipe->ringbuffer), buffer, size); + read_nbytes = rt_ringbuffer_get(&(pipe->ringbuffer), (rt_uint8_t *)buffer, size); if (read_nbytes == 0) { rt_thread_suspend(thread); @@ -134,10 +134,10 @@ static rt_size_t rt_pipe_write(rt_device_t dev, if (pipe->flag & RT_PIPE_FLAG_FORCE_WR) write_nbytes = rt_ringbuffer_put_force(&(pipe->ringbuffer), - buffer, size); + (const rt_uint8_t *)buffer, size); else write_nbytes = rt_ringbuffer_put(&(pipe->ringbuffer), - buffer, size); + (const rt_uint8_t *)buffer, size); _rt_pipe_resume_reader(pipe); @@ -153,7 +153,7 @@ static rt_size_t rt_pipe_write(rt_device_t dev, do { level = rt_hw_interrupt_disable(); - write_nbytes = rt_ringbuffer_put(&(pipe->ringbuffer), buffer, size); + write_nbytes = rt_ringbuffer_put(&(pipe->ringbuffer), (const rt_uint8_t *)buffer, size); if (write_nbytes == 0) { /* pipe full, waiting on suspended write list */ @@ -270,7 +270,7 @@ rt_err_t rt_audio_pipe_create(const char *name, rt_int32_t flag, rt_size_t size) return -RT_ENOMEM; /* create ring buffer of pipe */ - rb_memptr = rt_malloc(size); + rb_memptr = (rt_uint8_t *)rt_malloc(size); if (rb_memptr == RT_NULL) { rt_free(pipe); diff --git a/components/drivers/i2c/i2c-bit-ops.c b/components/drivers/i2c/i2c-bit-ops.c index 26479a1d68..478cf99fd6 100644 --- a/components/drivers/i2c/i2c-bit-ops.c +++ b/components/drivers/i2c/i2c-bit-ops.c @@ -132,7 +132,7 @@ static rt_int32_t i2c_writeb(struct rt_i2c_bus_device *bus, rt_uint8_t data) rt_int32_t i; rt_uint8_t bit; - struct rt_i2c_bit_ops *ops = bus->priv; + struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; for (i = 7; i >= 0; i--) { @@ -159,7 +159,7 @@ static rt_int32_t i2c_readb(struct rt_i2c_bus_device *bus) { rt_uint8_t i; rt_uint8_t data = 0; - struct rt_i2c_bit_ops *ops = bus->priv; + struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; SDA_H(ops); i2c_delay(ops); @@ -222,7 +222,7 @@ static rt_size_t i2c_send_bytes(struct rt_i2c_bus_device *bus, static rt_err_t i2c_send_ack_or_nack(struct rt_i2c_bus_device *bus, int ack) { - struct rt_i2c_bit_ops *ops = bus->priv; + struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; if (ack) SET_SDA(ops, 0); @@ -282,7 +282,7 @@ static rt_int32_t i2c_send_address(struct rt_i2c_bus_device *bus, rt_uint8_t addr, rt_int32_t retries) { - struct rt_i2c_bit_ops *ops = bus->priv; + struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; rt_int32_t i; rt_err_t ret = 0; @@ -306,7 +306,7 @@ static rt_err_t i2c_bit_send_address(struct rt_i2c_bus_device *bus, { rt_uint16_t flags = msg->flags; rt_uint16_t ignore_nack = msg->flags & RT_I2C_IGNORE_NACK; - struct rt_i2c_bit_ops *ops = bus->priv; + struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; rt_uint8_t addr1, addr2; rt_int32_t retries; @@ -369,7 +369,7 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus, rt_uint32_t num) { struct rt_i2c_msg *msg; - struct rt_i2c_bit_ops *ops = bus->priv; + struct rt_i2c_bit_ops *ops = (struct rt_i2c_bit_ops *)bus->priv; rt_int32_t i, ret; rt_uint16_t ignore_nack; diff --git a/components/drivers/i2c/i2c_dev.c b/components/drivers/i2c/i2c_dev.c index 6c7df8e427..c784a4e4ee 100644 --- a/components/drivers/i2c/i2c_dev.c +++ b/components/drivers/i2c/i2c_dev.c @@ -28,7 +28,7 @@ static rt_size_t i2c_bus_device_read(rt_device_t dev, addr = pos & 0xffff; flags = (pos >> 16) & 0xffff; - return rt_i2c_master_recv(bus, addr, flags, buffer, count); + return rt_i2c_master_recv(bus, addr, flags, (rt_uint8_t *)buffer, count); } static rt_size_t i2c_bus_device_write(rt_device_t dev, @@ -48,7 +48,7 @@ static rt_size_t i2c_bus_device_write(rt_device_t dev, addr = pos & 0xffff; flags = (pos >> 16) & 0xffff; - return rt_i2c_master_send(bus, addr, flags, buffer, count); + return rt_i2c_master_send(bus, addr, flags, (const rt_uint8_t *)buffer, count); } static rt_err_t i2c_bus_device_control(rt_device_t dev, diff --git a/components/drivers/sensors/sensor.c b/components/drivers/sensors/sensor.c index d689988fdd..451d2745f1 100644 --- a/components/drivers/sensors/sensor.c +++ b/components/drivers/sensors/sensor.c @@ -69,7 +69,7 @@ void rt_sensor_cb(rt_sensor_t sen) /* ISR for sensor interrupt */ static void irq_callback(void *args) { - rt_sensor_t sensor = args; + rt_sensor_t sensor = (rt_sensor_t)args; rt_uint8_t i; if (sensor->module) @@ -389,7 +389,7 @@ int rt_hw_sensor_register(rt_sensor_t sensor, /* Add a type name for the sensor device */ sensor_name = sensor_name_str[sensor->info.type]; - device_name = rt_calloc(1, rt_strlen(sensor_name) + 1 + rt_strlen(name)); + device_name = (char *)rt_calloc(1, rt_strlen(sensor_name) + 1 + rt_strlen(name)); if (device_name == RT_NULL) { LOG_E("device_name calloc failed!"); diff --git a/components/drivers/sensors/sensor_cmd.c b/components/drivers/sensors/sensor_cmd.c index 245279020e..ea9e56a3d3 100755 --- a/components/drivers/sensors/sensor_cmd.c +++ b/components/drivers/sensors/sensor_cmd.c @@ -63,15 +63,15 @@ static rt_err_t rx_callback(rt_device_t dev, rt_size_t size) static void sensor_fifo_rx_entry(void *parameter) { - rt_device_t dev = parameter; - rt_sensor_t sensor = parameter; + rt_device_t dev = (rt_device_t)parameter; + rt_sensor_t sensor = (rt_sensor_t)parameter; struct rt_sensor_data *data = RT_NULL; struct rt_sensor_info info; rt_size_t res, i; rt_device_control(dev, RT_SENSOR_CTRL_GET_INFO, &info); - data = rt_malloc(sizeof(struct rt_sensor_data) * info.fifo_max); + data = (struct rt_sensor_data *)rt_malloc(sizeof(struct rt_sensor_data) * info.fifo_max); if (data == RT_NULL) { LOG_E("Memory allocation failed!"); @@ -137,8 +137,8 @@ MSH_CMD_EXPORT(sensor_fifo, Sensor fifo mode test function); static void sensor_irq_rx_entry(void *parameter) { - rt_device_t dev = parameter; - rt_sensor_t sensor = parameter; + rt_device_t dev = (rt_device_t)parameter; + rt_sensor_t sensor = (rt_sensor_t)parameter; struct rt_sensor_data data; rt_size_t res, i = 0; diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index c3e96fc77b..04034e8c44 100644 --- a/components/drivers/serial/serial.c +++ b/components/drivers/serial/serial.c @@ -791,16 +791,16 @@ static rt_size_t rt_serial_read(struct rt_device *dev, if (dev->open_flag & RT_DEVICE_FLAG_INT_RX) { - return _serial_int_rx(serial, buffer, size); + return _serial_int_rx(serial, (rt_uint8_t *)buffer, size); } #ifdef RT_SERIAL_USING_DMA else if (dev->open_flag & RT_DEVICE_FLAG_DMA_RX) { - return _serial_dma_rx(serial, buffer, size); + return _serial_dma_rx(serial, (rt_uint8_t *)buffer, size); } #endif /* RT_SERIAL_USING_DMA */ - return _serial_poll_rx(serial, buffer, size); + return _serial_poll_rx(serial, (rt_uint8_t *)buffer, size); } static rt_size_t rt_serial_write(struct rt_device *dev, @@ -817,17 +817,17 @@ static rt_size_t rt_serial_write(struct rt_device *dev, if (dev->open_flag & RT_DEVICE_FLAG_INT_TX) { - return _serial_int_tx(serial, buffer, size); + return _serial_int_tx(serial, (const rt_uint8_t *)buffer, size); } #ifdef RT_SERIAL_USING_DMA else if (dev->open_flag & RT_DEVICE_FLAG_DMA_TX) { - return _serial_dma_tx(serial, buffer, size); + return _serial_dma_tx(serial, (const rt_uint8_t *)buffer, size); } #endif /* RT_SERIAL_USING_DMA */ else { - return _serial_poll_tx(serial, buffer, size); + return _serial_poll_tx(serial, (const rt_uint8_t *)buffer, size); } } diff --git a/components/drivers/src/pipe.c b/components/drivers/src/pipe.c index 16fb82dbfb..b682c351ad 100644 --- a/components/drivers/src/pipe.c +++ b/components/drivers/src/pipe.c @@ -425,7 +425,7 @@ rt_pipe_t *rt_pipe_create(const char *name, int bufsz) rt_pipe_t *pipe; rt_device_t dev; - pipe = rt_malloc(sizeof(rt_pipe_t)); + pipe = (rt_pipe_t *)rt_malloc(sizeof(rt_pipe_t)); if (pipe == RT_NULL) return RT_NULL; rt_memset(pipe, 0, sizeof(rt_pipe_t)); diff --git a/components/drivers/src/ringblk_buf.c b/components/drivers/src/ringblk_buf.c index 74ced674fe..86e812cd4c 100644 --- a/components/drivers/src/ringblk_buf.c +++ b/components/drivers/src/ringblk_buf.c @@ -134,16 +134,16 @@ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size) { rt_base_t level; rt_size_t empty1 = 0, empty2 = 0; - rt_rbb_blk_t head, tail, new = NULL; + rt_rbb_blk_t head, tail, new_rbb = NULL; RT_ASSERT(rbb); RT_ASSERT(blk_size < (1L << 24)); level = rt_hw_interrupt_disable(); - new = find_empty_blk_in_set(rbb); + new_rbb = find_empty_blk_in_set(rbb); - if (rt_slist_len(&rbb->blk_list) < rbb->blk_max_num && new) + if (rt_slist_len(&rbb->blk_list) < rbb->blk_max_num && new_rbb) { if (rt_slist_len(&rbb->blk_list) > 0) { @@ -163,22 +163,22 @@ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size) if (empty1 >= blk_size) { - rt_slist_append(&rbb->blk_list, &new->list); - new->status = RT_RBB_BLK_INITED; - new->buf = tail->buf + tail->size; - new->size = blk_size; + rt_slist_append(&rbb->blk_list, &new_rbb->list); + new_rbb->status = RT_RBB_BLK_INITED; + new_rbb->buf = tail->buf + tail->size; + new_rbb->size = blk_size; } else if (empty2 >= blk_size) { - rt_slist_append(&rbb->blk_list, &new->list); - new->status = RT_RBB_BLK_INITED; - new->buf = rbb->buf; - new->size = blk_size; + rt_slist_append(&rbb->blk_list, &new_rbb->list); + new_rbb->status = RT_RBB_BLK_INITED; + new_rbb->buf = rbb->buf; + new_rbb->size = blk_size; } else { /* no space */ - new = NULL; + new_rbb = NULL; } } else @@ -194,35 +194,35 @@ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size) if (empty1 >= blk_size) { - rt_slist_append(&rbb->blk_list, &new->list); - new->status = RT_RBB_BLK_INITED; - new->buf = tail->buf + tail->size; - new->size = blk_size; + rt_slist_append(&rbb->blk_list, &new_rbb->list); + new_rbb->status = RT_RBB_BLK_INITED; + new_rbb->buf = tail->buf + tail->size; + new_rbb->size = blk_size; } else { /* no space */ - new = NULL; + new_rbb = NULL; } } } else { /* the list is empty */ - rt_slist_append(&rbb->blk_list, &new->list); - new->status = RT_RBB_BLK_INITED; - new->buf = rbb->buf; - new->size = blk_size; + rt_slist_append(&rbb->blk_list, &new_rbb->list); + new_rbb->status = RT_RBB_BLK_INITED; + new_rbb->buf = rbb->buf; + new_rbb->size = blk_size; } } else { - new = NULL; + new_rbb = NULL; } rt_hw_interrupt_enable(level); - return new; + return new_rbb; } RTM_EXPORT(rt_rbb_blk_alloc); diff --git a/components/drivers/src/ringbuffer.c b/components/drivers/src/ringbuffer.c index 0acdbbd38c..c6a491a7cc 100644 --- a/components/drivers/src/ringbuffer.c +++ b/components/drivers/src/ringbuffer.c @@ -332,11 +332,11 @@ struct rt_ringbuffer* rt_ringbuffer_create(rt_uint16_t size) size = RT_ALIGN_DOWN(size, RT_ALIGN_SIZE); - rb = rt_malloc(sizeof(struct rt_ringbuffer)); + rb = (struct rt_ringbuffer *)rt_malloc(sizeof(struct rt_ringbuffer)); if (rb == RT_NULL) goto exit; - pool = rt_malloc(size); + pool = (rt_uint8_t *)rt_malloc(size); if (pool == RT_NULL) { rt_free(rb); diff --git a/components/drivers/usb/usbdevice/core/core.c b/components/drivers/usb/usbdevice/core/core.c index 4e3a3e9280..ae0704585f 100644 --- a/components/drivers/usb/usbdevice/core/core.c +++ b/components/drivers/usb/usbdevice/core/core.c @@ -995,7 +995,7 @@ udevice_t rt_usbd_device_new(void) RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usbd_device_new\n")); /* allocate memory for the object */ - udevice = rt_malloc(sizeof(struct udevice)); + udevice = (udevice_t)rt_malloc(sizeof(struct udevice)); if(udevice == RT_NULL) { rt_kprintf("alloc memery failed\n"); @@ -1109,7 +1109,7 @@ uconfig_t rt_usbd_config_new(void) RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usbd_config_new\n")); /* allocate memory for the object */ - cfg = rt_malloc(sizeof(struct uconfig)); + cfg = (uconfig_t)rt_malloc(sizeof(struct uconfig)); if(cfg == RT_NULL) { rt_kprintf("alloc memery failed\n"); @@ -2053,7 +2053,7 @@ rt_size_t rt_usbd_ep0_write(udevice_t device, void *buffer, rt_size_t size) ep0 = &device->dcd->ep0; ep0->request.size = size; - ep0->request.buffer = buffer; + ep0->request.buffer = (rt_uint8_t *)buffer; ep0->request.remain_size = size; if(size >= ep0->id->maxpacket) { @@ -2079,7 +2079,7 @@ rt_size_t rt_usbd_ep0_read(udevice_t device, void *buffer, rt_size_t size, RT_ASSERT(buffer != RT_NULL); ep0 = &device->dcd->ep0; - ep0->request.buffer = buffer; + ep0->request.buffer = (rt_uint8_t *)buffer; ep0->request.remain_size = size; ep0->rx_indicate = rx_ind; if(size >= ep0->id->maxpacket) diff --git a/components/finsh/shell.c b/components/finsh/shell.c index 3a02e24c2e..1505e071c5 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -56,7 +56,7 @@ int finsh_set_prompt(const char * prompt) /* strdup */ if(prompt) { - finsh_prompt_custom = rt_malloc(strlen(prompt)+1); + finsh_prompt_custom = (char *)rt_malloc(strlen(prompt)+1); if(finsh_prompt_custom) { strcpy(finsh_prompt_custom, prompt); diff --git a/src/ipc.c b/src/ipc.c index 0df4f05f23..e293eee8cd 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1308,7 +1308,7 @@ rt_err_t rt_mb_init(rt_mailbox_t mb, rt_ipc_object_init(&(mb->parent)); /* init mailbox */ - mb->msg_pool = msgpool; + mb->msg_pool = (rt_ubase_t *)msgpool; mb->size = size; mb->entry = 0; mb->in_offset = 0; @@ -1376,7 +1376,7 @@ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag) /* init mailbox */ mb->size = size; - mb->msg_pool = RT_KERNEL_MALLOC(mb->size * sizeof(rt_ubase_t)); + mb->msg_pool = (rt_ubase_t *)RT_KERNEL_MALLOC(mb->size * sizeof(rt_ubase_t)); if (mb->msg_pool == RT_NULL) { /* delete mailbox object */ @@ -1816,7 +1816,7 @@ rt_err_t rt_mq_init(rt_mq_t mq, { head = (struct rt_mq_message *)((rt_uint8_t *)mq->msg_pool + temp * (mq->msg_size + sizeof(struct rt_mq_message))); - head->next = mq->msg_queue_free; + head->next = (struct rt_mq_message *)mq->msg_queue_free; mq->msg_queue_free = head; } @@ -1909,7 +1909,7 @@ rt_mq_t rt_mq_create(const char *name, { head = (struct rt_mq_message *)((rt_uint8_t *)mq->msg_pool + temp * (mq->msg_size + sizeof(struct rt_mq_message))); - head->next = mq->msg_queue_free; + head->next = (struct rt_mq_message *)mq->msg_queue_free; mq->msg_queue_free = head; } @@ -2093,7 +2093,7 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, void *buffer, rt_size_t size) temp = rt_hw_interrupt_disable(); /* link msg to the beginning of message queue */ - msg->next = mq->msg_queue_head; + msg->next = (struct rt_mq_message *)mq->msg_queue_head; mq->msg_queue_head = msg; /* if there is no tail */ diff --git a/src/kservice.c b/src/kservice.c index 322fb61e28..202bd97f83 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -326,7 +326,7 @@ rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_ubase_t count) const unsigned char *su1, *su2; int res = 0; - for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) + for (su1 = (const unsigned char *)cs, su2 = (const unsigned char *)ct; 0 < count; ++su1, ++su2, count--) if ((res = *su1 - *su2) != 0) break; @@ -1117,14 +1117,14 @@ RTM_EXPORT(rt_console_get_device); */ rt_device_t rt_console_set_device(const char *name) { - rt_device_t new, old; + rt_device_t new_device, old_device; /* save old device */ - old = _console_device; + old_device = _console_device; /* find new console device */ - new = rt_device_find(name); - if (new != RT_NULL) + new_device = rt_device_find(name); + if (new_device != RT_NULL) { if (_console_device != RT_NULL) { @@ -1133,11 +1133,11 @@ rt_device_t rt_console_set_device(const char *name) } /* set new console device */ - rt_device_open(new, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM); - _console_device = new; + rt_device_open(new_device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM); + _console_device = new_device; } - return old; + return old_device; } RTM_EXPORT(rt_console_set_device); #endif @@ -1332,7 +1332,9 @@ int __rt_ffs(int value) #ifdef RT_DEBUG /* RT_ASSERT(EX)'s hook */ + void (*rt_assert_hook)(const char *ex, const char *func, rt_size_t line); + /** * This function will set a hook function to RT_ASSERT(EX). It will run when the expression is false. * diff --git a/src/thread.c b/src/thread.c index 276bba9938..ab203b1d49 100644 --- a/src/thread.c +++ b/src/thread.c @@ -141,7 +141,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread, (void *)rt_thread_exit); #else thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter, - (void *)((char *)thread->stack_addr + thread->stack_size - sizeof(rt_ubase_t)), + (rt_uint8_t *)((char *)thread->stack_addr + thread->stack_size - sizeof(rt_ubase_t)), (void *)rt_thread_exit); #endif -- cgit v1.3.1 From 97c9abffd11183fa396b920baa10864ee4eaefb7 Mon Sep 17 00:00:00 2001 From: gbcwbz Date: Fri, 26 Jul 2019 19:07:05 +0800 Subject: [components][dfs] Fix fd error in command list_fd --- components/dfs/src/dfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/dfs/src') diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 32cbbf643b..b20de13988 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -537,7 +537,7 @@ int list_fd(void) if (fd && fd->fops) { - rt_kprintf("%2d ", index); + rt_kprintf("%2d ", index + DFS_FD_OFFSET); if (fd->type == FT_DIRECTORY) rt_kprintf("%-7.7s ", "dir"); else if (fd->type == FT_REGULAR) rt_kprintf("%-7.7s ", "file"); else if (fd->type == FT_SOCKET) rt_kprintf("%-7.7s ", "socket"); -- cgit v1.3.1 From 60f2ae4d3cee0cbf200a89df21a3949c92125cf4 Mon Sep 17 00:00:00 2001 From: zhangjun <2281979437@qq.com> Date: Thu, 26 Sep 2019 10:22:33 +0800 Subject: [components][dfs]添加ftruncate接口 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dfs/filesystems/elmfat/dfs_elm.c | 25 ++++++++++++++++ components/dfs/include/dfs_file.h | 4 +++ components/dfs/include/dfs_posix.h | 1 + components/dfs/src/dfs_file.c | 29 ++++++++++++++++++ components/dfs/src/dfs_posix.c | 46 +++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+) (limited to 'components/dfs/src') diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index 3825fd9108..b6d2c2388a 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -478,6 +478,31 @@ int dfs_elm_close(struct dfs_fd *file) int dfs_elm_ioctl(struct dfs_fd *file, int cmd, void *args) { + switch (cmd) + { + case RT_FIOFTRUNCATE: + { + FIL *fd; + FSIZE_t fptr, length; + FRESULT result = FR_OK; + fd = (FIL *)(file->data); + RT_ASSERT(fd != RT_NULL); + + /* save file read/write point */ + fptr = fd->fptr; + length = *(off_t*)args; + if (length <= fd->obj.objsize) + { + fd->fptr = length; + result = f_truncate(fd); + }else{ + result = f_lseek(fd, length); + } + /* restore file read/write point */ + fd->fptr = fptr; + return elm_result_to_dfs(result); + } + } return -ENOSYS; } diff --git a/components/dfs/include/dfs_file.h b/components/dfs/include/dfs_file.h index aaff3f6e9c..2dfacd653e 100644 --- a/components/dfs/include/dfs_file.h +++ b/components/dfs/include/dfs_file.h @@ -66,6 +66,10 @@ int dfs_file_lseek(struct dfs_fd *fd, off_t offset); int dfs_file_stat(const char *path, struct stat *buf); int dfs_file_rename(const char *oldpath, const char *newpath); +int dfs_file_ftruncate(struct dfs_fd *fd, off_t length); + +/* 0x5254 is just a magic number to make these relatively unique ("RT") */ +#define RT_FIOFTRUNCATE 0x52540000U #ifdef __cplusplus } diff --git a/components/dfs/include/dfs_posix.h b/components/dfs/include/dfs_posix.h index 9fd76debe2..87d5f0771e 100644 --- a/components/dfs/include/dfs_posix.h +++ b/components/dfs/include/dfs_posix.h @@ -58,6 +58,7 @@ int fstat(int fildes, struct stat *buf); int fsync(int fildes); int fcntl(int fildes, int cmd, ...); int ioctl(int fildes, int cmd, ...); +int ftruncate(int fd, off_t length); /* directory api*/ int rmdir(const char *path); diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 5f090a7f6b..1063a278ab 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -482,6 +482,35 @@ __exit: return result; } +/** + * this function is will cause the regular file referenced by fd + * to be truncated to a size of precisely length bytes. + * + * @param fd the file descriptor. + * @param length the length to be truncated. + * + * @return the status of truncated. + */ +int dfs_file_ftruncate(struct dfs_fd *fd, off_t length) +{ + int result; + + /* fd is null or not a regular file system fd, or length is invalid */ + if (fd == NULL || fd->type != FT_REGULAR || length < 0) + return -EINVAL; + + if (fd->fops->ioctl == NULL) + return -ENOSYS; + + result = fd->fops->ioctl(fd, RT_FIOFTRUNCATE, (void*)&length); + + /* update current size */ + if (result == 0) + fd->size = length; + + return result; +} + #ifdef RT_USING_FINSH #include diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index 69fe56a84e..fc603df437 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -471,6 +471,52 @@ int ioctl(int fildes, int cmd, ...) } RTM_EXPORT(ioctl); +/** + * + * this function is a POSIX compliant version, which cause the regular file + * referenced by fd to be truncated to a size of precisely length bytes. + * @param fd the file descriptor. + * @param length the length to be truncated. + * + * @return Upon successful completion, ftruncate() shall return 0; + * otherwise, -1 shall be returned and errno set to indicate the error. + */ +int ftruncate(int fd, off_t length) +{ + int result; + struct dfs_fd *d; + + d = fd_get(fd); + if (d == NULL) + { + rt_set_errno(-EBADF); + + return -1; + } + + if (length < 0) + { + fd_put(d); + rt_set_errno(-EINVAL); + + return -1; + } + result = dfs_file_ftruncate(d, length); + if (result < 0) + { + fd_put(d); + rt_set_errno(result); + + return -1; + } + + /* release the ref-count of fd */ + fd_put(d); + + return 0; +} +RTM_EXPORT(ftruncate); + /** * this function is a POSIX compliant version, which will return the * information about a mounted file system. -- cgit v1.3.1 From aafed7b43455d6e2d66d5e36e8f3d849b677e195 Mon Sep 17 00:00:00 2001 From: hichard Date: Sat, 16 Nov 2019 11:16:48 +0800 Subject: 1.修复sd卡热插拔内存泄露的bug 2.dfs增加函数,配合实现sd卡热插拔自动挂载卸载文件系统 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dfs/include/dfs_fs.h | 1 + components/dfs/src/dfs_fs.c | 39 ++++++++++++++++++++++++++++++++++++- components/dfs/src/poll.c | 3 +++ components/dfs/src/select.c | 3 +++ components/drivers/sdio/block_dev.c | 7 ++++--- 5 files changed, 49 insertions(+), 4 deletions(-) (limited to 'components/dfs/src') diff --git a/components/dfs/include/dfs_fs.h b/components/dfs/include/dfs_fs.h index d3a00fc542..58a9e5cf55 100644 --- a/components/dfs/include/dfs_fs.h +++ b/components/dfs/include/dfs_fs.h @@ -90,6 +90,7 @@ int dfs_unmount(const char *specialfile); int dfs_mkfs(const char *fs_name, const char *device_name); int dfs_statfs(const char *path, struct statfs *buffer); +int dfs_mount_device(rt_device_t dev); #ifdef __cplusplus } diff --git a/components/dfs/src/dfs_fs.c b/components/dfs/src/dfs_fs.c index 04d862e85d..164beed719 100644 --- a/components/dfs/src/dfs_fs.c +++ b/components/dfs/src/dfs_fs.c @@ -508,7 +508,7 @@ int dfs_mount_table(void) mount_table[index].rwflag, mount_table[index].data) != 0) { - rt_kprintf("mount fs[%s] on %s failed.\n", mount_table[index].filesystemtype, + LOG_E("mount fs[%s] on %s failed.\n", mount_table[index].filesystemtype, mount_table[index].path); return -RT_ERROR; } @@ -518,6 +518,43 @@ int dfs_mount_table(void) return 0; } INIT_ENV_EXPORT(dfs_mount_table); + +int dfs_mount_device(rt_device_t dev) +{ + int index = 0; + + if(dev == RT_NULL) { + rt_kprintf("the device is NULL to be mounted.\n"); + return -RT_ERROR; + } + + while (1) + { + if (mount_table[index].path == NULL) break; + + if(strcmp(mount_table[index].device_name, dev->parent.name) == 0) { + if (dfs_mount(mount_table[index].device_name, + mount_table[index].path, + mount_table[index].filesystemtype, + mount_table[index].rwflag, + mount_table[index].data) != 0) + { + LOG_E("mount fs[%s] device[%s] to %s failed.\n", mount_table[index].filesystemtype, dev->parent.name, + mount_table[index].path); + return -RT_ERROR; + } else { + LOG_D("mount fs[%s] device[%s] to %s ok.\n", mount_table[index].filesystemtype, dev->parent.name, + mount_table[index].path); + return RT_EOK; + } + } + + index ++; + } + + rt_kprintf("can't find device:%s to be mounted.\n", dev->parent.name); + return -RT_ERROR; +} #endif #ifdef RT_USING_FINSH diff --git a/components/dfs/src/poll.c b/components/dfs/src/poll.c index 473b1579d2..3f304549f7 100644 --- a/components/dfs/src/poll.c +++ b/components/dfs/src/poll.c @@ -19,6 +19,8 @@ #include #include +#ifdef RT_USING_POSIX + struct rt_poll_node; struct rt_poll_table @@ -214,3 +216,4 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout) return num; } +#endif diff --git a/components/dfs/src/select.c b/components/dfs/src/select.c index b20f7cf656..181855bc74 100644 --- a/components/dfs/src/select.c +++ b/components/dfs/src/select.c @@ -14,6 +14,8 @@ #include #include +#ifdef RT_USING_POSIX + static void fdszero(fd_set *set, int nfds) { fd_mask *m; @@ -178,3 +180,4 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struc return ret; } +#endif diff --git a/components/drivers/sdio/block_dev.c b/components/drivers/sdio/block_dev.c index cac4fc5036..5db0f38c08 100644 --- a/components/drivers/sdio/block_dev.c +++ b/components/drivers/sdio/block_dev.c @@ -472,7 +472,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card) } #ifdef RT_USING_DFS_MNTTABLE - if (0) // if (blk_dev) + if (blk_dev) { LOG_I("try to mount file system!"); /* try to mount file system on this block device */ @@ -507,9 +507,10 @@ void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card) const char * mounted_path = dfs_filesystem_get_mounted_path(&(blk_dev->dev)); if (mounted_path) { - dfs_unmount(mounted_path); + dfs_unmount(mounted_path); + LOG_D("unmount file system %s for device %s.\r\n", mounted_path, blk_dev->dev.parent.name); } - + rt_sem_delete(blk_dev->part.lock); rt_device_unregister(&blk_dev->dev); rt_list_remove(&blk_dev->list); rt_free(blk_dev); -- cgit v1.3.1 From 78d42efd223275b93776d7653a5405ecd29feb8f Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Wed, 18 Dec 2019 21:37:42 +0800 Subject: [DFS] cleanup the log in dfs. --- components/dfs/src/dfs_file.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'components/dfs/src') diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 1063a278ab..91d39597f0 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -369,8 +369,7 @@ int dfs_file_stat(const char *path, struct stat *buf) if ((fs = dfs_filesystem_lookup(fullpath)) == NULL) { - LOG_E( - "can't find mounted filesystem on this path:%s", fullpath); + LOG_E("can't find mounted filesystem on this path:%s", fullpath); rt_free(fullpath); return -ENOENT; @@ -399,8 +398,7 @@ int dfs_file_stat(const char *path, struct stat *buf) if (fs->ops->stat == NULL) { rt_free(fullpath); - LOG_E( - "the filesystem didn't implement this function"); + LOG_E("the filesystem didn't implement this function"); return -ENOSYS; } @@ -565,7 +563,7 @@ void ls(const char *pathname) } else { - rt_kprintf("%-25lu\n", stat.st_size); + rt_kprintf("%-25lu\n", (unsigned long)stat.st_size); } } else -- cgit v1.3.1 From 1c68bd9d3cef3e6a935e520de57cb0acfc2c0a5e Mon Sep 17 00:00:00 2001 From: Cliff Chen Date: Mon, 16 Mar 2020 10:22:37 +0800 Subject: Support msc mode automatic switching Signed-off-by: Cliff Chen --- components/dfs/include/dfs_fs.h | 1 + components/dfs/src/dfs_fs.c | 48 +++++++++++++++++++++++ components/drivers/usb/usbdevice/class/mstorage.c | 13 +++++- 3 files changed, 61 insertions(+), 1 deletion(-) (limited to 'components/dfs/src') diff --git a/components/dfs/include/dfs_fs.h b/components/dfs/include/dfs_fs.h index 58a9e5cf55..a35a513044 100644 --- a/components/dfs/include/dfs_fs.h +++ b/components/dfs/include/dfs_fs.h @@ -91,6 +91,7 @@ int dfs_unmount(const char *specialfile); int dfs_mkfs(const char *fs_name, const char *device_name); int dfs_statfs(const char *path, struct statfs *buffer); int dfs_mount_device(rt_device_t dev); +int dfs_unmount_device(rt_device_t dev); #ifdef __cplusplus } diff --git a/components/dfs/src/dfs_fs.c b/components/dfs/src/dfs_fs.c index 164beed719..476e47fc06 100644 --- a/components/dfs/src/dfs_fs.c +++ b/components/dfs/src/dfs_fs.c @@ -555,6 +555,54 @@ int dfs_mount_device(rt_device_t dev) rt_kprintf("can't find device:%s to be mounted.\n", dev->parent.name); return -RT_ERROR; } + +int dfs_unmount_device(rt_device_t dev) +{ + struct dfs_filesystem *iter; + struct dfs_filesystem *fs = NULL; + + /* lock filesystem */ + dfs_lock(); + + for (iter = &filesystem_table[0]; + iter < &filesystem_table[DFS_FILESYSTEMS_MAX]; iter++) + { + /* check if the PATH is mounted */ + if ((iter->dev_id->parent.name != NULL) + && (strcmp(iter->dev_id->parent.name, dev->parent.name) == 0)) + { + fs = iter; + break; + } + } + + if (fs == NULL || + fs->ops->unmount == NULL || + fs->ops->unmount(fs) < 0) + { + goto err1; + } + + /* close device, but do not check the status of device */ + if (fs->dev_id != NULL) + rt_device_close(fs->dev_id); + + if (fs->path != NULL) + rt_free(fs->path); + + /* clear this filesystem table entry */ + memset(fs, 0, sizeof(struct dfs_filesystem)); + + dfs_unlock(); + + return 0; + +err1: + dfs_unlock(); + + return -1; +} + #endif #ifdef RT_USING_FINSH diff --git a/components/drivers/usb/usbdevice/class/mstorage.c b/components/drivers/usb/usbdevice/class/mstorage.c index 6a6e92415b..43fb25afe4 100644 --- a/components/drivers/usb/usbdevice/class/mstorage.c +++ b/components/drivers/usb/usbdevice/class/mstorage.c @@ -16,6 +16,10 @@ #include "drivers/usb_device.h" #include "mstorage.h" +#ifdef RT_USING_DFS_MNTTABLE +#include "dfs_fs.h" +#endif + #ifdef RT_USB_DEVICE_MSTORAGE enum STAT @@ -955,7 +959,7 @@ static rt_err_t _function_enable(ufunction_t func) struct mstorage *data; RT_ASSERT(func != RT_NULL); RT_DEBUG_LOG(RT_DEBUG_USB, ("Mass storage function enabled\n")); - data = (struct mstorage*)func->user_data; + data = (struct mstorage*)func->user_data; data->disk = rt_device_find(RT_USB_MSTORAGE_DISK_NAME); if(data->disk == RT_NULL) @@ -964,6 +968,10 @@ static rt_err_t _function_enable(ufunction_t func) return -RT_ERROR; } +#ifdef RT_USING_DFS_MNTTABLE + dfs_unmount_device(data->disk); +#endif + if(rt_device_open(data->disk, RT_DEVICE_OFLAG_RDWR) != RT_EOK) { rt_kprintf("disk open error\n"); @@ -1029,6 +1037,9 @@ static rt_err_t _function_disable(ufunction_t func) if(data->disk != RT_NULL) { rt_device_close(data->disk); +#ifdef RT_USING_DFS_MNTTABLE + dfs_mount_device(data->disk); +#endif data->disk = RT_NULL; } -- cgit v1.3.1 From 63950c9259cb099c4182e29fef3d27b929d66258 Mon Sep 17 00:00:00 2001 From: longtengmcu Date: Sun, 17 May 2020 15:51:35 +0800 Subject: 1、解决do_pollfd函数中处理底层网络设备返回错误-1的情况,返回-1时select函数也要返回-1 2、网卡设备调用关闭dhcp时,底层要调用dhcp_stop函数来关闭dhcp功能,打开时再调用dhcp_start,否则再次打开dhcp时无法获取ip地址或者出现在使用静态ip地址会在dhcp租约到期时自动再获取ip地址。 3、sal_socket.c程序中的sal_accept函数增加判断网卡up,down的功能 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dfs/src/poll.c | 18 +++++++++++++++++- components/net/lwip-2.0.2/src/netif/ethernetif.c | 10 ++++++++++ components/net/sal_socket/src/sal_socket.c | 3 +++ 3 files changed, 30 insertions(+), 1 deletion(-) (limited to 'components/dfs/src') diff --git a/components/dfs/src/poll.c b/components/dfs/src/poll.c index 3f304549f7..3996fdf580 100644 --- a/components/dfs/src/poll.c +++ b/components/dfs/src/poll.c @@ -137,6 +137,14 @@ static int do_pollfd(struct pollfd *pollfd, rt_pollreq_t *req) req->_key = pollfd->events | POLLERR | POLLHUP; mask = f->fops->poll(f, req); + + /* dealwith the device return error -1 zhaoshimin 20200509*/ + if (mask < 0) + { + fd_put(f); + pollfd->revents = 0; + return mask; + } } /* Mask out unneeded events. */ mask &= pollfd->events | POLLERR | POLLHUP; @@ -154,6 +162,7 @@ static int poll_do(struct pollfd *fds, nfds_t nfds, struct rt_poll_table *pt, in int istimeout = 0; int n; struct pollfd *pf; + int ret = 0; if (msec == 0) { @@ -168,7 +177,14 @@ static int poll_do(struct pollfd *fds, nfds_t nfds, struct rt_poll_table *pt, in for (n = 0; n < nfds; n ++) { - if (do_pollfd(pf, &pt->req)) + ret = do_pollfd(pf, &pt->req); + if(ret < 0) + { + /*dealwith the device return error -1 zhaoshimin 20200509*/ + pt->req._proc = RT_NULL; + return ret; + } + else if(ret > 0) { num ++; pt->req._proc = RT_NULL; diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index 6c5621281c..8e90f0daf3 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -164,6 +164,16 @@ static int lwip_netdev_set_dns_server(struct netdev *netif, uint8_t dns_num, ip_ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) { netdev_low_level_set_dhcp_status(netif, is_enabled); + + /*zhaoshimin 20200508 add dhcp start or stop must call dhcp_start and dhcp_stop function*/ + if(is_enabled == RT_TRUE) + { + dhcp_start((struct netif *)netif->user_data); + } + else + { + dhcp_stop((struct netif *)netif->user_data); + } return ERR_OK; } #endif /* RT_LWIP_DHCP */ diff --git a/components/net/sal_socket/src/sal_socket.c b/components/net/sal_socket/src/sal_socket.c index e3bea5a28e..1e43896012 100644 --- a/components/net/sal_socket/src/sal_socket.c +++ b/components/net/sal_socket/src/sal_socket.c @@ -564,6 +564,9 @@ int sal_accept(int socket, struct sockaddr *addr, socklen_t *addrlen) /* get the socket object by socket descriptor */ SAL_SOCKET_OBJ_GET(sock, socket); + /* check the network interface is up status zhaoshimin add 20200509*/ + SAL_NETDEV_IS_UP(sock->netdev); + /* check the network interface socket operations */ SAL_NETDEV_SOCKETOPS_VALID(sock->netdev, pf, accept); -- cgit v1.3.1 From d75f03e4b03be4c72c5155cc0b00683da31ae74b Mon Sep 17 00:00:00 2001 From: longtengmcu Date: Thu, 21 May 2020 22:05:38 +0800 Subject: 1、解决do_pollfd函数中处理底层网络设备返回错误-1的情况,返回-1时select函数也要返回-1 … 2、网卡设备调用关闭dhcp时,底层要调用dhcp_stop函数来关闭dhcp功能,打开时再调用dhcp_start,否则再次打开dhcp时无法获取ip地址或者出现在使用静态ip地址会在dhcp租约到期时自动再获取ip地址。 3、sal_socket.c程序中的sal_accept函数增加判断网卡up,down的功能 4、修改注释信息 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dfs/src/poll.c | 4 ++-- components/net/lwip-2.0.2/src/netif/ethernetif.c | 18 +++++++++--------- components/net/sal_socket/src/sal_socket.c | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'components/dfs/src') diff --git a/components/dfs/src/poll.c b/components/dfs/src/poll.c index 3996fdf580..fc48eca758 100644 --- a/components/dfs/src/poll.c +++ b/components/dfs/src/poll.c @@ -138,7 +138,7 @@ static int do_pollfd(struct pollfd *pollfd, rt_pollreq_t *req) mask = f->fops->poll(f, req); - /* dealwith the device return error -1 zhaoshimin 20200509*/ + /* dealwith the device return error -1*/ if (mask < 0) { fd_put(f); @@ -180,7 +180,7 @@ static int poll_do(struct pollfd *fds, nfds_t nfds, struct rt_poll_table *pt, in ret = do_pollfd(pf, &pt->req); if(ret < 0) { - /*dealwith the device return error -1 zhaoshimin 20200509*/ + /*dealwith the device return error -1 */ pt->req._proc = RT_NULL; return ret; } diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index 8e90f0daf3..be16da7ad3 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -165,15 +165,15 @@ static int lwip_netdev_set_dhcp(struct netdev *netif, rt_bool_t is_enabled) { netdev_low_level_set_dhcp_status(netif, is_enabled); - /*zhaoshimin 20200508 add dhcp start or stop must call dhcp_start and dhcp_stop function*/ - if(is_enabled == RT_TRUE) - { - dhcp_start((struct netif *)netif->user_data); - } - else - { - dhcp_stop((struct netif *)netif->user_data); - } + /*add dhcp start or stop must call dhcp_start and dhcp_stop function*/ + if(is_enabled == RT_TRUE) + { + dhcp_start((struct netif *)netif->user_data); + } + else + { + dhcp_stop((struct netif *)netif->user_data); + } return ERR_OK; } #endif /* RT_LWIP_DHCP */ diff --git a/components/net/sal_socket/src/sal_socket.c b/components/net/sal_socket/src/sal_socket.c index 1e43896012..ec0519df02 100644 --- a/components/net/sal_socket/src/sal_socket.c +++ b/components/net/sal_socket/src/sal_socket.c @@ -564,7 +564,7 @@ int sal_accept(int socket, struct sockaddr *addr, socklen_t *addrlen) /* get the socket object by socket descriptor */ SAL_SOCKET_OBJ_GET(sock, socket); - /* check the network interface is up status zhaoshimin add 20200509*/ + /* check the network interface is up status */ SAL_NETDEV_IS_UP(sock->netdev); /* check the network interface socket operations */ -- cgit v1.3.1 From ad3e6d889854f646fcfb1abc618d5fa3e1140b4e Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Fri, 7 Aug 2020 08:51:22 +0800 Subject: [DFS] clean the unnecessary checking --- components/dfs/src/dfs_fs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'components/dfs/src') diff --git a/components/dfs/src/dfs_fs.c b/components/dfs/src/dfs_fs.c index 476e47fc06..c21b914727 100644 --- a/components/dfs/src/dfs_fs.c +++ b/components/dfs/src/dfs_fs.c @@ -129,7 +129,7 @@ const char *dfs_filesystem_get_mounted_path(struct rt_device *device) for (iter = &filesystem_table[0]; iter < &filesystem_table[DFS_FILESYSTEMS_MAX]; iter++) { - /* fint the mounted device */ + /* find the mounted device */ if (iter->ops == NULL) continue; else if (iter->dev_id == device) { @@ -321,7 +321,7 @@ int dfs_mount(const char *device_name, if (rt_device_open(fs->dev_id, RT_DEVICE_OFLAG_RDWR) != RT_EOK) { - /* The underlaying device has error, clear the entry. */ + /* The underlying device has error, clear the entry. */ dfs_lock(); memset(fs, 0, sizeof(struct dfs_filesystem)); @@ -568,8 +568,7 @@ int dfs_unmount_device(rt_device_t dev) iter < &filesystem_table[DFS_FILESYSTEMS_MAX]; iter++) { /* check if the PATH is mounted */ - if ((iter->dev_id->parent.name != NULL) - && (strcmp(iter->dev_id->parent.name, dev->parent.name) == 0)) + if (strcmp(iter->dev_id->parent.name, dev->parent.name) == 0) { fs = iter; break; -- cgit v1.3.1 From 50dc41468ef69b6b79979772f9689d8d3099df30 Mon Sep 17 00:00:00 2001 From: tangyuxin <462747508@qq.com> Date: Sat, 26 Sep 2020 09:55:58 +0800 Subject: [add] DFS file system supports device types --- components/dfs/filesystems/devfs/devfs.c | 2 ++ components/dfs/include/dfs.h | 1 + components/dfs/src/dfs.c | 1 + 3 files changed, 4 insertions(+) (limited to 'components/dfs/src') diff --git a/components/dfs/filesystems/devfs/devfs.c b/components/dfs/filesystems/devfs/devfs.c index 936b074ce1..7637074dbb 100644 --- a/components/dfs/filesystems/devfs/devfs.c +++ b/components/dfs/filesystems/devfs/devfs.c @@ -186,6 +186,7 @@ int dfs_device_fs_open(struct dfs_fd *file) result = file->fops->open(file); if (result == RT_EOK || result == -RT_ENOSYS) { + file->type = FT_DEVICE; return 0; } } @@ -197,6 +198,7 @@ int dfs_device_fs_open(struct dfs_fd *file) if (result == RT_EOK || result == -RT_ENOSYS) { file->data = device; + file->type = FT_DEVICE; return RT_EOK; } } diff --git a/components/dfs/include/dfs.h b/components/dfs/include/dfs.h index eb32a4b411..1158df93cb 100644 --- a/components/dfs/include/dfs.h +++ b/components/dfs/include/dfs.h @@ -55,6 +55,7 @@ #define FT_SOCKET 1 /* socket file */ #define FT_DIRECTORY 2 /* directory */ #define FT_USER 3 /* user defined */ +#define FT_DEVICE 4 /* device */ /* File flags */ #define DFS_F_OPEN 0x01000000 diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index b20de13988..7ace0bc160 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -542,6 +542,7 @@ int list_fd(void) else if (fd->type == FT_REGULAR) rt_kprintf("%-7.7s ", "file"); else if (fd->type == FT_SOCKET) rt_kprintf("%-7.7s ", "socket"); else if (fd->type == FT_USER) rt_kprintf("%-7.7s ", "user"); + else if (fd->type == FT_DEVICE) rt_kprintf("%-7.7s ", "device"); else rt_kprintf("%-8.8s ", "unknown"); rt_kprintf("%3d ", fd->ref_count); rt_kprintf("%04x ", fd->magic); -- cgit v1.3.1 From 8861202c3b0a74d5e4d73176c38518a5418b2019 Mon Sep 17 00:00:00 2001 From: tangyuxin <462747508@qq.com> Date: Sat, 26 Sep 2020 12:30:39 +0800 Subject: [dfs] fix the DEVICE could not get or set flags --- components/dfs/src/dfs_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components/dfs/src') diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 91d39597f0..fd205f2f3a 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -157,7 +157,7 @@ int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args) return -EINVAL; /* regular file system fd */ - if (fd->type == FT_REGULAR) + if (fd->type == FT_REGULAR || fd->type == FT_DEVICE) { switch (cmd) { -- cgit v1.3.1