From 44a2d720a02775987dca11dc6aab74e55c355a59 Mon Sep 17 00:00:00 2001 From: dzzxzz Date: Fri, 23 Dec 2011 02:11:55 +0000 Subject: unify the components/dfs coding style according to the /documentation/coding_style_cn.txt git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1866 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- components/dfs/filesystems/elmfat/dfs_elm.c | 172 ++++++----- components/dfs/filesystems/nfs/dfs_nfs.c | 415 ++++++++++++++------------- components/dfs/filesystems/nfs/dfs_nfs.h | 13 + components/dfs/filesystems/romfs/dfs_romfs.c | 93 +++--- components/dfs/filesystems/romfs/dfs_romfs.h | 13 + 5 files changed, 401 insertions(+), 305 deletions(-) (limited to 'components/dfs/filesystems') diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index f85411f108..d52874255c 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -73,7 +73,7 @@ static int elm_result_to_dfs(FRESULT result) return status; } -int dfs_elm_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* data) +int dfs_elm_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data) { FATFS *fat; FRESULT result; @@ -87,12 +87,13 @@ int dfs_elm_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* d break; } } - if (index == _VOLUMES) return -DFS_STATUS_ENOSPC; + if (index == _VOLUMES) + return -DFS_STATUS_ENOSPC; /* get device */ disk[index] = fs->dev_id; - fat = (FATFS *) rt_malloc(sizeof(FATFS)); + fat = (FATFS *)rt_malloc(sizeof(FATFS)); if (fat == RT_NULL) { return -1; @@ -111,13 +112,13 @@ int dfs_elm_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* d return 0; } -int dfs_elm_unmount(struct dfs_filesystem* fs) +int dfs_elm_unmount(struct dfs_filesystem *fs) { FATFS *fat; FRESULT result; rt_uint32_t index; - fat = (FATFS*) fs->data; + fat = (FATFS *)fs->data; RT_ASSERT(fat != RT_NULL); @@ -141,7 +142,7 @@ int dfs_elm_unmount(struct dfs_filesystem* fs) return -DFS_STATUS_ENOENT; } -int dfs_elm_mkfs(const char* device_name) +int dfs_elm_mkfs(const char *device_name) { BYTE drv; rt_device_t dev; @@ -156,7 +157,7 @@ int dfs_elm_mkfs(const char* device_name) /* 1: no partition table */ /* 0: auto selection of cluster size */ result = f_mkfs(drv, 1, 0); - if ( result != FR_OK) + if (result != FR_OK) { rt_kprintf("format error\n"); return elm_result_to_dfs(result); @@ -171,7 +172,7 @@ int dfs_elm_mkfs(const char* device_name) return -DFS_STATUS_EIO; } -int dfs_elm_statfs(struct dfs_filesystem* fs, struct statfs *buf) +int dfs_elm_statfs(struct dfs_filesystem *fs, struct statfs *buf) { FATFS *f; FRESULT res; @@ -181,11 +182,12 @@ int dfs_elm_statfs(struct dfs_filesystem* fs, struct statfs *buf) RT_ASSERT(fs != RT_NULL); RT_ASSERT(buf != RT_NULL); - f = (FATFS*) fs->data; + f = (FATFS *)fs->data; rt_snprintf(driver, sizeof(driver), "%d:", f->drv); res = f_getfree(driver, &fre_clust, &f); - if (res) return elm_result_to_dfs(res); + if (res) + return elm_result_to_dfs(res); /* Get total sectors and free sectors */ tot_sect = (f->n_fatent - 2) * f->csize; @@ -202,9 +204,9 @@ int dfs_elm_statfs(struct dfs_filesystem* fs, struct statfs *buf) return 0; } -int dfs_elm_open(struct dfs_fd* file) +int dfs_elm_open(struct dfs_fd *file) { - FIL* fd; + FIL *fd; BYTE mode; FRESULT result; char *drivers_fn; @@ -215,9 +217,11 @@ int dfs_elm_open(struct dfs_fd* file) /* add path for ELM FatFS driver support */ vol = elm_get_vol((FATFS *)file->fs->data); - if (vol < 0) return -DFS_STATUS_ENOENT; + if (vol < 0) + return -DFS_STATUS_ENOENT; drivers_fn = rt_malloc(256); - if (drivers_fn == RT_NULL) return -DFS_STATUS_ENOMEM; + if (drivers_fn == RT_NULL) + return -DFS_STATUS_ENOMEM; rt_snprintf(drivers_fn, 256, "%d:%s", vol, file->path); #else @@ -267,17 +271,22 @@ int dfs_elm_open(struct dfs_fd* file) { mode = FA_READ; - if (file->flags & DFS_O_WRONLY) mode |= FA_WRITE; - if ((file->flags & DFS_O_ACCMODE) & DFS_O_RDWR) mode |= FA_WRITE; + if (file->flags & DFS_O_WRONLY) + mode |= FA_WRITE; + if ((file->flags & DFS_O_ACCMODE) & DFS_O_RDWR) + mode |= FA_WRITE; /* Opens the file, if it is existing. If not, a new file is created. */ - if (file->flags & DFS_O_CREAT) mode |= FA_OPEN_ALWAYS; + if (file->flags & DFS_O_CREAT) + mode |= FA_OPEN_ALWAYS; /* Creates a new file. If the file is existing, it is truncated and overwritten. */ - if (file->flags & DFS_O_TRUNC) mode |= FA_CREATE_ALWAYS; + if (file->flags & DFS_O_TRUNC) + mode |= FA_CREATE_ALWAYS; /* Creates a new file. The function fails if the file is already existing. */ - if (file->flags & DFS_O_EXCL) mode |= FA_CREATE_NEW; + if (file->flags & DFS_O_EXCL) + mode |= FA_CREATE_NEW; /* allocate a fd */ - fd = (FIL*)rt_malloc(sizeof(FIL)); + fd = (FIL *)rt_malloc(sizeof(FIL)); if (fd == RT_NULL) { return -DFS_STATUS_ENOMEM; @@ -309,16 +318,16 @@ int dfs_elm_open(struct dfs_fd* file) return DFS_STATUS_OK; } -int dfs_elm_close(struct dfs_fd* file) +int dfs_elm_close(struct dfs_fd *file) { FRESULT result; result = FR_OK; if (file->type == FT_DIRECTORY) { - DIR* dir; + DIR *dir; - dir = (DIR*)(file->data); + dir = (DIR *)(file->data); RT_ASSERT(dir != RT_NULL); /* release memory */ @@ -326,8 +335,8 @@ int dfs_elm_close(struct dfs_fd* file) } else if (file->type == FT_REGULAR) { - FIL* fd; - fd = (FIL*)(file->data); + FIL *fd; + fd = (FIL *)(file->data); RT_ASSERT(fd != RT_NULL); result = f_close(fd); @@ -341,14 +350,14 @@ int dfs_elm_close(struct dfs_fd* file) return elm_result_to_dfs(result); } -int dfs_elm_ioctl(struct dfs_fd* file, int cmd, void* args) +int dfs_elm_ioctl(struct dfs_fd *file, int cmd, void *args) { return -DFS_STATUS_ENOSYS; } -int dfs_elm_read(struct dfs_fd* file, void* buf, rt_size_t len) +int dfs_elm_read(struct dfs_fd *file, void *buf, rt_size_t len) { - FIL* fd; + FIL *fd; FRESULT result; UINT byte_read; @@ -357,20 +366,21 @@ int dfs_elm_read(struct dfs_fd* file, void* buf, rt_size_t len) return -DFS_STATUS_EISDIR; } - fd = (FIL*)(file->data); + fd = (FIL *)(file->data); RT_ASSERT(fd != RT_NULL); result = f_read(fd, buf, len, &byte_read); /* update position */ file->pos = fd->fptr; - if (result == FR_OK) return byte_read; + if (result == FR_OK) + return byte_read; return elm_result_to_dfs(result); } -int dfs_elm_write(struct dfs_fd* file, const void* buf, rt_size_t len) +int dfs_elm_write(struct dfs_fd *file, const void *buf, rt_size_t len) { - FIL* fd; + FIL *fd; FRESULT result; UINT byte_write; @@ -379,39 +389,40 @@ int dfs_elm_write(struct dfs_fd* file, const void* buf, rt_size_t len) return -DFS_STATUS_EISDIR; } - fd = (FIL*)(file->data); + fd = (FIL *)(file->data); RT_ASSERT(fd != RT_NULL); result = f_write(fd, buf, len, &byte_write); /* update position and file size */ file->pos = fd->fptr; file->size = fd->fsize; - if (result == FR_OK) return byte_write; + if (result == FR_OK) + return byte_write; return elm_result_to_dfs(result); } -int dfs_elm_flush(struct dfs_fd* file) +int dfs_elm_flush(struct dfs_fd *file) { - FIL* fd; + FIL *fd; FRESULT result; - fd = (FIL*)(file->data); + fd = (FIL *)(file->data); RT_ASSERT(fd != RT_NULL); result = f_sync(fd); return elm_result_to_dfs(result); } -int dfs_elm_lseek(struct dfs_fd* file, rt_off_t offset) +int dfs_elm_lseek(struct dfs_fd *file, rt_off_t offset) { FRESULT result = FR_OK; if (file->type == FT_REGULAR) { - FIL* fd; + FIL *fd; /* regular file type */ - fd = (FIL*)(file->data); + fd = (FIL *)(file->data); RT_ASSERT(fd != RT_NULL); result = f_lseek(fd, offset); @@ -424,9 +435,9 @@ int dfs_elm_lseek(struct dfs_fd* file, rt_off_t offset) else if (file->type == FT_DIRECTORY) { /* which is a directory */ - DIR* dir; + DIR *dir; - dir = (DIR*)(file->data); + dir = (DIR *)(file->data); RT_ASSERT(dir != RT_NULL); result = f_seekdir(dir, offset / sizeof(struct dirent)); @@ -441,20 +452,21 @@ int dfs_elm_lseek(struct dfs_fd* file, rt_off_t offset) return elm_result_to_dfs(result); } -int dfs_elm_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t count) +int dfs_elm_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint32_t count) { - DIR* dir; + DIR *dir; FILINFO fno; FRESULT result; rt_uint32_t index; - struct dirent* d; + struct dirent *d; - dir = (DIR*)(file->data); + dir = (DIR *)(file->data); RT_ASSERT(dir != RT_NULL); /* make integer count */ count = (count / sizeof(struct dirent)) * sizeof(struct dirent); - if ( count == 0 ) return -DFS_STATUS_EINVAL; + if (count == 0) + return -DFS_STATUS_EINVAL; #if _USE_LFN /* allocate long file name */ @@ -470,7 +482,8 @@ int dfs_elm_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t count d = dirp + index; result = f_readdir(dir, &fno); - if (result != FR_OK || fno.fname[0] == 0) break; + if (result != FR_OK || fno.fname[0] == 0) + break; #if _USE_LFN fn = *fno.lfname? fno.lfname : fno.fname; @@ -479,15 +492,17 @@ int dfs_elm_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t count #endif d->d_type = DFS_DT_UNKNOWN; - if (fno.fattrib & AM_DIR) d->d_type = DFS_DT_DIR; - else d->d_type = DFS_DT_REG; + if (fno.fattrib & AM_DIR) + d->d_type = DFS_DT_DIR; + else + d->d_type = DFS_DT_REG; d->d_namlen = rt_strlen(fn); d->d_reclen = (rt_uint16_t)sizeof(struct dirent); rt_strncpy(d->d_name, fn, rt_strlen(fn) + 1); index ++; - if ( index * sizeof(struct dirent) >= count ) + if (index * sizeof(struct dirent) >= count) break; } @@ -503,7 +518,7 @@ int dfs_elm_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t count return index * sizeof(struct dirent); } -int dfs_elm_unlink(struct dfs_filesystem* fs, const char* path) +int dfs_elm_unlink(struct dfs_filesystem *fs, const char *path) { FRESULT result; @@ -514,9 +529,11 @@ int dfs_elm_unlink(struct dfs_filesystem* fs, const char* path) /* add path for ELM FatFS driver support */ vol = elm_get_vol((FATFS *)fs->data); - if (vol < 0) return -DFS_STATUS_ENOENT; + if (vol < 0) + return -DFS_STATUS_ENOENT; drivers_fn = rt_malloc(256); - if (drivers_fn == RT_NULL) return -DFS_STATUS_ENOMEM; + if (drivers_fn == RT_NULL) + return -DFS_STATUS_ENOMEM; rt_snprintf(drivers_fn, 256, "%d:%s", vol, path); #else @@ -531,7 +548,7 @@ int dfs_elm_unlink(struct dfs_filesystem* fs, const char* path) return elm_result_to_dfs(result); } -int dfs_elm_rename(struct dfs_filesystem* fs, const char* oldpath, const char* newpath) +int dfs_elm_rename(struct dfs_filesystem *fs, const char *oldpath, const char *newpath) { FRESULT result; @@ -543,10 +560,12 @@ int dfs_elm_rename(struct dfs_filesystem* fs, const char* oldpath, const char* n /* add path for ELM FatFS driver support */ vol = elm_get_vol((FATFS *)fs->data); - if (vol < 0) return -DFS_STATUS_ENOENT; + if (vol < 0) + return -DFS_STATUS_ENOENT; drivers_oldfn = rt_malloc(256); - if (drivers_oldfn == RT_NULL) return -DFS_STATUS_ENOMEM; + if (drivers_oldfn == RT_NULL) + return -DFS_STATUS_ENOMEM; drivers_newfn = newpath; rt_snprintf(drivers_oldfn, 256, "%d:%s", vol, oldpath); @@ -564,7 +583,7 @@ int dfs_elm_rename(struct dfs_filesystem* fs, const char* oldpath, const char* n return elm_result_to_dfs(result); } -int dfs_elm_stat(struct dfs_filesystem* fs, const char *path, struct stat *st) +int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) { FILINFO file_info; FRESULT result; @@ -577,9 +596,11 @@ int dfs_elm_stat(struct dfs_filesystem* fs, const char *path, struct stat *st) /* add path for ELM FatFS driver support */ vol = elm_get_vol((FATFS *)fs->data); - if (vol < 0) return -DFS_STATUS_ENOENT; + if (vol < 0) + return -DFS_STATUS_ENOENT; drivers_fn = rt_malloc(256); - if (drivers_fn == RT_NULL) return -DFS_STATUS_ENOMEM; + if (drivers_fn == RT_NULL) + return -DFS_STATUS_ENOMEM; rt_snprintf(drivers_fn, 256, "%d:%s", vol, path); #else @@ -600,7 +621,7 @@ int dfs_elm_stat(struct dfs_filesystem* fs, const char *path, struct stat *st) if (result == FR_OK) { /* convert to dfs stat structure */ - st->st_dev = 0; + st->st_dev = 0; st->st_mode = DFS_S_IFREG | DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH | DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH; @@ -659,19 +680,19 @@ int elm_init(void) #include "diskio.h" /* Inidialize a Drive */ -DSTATUS disk_initialize (BYTE drv) +DSTATUS disk_initialize(BYTE drv) { return 0; } /* Return Disk Status */ -DSTATUS disk_status (BYTE drv) +DSTATUS disk_status(BYTE drv) { return 0; } /* Read Sector(s) */ -DRESULT disk_read (BYTE drv, BYTE *buff, DWORD sector, BYTE count) +DRESULT disk_read(BYTE drv, BYTE *buff, DWORD sector, BYTE count) { rt_size_t result; rt_device_t device = disk[drv]; @@ -686,7 +707,7 @@ DRESULT disk_read (BYTE drv, BYTE *buff, DWORD sector, BYTE count) } /* Write Sector(s) */ -DRESULT disk_write (BYTE drv, const BYTE *buff, DWORD sector, BYTE count) +DRESULT disk_write(BYTE drv, const BYTE *buff, DWORD sector, BYTE count) { rt_size_t result; rt_device_t device = disk[drv]; @@ -701,11 +722,12 @@ DRESULT disk_write (BYTE drv, const BYTE *buff, DWORD sector, BYTE count) } /* Miscellaneous Functions */ -DRESULT disk_ioctl (BYTE drv, BYTE ctrl, void *buff) +DRESULT disk_ioctl(BYTE drv, BYTE ctrl, void *buff) { rt_device_t device = disk[drv]; - if (device == RT_NULL) return RES_ERROR; + if (device == RT_NULL) + return RES_ERROR; if (ctrl == GET_SECTOR_COUNT) { @@ -714,8 +736,9 @@ DRESULT disk_ioctl (BYTE drv, BYTE ctrl, void *buff) rt_memset(&geometry, 0, sizeof(geometry)); rt_device_control(device, RT_DEVICE_CTRL_BLK_GETGEOME, &geometry); - *(DWORD*)buff = geometry.sector_count; - if (geometry.sector_count == 0) return RES_ERROR; + *(DWORD *)buff = geometry.sector_count; + if (geometry.sector_count == 0) + return RES_ERROR; } else if (ctrl == GET_SECTOR_SIZE) { @@ -724,7 +747,7 @@ DRESULT disk_ioctl (BYTE drv, BYTE ctrl, void *buff) rt_memset(&geometry, 0, sizeof(geometry)); rt_device_control(device, RT_DEVICE_CTRL_BLK_GETGEOME, &geometry); - *(WORD*)buff = geometry.bytes_per_sector; + *(WORD *)buff = geometry.bytes_per_sector; } else if (ctrl == GET_BLOCK_SIZE) /* Get erase block size in unit of sectors (DWORD) */ { @@ -733,19 +756,19 @@ DRESULT disk_ioctl (BYTE drv, BYTE ctrl, void *buff) rt_memset(&geometry, 0, sizeof(geometry)); rt_device_control(device, RT_DEVICE_CTRL_BLK_GETGEOME, &geometry); - *(DWORD*)buff = geometry.block_size/geometry.bytes_per_sector; + *(DWORD *)buff = geometry.block_size/geometry.bytes_per_sector; } return RES_OK; } -rt_time_t get_fattime() +rt_time_t get_fattime(void) { return 0; } #if _FS_REENTRANT -int ff_cre_syncobj(BYTE drv, _SYNC_t* m) +int ff_cre_syncobj(BYTE drv, _SYNC_t *m) { char name[8]; rt_mutex_t mutex; @@ -770,7 +793,8 @@ int ff_del_syncobj(_SYNC_t m) int ff_req_grant(_SYNC_t m) { - if (rt_mutex_take(m, _FS_TIMEOUT) == RT_EOK) return RT_TRUE; + if (rt_mutex_take(m, _FS_TIMEOUT) == RT_EOK) + return RT_TRUE; return RT_FALSE; } diff --git a/components/dfs/filesystems/nfs/dfs_nfs.c b/components/dfs/filesystems/nfs/dfs_nfs.c index bf01607e5f..528d4d910e 100644 --- a/components/dfs/filesystems/nfs/dfs_nfs.c +++ b/components/dfs/filesystems/nfs/dfs_nfs.c @@ -1,3 +1,16 @@ +/* + * File : dfs_nfs.c + * This file is part of Device File System in RT-Thread RTOS + * COPYRIGHT (C) 2004-2011, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE. + * + * Change Logs: + * Date Author Notes + */ + #include #include #include @@ -43,27 +56,30 @@ struct nfs_filesystem }; typedef struct nfs_file nfs_file; typedef struct nfs_dir nfs_dir; -nfs_dir *nfs_opendir(struct nfs_filesystem* nfs, const char *path); +nfs_dir *nfs_opendir(struct nfs_filesystem *nfs, const char *path); -static int nfs_parse_host_export(const char* host_export, - char* host, size_t host_len, - char* export, size_t export_len) +static int nfs_parse_host_export(const char *host_export, + char *host, size_t host_len, + char *export, size_t export_len) { int index; for (index = 0; index < host_len; index ++) { /* it's end of string, failed */ - if (host_export[index] == 0) return -1; + if (host_export[index] == 0) + return -1; /* copy to host buffer */ if (host_export[index] != ':') host[index] = host_export[index]; - else break; + else + break; } /* host buffer is not enough, failed */ - if (index == host_len) return -1; + if (index == host_len) + return -1; /* make RT_NULL */ host_len = index; @@ -90,38 +106,38 @@ static void copy_handle(nfs_fh3 *dest, const nfs_fh3 *source) { dest->data.data_len = source->data.data_len; dest->data.data_val = rt_malloc(dest->data.data_len); - if(dest->data.data_val==RT_NULL) + if (dest->data.data_val == RT_NULL) { - dest->data.data_len=0; + dest->data.data_len = 0; return; } memcpy(dest->data.data_val, source->data.data_val, dest->data.data_len); } -static nfs_fh3 *get_handle(struct nfs_filesystem* nfs, const char *name) +static nfs_fh3 *get_handle(struct nfs_filesystem *nfs, const char *name) { - nfs_fh3 *handle=RT_NULL; + nfs_fh3 *handle = RT_NULL; char *file; char *path; char *init; init = path = rt_malloc(strlen(name)+1); - if(init==RT_NULL) + if (init == RT_NULL) return RT_NULL; memcpy(init, name, strlen(name)+1); handle = rt_malloc(sizeof(nfs_fh3)); - if(handle==RT_NULL) + if (handle == RT_NULL) { rt_free(init); return RT_NULL; } - if(path[0]=='/') + if (path[0] == '/') { - path++; + path ++; copy_handle(handle, &nfs->root_handle); } else @@ -129,16 +145,16 @@ static nfs_fh3 *get_handle(struct nfs_filesystem* nfs, const char *name) copy_handle(handle, &nfs->current_handle); } - while((file=strtok_r(RT_NULL, "/", &path))!=RT_NULL) + while ((file = strtok_r(RT_NULL, "/", &path)) != RT_NULL) { LOOKUP3args args; LOOKUP3res res; memset(&res, 0, sizeof(res)); copy_handle(&args.what.dir, handle); xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)handle); - args.what.name=file; + args.what.name = file; - if(nfsproc3_lookup_3(args, &res, nfs->nfs_client)!=RPC_SUCCESS) + if (nfsproc3_lookup_3(args, &res, nfs->nfs_client) != RPC_SUCCESS) { rt_kprintf("Lookup failed\n"); rt_free(init); @@ -146,7 +162,7 @@ static nfs_fh3 *get_handle(struct nfs_filesystem* nfs, const char *name) xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)&args.what.dir); return RT_NULL; } - else if(res.status!=NFS3_OK) + else if (res.status != NFS3_OK) { rt_kprintf("Lookup failed: %d\n", res.status); rt_free(init); @@ -164,28 +180,28 @@ static nfs_fh3 *get_handle(struct nfs_filesystem* nfs, const char *name) return handle; } -static nfs_fh3 *get_dir_handle(struct nfs_filesystem* nfs, const char *name) +static nfs_fh3 *get_dir_handle(struct nfs_filesystem *nfs, const char *name) { - nfs_fh3 *handle=RT_NULL; + nfs_fh3 *handle = RT_NULL; char *file; char *path; char *init; init = path = rt_malloc(strlen(name)+1); - if(init==RT_NULL) + if (init == RT_NULL) return RT_NULL; memcpy(init, name, strlen(name)+1); handle = rt_malloc(sizeof(nfs_fh3)); - if(handle == RT_NULL) + if (handle == RT_NULL) { rt_free(init); return RT_NULL; } - if(path[0]=='/') + if (path[0] == '/') { - path++; + path ++; copy_handle(handle, &nfs->root_handle); } else @@ -193,16 +209,16 @@ static nfs_fh3 *get_dir_handle(struct nfs_filesystem* nfs, const char *name) copy_handle(handle, &nfs->current_handle); } - while((file=strtok_r(RT_NULL, "/", &path))!=RT_NULL && path[0]!='\0') + while ((file = strtok_r(RT_NULL, "/", &path)) != RT_NULL && path[0] != '\0') { LOOKUP3args args; LOOKUP3res res; memset(&res, 0, sizeof(res)); copy_handle(&args.what.dir, handle); xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)handle); - args.what.name=file; + args.what.name = file; - if(nfsproc3_lookup_3(args, &res, nfs->nfs_client)!=RPC_SUCCESS) + if (nfsproc3_lookup_3(args, &res, nfs->nfs_client) != RPC_SUCCESS) { rt_kprintf("Lookup failed\n"); rt_free(init); @@ -210,7 +226,7 @@ static nfs_fh3 *get_dir_handle(struct nfs_filesystem* nfs, const char *name) xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)&args.what.dir); return RT_NULL; } - else if(res.status!=NFS3_OK) + else if (res.status != NFS3_OK) { rt_kprintf("Lookup failed: %d\n", res.status); rt_free(init); @@ -228,7 +244,7 @@ static nfs_fh3 *get_dir_handle(struct nfs_filesystem* nfs, const char *name) return handle; } -static size_t nfs_get_filesize(struct nfs_filesystem* nfs, nfs_fh3 *handle) +static size_t nfs_get_filesize(struct nfs_filesystem *nfs, nfs_fh3 *handle) { GETATTR3args args; GETATTR3res res; @@ -246,14 +262,14 @@ static size_t nfs_get_filesize(struct nfs_filesystem* nfs, nfs_fh3 *handle) return 0; } - info=&res.GETATTR3res_u.resok.obj_attributes; + info = &res.GETATTR3res_u.resok.obj_attributes; size = info->size; xdr_free((xdrproc_t)xdr_GETATTR3res, (char *)&res); return size; } -rt_bool_t nfs_is_directory(struct nfs_filesystem* nfs, const char* name) +rt_bool_t nfs_is_directory(struct nfs_filesystem *nfs, const char *name) { GETATTR3args args; GETATTR3res res; @@ -263,18 +279,19 @@ rt_bool_t nfs_is_directory(struct nfs_filesystem* nfs, const char* name) result = RT_FALSE; handle = get_handle(nfs, name); - if(handle == RT_NULL) return RT_FALSE; + if (handle == RT_NULL) + return RT_FALSE; args.object = *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) { rt_kprintf("GetAttr failed\n"); return RT_FALSE; } - else if(res.status!=NFS3_OK) + else if (res.status != NFS3_OK) { rt_kprintf("Getattr failed: %d\n", res.status); return RT_FALSE; @@ -282,7 +299,8 @@ rt_bool_t nfs_is_directory(struct nfs_filesystem* nfs, const char* name) info=&res.GETATTR3res_u.resok.obj_attributes; - if (info->type == NFS3DIR) result = RT_TRUE; + if (info->type == NFS3DIR) + result = RT_TRUE; xdr_free((xdrproc_t)xdr_GETATTR3res, (char *)&res); xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)handle); @@ -291,47 +309,47 @@ rt_bool_t nfs_is_directory(struct nfs_filesystem* nfs, const char* name) return result; } -int nfs_create(struct nfs_filesystem* nfs, const char *name, mode_t mode) +int nfs_create(struct nfs_filesystem *nfs, const char *name, mode_t mode) { CREATE3args args; CREATE3res res; - int ret=0; + int ret = 0; nfs_fh3 *handle; - if(nfs->nfs_client==RT_NULL) + if (nfs->nfs_client == RT_NULL) { return -1; } - handle=get_dir_handle(nfs, name); - if(handle==RT_NULL) + handle = get_dir_handle(nfs, name); + if (handle == RT_NULL) { return -1; } - args.where.dir=*handle; - args.where.name=strrchr(name, '/') + 1; - if(args.where.name==RT_NULL) + args.where.dir = *handle; + args.where.name = strrchr(name, '/') + 1; + if (args.where.name == RT_NULL) { - args.where.name=(char *)name; + args.where.name = (char *)name; } - args.how.mode=GUARDED; + args.how.mode = GUARDED; - args.how.createhow3_u.obj_attributes.mode.set_it=TRUE; - args.how.createhow3_u.obj_attributes.mode.set_mode3_u.mode=mode; - args.how.createhow3_u.obj_attributes.uid.set_it=FALSE; - args.how.createhow3_u.obj_attributes.gid.set_it=FALSE; - args.how.createhow3_u.obj_attributes.size.set_it=FALSE; - args.how.createhow3_u.obj_attributes.atime.set_it=DONT_CHANGE; - args.how.createhow3_u.obj_attributes.mtime.set_it=DONT_CHANGE; + args.how.createhow3_u.obj_attributes.mode.set_it = TRUE; + args.how.createhow3_u.obj_attributes.mode.set_mode3_u.mode = mode; + args.how.createhow3_u.obj_attributes.uid.set_it = FALSE; + args.how.createhow3_u.obj_attributes.gid.set_it = FALSE; + args.how.createhow3_u.obj_attributes.size.set_it = FALSE; + args.how.createhow3_u.obj_attributes.atime.set_it = DONT_CHANGE; + args.how.createhow3_u.obj_attributes.mtime.set_it = DONT_CHANGE; memset(&res, 0, sizeof(res)); - if(nfsproc3_create_3(args, &res, nfs->nfs_client)!=RPC_SUCCESS) + if (nfsproc3_create_3(args, &res, nfs->nfs_client) != RPC_SUCCESS) { rt_kprintf("Create failed\n"); ret = -1; } - else if(res.status!=NFS3_OK) + else if (res.status != NFS3_OK) { rt_kprintf("Create failed: %d\n", res.status); ret = -1; @@ -343,46 +361,46 @@ int nfs_create(struct nfs_filesystem* nfs, const char *name, mode_t mode) return ret; } -int nfs_mkdir(struct nfs_filesystem* nfs, const char *name, mode_t mode) +int nfs_mkdir(struct nfs_filesystem *nfs, const char *name, mode_t mode) { MKDIR3args args; MKDIR3res res; - int ret=0; + int ret = 0; nfs_fh3 *handle; - if(nfs->nfs_client==RT_NULL) + if (nfs->nfs_client == RT_NULL) return -1; - handle=get_dir_handle(nfs, name); - if(handle==RT_NULL) + handle = get_dir_handle(nfs, name); + if (handle == RT_NULL) return -1; - args.where.dir=*handle; - args.where.name=strrchr(name, '/') + 1; - if(args.where.name==RT_NULL) + args.where.dir = *handle; + args.where.name = strrchr(name, '/') + 1; + if (args.where.name == RT_NULL) { - args.where.name=(char *)name; + args.where.name = (char *)name; } - args.attributes.mode.set_it=TRUE; - args.attributes.mode.set_mode3_u.mode=mode; - args.attributes.uid.set_it=FALSE; - args.attributes.gid.set_it=FALSE; - args.attributes.size.set_it=FALSE; - args.attributes.atime.set_it=DONT_CHANGE; - args.attributes.mtime.set_it=DONT_CHANGE; + args.attributes.mode.set_it = TRUE; + args.attributes.mode.set_mode3_u.mode = mode; + args.attributes.uid.set_it = FALSE; + args.attributes.gid.set_it = FALSE; + args.attributes.size.set_it = FALSE; + args.attributes.atime.set_it = DONT_CHANGE; + args.attributes.mtime.set_it = DONT_CHANGE; memset(&res, 0, sizeof(res)); - if(nfsproc3_mkdir_3(args, &res, nfs->nfs_client)!=RPC_SUCCESS) + if (nfsproc3_mkdir_3(args, &res, nfs->nfs_client) != RPC_SUCCESS) { rt_kprintf("Mkdir failed\n"); - ret=-1; + ret = -1; } - else if(res.status!=NFS3_OK) + else if (res.status != NFS3_OK) { rt_kprintf("Mkdir failed: %d\n", res.status); - ret=-1; + ret = -1; } xdr_free((xdrproc_t)xdr_MKDIR3res, (char *)&res); xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)handle); @@ -392,15 +410,15 @@ int nfs_mkdir(struct nfs_filesystem* nfs, const char *name, mode_t mode) } /* mount(RT_NULL, "/mnt", "nfs", 0, "192.168.1.1:/export") */ -int nfs_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* data) +int nfs_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data) { mountres3 res; - struct nfs_filesystem* nfs; + struct nfs_filesystem *nfs; - nfs = (struct nfs_filesystem*)rt_malloc(sizeof(struct nfs_filesystem)); + nfs = (struct nfs_filesystem *)rt_malloc(sizeof(struct nfs_filesystem)); memset(nfs, 0, sizeof(struct nfs_filesystem)); - if (nfs_parse_host_export((const char*)data, nfs->host, HOST_LENGTH, + if (nfs_parse_host_export((const char *)data, nfs->host, HOST_LENGTH, nfs->export, EXPORT_PATH_LENGTH) < 0) { rt_kprintf("host or export path error\n"); @@ -408,25 +426,25 @@ int nfs_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* data) } nfs->mount_client=clnt_create((char *)nfs->host, MOUNT_PROGRAM, MOUNT_V3, "udp"); - if(nfs->mount_client==RT_NULL) + if (nfs->mount_client == RT_NULL) { rt_kprintf("create mount client failed\n"); goto __return; } memset(&res, '\0', sizeof(mountres3)); - if(mountproc3_mnt_3((char *)nfs->export, &res, nfs->mount_client)!=RPC_SUCCESS) + if (mountproc3_mnt_3((char *)nfs->export, &res, nfs->mount_client) != RPC_SUCCESS) { rt_kprintf("nfs mount failed\n"); goto __return; } - else if(res.fhs_status!=MNT3_OK) + else if (res.fhs_status != MNT3_OK) { rt_kprintf("nfs mount failed\n"); goto __return; } nfs->nfs_client=clnt_create((char *)nfs->host, NFS_PROGRAM, NFS_V3, "udp"); - if(nfs->nfs_client == RT_NULL) + if (nfs->nfs_client == RT_NULL) { rt_kprintf("creat nfs client failed\n"); goto __return; @@ -434,7 +452,7 @@ int nfs_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* data) copy_handle(&nfs->root_handle, (nfs_fh3 *)&res.mountres3_u.mountinfo.fhandle); copy_handle(&nfs->current_handle, &nfs->root_handle); - nfs->nfs_client->cl_auth=authnone_create(); + nfs->nfs_client->cl_auth = authnone_create(); fs->data = nfs; return 0; @@ -460,9 +478,9 @@ __return: return -1; } -int nfs_unmount(struct dfs_filesystem* fs) +int nfs_unmount(struct dfs_filesystem *fs) { - struct nfs_filesystem* nfs; + struct nfs_filesystem *nfs; RT_ASSERT(fs != RT_NULL); RT_ASSERT(fs->data != RT_NULL); @@ -476,9 +494,9 @@ int nfs_unmount(struct dfs_filesystem* fs) } /* destroy nfs client */ - if(nfs->nfs_client != RT_NULL) + if (nfs->nfs_client != RT_NULL) { - if(nfs->nfs_client->cl_auth!=RT_NULL) + if (nfs->nfs_client->cl_auth != RT_NULL) { auth_destroy(nfs->nfs_client->cl_auth); nfs->nfs_client->cl_auth = RT_NULL; @@ -488,15 +506,15 @@ int nfs_unmount(struct dfs_filesystem* fs) } /* destroy mount client */ - if(nfs->mount_client != RT_NULL) + if (nfs->mount_client != RT_NULL) { - if(nfs->mount_client->cl_auth != RT_NULL) + if (nfs->mount_client->cl_auth != RT_NULL) { auth_destroy(nfs->mount_client->cl_auth); nfs->mount_client->cl_auth = RT_NULL; } clnt_destroy(nfs->mount_client); - nfs->mount_client=RT_NULL; + nfs->mount_client = RT_NULL; } rt_free(nfs); @@ -505,18 +523,18 @@ int nfs_unmount(struct dfs_filesystem* fs) return 0; } -int nfs_ioctl(struct dfs_fd* file, int cmd, void* args) +int nfs_ioctl(struct dfs_fd *file, int cmd, void *args) { return -DFS_STATUS_ENOSYS; } -int nfs_read(struct dfs_fd* file, void *buf, rt_size_t count) +int nfs_read(struct dfs_fd *file, void *buf, rt_size_t count) { READ3args args; READ3res res; ssize_t bytes; nfs_file *fd; - struct nfs_filesystem* nfs; + struct nfs_filesystem *nfs; if (file->type == FT_DIRECTORY) return -DFS_STATUS_EISDIR; @@ -527,35 +545,36 @@ int nfs_read(struct dfs_fd* file, void *buf, rt_size_t count) RT_ASSERT(file->fs->data != RT_NULL); nfs = (struct nfs_filesystem *)file->fs->data; - if(nfs->nfs_client==RT_NULL) + if (nfs->nfs_client == RT_NULL) return -1; /* end of file */ - if (fd->eof == TRUE) return 0; + if (fd->eof == TRUE) + return 0; - args.file=fd->handle; - args.offset=fd->offset; - args.count=count; + args.file = fd->handle; + args.offset = fd->offset; + args.count = count; memset(&res, 0, sizeof(res)); - if(nfsproc3_read_3(args, &res, nfs->nfs_client) != RPC_SUCCESS) + if (nfsproc3_read_3(args, &res, nfs->nfs_client) != RPC_SUCCESS) { rt_kprintf("Read failed\n"); bytes = 0; } - else if(res.status!=NFS3_OK) + else if (res.status != NFS3_OK) { rt_kprintf("Read failed: %d\n", res.status); bytes = 0; } else { - if(res.READ3res_u.resok.eof) + if (res.READ3res_u.resok.eof) { /* something should probably be here */ fd->eof = TRUE; } - bytes=res.READ3res_u.resok.count; + bytes = res.READ3res_u.resok.count; fd->offset += bytes; /* update current position */ file->pos = fd->offset; @@ -566,13 +585,13 @@ int nfs_read(struct dfs_fd* file, void *buf, rt_size_t count) return bytes; } -int nfs_write(struct dfs_fd* file, const void *buf, rt_size_t count) +int nfs_write(struct dfs_fd *file, const void *buf, rt_size_t count) { WRITE3args args; WRITE3res res; ssize_t bytes; nfs_file *fd; - struct nfs_filesystem* nfs; + struct nfs_filesystem *nfs; if (file->type == FT_DIRECTORY) return -DFS_STATUS_EISDIR; @@ -583,31 +602,31 @@ int nfs_write(struct dfs_fd* file, const void *buf, rt_size_t count) RT_ASSERT(file->fs->data != RT_NULL); nfs = (struct nfs_filesystem *)file->fs->data; - if(nfs->nfs_client==RT_NULL) + if (nfs->nfs_client == RT_NULL) return -1; - args.file=fd->handle; - args.stable=FILE_SYNC; - args.offset=fd->offset; + args.file = fd->handle; + args.stable = FILE_SYNC; + args.offset = fd->offset; memset(&res, 0, sizeof(res)); args.data.data_val=(void *)buf; - args.count=args.data.data_len=count; + args.count=args.data.data_len = count; - if(nfsproc3_write_3(args, &res, nfs->nfs_client)!=RPC_SUCCESS) + if (nfsproc3_write_3(args, &res, nfs->nfs_client) != RPC_SUCCESS) { rt_kprintf("Write failed\n"); bytes = 0; } - else if(res.status!=NFS3_OK) + else if (res.status != NFS3_OK) { rt_kprintf("Write failed: %d\n", res.status); bytes = 0; } else { - bytes=res.WRITE3res_u.resok.count; - fd->offset+=bytes; + bytes = res.WRITE3res_u.resok.count; + fd->offset += bytes; /* update current position */ file->pos = fd->offset; /* todo: update file size */ @@ -617,7 +636,7 @@ int nfs_write(struct dfs_fd* file, const void *buf, rt_size_t count) return bytes; } -int nfs_lseek(struct dfs_fd* file, rt_off_t offset) +int nfs_lseek(struct dfs_fd *file, rt_off_t offset) { nfs_file *fd; @@ -636,22 +655,22 @@ int nfs_lseek(struct dfs_fd* file, rt_off_t offset) return -DFS_STATUS_EIO; } -int nfs_close(struct dfs_fd* file) +int nfs_close(struct dfs_fd *file) { if (file->type == FT_DIRECTORY) { - struct nfs_dir* dir; + struct nfs_dir *dir; - dir = (struct nfs_dir*)file->data; + dir = (struct nfs_dir *)file->data; xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)&dir->handle); xdr_free((xdrproc_t)xdr_READDIR3res, (char *)&dir->res); rt_free(dir); } else if (file->type == FT_REGULAR) { - struct nfs_file* fd; + struct nfs_file *fd; - fd = (struct nfs_file*)file->data; + fd = (struct nfs_file *)file->data; xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)&fd->handle); rt_free(fd); @@ -661,9 +680,9 @@ int nfs_close(struct dfs_fd* file) return 0; } -int nfs_open(struct dfs_fd* file) +int nfs_open(struct dfs_fd *file) { - struct nfs_filesystem* nfs; + struct nfs_filesystem *nfs; RT_ASSERT(file->fs != RT_NULL); RT_ASSERT(file->fs->data != RT_NULL); @@ -695,12 +714,12 @@ int nfs_open(struct dfs_fd* file) } /* open file (get file handle ) */ - fp=rt_malloc(sizeof(nfs_file)); - if(fp == RT_NULL) + fp = rt_malloc(sizeof(nfs_file)); + if (fp == RT_NULL) return -1; handle = get_handle(nfs, file->path); - if(handle == RT_NULL) + if (handle == RT_NULL) { rt_free(fp); return -1; @@ -708,7 +727,7 @@ int nfs_open(struct dfs_fd* file) /* get size of file */ fp->size = nfs_get_filesize(nfs, handle); - fp->offset=0; + fp->offset = 0; fp->eof = FALSE; copy_handle(&fp->handle, handle); @@ -727,32 +746,32 @@ int nfs_open(struct dfs_fd* file) return 0; } -int nfs_stat(struct dfs_filesystem* fs, const char *path, struct stat *st) +int nfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) { GETATTR3args args; GETATTR3res res; fattr3 *info; nfs_fh3 *handle; - struct nfs_filesystem* nfs; + struct nfs_filesystem *nfs; RT_ASSERT(fs != RT_NULL); RT_ASSERT(fs->data != RT_NULL); nfs = (struct nfs_filesystem *)fs->data; handle = get_handle(nfs, path); - if(handle == RT_NULL) + if (handle == RT_NULL) return -1; args.object = *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) { rt_kprintf("GetAttr failed\n"); return -1; } - else if(res.status!=NFS3_OK) + else if (res.status != NFS3_OK) { rt_kprintf("Getattr failed: %d\n", res.status); return -1; @@ -760,7 +779,7 @@ int nfs_stat(struct dfs_filesystem* fs, const char *path, struct stat *st) info = &res.GETATTR3res_u.resok.obj_attributes; - st->st_dev = 0; + st->st_dev = 0; st->st_mode = DFS_S_IFREG | DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH | DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH; @@ -781,19 +800,19 @@ int nfs_stat(struct dfs_filesystem* fs, const char *path, struct stat *st) return 0; } -nfs_dir *nfs_opendir(struct nfs_filesystem* nfs, const char *path) +nfs_dir *nfs_opendir(struct nfs_filesystem *nfs, const char *path) { nfs_dir *dir; nfs_fh3 *handle; - dir=rt_malloc(sizeof(nfs_dir)); - if(dir==RT_NULL) + dir = rt_malloc(sizeof(nfs_dir)); + if (dir == RT_NULL) { return RT_NULL; } handle = get_handle(nfs, path); - if(handle == RT_NULL) + if (handle == RT_NULL) { rt_free(dir); return RT_NULL; @@ -803,63 +822,63 @@ nfs_dir *nfs_opendir(struct nfs_filesystem* nfs, const char *path) xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)handle); rt_free(handle); - dir->cookie=0; + dir->cookie = 0; memset(&dir->cookieverf, '\0', sizeof(cookieverf3)); - dir->entry=RT_NULL; - dir->eof=FALSE; + dir->entry = RT_NULL; + dir->eof = FALSE; memset(&dir->res, '\0', sizeof(dir->res)); return dir; } -char *nfs_readdir(struct nfs_filesystem* nfs, nfs_dir *dir) +char *nfs_readdir(struct nfs_filesystem *nfs, nfs_dir *dir) { static char name[NAME_MAX]; - if(nfs->nfs_client==RT_NULL || dir == RT_NULL) + if (nfs->nfs_client == RT_NULL || dir == RT_NULL) return RT_NULL; - if(dir->entry==RT_NULL) + if (dir->entry == RT_NULL) { READDIR3args args; xdr_free((xdrproc_t)xdr_READDIR3res, (char *)&dir->res); memset(&dir->res, '\0', sizeof(dir->res)); - args.dir=dir->handle; - args.cookie=dir->cookie; + args.dir = dir->handle; + args.cookie = dir->cookie; memcpy(&args.cookieverf, &dir->cookieverf, sizeof(cookieverf3)); - args.count=1024; + args.count = 1024; - if(nfsproc3_readdir_3(args, &dir->res, nfs->nfs_client)!=RPC_SUCCESS) + if (nfsproc3_readdir_3(args, &dir->res, nfs->nfs_client) != RPC_SUCCESS) { rt_kprintf("Readdir failed\n"); return RT_NULL; } - else if(dir->res.status!=NFS3_OK) + else if (dir->res.status != NFS3_OK) { rt_kprintf("Readdir failed: %d\n", dir->res.status); return RT_NULL; } memcpy(&dir->cookieverf, &dir->res.READDIR3res_u.resok.cookieverf, sizeof(cookieverf3)); - dir->eof=dir->res.READDIR3res_u.resok.reply.eof; - dir->entry=dir->res.READDIR3res_u.resok.reply.entries; + dir->eof = dir->res.READDIR3res_u.resok.reply.eof; + dir->entry = dir->res.READDIR3res_u.resok.reply.entries; } - if(dir->eof==TRUE && dir->entry==RT_NULL) + if (dir->eof == TRUE && dir->entry == RT_NULL) return RT_NULL; - dir->cookie=dir->entry->cookie; + dir->cookie = dir->entry->cookie; strncpy(name, dir->entry->name, NAME_MAX-1); - dir->entry=dir->entry->nextentry; - name[NAME_MAX - 1]='\0'; + dir->entry = dir->entry->nextentry; + name[NAME_MAX - 1] = '\0'; return name; } -int nfs_unlink(struct dfs_filesystem* fs, const char* path) +int nfs_unlink(struct dfs_filesystem *fs, const char *path) { int ret = 0; - struct nfs_filesystem* nfs; + struct nfs_filesystem *nfs; RT_ASSERT(fs != RT_NULL); RT_ASSERT(fs->data != RT_NULL); @@ -873,26 +892,27 @@ int nfs_unlink(struct dfs_filesystem* fs, const char* path) nfs_fh3 *handle; handle = get_dir_handle(nfs, path); - if(handle == RT_NULL) return -1; + if (handle == RT_NULL) + return -1; - args.object.dir=*handle; - args.object.name=strrchr(path, '/') + 1; - if(args.object.name==RT_NULL) + args.object.dir = *handle; + args.object.name = strrchr(path, '/') + 1; + if (args.object.name == RT_NULL) { - args.object.name=(char *)path; + args.object.name = (char *)path; } memset(&res, 0, sizeof(res)); - if(nfsproc3_remove_3(args, &res, nfs->nfs_client)!=RPC_SUCCESS) + if (nfsproc3_remove_3(args, &res, nfs->nfs_client) != RPC_SUCCESS) { rt_kprintf("Remove failed\n"); - ret=-1; + ret = -1; } - else if(res.status!=NFS3_OK) + else if (res.status != NFS3_OK) { rt_kprintf("Remove failed: %d\n", res.status); - ret=-1; + ret = -1; } xdr_free((xdrproc_t)xdr_REMOVE3res, (char *)&res); xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)handle); @@ -905,24 +925,25 @@ int nfs_unlink(struct dfs_filesystem* fs, const char* path) RMDIR3res res; nfs_fh3 *handle; - handle=get_dir_handle(nfs, path); - if(handle==RT_NULL) return -1; + handle = get_dir_handle(nfs, path); + if (handle == RT_NULL) + return -1; - args.object.dir=*handle; - args.object.name=strrchr(path, '/') + 1; - if(args.object.name==RT_NULL) + args.object.dir = *handle; + args.object.name = strrchr(path, '/') + 1; + if (args.object.name == RT_NULL) { - args.object.name=(char *)path; + args.object.name = (char *)path; } memset(&res, 0, sizeof(res)); - if(nfsproc3_rmdir_3(args, &res, nfs->nfs_client)!=RPC_SUCCESS) + if (nfsproc3_rmdir_3(args, &res, nfs->nfs_client) != RPC_SUCCESS) { rt_kprintf("Rmdir failed\n"); ret = -1; } - else if(res.status!=NFS3_OK) + else if (res.status != NFS3_OK) { rt_kprintf("Rmdir failed: %d\n", res.status); ret = -1; @@ -936,48 +957,48 @@ int nfs_unlink(struct dfs_filesystem* fs, const char* path) return ret; } -int nfs_rename(struct dfs_filesystem* fs, const char *src, const char *dest) +int nfs_rename(struct dfs_filesystem *fs, const char *src, const char *dest) { RENAME3args args; RENAME3res res; nfs_fh3 *sHandle; nfs_fh3 *dHandle; - int ret=0; - struct nfs_filesystem* nfs; + int ret = 0; + struct nfs_filesystem *nfs; RT_ASSERT(fs != RT_NULL); RT_ASSERT(fs->data != RT_NULL); nfs = (struct nfs_filesystem *)fs->data; - if(nfs->nfs_client==RT_NULL) + if (nfs->nfs_client == RT_NULL) return -1; - sHandle=get_dir_handle(nfs, src); - if(sHandle==RT_NULL) + sHandle = get_dir_handle(nfs, src); + if (sHandle == RT_NULL) return -1; - dHandle=get_dir_handle(nfs, dest); - if(dHandle==RT_NULL) + dHandle = get_dir_handle(nfs, dest); + if (dHandle == RT_NULL) return -1; - args.from.dir=*sHandle; - args.from.name=strrchr(src, '/') + 1; - if(args.from.name==RT_NULL) - args.from.name=(char *)src; + args.from.dir = *sHandle; + args.from.name = strrchr(src, '/') + 1; + if (args.from.name == RT_NULL) + args.from.name = (char *)src; - args.to.dir=*dHandle; - args.to.name=strrchr(src, '/') + 1; - if(args.to.name==RT_NULL) - args.to.name=(char *)dest; + args.to.dir = *dHandle; + args.to.name = strrchr(src, '/') + 1; + if (args.to.name == RT_NULL) + args.to.name = (char *)dest; memset(&res, '\0', sizeof(res)); - if(nfsproc3_rename_3(args, &res, nfs->nfs_client)!=RPC_SUCCESS) + if (nfsproc3_rename_3(args, &res, nfs->nfs_client) != RPC_SUCCESS) { rt_kprintf("Rename failed\n"); ret = -1; } - else if(res.status!=NFS3_OK) + else if (res.status != NFS3_OK) { rt_kprintf("Rename failed: %d\n", res.status); ret = -1; @@ -989,12 +1010,12 @@ int nfs_rename(struct dfs_filesystem* fs, const char *src, const char *dest) return ret; } -int nfs_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t count) +int nfs_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint32_t count) { nfs_dir *dir; rt_uint32_t index; - struct dirent* d; - struct nfs_filesystem* nfs; + struct dirent *d; + struct nfs_filesystem *nfs; char *name; dir = (nfs_dir *)(file->data); @@ -1005,7 +1026,8 @@ int nfs_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t count) /* make integer count */ count = (count / sizeof(struct dirent)) * sizeof(struct dirent); - if ( count == 0 ) return -DFS_STATUS_EINVAL; + if (count == 0) + return -DFS_STATUS_EINVAL; index = 0; while (1) @@ -1015,7 +1037,8 @@ int nfs_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t count) d = dirp + index; name = nfs_readdir(nfs, dir); - if (name == RT_NULL) break; + if (name == RT_NULL) + break; d->d_type = DFS_DT_REG; @@ -1024,7 +1047,7 @@ int nfs_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t count) rt_strncpy(d->d_name, name, rt_strlen(name) + 1); index ++; - if ( index * sizeof(struct dirent) >= count ) + if (index * sizeof(struct dirent) >= count) break; } diff --git a/components/dfs/filesystems/nfs/dfs_nfs.h b/components/dfs/filesystems/nfs/dfs_nfs.h index 843b6b9ddc..d45af577de 100644 --- a/components/dfs/filesystems/nfs/dfs_nfs.h +++ b/components/dfs/filesystems/nfs/dfs_nfs.h @@ -1,3 +1,16 @@ +/* + * File : dfs_nfs.h + * This file is part of Device File System in RT-Thread RTOS + * COPYRIGHT (C) 2004-2011, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE. + * + * Change Logs: + * Date Author Notes + */ + #ifndef __NFS_H__ #define __NFS_H__ diff --git a/components/dfs/filesystems/romfs/dfs_romfs.c b/components/dfs/filesystems/romfs/dfs_romfs.c index b5effaf81c..760593b58c 100644 --- a/components/dfs/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/filesystems/romfs/dfs_romfs.c @@ -1,35 +1,49 @@ +/* + * File : dfs_romfs.c + * This file is part of Device File System in RT-Thread RTOS + * COPYRIGHT (C) 2004-2011, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE. + * + * Change Logs: + * Date Author Notes + */ + #include #include #include #include "dfs_romfs.h" -int dfs_romfs_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* data) +int dfs_romfs_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data) { - struct romfs_dirent* root_dirent; + struct romfs_dirent *root_dirent; - if (data == RT_NULL) return -DFS_STATUS_EIO; + if (data == RT_NULL) + return -DFS_STATUS_EIO; - root_dirent = (struct romfs_dirent*)data; + root_dirent = (struct romfs_dirent *)data; fs->data = root_dirent; return DFS_STATUS_OK; } -int dfs_romfs_unmount(struct dfs_filesystem* fs) +int dfs_romfs_unmount(struct dfs_filesystem *fs) { return DFS_STATUS_OK; } -int dfs_romfs_ioctl(struct dfs_fd* file, int cmd, void* args) +int dfs_romfs_ioctl(struct dfs_fd *file, int cmd, void *args) { return -DFS_STATUS_EIO; } -struct romfs_dirent* dfs_romfs_lookup(struct romfs_dirent* root_dirent, const char* path, rt_size_t *size) +struct romfs_dirent *dfs_romfs_lookup(struct romfs_dirent *root_dirent, const char *path, rt_size_t *size) { rt_size_t index, found; const char *subpath, *subpath_end; - struct romfs_dirent* dirent; + struct romfs_dirent *dirent; rt_size_t dirent_size; if (path[0] == '/' && path[1] == '\0') @@ -39,15 +53,17 @@ struct romfs_dirent* dfs_romfs_lookup(struct romfs_dirent* root_dirent, const ch } /* goto root directy entries */ - dirent = (struct romfs_dirent*)root_dirent->data; + dirent = (struct romfs_dirent *)root_dirent->data; dirent_size = root_dirent->size; /* get the end position of this subpath */ subpath_end = path; /* skip /// */ - while (*subpath_end && *subpath_end == '/') subpath_end ++; + while (*subpath_end && *subpath_end == '/') + subpath_end ++; subpath = subpath_end; - while ((*subpath_end != '/') && *subpath_end) subpath_end ++; + while ((*subpath_end != '/') && *subpath_end) + subpath_end ++; while (dirent != RT_NULL) { @@ -61,9 +77,11 @@ struct romfs_dirent* dfs_romfs_lookup(struct romfs_dirent* root_dirent, const ch dirent_size = dirent[index].size; /* skip /// */ - while (*subpath_end && *subpath_end == '/') subpath_end ++; + while (*subpath_end && *subpath_end == '/') + subpath_end ++; subpath = subpath_end; - while ((*subpath_end != '/') && *subpath_end) subpath_end ++; + while ((*subpath_end != '/') && *subpath_end) + subpath_end ++; if (!(*subpath)) { @@ -81,24 +99,26 @@ struct romfs_dirent* dfs_romfs_lookup(struct romfs_dirent* root_dirent, const ch else { /* return file dirent */ - if (subpath != RT_NULL) break; /* not the end of path */ + if (subpath != RT_NULL) + break; /* not the end of path */ return &dirent[index]; } } } - if (!found) break; /* not found */ + if (!found) + break; /* not found */ } /* not found */ return RT_NULL; } -int dfs_romfs_read(struct dfs_fd* file, void *buf, rt_size_t count) +int dfs_romfs_read(struct dfs_fd *file, void *buf, rt_size_t count) { rt_size_t length; - struct romfs_dirent* dirent; + struct romfs_dirent *dirent; dirent = (struct romfs_dirent *)file->data; RT_ASSERT(dirent != RT_NULL); @@ -117,7 +137,7 @@ int dfs_romfs_read(struct dfs_fd* file, void *buf, rt_size_t count) return length; } -int dfs_romfs_lseek(struct dfs_fd* file, rt_off_t offset) +int dfs_romfs_lseek(struct dfs_fd *file, rt_off_t offset) { if (offset <= file->size) { @@ -128,30 +148,31 @@ int dfs_romfs_lseek(struct dfs_fd* file, rt_off_t offset) return -DFS_STATUS_EIO; } -int dfs_romfs_close(struct dfs_fd* file) +int dfs_romfs_close(struct dfs_fd *file) { file->data = RT_NULL; return DFS_STATUS_OK; } -int dfs_romfs_open(struct dfs_fd* file) +int dfs_romfs_open(struct dfs_fd *file) { rt_size_t size; - struct romfs_dirent* dirent; - struct romfs_dirent* root_dirent; + struct romfs_dirent *dirent; + struct romfs_dirent *root_dirent; - root_dirent = (struct romfs_dirent*)file->fs->data; + root_dirent = (struct romfs_dirent *)file->fs->data; if (file->flags & (DFS_O_CREAT | DFS_O_WRONLY | DFS_O_APPEND | DFS_O_TRUNC | DFS_O_RDWR)) return -DFS_STATUS_EINVAL; dirent = dfs_romfs_lookup(root_dirent, file->path, &size); - if (dirent == RT_NULL) return -DFS_STATUS_ENOENT; + if (dirent == RT_NULL) + return -DFS_STATUS_ENOENT; /* entry is a directory file type */ if (dirent->type == ROMFS_DIRENT_DIR) { - if (!(file->flags & DFS_O_DIRECTORY) ) + if (!(file->flags & DFS_O_DIRECTORY)) return -DFS_STATUS_ENOENT; } else @@ -168,16 +189,17 @@ int dfs_romfs_open(struct dfs_fd* file) return DFS_STATUS_OK; } -int dfs_romfs_stat(struct dfs_filesystem* fs, const char *path, struct stat *st) +int dfs_romfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) { rt_size_t size; - struct romfs_dirent* dirent; - struct romfs_dirent* root_dirent; + struct romfs_dirent *dirent; + struct romfs_dirent *root_dirent; - root_dirent = (struct romfs_dirent*)fs->data; + root_dirent = (struct romfs_dirent *)fs->data; dirent = dfs_romfs_lookup(root_dirent, path, &size); - if (dirent == RT_NULL) return -DFS_STATUS_ENOENT; + if (dirent == RT_NULL) + return -DFS_STATUS_ENOENT; st->st_dev = 0; st->st_mode = DFS_S_IFREG | DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH | @@ -196,22 +218,23 @@ int dfs_romfs_stat(struct dfs_filesystem* fs, const char *path, struct stat *st) return DFS_STATUS_OK; } -int dfs_romfs_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t count) +int dfs_romfs_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint32_t count) { rt_size_t index; const char *name; - struct dirent* d; + struct dirent *d; struct romfs_dirent *dirent, *sub_dirent; - dirent = (struct romfs_dirent*) file->data; + dirent = (struct romfs_dirent *)file->data; RT_ASSERT(dirent->type == ROMFS_DIRENT_DIR); /* enter directory */ - dirent = (struct romfs_dirent*) dirent->data; + dirent = (struct romfs_dirent *)dirent->data; /* make integer count */ count = (count / sizeof(struct dirent)); - if ( count == 0 ) return -DFS_STATUS_EINVAL; + if (count == 0) + return -DFS_STATUS_EINVAL; index = 0; for (index = 0; index < count && file->pos < file->size; index ++) diff --git a/components/dfs/filesystems/romfs/dfs_romfs.h b/components/dfs/filesystems/romfs/dfs_romfs.h index 6a3f7ac1cc..3e0d7daf07 100644 --- a/components/dfs/filesystems/romfs/dfs_romfs.h +++ b/components/dfs/filesystems/romfs/dfs_romfs.h @@ -1,3 +1,16 @@ +/* + * File : dfs_romfs.h + * This file is part of Device File System in RT-Thread RTOS + * COPYRIGHT (C) 2004-2011, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE. + * + * Change Logs: + * Date Author Notes + */ + #ifndef __DFS_ROMFS_H__ #define __DFS_ROMFS_H__ -- cgit v1.3.1