注解根文件系统

    百万汉字注解 + 百篇博客分析 => 挖透鸿蒙内核源码
    博客输出站点(国内):http://weharmonyos.com
    博客输出站点(国外):https://openharmony.github.io
    注解文件系统:https://gitee.com/weharmony/third_party_NuttX
    注解协议栈:https://gitee.com/weharmony/third_party_lwip
    注解编译子系统:https://gitee.com/weharmony/build_lite
上级 d01bbdaa
此差异已折叠。
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __MTD_DEV_H__
#define __MTD_DEV_H__
#include "los_typedef.h"
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __MTD_DEV_H__
#define __MTD_DEV_H__
#include "los_typedef.h"
/************************************************
MTD,Memory Technology Device即内存技术设备
Linux系统中采用MTD来管理不同类型的Flash芯片,包括NandFlash和NorFlash
......@@ -47,12 +47,12 @@ NAND型Flash具有较高的单元密度,容量可以做得比较大,加之
为1~16MB闪存市场的大部分,而NAND型Flash只是用在8~128MB的产品中,这也说明NOR主要用在代码存储介质中,
NAND适合数据存储。
************************************************/
#define MTD_NORFLASH 3 //存储空间一般比较小,但它可以不用初始化,可以在其内部运行程序,一般在其存储一些初始化内存的固件代码;
#define MTD_NANDFLASH 4
#define MTD_DATAFLASH 6
#define MTD_MLCNANDFLASH 8
#define MTD_NORFLASH 3 //存储空间一般比较小,但它可以不用初始化,可以在其内部运行程序,一般在其存储一些初始化内存的固件代码;
#define MTD_NANDFLASH 4
#define MTD_DATAFLASH 6
#define MTD_MLCNANDFLASH 8
/*********************************************
扇区是对硬盘而言,而块是对文件系统而言
文件系统不是一个扇区一个扇区的来读数据,一个扇区512个字节,太慢了,所以有了block(块)的概念,
......@@ -63,8 +63,8 @@ struct MtdNorDev {//一个block是4K,即:文件系统中1个块是由连续的
unsigned long blockStart; //开始块索引
unsigned long blockEnd; //结束块索引
};
struct MtdDev {//flash MTD 层 描述符
VOID *priv;
UINT32 type;
......@@ -76,6 +76,6 @@ struct MtdDev {//flash MTD 层 描述符
int (*read)(struct MtdDev *mtd, UINT64 start, UINT64 len, const char *buf);//读操作
int (*write)(struct MtdDev *mtd, UINT64 start, UINT64 len, const char *buf);//写操作
};
#endif /* __MTD_DEV_H__ */
#endif /* __MTD_DEV_H__ */
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @defgroup filesystem FileSystem
* @defgroup mtd_partition Multi Partition
* @ingroup filesystem
*/
#ifndef _MTD_PARTITION_H
#define _MTD_PARTITION_H
#include "sys/types.h"
#include "los_mux.h"
#include "mtd_list.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @defgroup filesystem FileSystem
* @defgroup mtd_partition Multi Partition
* @ingroup filesystem
*/
#ifndef _MTD_PARTITION_H
#define _MTD_PARTITION_H
#include "sys/types.h"
#include "los_mux.h"
#include "mtd_list.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/***************************************************************
* flash按照内部存储结构不同,分为两种:nor flash和nand flash
* Nor FLASH使用方便,易于连接,可以在芯片上直接运行代码,稳定性出色,传输速率高,
......@@ -79,14 +79,14 @@ Nand Flash:芯片操作是以“块”为基本单位.NAND闪存的块比较
参考:https://blog.csdn.net/zhejfl/article/details/78544796
***************************************************************/
#define SPIBLK_NAME "/dev/spinorblk" //nor spi flash 块设备
#define SPICHR_NAME "/dev/spinorchr" //nor spi flash 字符设备
#define NANDBLK_NAME "/dev/nandblk" //nand flash 块设备
#define NANDCHR_NAME "/dev/nandchr" //nand flash 字符设备
/***************************************************************
存储器技术设备(英语:Memory Technology Device,缩写为 MTD),是Linux系统中设备文件系统的一个类别,
主要用于闪存的应用,是一种闪存转换层(Flash Translation Layer,FTL)。创造MTD子系统的主要目的是提供
......@@ -122,7 +122,7 @@ MTD设备通常可分为四层
这四层从上到下依次是:设备节点、MTD设备层、MTD原始设备层和硬件驱动层。
参考: https://blog.csdn.net/lwj103862095/article/details/21545791
***************************************************************/
typedef struct mtd_node {//通过mknod在/dev子目录下建立MTD块设备节点(主设备号为31)和MTD字符设备节点(主设备号为90)
UINT32 start_block; //开始块索引
UINT32 end_block; //结束块索引
......@@ -135,7 +135,7 @@ typedef struct mtd_node {//通过mknod在/dev子目录下建立MTD块设备节
LosMux lock; //每个分区都有自己的互斥锁
UINT32 user_num; //使用数量
} mtd_partition;
typedef struct par_param {//分区参数描述符,一个分区既可支持按块访问也可以支持按字符访问,只要有驱动程序就阔以
mtd_partition *partition_head; //首个分区,其他分区都挂在.node_info节点上
struct MtdDev *flash_mtd; //flash设备描述符,属于硬件驱动层
......@@ -145,87 +145,87 @@ typedef struct par_param {//分区参数描述符,一个分区既可支持按块
CHAR *charname; //字符设备名称
UINT32 block_size; //块单位(4K),对文件系统而言是按块读取数据,方便和内存页置换
} partition_param;
#define CONFIG_MTD_PATTITION_NUM 20 //分区数量的上限
#define ALIGN_ASSIGN(len, startAddr, startBlk, endBlk, blkSize) do { \
(len) = (((len) + ((blkSize) - 1)) & ~((blkSize) - 1)); \
(startAddr) = ((startAddr) & ~((blkSize) - 1)); \
(startBlk) = (startAddr) / (blkSize); \
(endBlk) = (len) / (blkSize) + ((startBlk) - 1); \
} while (0)
#define PAR_ASSIGNMENT(node, len, startAddr, num, mtd, blkSize) do { \
(node)->start_block = (startAddr) / (blkSize); \
(node)->end_block = (len) / (blkSize) + ((node)->start_block - 1); \
(node)->patitionnum = (num); \
(node)->mtd_info = (mtd); \
(node)->mountpoint_name = NULL; \
} while (0)
partition_param *GetNandPartParam(VOID);
partition_param *GetSpinorPartParam(VOID);
mtd_partition *GetSpinorPartitionHead(VOID);
/**
* @ingroup mtd_partition
* @brief Add a partition.
*
* @par Description:
* <ul>
* <li>This API is used to add a partition according to the passed-in parameters.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param type [IN] Storage medium type, support "nand" and "spinor" currently.
* @param startAddr [IN] Starting address of a partition.
* @param length [IN] Partition size.
* @param partitionNum [IN] Partition number, less than the value defined by CONFIG_MTD_PATTITION_NUM.
*
* @retval #-ENODEV The driver is not found.
* @retval #-EINVAL Invalid parameter.
* @retval #-ENOMEM Insufficient memory.
* @retval #ENOERR The partition is successfully created.
*
* @par Dependency:
* <ul><li>mtd_partition.h: the header file that contains the API declaration.</li></ul>
* @see delete_mtd_partition
*/
extern INT32 add_mtd_partition(const CHAR *type, UINT32 startAddr, UINT32 length, UINT32 partitionNum);
/**
* @ingroup mtd_partition
* @brief Delete a partition.
*
* @par Description:
* <ul>
* <li>This API is used to delete a partition according to its partition number and storage medium type.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param partitionNum [IN] Partition number, less than the value defined by CONFIG_MTD_PATTITION_NUM.
* @param type [IN] Storage medium type, support "nand" and "spinor" currently.
*
* @retval #-EINVAL Invalid parameter.
* @retval #ENOERR The partition is successfully deleted.
*
* @par Dependency:
* <ul><li>mtd_partition.h: the header file that contains the API declaration.</li></ul>
* @see add_mtd_partition
*/
extern INT32 delete_mtd_partition(UINT32 partitionNum, const CHAR *type);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _MTD_PARTITION_H */
#define CONFIG_MTD_PATTITION_NUM 20 //分区数量的上限
#define ALIGN_ASSIGN(len, startAddr, startBlk, endBlk, blkSize) do { \
(len) = (((len) + ((blkSize) - 1)) & ~((blkSize) - 1)); \
(startAddr) = ((startAddr) & ~((blkSize) - 1)); \
(startBlk) = (startAddr) / (blkSize); \
(endBlk) = (len) / (blkSize) + ((startBlk) - 1); \
} while (0)
#define PAR_ASSIGNMENT(node, len, startAddr, num, mtd, blkSize) do { \
(node)->start_block = (startAddr) / (blkSize); \
(node)->end_block = (len) / (blkSize) + ((node)->start_block - 1); \
(node)->patitionnum = (num); \
(node)->mtd_info = (mtd); \
(node)->mountpoint_name = NULL; \
} while (0)
partition_param *GetNandPartParam(VOID);
partition_param *GetSpinorPartParam(VOID);
mtd_partition *GetSpinorPartitionHead(VOID);
/**
* @ingroup mtd_partition
* @brief Add a partition.
*
* @par Description:
* <ul>
* <li>This API is used to add a partition according to the passed-in parameters.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param type [IN] Storage medium type, support "nand" and "spinor" currently.
* @param startAddr [IN] Starting address of a partition.
* @param length [IN] Partition size.
* @param partitionNum [IN] Partition number, less than the value defined by CONFIG_MTD_PATTITION_NUM.
*
* @retval #-ENODEV The driver is not found.
* @retval #-EINVAL Invalid parameter.
* @retval #-ENOMEM Insufficient memory.
* @retval #ENOERR The partition is successfully created.
*
* @par Dependency:
* <ul><li>mtd_partition.h: the header file that contains the API declaration.</li></ul>
* @see delete_mtd_partition
*/
extern INT32 add_mtd_partition(const CHAR *type, UINT32 startAddr, UINT32 length, UINT32 partitionNum);
/**
* @ingroup mtd_partition
* @brief Delete a partition.
*
* @par Description:
* <ul>
* <li>This API is used to delete a partition according to its partition number and storage medium type.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param partitionNum [IN] Partition number, less than the value defined by CONFIG_MTD_PATTITION_NUM.
* @param type [IN] Storage medium type, support "nand" and "spinor" currently.
*
* @retval #-EINVAL Invalid parameter.
* @retval #ENOERR The partition is successfully deleted.
*
* @par Dependency:
* <ul><li>mtd_partition.h: the header file that contains the API declaration.</li></ul>
* @see add_mtd_partition
*/
extern INT32 delete_mtd_partition(UINT32 partitionNum, const CHAR *type);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _MTD_PARTITION_H */
......@@ -191,7 +191,7 @@ int VfsProcfsLookup(struct Vnode *parent, const char *name, int len, struct Vnod
(*vpp)->parent = parent;
return LOS_OK;
}
//载实现,找个vnode节点挂上去
//挂s载实现,找个vnode节点挂上去
int VfsProcfsMount(struct Mount *mnt, struct Vnode *device, const void *data)
{
struct Vnode *vp = NULL;
......
......@@ -71,7 +71,7 @@ void los_vfs_init(void)//只能调用一次,多次调用将会造成文件系
files_initialize();
files_initlist(&tg_filelist);
retval = VnodesInit();//虚拟节点初始化
retval = VnodesInit();//索引节点初始化
if (retval != LOS_OK) {
PRINT_ERR("los_vfs_init VnodeInit failed error %d\n", retval);
return;
......
......@@ -41,7 +41,7 @@ static int g_totalVnodeSize = 0; /* total vnode size */ //已分配的总
static LosMux g_vnodeMux; //操作链表互斥量
static struct Vnode *g_rootVnode = NULL;//根节点
static struct VnodeOps g_devfsOps;//设备文件系统节点操作
static struct VnodeOps g_devfsOps;//设备文件节点操作
/*********************************************************
linux下有专门的文件系统(devfs | sysfs)用来对设备进行管理,鸿蒙目前只支持 devfs方式
devfs和sysfs都是和proc一样,是一个虚拟的文件系统,提供了一种类似于文件的方法来管理位于/dev目录下的所有设备,
......@@ -218,7 +218,7 @@ int VnodeFree(struct Vnode *vnode)
vnode->vop->Reclaim(vnode);//先回收资源
}
if (vnode->vop == &g_devfsOps) {//对于设备文件系统的回收
if (vnode->vop == &g_devfsOps) {//对设备文件的回收
/* for dev vnode, just free it */
free(vnode->data);//
free(vnode);
......
......@@ -47,7 +47,7 @@
STATIC CHAR *g_cmdLine = NULL;
STATIC UINT64 g_alignSize = 0;
STATIC struct BootArgs g_bootArgs[MAX_ARGS_NUM] = {0};
//读取环境变量bootcmd 来启动内核
INT32 LOS_GetCmdLine()
{
int ret;
......@@ -59,40 +59,40 @@ INT32 LOS_GetCmdLine()
}
#ifdef LOSCFG_STORAGE_EMMC
los_disk *emmcDisk = los_get_mmcdisk_bytype(EMMC);
los_disk *emmcDisk = los_get_mmcdisk_bytype(EMMC); //获取硬盘信息
if (emmcDisk == NULL) {
PRINT_ERR("Get EMMC disk failed!\n");
goto ERROUT;
}
g_alignSize = EMMC_SEC_SIZE;
ret = los_disk_read(emmcDisk->disk_id, g_cmdLine, COMMAND_LINE_ADDR / EMMC_SEC_SIZE,
COMMAND_LINE_SIZE / EMMC_SEC_SIZE, TRUE);
COMMAND_LINE_SIZE / EMMC_SEC_SIZE, TRUE);//读取命令行内容
if (ret == 0) {
return LOS_OK;
}
#endif
#ifdef LOSCFG_STORAGE_SPINOR
struct MtdDev *mtd = GetMtd("spinor");
struct MtdDev *mtd = GetMtd("spinor");//获取flash描述信息
if (mtd == NULL) {
PRINT_ERR("Get spinor mtd failed!\n");
goto ERROUT;
}
g_alignSize = mtd->eraseSize;
ret = mtd->read(mtd, COMMAND_LINE_ADDR, COMMAND_LINE_SIZE, g_cmdLine);
ret = mtd->read(mtd, COMMAND_LINE_ADDR, COMMAND_LINE_SIZE, g_cmdLine);//读取spinor下的命令行内容
if (ret == COMMAND_LINE_SIZE) {
return LOS_OK;
}
#endif
#ifdef LOSCFG_STORAGE_SPINAND
struct MtdDev *mtd = GetMtd("nand");
struct MtdDev *mtd = GetMtd("nand");//获取flash描述信息
if (mtd == NULL) {
PRINT_ERR("Get nand mtd failed!\n");
goto ERROUT;
}
g_alignSize = mtd->eraseSize;
ret = mtd->read(mtd, COMMAND_LINE_ADDR, COMMAND_LINE_SIZE, g_cmdLine);
ret = mtd->read(mtd, COMMAND_LINE_ADDR, COMMAND_LINE_SIZE, g_cmdLine);//读取nand下的命令行内容
if (ret == COMMAND_LINE_SIZE) {
return LOS_OK;
}
......@@ -125,7 +125,7 @@ VOID LOS_FreeCmdLine()
g_cmdLine = NULL;
}
}
//获取boot参数
STATIC INT32 GetBootargs(CHAR **args)
{
#ifdef LOSCFG_BOOTENV_RAM
......@@ -154,7 +154,7 @@ STATIC INT32 GetBootargs(CHAR **args)
return LOS_NOK;
#endif
}
//解析boot参数
INT32 LOS_ParseBootargs()
{
INT32 idx = 0;
......
......@@ -43,7 +43,7 @@
#define EMMC_SEC_SIZE 512
#endif
struct BootArgs {
struct BootArgs {//模式 | foo=bar
CHAR *argName;
CHAR *argValue;
};
......
......@@ -114,7 +114,7 @@ STATIC INT32 AddEmmcParts(INT32 rootAddr, INT32 rootSize, INT32 userAddr, INT32
}
#endif
//增加一个分区
STATIC INT32 AddPartitions(CHAR *dev, UINT64 rootAddr, UINT64 rootSize, UINT64 userAddr, UINT64 userSize)
{
#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
......@@ -129,7 +129,7 @@ STATIC INT32 AddPartitions(CHAR *dev, UINT64 rootAddr, UINT64 rootSize, UINT64 u
INT32 blk0 = 0;
INT32 blk2 = 2;
if (strcmp(dev, "flash") == 0 || strcmp(dev, FLASH_TYPE) == 0) {
ret = add_mtd_partition(FLASH_TYPE, rootAddr, rootSize, blk0);
ret = add_mtd_partition(FLASH_TYPE, rootAddr, rootSize, blk0);//增加一个MTD分区
if (ret != LOS_OK) {
PRINT_ERR("Failed to add mtd root partition!\n");
return LOS_NOK;
......@@ -155,33 +155,33 @@ STATIC INT32 AddPartitions(CHAR *dev, UINT64 rootAddr, UINT64 rootSize, UINT64 u
return LOS_NOK;
}
//获取根文件系统参数
STATIC INT32 ParseRootArgs(CHAR **dev, CHAR **fstype, UINT64 *rootAddr, UINT64 *rootSize, UINT32 *mountFlags)
{
INT32 ret;
CHAR *rootAddrStr = NULL;
CHAR *rootSizeStr = NULL;
CHAR *rwTag = NULL;
ret = LOS_GetArgValue("root", dev);
//获取文件系统放在哪种设备上
ret = LOS_GetArgValue("root", dev);//root = flash | mmc |
if (ret != LOS_OK) {
PRINT_ERR("Cannot find root!");
return ret;
}
//获取文件系统类型
ret = LOS_GetArgValue("fstype", fstype);
if (ret != LOS_OK) {
PRINT_ERR("Cannot find fstype!");
return ret;
}
//获取内核地址空间开始位置
ret = LOS_GetArgValue("rootaddr", &rootAddrStr);
if (ret != LOS_OK) {
*rootAddr = ROOTFS_ADDR;
} else {
*rootAddr = LOS_SizeStrToNum(rootAddrStr);
}
//获取内核地址空间大小
ret = LOS_GetArgValue("rootsize", &rootSizeStr);
if (ret != LOS_OK) {
*rootSize = ROOTFS_SIZE;
......@@ -221,14 +221,14 @@ STATIC INT32 ParseUserArgs(UINT64 rootAddr, UINT64 rootSize, UINT64 *userAddr, U
return LOS_OK;
}
//挂载分区,即挂载 "/","/storage"
STATIC INT32 MountPartitions(CHAR *fsType, UINT32 mountFlags)
{
INT32 ret;
INT32 err;
/* Mount rootfs */
ret = mount(ROOT_DEV_NAME, ROOT_DIR_NAME, fsType, mountFlags, NULL);
ret = mount(ROOT_DEV_NAME, ROOT_DIR_NAME, fsType, mountFlags, NULL);//挂载根文件系统
if (ret != LOS_OK) {
err = get_errno();
PRINT_ERR("Failed to mount %s, rootDev %s, errno %d: %s\n", ROOT_DIR_NAME, ROOT_DEV_NAME, err, strerror(err));
......@@ -236,13 +236,13 @@ STATIC INT32 MountPartitions(CHAR *fsType, UINT32 mountFlags)
}
/* Mount userfs */
ret = mkdir(STORAGE_DIR_NAME, DEFAULT_MOUNT_DIR_MODE);
ret = mkdir(STORAGE_DIR_NAME, DEFAULT_MOUNT_DIR_MODE);//创建目录"/storage"
if ((ret != LOS_OK) && ((err = get_errno()) != EEXIST)) {
PRINT_ERR("Failed to mkdir %s, errno %d: %s\n", STORAGE_DIR_NAME, err, strerror(err));
return ret;
}
ret = mount(USER_DEV_NAME, STORAGE_DIR_NAME, fsType, 0, DEFAULT_MOUNT_DATA);
ret = mount(USER_DEV_NAME, STORAGE_DIR_NAME, fsType, 0, DEFAULT_MOUNT_DATA);//挂载用户数据文件系统
if (ret != LOS_OK) {
err = get_errno();
PRINT_ERR("Failed to mount %s, errno %d: %s\n", STORAGE_DIR_NAME, err, strerror(err));
......@@ -251,13 +251,13 @@ STATIC INT32 MountPartitions(CHAR *fsType, UINT32 mountFlags)
#ifdef LOSCFG_STORAGE_EMMC
/* Mount userdata */
ret = mkdir(USERDATA_DIR_NAME, DEFAULT_MOUNT_DIR_MODE);
ret = mkdir(USERDATA_DIR_NAME, DEFAULT_MOUNT_DIR_MODE);//创建目录"/userdata"
if ((ret != LOS_OK) && ((err = get_errno()) != EEXIST)) {
PRINT_ERR("Failed to mkdir %s, errno %d: %s\n", USERDATA_DIR_NAME, err, strerror(err));
return ret;
}
ret = mount(USERDATA_DEV_NAME, USERDATA_DIR_NAME, fsType, 0, DEFAULT_MOUNT_DATA);
ret = mount(USERDATA_DEV_NAME, USERDATA_DIR_NAME, fsType, 0, DEFAULT_MOUNT_DATA);//挂载用户数据文件系统
if ((ret != LOS_OK) && ((err = get_errno()) == ENOTSUP)) {
ret = format(USERDATA_DEV_NAME, 0, FM_FAT32);
if (ret != LOS_OK) {
......@@ -294,7 +294,7 @@ STATIC INT32 CheckValidation(UINT64 rootAddr, UINT64 rootSize, UINT64 userAddr,
return LOS_OK;
}
//挂载根文件系统 由 SystemInit 调用
INT32 OsMountRootfs()
{
INT32 ret;
......@@ -305,27 +305,27 @@ INT32 OsMountRootfs()
UINT64 userAddr;
UINT64 userSize;
UINT32 mountFlags;
//获取根文件系统s参数
ret = ParseRootArgs(&dev, &fstype, &rootAddr, &rootSize, &mountFlags);
if (ret != LOS_OK) {
return ret;
}
//获取用户文件参数
ret = ParseUserArgs(rootAddr, rootSize, &userAddr, &userSize);
if (ret != LOS_OK) {
return ret;
}
//检查内核和用户空间的有效性
ret = CheckValidation(rootAddr, rootSize, userAddr, userSize);
if (ret != LOS_OK) {
return ret;
}
//添加分区
ret = AddPartitions(dev, rootAddr, rootSize, userAddr, userSize);
if (ret != LOS_OK) {
return ret;
}
//挂载分区,即挂载 `/`
ret = MountPartitions(fstype, mountFlags);
if (ret != LOS_OK) {
return ret;
......
......@@ -64,7 +64,7 @@ VFS是一种机制、是每一种文件系统都必须按照这个机制去实
#ifdef LOSCFG_STORAGE_SPINOR //外部开关定 使用哪种flash
#define FLASH_TYPE "spinor" //flash类型
#define ROOT_DEV_NAME "/dev/spinorblk0" //设备名称
#define ROOT_DEV_NAME "/dev/spinorblk0" //根设备名称,将挂载到 `/` 目录下
#define USER_DEV_NAME "/dev/spinorblk2"
#define ROOTFS_ADDR 0x600000
#define ROOTFS_SIZE 0x800000
......
git add -A
git commit -m ' 新增文件系统博客 | 同步官方源码
git commit -m ' 注解根文件系统
百万汉字注解 + 百篇博客分析 => 挖透鸿蒙内核源码
博客输出站点(国内):http://weharmonyos.com
博客输出站点(国外):https://openharmony.github.io
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册