1 /*
2  * Copyright (c) 2006-2023, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  */
9 
10 #include "proc.h"
11 #include "procfs.h"
12 
13 #include <rthw.h>
14 #include <rtdbg.h>
15 
16 #include <fcntl.h>
17 #include <errno.h>
18 
19 #include <dfs_dentry.h>
20 
21 
seq_start(struct dfs_seq_file * seq,off_t * index)22 static void *seq_start(struct dfs_seq_file *seq, off_t *index)
23 {
24     off_t i = *index; // seq->index
25 
26     return NULL + (i == 0);
27 }
28 
seq_stop(struct dfs_seq_file * seq,void * data)29 static void seq_stop(struct dfs_seq_file *seq, void *data)
30 {
31 }
32 
seq_next(struct dfs_seq_file * seq,void * data,off_t * index)33 static void *seq_next(struct dfs_seq_file *seq, void *data, off_t *index)
34 {
35     /* data: The return value of the start or next*/
36     off_t i = *index + 1; // seq->index
37 
38     *index = i;
39 
40     return NULL;
41 }
42 
seq_show(struct dfs_seq_file * seq,void * data)43 static int seq_show(struct dfs_seq_file *seq, void *data)
44 {
45     /* data: The return value of the start or next*/
46     dfs_seq_puts(seq, "todo\n");
47 
48     return 0;
49 }
50 
51 static const struct dfs_seq_ops seq_ops = {
52     .start  = seq_start,
53     .stop   = seq_stop,
54     .next   = seq_next,
55     .show   = seq_show,
56 };
57 
proc_tty_register_driver(void * driver)58 void proc_tty_register_driver(void *driver)
59 {
60     //todo
61 }
62 
proc_tty_unregister_driver(void * driver)63 void proc_tty_unregister_driver(void *driver)
64 {
65     //todo
66 }
67 
proc_tty_init(void)68 int proc_tty_init(void)
69 {
70     struct proc_dentry *dentry;
71 
72     dentry = proc_mkdir("tty", NULL);
73     if (!dentry)
74         return -1;
75 
76     proc_release(dentry);
77 
78     dentry = proc_mkdir("tty/ldisc", NULL);
79     proc_release(dentry);
80 
81     dentry = proc_mkdir_mode("tty/driver", S_IRUSR|S_IXUSR, NULL);
82     proc_release(dentry);
83 
84     dentry = proc_create_data("tty/ldiscs", 0, NULL, NULL, NULL);
85     if (dentry)
86     {
87         dentry->seq_ops = &seq_ops;
88     }
89     proc_release(dentry);
90 
91     dentry = proc_create_data("tty/drivers", 0, NULL, NULL, NULL);
92     if (dentry)
93     {
94         dentry->seq_ops = &seq_ops;
95     }
96     proc_release(dentry);
97 
98     return 0;
99 }
100 INIT_ENV_EXPORT(proc_tty_init);
101