1 /*********************************************************************
5 * Description: Various entries in the /proc file system
6 * Status: Experimental.
7 * Author: Thomas Davis, <ratbert@radiks.net>
8 * Created at: Sat Feb 21 21:33:24 1998
9 * Modified at: Tue Apr 6 19:07:06 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
12 * Copyright (c) 1998, Thomas Davis, <ratbert@radiks.net>,
13 * All Rights Reserved.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
20 * I, Thomas Davis, provide no warranty for any of this software.
21 * This material is provided "AS-IS" and at no charge.
23 * Portions lifted from the linux/fs/procfs/ files.
25 ********************************************************************/
27 #include <linux/miscdevice.h>
28 #include <linux/proc_fs.h>
30 #include <net/irda/irda.h>
31 #include <net/irda/irmod.h>
32 #include <net/irda/irlap.h>
33 #include <net/irda/irlmp.h>
35 static int proc_irda_lookup(struct inode
* dir
, struct dentry
*dentry
);
37 static int proc_irda_readdir(struct file
*filp
, void *dirent
,
40 extern int irda_device_proc_read(char *buf
, char **start
, off_t offset
,
42 extern int irlap_proc_read(char *buf
, char **start
, off_t offset
, int len
,
44 extern int irlmp_proc_read(char *buf
, char **start
, off_t offset
, int len
,
46 extern int irttp_proc_read(char *buf
, char **start
, off_t offset
, int len
,
48 extern int irias_proc_read(char *buf
, char **start
, off_t offset
, int len
,
50 extern int discovery_proc_read(char *buf
, char **start
, off_t offset
, int len
,
53 static int proc_discovery_read(char *buf
, char **start
, off_t offset
, int len
,
56 enum irda_directory_inos
{
62 PROC_IRDA_IRDA_DEVICE
,
66 static struct file_operations proc_irda_dir_operations
= {
67 NULL
, /* lseek - default */
68 NULL
, /* read - bad */
69 NULL
, /* write - bad */
70 proc_irda_readdir
, /* readdir */
71 NULL
, /* select - default */
72 NULL
, /* ioctl - default */
74 NULL
, /* no special open code */
75 NULL
, /* no special release code */
76 NULL
/* can't fsync */
80 * proc directories can do almost nothing..
82 struct inode_operations proc_irda_dir_inode_operations
= {
83 &proc_irda_dir_operations
, /* default net directory file-ops */
94 NULL
, /* follow_link */
102 struct proc_dir_entry proc_irda
= {
104 S_IFDIR
| S_IRUGO
| S_IXUGO
, 2, 0, 0,
105 0, &proc_irda_dir_inode_operations
,
112 struct proc_dir_entry proc_lpt
= {
114 S_IFREG
| S_IRUGO
, 1, 0, 0,
115 0, NULL
/* ops -- default to array */,
116 &irlpt_proc_read
/* get_info */,
120 struct proc_dir_entry proc_discovery
= {
122 S_IFREG
| S_IRUGO
, 1, 0, 0,
123 0, NULL
/* ops -- default to array */,
124 &discovery_proc_read
/* get_info */,
127 struct proc_dir_entry proc_irda_device
= {
128 0, 11, "irda_device",
129 S_IFREG
| S_IRUGO
, 1, 0, 0,
131 &irda_device_proc_read
,
134 struct proc_dir_entry proc_ttp
= {
136 S_IFREG
| S_IRUGO
, 1, 0, 0,
137 0, NULL
/* ops -- default to array */,
138 &irttp_proc_read
/* get_info */,
141 struct proc_dir_entry proc_lmp
= {
143 S_IFREG
| S_IRUGO
, 1, 0, 0,
144 0, NULL
/* ops -- default to array */,
145 &irlmp_proc_read
/* get_info */,
148 struct proc_dir_entry proc_lap
= {
150 S_IFREG
| S_IRUGO
, 1, 0, 0,
151 0, NULL
/* ops -- default to array */,
152 &irlap_proc_read
/* get_info */,
155 struct proc_dir_entry proc_ias
= {
157 S_IFREG
| S_IRUGO
, 1, 0, 0,
158 0, NULL
/* ops -- default to array */,
159 &irias_proc_read
/* get_info */,
163 * Function proc_delete_dentry (dentry)
165 * Copy of proc/root.c because this function is invisible to the irda
169 static void proc_delete_dentry(struct dentry
* dentry
)
174 static struct dentry_operations proc_dentry_operations
=
176 NULL
, /* revalidate */
178 NULL
, /* d_compare */
179 proc_delete_dentry
/* d_delete(struct dentry *) */
183 * Function irda_proc_register (void)
185 * Register irda entry in /proc file system
188 void irda_proc_register(void) {
189 proc_net_register(&proc_irda
);
191 proc_irda
.fill_inode
= &irda_proc_modcount
;
193 proc_register(&proc_irda
, &proc_lap
);
194 proc_register(&proc_irda
, &proc_lmp
);
195 proc_register(&proc_irda
, &proc_ttp
);
196 proc_register(&proc_irda
, &proc_ias
);
197 proc_register(&proc_irda
, &proc_irda_device
);
198 proc_register(&proc_irda
, &proc_discovery
);
202 * Function irda_proc_unregister (void)
204 * Unregister irda entry in /proc file system
207 void irda_proc_unregister(void) {
208 proc_unregister(&proc_irda
, proc_discovery
.low_ino
);
209 proc_unregister(&proc_irda
, proc_irda_device
.low_ino
);
210 proc_unregister(&proc_irda
, proc_ias
.low_ino
);
211 proc_unregister(&proc_irda
, proc_ttp
.low_ino
);
212 proc_unregister(&proc_irda
, proc_lmp
.low_ino
);
213 proc_unregister(&proc_irda
, proc_lap
.low_ino
);
214 proc_unregister(proc_net
, proc_irda
.low_ino
);
218 * Function proc_irda_lookup (dir, dentry)
220 * This is a copy of proc_lookup from the linux-2.2.x kernel
223 int proc_irda_lookup(struct inode
* dir
, struct dentry
*dentry
)
226 struct proc_dir_entry
* de
;
230 if (!dir
|| !S_ISDIR(dir
->i_mode
))
235 de
= (struct proc_dir_entry
*) dir
->u
.generic_ip
;
237 for (de
= de
->subdir
; de
; de
= de
->next
) {
238 if (!de
|| !de
->low_ino
)
240 if (de
->namelen
!= dentry
->d_name
.len
)
242 if (!memcmp(dentry
->d_name
.name
, de
->name
, de
->namelen
)) {
243 int ino
= de
->low_ino
| (dir
->i_ino
& ~(0xffff));
245 inode
= proc_get_inode(dir
->i_sb
, ino
, de
);
252 dentry
->d_op
= &proc_dentry_operations
;
253 d_add(dentry
, inode
);
261 * Function proc_irda_readdir (filp, dirent, filldir)
263 * This is a copy from linux/fs/proc because the function is invisible
267 static int proc_irda_readdir(struct file
*filp
, void *dirent
,
270 struct proc_dir_entry
* de
;
274 struct inode
*inode
= filp
->f_dentry
->d_inode
;
275 if (!inode
|| !S_ISDIR(inode
->i_mode
))
278 de
= (struct proc_dir_entry
*) inode
->u
.generic_ip
;
284 if (filldir(dirent
, ".", 1, i
, ino
) < 0)
290 if (filldir(dirent
, "..", 2, i
, de
->parent
->low_ino
) < 0)
309 if (filldir(dirent
, de
->name
, de
->namelen
, filp
->f_pos
,
310 ino
| de
->low_ino
) < 0)