mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-21 02:06:14 +08:00
[components][dfs]格式化代码
This commit is contained in:
@@ -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 ++)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
+21
-21
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user