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: 文件系统vfs层 14 */ 15 16#include <stdlib.h> 17#include "securec.h" 18#include "vfs_maps.h" 19#include "vfs_operations.h" 20#include "prt_fs.h" 21 22static struct TagFsMap *g_fsMap; 23 24struct TagFsMap *OsVfsGetFsMap(const char *fsType) 25{ 26 struct TagFsMap *curr = g_fsMap; 27 while (curr != NULL) { 28 if ((curr->fsType != NULL) && (fsType != NULL) && 29 (strcmp(curr->fsType, fsType) == 0)) { 30 return curr; 31 } 32 curr = curr->next; 33 } 34 return NULL; 35} 36 37S32 OsVfsFsMgtDisk(const char *dev, const char *fsType, S32 *lengthArray, S32 partNum) 38{ 39 S32 ret = FS_OK; 40 (void)OsVfsLock(); 41 struct TagFsMap *fMap = OsVfsGetFsMap(fsType); 42 if ((fMap != NULL) && (fMap->fsMgt != NULL) && (fMap->fsMgt->fdisk != NULL)) { 43 ret = fMap->fsMgt->fdisk(dev, lengthArray, partNum); 44 } 45 (void)OsVfsUnlock(); 46 return ret; 47} 48 49S32 OsVfsFsMgtFormat(const char *partName, char *fsType, void *data) 50{ 51 S32 ret = FS_OK; 52 (void)OsVfsLock(); 53 struct TagFsMap *fMap = OsVfsGetFsMap(fsType); 54 if ((fMap != NULL) && (fMap->fsMgt != NULL) && (fMap->fsMgt->format != NULL)) { 55 ret = fMap->fsMgt->format(partName, data); 56 } 57 (void)OsVfsUnlock(); 58 return ret; 59} 60 61S32 OsFsRegister(const char *fsType, struct TagMountOps *fsMops, 62 struct TagFileOps *fsFops, struct TagFsManagement *fsMgt) 63{ 64 if ((fsMops == NULL) || (fsFops == NULL)) { 65 return FS_NOK; 66 } 67 68 struct TagFsMap *newfs = (struct TagFsMap *)malloc(sizeof(struct TagFsMap)); 69 if (newfs == NULL) { 70 return FS_NOK; 71 } 72 if (memset_s(newfs, sizeof(struct TagFsMap), 0, sizeof(struct TagFsMap)) != EOK) { 73 free(newfs); 74 return FS_NOK; 75 } 76 77 newfs->fsType = strdup(fsType); 78 if (newfs->fsType == NULL) { 79 free(newfs); 80 return FS_NOK; 81 } 82 83 newfs->fsMops = fsMops; 84 newfs->fsFops = fsFops; 85 newfs->fsMgt = fsMgt; 86 newfs->fsRefs = 0; 87 88 (void)OsVfsLock(); 89 newfs->next = g_fsMap; 90 g_fsMap = newfs; 91 92 OsVfsUnlock(); 93 return FS_OK; 94} 95