提交 69521e2c 编写于 作者: D dzzxzz@gmail.com

fixed the coding style in components/dfs

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2530 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 ef5c47e6
/*
* File : dfs.h
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......
/*
* File : dfs_def.h
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......
/*
* File : dfs_elm.h
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2008-2011, RT-Thread Development Team
* COPYRIGHT (C) 2008-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......
/*
* File : dfs_file.c
* File : dfs_file.h
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......@@ -12,8 +12,8 @@
* 2005-01-26 Bernard The first version.
*/
#ifndef __DFS_RAW_H__
#define __DFS_RAW_H__
#ifndef __DFS_FILE_H__
#define __DFS_FILE_H__
#include <dfs_def.h>
#include <dfs.h>
......
/*
* File : dfs_fs.h
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......@@ -74,11 +74,15 @@ struct dfs_partition
int dfs_register(const struct dfs_filesystem_operation *ops);
struct dfs_filesystem *dfs_filesystem_lookup(const char *path);
rt_err_t dfs_filesystem_get_partition(struct dfs_partition *part, rt_uint8_t *buf, rt_uint32_t pindex);
int dfs_mount(const char *device_name, const char *path,
const char *filesystemtype, rt_uint32_t rwflag, const
void *data);
rt_err_t dfs_filesystem_get_partition(struct dfs_partition *part,
rt_uint8_t *buf,
rt_uint32_t pindex);
int dfs_mount(const char *device_name,
const char *path,
const char *filesystemtype,
rt_uint32_t rwflag,
const void *data);
int dfs_unmount(const char *specialfile);
/* extern variable */
......
/*
* File : dfs_init.h
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......
/*
* File : dfs_def.h
* File : dfs_posix.h
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......
......@@ -264,7 +264,8 @@ const char *dfs_subdir(const char *directory, const char *filename)
}
/**
* this function will normalize a path according to specified parent directory and file name.
* this function will normalize a path according to specified parent directory
* and file name.
*
* @param directory the parent path
* @param filename the file name
......
......@@ -19,6 +19,7 @@
/**
* @addtogroup FileApi
*/
/*@{*/
/**
......@@ -54,6 +55,7 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
if (fs == RT_NULL)
{
rt_free(fullpath); /* release path */
return -DFS_STATUS_ENOENT;
}
......@@ -160,7 +162,8 @@ int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args)
}
/**
* this function will read specified length data from a file descriptor to a buffer.
* this function will read specified length data from a file descriptor to a
* buffer.
*
* @param fd the file descriptor.
* @param buf the buffer to save the read data.
......@@ -358,8 +361,10 @@ int dfs_file_stat(const char *path, struct stat *buf)
if ((fs = dfs_filesystem_lookup(fullpath)) == RT_NULL)
{
dfs_log(DFS_DEBUG_ERROR, ("can't find mounted filesystem on this path:%s", fullpath));
dfs_log(DFS_DEBUG_ERROR,
("can't find mounted filesystem on this path:%s", fullpath));
rt_free(fullpath);
return -DFS_STATUS_ENOENT;
}
......@@ -387,7 +392,9 @@ int dfs_file_stat(const char *path, struct stat *buf)
if (fs->ops->stat == RT_NULL)
{
rt_free(fullpath);
dfs_log(DFS_DEBUG_ERROR, ("the filesystem didn't implement this function"));
dfs_log(DFS_DEBUG_ERROR,
("the filesystem didn't implement this function"));
return -DFS_STATUS_ENOSYS;
}
......@@ -396,7 +403,6 @@ int dfs_file_stat(const char *path, struct stat *buf)
result = fs->ops->stat(fs, fullpath, buf);
else
result = fs->ops->stat(fs, dfs_subdir(fs->path, fullpath), buf);
}
rt_free(fullpath);
......@@ -451,7 +457,8 @@ int dfs_file_rename(const char *oldpath, const char *newpath)
result = oldfs->ops->rename(oldfs, oldfullpath, newfullpath);
else
/* use sub directory to rename in file system */
result = oldfs->ops->rename(oldfs, dfs_subdir(oldfs->path, oldfullpath),
result = oldfs->ops->rename(oldfs,
dfs_subdir(oldfs->path, oldfullpath),
dfs_subdir(newfs->path, newfullpath));
}
}
......@@ -488,7 +495,8 @@ void ls(const char *pathname)
#else
path = rt_strdup("/");
#endif
if (path == RT_NULL) return ; /* out of memory */
if (path == RT_NULL)
return ; /* out of memory */
}
else
{
......@@ -558,6 +566,7 @@ void cat(const char* filename)
if (dfs_file_open(&fd, filename, DFS_O_RDONLY) < 0)
{
rt_kprintf("Open %s failed\n", filename);
return;
}
......@@ -586,6 +595,7 @@ void copy(const char *src, const char *dst)
if (block_ptr == RT_NULL)
{
rt_kprintf("out of memory\n");
return;
}
......@@ -593,6 +603,7 @@ void copy(const char *src, const char *dst)
{
rt_free(block_ptr);
rt_kprintf("Read %s failed\n", src);
return;
}
if (dfs_file_open(&fd, dst, DFS_O_WRONLY | DFS_O_CREAT) < 0)
......@@ -601,6 +612,7 @@ void copy(const char *src, const char *dst)
dfs_file_close(&src_fd);
rt_kprintf("Write %s failed\n", dst);
return;
}
......
......@@ -50,8 +50,10 @@ int dfs_register(const struct dfs_filesystem_operation *ops)
}
/* find out an empty filesystem type entry */
for (index = 0; index < DFS_FILESYSTEM_TYPES_MAX && filesystem_operation_table[index] != RT_NULL;
index++) ;
for (index = 0;
index < DFS_FILESYSTEM_TYPES_MAX && filesystem_operation_table[index] != RT_NULL;
index ++)
;
/* filesystem type table full */
if (index == DFS_FILESYSTEM_TYPES_MAX)
......@@ -125,7 +127,9 @@ struct dfs_filesystem *dfs_filesystem_lookup(const char *path)
*
* @return RT_EOK on successful or -RT_ERROR on failed.
*/
rt_err_t dfs_filesystem_get_partition(struct dfs_partition *part, rt_uint8_t *buf, rt_uint32_t pindex)
rt_err_t dfs_filesystem_get_partition(struct dfs_partition *part,
rt_uint8_t *buf,
rt_uint32_t pindex)
{
#define DPT_ADDRESS 0x1be /* device partition offset in Boot Sector */
#define DPT_ITEM_SIZE 16 /* partition item size */
......@@ -145,6 +149,7 @@ rt_err_t dfs_filesystem_get_partition(struct dfs_partition *part, rt_uint8_t *bu
{
/* which is not a partition table */
result = -RT_ERROR;
return result;
}
......@@ -160,23 +165,27 @@ rt_err_t dfs_filesystem_get_partition(struct dfs_partition *part, rt_uint8_t *bu
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);
rt_kprintf("found part[%d], begin: %d, size: ",
pindex, part->offset*512);
if ((part->size>>11) > 0) /* MB */
{
unsigned int part_size;
part_size = part->size >> 11;/* MB */
if ((part_size>>10) > 0) /* GB */
{
rt_kprintf("%d.%d%s",part_size>>10,part_size&0x3FF,"GB\r\n");/* GB */
/* GB */
rt_kprintf("%d.%d%s",part_size>>10,part_size&0x3FF,"GB\r\n");
}
else
{
rt_kprintf("%d.%d%s",part_size,(part->size>>1)&0x3FF,"MB\r\n");/* MB */
/* MB */
rt_kprintf("%d.%d%s",part_size,(part->size>>1)&0x3FF,"MB\r\n");
}
}
else
{
rt_kprintf("%d%s",part->size>>1,"KB\r\n");/* KB */
/* KB */
rt_kprintf("%d%s",part->size>>1,"KB\r\n");
}
}
else
......@@ -198,9 +207,11 @@ rt_err_t dfs_filesystem_get_partition(struct dfs_partition *part, rt_uint8_t *bu
*
* @return 0 on successful or -1 on failed.
*/
int dfs_mount(const char *device_name, const char *path,
const char *filesystemtype, unsigned long rwflag, const
void *data)
int dfs_mount(const char *device_name,
const char *path,
const char *filesystemtype,
unsigned long rwflag,
const void *data)
{
const struct dfs_filesystem_operation *ops;
struct dfs_filesystem *fs;
......@@ -216,6 +227,7 @@ int dfs_mount(const char *device_name, const char *path,
{
/* no this device */
rt_set_errno(-DFS_STATUS_ENODEV);
return -1;
}
}
......@@ -238,6 +250,7 @@ int dfs_mount(const char *device_name, const char *path,
{
rt_set_errno(-DFS_STATUS_ENODEV);
dfs_unlock();
return -1;
}
ops = filesystem_operation_table[index];
......@@ -248,6 +261,7 @@ int dfs_mount(const char *device_name, const char *path,
if (fullpath == RT_NULL) /* not an abstract path */
{
rt_set_errno(-DFS_STATUS_ENOTDIR);
return -1;
}
......@@ -260,6 +274,7 @@ int dfs_mount(const char *device_name, const char *path,
{
rt_free(fullpath);
rt_set_errno(-DFS_STATUS_ENOTDIR);
return -1;
}
dfs_file_close(&fd);
......@@ -267,7 +282,7 @@ int dfs_mount(const char *device_name, const char *path,
/* check whether the file system mounted or not */
dfs_lock();
for (index =0; index < DFS_FILESYSTEMS_MAX; index++)
for (index = 0; index < DFS_FILESYSTEMS_MAX; index ++)
{
if (filesystem_table[index].ops != RT_NULL &&
strcmp(filesystem_table[index].path, path) == 0)
......@@ -278,9 +293,13 @@ int dfs_mount(const char *device_name, const char *path,
}
/* find out an empty filesystem table entry */
for (index = 0; index < DFS_FILESYSTEMS_MAX && filesystem_table[index].ops != RT_NULL;
index++) ;
if (index == DFS_FILESYSTEMS_MAX) /* can't find en empty filesystem table entry */
for (index = 0;
index < DFS_FILESYSTEMS_MAX && filesystem_table[index].ops != RT_NULL;
index ++)
;
/* can't find en empty filesystem table entry */
if (index == DFS_FILESYSTEMS_MAX)
{
rt_set_errno(-DFS_STATUS_ENOSPC);
goto err1;
......@@ -298,7 +317,8 @@ int dfs_mount(const char *device_name, const char *path,
if (dev_id != RT_NULL)
rt_device_open(fs->dev_id, RT_DEVICE_OFLAG_RDWR);
if (ops->mount == RT_NULL) /* there is no mount implementation */
/* there is no mount implementation */
if (ops->mount == RT_NULL)
{
if (dev_id != RT_NULL)
rt_device_close(dev_id);
......@@ -309,6 +329,7 @@ int dfs_mount(const char *device_name, const char *path,
rt_free(fullpath);
rt_set_errno(-DFS_STATUS_ENOSYS);
return -1;
}
/* call mount of this filesystem */
......@@ -325,6 +346,7 @@ int dfs_mount(const char *device_name, const char *path,
dfs_unlock();
rt_free(fullpath);
return -1;
}
......@@ -354,6 +376,7 @@ int dfs_unmount(const char *specialfile)
if (fullpath == RT_NULL)
{
rt_set_errno(-DFS_STATUS_ENOTDIR);
return -1;
}
......@@ -361,7 +384,9 @@ int dfs_unmount(const char *specialfile)
dfs_lock();
fs = dfs_filesystem_lookup(fullpath);
if (fs == RT_NULL || fs->ops->unmount == RT_NULL || fs->ops->unmount(fs) < 0)
if (fs == RT_NULL ||
fs->ops->unmount == RT_NULL ||
fs->ops->unmount(fs) < 0)
{
goto err1;
}
......@@ -403,13 +428,13 @@ 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] != RT_NULL &&
strcmp(filesystem_operation_table[index]->name, fs_name) == 0)
{
/* find file system operation */
const struct dfs_filesystem_operation* ops = filesystem_operation_table[index];
const struct dfs_filesystem_operation *ops = filesystem_operation_table[index];
dfs_unlock();
if (ops->mkfs != RT_NULL)
......@@ -466,7 +491,8 @@ void df(const char *path)
if (result == 0)
{
rt_kprintf("disk free: %d block[%d bytes per block]\n", buffer.f_bfree, buffer.f_bsize);
rt_kprintf("disk free: %d block[%d bytes per block]\n",
buffer.f_bfree, buffer.f_bsize);
}
}
FINSH_FUNCTION_EXPORT(df, get disk free);
......
......@@ -18,11 +18,12 @@
/**
* @addtogroup FsPosixApi
*/
/*@{*/
/**
* this function is a POSIX compliant version, which will open a file and return
* a file descriptor.
* this function is a POSIX compliant version, which will open a file and
* return a file descriptor.
*
* @param file the path name of file.
* @param flags the file open flags.
......@@ -40,6 +41,7 @@ int open(const char *file, int flags, int mode)
if (fd < 0)
{
rt_set_errno(-DFS_STATUS_ENOMEM);
return -1;
}
d = fd_get(fd);
......@@ -80,6 +82,7 @@ int close(int fd)
if (d == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
......@@ -100,8 +103,8 @@ int close(int fd)
RTM_EXPORT(close);
/**
* this function is a POSIX compliant version, which will read specified data buffer
* length for an open file descriptor.
* this function is a POSIX compliant version, which will read specified data
* buffer length for an open file descriptor.
*
* @param fd the file descriptor.
* @param buf the buffer to save the read data.
......@@ -119,6 +122,7 @@ int read(int fd, void *buf, size_t len)
if (d == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
......@@ -139,8 +143,8 @@ int read(int fd, void *buf, size_t len)
RTM_EXPORT(read);
/**
* this function is a POSIX compliant version, which will write specified data buffer
* length for an open file descriptor.
* this function is a POSIX compliant version, which will write specified data
* buffer length for an open file descriptor.
*
* @param fd the file descriptor
* @param buf the data buffer to be written.
......@@ -179,8 +183,8 @@ int write(int fd, const void *buf, size_t len)
RTM_EXPORT(write);
/**
* this function is a POSIX compliant version, which will seek the offset for an
* open file descriptor.
* this function is a POSIX compliant version, which will seek the offset for
* an open file descriptor.
*
* @param fd the file descriptor.
* @param offset the offset to be seeked.
......@@ -197,6 +201,7 @@ off_t lseek(int fd, off_t offset, int whence)
if (d == RT_NULL)
{
rt_set_errno(-DFS_STATUS_EBADF);
return -1;
}
......@@ -215,6 +220,7 @@ off_t lseek(int fd, off_t offset, int whence)
default:
rt_set_errno(-DFS_STATUS_EINVAL);
return -1;
}
......@@ -241,8 +247,8 @@ off_t lseek(int fd, off_t offset, int whence)
RTM_EXPORT(lseek);
/**
* this function is a POSIX compliant version, which will rename old file name to
* new file name.
* this function is a POSIX compliant version, which will rename old file name
* to new file name.
*
* @param old the old file name.
* @param new the new file name.
......@@ -525,10 +531,13 @@ struct dirent *readdir(DIR *d)
return RT_NULL;
}
if (!d->num || (d->cur += ((struct dirent*)(d->buf + d->cur))->d_reclen) >= d->num)
if (!d->num ||
(d->cur += ((struct dirent *)(d->buf + d->cur))->d_reclen) >= d->num)
{
/* get a new entry */
result = dfs_file_getdents(fd, (struct dirent*)d->buf, sizeof(d->buf) - 1);
result = dfs_file_getdents(fd,
(struct dirent*)d->buf,
sizeof(d->buf) - 1);
if (result <= 0)
{
fd_put(fd);
......@@ -602,7 +611,8 @@ void seekdir(DIR *d, off_t offset)
RTM_EXPORT(seekdir);
/**
* this function is a POSIX compliant version, which will reset directory stream.
* this function is a POSIX compliant version, which will reset directory
* stream.
*
* @param d the directory stream.
*/
......@@ -665,7 +675,8 @@ RTM_EXPORT(closedir);
#ifdef DFS_USING_WORKDIR
/**
* this function is a POSIX compliant version, which will change working directory.
* this function is a POSIX compliant version, which will change working
* directory.
*
* @param path the path name to be changed to.
*
......@@ -716,7 +727,8 @@ int chdir(const char *path)
/* copy full path to working directory */
strncpy(working_directory, fullpath, DFS_PATH_MAX);
rt_free(fullpath); /* release normalize directory path name */
/* release normalize directory path name */
rt_free(fullpath);
dfs_unlock();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册