dfs_fs.h 2.6 KB
Newer Older
1
/*
2
 * Copyright (c) 2006-2018, 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>
15

B
bernard 已提交
16 17 18
#ifdef __cplusplus
extern "C" {
#endif
19

20 21 22 23
/* Pre-declaration */
struct dfs_filesystem;
struct dfs_fd;

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

    /* operations for file */
    const struct dfs_file_ops *fops;
32 33 34 35 36 37

    /* 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 */
38
    int (*mkfs)     (rt_device_t devid);
39 40 41 42 43
    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);
44 45 46 47 48
};

/* Mounted file system */
struct dfs_filesystem
{
49
    rt_device_t dev_id;     /* Attached device */
50

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

54
    void *data;             /* Specific file system data */
55 56 57 58 59
};

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

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

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

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

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

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

B
bernard 已提交
96 97 98 99
#ifdef __cplusplus
}
#endif

100
#endif