dfs_fs.h 2.7 KB
Newer Older
1
/*
2
 * Copyright (c) 2006-2021, RT-Thread Development Team
3
 *
4
 * SPDX-License-Identifier: Apache-2.0
5 6 7 8 9
 *
 * Change Logs:
 * Date           Author       Notes
 * 2005-02-22     Bernard      The first version.
 */
10

11 12 13
#ifndef __DFS_FS_H__
#define __DFS_FS_H__

B
bernard 已提交
14
#include <dfs.h>
mysterywolf's avatar
mysterywolf 已提交
15
#include <sys/types.h>
16
#include <sys/errno.h>
mysterywolf's avatar
mysterywolf 已提交
17

B
bernard 已提交
18 19 20
#ifdef __cplusplus
extern "C" {
#endif
21

22 23 24 25
/* Pre-declaration */
struct dfs_filesystem;
struct dfs_fd;

B
bernard 已提交
26 27
/* File system operations */
struct dfs_filesystem_ops
28
{
29
    char *name;
B
bernard 已提交
30 31 32 33
    uint32_t flags;      /* flags for file system operations */

    /* operations for file */
    const struct dfs_file_ops *fops;
34 35 36 37 38 39

    /* mount and unmount file system */
    int (*mount)    (struct dfs_filesystem *fs, unsigned long rwflag, const void *data);
    int (*unmount)  (struct dfs_filesystem *fs);

    /* make a file system */
40
    int (*mkfs)     (rt_device_t devid);
41 42 43 44 45
    int (*statfs)   (struct dfs_filesystem *fs, struct statfs *buf);

    int (*unlink)   (struct dfs_filesystem *fs, const char *pathname);
    int (*stat)     (struct dfs_filesystem *fs, const char *filename, struct stat *buf);
    int (*rename)   (struct dfs_filesystem *fs, const char *oldpath, const char *newpath);
46 47 48 49 50
};

/* Mounted file system */
struct dfs_filesystem
{
51
    rt_device_t dev_id;     /* Attached device */
52

53
    char *path;             /* File system mount point */
B
bernard 已提交
54
    const struct dfs_filesystem_ops *ops; /* Operations for file system type */
55

56
    void *data;             /* Specific file system data */
57 58 59 60 61
};

/* file system partition table */
struct dfs_partition
{
B
bernard 已提交
62 63 64
    uint8_t type;        /* file system type */
    off_t  offset;       /* partition start offset */
    size_t size;         /* partition size */
65
    rt_sem_t lock;
66 67
};

B
bernard 已提交
68 69 70
/* mount table */
struct dfs_mount_tbl
{
B
bernard 已提交
71 72 73 74 75
    const char   *device_name;
    const char   *path;
    const char   *filesystemtype;
    unsigned long rwflag;
    const void   *data;
B
bernard 已提交
76 77
};

B
bernard 已提交
78
int dfs_register(const struct dfs_filesystem_ops *ops);
79
struct dfs_filesystem *dfs_filesystem_lookup(const char *path);
80
const char *dfs_filesystem_get_mounted_path(struct rt_device *device);
81

B
bernard 已提交
82
int dfs_filesystem_get_partition(struct dfs_partition *part,
83 84
                                 uint8_t         *buf,
                                 uint32_t        pindex);
85 86 87 88

int dfs_mount(const char *device_name,
              const char *path,
              const char *filesystemtype,
B
bernard 已提交
89
              unsigned long rwflag,
90
              const void *data);
91 92
int dfs_unmount(const char *specialfile);

93
int dfs_mkfs(const char *fs_name, const char *device_name);
94
int dfs_statfs(const char *path, struct statfs *buffer);
H
hichard 已提交
95
int dfs_mount_device(rt_device_t dev);
96
int dfs_unmount_device(rt_device_t dev);
97

B
bernard 已提交
98 99 100 101
#ifdef __cplusplus
}
#endif

102
#endif