diff --git a/components/dfs/Kconfig b/components/dfs/Kconfig index ec9985e21c..19c1327da6 100644 --- a/components/dfs/Kconfig +++ b/components/dfs/Kconfig @@ -157,6 +157,11 @@ if RT_USING_DFS endif + config RT_USING_DFS_JFFS2 + bool "Enable JFFS2 file system" + select RT_USING_MTD_NOR + default n + config RT_USING_DFS_NFS bool "Using NFS v3 client file system" select RT_USING_LWIP diff --git a/components/dfs/filesystems/jffs2/cyg/compress/src/zutil.h b/components/dfs/filesystems/jffs2/cyg/compress/src/zutil.h index a91c9a5eb7..013754a1f7 100644 --- a/components/dfs/filesystems/jffs2/cyg/compress/src/zutil.h +++ b/components/dfs/filesystems/jffs2/cyg/compress/src/zutil.h @@ -28,7 +28,7 @@ # include # endif # include -//# include //remove by prife @ 2012/1/30 +# include #endif #ifdef NO_ERRNO_H # ifdef _WIN32_WCE diff --git a/components/dfs/filesystems/jffs2/cyg/compress/zconf.h b/components/dfs/filesystems/jffs2/cyg/compress/zconf.h index 740a1e144b..dc360d8ff6 100644 --- a/components/dfs/filesystems/jffs2/cyg/compress/zconf.h +++ b/components/dfs/filesystems/jffs2/cyg/compress/zconf.h @@ -12,11 +12,16 @@ #undef __ECOS__ #define __ECOS__ #include -#define malloc rt_malloc -#define free rt_free -#define printf rt_kprintf + +#ifndef RT_USING_LIBC +#define malloc rt_malloc +#define free rt_free +#define printf rt_kprintf +#endif + //#define Z_PREFIX //by prife //#include //prife no such file. + #if CYGINT_COMPRESS_ZLIB_LOCAL_ALLOC != 0 #define MY_ZCALLOC #endif diff --git a/components/dfs/filesystems/jffs2/cyg/fileio/fileio.h b/components/dfs/filesystems/jffs2/cyg/fileio/fileio.h index 2e0ff17975..d364ae3b45 100644 --- a/components/dfs/filesystems/jffs2/cyg/fileio/fileio.h +++ b/components/dfs/filesystems/jffs2/cyg/fileio/fileio.h @@ -313,13 +313,13 @@ struct CYG_FILEOPS_TAG struct CYG_FILE_TAG { - cyg_uint32 f_flag; /* file state */ + cyg_uint32 f_flag; /* file state */ cyg_uint16 f_ucount; /* use count */ - cyg_uint16 f_type; /* descriptor type */ + cyg_uint16 f_type; /* descriptor type */ cyg_uint32 f_syncmode; /* synchronization protocol */ struct CYG_FILEOPS_TAG *f_ops; /* file operations */ - off_t f_offset; /* current offset */ - CYG_ADDRWORD f_data; /* file or socket */ + off_t f_offset; /* current offset */ + CYG_ADDRWORD f_data; /* file or socket */ CYG_ADDRWORD f_xops; /* extra type specific ops */ cyg_mtab_entry *f_mte; /* mount table entry */ }; diff --git a/components/dfs/filesystems/jffs2/dfs_jffs2.c b/components/dfs/filesystems/jffs2/dfs_jffs2.c index f2ffe471ed..17e84f94c0 100644 --- a/components/dfs/filesystems/jffs2/dfs_jffs2.c +++ b/components/dfs/filesystems/jffs2/dfs_jffs2.c @@ -1,16 +1,27 @@ /* - * File : rtthread.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006-2012, RT-Thread Development Team + * File : dfs_jffs2.c + * This file is part of Device File System in RT-Thread RTOS + * COPYRIGHT (C) 2006-2017, 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. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Change Logs: * Date Author Notes * 2012-1-7 prife the first version -*/ + */ + #include #include @@ -21,7 +32,7 @@ #undef mode_t #include -#include +#include #include "dfs_jffs2.h" #include "jffs2_config.h" @@ -29,51 +40,50 @@ #include #if DEVICE_PART_MAX > 1 - #error "support only one jffs2 partition on a flash device!" + #error "support only one jffs2 partition on a flash device!" #endif - + /* make sure the following struct var had been initilased to 0! */ -struct device_part +struct device_part { - struct cyg_mtab_entry * mte; - struct rt_mtd_nor_device *dev; + struct cyg_mtab_entry * mte; + struct rt_mtd_nor_device *dev; }; static struct device_part device_partition[DEVICE_PART_MAX] = {0}; - static struct rt_mutex jffs2_lock; -#define jffs2_mount jffs2_fste.mount -#define jffs2_umount jffs2_fste.umount -#define jffs2_open jffs2_fste.open -#define jffs2_file_unlink jffs2_fste.unlink -#define jffs2_mkdir jffs2_fste.mkdir -#define jffs2_rmdir jffs2_fste.rmdir -#define jffs2_rename jffs2_fste.rename -#define jffs2_link jffs2_fste.link -#define jffs2_opendir jffs2_fste.opendir -#define jffs2_chdir jffs2_fste.chdir -#define jffs2_ops_stat jffs2_fste.stat -#define jffs2_getinfo jffs2_fste.getinfo -#define jffs2_setinfo jffs2_fste.setinfo +#define jffs2_mount jffs2_fste.mount +#define jffs2_umount jffs2_fste.umount +#define jffs2_open jffs2_fste.open +#define jffs2_file_unlink jffs2_fste.unlink +#define jffs2_mkdir jffs2_fste.mkdir +#define jffs2_rmdir jffs2_fste.rmdir +#define jffs2_rename jffs2_fste.rename +#define jffs2_link jffs2_fste.link +#define jffs2_opendir jffs2_fste.opendir +#define jffs2_chdir jffs2_fste.chdir +#define jffs2_ops_stat jffs2_fste.stat +#define jffs2_getinfo jffs2_fste.getinfo +#define jffs2_setinfo jffs2_fste.setinfo -#define jffs2_file_read jffs2_fileops.fo_read -#define jffs2_file_write jffs2_fileops.fo_write -#define jffs2_file_lseek jffs2_fileops.fo_lseek -#define jffs2_file_ioctl jffs2_fileops.fo_ioctl -#define jffs2_file_select jffs2_fileops.fo_select -#define jffs2_file_fsync jffs2_fileops.fo_fsync -#define jffs2_file_colse jffs2_fileops.fo_close -#define jffs2_file_fstat jffs2_fileops.fo_fstat -#define jffs2_file_getinfo jffs2_fileops.fo_getinfo -#define jffs2_file_setinfo jffs2_fileops.fo_setinfo +#define jffs2_file_read jffs2_fileops.fo_read +#define jffs2_file_write jffs2_fileops.fo_write +#define jffs2_file_lseek jffs2_fileops.fo_lseek +#define jffs2_file_ioctl jffs2_fileops.fo_ioctl +#define jffs2_file_select jffs2_fileops.fo_select +#define jffs2_file_fsync jffs2_fileops.fo_fsync +#define jffs2_file_colse jffs2_fileops.fo_close +#define jffs2_file_fstat jffs2_fileops.fo_fstat +#define jffs2_file_getinfo jffs2_fileops.fo_getinfo +#define jffs2_file_setinfo jffs2_fileops.fo_setinfo -#define jffs2_dir_read jffs2_dirops.fo_read +#define jffs2_dir_read jffs2_dirops.fo_read //#define jffs2_dir_write jffs2_dirops.fo_write -#define jffs2_dir_lseek jffs2_dirops.fo_lseek +#define jffs2_dir_lseek jffs2_dirops.fo_lseek //#define jffs2_dir_ioctl jffs2_dirops.fo_ioctl -#define jffs2_dir_select jffs2_dirops.fo_select +#define jffs2_dir_select jffs2_dirops.fo_select //#define jffs2_dir_fsync jffs2_dirops.fo_fsync -#define jffs2_dir_colse jffs2_dirops.fo_close +#define jffs2_dir_colse jffs2_dirops.fo_close //#define jffs2_dir_fstat jffs2_dirops.fo_fstat //#define jffs2_dir_getinfo jffs2_dirops.fo_getinfo //#define jffs2_dir_setinfo jffs2_dirops.fo_setinfo @@ -82,649 +92,610 @@ static struct rt_mutex jffs2_lock; * RT-Thread Device Interface for jffs2 */ -/* these code is in src/flashio.c */ +/* these code is in src/flashio.c */ static int jffs2_result_to_dfs(int result) { - int status = -1; + if (result < 0) return result; + if (result > 0) return -result; - if (result < 0) - result = -result; - - switch (result) - { - case ENOERR:/** no error */ - break; - case EACCES:/** Tried to open read-only file for writing, or files sharing mode - does not allow specified operations, or given path is directory */ - status = -DFS_STATUS_EINVAL; - break;/* no suitable */ - case EEXIST: /** _O_CREAT and _O_EXCL flags specified, but filename already exists */ - status = -DFS_STATUS_EEXIST; - break; - case EINVAL: /** Invalid oflag or pmode argument */ - status = -DFS_STATUS_EINVAL; - break; - case EMFILE: /** No more file handles available(too many open files) */ - rt_kprintf("dfs_jffs2.c error: no more file handles available\r\n"); - status = -1; - break;//fixme - case ENOENT: /** file or path not found */ - status = -DFS_STATUS_ENOENT; - break; - case EBADF: /** invalid file handle */ - status = -DFS_STATUS_EBADF; - break; - case ENOMEM:/** no enough memory */ - status = -DFS_STATUS_ENOMEM; - break; - case EIO: /** I/O error from lower level flash operation */ - status = -DFS_STATUS_EIO; - break; - case ENOTDIR: /** Not a directory */ - status = -DFS_STATUS_ENOTDIR; - break; - case EISDIR: /** Is a directory */ - status = -DFS_STATUS_EISDIR; - break; - case ENOSPC: /**//* No space left on device */ - status = -DFS_STATUS_ENOSPC; - break; - - default: - rt_kprintf("dfs_jffs2.c error: %d\r\n", result); - status = -1; - break; /* unknown error! */ - } - - return status; + return 0; } /* * RT-Thread DFS Interface for jffs2 */ -static int dfs_jffs2_mount(struct dfs_filesystem* fs, - unsigned long rwflag, - const void* data) +static int dfs_jffs2_mount(struct dfs_filesystem* fs, + unsigned long rwflag, + const void* data) { - unsigned index; - struct cyg_mtab_entry * mte; - int result; + unsigned index; + struct cyg_mtab_entry * mte; + int result; - /* find a empty entry in partition table */ - for (index = 0; index < DEVICE_PART_MAX; index ++) - { - if (device_partition[index].dev == RT_NULL) - break; - } - if (index == DEVICE_PART_MAX) - return -DFS_STATUS_ENOSPC; + /* find a empty entry in partition table */ + for (index = 0; index < DEVICE_PART_MAX; index ++) + { + if (device_partition[index].dev == RT_NULL) + break; + } + if (index == DEVICE_PART_MAX) + return -ENOSPC; - mte = rt_malloc(sizeof(struct cyg_mtab_entry)); - if (mte == RT_NULL) - return -DFS_STATUS_ENOMEM; + mte = rt_malloc(sizeof(struct cyg_mtab_entry)); + if (mte == RT_NULL) + return -ENOMEM; - mte->name = fs->path; - mte->fsname = "jffs2"; - mte->devname = NULL; - /* note that, i use mte->data to store rtt's device - * while, in jffs2_mount, mte->data will be copy into - * s_dev in struct super_block, and mte->data will be - * filled with jffs2_sb(see the source of jffs2_mount. - */ - mte->data = (CYG_ADDRWORD)fs->dev_id; + mte->name = fs->path; + mte->fsname = "jffs2"; + mte->devname = NULL; + /* note that, i use mte->data to store rtt's device + * while, in jffs2_mount, mte->data will be copy into + * s_dev in struct super_block, and mte->data will be + * filled with jffs2_sb(see the source of jffs2_mount. + */ + mte->data = (CYG_ADDRWORD)fs->dev_id; - device_partition[index].dev = RT_MTD_NOR_DEVICE(fs->dev_id); - /* after jffs2_mount, mte->data will not be dev_id any more */ - result = jffs2_mount(NULL, mte); - if (result != 0) - { - device_partition[index].dev = NULL; - return jffs2_result_to_dfs(result); - } - /* save this pointer */ - device_partition[index].mte = mte; - return 0; + device_partition[index].dev = RT_MTD_NOR_DEVICE(fs->dev_id); + /* after jffs2_mount, mte->data will not be dev_id any more */ + result = jffs2_mount(NULL, mte); + if (result != 0) + { + device_partition[index].dev = NULL; + return jffs2_result_to_dfs(result); + } + + /* save this pointer */ + device_partition[index].mte = mte; + return 0; } static int _find_fs(struct cyg_mtab_entry ** mte, rt_device_t dev_id) { - unsigned index; - /* find device index */ - for (index = 0; index < DEVICE_PART_MAX; index++) - { - if (device_partition[index].dev == RT_MTD_NOR_DEVICE(dev_id)) - { - *mte = device_partition[index].mte; - return 0; - } - } - rt_kprintf("error, could not found the fs!"); - return -1; + unsigned index; + + /* find device index */ + for (index = 0; index < DEVICE_PART_MAX; index++) + { + if (device_partition[index].dev == RT_MTD_NOR_DEVICE(dev_id)) + { + *mte = device_partition[index].mte; + return 0; + } + } + + rt_kprintf("error, could not found the fs!"); + return -1; } static int dfs_jffs2_unmount(struct dfs_filesystem* fs) { - int result; - unsigned index; - /* find device index, then umount it */ - for (index = 0; index < DEVICE_PART_MAX; index++) - { - if (device_partition[index].dev == RT_MTD_NOR_DEVICE(fs->dev_id)) - { - result = jffs2_umount(device_partition[index].mte); - if (result) - return jffs2_result_to_dfs(result); - rt_free(device_partition[index].mte); - device_partition[index].dev = NULL; - device_partition[index].mte = NULL; - return DFS_STATUS_OK; - } - } - return -DFS_STATUS_ENOENT; + int result; + unsigned index; + + /* find device index, then umount it */ + for (index = 0; index < DEVICE_PART_MAX; index++) + { + if (device_partition[index].dev == RT_MTD_NOR_DEVICE(fs->dev_id)) + { + result = jffs2_umount(device_partition[index].mte); + if (result) return jffs2_result_to_dfs(result); + + rt_free(device_partition[index].mte); + device_partition[index].dev = NULL; + device_partition[index].mte = NULL; + return RT_EOK; + } + } + + return -ENOENT; } static int dfs_jffs2_mkfs(rt_device_t dev_id) { - /* just erase all blocks on this nand partition */ - return -DFS_STATUS_ENOSYS; + /* just erase all blocks on this nand partition */ + return -ENOSYS; } -static int dfs_jffs2_statfs(struct dfs_filesystem* fs, +static int dfs_jffs2_statfs(struct dfs_filesystem* fs, struct statfs *buf) { - /* since the limit of unsigned long, so the max size of flash device is 4G */ - struct cyg_mtab_entry * mte; - struct jffs2_fs_info info; - int result; - - result = _find_fs(&mte, fs->dev_id); - if (result) - return -DFS_STATUS_ENOENT; - - RT_ASSERT(mte->data != NULL); + /* since the limit of unsigned long, so the max size of flash device is 4G */ + struct cyg_mtab_entry * mte; + struct jffs2_fs_info info; + int result; - jffs2_get_info_from_sb((void *)mte->data, &info); - buf->f_bsize = info.sector_size; - buf->f_blocks = info.nr_blocks; - buf->f_bfree = info.free_size / info.sector_size; - - return 0; + result = _find_fs(&mte, fs->dev_id); + if (result) + return -ENOENT; + + RT_ASSERT(mte->data != 0); + + jffs2_get_info_from_sb((void *)mte->data, &info); + buf->f_bsize = info.sector_size; + buf->f_blocks = info.nr_blocks; + buf->f_bfree = info.free_size / info.sector_size; + + return 0; } static const char jffs2_root_path[] = "."; static int dfs_jffs2_open(struct dfs_fd* file) { - int oflag, mode; - int result; - cyg_file * jffs2_file; - struct cyg_mtab_entry * mte; - const char * name; + int result; + int oflag, mode; + const char * name; + cyg_file * jffs2_file; + struct dfs_filesystem *fs; + struct cyg_mtab_entry * mte; - oflag = file->flags; + oflag = file->flags; + fs = (struct dfs_filesystem *)file->data; + RT_ASSERT(fs != RT_NULL); - jffs2_file = rt_malloc(sizeof(cyg_file)); - if (jffs2_file == RT_NULL) - return -DFS_STATUS_ENOMEM; + jffs2_file = rt_malloc(sizeof(cyg_file)); + if (jffs2_file == RT_NULL) + return -ENOMEM; - /* just escape '/' provided by dfs code */ - name = file->path; - if ((name[0] == '/') && (name[1] == 0)) - name = jffs2_root_path; - else /* name[0] still will be '/' */ - name ++; - - result = _find_fs(&mte, file->fs->dev_id); - if (result) - { - rt_free(jffs2_file); - return -DFS_STATUS_ENOENT; - } - - if (oflag & DFS_O_DIRECTORY) /* operations about dir */ - { - rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); - if (oflag & DFS_O_CREAT) /* create a dir*/ - { - /* fixme, should test file->path can end with '/' */ - result = jffs2_mkdir(mte, mte->root, name); - if (result) - { - rt_mutex_release(&jffs2_lock); - rt_free(jffs2_file); - return jffs2_result_to_dfs(result); - } - } - /* open dir */ - result = jffs2_opendir(mte, mte->root, name, jffs2_file); - rt_mutex_release(&jffs2_lock); - if (result) - { - rt_free(jffs2_file); - return jffs2_result_to_dfs(result); - } + /* just escape '/' provided by dfs code */ + name = file->path; + if ((name[0] == '/') && (name[1] == 0)) + name = jffs2_root_path; + else /* name[0] still will be '/' */ + name ++; + + result = _find_fs(&mte, fs->dev_id); + if (result) + { + rt_free(jffs2_file); + return -ENOENT; + } + + /* set mount table */ + jffs2_file->f_mte = mte; + + if (oflag & O_DIRECTORY) /* operations about dir */ + { + rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); + if (oflag & O_CREAT) /* create a dir*/ + { + /* fixme, should test file->path can end with '/' */ + result = jffs2_mkdir(mte, mte->root, name); + if (result) + { + rt_mutex_release(&jffs2_lock); + rt_free(jffs2_file); + return jffs2_result_to_dfs(result); + } + } + + /* open dir */ + result = jffs2_opendir(mte, mte->root, name, jffs2_file); + rt_mutex_release(&jffs2_lock); + if (result) + { + rt_free(jffs2_file); + return jffs2_result_to_dfs(result); + } #ifdef CONFIG_JFFS2_NO_RELATIVEDIR - jffs2_file->f_offset = 2; + jffs2_file->f_offset = 2; #endif - /* save this pointer, it will be used by dfs_jffs2_getdents*/ - file->data = jffs2_file; - return 0; - } - /* regular file operations */ - mode = 0; - if (oflag & DFS_O_RDONLY) mode |= JFFS2_O_RDONLY; - if (oflag & DFS_O_WRONLY) mode |= JFFS2_O_WRONLY; - if (oflag & DFS_O_RDWR) mode |= JFFS2_O_RDWR; - /* Opens the file, if it is existing. If not, a new file is created. */ - if (oflag & DFS_O_CREAT) mode |= JFFS2_O_CREAT; - /* Creates a new file. If the file is existing, it is truncated and overwritten. */ - if (oflag & DFS_O_TRUNC) mode |= JFFS2_O_TRUNC; - /* Creates a new file. The function fails if the file is already existing. */ - if (oflag & DFS_O_EXCL) mode |= JFFS2_O_EXCL; -// if (oflag & DFS_O_APPEND) mode |= JFFS2_O_APPEND; - rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); + /* save this pointer, it will be used by dfs_jffs2_getdents*/ + file->data = jffs2_file; + return 0; + } + /* regular file operations */ + mode = JFFS2_O_RDONLY; + if (oflag & O_WRONLY) mode |= JFFS2_O_WRONLY; + if (oflag & O_RDWR) mode |= JFFS2_O_RDWR; + /* Opens the file, if it is existing. If not, a new file is created. */ + if (oflag & O_CREAT) mode |= JFFS2_O_CREAT; + /* Creates a new file. If the file is existing, it is truncated and overwritten. */ + if (oflag & O_TRUNC) mode |= JFFS2_O_TRUNC; + /* Creates a new file. The function fails if the file is already existing. */ + if (oflag & O_EXCL) mode |= JFFS2_O_EXCL; + + rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); result = jffs2_open(mte, 0, name, mode, jffs2_file); if (result != 0) { - rt_mutex_release(&jffs2_lock); - rt_free(jffs2_file); - return jffs2_result_to_dfs(result); + rt_mutex_release(&jffs2_lock); + rt_free(jffs2_file); + return jffs2_result_to_dfs(result); } - - /* save this pointer, it will be used when calling read()��write(), - flush(), lessk(), and will be rt_free when calling close()*/ - file->data = jffs2_file; - file->pos = jffs2_file->f_offset; - file->size = 0; - jffs2_file_lseek(jffs2_file, (off_t *)(&(file->size)), DFS_SEEK_END); - jffs2_file->f_offset = (off_t)file->pos; - rt_mutex_release(&jffs2_lock); - - if (oflag & DFS_O_APPEND) - { - file->pos = file->size; - jffs2_file->f_offset = file->size; - } - return 0; -} + + /* save this pointer, it will be used when calling read()��write(), + flush(), lessk(), and will be rt_free when calling close()*/ + file->data = jffs2_file; + file->pos = jffs2_file->f_offset; + file->size = 0; + jffs2_file_lseek(jffs2_file, (off_t *)(&(file->size)), SEEK_END); + jffs2_file->f_offset = (off_t)file->pos; + rt_mutex_release(&jffs2_lock); + + if (oflag & O_APPEND) + { + file->pos = file->size; + jffs2_file->f_offset = file->size; + } + + return 0; +} static int dfs_jffs2_close(struct dfs_fd* file) { - int result; - cyg_file * jffs2_file; - - RT_ASSERT(file->data != NULL); - jffs2_file = (cyg_file *)(file->data); - - if (file->flags & DFS_O_DIRECTORY) /* operations about dir */ - { - rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); - result = jffs2_dir_colse(jffs2_file); - rt_mutex_release(&jffs2_lock); - if (result) - return jffs2_result_to_dfs(result); + int result; + cyg_file * jffs2_file; - rt_free(jffs2_file); - return 0; - } - /* regular file operations */ - rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); - result = jffs2_file_colse(jffs2_file); - rt_mutex_release(&jffs2_lock); - if (result) - return jffs2_result_to_dfs(result); - - /* release memory */ - rt_free(jffs2_file); - return 0; + RT_ASSERT(file->data != NULL); + jffs2_file = (cyg_file *)(file->data); + + if (file->flags & O_DIRECTORY) /* operations about dir */ + { + rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); + result = jffs2_dir_colse(jffs2_file); + rt_mutex_release(&jffs2_lock); + if (result) + return jffs2_result_to_dfs(result); + + rt_free(jffs2_file); + return 0; + } + /* regular file operations */ + rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); + result = jffs2_file_colse(jffs2_file); + rt_mutex_release(&jffs2_lock); + if (result) + return jffs2_result_to_dfs(result); + + /* release memory */ + rt_free(jffs2_file); + return 0; } static int dfs_jffs2_ioctl(struct dfs_fd* file, int cmd, void* args) { - return -DFS_STATUS_ENOSYS; + return -ENOSYS; } -static int dfs_jffs2_read(struct dfs_fd* file, void* buf, rt_size_t len) +static int dfs_jffs2_read(struct dfs_fd* file, void* buf, size_t len) { - cyg_file * jffs2_file; - struct CYG_UIO_TAG uio_s; - struct CYG_IOVEC_TAG iovec; - int char_read; - int result; - - RT_ASSERT(file->data != NULL); - jffs2_file = (cyg_file *)(file->data); + cyg_file * jffs2_file; + struct CYG_UIO_TAG uio_s; + struct CYG_IOVEC_TAG iovec; + int char_read; + int result; + + RT_ASSERT(file->data != NULL); + jffs2_file = (cyg_file *)(file->data); uio_s.uio_iov = &iovec; uio_s.uio_iov->iov_base = buf; uio_s.uio_iov->iov_len = len; uio_s.uio_iovcnt = 1; //must be 1 //uio_s.uio_offset //not used... uio_s.uio_resid = uio_s.uio_iov->iov_len; //seem no use in jffs2; - - char_read = jffs2_file->f_offset; /* the current offset */ - rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); - result = jffs2_file_read(jffs2_file, &uio_s); - rt_mutex_release(&jffs2_lock); - if (result) - return jffs2_result_to_dfs(result); - - /* update position */ - file->pos = jffs2_file->f_offset; - char_read = jffs2_file->f_offset - char_read; - return char_read; + + char_read = jffs2_file->f_offset; /* the current offset */ + rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); + result = jffs2_file_read(jffs2_file, &uio_s); + rt_mutex_release(&jffs2_lock); + if (result) + return jffs2_result_to_dfs(result); + + /* update position */ + file->pos = jffs2_file->f_offset; + char_read = jffs2_file->f_offset - char_read; + return char_read; } -static int dfs_jffs2_write(struct dfs_fd* file, - const void* buf, - rt_size_t len) +static int dfs_jffs2_write(struct dfs_fd* file, + const void* buf, + size_t len) { - cyg_file * jffs2_file; - struct CYG_UIO_TAG uio_s; - struct CYG_IOVEC_TAG iovec; - int char_write; - int result; - - RT_ASSERT(file->data != NULL); - jffs2_file = (cyg_file *)(file->data); + cyg_file * jffs2_file; + struct CYG_UIO_TAG uio_s; + struct CYG_IOVEC_TAG iovec; + int char_write; + int result; + + RT_ASSERT(file->data != NULL); + jffs2_file = (cyg_file *)(file->data); uio_s.uio_iov = &iovec; uio_s.uio_iov->iov_base = (void *)buf; uio_s.uio_iov->iov_len = len; uio_s.uio_iovcnt = 1; //must be 1 //uio_s.uio_offset //not used... uio_s.uio_resid = uio_s.uio_iov->iov_len; //seem no use in jffs2; - - char_write = jffs2_file->f_offset; - rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); - result = jffs2_file_write(jffs2_file, &uio_s); - rt_mutex_release(&jffs2_lock); - if (result) - return jffs2_result_to_dfs(result); - - /* update position */ - file->pos = jffs2_file->f_offset; - char_write = jffs2_file->f_offset - char_write; - return char_write; + + char_write = jffs2_file->f_offset; + rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); + result = jffs2_file_write(jffs2_file, &uio_s); + rt_mutex_release(&jffs2_lock); + if (result) + return jffs2_result_to_dfs(result); + + /* update position */ + file->pos = jffs2_file->f_offset; + char_write = jffs2_file->f_offset - char_write; + return char_write; } static int dfs_jffs2_flush(struct dfs_fd* file) { - /* infact, jffs2 not support, jffs2_fo_sync just return ok */ - return -DFS_STATUS_ENOSYS; + /* infact, jffs2 not support, jffs2_fo_sync just return ok */ + return -ENOSYS; } /* fixme warning: the offset is rt_off_t, so maybe the size of a file is must <= 2G*/ -static int dfs_jffs2_lseek(struct dfs_fd* file, +static int dfs_jffs2_lseek(struct dfs_fd* file, rt_off_t offset) { - cyg_file * jffs2_file; - int result; - - RT_ASSERT(file->data != NULL); - jffs2_file = (cyg_file *)(file->data); - - /* set offset as current offset */ - rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); - result = jffs2_file_lseek(jffs2_file, &offset, DFS_SEEK_SET); - rt_mutex_release(&jffs2_lock); - if (result) - return jffs2_result_to_dfs(result); - /* update file position */ - file->pos = offset; - return offset; + cyg_file * jffs2_file; + int result; + + RT_ASSERT(file->data != NULL); + jffs2_file = (cyg_file *)(file->data); + + /* set offset as current offset */ + rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); + result = jffs2_file_lseek(jffs2_file, &offset, SEEK_SET); + rt_mutex_release(&jffs2_lock); + if (result) + return jffs2_result_to_dfs(result); + /* update file position */ + file->pos = offset; + return offset; } /* return the size of struct dirent*/ -static int dfs_jffs2_getdents(struct dfs_fd* file, - struct dirent* dirp, - rt_uint32_t count) +static int dfs_jffs2_getdents(struct dfs_fd* file, + struct dirent* dirp, + rt_uint32_t count) { - cyg_file * jffs2_file; - struct CYG_UIO_TAG uio_s; - struct CYG_IOVEC_TAG iovec; - struct jffs2_dirent jffs2_d; - struct dirent * d; - rt_uint32_t index; + cyg_file * jffs2_file; + struct CYG_UIO_TAG uio_s; + struct CYG_IOVEC_TAG iovec; + struct jffs2_dirent jffs2_d; + struct dirent * d; + rt_uint32_t index; #if !defined (CYGPKG_FS_JFFS2_RET_DIRENT_DTYPE) - struct jffs2_stat s; - cyg_mtab_entry * mte; - char * fullname; + struct jffs2_stat s; + cyg_mtab_entry * mte; + char * fullname; #endif - int result; - - RT_ASSERT(file->data != RT_NULL); - jffs2_file = (cyg_file*)(file->data); - - //set jffs2_d - memset(&jffs2_d, 0, sizeof(struct jffs2_dirent)); - //set CYG_UIO_TAG uio_s - uio_s.uio_iov = &iovec; - uio_s.uio_iov->iov_base = &jffs2_d; - uio_s.uio_iov->iov_len = sizeof(struct jffs2_dirent);; - uio_s.uio_iovcnt = 1; //must be 1 - uio_s.uio_offset = 0;//not used... - uio_s.uio_resid = uio_s.uio_iov->iov_len; //seem no use in jffs2; + int result; -#if !defined (CYGPKG_FS_JFFS2_RET_DIRENT_DTYPE) + RT_ASSERT(file->data != RT_NULL); + jffs2_file = (cyg_file*)(file->data); + mte = jffs2_file->f_mte; - result = _find_fs(&mte, file->fs->dev_id); - if (result) - return -DFS_STATUS_ENOENT; -#endif + //set jffs2_d + memset(&jffs2_d, 0, sizeof(struct jffs2_dirent)); + //set CYG_UIO_TAG uio_s + uio_s.uio_iov = &iovec; + uio_s.uio_iov->iov_base = &jffs2_d; + uio_s.uio_iov->iov_len = sizeof(struct jffs2_dirent);; + uio_s.uio_iovcnt = 1; //must be 1 + uio_s.uio_offset = 0;//not used... + uio_s.uio_resid = uio_s.uio_iov->iov_len; //seem no use in jffs2; - /* make integer count, usually count is 1 */ - count = (count / sizeof(struct dirent)) * sizeof(struct dirent); - if (count == 0) - return -DFS_STATUS_EINVAL; + /* make integer count, usually count is 1 */ + count = (count / sizeof(struct dirent)) * sizeof(struct dirent); + if (count == 0) return -EINVAL; - index = 0; - /* usually, the while loop should only be looped only once! */ - while (1) - { - d = dirp + index; - rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); - result = jffs2_dir_read(jffs2_file, &uio_s); - rt_mutex_release(&jffs2_lock); - /* if met a error or all entry are read over, break while*/ - if (result || jffs2_d.d_name[0] == 0) - break; + index = 0; + /* usually, the while loop should only be looped only once! */ + while (1) + { + d = dirp + index; + rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); + result = jffs2_dir_read(jffs2_file, &uio_s); + rt_mutex_release(&jffs2_lock); + /* if met a error or all entry are read over, break while*/ + if (result || jffs2_d.d_name[0] == 0) + break; #if defined (CYGPKG_FS_JFFS2_RET_DIRENT_DTYPE) - switch(jffs2_d.d_type & JFFS2_S_IFMT) - { - case JFFS2_S_IFREG: d->d_type = DFS_DT_REG; break; - case JFFS2_S_IFDIR: d->d_type = DFS_DT_DIR; break; - default: d->d_type = DFS_DT_UNKNOWN; break; - } + switch(jffs2_d.d_type & JFFS2_S_IFMT) + { + case JFFS2_S_IFREG: d->d_type = DT_REG; break; + case JFFS2_S_IFDIR: d->d_type = DT_DIR; break; + default: d->d_type = DT_UNKNOWN; break; + } #else - fullname = rt_malloc(FILE_PATH_MAX); - if(fullname == RT_NULL) - return -DFS_STATUS_ENOMEM; + fullname = rt_malloc(FILE_PATH_MAX); + if(fullname == RT_NULL) + return -ENOMEM; - /* make a right entry */ - if ((file->path[0] == '/') ) - { - if (file->path[1] == 0) - strcpy(fullname, jffs2_d.d_name); - else - rt_sprintf(fullname, "%s/%s", file->path+1, jffs2_d.d_name); - } - else - rt_sprintf(fullname, "%s/%s", file->path, jffs2_d.d_name); - rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); - result = jffs2_porting_stat(mte, mte->root, fullname, (void *)&s); - rt_mutex_release(&jffs2_lock); - if (result) - return jffs2_result_to_dfs(result); + /* make a right entry */ + if ((file->path[0] == '/') ) + { + if (file->path[1] == 0) + strcpy(fullname, jffs2_d.d_name); + else + rt_sprintf(fullname, "%s/%s", file->path+1, jffs2_d.d_name); + } + else + rt_sprintf(fullname, "%s/%s", file->path, jffs2_d.d_name); + rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); + result = jffs2_porting_stat(mte, mte->root, fullname, (void *)&s); + rt_mutex_release(&jffs2_lock); + if (result) + return jffs2_result_to_dfs(result); - rt_free(fullname); - /* convert to dfs stat structure */ - switch(s.st_mode & JFFS2_S_IFMT) - { - case JFFS2_S_IFREG: d->d_type = DFS_DT_REG; break; - case JFFS2_S_IFDIR: d->d_type = DFS_DT_DIR; break; - default: d->d_type = DFS_DT_UNKNOWN; break; - } + rt_free(fullname); + /* convert to dfs stat structure */ + switch(s.st_mode & JFFS2_S_IFMT) + { + case JFFS2_S_IFREG: d->d_type = DT_REG; break; + case JFFS2_S_IFDIR: d->d_type = DT_DIR; break; + default: d->d_type = DT_UNKNOWN; break; + } #endif - /* write the rest fields of struct dirent* dirp */ - d->d_namlen = rt_strlen(jffs2_d.d_name); - d->d_reclen = (rt_uint16_t)sizeof(struct dirent); - rt_strncpy(d->d_name, jffs2_d.d_name, d->d_namlen + 1); - - index ++; - if (index * sizeof(struct dirent) >= count) - break; - } - if (result) - return jffs2_result_to_dfs(result); - return index * sizeof(struct dirent); + /* write the rest fields of struct dirent* dirp */ + d->d_namlen = rt_strlen(jffs2_d.d_name); + d->d_reclen = (rt_uint16_t)sizeof(struct dirent); + rt_strncpy(d->d_name, jffs2_d.d_name, d->d_namlen + 1); + + index ++; + if (index * sizeof(struct dirent) >= count) + break; + } + if (result) + return jffs2_result_to_dfs(result); + return index * sizeof(struct dirent); } static int dfs_jffs2_unlink(struct dfs_filesystem* fs, const char* path) { - int result; - struct jffs2_stat s; - cyg_mtab_entry * mte; - - result = _find_fs(&mte, fs->dev_id); - if (result) - return -DFS_STATUS_ENOENT; - - /* deal path */ - if (path[0] == '/') - path++; - - /* judge file type, dir is to be delete by rmdir, others by unlink */ - rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); - result = jffs2_porting_stat(mte, mte->root, path, (void *)&s); - if (result) - { - rt_mutex_release(&jffs2_lock); - return jffs2_result_to_dfs(result); - } + int result; + struct jffs2_stat s; + cyg_mtab_entry * mte; - switch(s.st_mode & JFFS2_S_IFMT) - { - case JFFS2_S_IFREG: - result = jffs2_file_unlink(mte, mte->root, path); - break; - case JFFS2_S_IFDIR: - result = jffs2_rmdir(mte, mte->root, path); - break; - default: - /* unknown file type */ - rt_mutex_release(&jffs2_lock); - return -1; - } - rt_mutex_release(&jffs2_lock); - if (result) - return jffs2_result_to_dfs(result); - return 0; + result = _find_fs(&mte, fs->dev_id); + if (result) + return -ENOENT; + + /* deal path */ + if (path[0] == '/') + path++; + + /* judge file type, dir is to be delete by rmdir, others by unlink */ + rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); + result = jffs2_porting_stat(mte, mte->root, path, (void *)&s); + if (result) + { + rt_mutex_release(&jffs2_lock); + return jffs2_result_to_dfs(result); + } + + switch(s.st_mode & JFFS2_S_IFMT) + { + case JFFS2_S_IFREG: + result = jffs2_file_unlink(mte, mte->root, path); + break; + case JFFS2_S_IFDIR: + result = jffs2_rmdir(mte, mte->root, path); + break; + default: + /* unknown file type */ + rt_mutex_release(&jffs2_lock); + return -1; + } + rt_mutex_release(&jffs2_lock); + if (result) + return jffs2_result_to_dfs(result); + return 0; } -static int dfs_jffs2_rename(struct dfs_filesystem* fs, +static int dfs_jffs2_rename(struct dfs_filesystem* fs, const char* oldpath, - const char* newpath) + const char* newpath) { - int result; - cyg_mtab_entry * mte; - - result = _find_fs(&mte, fs->dev_id); - if (result) - return -DFS_STATUS_ENOENT; - - if (*oldpath == '/') - oldpath += 1; - if (*newpath == '/') - newpath += 1; - rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); - result = jffs2_rename(mte, mte->root, oldpath, mte->root, newpath); - rt_mutex_release(&jffs2_lock); - if (result) - return jffs2_result_to_dfs(result); - return 0; + int result; + cyg_mtab_entry * mte; + + result = _find_fs(&mte, fs->dev_id); + if (result) + return -ENOENT; + + if (*oldpath == '/') + oldpath += 1; + if (*newpath == '/') + newpath += 1; + rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); + result = jffs2_rename(mte, mte->root, oldpath, mte->root, newpath); + rt_mutex_release(&jffs2_lock); + if (result) + return jffs2_result_to_dfs(result); + return 0; } static int dfs_jffs2_stat(struct dfs_filesystem* fs, const char *path, struct stat *st) { - int result; - struct jffs2_stat s; - cyg_mtab_entry * mte; - - /* deal the path for jffs2 */ - RT_ASSERT(!((path[0] == '/') && (path[1] == 0))); - - if (path[0] == '/') - path++; + int result; + struct jffs2_stat s; + cyg_mtab_entry * mte; - result = _find_fs(&mte, fs->dev_id); - if (result) - return -DFS_STATUS_ENOENT; + /* deal the path for jffs2 */ + RT_ASSERT(!((path[0] == '/') && (path[1] == 0))); - rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); - result = jffs2_porting_stat(mte, mte->root, path, (void *)&s); - rt_mutex_release(&jffs2_lock); + if (path[0] == '/') + path++; - if (result) - return jffs2_result_to_dfs(result); - /* convert to dfs stat structure */ - switch(s.st_mode & JFFS2_S_IFMT) - { - case JFFS2_S_IFREG: - st->st_mode = DFS_S_IFREG | DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH | - DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH; - break; + result = _find_fs(&mte, fs->dev_id); + if (result) + return -ENOENT; - case JFFS2_S_IFDIR: - st->st_mode = DFS_S_IFDIR | DFS_S_IXUSR | DFS_S_IXGRP | DFS_S_IXOTH; - break; + rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER); + result = jffs2_porting_stat(mte, mte->root, path, (void *)&s); + rt_mutex_release(&jffs2_lock); - default: - st->st_mode = DFS_DT_UNKNOWN; //fixme - break; - } + if (result) + return jffs2_result_to_dfs(result); + /* convert to dfs stat structure */ + switch(s.st_mode & JFFS2_S_IFMT) + { + case JFFS2_S_IFREG: + st->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH | + S_IWUSR | S_IWGRP | S_IWOTH; + break; - st->st_dev = 0; - st->st_size = s.st_size; - st->st_mtime = s.st_mtime; + case JFFS2_S_IFDIR: + st->st_mode = S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; + break; - return 0; + default: + st->st_mode = DT_UNKNOWN; //fixme + break; + } + + st->st_dev = 0; + st->st_size = s.st_size; + st->st_mtime = s.st_mtime; + + return 0; } -static const struct dfs_filesystem_operation dfs_jffs2_ops = +static const struct dfs_file_ops _jffs2_fops = { - "jffs2", /* file system type: jffs2 */ -#if RTTHREAD_VERSION >= 10100 - DFS_FS_FLAG_DEFAULT, /* use Relative Path */ -#endif - dfs_jffs2_mount, - dfs_jffs2_unmount, - dfs_jffs2_mkfs, - dfs_jffs2_statfs, + dfs_jffs2_open, + dfs_jffs2_close, + dfs_jffs2_ioctl, + dfs_jffs2_read, + dfs_jffs2_write, + dfs_jffs2_flush, + dfs_jffs2_lseek, + dfs_jffs2_getdents, +}; - dfs_jffs2_open, - dfs_jffs2_close, - dfs_jffs2_ioctl, - dfs_jffs2_read, - dfs_jffs2_write, - dfs_jffs2_flush, - dfs_jffs2_lseek, - dfs_jffs2_getdents, - dfs_jffs2_unlink, - dfs_jffs2_stat, - dfs_jffs2_rename, +static const struct dfs_filesystem_ops _jffs2_ops = +{ + "jffs2", + DFS_FS_FLAG_DEFAULT, + &_jffs2_fops, + + dfs_jffs2_mount, + dfs_jffs2_unmount, + dfs_jffs2_mkfs, + dfs_jffs2_statfs, + + dfs_jffs2_unlink, + dfs_jffs2_stat, + dfs_jffs2_rename, }; int dfs_jffs2_init(void) { /* register fatfs file system */ - dfs_register(&dfs_jffs2_ops); + dfs_register(&_jffs2_ops); + /* initialize mutex */ - if (rt_mutex_init(&jffs2_lock, "jffs2lock", RT_IPC_FLAG_FIFO) != RT_EOK) - { - rt_kprintf("init jffs2 lock mutex failed\n"); - } - rt_kprintf("init jffs2 lock mutex okay\n"); - return 0; + if (rt_mutex_init(&jffs2_lock, "jffs2lock", RT_IPC_FLAG_FIFO) != RT_EOK) + { + rt_kprintf("init jffs2 lock mutex failed\n"); + } + rt_kprintf("init jffs2 lock mutex okay\n"); + return 0; } INIT_COMPONENT_EXPORT(dfs_jffs2_init); - diff --git a/components/dfs/filesystems/jffs2/include/linux/jffs2.h b/components/dfs/filesystems/jffs2/include/linux/jffs2.h index 1c4b055495..ab034effe6 100644 --- a/components/dfs/filesystems/jffs2/include/linux/jffs2.h +++ b/components/dfs/filesystems/jffs2/include/linux/jffs2.h @@ -74,6 +74,8 @@ /* These can go once we've made sure we've caught all uses without byteswapping */ +#include + #if defined(__GNUC__) || (__CC_ARM) typedef struct { uint32_t v32; diff --git a/components/dfs/filesystems/jffs2/include/port/codes.h b/components/dfs/filesystems/jffs2/include/port/codes.h index 798c3f55d9..2426465c84 100644 --- a/components/dfs/filesystems/jffs2/include/port/codes.h +++ b/components/dfs/filesystems/jffs2/include/port/codes.h @@ -86,94 +86,9 @@ extern "C" { typedef int Cyg_ErrNo; +#include -/* CONSTANT DEFINITIONS */ - -/* If adding to this list, you must also update strerror() with its text - * If there is a common error of the same purpose on Unix, try and use its - * name and number. If not, use one above 200 to prevent future conflicts - * - * Do not use negative numbers, so that functions can return positive on - * success and -ESOMETHING on error, and it all works consistently. -*/ - -#define ENOERR 0 /* No error */ -#define EPERM 1 /* Not permitted */ -#define ENOENT 2 /* No such entity */ -#define ESRCH 3 /* No such process */ -#define EINTR 4 /* Operation interrupted */ -#define EIO 5 /* I/O error */ -#define EBADF 9 /* Bad file handle */ -#define EAGAIN 11 /* Try again later */ -#define EWOULDBLOCK EAGAIN -#define ENOMEM 12 /* Out of memory */ -#define EBUSY 16 /* Resource busy */ -#define EXDEV 18 /* Cross-device link */ -#define ENODEV 19 /* No such device */ -#define ENOTDIR 20 /* Not a directory */ -#define EISDIR 21 /* Is a directory */ -#define EINVAL 22 /* Invalid argument */ -#define ENFILE 23 /* Too many open files in system */ -#define EMFILE 24 /* Too many open files */ -#define EFBIG 27 /* File too large */ -#define ENOSPC 28 /* No space left on device */ -#define ESPIPE 29 /* Illegal seek */ -#define EROFS 30 /* Read-only file system */ -#define EDOM 33 /* Argument to math function outside valid */ - /* domain */ -#define ERANGE 34 /* Math result cannot be represented */ -#define EDEADLK 35 /* Resource deadlock would occur */ -#define EDEADLOCK EDEADLK -#define ENOSYS 38 /* Function not implemented */ -#define ENAMETOOLONG 60 /* File name too long */ -#define ENOTEMPTY 66 /* Directory not empty */ -#define ENOTSUP 95 /* Not supported error */ -#define EEOF 200 /* End of file reached */ -#define ENOSUPP 201 /* Operation not supported */ -#define EDEVNOSUPP 202 /* Device does not support this operation */ - -/* Additional errors used by networking */ -#define ENXIO 300 /* Device not configured */ -#define EACCES 301 /* Permission denied */ -#define EEXIST 302 /* File exists */ -#define ENOTTY 303 /* Inappropriate ioctl for device */ -#define EPIPE 304 /* Broken pipe */ - -/* non-blocking and interrupt i/o */ -#define EINPROGRESS 310 /* Operation now in progress */ -#define EALREADY 311 /* Operation already in progress */ - -/* ipc/network software -- argument errors */ -#define ENOTSOCK 320 /* Socket operation on non-socket */ -#define EDESTADDRREQ 321 /* Destination address required */ -#define EMSGSIZE 322 /* Message too long */ -#define EPROTOTYPE 323 /* Protocol wrong type for socket */ -#define ENOPROTOOPT 324 /* Protocol not available */ -#define EPROTONOSUPPORT 325 /* Protocol not supported */ -#define ESOCKTNOSUPPORT 326 /* Socket type not supported */ -#define EOPNOTSUPP 327 /* Operation not supported */ -#define EPFNOSUPPORT 328 /* Protocol family not supported */ -#define EAFNOSUPPORT 329 /* Address family not supported by */ - /* protocol family */ -#define EADDRINUSE 330 /* Address already in use */ -#define EADDRNOTAVAIL 331 /* Can't assign requested address */ - -/* ipc/network software -- operational errors */ -#define ENETDOWN 350 /* Network is down */ -#define ENETUNREACH 351 /* Network is unreachable */ -#define ENETRESET 352 /* Network dropped connection on reset */ -#define ECONNABORTED 353 /* Software caused connection abort */ -#define ECONNRESET 354 /* Connection reset by peer */ -#define ENOBUFS 355 /* No buffer space available */ -#define EISCONN 356 /* Socket is already connected */ -#define ENOTCONN 357 /* Socket is not connected */ -#define ESHUTDOWN 358 /* Can't send after socket shutdown */ -#define ETOOMANYREFS 359 /* Too many references: can't splice */ -#define ETIMEDOUT 360 /* Operation timed out */ -#define ECONNREFUSED 361 /* Connection refused */ - -#define EHOSTDOWN 364 /* Host is down */ -#define EHOSTUNREACH 365 /* No route to host */ +#define ENOERR RT_EOK #ifdef __cplusplus } /* extern "C" */ diff --git a/components/dfs/filesystems/jffs2/include/port/fcntl.h b/components/dfs/filesystems/jffs2/include/port/fcntl.h index 438b72541b..fcc3088fc7 100644 --- a/components/dfs/filesystems/jffs2/include/port/fcntl.h +++ b/components/dfs/filesystems/jffs2/include/port/fcntl.h @@ -1,34 +1,12 @@ #ifndef CYGONCE_ISO_FCNTL_H #define CYGONCE_ISO_FCNTL_H -#if defined(__CC_ARM) || defined(MSVC) -/* File access modes used for open() and fnctl() */ -#define O_RDONLY (1<<0) /* Open for reading only */ -#define O_WRONLY (1<<1) /* Open for writing only */ -#define O_RDWR (O_RDONLY|O_WRONLY) /* Open for reading and writing */ - -/* File access mode mask */ -#define O_ACCMODE (O_RDONLY|O_RDWR|O_WRONLY) - -/* open() mode flags */ - -#define O_CREAT (1<<3) /* Create file it it does not exist */ -#define O_EXCL (1<<4) /* Exclusive use */ -#define O_NOCTTY (1<<5) /* Do not assign a controlling terminal */ -#define O_TRUNC (1<<6) /* Truncate */ - -/* File status flags used for open() and fcntl() */ -#define O_APPEND (1<<7) /* Set append mode */ -#define O_DSYNC (1<<8) /* Synchronized I/O data integrity writes */ -#define O_NONBLOCK (1<<9) /* No delay */ -#define O_RSYNC (1<<10) /* Synchronized read I/O */ -#define O_SYNC (1<<11) /* Synchronized I/O file integrity writes */ /*------------------------------------------------------------------------*/ -/* for dfs_jffs2.c */ +/* for dfs_jffs2.c */ /*------------------------------------------------------------------------*/ /* File access modes used for open() and fnctl() */ -#define JFFS2_O_RDONLY (1<<0) /* Open for reading only */ -#define JFFS2_O_WRONLY (1<<1) /* Open for writing only */ +#define JFFS2_O_RDONLY (O_RDONLY) /* Open for reading only */ +#define JFFS2_O_WRONLY (O_WRONLY) /* Open for writing only */ #define JFFS2_O_RDWR (O_RDONLY|O_WRONLY) /* Open for reading and writing */ /* File access mode mask */ @@ -36,45 +14,18 @@ /* open() mode flags */ -#define JFFS2_O_CREAT (1<<3) /* Create file it it does not exist */ -#define JFFS2_O_EXCL (1<<4) /* Exclusive use */ -#define JFFS2_O_NOCTTY (1<<5) /* Do not assign a controlling terminal */ -#define JFFS2_O_TRUNC (1<<6) /* Truncate */ +#define JFFS2_O_CREAT (O_CREAT) /* Create file it it does not exist */ +#define JFFS2_O_EXCL (O_EXCL) /* Exclusive use */ +#define JFFS2_O_NOCTTY (O_NOCTTY) /* Do not assign a controlling terminal */ +#define JFFS2_O_TRUNC (O_TRUNC) /* Truncate */ /* File status flags used for open() and fcntl() */ -#define JFFS2_O_APPEND (1<<7) /* Set append mode */ -#define JFFS2_O_DSYNC (1<<8) /* Synchronized I/O data integrity writes */ -#define JFFS2_O_NONBLOCK (1<<9) /* No delay */ -#define JFFS2_O_RSYNC (1<<10) /* Synchronized read I/O */ -#define JFFS2_O_SYNC (1<<11) /* Synchronized I/O file integrity writes */ - -#elif defined(__GNUC__) - -/*------------------------------------------------------------------------*/ -/* for dfs_jffs2.c */ -/*------------------------------------------------------------------------*/ -/* File access modes used for open() and fnctl() */ -#define JFFS2_O_RDONLY (DFS_O_RDONLY) /* Open for reading only */ -#define JFFS2_O_WRONLY (DFS_O_WRONLY) /* Open for writing only */ -#define JFFS2_O_RDWR (DFS_O_RDONLY|DFS_O_WRONLY) /* Open for reading and writing */ - -/* File access mode mask */ -#define JFFS2_O_ACCMODE (DFS_O_RDONLY|DFS_O_RDWR|DFS_O_WRONLY) - -/* open() mode flags */ - -#define JFFS2_O_CREAT (DFS_O_CREAT) /* Create file it it does not exist */ -#define JFFS2_O_EXCL (DFS_O_EXCL) /* Exclusive use */ -#define JFFS2_O_NOCTTY (DFS_O_NOCTTY) /* Do not assign a controlling terminal */ -#define JFFS2_O_TRUNC (DFS_O_TRUNC) /* Truncate */ - -/* File status flags used for open() and fcntl() */ -#define JFFS2_O_APPEND (DFS_O_APPEND) /* Set append mode */ -#define JFFS2_O_DSYNC (DFS_O_DSYNC) /* Synchronized I/O data integrity writes */ -#define JFFS2_O_NONBLOCK (DFS_O_NONBLOCK)/* No delay */ -#define JFFS2_O_RSYNC (DFS_O_RSYNC) /* Synchronized read I/O */ -#define JFFS2_O_SYNC (DFS_O_SYNC) /* Synchronized I/O file integrity writes */ +#define JFFS2_O_APPEND (O_APPEND) /* Set append mode */ +#define JFFS2_O_DSYNC (O_DSYNC) /* Synchronized I/O data integrity writes */ +#define JFFS2_O_NONBLOCK (O_NONBLOCK)/* No delay */ +#define JFFS2_O_RSYNC (O_RSYNC) /* Synchronized read I/O */ +#define JFFS2_O_SYNC (O_SYNC) /* Synchronized I/O file integrity writes */ #endif -#endif + /* EOF fcntl.h */ diff --git a/components/dfs/filesystems/jffs2/include/port/sys/stat.h b/components/dfs/filesystems/jffs2/include/port/sys/stat.h index 845f40d1f4..43958a752f 100644 --- a/components/dfs/filesystems/jffs2/include/port/sys/stat.h +++ b/components/dfs/filesystems/jffs2/include/port/sys/stat.h @@ -271,51 +271,6 @@ typedef void *cyg_io_handle_t; #define __stat_mode_LNK (1<<8) #define __stat_mode_SOCK (1<<9) -#if !defined(_POSIX_C_SOURCE) || (_POSIX_C_SOURCE >= 200112L) -#define S_IFDIR (__stat_mode_DIR) -#define S_IFCHR (__stat_mode_CHR) -#define S_IFBLK (__stat_mode_BLK) -#define S_IFREG (__stat_mode_REG) -#define S_IFIFO (__stat_mode_FIFO) -#define S_IFLNK (__stat_mode_LNK) -#define S_IFSOCK (__stat_mode_SOCK) -#define S_IFMT (S_IFDIR|S_IFCHR|S_IFBLK|S_IFREG| \ - S_IFIFO|S_IFLNK|S_IFSOCK) -#endif - -#define S_ISDIR(__mode) ((__mode) & __stat_mode_DIR ) -#define S_ISCHR(__mode) ((__mode) & __stat_mode_CHR ) -#define S_ISBLK(__mode) ((__mode) & __stat_mode_BLK ) -#define S_ISREG(__mode) ((__mode) & __stat_mode_REG ) -#define S_ISFIFO(__mode) ((__mode) & __stat_mode_FIFO ) -#if !defined(_POSIX_C_SOURCE) || (_POSIX_C_SOURCE >= 200112L) -#define S_ISLNK(__mode) ((__mode) & __stat_mode_LNK ) -#define S_ISSOCK(__mode) ((__mode) & __stat_mode_SOCK ) -#endif - -#define S_TYPEISMQ(__buf) ((__buf)->st_mode & __stat_mode_MQ ) -#define S_TYPEISSEM(__buf) ((__buf)->st_mode & __stat_mode_SEM ) -#define S_TYPEISSHM(__buf) ((__buf)->st_mode & __stat_mode_SHM ) - - -#define S_IRUSR (1<<16) -#define S_IWUSR (1<<17) -#define S_IXUSR (1<<18) -#define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR) - -#define S_IRGRP (1<<19) -#define S_IWGRP (1<<20) -#define S_IXGRP (1<<21) -#define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP) - -#define S_IROTH (1<<22) -#define S_IWOTH (1<<23) -#define S_IXOTH (1<<24) -#define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH) - -#define S_ISUID (1<<25) -#define S_ISGID (1<<26) - #if defined(MSVC) /* for time_t */ #include @@ -333,22 +288,6 @@ typedef long time_t; #include #endif -struct stat { - mode_t st_mode; /* File mode */ - ino_t st_ino; /* File serial number */ - dev_t st_dev; /* ID of device containing file */ - nlink_t st_nlink; /* Number of hard links */ - uid_t st_uid; /* User ID of the file owner */ - gid_t st_gid; /* Group ID of the file's group */ - off_t st_size; /* File size (regular files only) */ - time_t st_atime; /* Last access time */ - time_t st_mtime; /* Last data modification time */ - time_t st_ctime; /* Last file status change time */ -}; - -//fcntl.h -#define O_NONBLOCK (1<<9) /* No delay */ - #endif /* CYGONCE_ISO_SYS_TYPES_H multiple inclusion protection */ /* EOF sys/types.h */ diff --git a/components/dfs/filesystems/jffs2/kernel/linux/fs.h b/components/dfs/filesystems/jffs2/kernel/linux/fs.h index c2f173ac81..94f493c91a 100644 --- a/components/dfs/filesystems/jffs2/kernel/linux/fs.h +++ b/components/dfs/filesystems/jffs2/kernel/linux/fs.h @@ -2,12 +2,5 @@ #define __LINUX_FS_H__ #include -/* - * File types - */ -#define DT_UNKNOWN 0 -#define DT_DIR 4 -#define DT_REG 8 - #endif /* __LINUX_FS_H__ */ diff --git a/components/dfs/filesystems/jffs2/kernel/linux/types.h b/components/dfs/filesystems/jffs2/kernel/linux/types.h index 56665b774e..bfa09c14c0 100644 --- a/components/dfs/filesystems/jffs2/kernel/linux/types.h +++ b/components/dfs/filesystems/jffs2/kernel/linux/types.h @@ -3,17 +3,7 @@ #include "cyg/infra/cyg_type.h" -#define uint8_t cyg_uint8 -#define uint16_t cyg_uint16 -#define uint32_t cyg_uint32 - -#define int8_t cyg_int8 -#define int16_t cyg_int16 -#define int32_t cyg_int32 - #define loff_t off_t - #define kvec iovec #endif /* __LINUX_TYPES_H__ */ - diff --git a/components/dfs/filesystems/jffs2/src/flashio.c b/components/dfs/filesystems/jffs2/src/flashio.c index 65fd7b8aac..37c332de70 100644 --- a/components/dfs/filesystems/jffs2/src/flashio.c +++ b/components/dfs/filesystems/jffs2/src/flashio.c @@ -16,7 +16,7 @@ #include "nodelist.h" #include -int jffs2_flash_read(struct jffs2_sb_info * c, uint32_t offset, +int jffs2_flash_read(struct jffs2_sb_info * c, cyg_uint32 offset, const size_t size, size_t * return_size, unsigned char *buffer) @@ -33,7 +33,7 @@ int jffs2_flash_read(struct jffs2_sb_info * c, uint32_t offset, } int jffs2_flash_write(struct jffs2_sb_info * c, - uint32_t offset, const size_t size, + cyg_uint32 offset, const size_t size, size_t * return_size, unsigned char *buffer) { uint32_t len; diff --git a/components/dfs/filesystems/jffs2/src/readinode.c b/components/dfs/filesystems/jffs2/src/readinode.c index d6596058bc..ae1481fd23 100644 --- a/components/dfs/filesystems/jffs2/src/readinode.c +++ b/components/dfs/filesystems/jffs2/src/readinode.c @@ -188,7 +188,7 @@ read_direntry(struct jffs2_sb_info *c, int already = read - sizeof(*rd); err = jffs2_flash_read(c, (ref_offset(ref)) + read, - rd->nsize - already, &read, &fd->name[already]); + rd->nsize - already, (size_t*)&read, &fd->name[already]); if (unlikely(read != rd->nsize - already) && likely(!err)) return -EIO; @@ -278,7 +278,7 @@ read_dnode(struct jffs2_sb_info *c, return -ENOMEM; err = jffs2_flash_read(c, ref_offset(ref) + sizeof(*rd), je32_to_cpu(rd->csize), - &read, buf); + (size_t*)&read, buf); if (unlikely(read != je32_to_cpu(rd->csize)) && likely(!err)) err = -EIO; if (err) {