xref: /kernel/uniproton/src/fs/vfs/vfs_files.h (revision 54568cb3)
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#ifndef VFS_FILES_H
17#define VFS_FILES_H
18
19#include "dirent.h"
20#include "sys/stat.h"
21#include "unistd.h"
22#include "prt_fs.h"
23
24#define FILE_STATUS_NOT_USED 0
25#define FILE_STATUS_INITING 1
26#define FILE_STATUS_READY 2
27#define FILE_STATUS_CLOSING 3
28
29struct TagFileOps;
30struct TagFile;
31struct TagDir;
32struct TagMountPoint;
33
34struct TagFileOps {
35    S32     (*open)(struct TagFile *, const char *, S32);
36    S32     (*close)(struct TagFile *);
37    ssize_t (*read)(struct TagFile *, char *, size_t);
38    ssize_t (*write)(struct TagFile *, const char *, size_t);
39    off_t   (*lseek)(struct TagFile *, off_t, S32);
40    S32     (*stat)(struct TagMountPoint *, const char *, struct stat *);
41    S32     (*truncate)(struct TagFile *, off_t);
42    S32     (*unlink)(struct TagMountPoint *, const char *);
43    S32     (*rename)(struct TagMountPoint *, const char *, const char *);
44    S32     (*ioctl)(struct TagFile *, S32, uintptr_t);
45    S32     (*sync)(struct TagFile *);
46    S32     (*opendir)(struct TagDir *, const char *);
47    S32     (*readdir)(struct TagDir *, struct dirent *);
48    S32     (*closedir)(struct TagDir *);
49    S32     (*mkdir)(struct TagMountPoint *, const char *);
50    S32     (*rmdir)(struct TagMountPoint *, const char *);
51};
52
53struct TagFile {
54    const struct TagFileOps *fFops;
55    U32                     fFlags;
56    U32                     fStatus;
57    off_t                   fOffset;
58    S32                     fOwner;
59    struct TagMountPoint    *fMp;
60    void                    *fData;
61    const char              *fullPath;
62};
63
64struct TagDir {
65    struct TagMountPoint *dMp;
66    struct dirent        dDent;
67    off_t                dOffset;
68    void                 *dData;
69};
70
71S32 OsFileToFd(struct TagFile *file);
72struct TagFile *OsFdToFile(S32 fd);
73struct TagFile *OsVfsGetFile(void);
74struct TagFile *OsVfsGetFileSpec(S32 fd);
75void OsVfsPutFile(struct TagFile *file);
76
77#endif /* VFS_FILES_H */
78