• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
3  *
4  * UniProton is licensed under Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *          http://license.coscl.org.cn/MulanPSL2
8  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11  * See the Mulan PSL v2 for more details.
12  * Create: 2022-09-21
13  * Description: fs对外头文件
14  */
15 #ifndef PRT_FS_H
16 #define PRT_FS_H
17 
18 #include "dirent.h"
19 #include "sys/mount.h"
20 #include "sys/statfs.h"
21 #include "sys/stat.h"
22 #include "sys/uio.h"
23 #include "unistd.h"
24 
25 #include "prt_config.h"
26 #include "prt_typedef.h"
27 #include "prt_sem.h"
28 
29 struct PartitionCfg {
30     /* partition low-level read func */
31     S32  (*readFunc)(S32 partition, uintptr_t offset, void *buf, U32 size);
32     /* partition low-level write func */
33     S32  (*writeFunc)(S32 partition, uintptr_t offset, const void *buf, U32 size);
34     /* partition low-level erase func */
35     S32  (*eraseFunc)(S32 partition, uintptr_t offset, U32 size);
36 
37     S32 readSize;       /* size of a block read */
38     S32 writeSize;      /* size of a block write */
39     S32 blockSize;      /* size of an erasable block */
40     S32 blockCount;     /* number of partition blocks */
41     S32 cacheSize;      /* size of block caches */
42 
43     S32 partNo;         /* partition number */
44     S32 lookaheadSize;  /* lookahead size */
45     S32 blockCycles;    /* block cycles */
46 };
47 
48 /*
49  * @brief Divide the device into partitions.
50  *
51  * @param dev Device name, which customized by caller, it is recommended to
52  * name it as: "emmc0", "emmc1", "flash0", etc. The name is combined with
53  * "device_type" + "device_id", and the last character is device_id.
54  * device_id >= 0 && device_id <= 9.
55  * @param fsType Filesystem type.
56  * @param lengthArray List of partition size. For example:
57  *     [0x10000000, 0x2000000], 256M and 512M partitions will be created and
58  *     left all will not allocated.
59  * @param addrArray List of partition start addr, partition num same as lengthArray
60  * @param partNum Length of 'lengthArray'.
61  *
62  * @return Return PRT_NOK if error. Return FS_OK if success.
63  * Partition naming rules:
64  *     In the current vfs, after successfully calling the 'fdisk' hook,
65  *     "partNum" partitions will be created.
66  *     The partition naming rules is:
67  *         The name is a combination of: 'deviceName'+'p'+'partitionId',
68  *         such as "emmc0p0", "emmc0p1", "emmc0p2"...
69  */
70 S32 PRT_DiskPartition(const char *dev, const char *fsType, S32 *lengthArray, S32 *addrArray,
71                       S32 partNum);
72 
73 /*
74  * @brief Format a partition.
75  *
76  * @param partName PartitionName, following the rule of fdisk hook.
77  * @param data For FatFs, the data indicates a pointer to a byte which
78  * specifies combination of FAT type flags, FM_FAT, FM_FAT32, FM_EXFAT and
79  * bitwise-or of these three, FM_ANY.
80  *
81  * @return Return PRT_NOK if error. Return FS_OK if success.
82  */
83 S32 PRT_PartitionFormat(const char *partName, char *fsType, void *data);
84 
85 /*
86  * @brief vfs init
87  */
88 S32 PRT_VfsInit(void);
89 
90 #endif /* PRT_FS_H */
91