summaryrefslogtreecommitdiff
path: root/components/dfs/dfs_v2/filesystems/procfs/proc.h
blob: e697860e22e172140404b1517153cea0b6f0cde8 (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
/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 */

#ifndef __PROC_H__
#define __PROC_H__

#include <dfs_file.h>
#include <dfs_seq_file.h>
#include <dfs_vfs.h>

#ifdef __cplusplus
extern "C"
{
#endif

struct proc_dentry;

struct proc_ops
{
    struct proc_dentry *(*lookup)(struct proc_dentry *parent, const char *name);
    int (*readlink)(struct proc_dentry *dentry, char *buf, int len);
};

struct proc_dentry
{
    rt_uint32_t mode;
    rt_atomic_t ref_count;

    struct proc_dentry *parent;
    struct dfs_vfs_node node;

    const struct dfs_file_ops *fops;
    const struct proc_ops *ops;
    const struct dfs_seq_ops *seq_ops;
    int (*single_show)(struct dfs_seq_file *seq, void *data);

    int pid;

    char *name;
    void *data;
};

struct proc_dentry *dfs_proc_find(const char *name);

struct proc_dentry *proc_mkdir_data(const char *name, mode_t mode, struct proc_dentry *parent,
                                    const struct dfs_file_ops *fops, void *data);
struct proc_dentry *proc_mkdir_mode(const char *name, mode_t mode, struct proc_dentry *parent);
struct proc_dentry *proc_mkdir(const char *name, struct proc_dentry *parent);

struct proc_dentry *proc_create_data(const char *name, mode_t mode, struct proc_dentry *parent,
                                     const struct dfs_file_ops *fops, void *data);
struct proc_dentry *proc_create_single_data(const char *name, mode_t mode, struct proc_dentry *parent,
                                            int (*show)(struct dfs_seq_file *, void *), void *data);

struct proc_dentry *proc_symlink(const char *name, struct proc_dentry *parent, const char *dest);

struct proc_dentry *proc_acquire(struct proc_dentry *dentry);
void proc_release(struct proc_dentry *dentry);

void proc_remove(struct proc_dentry *dentry);
void proc_remove_dentry(const char *name, struct proc_dentry *parent);

int proc_pid(int pid);

#ifdef __cplusplus
}
#endif

#endif