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

#include "proc.h"
#include "procfs.h"

#include <rthw.h>
#include <rtdbg.h>

#include <fcntl.h>
#include <errno.h>

#include <dfs_dentry.h>


static void *seq_start(struct dfs_seq_file *seq, off_t *index)
{
    off_t i = *index; // seq->index

    return NULL + (i == 0);
}

static void seq_stop(struct dfs_seq_file *seq, void *data)
{
}

static void *seq_next(struct dfs_seq_file *seq, void *data, off_t *index)
{
    /* data: The return value of the start or next*/
    off_t i = *index + 1; // seq->index

    *index = i;

    return NULL;
}

static int seq_show(struct dfs_seq_file *seq, void *data)
{
    /* data: The return value of the start or next*/
    dfs_seq_puts(seq, "todo\n");

    return 0;
}

static const struct dfs_seq_ops seq_ops = {
    .start  = seq_start,
    .stop   = seq_stop,
    .next   = seq_next,
    .show   = seq_show,
};

void proc_tty_register_driver(void *driver)
{
    //todo
}

void proc_tty_unregister_driver(void *driver)
{
    //todo
}

int proc_tty_init(void)
{
    struct proc_dentry *dentry;

    dentry = proc_mkdir("tty", NULL);
    if (!dentry)
        return -1;

    proc_release(dentry);

    dentry = proc_mkdir("tty/ldisc", NULL);
    proc_release(dentry);

    dentry = proc_mkdir_mode("tty/driver", S_IRUSR|S_IXUSR, NULL);
    proc_release(dentry);

    dentry = proc_create_data("tty/ldiscs", 0, NULL, NULL, NULL);
    if (dentry)
    {
        dentry->seq_ops = &seq_ops;
    }
    proc_release(dentry);

    dentry = proc_create_data("tty/drivers", 0, NULL, NULL, NULL);
    if (dentry)
    {
        dentry->seq_ops = &seq_ops;
    }
    proc_release(dentry);

    return 0;
}
INIT_ENV_EXPORT(proc_tty_init);