diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64..0000000000000000000000000000000000000000 --- a/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/OAT.xml b/OAT.xml deleted file mode 100644 index ff8c69fdbb2c0c01d80854235bf159ff14ed6d87..0000000000000000000000000000000000000000 --- a/OAT.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - LICENSE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/README.OpenSource b/README.OpenSource deleted file mode 100755 index b57ec7bf3cd3771c6c1fb4f6a1c27dac3852543d..0000000000000000000000000000000000000000 --- a/README.OpenSource +++ /dev/null @@ -1,11 +0,0 @@ -[ - { - "Name" : "rt-thread", - "License" : "Apache License V2.0", - "License File" : "COPYRIGHT", - "Version Number" : "4.0.2", - "Owner" : "tonghaoyang1@huawei.com", - "Upstream URL" : "http://code.google.com/p/rt-thread/", - "Description" : "The Real-Time Thread(RT-Thread) Operating System is an open source real-time operating system developed by the RT-Thread Studio based in China, more on kernel and components Introduction." - } -] diff --git a/README.md b/README.md deleted file mode 100644 index 41824d6ca64db043b8cb361dae826b5fff3c47e7..0000000000000000000000000000000000000000 --- a/README.md +++ /dev/null @@ -1,84 +0,0 @@ -# RT-Thread # - -[中文页](README_zh.md) | - -[![GitHub](https://img.shields.io/github/license/RT-Thread/rt-thread.svg)](https://github.com/RT-Thread/rt-thread/blob/master/LICENSE) -[![GitHub release](https://img.shields.io/github/release/RT-Thread/rt-thread.svg)](https://github.com/RT-Thread/rt-thread/releases) -[![Build Status](https://travis-ci.org/RT-Thread/rt-thread.svg)](https://travis-ci.org/RT-Thread/rt-thread) -[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/RT-Thread/rt-thread?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![GitHub pull-requests](https://img.shields.io/github/issues-pr/RT-Thread/rt-thread.svg)](https://github.com/RT-Thread/rt-thread/pulls) -[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](https://github.com/RT-Thread/rt-thread/pulls) - -RT-Thread is an open source IoT operating system from China, which has strong scalability: from a tiny kernel running on a tiny core, for example ARM Cortex-M0, or Cortex-M3/4/7, to a rich feature system running on MIPS32, ARM Cortex-A8, ARM Cortex-A9 DualCore etc. - -## Overview ## - -RT-Thread RTOS like a traditional real-time operating system. The kernel has real-time multi-task scheduling, semaphore, mutex, mail box, message queue, signal etc. However, it has three different things: - -* Device Driver; -* Component; -* Dynamic Module - -The device driver is more like a driver framework, UART, IIC, SPI, SDIO, USB device/host, EMAC, MTD NAND etc. The developer can easily add low level driver and board configuration, then combined with the upper framework, he/she can use lots of features. - -The Component is a software concept upon RT-Thread kernel, for example a shell (finsh/msh shell), virtual file system (FAT, YAFFS, UFFS, ROM/RAM file system etc), TCP/IP protocol stack (lwIP), POSIX (thread) interface etc. One component must be a directory under RT-Thread/Components and one component can be descripted by a SConscript file (then be compiled and linked into the system). - -The Dynamic Module, formerly named as User Applicaion (UA) is a dynamic loaded module or library, it can be compiled standalone without Kernel. Each Dynamic Module has its own object list to manage thread/semaphore/kernel object which was created or initialized inside this UA. More information about UA, please visit another [git repo](https://github.com/RT-Thread/rtthread-apps). - -## Board Support Package ## - -RT-Thread RTOS can support many architectures: - -* ARM Cortex-M0 -* ARM Cortex-M3/M4/7 -* ARM Cortex-R4 -* ARM Cortex-A8/A9 -* ARM920T/ARM926 etc -* MIPS32 -* x86 -* Andes -* C-Sky -* RISC-V -* PowerPC - -## License ## - -RT-Thread is Open Source software under the Apache License 2.0 since RT-Thread v3.1.1. License and copyright information can be found within the code. - - /* - * Copyright (c) 2006-2018, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - */ - -Since 9th of September 2018, PRs submitted by the community may be merged into the main line only after signing the Contributor License Agreement(CLA). - -## Usage ## - -RT-Thread RTOS uses [scons](http://www.scons.org) as building system. Therefore, please install scons and Python 2.7 firstly. -So far, the RT-Thread scons building system support the command line compile or generate some IDE's project. There are some option varaibles in the scons building script (rtconfig.py): - -* ```CROSS_TOOL``` the compiler which you want to use, gcc/keil/iar. -* ```EXEC_PATH``` the path of compiler. - -In SConstruct file: - -```RTT_ROOT``` This variable is the root directory of RT-Thread RTOS. If you build the porting in the bsp directory, you can use the default setting. Also, you can set the root directory in ```RTT_ROOT``` environment variable and not modify SConstruct files. - -When you set these variables correctly, you can use command: - - scons - -under BSP directory to simplely compile RT-Thread RTOS. - -If you want to generate the IDE's project file, you can use command: - - scons --target=mdk/mdk4/mdk5/iar/cb -s - -to generate the project file. - -NOTE: RT-Thread scons building system will tailor the system according to your rtconfig.h configuration header file. For example, if you disable the lwIP in the rtconfig.h by commenting the ```#define RT_USING_LWIP```, the generated project file should have no lwIP related files. - -## Contribution ## - -Please refer the contributors in the github. Thank all of RT-Thread Developers. diff --git a/README_zh.md b/README_zh.md deleted file mode 100644 index 56fe0969638b08090418648192e87aa4fc017310..0000000000000000000000000000000000000000 --- a/README_zh.md +++ /dev/null @@ -1,97 +0,0 @@ -# RT-Thread # - -[![GitHub release](https://img.shields.io/github/release/RT-Thread/rt-thread.svg)](https://github.com/RT-Thread/rt-thread/releases) -[![Build Status](https://travis-ci.org/RT-Thread/rt-thread.svg)](https://travis-ci.org/RT-Thread/rt-thread) -[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/RT-Thread/rt-thread?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![GitHub pull-requests](https://img.shields.io/github/issues-pr/RT-Thread/rt-thread.svg)](https://github.com/RT-Thread/rt-thread/pulls) -[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](https://github.com/RT-Thread/rt-thread/pulls) - -RT-Thread是一个来自中国的开源物联网操作系统,它提供了非常强的可伸缩能力:从一个可以运行在ARM Cortex-M0芯片上的极小内核,到中等的ARM Cortex-M3/4/7系统,甚至是运行于MIPS32、ARM Cortex-A系列处理器上功能丰富系统。 - -## 简介 ## - -RT-Thread包含了一个自有的、传统的硬实时内核:可抢占的多任务实时调度器,信号量,互斥量,邮箱,消息队列,信号等。当然,它和传统的实时操作系统还存在着三种不同: - -* 设备驱动框架; -* 软件组件; -* 应用模块 - -设备驱动框架更类似一套驱动框架,涉及到UART,IIC,SPI,SDIO,USB从设备/主设备,EMAC,NAND闪存设备等。它会把这些设备驱动中的共性抽象/抽取出来,而驱动工程师只需要按照固定的模式实现少量的底层硬件操作及板级配置。通过这样的方式,让一个硬件外设更容易地对接到RT-Thread系统中,并获得RT-Thread平台上的完整软件栈功能。 - -软件组件是位于RT-Thread内核上的软件单元,例如命令行(finsh/msh shell),虚拟文件系统(FAT,YAFFS,UFFS,ROM/RAM文件系统等),TCP/IP网络协议栈(lwIP),Libc/POSIX标准层等。一般的,一个软件组件放置于一个目录下,例如RT-Thread/components目录下的文件夹,并且每个软件组件通过一个 SConscript文件来描述并被添加到RT-Thread的构建系统中。当系统配置中开启了这一软件组件时,这个组件将被编译并链接到最终的RT-Thread固件中。 - -注:随着RT-Thread 3.0中的包管理器开启,越来越多的软件组件将以package方式出现在RT-Thread平台中。而RT-Thread平台更多的是指: - -* RT-Thread内核; -* shell命令行; -* 虚拟文件系统; -* TCP/IP网络协议栈; -* 设备驱动框架; -* Libc/POSIX标准层。 - -更多的IoT软件包则以package方式被添加到RT-Thread系统中。 - -应用模块,或者说用户应用(User Application,UA)是一个可动态加载的模块:它可以独立于RT-Thread固件而单独编译。一般的,每个UA都包含一个main函数入口;一个它自己的对象链表,用于管理这个应用的任务/信号量/消息队列等内核对象,创建、初始化、销毁等。更多关于UA的信息,请访问另外一个 [git 仓库](https://github.com/RT-Thread/rtthread-apps) 了解。 - -## 支持的芯片架构 ## - -RT-Thread支持数种芯片体系架构,已经覆盖当前应用中的主流体系架构: - -* ARM Cortex-M0 -* ARM Cortex-M3/M4/7 -* ARM Cortex-R4 -* ARM Cortex-A8/A9 -* ARM920T/ARM926 etc -* MIPS32 -* x86 -* Andes -* C-Sky -* RISC-V -* PowerPC - -## 许可证 ## - -RT-Thread从v3.1.1版本开始,是一个以Apache许可证2.0版本授权的开源软件,许可证信息以及版权信息一般的可以在代码首部看到: - - /* - * Copyright (c) 2006-2018, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - */ - -从2018/09/09开始,开发者提交PR需要签署贡献者许可协议(CLA)。 - -注意: - -以Apache许可协议v2.0版本授权仅在RT-Thread v3.1.1正式版发布之后才正式实施,当前依然在准备阶段(准备所有原有开发者签署CLA协议)。 - -## 编译 ## - -RT-Thread使用了[scons](http://www.scons.org)做为自身的编译构建系统,并进行一定的定制以满足自身的需求(可以通过scons --help查看RT-Thread中额外添加的命令)。在编译RT-Thread前,请先安装Python 2.7.x及scons。 - -截至目前,RT-Thread scons构建系统可以使用命令行方式编译代码,或者使用scons来生成不同IDE的工程文件。在使用scons时,需要对构建配置文件(rtconfig.py)中如下的变量进行配置: - -* ```CROSS_TOOL``` 指定希望使用的工具链,例如gcc/keil/iar. -* ```EXEC_PATH``` 工具链的路径. - -注:在SConstruct文件中: - -```RTT_ROOT``` 这个变量指向了RT-Thread的发布源代码根目录。如果你仅计划编译bsp目录下的target,这个`RTT_ROOT`可以使用默认配置。另外,你也可以设置同名的环境变量来指向不同的RT-Thread源代码根目录。 - -当你把相关的配置都配置正确后,你可以在具有目标目录下(这个目录应包括rtconfig.py、SContruct文件)执行以下命令: - - scons - -从而简单地就编译好RT-Thread。 - -如果你希望使用IDE来编译RT-Thread,你也可以使用命令行: - - scons --target=mdk/mdk4/mdk5/iar/cb -s - -来生成mdk/iar等的工程文件。而后在IDE中打开project前缀的工程文件来编译RT-Thread。 - -注意:RT-Thread的scons构建系统会根据配置头文件rtconfig.h来裁剪系统。例如,如果你关闭了rtconfig.h中的lwIP定义(通过注释掉```#define RT_USING_LWIP```的方式),则scons生成的IDE工程文件中将自动不包括lwIP相关的文件。而在RT-Thread 3.0版本中,可以通过menuconfig的方式来配置整个系统,而不需要再手工更改rtconfig.h配置头文件。 - -## 贡献者 ## - -请访问github上RT-Thread项目上的contributors了解已经为RT-Thread提交过代码,PR的贡献者。感谢所有为RT-Thread付出的开发者们! diff --git a/components/dfs/filesystems/jffs2/cyg/fileio/fileio.h b/components/dfs/filesystems/jffs2/cyg/fileio/fileio.h deleted file mode 100644 index 6427783214c66a448c2a37048875809a80453c68..0000000000000000000000000000000000000000 --- a/components/dfs/filesystems/jffs2/cyg/fileio/fileio.h +++ /dev/null @@ -1,178 +0,0 @@ -#ifndef CYGONCE_FILEIO_H -#define CYGONCE_FILEIO_H -//============================================================================= -// -// fileio.h -// -// Fileio header -// -//============================================================================= -// ####ECOSGPLCOPYRIGHTBEGIN#### -// ------------------------------------------- -// This file is part of eCos, the Embedded Configurable Operating System. -// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. -// -// eCos 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 or (at your option) any later -// version. -// -// eCos 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 eCos; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// -// As a special exception, if other files instantiate templates or use -// macros or inline functions from this file, or you compile this file -// and link it with other works to produce a work based on this file, -// this file does not by itself cause the resulting work to be covered by -// the GNU General Public License. However the source code for this file -// must still be made available in accordance with section (3) of the GNU -// General Public License v2. -// -// This exception does not invalidate any other reasons why a work based -// on this file might be covered by the GNU General Public License. -// ------------------------------------------- -// ####ECOSGPLCOPYRIGHTEND#### -//============================================================================= -//#####DESCRIPTIONBEGIN#### -// -// Author(s): nickg -// Contributors: nickg -// Date: 2000-05-25 -// Purpose: Fileio header -// Description: This header contains the external definitions of the general file -// IO subsystem for POSIX and EL/IX compatability. -// -// Usage: -// #include -// ... -// -// -//####DESCRIPTIONEND#### -// -//============================================================================= -#include "fs_other.h" - -#include -#include // NULL, size_t -#include -#include -#include "fcntl.h" - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -//============================================================================= - - -struct cyg_fstab_entry; -typedef struct cyg_fstab_entry cyg_fstab_entry; - -struct CYG_FILEOPS_TAG; -typedef struct CYG_FILEOPS_TAG cyg_fileops; - -struct CYG_FILE_TAG; -typedef struct CYG_FILE_TAG cyg_file; - -struct CYG_IOVEC_TAG; -typedef struct CYG_IOVEC_TAG jffs2_iovec; - -struct CYG_UIO_TAG; -typedef struct CYG_UIO_TAG jffs2_uio; - -typedef struct IATTR iattr; - -//============================================================================= -// Directory pointer -#define CYG_ADDRWORD UINTPTR -typedef CYG_ADDRWORD cyg_dir; - -#define JFFS2_DIR_NULL 0 - -//============================================================================= - -struct jffs2_stat; - -//============================================================================= -// Mount table entry - -struct cyg_mtab_entry -{ - const char *name; // name of mount point - const char *fsname; // name of implementing filesystem - const char *devname; // name of hardware device - CYG_ADDRWORD data; // private data value - - // The following are filled in after a successful mount operation - int valid; // Valid entry? - //jffs2_fstab_entry *fs; // pointer to fstab entry - cyg_dir root; // root directory pointer -} ; // JFFS2_HAL_TABLE_TYPE; // prife -typedef struct cyg_mtab_entry cyg_mtab_entry; -//============================================================================= -// IO vector descriptors - -struct CYG_IOVEC_TAG -{ - void *iov_base; /* Base address. */ - ssize_t iov_len; /* Length. */ -}; - -enum cyg_uio_rw { UIO_READ, UIO_WRITE }; - -/* Segment flag values. */ -enum cyg_uio_seg -{ - UIO_USERSPACE, /* from user data space */ - UIO_SYSSPACE /* from system space */ -}; - -struct CYG_UIO_TAG -{ - struct CYG_IOVEC_TAG *uio_iov; /* pointer to array of iovecs */ - int uio_iovcnt; /* number of iovecs in array */ - off_t uio_offset; /* offset into file this uio corresponds to */ - ssize_t uio_resid; /* residual i/o count */ - enum cyg_uio_seg uio_segflg; /* see above */ - enum cyg_uio_rw uio_rw; /* see above */ -}; - -struct CYG_FILE_TAG -{ - UINT32 f_flag; /* file state */ - UINT16 f_ucount; /* use count */ - UINT16 f_type; /* descriptor type */ - 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 */ - CYG_ADDRWORD f_xops; /* extra type specific ops */ - cyg_mtab_entry *f_mte; /* mount table entry */ -}; - - -//----------------------------------------------------------------------------- -// Type of file - -#define CYG_FILE_TYPE_FILE 1 /* file */ -#define CYG_FILE_TYPE_SOCKET 2 /* communications endpoint */ -#define CYG_FILE_TYPE_DEVICE 3 /* device */ - -//----------------------------------------------------------------------------- - -#ifdef __cplusplus -#if __cplusplus -} -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -#endif // ifndef JFFS2ONCE_FILEIO_H -// End of fileio.h diff --git a/components/dfs/filesystems/jffs2/include/port/fcntl.h b/components/dfs/filesystems/jffs2/include/port/fcntl.h deleted file mode 100644 index 510cda6f4f6a2b4543b8edecbbb9517d96ad438e..0000000000000000000000000000000000000000 --- a/components/dfs/filesystems/jffs2/include/port/fcntl.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef CYGONCE_ISO_FCNTL_H -#define CYGONCE_ISO_FCNTL_H - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -#define __CC_ARM -/* File access modes used for open() and fnctl() */ -/* for vfs_jffs2.c */ -/*------------------------------------------------------------------------*/ -/* File access modes used for open() and fnctl() */ - -/* File access mode mask */ -#define JFFS2_O_ACCMODE (O_RDONLY | O_WRONLY | O_NONBLOCK | O_APPEND) - - -#define JFFS2_O_EXECVE (1 << 2) /* Execute use */ - -#define READ_OP 4 -#define WRITE_OP 2 -#define EXEC_OP 1 -#define JFFS2_USER_SHFIT 6 -#define JFFS2_GROUP_SHFIT 3 -#define JFFS2_MODE_ALL (READ_OP | WRITE_OP | EXEC_OP) - -#ifdef __cplusplus -#if __cplusplus -} -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -#endif -/* EOF fcntl.h */ diff --git a/components/dfs/filesystems/jffs2/jffs2_config.h b/components/dfs/filesystems/jffs2/jffs2_config.h deleted file mode 100644 index 538d5b39f6103d1f7b2cec6625359bf95bdeba95..0000000000000000000000000000000000000000 --- a/components/dfs/filesystems/jffs2/jffs2_config.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef JFFS2_CONFIG_H -#define JFFS2_CONFIG_H - -#include "mtd_partition.h" - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -#define JFFS_THREAD_PRIORITY_MAX 32 -#define FILE_PATH_MAX 128 /* the longest file path */ -#define CONFIG_JFFS2_ENTRY_NAME_MAX 256 -#define JFFS2_NAME_MAX CONFIG_JFFS2_ENTRY_NAME_MAX -#define JFFS2_PATH_MAX FILE_PATH_MAX -#define JFFS_NOR_FLASH_BASE 0x100000 -#define JFFS_NOR_FLASH_END_ADDR 0x2000000 -#define DEVICE_PART_MAX 1 /* the max partions on a nand deivce*/ -#define JFFS2_PAGE_SIZE 1024 -/* memory page size in kernel/asm/page.h, it is correspond with flash read/write - * option, so this size has a great impact on reading/writing speed */ -#define CONFIG_JFFS2_PAGE_SHIFT 12 /* (1<<12) 4096bytes*/ - -#define CONFIG_JFFS2_NO_RELATIVEDIR - -#define CYGPKG_FS_JFFS2_RET_DIRENT_DTYPE -#if defined(CYGPKG_FS_JFFS2_RET_DIRENT_DTYPE) - #define CYGPKG_FILEIO_DIRENT_DTYPE -#endif - -#define CYGOPT_FS_JFFS2_WRITE /* if not defined, jffs2 is read only*/ - -/* jffs2 debug output opion */ -#define CONFIG_JFFS2_FS_DEBUG 0 /* 1 or 2 */ - -/* jffs2 gc thread section */ -#define CYGOPT_FS_JFFS2_GCTHREAD -#define CYGNUM_JFFS2_GC_THREAD_PRIORITY 10 /* GC thread's priority */ -#define CYGNUM_JFFS2_GS_THREAD_TICKS 20 /* event timeout ticks */ -#define CYGNUM_JFFS2_GC_THREAD_TICKS 20 /* GC thread's running ticks */ - -/* zlib section*/ -#define CONFIG_JFFS2_ZLIB -#define CONFIG_JFFS2_RTIME -#define CONFIG_JFFS2_RUBIN - -#ifdef __cplusplus -#if __cplusplus -} -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -#endif diff --git a/components/dfs/filesystems/jffs2/porting.c b/components/dfs/filesystems/jffs2/porting.c deleted file mode 100644 index a69a8dd73bf5aa160b58d85d91f171d3d6322d64..0000000000000000000000000000000000000000 --- a/components/dfs/filesystems/jffs2/porting.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include "nodelist.h" -#include "porting.h" - -time_t jffs2_get_timestamp(void) -{ - struct timeval tv; - if (gettimeofday(&tv, NULL)) - return 0; - return (uint32_t)(tv.tv_sec); -} - -void jffs2_get_info_from_sb(void *data, struct jffs2_fs_info *info) -{ - struct jffs2_fs_info; - struct super_block *jffs2_sb = NULL; - struct jffs2_sb_info *c = NULL; - - jffs2_sb = (struct super_block *)(data); - c = JFFS2_SB_INFO(jffs2_sb); - - info->sector_size = c->sector_size; - info->nr_blocks = c->nr_blocks; - info->free_size = c->free_size + c->dirty_size; // fixme need test! -} - -static pthread_mutex_t jffs_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; - -void jffs_lock(void) -{ - (void)pthread_mutex_lock(&jffs_mutex); -} - -void jffs_unlock(void) -{ - (void)pthread_mutex_unlock(&jffs_mutex); -} - -void jffs_mutex_take(LosMux *mutex, uint32_t time_out) -{ - (void)LOS_MuxLock(mutex, time_out); -} - -void jffs_mutex_release(LosMux *mutex) -{ - (void)LOS_MuxUnlock(mutex); -} - -void jffs_mutex_create(LosMux *mutex) -{ - (void)LOS_MuxInit(mutex, NULL); -} - -void jffs_mutex_delete(LosMux *mutex) -{ - (void)LOS_MuxDestroy(mutex); -} - -void jffs_event_create(PEVENT_CB_S event_CB) -{ - (void)LOS_EventInit(event_CB); -} - -void jffs_event_send(PEVENT_CB_S event_CB, uint32_t events) -{ - (void)LOS_EventWrite(event_CB, events); -} - -uint32_t jffs_event_recv(PEVENT_CB_S event_CB, uint32_t event_mask, uint32_t mode, uint32_t time_out) -{ - return(LOS_EventRead(event_CB, event_mask, mode, time_out)); -} - -void jffs_event_detach(PEVENT_CB_S event_CB) -{ - (void)LOS_EventWrite(event_CB, 0xFFFFFFFF); -} - - diff --git a/components/dfs/filesystems/jffs2/porting.h b/components/dfs/filesystems/jffs2/porting.h deleted file mode 100644 index cdea52e52ff1623ad4304026b7f272f0e8d17aa7..0000000000000000000000000000000000000000 --- a/components/dfs/filesystems/jffs2/porting.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef _PORTING_H -#define _PORTING_H - -#include "los_mux.h" -#include "los_event.h" -#include "los_typedef.h" -#include "jffs2.h" -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -/* the following should be same with os_sys_stat.h */ -#define JFFS2_S_IFMT 0x00000f000 -#define JFFS2_S_IFDIR 0040000 -#define JFFS2_S_IFREG 0100000 - -struct jffs2_fs_info { - unsigned long sector_size; /* a erasing block size*/ - unsigned long nr_blocks; /* number of blocks in flash */ - unsigned long free_size; /* size of free flash */ -}; - -struct jffs2_stat { - unsigned long st_mode; /* File mode */ - uint32_t st_ino; /* File serial number */ - uint32_t st_dev; /* ID of device containing file */ - unsigned long st_nlink; /* Number of hard links */ - unsigned long st_uid; /* User ID of the file owner */ - unsigned long st_gid; /* Group ID of the file's group */ - long st_size; /* File size (regular files only) */ - long sddst_atime; /* Last access time */ - long sddst_mtime; /* Last data modification time */ - long sddst_ctime; /* Last file status change time */ -}; - -extern cyg_fileops jffs2_fileops; -extern cyg_fileops jffs2_dirops; -extern struct cyg_fstab_entry jffs2_fste; - -time_t jffs2_get_timestamp(void); -void jffs2_get_info_from_sb(void *data, struct jffs2_fs_info *info); - -void jffs_mutex_take(LosMux *mutex, uint32_t time_out); - -void jffs_mutex_release(LosMux *mutex); - -void jffs_mutex_create(LosMux *mutex); - -void jffs_mutex_delete(LosMux *mutex); -void jffs_event_create(PEVENT_CB_S event_CB); -void jffs_event_send(PEVENT_CB_S event_CB, uint32_t events); -uint32_t jffs_event_recv(PEVENT_CB_S event_CB, uint32_t event_mask, uint32_t mode, uint32_t time_out); -void jffs_event_detach(PEVENT_CB_S event_CB); -void jffs_lock(void); -void jffs_unlock(void); - -#ifdef __cplusplus -#if __cplusplus -} -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -#endif diff --git a/components/dfs/filesystems/jffs2/src/LICENCE b/components/dfs/filesystems/jffs2/src/LICENCE deleted file mode 100644 index f3f9a6f6ec7055962cfc4ebab12bbe44ab5a35d6..0000000000000000000000000000000000000000 --- a/components/dfs/filesystems/jffs2/src/LICENCE +++ /dev/null @@ -1,35 +0,0 @@ -The files in this directory and elsewhere which refer to this LICENCE -file are part of JFFS2, the Journalling Flash File System v2. - - Copyright (C) 2001-2003 Red Hat, Inc. - -JFFS2 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 or (at your option) any later -version. - -JFFS2 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 JFFS2; if not, write to the Free Software Foundation, Inc., -59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - -As a special exception, if other files instantiate templates or use -macros or inline functions from these files, or you compile these -files and link them with other works to produce a work based on these -files, these files do not by themselves cause the resulting work to be -covered by the GNU General Public License. However the source code for -these files must still be made available in accordance with section (3) -of the GNU General Public License. - -This exception does not invalidate any other reasons why a work based on -this file might be covered by the GNU General Public License. - -For information on obtaining alternative licences for JFFS2, see -http://sources.redhat.com/jffs2/jffs2-licence.html - - - $Id: LICENCE,v 1.2 2003/10/04 08:33:05 dwmw2 Exp $ diff --git a/components/dfs/filesystems/jffs2/src/fs-ecos.c b/components/dfs/filesystems/jffs2/src/fs-ecos.c deleted file mode 100755 index 00d99d76de2781ecbc8d64c817a25ffa719c35bf..0000000000000000000000000000000000000000 --- a/components/dfs/filesystems/jffs2/src/fs-ecos.c +++ /dev/null @@ -1,2063 +0,0 @@ -/* - * JFFS2 -- Journalling Flash File System, Version 2. - * - * Copyright (C) 2001-2003 Free Software Foundation, Inc. - * - * Created by Dominic Ostrowski - * Contributors: David Woodhouse, Nick Garnett, Richard Panton. - * - * For licensing information, see the file 'LICENCE' in this directory. - * - * $Id: fs-ecos.c,v 1.44 2005/07/24 15:29:57 dedekind Exp $ - * - */ - -#include //prife for SEEK_SET SEEK_CUR SEEK_END -#include -#include -#include -#include -#include -#include "mtd_list.h" -#include "jffs2/nodelist.h" -#include "los_crc32.h" -#include "jffs2/compr.h" -#include "port/fcntl.h" -#include "porting.h" -#include "limits.h" -#include "los_process_pri.h" -#include "capability_type.h" -#include "capability_api.h" -#include "mtd_partition.h" -#include "vfs_jffs2.h" - -// Filesystem operations -static int jffs2_mount(cyg_mtab_entry *mte, int partition_num); -static int jffs2_umount(cyg_mtab_entry *mte); -static int jffs2_open (cyg_mtab_entry *mte, const char *name, int flags, - int mode, cyg_file *fte); -static int jffs2_ops_unlink(cyg_mtab_entry *mte, const char *name); -static int jffs2_ops_mkdir(cyg_mtab_entry *mte, const char *name, int mode); -static int jffs2_ops_rmdir(cyg_mtab_entry *mte, const char *name); -static int jffs2_ops_rename(cyg_mtab_entry *mte, const char *name1, const char *name2); -static int jffs2_opendir(cyg_mtab_entry *mte, const char *name, cyg_file *fte); -static int jffs2_stat(cyg_mtab_entry *mte, const char *name, struct jffs2_stat *buf); -static int jffs2_fo_chattr(cyg_mtab_entry *mte, const char *name, iattr *attr); - -// File operations -static int jffs2_fo_read(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio); -static int jffs2_fo_write(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio); -static int jffs2_fo_lseek(struct CYG_FILE_TAG *fp, off_t *apos, int whence); -static int jffs2_fo_close(struct CYG_FILE_TAG *fp); - -// Directory operations -static int jffs2_fo_dirread(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio); -static int jffs2_fo_dirlseek(struct CYG_FILE_TAG *fp, off_t *pos, int whence); - -static int jffs2_read_inode (struct _inode *inode); -static void jffs2_clear_inode (struct _inode *inode); -static int jffs2_truncate_file (struct _inode *inode); -static int jffsfs_IsPathDivider(char ch); -static int jffs_check_path(const char *path); -static unsigned int CheckPermission(struct _inode *node, int accMode); -int jffs2_chattr (struct _inode *dir_i, const unsigned char *d_name, iattr *attr, struct _inode *node_old); - - -struct MtdNorDev jffs_part[CONFIG_MTD_PATTITION_NUM]; -//========================================================================== -// STATIC VARIABLES !!! - -static unsigned char gc_buffer[PAGE_CACHE_SIZE]; //avoids malloc when user may be under memory pressure -static unsigned char n_fs_mounted = 0; // a counter to track the number of jffs2 instances mounted - -#define JFFS_PATH_DIVIDERS "/" -//========================================================================== -// Directory operations - -struct jffs2_dirsearch { - struct _inode *dir; // directory to search - const unsigned char *path; // path to follow - struct _inode *node; // Node found - const unsigned char *name; // last name fragment used - int namelen; // name fragment length - int last; // last name in path? - int accMode; // access mode -}; - -typedef struct jffs2_dirsearch jffs2_dirsearch; - -//========================================================================== -// Ref count and nlink management - -// FIXME: This seems like real cruft. Wouldn't it be better just to do the -// right thing? -static void icache_evict(struct _inode *root_i, struct _inode *i) -{ - struct _inode *this = root_i; - struct _inode *next = NULL; - struct _inode *temp = NULL; - struct jffs2_inode_info *f = NULL; - jffs_lock(); - restart: - D2(PRINTK("icache_evict\n")); - // If this is an absolute search path from the root, - // remove all cached inodes with i_count of zero (these are only - // held where needed for dotdot filepaths) - - while (this) { - next = this->i_cache_next; - if (this != i && this->i_count == 0) { - struct _inode *parent = this->i_parent; - - if (this->i_cache_next) - this->i_cache_next->i_cache_prev = this->i_cache_prev; - if (this->i_cache_prev) - this->i_cache_prev->i_cache_next = this->i_cache_next; - jffs2_clear_inode(this); - f = JFFS2_INODE_INFO(this); - (void)mutex_destroy(&(f->sem)); - (void)memset_s(this, sizeof(*this), 0x5a, sizeof(*this)); - temp = this; - free(this); - if (parent && parent != temp) { - parent->i_count--; - this = root_i; - goto restart; - } - } - this = next; - } - jffs_unlock(); -} - -//========================================================================== -// Directory search - -// ------------------------------------------------------------------------- -// init_dirsearch() -// Initialize a dirsearch object to start a search - -void init_dirsearch(jffs2_dirsearch * ds, - struct _inode *dir, const unsigned char *name, int flags) -{ - D2(PRINTK("init_dirsearch name = %s\n", name)); - D2(PRINTK("init_dirsearch dir = %x\n", dir)); - - dir->i_count++; - ds->dir = dir; - ds->path = name; - ds->node = dir; - ds->name = name; - ds->namelen = 0; - ds->last = false; - ds->accMode = flags; -} - -// ------------------------------------------------------------------------- -// find_entry() -// Search a single directory for the next name in a path and update the -// dirsearch object appropriately. - -static int find_entry(jffs2_dirsearch * ds) -{ - struct _inode *dir = ds->dir; - const unsigned char *name = ds->path; - const unsigned char *n = name; - int namelen = 0; - struct _inode *d; - int accMode = 0; - - // Isolate the next element of the path name. - while (*n != '\0' && *n != '/') { - n++; - namelen++; - } - - // Check if this is the last path element. - while( *n == '/') n++; - if (*n == '\0') - ds->last = true; - - // update name in dirsearch object - ds->name = name; - ds->namelen = namelen; - if (name[0] == '.') - switch (namelen) { - default: - break; - case 2: - // Dot followed by not Dot, treat as any other name - if (name[1] != '.') - break; - // Dot Dot - // Move back up the search path - ds->dir = ds->node; - ds->node = ds->dir->i_parent; - ds->node->i_count++; - return ENOERR; - case 1: - // Dot is consumed - ds->node = ds->dir; - ds->dir->i_count++; - return ENOERR; - } - - // Here we have the name and its length set up. - // Search the directory for a matching entry - d = jffs2_lookup(dir, name, namelen); - - if (d == NULL) { - return ENOENT; - } - if (IS_ERR(d)) { - return -(int)(PTR_ERR(d));} - - // If it's a new directory inode, increase refcount on its parent - if (S_ISDIR(d->i_mode) && !d->i_parent) { - d->i_parent = dir; - dir->i_count++; - } - - accMode = (ds->last) ? ds->accMode : EXEC_OP; - - if (CheckPermission(d, accMode)) { - jffs2_iput(d); - return EACCES; - } - - // pass back the node we have found - ds->node = d; - return ENOERR; -} - -// ------------------------------------------------------------------------- -// jffs2_find() -// Main interface to directory search code. This is used in all file -// level operations to locate the object named by the pathname. - -// Returns with use count incremented on both the sought object and -// the directory it was found in -static int jffs2_find(jffs2_dirsearch * d) -{ - int err; - - D2(PRINTK("jffs2_find for path =%s\n", d->path)); - // Short circuit empty paths - if (*(d->path) == '\0') { - d->node->i_count++; - return ENOERR; - } - - // iterate down directory tree until we find the object - // we want. - for (;;) { - // check that we really have a directory - if (!S_ISDIR(d->dir->i_mode)) { - return ENOTDIR; - } - - err = find_entry(d); - if (err != ENOERR) { - return err; - } - if (d->last) - return ENOERR; - - /* We're done with it, although it we found a subdir that - will have caused the refcount to have been increased */ - jffs2_iput(d->dir); - - // Update dirsearch object to search next directory. - d->dir = d->node; - d->path += d->namelen; - while (*(d->path) == '/') - d->path++; // skip dirname separators - } -} - - -//========================================================================== -// Filesystem operations -// ------------------------------------------------------------------------- -// jffs2_mount() -// Process a mount request. This mainly creates a root for the -// filesystem. -static int jffs2_read_super(struct super_block *sb) -{ - int err; - struct jffs2_sb_info *c; - struct MtdNorDev *device; - - c = JFFS2_SB_INFO(sb); - device = (struct MtdNorDev*)(sb->s_dev); - - /* initialize mutex lock */ - (void)mutex_init(&c->alloc_sem); - (void)mutex_init(&c->erase_free_sem); - spin_lock_init(&c->erase_completion_lock); - spin_lock_init(&c->inocache_lock); - - /* sector size is the erase block size */ - c->sector_size = device->blockSize; - c->flash_size = (device->blockEnd - device->blockStart + 1) * device->blockSize; - c->cleanmarker_size = sizeof(struct jffs2_unknown_node); - err = jffs2_do_mount_fs(c); - - if (err) { - (void)mutex_destroy(&c->alloc_sem); - (void)mutex_destroy(&c->erase_free_sem); - return -err; - } - D1(printk(KERN_DEBUG "jffs2_read_super(): Getting root inode\n")); - - sb->s_root = jffs2_iget(sb, 1); - - if (IS_ERR(sb->s_root)) { - D1(printk(KERN_WARNING "get root inode failed\n")); - err = PTR_ERR(sb->s_root); - sb->s_root = NULL; - goto out_nodes; - } - return 0; - -out_nodes: - jffs2_free_ino_caches(c); - jffs2_free_raw_node_refs(c); - free(c->blocks); - (void)mutex_destroy(&c->alloc_sem); - (void)mutex_destroy(&c->erase_free_sem); - - return err; -} - -static int jffs2_mount(cyg_mtab_entry *mte, int partition_num) -{ - struct super_block *jffs2_sb = NULL; - struct jffs2_sb_info *c = NULL; - mtd_partition *current_node = GetSpinorPartitionHead(); - LOS_DL_LIST *patition_head = NULL; - int err; - struct MtdDev *spinor_mtd = NULL; - - jffs2_dbg(1, "begin los_jffs2_mount:%d\n", partition_num); - - jffs2_sb = malloc(sizeof (struct super_block)); - - if (jffs2_sb == NULL) { - return ENOMEM; - } - c = JFFS2_SB_INFO(jffs2_sb); - (void)memset_s(jffs2_sb, sizeof (struct super_block), 0, sizeof (struct super_block)); - patition_head = &(GetSpinorPartitionHead()->node_info); - LOS_DL_LIST_FOR_EACH_ENTRY(current_node,patition_head, mtd_partition, node_info) { - if (current_node->patitionnum == partition_num) - break; - } -#ifndef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7 - spinor_mtd = GetMtd("spinor"); -#else - spinor_mtd = (struct MtdDev *)LOS_DL_LIST_ENTRY(patition_head->pstNext, mtd_partition, node_info)->mtd_info; -#endif - if (spinor_mtd == NULL) { - free(jffs2_sb); - return EPERM; - } - jffs_part[partition_num].blockEnd = current_node->end_block; - jffs_part[partition_num].blockSize = spinor_mtd->eraseSize; - jffs_part[partition_num].blockStart = current_node->start_block; -#ifndef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7 - (void)FreeMtd(spinor_mtd); -#endif - jffs2_sb->jffs2_sb.mtd = current_node->mtd_info; - jffs2_sb->s_dev = (cyg_io_handle_t)(&jffs_part[partition_num]); - - c->flash_size = (current_node->end_block - current_node->start_block + 1) * spinor_mtd->eraseSize; - c->inocache_hashsize = calculate_inocache_hashsize(c->flash_size); - c->sector_size = spinor_mtd->eraseSize; - - jffs2_dbg(1, "C mtd_size:%d,mtd-erase:%d,blocks:%d,hashsize:%d\n", - c->flash_size, c->sector_size, c->flash_size / c->sector_size, c->inocache_hashsize); - - c->inocache_list = malloc(sizeof(struct jffs2_inode_cache *) * c->inocache_hashsize); - if (c->inocache_list == NULL) { - free(jffs2_sb); - return ENOMEM; - } - (void)memset_s(c->inocache_list, sizeof(struct jffs2_inode_cache *) * c->inocache_hashsize, 0, - sizeof(struct jffs2_inode_cache *) * c->inocache_hashsize); - if (n_fs_mounted++ == 0) { - (void)jffs2_create_slab_caches(); // No error check, cannot fail - (void)jffs2_compressors_init(); - } - - err = jffs2_read_super(jffs2_sb); - - if (err) { - if (--n_fs_mounted == 0) { - jffs2_destroy_slab_caches(); - (void)jffs2_compressors_exit(); - } - - free(jffs2_sb); - free(c->inocache_list); - c->inocache_list = NULL; - return err; - } - jffs2_sb->s_root->i_parent = jffs2_sb->s_root; // points to itself, no dotdot paths above mountpoint - jffs2_sb->s_root->i_cache_prev = NULL; // root inode, so always null - jffs2_sb->s_root->i_cache_next = NULL; - jffs2_sb->s_root->i_count = 1; // Ensures the root inode is always in ram until umount - -#ifdef CYGOPT_FS_JFFS2_GCTHREAD - jffs2_start_garbage_collect_thread(c); -#endif - - mte->data = (CYG_ADDRWORD)jffs2_sb; - jffs2_sb->s_mount_count++; - mte->root = (cyg_dir)jffs2_sb->s_root; - D2(PRINTK("jffs2_mounted superblock at %x\n", mte->root)); - return ENOERR; -} - - -// ------------------------------------------------------------------------- -// jffs2_umount() -// Unmount the filesystem. - -static int jffs2_umount(cyg_mtab_entry *mte) -{ - struct _inode *root = (struct _inode *) mte->root; - struct super_block *jffs2_sb = root->i_sb; - struct jffs2_sb_info *c = JFFS2_SB_INFO(jffs2_sb); - struct jffs2_full_dirent *fd, *next; - - D2(PRINTK("jffs2_umount\n")); - - // Only really umount if this is the only mount - if (jffs2_sb->s_mount_count == 1) { - icache_evict(root, NULL); - if (root->i_cache_next != NULL) { - struct _inode *inode = root; - while (inode) { - PRINTK("Ino #%u has use count %d\n", - inode->i_ino, inode->i_count); - inode = inode->i_cache_next; - } - // root icount was set to 1 on mount - return EBUSY; - } - if (root->i_count != 1) { - PRINTK("Ino #1 has use count %d\n", - root->i_count); - return EBUSY; - } -#ifdef CYGOPT_FS_JFFS2_GCTHREAD - jffs2_stop_garbage_collect_thread(c); -#endif - jffs2_iput(root); // Time to free the root inode - - // free directory entries - for (fd = root->jffs2_i.dents; fd; fd = next) { - next = fd->next; - jffs2_free_full_dirent(fd); - } - - free(root); - - // Clean up the super block and root inode - jffs2_free_ino_caches(c); - jffs2_free_raw_node_refs(c); - free(c->blocks); - c->blocks = NULL; - free(c->inocache_list); - c->inocache_list = NULL; - - (void)mutex_destroy(&c->alloc_sem); - (void)mutex_destroy(&c->erase_free_sem); - free(jffs2_sb); - // Clear superblock & root pointer - mte->root = 0; - mte->data = 0; - // That's all folks. - D2(PRINTK("jffs2_umount No current mounts\n")); - } else { - jffs2_sb->s_mount_count--; - } - if (--n_fs_mounted == 0) { - jffs2_destroy_slab_caches(); - (void)jffs2_compressors_exit(); - } - return ENOERR; -} - -// ------------------------------------------------------------------------- -// jffs2_open() -// Open a file for reading or writing. - -static int jffs2_open (cyg_mtab_entry *mte, const char *name, int flags, - int mode, cyg_file *fte) -{ - jffs2_dirsearch ds; - struct _inode *node = NULL; - int err; - jffs2_dbg(1, "open %s at mode: %d\n",name,mode); - -#ifndef CYGOPT_FS_JFFS2_WRITE - if (flags & (O_CREAT | O_TRUNC | O_WRONLY)) - return EROFS; -#endif - - if (jffs_check_path(name)) - return ENAMETOOLONG; - - init_dirsearch(&ds, (struct _inode *)mte->root, - (const unsigned char *) name, jffs2_oflag_to_accmode(flags)); - - err = jffs2_find(&ds); - - if (err == ENOENT) { -#ifdef CYGOPT_FS_JFFS2_WRITE - if (ds.last && (flags & O_CREAT)) { - - // No node there, if the O_CREAT bit is set then we must - // create a new one. The dir and name fields of the dirsearch - // object will have been updated so we know where to put it. - err = jffs2_create(ds.dir, ds.name, mode, &node); - if (err != 0) { - //Possible orphaned inode on the flash - but will be gc'd - jffs2_iput(ds.dir); - return -err; - } - - err = ENOERR; - } -#endif - } else if (err == ENOERR) { - // The node exists. If the O_CREAT and O_EXCL bits are set, we - // must fail the open. - - if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) { - jffs2_iput(ds.node); - err = EEXIST; - } else - node = ds.node; - } else if (err == EACCES) { - jffs2_iput(ds.dir); - return -err; - } - - D1(PRINTK("%s, %d, uid %d gid %d mode %d%d%d\n", __FUNCTION__, __LINE__, node->i_uid, node->i_gid, - (node->i_mode >> JFFS2_USER_SHFIT) & JFFS2_MODE_ALL, (node->i_mode >> JFFS2_GROUP_SHFIT) & JFFS2_MODE_ALL, - (node->i_mode) & JFFS2_MODE_ALL)); - - // Finished with the directory now - jffs2_iput(ds.dir); - - if (err != ENOERR) { - return err; - } - // Check that we actually have a file here - if (S_ISDIR(node->i_mode)) { - jffs2_iput(node); - return EISDIR; - } - - // If the O_TRUNC bit is set we must clean out the file data. - if (flags & O_TRUNC) { -#ifdef CYGOPT_FS_JFFS2_WRITE - err = jffs2_truncate_file(node); - if (err) { - jffs2_iput(node); - return err; - } -#else - jffs2_iput(node); - return EROFS; -#endif - } - - // Initialise the file object - fte->f_flag = flags & JFFS2_O_ACCMODE; - fte->f_offset = (flags & O_APPEND) ? node->i_size : 0; - fte->f_data = (UINTPTR) node; - - return ENOERR; -} - -// ------------------------------------------------------------------------- -// jffs2_ops_unlink() -// Remove a file link from its directory. - -static int jffs2_ops_unlink(cyg_mtab_entry *mte, const char *name) -{ - jffs2_dirsearch ds; - int err; - - jffs2_dbg(1, "unlink: %s\n", name); - - if (jffs_check_path(name)) - return ENAMETOOLONG; - - init_dirsearch(&ds, (struct _inode *) mte->root, - (const unsigned char *)name, 0); - - err = jffs2_find(&ds); - - if (err != ENOERR) { - jffs2_iput(ds.dir); - return err; - } - - if (CheckPermission(ds.dir, WRITE_OP | EXEC_OP)) { - jffs2_iput(ds.dir); - jffs2_iput(ds.node); - return EACCES; - } - - // Cannot unlink directories, use rmdir() instead - if (S_ISDIR(ds.node->i_mode)) { - jffs2_iput(ds.dir); - jffs2_iput(ds.node); - return EISDIR; - } - - // Delete it from its directory - - err = jffs2_unlink(ds.dir, ds.node, ds.name); - jffs2_iput(ds.dir); - jffs2_iput(ds.node); - - return -err; -} - -// ------------------------------------------------------------------------- -// jffs2_ops_mkdir() -// Create a new directory. - -static int jffs2_ops_mkdir(cyg_mtab_entry *mte, const char *name,int mode) -{ - jffs2_dirsearch ds; - int err; - - jffs2_dbg(1, "mkdir: %s\n",name); - - if (jffs_check_path(name)) - return ENAMETOOLONG; - - init_dirsearch(&ds, (struct _inode *)mte->root, (const unsigned char *)name, 0); - - err = jffs2_find(&ds); - if (err == ENOENT) { - if (ds.last) { - // The entry does not exist, and it is the last element in - // the pathname, so we can create it here. - err = jffs2_mkdir(ds.dir, ds.name, mode); - } - // If this was not the last element, then an intermediate - // directory does not exist. - } else { - // If there we no error, something already exists with that - // name, so we cannot create another one. - if (err == ENOERR) { - jffs2_iput(ds.node); - err = -EEXIST; - } - } - jffs2_iput(ds.dir); - if (err == EACCES) { - err = -EACCES; - } - return err; -} - -// ------------------------------------------------------------------------- -// jffs2_ops_rmdir() -// Remove a directory. - -static int jffs2_ops_rmdir(cyg_mtab_entry *mte, const char *name) -{ - jffs2_dirsearch ds; - int err; - - jffs2_dbg(1, "rmdir: %s\n",name); - - if (jffs_check_path(name)) - return ENAMETOOLONG; - - init_dirsearch(&ds, (struct _inode *)mte->root, (const unsigned char *)name, 0); - - err = jffs2_find(&ds); - if (err != ENOERR) { - jffs2_iput(ds.dir); - return -err; - } - - if (CheckPermission(ds.dir, WRITE_OP | EXEC_OP)) { - jffs2_iput(ds.dir); - jffs2_iput(ds.node); - return -EACCES; - } - - // Check that this is actually a directory. - if (!S_ISDIR(ds.node->i_mode)) { - jffs2_iput(ds.dir); - jffs2_iput(ds.node); - return -ENOTDIR; - } - - err = jffs2_rmdir(ds.dir, ds.node, ds.name); - - jffs2_iput(ds.dir); - jffs2_iput(ds.node); - return err; -} - -// ------------------------------------------------------------------------- -// jffs2_ops_rename() -// Rename a file/dir. - -static int jffs2_ops_rename(cyg_mtab_entry *mte, const char *name1, const char *name2) -{ - jffs2_dirsearch ds1, ds2; - int err; - struct jffs2_inode_info *f = NULL; - struct jffs2_full_dirent *fd = NULL; - unsigned int oldrelpath_len, newrelpath_len, cmp_namelen; - - jffs2_dbg(1, "from: %s to: %s\n", name1, name2); - - if (jffs_check_path(name1)) - return ENAMETOOLONG; - - if (jffs_check_path(name2)) - return ENAMETOOLONG; - - oldrelpath_len = strlen(name1); - newrelpath_len = strlen(name2); - if (!oldrelpath_len || !newrelpath_len) - return EPERM; - - cmp_namelen = (oldrelpath_len <= newrelpath_len) ? oldrelpath_len : newrelpath_len; - if ((!strncmp(name1, name2, cmp_namelen)) && ((name1[cmp_namelen] == '/') || (name2[cmp_namelen] == '/'))) { - err = -EPERM; - return err; - } - - init_dirsearch(&ds1, (struct _inode *)mte->root, - (const unsigned char *)name1, 0); - - err = jffs2_find(&ds1); - - if (err != ENOERR) { - jffs2_iput(ds1.dir); - return err; - } - - if (CheckPermission(ds1.dir, WRITE_OP | EXEC_OP)) { - jffs2_iput(ds1.dir); - jffs2_iput(ds1.node); - return -EACCES; - } - - - init_dirsearch(&ds2, (struct _inode *)mte->root, - (const unsigned char *)name2, 0); - - err = jffs2_find(&ds2); - - // Allow through renames to non-existent objects. - if (ds2.last && err == ENOENT) { - ds2.node = NULL; - err = ENOERR; - } else if ((err == ENOERR) && S_ISDIR(ds2.node->i_mode)) { - f = JFFS2_INODE_INFO(ds2.node); - for (fd = f->dents; fd; fd = fd->next) { - if (fd->ino) { - jffs2_iput(ds2.node); - err = ENOTEMPTY; - break; - } - } - } - if (err != ENOERR) { - jffs2_iput(ds1.dir); - jffs2_iput(ds1.node); - jffs2_iput(ds2.dir); - return err; - } - - if (CheckPermission(ds2.dir, WRITE_OP | EXEC_OP)) { - jffs2_iput(ds1.dir); - jffs2_iput(ds1.node); - jffs2_iput(ds2.dir); - jffs2_iput(ds2.node); - return -EACCES; - } - - // Null rename, just return - if (ds1.node == ds2.node) { - err = ENOERR; - goto out; - } - - // First deal with any entry that is at the destination - if (ds2.node != NULL) { - // Check that we are renaming like-for-like - - if (!S_ISDIR(ds1.node->i_mode) && S_ISDIR(ds2.node->i_mode)) { - err = EISDIR; - goto out; - } - - if (S_ISDIR(ds1.node->i_mode) && !S_ISDIR(ds2.node->i_mode)) { - err = ENOTDIR; - goto out; - } - - // Now delete the destination directory entry - /* Er, what happened to atomicity of rename()? */ - err = -jffs2_unlink(ds2.dir, ds2.node, ds2.name); - - if (err != 0) - goto out; - } - // Now we know that there is no clashing node at the destination, - // make a new direntry at the destination and delete the old entry - // at the source. - - err = -jffs2_rename(ds1.dir, ds1.node, ds1.name, ds2.dir, ds2.name); - - // Update directory times - if (!err) - ds1.dir->i_ctime = - ds1.dir->i_mtime = - ds2.dir->i_ctime = ds2.dir->i_mtime = jffs2_get_timestamp(); - out: - jffs2_iput(ds1.dir); - if (S_ISDIR(ds1.node->i_mode)) { - /* Renamed a directory to elsewhere... so fix up its - i_parent pointer and the i_counts of its old and - new parents. */ - jffs2_iput(ds1.node->i_parent); - ds1.node->i_parent = ds2.dir; - /* We effectively increase its use count by not... */ - } else { - jffs2_iput(ds2.dir); /* ... doing this */ - } - jffs2_iput(ds1.node); - if (ds2.node != NULL) - jffs2_iput(ds2.node); - - return err; -} - -static int jffsfs_IsPathDivider(char ch) -{ - const char *str = JFFS_PATH_DIVIDERS; - while (*str) { - if (*str == ch) - return 1; - str++; - } - return 0; -} - -// ------------------------------------------------------------------------- -// jffs2_opendir() -// Open a directory for reading. - -static int jffs2_opendir(cyg_mtab_entry *mte, const char *name, cyg_file *fte) -{ - jffs2_dirsearch ds; - int err; - - jffs2_dbg(1, "opendir: %s\n",name); - - if (jffs_check_path(name)) - return ENAMETOOLONG; - - init_dirsearch(&ds, (struct _inode *) mte->root, - (const unsigned char *) name, jffs2_oflag_to_accmode(O_RDONLY | O_EXECVE)); - - err = jffs2_find(&ds); - - jffs2_iput(ds.dir); - - if (err != ENOERR) { - return err; - } - - // check it is really a directory. - if (!S_ISDIR(ds.node->i_mode)) { - jffs2_iput(ds.node); - return ENOTDIR; - } - - // Initialize the file object, setting the f_ops field to a - // special set of file ops. - - fte->f_flag = 0; - fte->f_offset = 0; - fte->f_data = (UINTPTR) ds.node; - - return ENOERR; -} - -static int jffs2_fo_chattr(cyg_mtab_entry *mte, const char *name, iattr *attr) -{ - jffs2_dirsearch ds; - int ret; - int flags = 0; - D2(PRINTK("jffs2_chattr: %s\n", name)); - - if (jffs_check_path(name)) - return ENAMETOOLONG; - - init_dirsearch(&ds, (struct _inode *)mte->root, (const unsigned char *)name, flags); - - ret = jffs2_find(&ds); - if (ret == ENOERR) { - ret = jffs2_chattr(ds.dir, ds.name, attr, ds.node); - jffs2_iput(ds.node); - } else { - ret = -ret; - } - jffs2_iput(ds.dir); - return ret; -} - -// ------------------------------------------------------------------------- -// jffs2_stat() -// Get struct stat info for named object. - -static int jffs2_stat(cyg_mtab_entry *mte, const char *name, struct jffs2_stat *buf) -{ - jffs2_dirsearch ds; - int err; - - jffs2_dbg(1, "get %s stat\n", name); - - if (jffs_check_path(name)) - return ENAMETOOLONG; - - init_dirsearch(&ds, (struct _inode *)mte->root, - (const unsigned char *) name, 0); - - err = jffs2_find(&ds); - jffs2_iput(ds.dir); - - if (err != ENOERR) - return err; - - // Fill in the status - buf->st_mode = ds.node->i_mode; - buf->st_ino = ds.node->i_ino; - buf->st_dev = 0; - buf->st_nlink = ds.node->i_nlink; - buf->st_uid = ds.node->i_uid; - buf->st_gid = ds.node->i_gid; - buf->st_size = ds.node->i_size; - buf->sddst_atime = ds.node->i_atime; - buf->sddst_mtime = ds.node->i_mtime; - buf->sddst_ctime = ds.node->i_ctime; - - jffs2_iput(ds.node); - - return ENOERR; -} - -//========================================================================== -// File operations - -// ------------------------------------------------------------------------- -// jffs2_fo_read() -// Read data from the file. - -static int jffs2_fo_read(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio) -{ - struct _inode *inode = (struct _inode *) fp->f_data; - struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); - struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); - int i; - ssize_t resid = uio->uio_resid; - off_t pos = fp->f_offset; - - mutex_lock(&f->sem); - - // Loop over the io vectors until there are none left - for (i = 0; i < uio->uio_iovcnt && pos < inode->i_size; i++) { - int ret; - jffs2_iovec *iov = &uio->uio_iov[i]; - off_t len = min((iov->iov_len), (inode->i_size - pos)); - - D2(PRINTK("jffs2_fo_read inode size %d\n", inode->i_size)); - - ret = jffs2_read_inode_range(c, f,(unsigned char *) iov->iov_base, pos,len); - if (ret) { - D1(PRINTK - ("jffs2_fo_read(): read_inode_range failed %d\n", - ret)); - uio->uio_resid = resid; - mutex_unlock(&f->sem); - return -ret; - } - resid -= len; - pos += len; - } - - // We successfully read some data, update the node's access time - // and update the file offset and transfer residue. - - inode->i_atime = jffs2_get_timestamp(); - - uio->uio_resid = resid; - fp->f_offset = pos; - - mutex_unlock(&f->sem); - - return ENOERR; -} - -#ifdef CYGOPT_FS_JFFS2_WRITE -// ------------------------------------------------------------------------- -// jffs2_fo_write() -// Write data to file. -static int jffs2_extend_file (struct _inode *inode, struct jffs2_raw_inode *ri, - unsigned long offset) -{ - struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); - struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); - struct jffs2_full_dnode *fn; - uint32_t alloc_len; - int ret = 0; - - /* Make new hole frag from old EOF to new page */ - D1(printk(KERN_DEBUG "Writing new hole frag 0x%x-0x%x between current EOF and new page\n", - (unsigned int)inode->i_size, offset)); - - ret = jffs2_reserve_space(c, sizeof(*ri), &alloc_len, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); - if (ret) - return ret; - - mutex_lock(&f->sem); - - ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); - ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE); - ri->totlen = cpu_to_je32(sizeof(*ri)); - ri->hdr_crc = cpu_to_je32(crc32(0, ri, (sizeof(struct jffs2_unknown_node)-4))); - - ri->version = cpu_to_je32(++f->highest_version); - ri->isize = cpu_to_je32(max((uint32_t)inode->i_size, offset)); - - ri->offset = cpu_to_je32(inode->i_size); - ri->dsize = cpu_to_je32((offset - inode->i_size)); - ri->csize = cpu_to_je32(0); - ri->compr = JFFS2_COMPR_ZERO; - ri->node_crc = cpu_to_je32(crc32(0, ri, (sizeof(*ri)-8))); - ri->data_crc = cpu_to_je32(0); - - fn = jffs2_write_dnode(c, f, ri, NULL, 0, ALLOC_NORMAL); - jffs2_complete_reservation(c); - if (IS_ERR(fn)) { - ret = PTR_ERR(fn); - (void)mutex_unlock(&f->sem); - return ret; - } - ret = jffs2_add_full_dnode_to_inode(c, f, fn); - if (f->metadata) { - jffs2_mark_node_obsolete(c, f->metadata->raw); - jffs2_free_full_dnode(f->metadata); - f->metadata = NULL; - } - if (ret) { - D1(printk(KERN_DEBUG "Eep. add_full_dnode_to_inode() failed in prepare_write, returned %d\n", ret)); - jffs2_mark_node_obsolete(c, fn->raw); - jffs2_free_full_dnode(fn); - mutex_unlock(&f->sem); - return ret; - } - inode->i_size = offset; - mutex_unlock(&f->sem); - return 0; -} - -// jffs2_fo_open() -// Truncate a file -static int jffs2_truncate_file (struct _inode *inode) -{ - struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); - struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); - struct jffs2_full_dnode *new_metadata, * old_metadata; - struct jffs2_raw_inode *ri; - uint32_t alloclen; - int err; - - ri = jffs2_alloc_raw_inode(); - if (!ri) { - return ENOMEM; - } - err = jffs2_reserve_space(c, sizeof(*ri), &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); - - if (err) { - jffs2_free_raw_inode(ri); - return err; - } - mutex_lock(&f->sem); - ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); - ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE); - ri->totlen = cpu_to_je32(sizeof(*ri)); - ri->hdr_crc = cpu_to_je32(crc32(0, ri, (sizeof(struct jffs2_unknown_node)-4))); - - ri->ino = cpu_to_je32(inode->i_ino); - ri->version = cpu_to_je32(++f->highest_version); - - ri->uid = cpu_to_je16(inode->i_uid); - ri->gid = cpu_to_je16(inode->i_gid); - ri->mode = cpu_to_jemode(inode->i_mode); - ri->isize = cpu_to_je32(0); - ri->atime = cpu_to_je32(inode->i_atime); - ri->mtime = cpu_to_je32(jffs2_get_timestamp()); - ri->offset = cpu_to_je32(0); - ri->csize = ri->dsize = cpu_to_je32(0); - ri->compr = JFFS2_COMPR_NONE; - ri->node_crc = cpu_to_je32(crc32(0, ri, (sizeof(*ri)-8))); - ri->data_crc = cpu_to_je32(0); - new_metadata = jffs2_write_dnode(c, f, ri, NULL, 0, ALLOC_NORMAL); - if (IS_ERR(new_metadata)) { - jffs2_complete_reservation(c); - jffs2_free_raw_inode(ri); - mutex_unlock(&f->sem); - return PTR_ERR(new_metadata); - } - - /* It worked. Update the inode */ - inode->i_mtime = jffs2_get_timestamp(); - inode->i_size = 0; - old_metadata = f->metadata; - jffs2_truncate_fragtree (c, &f->fragtree, 0); - f->metadata = new_metadata; - if (old_metadata) { - jffs2_mark_node_obsolete(c, old_metadata->raw); - jffs2_free_full_dnode(old_metadata); - } - jffs2_free_raw_inode(ri); - -mutex_unlock(&f->sem); - jffs2_complete_reservation(c); - - return 0; -} - -// jffs2_fo_open() -// Truncate a file - -static int jffs2_fo_write(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio) -{ - struct _inode *inode = (struct _inode *) fp->f_data; - off_t pos = fp->f_offset; - ssize_t resid = uio->uio_resid; - struct jffs2_raw_inode ri; - struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); - struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); - int i; - -#ifdef LOSCFG_KERNEL_SMP - struct super_block *sb = inode->i_sb; - UINT16 gc_cpu_mask = LOS_TaskCpuAffiGet(sb->s_gc_thread); - UINT32 cur_task_id = LOS_CurTaskIDGet(); - UINT16 cur_cpu_mask = LOS_TaskCpuAffiGet(cur_task_id); - - if (cur_cpu_mask != gc_cpu_mask) { - if (cur_cpu_mask != LOSCFG_KERNEL_CPU_MASK) - (void)LOS_TaskCpuAffiSet(sb->s_gc_thread, cur_cpu_mask); - else - (void)LOS_TaskCpuAffiSet(cur_task_id, gc_cpu_mask); - } -#endif - // If the APPEND mode bit was supplied, force all writes to - // the end of the file. - if (fp->f_flag & O_APPEND) - pos = fp->f_offset = inode->i_size; - - if (pos < 0) - return EINVAL; - - (void)memset_s(&ri, sizeof(ri), 0, sizeof(ri)); - - ri.ino = cpu_to_je32(f->inocache->ino); - ri.mode = cpu_to_jemode(inode->i_mode); - ri.uid = cpu_to_je16(inode->i_uid); - ri.gid = cpu_to_je16(inode->i_gid); - ri.atime = ri.ctime = ri.mtime = cpu_to_je32(jffs2_get_timestamp()); - - if (pos > inode->i_size) { - int err; - ri.version = cpu_to_je32(++f->highest_version); - err = jffs2_extend_file(inode, &ri, pos); - if (err) - return -err; - } - ri.isize = cpu_to_je32(inode->i_size); - - // Now loop over the iovecs until they are all done, or - // we get an error. - for (i = 0; i < uio->uio_iovcnt; i++) { - jffs2_iovec *iov = &uio->uio_iov[i]; - unsigned char *buf = iov->iov_base; - off_t len = iov->iov_len; - - uint32_t writtenlen; - int err; - - D2(PRINTK("jffs2_fo_write page_start_pos %d\n", pos)); - D2(PRINTK("jffs2_fo_write transfer size %d\n", len)); - - err = jffs2_write_inode_range(c, f, &ri, buf, - pos, len, &writtenlen); - if (err) { - pos += writtenlen; - resid -= writtenlen; - - inode->i_mtime = inode->i_ctime = je32_to_cpu(ri.mtime); - if (pos > inode->i_size) - inode->i_size = pos; - - uio->uio_resid = resid; - fp->f_offset = pos; - - return -err; - } - - if (writtenlen != len) { - pos += writtenlen; - resid -= writtenlen; - - inode->i_mtime = inode->i_ctime = je32_to_cpu(ri.mtime); - if (pos > inode->i_size) - inode->i_size = pos; - - uio->uio_resid = resid; - fp->f_offset = pos; - - return ENOSPC; - } - - pos += len; - resid -= len; - } - - // We wrote some data successfully, update the modified and access - // times of the inode, increase its size appropriately, and update - // the file offset and transfer residue. - inode->i_mtime = inode->i_ctime = je32_to_cpu(ri.mtime); - if (pos > inode->i_size) - inode->i_size = pos; - - uio->uio_resid = resid; - fp->f_offset = pos; - - return ENOERR; -} -#endif /* CYGOPT_FS_JFFS2_WRITE */ - -// ------------------------------------------------------------------------- -// jffs2_fo_lseek() -// Seek to a new file position. - -static int jffs2_fo_lseek(struct CYG_FILE_TAG *fp, off_t *apos, int whence) -{ - struct _inode *node = (struct _inode *) fp->f_data; - off_t pos = *apos; - - D2(PRINTK("jffs2_fo_lseek\n")); - - switch (whence) { - case SEEK_SET: - // Pos is already where we want to be. - break; - - case SEEK_CUR: - // Add pos to current offset. - pos += fp->f_offset; - break; - - case SEEK_END: - // Add pos to file size. - pos += node->i_size; - break; - - default: - return EINVAL; - } - - if (pos < 0) - return EINVAL; - - // All OK, set fp offset and return new position. - *apos = fp->f_offset = pos; - - return ENOERR; -} - -// ------------------------------------------------------------------------- -// jffs2_fo_close() -// Close a file. We just decrement the refcnt and let it go away if -// that is all that is keeping it here. - -static int jffs2_fo_close(struct CYG_FILE_TAG *fp) -{ - struct _inode *node = (struct _inode *) fp->f_data; - - jffs2_dbg(1, "jffs close data: 0x%x\n",fp->f_data); - if (node == NULL) { - return ENOENT; - } - jffs2_iput(node); - - fp->f_data = 0; - free(fp); - - return ENOERR; -} - -//========================================================================== -// Directory operations - -// ------------------------------------------------------------------------- -// jffs2_fo_dirread() -// Read a single directory entry from a file. - -static __inline void filldir(char *nbuf, int nlen, const unsigned char *name, int namlen) -{ - int len = nlen < namlen ? nlen : namlen; - (void)memcpy_s(nbuf, nlen, name, len); - nbuf[len] = '\0'; -} - -static int jffs2_fo_dirread(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio) -{ - struct _inode *d_inode = (struct _inode *) fp->f_data; - struct jffs2_dirent *ent = (struct jffs2_dirent *) uio->uio_iov[0].iov_base; - char *nbuf = ent->d_name; - int nlen = sizeof(ent->d_name) - 1; - off_t len = uio->uio_iov[0].iov_len; - struct jffs2_inode_info *f; - struct _inode *inode = d_inode; - struct jffs2_full_dirent *fd; - unsigned long offset, curofs; - int found = 1; - - jffs2_dbg(1, "read at: 0x%x \n", fp->f_data); - - if (len < (off_t)sizeof (struct jffs2_dirent)) - return EINVAL; - - if (CheckPermission(inode, READ_OP)) { - return EACCES; - } - - D1(printk - (KERN_DEBUG "jffs2_readdir() for dir_i #%lu\n", d_inode->i_ino)); - - f = JFFS2_INODE_INFO(inode); - - offset = fp->f_offset; - if (offset == 0) { - D1(printk - (KERN_DEBUG "Dirent 0: \".\", ino #%lu\n", inode->i_ino)); - filldir(nbuf, nlen, (const unsigned char *) ".", 1); -#ifdef CYGPKG_FS_JFFS2_RET_DIRENT_DTYPE - // Flags here are the same as jffs2_mkdir. Make sure - // d_type is the same as st_mode of calling stat. - ent->d_type = - jemode_to_cpu(cpu_to_jemode(S_IRUGO | S_IXUGO | S_IWUSR | S_IFDIR)); -#endif - goto out; - } - if (offset == 1) { - filldir(nbuf, nlen, (const unsigned char *) "..", 2); -#ifdef CYGPKG_FS_JFFS2_RET_DIRENT_DTYPE - // Flags here are the same as jffs2_mkdir. Make sure - // d_type is the same as st_mode of calling stat. - ent->d_type = - jemode_to_cpu(cpu_to_jemode(S_IRUGO | S_IXUGO | S_IWUSR | S_IFDIR)); -#endif - goto out; - } - curofs = 1; - mutex_lock(&f->sem); - for (fd = f->dents; fd; fd = fd->next) { - curofs++; - /* First loop: curofs = 2; offset = 2 */ - if (curofs < offset) { - D2(printk - (KERN_DEBUG - "Skipping dirent: \"%s\", ino #%u, type %d, because curofs %ld < offset %ld\n", - fd->name, fd->ino, fd->type, curofs, offset)); - continue; - } - if (!fd->ino) { - D2(printk - (KERN_DEBUG "Skipping deletion dirent \"%s\"\n", - fd->name)); - offset++; - continue; - } - D2(printk - (KERN_DEBUG "Dirent %ld: \"%s\", ino #%u, type %d\n", offset, - fd->name, fd->ino, fd->type)); - filldir(nbuf, nlen, fd->name, strlen((char *)fd->name)); - ent->d_type = fd->type; - goto out_sem; - } - /* Reached the end of the directory */ - found = 0; - out_sem: - mutex_unlock(&f->sem); - if (fd == NULL) { - D2(printk - (KERN_DEBUG "reached the end of the directory\n")); - return ENOENT; - } - out: - fp->f_offset = ++offset; - - - if (found) { - uio->uio_resid -= sizeof (struct jffs2_dirent); - } - return ENOERR; -} - -static int jffs2_fo_dirlseek(struct CYG_FILE_TAG *fp, off_t *pos, int whence) -{ - // Only allow SEEK_SET to zero - jffs2_dbg(1, "lseekdir at: %d \n", whence); - - if (whence != SEEK_SET || *pos != 0) - return EINVAL; - - *pos = fp->f_offset = 2; - - return ENOERR; -} - -//========================================================================== -// -// Called by JFFS2 -// =============== -// -// -//========================================================================== - -unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c, - struct jffs2_inode_info *f, - unsigned long offset, - unsigned long *priv) -{ - /* FIXME: This works only with one file system mounted at a time */ - int ret; - - ret = jffs2_read_inode_range(c, f, gc_buffer, - offset & ~(PAGE_CACHE_SIZE-1), PAGE_CACHE_SIZE); - if (ret) - return ERR_PTR(ret); - - return gc_buffer; -} - -void jffs2_gc_release_page(struct jffs2_sb_info *c, - unsigned char *ptr, - unsigned long *priv) -{ - /* Do nothing */ -} - -struct _inode *new_inode(struct super_block *sb) -{ - struct _inode *inode; - struct _inode *cached_inode; - - inode = malloc(sizeof (struct _inode)); - if (inode == NULL) - return 0; - - D2(PRINTK("malloc new_inode %x ####################################\n", - inode)); - - (void)memset_s(inode, sizeof (struct _inode), 0, sizeof (struct _inode)); - inode->i_sb = sb; - inode->i_ino = 1; - inode->i_count = 1; - inode->i_nlink = 1; // Let JFFS2 manage the link count - inode->i_size = 0; - - inode->i_cache_next = NULL; // Newest inode, about to be cached - // Add to the icache - for (cached_inode = sb->s_root; cached_inode != NULL; - cached_inode = cached_inode->i_cache_next) { - if (cached_inode->i_cache_next == NULL) { - cached_inode->i_cache_next = inode; // Current last in cache points to newcomer - inode->i_cache_prev = cached_inode; // Newcomer points back to last - break; - } - } - return inode; -} - -static struct _inode *ilookup(struct super_block *sb, uint32_t ino) -{ - struct _inode *inode = NULL; - - D2(PRINTK("ilookup\n")); - // Check for this inode in the cache - jffs_lock(); - for (inode = sb->s_root; inode != NULL; inode = inode->i_cache_next) { - if (inode->i_ino == ino) { - inode->i_count++; - break; - } - } - jffs_unlock(); - return inode; -} - -struct _inode *jffs2_iget(struct super_block *sb, uint32_t ino) -{ - // Called in super.c jffs2_read_super, dir.c jffs2_lookup, - // and gc.c jffs2_garbage_collect_pass - - // Must first check for cached inode - // If this fails let new_inode create one - - struct _inode *inode; - int err; - - D2(PRINTK("jffs2_iget\n")); - - jffs_lock(); - inode = ilookup(sb, ino); - if (inode) { - jffs_unlock(); - return inode; - } - - // Not cached, so malloc it - - inode = new_inode(sb); - if (inode == NULL) { - jffs_unlock(); - return ERR_PTR(-ENOMEM); - } - inode->i_ino = ino; - err = jffs2_read_inode(inode); - - if (err) { - PRINTK("jffs2_read_inode() failed\n"); - inode->i_nlink = 0; // free _this_ bad inode right now - - jffs2_iput(inode); - jffs_unlock(); - return ERR_PTR(err); - } - - jffs_unlock(); - return inode; -} - -// ------------------------------------------------------------------------- -// Decrement the reference count on an inode. If this makes the ref count -// zero, then this inode can be freed. - -void jffs2_iput(struct _inode *i) -{ - // Called in jffs2_find - // (and jffs2_open and jffs2_ops_mkdir?) - // super.c jffs2_read_super, - // and gc.c jffs2_garbage_collect_pass - struct jffs2_inode_info *f = NULL; - struct _inode *temp = NULL; - jffs_lock(); - recurse: - if (!i) { - PRINT_ERR("jffs2_iput() called with NULL inode\n"); - // and let it fault... - jffs_unlock(); - return; - } - i->i_count--; - if (i->i_count < 0) - BUG(); - - if (i->i_count) { - jffs_unlock(); - return; - } - - if (!i->i_nlink) { - struct _inode *parent; - // Remove from the icache linked list and free immediately - if (i->i_cache_prev) - i->i_cache_prev->i_cache_next = i->i_cache_next; - if (i->i_cache_next) - i->i_cache_next->i_cache_prev = i->i_cache_prev; - parent = i->i_parent; - jffs2_clear_inode(i); - f = JFFS2_INODE_INFO(i); - (void)mutex_destroy(&(f->sem)); - (void)memset_s(i, sizeof(*i), 0x5a, sizeof(*i)); - temp = i; - free(i); - - if (parent && parent != temp) { - i = parent; - goto recurse; - } - - } else { - // Evict some _other_ inode with i_count zero, leaving - // this latest one in the cache for a while - icache_evict(i->i_sb->s_root, i); - } - jffs_unlock(); -} - - -// ------------------------------------------------------------------------- -// EOF jffs2.c - - -static inline void jffs2_init_inode_info(struct jffs2_inode_info *f) -{ - (void)memset_s(f, sizeof(struct jffs2_inode_info), 0, sizeof(struct jffs2_inode_info)); - (void)mutex_init(&f->sem); - (void)mutex_lock(&f->sem); -} - -static void jffs2_clear_inode (struct _inode *inode) -{ - /* We can forget about this inode for now - drop all - * the nodelists associated with it, etc. - */ - struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); - struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode); - - D1(printk(KERN_DEBUG "jffs2_clear_inode(): ino #%lu mode %o\n", inode->i_ino, inode->i_mode)); - - jffs2_do_clear_inode(c, f); -} - - -/* jffs2_new_inode: allocate a new inode and inocache, add it to the hash, - fill in the raw_inode while you're at it. */ -struct _inode *jffs2_new_inode (struct _inode *dir_i, int mode, struct jffs2_raw_inode *ri) -{ - struct _inode *inode; - struct super_block *sb = dir_i->i_sb; - struct jffs2_sb_info *c; - struct jffs2_inode_info *f; - int ret; - - D1(printk(KERN_DEBUG "jffs2_new_inode(): dir_i %ld, mode 0x%x\n", dir_i->i_ino, mode)); - - c = JFFS2_SB_INFO(sb); - - if (CheckPermission(dir_i, WRITE_OP | EXEC_OP)) { - D1(PRINTK("%s, %d, check permission fail\n", __FUNCTION__, __LINE__)); - return ERR_PTR(-EACCES); - } - - jffs_lock(); - inode = new_inode(sb); - if (!inode) { - jffs_unlock(); - return ERR_PTR(-ENOMEM); - } - - f = JFFS2_INODE_INFO(inode); - jffs2_init_inode_info(f); - (void)memset_s(ri, sizeof(*ri), 0, sizeof(*ri)); - /* Set OS-specific defaults for new inodes */ - ri->uid = cpu_to_je16(OsCurrUserGet()->effUserID); - ri->gid = cpu_to_je16(OsCurrUserGet()->effGid); - ri->mode = cpu_to_jemode(mode); - ret = jffs2_do_new_inode (c, f, mode, ri); - if (ret) { - // forceful evict: f->sem is locked already, and the - // inode is bad. - if (inode->i_cache_prev) - inode->i_cache_prev->i_cache_next = inode->i_cache_next; - if (inode->i_cache_next) - inode->i_cache_next->i_cache_prev = inode->i_cache_prev; - mutex_unlock(&(f->sem)); - jffs2_clear_inode(inode); - (void)mutex_destroy(&(f->sem)); - (void)memset_s(inode, sizeof(*inode), 0x6a, sizeof(*inode)); - free(inode); - jffs_unlock(); - return ERR_PTR(ret); - } - inode->i_nlink = 1; - inode->i_ino = je32_to_cpu(ri->ino); - inode->i_mode = jemode_to_cpu(ri->mode); - inode->i_gid = je16_to_cpu(ri->gid); - inode->i_uid = je16_to_cpu(ri->uid); - inode->i_atime = inode->i_ctime = inode->i_mtime = jffs2_get_timestamp(); - ri->atime = ri->mtime = ri->ctime = cpu_to_je32(inode->i_mtime); - - inode->i_size = 0; - jffs_unlock(); - - return inode; -} - - -static int jffs2_read_inode (struct _inode *inode) -{ - struct jffs2_inode_info *f; - struct jffs2_sb_info *c; - struct jffs2_raw_inode latest_node; - int ret; - - D1(printk(KERN_DEBUG "jffs2_read_inode(): inode->i_ino == %lu\n", inode->i_ino)); - - f = JFFS2_INODE_INFO(inode); - c = JFFS2_SB_INFO(inode->i_sb); - - jffs2_init_inode_info(f); - - ret = jffs2_do_read_inode(c, f, inode->i_ino, &latest_node); - - if (ret) { - (void)mutex_unlock(&f->sem); - - return ret; - } - inode->i_mode = jemode_to_cpu(latest_node.mode); - inode->i_uid = je16_to_cpu(latest_node.uid); - inode->i_gid = je16_to_cpu(latest_node.gid); - inode->i_size = je32_to_cpu(latest_node.isize); - inode->i_atime = je32_to_cpu(latest_node.atime); - inode->i_mtime = je32_to_cpu(latest_node.mtime); - inode->i_ctime = je32_to_cpu(latest_node.ctime); - - inode->i_nlink = f->inocache->pino_nlink; - mutex_unlock(&f->sem); - - D1(printk(KERN_DEBUG "jffs2_read_inode() returning\n")); - return 0; -} - - -void jffs2_gc_release_inode(struct jffs2_sb_info *c, - struct jffs2_inode_info *f) -{ - jffs2_iput(OFNI_EDONI_2SFFJ(f)); -} - -struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c, - int inum, int unlinked) -{ - struct _inode *inode; - struct jffs2_inode_cache *ic; - - if (unlinked) { - /* The inode has zero nlink but its nodes weren't yet marked - obsolete. This has to be because we're still waiting for - the final (close() and) jffs2_iput() to happen. - - There's a possibility that the final jffs2_iput() could have - happened while we were contemplating. In order to ensure - that we don't cause a new read_inode() (which would fail) - for the inode in question, we use ilookup() in this case - instead of jffs2_iget(). - - The nlink can't _become_ zero at this point because we're - holding the alloc_sem, and jffs2_do_unlink() would also - need that while decrementing nlink on any inode. - */ - inode = ilookup(OFNI_BS_2SFFJ(c), inum); - if (!inode) { - D1(printk(KERN_DEBUG "ilookup() failed for ino #%u; inode is probably deleted.\n", - inum)); - - spin_lock(&c->inocache_lock); - ic = jffs2_get_ino_cache(c, inum); - if (!ic) { - D1(printk(KERN_DEBUG "Inode cache for ino #%u is gone.\n", inum)); - spin_unlock(&c->inocache_lock); - return NULL; - } - if (ic->state != INO_STATE_CHECKEDABSENT) { - /* Wait for progress. Don't just loop */ - D1(printk(KERN_DEBUG "Waiting for ino #%u in state %d\n", - ic->ino, ic->state)); - sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock); - } else { - spin_unlock(&c->inocache_lock); - } - - return NULL; - } - } else { - /* Inode has links to it still; they're not going away because - jffs2_do_unlink() would need the alloc_sem and we have it. - Just jffs2_iget() it, and if read_inode() is necessary that's OK. - */ - inode = jffs2_iget(OFNI_BS_2SFFJ(c), inum); - if (IS_ERR(inode)) - return (void *)inode; - } - - return JFFS2_INODE_INFO(inode); -} -static int jffs_check_path(const char *path) -{ - int n = 0; - int divs = 0; - while (*path && n < NAME_MAX && divs < 100) { // File depth cannot exceed 100 - if (jffsfs_IsPathDivider(*path)) { - n = 0; - divs++; - } else - n++; - path++; - } - return (*path) ? -1 : 0; -} - -int jffs2_oflag_to_accmode(int oflags) -{ - /* regular file operations */ - int acc_mode = 0; - if ((oflags & O_ACCMODE) == O_RDONLY) { - acc_mode |= READ_OP; - } - - if (oflags & O_WRONLY) { - acc_mode |= WRITE_OP; - } - - if (oflags & O_RDWR) { - acc_mode |= READ_OP | WRITE_OP; - } - - /* Opens the file, if it is existing. If not, a new file is created. */ - if (oflags & O_CREAT) { - acc_mode |= WRITE_OP; - } - - /* Creates a new file. If the file is existing, it is truncated and overwritten. */ - if (oflags & O_TRUNC) { - acc_mode |= WRITE_OP; - } - - /* Creates a new file. The function fails if the file is already existing. */ - if (oflags & O_EXCL) { - acc_mode |= WRITE_OP; - } - - if (oflags & O_APPEND) { - acc_mode |= WRITE_OP; - } - - /* mark for executing operation */ - if (oflags & O_EXECVE) { - acc_mode |= EXEC_OP; - } - - return acc_mode; -} - -static unsigned int CheckPermission(struct _inode *node, int accMode) -{ - uint uid = OsCurrUserGet()->effUserID; - mode_t file_mode = node->i_mode; - - if (uid == node->i_uid) { - file_mode >>= JFFS2_USER_SHFIT; - } else if (LOS_CheckInGroups(node->i_gid)) { - file_mode >>= JFFS2_GROUP_SHFIT; - } - - file_mode &= JFFS2_MODE_ALL; - - if ((accMode & file_mode) == accMode) { - return 0; - } - - file_mode = 0; - if (S_ISDIR(node->i_mode)) { - if ((accMode & EXEC_OP) && (IsCapPermit(CAP_DAC_READ_SEARCH))) { - file_mode |= EXEC_OP; - } - } else { - if ((accMode & EXEC_OP) && (IsCapPermit(CAP_DAC_EXECUTE)) && (node->i_mode & S_IXUGO)) { - file_mode |= EXEC_OP; - } - } - - if ((accMode & WRITE_OP) && IsCapPermit(CAP_DAC_WRITE)) { - file_mode |= WRITE_OP; - } - - if ((accMode & READ_OP) && IsCapPermit(CAP_DAC_READ_SEARCH)) { - file_mode |= READ_OP; - } - - if ((accMode & file_mode) == accMode) { - return 0; - } - - D1(PRINTK("%s, %d, permission check fail,uid %d, gid %d, mode %d, accMode %d, cuid %d\n", - __FUNCTION__, __LINE__, node->i_uid, node->i_gid, (node->i_mode) & UMASK_FULL, accMode, uid)); - - return 1; -} - -static int check_to_setattr(struct jffs2_raw_inode *ri, struct jffs2_inode_info *f, - const struct _inode *node, iattr *attr) -{ - unsigned int valid; - mode_t tmp_mode; - uint c_uid = OsCurrUserGet()->effUserID; - uint c_gid = OsCurrUserGet()->effGid; - - valid = attr->attr_chg_valid; - ri->uid = cpu_to_je16(node->i_uid); - ri->gid = cpu_to_je16(node->i_gid); - tmp_mode = node->i_mode; - if (valid & CHG_UID) { - if (((c_uid != node->i_uid) || (attr->attr_chg_uid != node->i_uid)) && (!IsCapPermit(CAP_CHOWN))) { - return -EPERM; - } else { - ri->uid = cpu_to_je16(attr->attr_chg_uid); - } - } - - if (valid & CHG_GID) { - if (((c_gid != node->i_gid) || (attr->attr_chg_gid != node->i_gid)) && (!IsCapPermit(CAP_CHOWN))) { - return -EPERM; - } else { - ri->gid = cpu_to_je16(attr->attr_chg_gid); - } - } - - if (valid & CHG_MODE) { - if (!IsCapPermit(CAP_FOWNER) && (c_uid != node->i_uid)) { - return -EPERM; - } else { - attr->attr_chg_mode &= ~S_IFMT; // delete file type - tmp_mode &= S_IFMT; - tmp_mode = attr->attr_chg_mode | tmp_mode; // add old file type - } - } - ri->mode = cpu_to_jemode(tmp_mode); - ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); - ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE); - ri->totlen = cpu_to_je32(sizeof(*ri)); - ri->hdr_crc = cpu_to_je32(crc32(0, ri, (sizeof(struct jffs2_unknown_node)-4))); - ri->ino = cpu_to_je32(node->i_ino); - ri->version = cpu_to_je32(++f->highest_version); - ri->isize = cpu_to_je32((uint32_t)node->i_size); - ri->atime = cpu_to_je32(node->i_atime); - ri->mtime = cpu_to_je32(jffs2_get_timestamp()); - ri->offset = cpu_to_je32(0); - ri->csize = ri->dsize = cpu_to_je32(0); - ri->compr = JFFS2_COMPR_NONE; - ri->node_crc = cpu_to_je32(crc32(0, ri, (sizeof(*ri)-8))); - ri->data_crc = cpu_to_je32(0); - return 0; -} - -int jffs2_chattr (struct _inode *dir_i, const unsigned char *d_name, iattr *attr, struct _inode *node_old) -{ - struct jffs2_inode_info *f = NULL; - struct jffs2_sb_info *c = NULL; - struct jffs2_raw_inode *ri = NULL; - struct jffs2_full_dnode *new_metadata = NULL; - struct jffs2_full_dnode *old_metadata = NULL; - uint32_t alloclen; - int ret; - ri = jffs2_alloc_raw_inode(); - if (!ri) { - set_errno(ENOMEM); - return -ENOMEM; - } - c = JFFS2_SB_INFO(dir_i->i_sb); - /* Try to reserve enough space for both node and dirent. - * Just the node will do for now, though - */ - ret = jffs2_reserve_space(c, sizeof(*ri), &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); - if (ret) { - jffs2_free_raw_inode(ri); - return ret; - } - - f = JFFS2_INODE_INFO(node_old); - mutex_lock(&f->sem); - ret = check_to_setattr(ri, f, node_old, attr); - - if (ret < 0) { - set_errno(-ret); - goto errout; - } - new_metadata = jffs2_write_dnode(c, f, ri, NULL, 0, ALLOC_NORMAL); - if (IS_ERR(new_metadata)) { - ret = PTR_ERR(new_metadata); - set_errno(-ret); - goto errout; - } - node_old->i_atime = je32_to_cpu(ri->atime); - node_old->i_ctime = je32_to_cpu(ri->ctime); - node_old->i_mtime = je32_to_cpu(ri->mtime); - node_old->i_mode = jemode_to_cpu(ri->mode); - node_old->i_uid = je16_to_cpu(ri->uid); - node_old->i_gid = je16_to_cpu(ri->gid); - - old_metadata = f->metadata; - f->metadata = new_metadata; - if (old_metadata) { - jffs2_mark_node_obsolete(c, old_metadata->raw); - jffs2_free_full_dnode(old_metadata); - } - jffs2_complete_reservation(c); - jffs2_free_raw_inode(ri); - mutex_unlock(&f->sem); - return 0; -errout: - jffs2_complete_reservation(c); - jffs2_free_raw_inode(ri); - mutex_unlock(&f->sem); - return ret; -} - -struct los_jffs2_operations jffs2_dir_operations = { - .opendir = jffs2_opendir, - .lseekdir = jffs2_fo_dirlseek, - .readdir = jffs2_fo_dirread, - -}; - -struct los_jffs2_operations jffs2_fs_type = { - .mount = jffs2_mount, - .stat = jffs2_stat, - .umount = jffs2_umount -}; - - -struct los_jffs2_operations jffs2_file_operations = { - .open = jffs2_open, - .close = jffs2_fo_close, - .read = jffs2_fo_read, - .write = jffs2_fo_write, - .lseek = jffs2_fo_lseek, - .chattr = jffs2_fo_chattr -}; - -struct los_jffs2_operations jffs2_dir_inode_operations = { - .mkdir = jffs2_ops_mkdir, - .rmdir = jffs2_ops_rmdir, - .unlink = jffs2_ops_unlink, - .rename = jffs2_ops_rename, -}; diff --git a/components/dfs/filesystems/jffs2/src/os-ecos.h b/components/dfs/filesystems/jffs2/src/os-ecos.h deleted file mode 100644 index 73f121e16f63e01d4e01d6e414751673db37048b..0000000000000000000000000000000000000000 --- a/components/dfs/filesystems/jffs2/src/os-ecos.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * JFFS2 -- Journalling Flash File System, Version 2. - * - * Copyright (C) 2002-2003 Free Software Foundation, Inc. - * - * Created by David Woodhouse - * - * For licensing information, see the file 'LICENCE' in this directory. - * - * $Id: os-ecos.h,v 1.24 2005/02/09 09:23:55 pavlov Exp $ - * - */ - -#ifndef __JFFS2_OS_ECOS_H__ -#define __JFFS2_OS_ECOS_H__ -#include -#include -#include -#include -#include "jffs2_config.h" -#include "los_event.h" -#include "los_mux.h" -#include "los_task.h" -#include "errno.h" -#include "jffs2_fs_i.h" -#include "jffs2_fs_sb.h" -#include "fileio.h" -#include "sys/uio.h" - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -struct jffs2_dirent { -#ifdef CYGPKG_FILEIO_DIRENT_DTYPE - - unsigned long d_type; // Only supported with FATFS, RAMFS, ROMFS, - // and JFFS2. - // d_type is not part of POSIX so - // should be used with caution. -#endif - char d_name[JFFS2_NAME_MAX+1]; -}; - -struct _inode; -struct super_block; - -static inline unsigned int full_name_hash(const unsigned char * name, unsigned int len) { - - unsigned hash = 0; - while (len--) { - hash = (hash << 4) | (hash >> 28); - hash ^= *(name++); - } - return hash; -} - -#ifdef CYGOPT_FS_JFFS2_WRITE -#define jffs2_is_readonly(c) (0) -#else -#define jffs2_is_readonly(c) (1) -#endif - -#define JFFS2_INODE_INFO(i) (&(i)->jffs2_i) -#define OFNI_EDONI_2SFFJ(f) \ - ((struct _inode *) ( ((char *)f) - ((char *)(&((struct _inode *)NULL)->jffs2_i)) ) ) - -#define JFFS2_F_I_SIZE(f) (OFNI_EDONI_2SFFJ(f)->i_size) -#define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode) -#define JFFS2_F_I_UID(f) (OFNI_EDONI_2SFFJ(f)->i_uid) -#define JFFS2_F_I_GID(f) (OFNI_EDONI_2SFFJ(f)->i_gid) -#define JFFS2_F_I_CTIME(f) (OFNI_EDONI_2SFFJ(f)->i_ctime) -#define JFFS2_F_I_MTIME(f) (OFNI_EDONI_2SFFJ(f)->i_mtime) -#define JFFS2_F_I_ATIME(f) (OFNI_EDONI_2SFFJ(f)->i_atime) - -#define JFFS2_F_I_RDEV_MIN(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)&0xff) -#define JFFS2_F_I_RDEV_MAJ(f) ((OFNI_EDONI_2SFFJ(f)->i_rdev)>>8) - -#define get_seconds jffs2_get_timestamp - -struct _inode { - uint32_t i_ino; - int i_count; - mode_t i_mode; - nlink_t i_nlink; // Could we dispense with this? - uid_t i_uid; - gid_t i_gid; - time_t i_atime; - time_t i_mtime; - time_t i_ctime; -// union { - unsigned short i_rdev; // For devices only - struct _inode * i_parent; // For directories only - off_t i_size; // For files only -// }; - struct super_block * i_sb; - - struct jffs2_inode_info jffs2_i; - - struct _inode * i_cache_prev; // We need doubly-linked? - struct _inode * i_cache_next; -}; - -#define JFFS2_SB_INFO(sb) (&(sb)->jffs2_sb) -#define OFNI_BS_2SFFJ(c) \ - ((struct super_block *) ( ((char *)c) - ((char *)(&((struct super_block *)NULL)->jffs2_sb)) ) ) -typedef void* cyg_io_handle_t; - -struct super_block { - struct jffs2_sb_info jffs2_sb; - struct _inode * s_root; - unsigned long s_mount_count; - cyg_io_handle_t s_dev; - -#ifdef CYGOPT_FS_JFFS2_GCTHREAD - UINT32 s_lock; // Lock the inode cache - EVENT_CB_S s_gc_thread_flags; // Communication with the gcthread - unsigned int s_gc_thread; -#endif - -}; - -#ifndef BUG_ON -#define BUG_ON(x) do {if (unlikely(x)) BUG();} while (0) -#endif - -// fs-ecos.c - -int jffs2_oflag_to_accmode(int oflags); - - -#ifdef __cplusplus -#if __cplusplus -} -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -#endif /* __JFFS2_OS_ECOS_H__ */ diff --git a/components/dfs/filesystems/jffs2/vfs_jffs2.c b/components/dfs/filesystems/jffs2/vfs_jffs2.c deleted file mode 100755 index 506f6e37d3ee0bb587d2712155366a227736862d..0000000000000000000000000000000000000000 --- a/components/dfs/filesystems/jffs2/vfs_jffs2.c +++ /dev/null @@ -1,690 +0,0 @@ -/* - * Copyright (c) 2006-2018, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2012-1-7 prife the first version - */ - -#include "los_typedef.h" -#include "fileio.h" -#include "fcntl.h" -#include "sys/stat.h" -#undef mode_t - -#include "vfs_jffs2.h" -#include "jffs2_config.h" -#include "porting.h" -#include "los_mux.h" -#include "inode/inode.h" -#include "sys/statfs.h" -#include "fs/dirent_fs.h" -#include "fs/fs.h" -#include "los_tables.h" -#include "mtd_list.h" -#include "port/fcntl.h" -#include "los_vm_filemap.h" - -#ifdef LOSCFG_FS_JFFS - -#if DEVICE_PART_MAX > 1 - #error "support only one jffs2 partition on a flash device!" -#endif - -LosMux jffs2_lock; -cyg_mtab_entry *mte[CONFIG_MTD_PATTITION_NUM]; -static const char jffs2_root_path[] = "."; -#define BLOCK_SIZE 4096 - -int jffs2_result_to_vfs(int result) -{ - if (result > 0) - result = -result; - return result; -} - -struct inode *jffs_block[CONFIG_MTD_PATTITION_NUM]; -static int vfs_jffs_bind(FAR struct inode *blkdriver, - FAR const void *data, - FAR void **handle, - FAR const char *relpath) -{ - int result; - mtd_partition *p = (mtd_partition *)blkdriver->i_private; - int partition_num = p->patitionnum; - struct MtdDev *mtd = (struct MtdDev *)(p->mtd_info); - /* find a empty entry in partition table */ - if (mtd == NULL) { - return -EINVAL; - } - if (mtd->type != MTD_NORFLASH) { - return -EINVAL; - } - - mte[partition_num] = (cyg_mtab_entry*)malloc(sizeof(cyg_mtab_entry)); - if (mte[partition_num] == NULL) { - return -ENOMEM; - } - - mte[partition_num]->name = "jffs2"; - - /* note that, i use mte->n_private to store rtt's device - * while, in jffs2_mount, mte->n_private will be copy into - * s_dev in struct super_block, and mte->n_private will be - * filled with jffs2_sb(see the source of jffs2_mount. - */ - /* after jffs2_mount, mte->n_private will not be dev_id any more */ - result = jffs2_fs_type.mount(mte[partition_num], partition_num); - if (result != 0) { - free(mte[partition_num]); - mte[partition_num] = NULL; - return jffs2_result_to_vfs(result); - } - *handle = (void *)p; - jffs_block[partition_num] = blkdriver; - return 0; -} - -static int vfs_jffs_unbind(FAR void *handle, FAR struct inode **blkdriver) -{ - int result; - mtd_partition *p = (mtd_partition *)handle; - int partition_num; - - if (p == NULL) - return -EINVAL; - - partition_num = p->patitionnum; - result = jffs2_fs_type.umount(mte[partition_num]); - if (result) - return jffs2_result_to_vfs(result); - - free(mte[partition_num]); - mte[partition_num] = NULL; - free(p->mountpoint_name); - p->mountpoint_name = NULL; - *blkdriver = jffs_block[partition_num]; - return 0; -} - -static bool oflag_convert_and_check(FAR struct file *filep, int oflags) -{ - int acc_mode = 0; - if ((oflags & O_ACCMODE) == O_RDONLY) - acc_mode |= READ_OP; - if (oflags & O_WRONLY) - acc_mode |= WRITE_OP; - if (oflags & O_RDWR) - acc_mode |= READ_OP | WRITE_OP; - - if (oflags & O_CREAT) - acc_mode |= WRITE_OP; - - if (oflags & O_TRUNC) - acc_mode |= WRITE_OP; - - if (oflags & O_EXCL) - acc_mode |= WRITE_OP; - if (oflags & O_APPEND) - acc_mode |= WRITE_OP; - - if (oflags & O_EXECVE) - acc_mode |= EXEC_OP; - - if (filep->f_inode->mountflags == MS_RDONLY && (acc_mode & WRITE_OP) != 0) { - return false; - } - return true; -} - - -static int vfs_jffs_open(FAR struct file *filep, - FAR const char *relpath, - int oflags, - mode_t mode) -{ - int result; - int partition_num; - const char *name = NULL; - - cyg_file *jffs2_file = NULL; - mtd_partition *p = NULL; - - p = (mtd_partition *)filep->f_inode->i_private; - partition_num = p->patitionnum; - jffs2_file = malloc(sizeof(cyg_file)); - if (jffs2_file == NULL) { - return -ENOMEM; - } - name = relpath; - if ((name[0] == '/') && (name[1] == 0)) - name = jffs2_root_path; - else if (name[0] == '/') /* name[0] still will be '/' */ - name++; - - if (oflag_convert_and_check(filep, oflags) != true) { - free(jffs2_file); - return -EACCES; - } - - - if (oflags & O_DIRECTORY) { /* operations about dir */ - free(jffs2_file); - return -EACCES; - } - - - jffs_mutex_take(&jffs2_lock, (uint32_t)JFFS_WAITING_FOREVER); - result = jffs2_file_operations.open(mte[partition_num], name, oflags, mode, jffs2_file); - if (result != 0) { - jffs_mutex_release(&jffs2_lock); - free(jffs2_file); - return jffs2_result_to_vfs(result); - } - /* save this pointer, it will be used when calling read(),write(), - * flush(), lessk(), and will be free when calling close() - */ - filep->f_priv = jffs2_file; - filep->f_pos = jffs2_file->f_offset; - jffs_mutex_release(&jffs2_lock); - return 0; -} - -static int vfs_jffs_close(FAR struct file *filep) -{ - int result; - cyg_file *jffs2_file = NULL; - - LOS_ASSERT(filep->f_priv != NULL); - jffs2_file = (cyg_file *)(filep->f_priv); - - /* regular file operations */ - jffs_mutex_take(&jffs2_lock, (uint32_t)JFFS_WAITING_FOREVER); - result = jffs2_file_operations.close(jffs2_file); - jffs_mutex_release(&jffs2_lock); - if (result) { - return jffs2_result_to_vfs(result); - } - return 0; -} - -static ssize_t vfs_jffs_read(FAR struct file *filep, FAR char *buffer, size_t buflen) -{ - cyg_file *jffs2_file = NULL; - struct CYG_UIO_TAG uio_s; - struct CYG_IOVEC_TAG iovec; - int result; - - LOS_ASSERT(filep->f_priv != NULL); - jffs2_file = (cyg_file *)(filep->f_priv); - uio_s.uio_iov = &iovec; - uio_s.uio_iov->iov_base = buffer; - uio_s.uio_iov->iov_len = buflen; - uio_s.uio_iovcnt = 1; /* must be 1 */ - uio_s.uio_resid = uio_s.uio_iov->iov_len; /* seem no use in jffs2 */ - - jffs_mutex_take(&jffs2_lock, (uint32_t)JFFS_WAITING_FOREVER); - result = jffs2_file_operations.read(jffs2_file, &uio_s); - jffs_mutex_release(&jffs2_lock); - if (result) - return jffs2_result_to_vfs(result); - - /* update position */ - filep->f_pos= (loff_t)jffs2_file->f_offset; - return uio_s.uio_iov->iov_len - uio_s.uio_resid; -} - -static ssize_t vfs_jffs_write(FAR struct file *filep, - FAR const char *buffer, - size_t buflen) -{ - cyg_file *jffs2_file = NULL; - struct CYG_UIO_TAG uio_s; - struct CYG_IOVEC_TAG iovec; - int result; - - if (filep->f_inode->mountflags == MS_RDONLY) { - return -EACCES; - } - - LOS_ASSERT(filep->f_priv != NULL); - jffs2_file = (cyg_file *)(filep->f_priv); - uio_s.uio_iov = &iovec; - uio_s.uio_iov->iov_base = (void *)buffer; - uio_s.uio_iov->iov_len = buflen; - uio_s.uio_iovcnt = 1; /* must be 1 */ - - uio_s.uio_resid = uio_s.uio_iov->iov_len; /* seem no use in jffs2 */ - - jffs_mutex_take(&jffs2_lock, (uint32_t)JFFS_WAITING_FOREVER); - result = jffs2_file_operations.write(jffs2_file, &uio_s); - jffs_mutex_release(&jffs2_lock); - /* update position */ - filep->f_pos = (loff_t)jffs2_file->f_offset; - if (result) { - return jffs2_result_to_vfs(result); - } - return uio_s.uio_iov->iov_len - uio_s.uio_resid; -} -static off_t vfs_jffs_seek(FAR struct file *filep, off_t offset, int whence) -{ - cyg_file *jffs2_file = NULL; - int result; - LOS_ASSERT(filep->f_priv != NULL); - jffs2_file = (cyg_file *)(filep->f_priv); - - /* set offset as current offset */ - jffs_mutex_take(&jffs2_lock, (uint32_t)JFFS_WAITING_FOREVER); - result = jffs2_file_operations.lseek(jffs2_file, &offset, whence); - jffs_mutex_release(&jffs2_lock); - if (result) - return jffs2_result_to_vfs(result); - /* update file position */ - filep->f_pos = (loff_t)offset; - return offset; -} - -static loff_t vfs_jffs_seek64(FAR struct file *filep, loff_t offset, int whence) -{ - return (loff_t)vfs_jffs_seek(filep, (off_t)offset, whence); -} - -static int vfs_jffs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) -{ - PRINT_DEBUG("%s NOT SUPPORT\n", __FUNCTION__); - return -ENOSYS; -} - -static int vfs_jffs_sync(FAR struct file *filep) -{ - PRINT_DEBUG("%s NOT SUPPORT\n", __FUNCTION__); - return -ENOSYS; -} - -static int vfs_jffs_dup(FAR const struct file *oldp, FAR struct file *newp) -{ - PRINT_DEBUG("%s NOT SUPPORT\n", __FUNCTION__); - return -ENOSYS; -} - -static int vfs_jffs_opendir(FAR struct inode *mountpt, - FAR const char *relpath, - FAR struct fs_dirent_s *dir) -{ -#ifdef CONFIG_JFFS2_NO_RELATIVEDIR - #define FILE_OFFSET 2 -#endif - int result; - cyg_file *jffs2_file = NULL; - mtd_partition *p = (mtd_partition *)mountpt->i_private; - int partition_num = p->patitionnum; - - jffs2_file = malloc(sizeof(cyg_file)); - if (jffs2_file == NULL) - return -ENOMEM; - - /* just escape '/' provided by vfs code */ - if ((relpath[0] == '/') && (relpath[1] == 0)) - relpath = jffs2_root_path; - else if (relpath[0] == '/') /* name[0] still will be '/' */ - relpath ++; - - /* open dir */ - jffs_mutex_take(&jffs2_lock, (uint32_t)JFFS_WAITING_FOREVER); - result = jffs2_dir_operations.opendir(mte[partition_num], relpath, jffs2_file); - jffs_mutex_release(&jffs2_lock); - if (result) { - free(jffs2_file); - return jffs2_result_to_vfs(result); - } -#ifdef CONFIG_JFFS2_NO_RELATIVEDIR - jffs2_file->f_offset = FILE_OFFSET; -#endif - dir->u.fs_dir = (fs_dir_s)jffs2_file; - /* save this pointer, it will be used by vfs_jffs2_getdents */ - return 0; - -} - -static int vfs_jffs_closedir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir) -{ - int result; - cyg_file *jffs2_file = NULL; - jffs2_file = (cyg_file *)dir->u.fs_dir; - jffs_mutex_take(&jffs2_lock, (uint32_t)JFFS_WAITING_FOREVER); - result = jffs2_file_operations.close(jffs2_file); - jffs_mutex_release(&jffs2_lock); - if (result) - return jffs2_result_to_vfs(result); - return 0; -} - -static int vfs_jffs_readdir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir) -{ - cyg_file *jffs2_file = NULL; - struct CYG_UIO_TAG uio_s; - struct CYG_IOVEC_TAG iovec; - struct jffs2_dirent jffs2_d; - int result; - int i = 0; - uint32_t dst_name_size; - - jffs2_file = (cyg_file *)(dir->u.fs_dir); - - while (i < MAX_DIRENT_NUM && i < dir->read_cnt) { - /* set jffs2_d */ - (void)memset_s(&jffs2_d, sizeof(struct jffs2_dirent), 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; */ - - jffs_mutex_take(&jffs2_lock, (uint32_t)JFFS_WAITING_FOREVER); - result = jffs2_dir_operations.readdir(jffs2_file, &uio_s); - jffs_mutex_release(&jffs2_lock); - - if (result) { - break; - } - - dir->fd_dir[i].d_type = jffs2_d.d_type; - dst_name_size = sizeof(dir->fd_dir[i].d_name); - result = strncpy_s(dir->fd_dir[i].d_name, dst_name_size, jffs2_d.d_name, dst_name_size - 1); - if (result != EOK) { - return -ENAMETOOLONG; - } - dir->fd_dir[i].d_name[dst_name_size - 1] = '\0'; - dir->fd_position++; - dir->fd_dir[i].d_off = dir->fd_position; - dir->fd_dir[i].d_reclen = (uint16_t)sizeof(struct dirent); - - i++; - } - return i; -} - -static int vfs_jffs_rewinddir(FAR struct inode *mountpt, - FAR struct fs_dirent_s *dir) -{ - int result; - off_t pos = 0; - cyg_file *jffs2_file = (cyg_file *)(dir->u.fs_dir); - - jffs_mutex_take(&jffs2_lock, (uint32_t)JFFS_WAITING_FOREVER); - result = jffs2_dir_operations.lseekdir(jffs2_file, &pos, SEEK_SET); - jffs_mutex_release(&jffs2_lock); - - if (result) - return jffs2_result_to_vfs(result); - return OK; -} - -static int vfs_jffs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, mode_t mode) -{ - int result; - mtd_partition *p = (mtd_partition *)mountpt->i_private; - int partition_num = p->patitionnum; - /* deal path */ - if (relpath[0] == '/') - relpath++; - - if (mountpt->mountflags == MS_RDONLY) - return -EACCES; - - jffs_mutex_take(&jffs2_lock, (uint32_t)JFFS_WAITING_FOREVER); - result = jffs2_dir_inode_operations.mkdir(mte[partition_num], relpath, mode); - jffs_mutex_release(&jffs2_lock); - - if (result) - return jffs2_result_to_vfs(result); - return OK; -} - -static int vfs_jffs_chattr(FAR struct inode *mountpt, FAR const char *relpath, iattr *attr) -{ - int result; - mtd_partition *p = (mtd_partition *)mountpt->i_private; - int partition_num = p->patitionnum; - /* deal path */ - if (relpath[0] == '/') - relpath++; - - if (mountpt->mountflags == MS_RDONLY) - return -EACCES; - - jffs_mutex_take(&jffs2_lock, (uint32_t)JFFS_WAITING_FOREVER); - result = jffs2_file_operations.chattr(mte[partition_num],relpath, attr); - jffs_mutex_release(&jffs2_lock); - - if (result) - return jffs2_result_to_vfs(result); - return OK; -} - - -static int vfs_jffs_rmdir(FAR struct inode *mountpt, FAR const char *relpath) -{ - int result; - mtd_partition *p = (mtd_partition *)mountpt->i_private; - int partition_num = p->patitionnum; - - /* deal path */ - if (relpath[0] == '/') - relpath++; - else if (relpath[0] == '\0') - return -EBUSY; - - if (mountpt->mountflags == MS_RDONLY) - return -EACCES; - - jffs_mutex_take(&jffs2_lock, (uint32_t)JFFS_WAITING_FOREVER); - result = jffs2_dir_inode_operations.rmdir(mte[partition_num], relpath); - jffs_mutex_release(&jffs2_lock); - - if (result) - return jffs2_result_to_vfs(result); - return OK; -} - -static int vfs_jffs_unlink(FAR struct inode *mountpt, FAR const char *relpath) -{ - int result; - mtd_partition *p = (mtd_partition *)mountpt->i_private; - int partition_num = p->patitionnum; - struct jffs2_stat s; - /* deal path */ - if (relpath[0] == '/') - relpath++; - - if (mountpt->mountflags == MS_RDONLY) - return -EACCES; - - /* judge file type, dir is to be delete by rmdir, others by unlink */ - jffs_mutex_take(&jffs2_lock, (uint32_t)JFFS_WAITING_FOREVER); - result = jffs2_fs_type.stat(mte[partition_num],relpath, &s); - if (result) { - jffs_mutex_release(&jffs2_lock); - return jffs2_result_to_vfs(result); - } - switch (s.st_mode & JFFS2_S_IFMT) { - case JFFS2_S_IFREG: - result = jffs2_dir_inode_operations.unlink(mte[partition_num],relpath); - break; - case JFFS2_S_IFDIR: - result = -EISDIR; - break; - default: - /* unknown file type */ - jffs_mutex_release(&jffs2_lock); - return -1; - } - jffs_mutex_release(&jffs2_lock); - if (result) - return jffs2_result_to_vfs(result); - return 0; -} - -static int vfs_jffs_rename(FAR struct inode *mountpt, - FAR const char *oldrelpath, - FAR const char *newrelpath) -{ - int result; - mtd_partition *p = (mtd_partition *)mountpt->i_private; - int partition_num = p->patitionnum; - if (*oldrelpath == '/') - oldrelpath += 1; - if (*newrelpath == '/') - newrelpath += 1; - - if (mountpt->mountflags == MS_RDONLY) - return -EACCES; - - jffs_mutex_take(&jffs2_lock, (uint32_t)JFFS_WAITING_FOREVER); - result = jffs2_dir_inode_operations.rename(mte[partition_num],oldrelpath,newrelpath); - jffs_mutex_release(&jffs2_lock); - if (result) - return jffs2_result_to_vfs(result); - return 0; -} - -static int vfs_jffs_stat(FAR struct inode *mountpt, - FAR const char *relpath, - FAR struct stat *buf) -{ - int result; - struct jffs2_stat s; - mtd_partition *p = (mtd_partition *)mountpt->i_private; - int partition_num = p->patitionnum; - - /* deal the path for jffs2 */ - if (relpath[0] == '/') - relpath++; - - jffs_mutex_take(&jffs2_lock, (uint32_t)JFFS_WAITING_FOREVER); - result = jffs2_fs_type.stat(mte[partition_num], relpath, &s); - jffs_mutex_release(&jffs2_lock); - - if (result) - return jffs2_result_to_vfs(result); - /* convert to vfs stat structure */ - switch (s.st_mode & JFFS2_S_IFMT) { - case JFFS2_S_IFREG: - buf->st_mode = s.st_mode; - break; - - case JFFS2_S_IFDIR: - buf->st_mode = s.st_mode; - break; - - default: - buf->st_mode = DT_UNKNOWN; /* fixme */ - break; - } - - buf->st_dev = 0; - buf->st_size = s.st_size; - buf->st_mtim.tv_sec = s.sddst_mtime; - buf->st_mtim.tv_nsec = 0; - buf->st_atim.tv_sec = s.sddst_atime; - buf->st_atim.tv_nsec = 0; - buf->st_ctim.tv_sec = s.sddst_ctime; - buf->st_ctim.tv_nsec = 0; - buf->st_blksize = BLOCK_SIZE; /* fixme: what's this field? */ - buf->st_ino = s.st_ino; - buf->st_gid = s.st_gid; - buf->st_uid = s.st_uid; - buf->st_nlink = s.st_nlink; - buf->st_blocks = s.st_size / BLOCK_SIZE; - - return 0; -} - -static int vfs_jffs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) -{ - /* since the limit of unsigned long, so the max size of flash device is 4G */ - struct jffs2_fs_info info; - mtd_partition *p = (mtd_partition *)mountpt->i_private; - int partition_num = p->patitionnum; - LOS_ASSERT(mte[partition_num]->data != 0); - - jffs2_get_info_from_sb((void *)mte[partition_num]->data, &info); - buf->f_type = JFFS2_SUPER_MAGIC; - buf->f_bsize = JFFS2_PAGE_SIZE; - buf->f_blocks = (((uint64_t)info.nr_blocks) * info.sector_size) / JFFS2_PAGE_SIZE; - buf->f_bfree = info.free_size / JFFS2_PAGE_SIZE; - buf->f_bavail = buf->f_bfree; - buf->f_namelen = CONFIG_JFFS2_ENTRY_NAME_MAX; - buf->f_fsid.__val[0] = JFFS2_SUPER_MAGIC; - buf->f_fsid.__val[1] = 1; - buf->f_frsize = BLOCK_SIZE; - buf->f_files = 0; - buf->f_ffree = 0; - buf->f_flags = mountpt->mountflags; - return 0; -} - -int JffsMutexCreate(void) -{ - if (LOS_MuxInit(&jffs2_lock, NULL) != LOS_OK) { - PRINT_ERR("%s, LOS_MuxCreate failed\n", __FUNCTION__); - return -1; - } else { - return 0; - } -} - -void JffsMutexDelete(void) -{ - (void)LOS_MuxDestroy(&jffs2_lock); -} - -const struct mountpt_operations jffs_operations = { - vfs_jffs_open, /* open */ - vfs_jffs_close, /* close */ - vfs_jffs_read, /* read */ - vfs_jffs_write, /* write */ - vfs_jffs_seek, /* seek */ - vfs_jffs_ioctl, /* ioctl */ - OsVfsFileMmap, /* mmap */ - - vfs_jffs_sync, /* sync */ - vfs_jffs_dup, /* dup */ - NULL, /* fstat */ - NULL, /* truncate */ - - vfs_jffs_opendir, /* opendir */ - vfs_jffs_closedir, /* closedir */ - vfs_jffs_readdir, /* readdir */ - - vfs_jffs_rewinddir, /* rewinddir */ - - vfs_jffs_bind, /* bind */ - vfs_jffs_unbind, /* unbind */ - vfs_jffs_statfs, /* statfs */ - NULL, /* virstatfs */ - vfs_jffs_unlink, /* unlinke */ - vfs_jffs_mkdir, /* mkdir */ - vfs_jffs_rmdir, /* rmdir */ - vfs_jffs_rename, /* rename */ - vfs_jffs_stat, /* stat */ - NULL, /* for utime */ - vfs_jffs_chattr, /* chattr */ - vfs_jffs_seek64, /* seek64 */ - NULL, /* getlabel */ - NULL, /* fallocate Contiguous blocks */ - NULL, /* fallocate64 */ - NULL, /* truncate64 */ - NULL, /* fscheck */ - NULL, /* map_pages */ - NULL, /* readpage */ - NULL, /* writepage */ -}; - -FSMAP_ENTRY(jffs_fsmap, "jffs2", jffs_operations, TRUE, TRUE); - -#endif diff --git a/components/dfs/filesystems/jffs2/vfs_jffs2.h b/components/dfs/filesystems/jffs2/vfs_jffs2.h deleted file mode 100644 index f0d46d1658cf449df213ba2fc3872297baf671dc..0000000000000000000000000000000000000000 --- a/components/dfs/filesystems/jffs2/vfs_jffs2.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2006-2018, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - */ -#ifndef __DFS_JFFS2_H__ -#define __DFS_JFFS2_H__ - -#include "mtd_partition.h" -#include "os-ecos.h" -#include "fileio.h" - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -#ifndef NOR_FLASH_BOOT_SIZE -#define NOR_FLASH_BOOT_SIZE 0x100000 -#endif - -#define JFFS_WAITING_FOREVER -1 /* Block forever until get resource. */ - - -struct los_jffs2_operations { - int (*mount) (cyg_mtab_entry *mte, int partition_num); - int (*stat) (cyg_mtab_entry *mte, const char *name, struct jffs2_stat *buf); - int (*open) (cyg_mtab_entry *mte, const char *name, int flags, - int mode, cyg_file *fte); - int (*close) (struct CYG_FILE_TAG *fp); - int (*read) (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio); - int (*write) (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio); - int (*lseek) (struct CYG_FILE_TAG *fp, off_t *apos, int whence); - int (*opendir) (cyg_mtab_entry *mte, const char *name, cyg_file *fte); - int (*mkdir) (cyg_mtab_entry *mte, const char *name, int mode); - int (*rmdir) (cyg_mtab_entry *mte, const char *name); - int (*unlink) (cyg_mtab_entry *mte, const char *name); - int (*rename) (cyg_mtab_entry *mte, const char *name1, const char *name2); - int (*readdir) (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio); - int (*lseekdir) (struct CYG_FILE_TAG *fp, off_t *pos, int whence); - int (*umount) (cyg_mtab_entry *mte); - int (*chattr) (cyg_mtab_entry *mte, const char *name, iattr *attr); -}; - -extern struct los_jffs2_operations jffs2_fs_type; -extern struct los_jffs2_operations jffs2_file_operations; -extern struct los_jffs2_operations jffs2_dir_operations; -extern struct los_jffs2_operations jffs2_dir_inode_operations; - -int JffsMutexCreate(void); -void JffsMutexDelete(void); - -#ifdef __cplusplus -#if __cplusplus -} -#endif /* __cplusplus */ -#endif /* __cplusplus */ - -#endif