154568cb3Sopenharmony_ci/*
254568cb3Sopenharmony_ci * Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
354568cb3Sopenharmony_ci *
454568cb3Sopenharmony_ci * UniProton is licensed under Mulan PSL v2.
554568cb3Sopenharmony_ci * You can use this software according to the terms and conditions of the Mulan PSL v2.
654568cb3Sopenharmony_ci * You may obtain a copy of Mulan PSL v2 at:
754568cb3Sopenharmony_ci *          http://license.coscl.org.cn/MulanPSL2
854568cb3Sopenharmony_ci * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
954568cb3Sopenharmony_ci * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
1054568cb3Sopenharmony_ci * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
1154568cb3Sopenharmony_ci * See the Mulan PSL v2 for more details.
1254568cb3Sopenharmony_ci * Create: 2022-09-21
1354568cb3Sopenharmony_ci * Description: 文件系统vfs层
1454568cb3Sopenharmony_ci */
1554568cb3Sopenharmony_ci
1654568cb3Sopenharmony_ci#ifndef VFS_FILES_H
1754568cb3Sopenharmony_ci#define VFS_FILES_H
1854568cb3Sopenharmony_ci
1954568cb3Sopenharmony_ci#include "dirent.h"
2054568cb3Sopenharmony_ci#include "sys/stat.h"
2154568cb3Sopenharmony_ci#include "unistd.h"
2254568cb3Sopenharmony_ci#include "prt_fs.h"
2354568cb3Sopenharmony_ci
2454568cb3Sopenharmony_ci#define FILE_STATUS_NOT_USED 0
2554568cb3Sopenharmony_ci#define FILE_STATUS_INITING 1
2654568cb3Sopenharmony_ci#define FILE_STATUS_READY 2
2754568cb3Sopenharmony_ci#define FILE_STATUS_CLOSING 3
2854568cb3Sopenharmony_ci
2954568cb3Sopenharmony_cistruct TagFileOps;
3054568cb3Sopenharmony_cistruct TagFile;
3154568cb3Sopenharmony_cistruct TagDir;
3254568cb3Sopenharmony_cistruct TagMountPoint;
3354568cb3Sopenharmony_ci
3454568cb3Sopenharmony_cistruct TagFileOps {
3554568cb3Sopenharmony_ci    S32     (*open)(struct TagFile *, const char *, S32);
3654568cb3Sopenharmony_ci    S32     (*close)(struct TagFile *);
3754568cb3Sopenharmony_ci    ssize_t (*read)(struct TagFile *, char *, size_t);
3854568cb3Sopenharmony_ci    ssize_t (*write)(struct TagFile *, const char *, size_t);
3954568cb3Sopenharmony_ci    off_t   (*lseek)(struct TagFile *, off_t, S32);
4054568cb3Sopenharmony_ci    S32     (*stat)(struct TagMountPoint *, const char *, struct stat *);
4154568cb3Sopenharmony_ci    S32     (*truncate)(struct TagFile *, off_t);
4254568cb3Sopenharmony_ci    S32     (*unlink)(struct TagMountPoint *, const char *);
4354568cb3Sopenharmony_ci    S32     (*rename)(struct TagMountPoint *, const char *, const char *);
4454568cb3Sopenharmony_ci    S32     (*ioctl)(struct TagFile *, S32, uintptr_t);
4554568cb3Sopenharmony_ci    S32     (*sync)(struct TagFile *);
4654568cb3Sopenharmony_ci    S32     (*opendir)(struct TagDir *, const char *);
4754568cb3Sopenharmony_ci    S32     (*readdir)(struct TagDir *, struct dirent *);
4854568cb3Sopenharmony_ci    S32     (*closedir)(struct TagDir *);
4954568cb3Sopenharmony_ci    S32     (*mkdir)(struct TagMountPoint *, const char *);
5054568cb3Sopenharmony_ci    S32     (*rmdir)(struct TagMountPoint *, const char *);
5154568cb3Sopenharmony_ci};
5254568cb3Sopenharmony_ci
5354568cb3Sopenharmony_cistruct TagFile {
5454568cb3Sopenharmony_ci    const struct TagFileOps *fFops;
5554568cb3Sopenharmony_ci    U32                     fFlags;
5654568cb3Sopenharmony_ci    U32                     fStatus;
5754568cb3Sopenharmony_ci    off_t                   fOffset;
5854568cb3Sopenharmony_ci    S32                     fOwner;
5954568cb3Sopenharmony_ci    struct TagMountPoint    *fMp;
6054568cb3Sopenharmony_ci    void                    *fData;
6154568cb3Sopenharmony_ci    const char              *fullPath;
6254568cb3Sopenharmony_ci};
6354568cb3Sopenharmony_ci
6454568cb3Sopenharmony_cistruct TagDir {
6554568cb3Sopenharmony_ci    struct TagMountPoint *dMp;
6654568cb3Sopenharmony_ci    struct dirent        dDent;
6754568cb3Sopenharmony_ci    off_t                dOffset;
6854568cb3Sopenharmony_ci    void                 *dData;
6954568cb3Sopenharmony_ci};
7054568cb3Sopenharmony_ci
7154568cb3Sopenharmony_ciS32 OsFileToFd(struct TagFile *file);
7254568cb3Sopenharmony_cistruct TagFile *OsFdToFile(S32 fd);
7354568cb3Sopenharmony_cistruct TagFile *OsVfsGetFile(void);
7454568cb3Sopenharmony_cistruct TagFile *OsVfsGetFileSpec(S32 fd);
7554568cb3Sopenharmony_civoid OsVfsPutFile(struct TagFile *file);
7654568cb3Sopenharmony_ci
7754568cb3Sopenharmony_ci#endif /* VFS_FILES_H */
78