summaryrefslogtreecommitdiff
path: root/components/dfs/dfs_v2/include/dfs_fs.h
blob: d30967aac53e55c279b6fec878cd4e176e5c717e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2005-02-22     Bernard      The first version.
 * 2023-05-05     Bernard      Change to dfs v2.0
 */

#ifndef __DFS_FS_H__
#define __DFS_FS_H__

#include <dfs.h>
#include <dfs_file.h>

#ifdef __cplusplus
extern "C"
{
#endif

/* file system partition table */
struct dfs_partition
{
    uint8_t type; /* file system type */
    off_t offset; /* partition start offset */
    size_t size;  /* partition size */
    rt_sem_t lock;
};

struct dfs_attr
{
    unsigned int ia_valid;
    uid_t st_uid;
    gid_t st_gid;
    mode_t st_mode;
    struct timespec ia_atime;
    struct timespec ia_mtime;
};

struct dfs_mnt;
struct dfs_dentry;
struct dfs_vnode;

struct statfs;

struct dfs_filesystem_ops
{
    const char *name;
    uint32_t flags;
#define FS_NEED_DEVICE 0x1

    const struct dfs_file_ops *default_fops;

    int (*mount)(struct dfs_mnt *mnt, unsigned long rwflag, const void *data);
    int (*umount)(struct dfs_mnt *mnt);

    int (*mkfs)(rt_device_t devid, const char *fs_name);

    int (*readlink)(struct dfs_dentry *dentry, char *buf, int len);
    int (*link)(struct dfs_dentry *src_dentry, struct dfs_dentry *dst_dentry); /*hard link interface */
    int (*unlink)(struct dfs_dentry *dentry);
    int (*symlink)(struct dfs_dentry *parent_dentry, const char *target, const char *newpath); /*soft link interface*/

    int (*rename)(struct dfs_dentry *old_dentry, struct dfs_dentry *new_dentry);
    int (*stat)(struct dfs_dentry *dentry, struct stat *buf);

    int (*statfs)(struct dfs_mnt *mnt, struct statfs *buf);

    int (*setattr) (struct dfs_dentry *dentry, struct dfs_attr *attr);

    struct dfs_vnode* (*lookup)(struct dfs_dentry *dentry);

    struct dfs_vnode* (*create_vnode)(struct dfs_dentry *dentry, int type, mode_t mode);
    int (*free_vnode)(struct dfs_vnode* vnode);
};

struct dfs_filesystem_type
{
    const struct dfs_filesystem_ops *fs_ops;
    struct dfs_filesystem_type *next;
};

struct dfs_filesystem_type *dfs_filesystems(void);
int dfs_unregister(struct dfs_filesystem_type *fs);
int dfs_register(struct dfs_filesystem_type *fs);
const char *dfs_filesystem_get_mounted_path(struct rt_device *device);

int dfs_mount(const char *device_name,
            const char *path,
            const char *filesystemtype,
            unsigned long rwflag,
            const void *data);
int dfs_umount(const char *specialfile, int flags);
int dfs_unmount(const char *specialfile);
int dfs_is_mounted(struct dfs_mnt *mnt);
int dfs_mkfs(const char *fs_name, const char *device_name);
int dfs_statfs(const char *path, struct statfs *buffer);
int dfs_filesystem_get_partition(struct dfs_partition *part,
                                uint8_t *buf,
                                uint32_t pindex);

#ifdef __cplusplus
}
#endif

#endif