blob: 99198e1cf97946507796d32f98b6e3ef7c2c996e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Information interface for ALSA driver
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02003 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/time.h>
Andrea Righi27ac7922008-07-23 21:28:13 -070024#include <linux/mm.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Paulo Marques543537b2005-06-23 00:09:02 -070026#include <linux/string.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040027#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <sound/core.h>
29#include <sound/minors.h>
30#include <sound/info.h>
31#include <sound/version.h>
32#include <linux/proc_fs.h>
Ingo Molnar1a60d4c2006-01-16 16:29:08 +010033#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <stdarg.h>
35
36/*
37 *
38 */
39
Takashi Iwaie28563c2005-12-01 10:42:42 +010040#ifdef CONFIG_PROC_FS
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042int snd_info_check_reserved_words(const char *str)
43{
44 static char *reserved[] =
45 {
46 "version",
47 "meminfo",
48 "memdebug",
49 "detect",
50 "devices",
51 "oss",
52 "cards",
53 "timers",
54 "synth",
55 "pcm",
56 "seq",
57 NULL
58 };
59 char **xstr = reserved;
60
61 while (*xstr) {
62 if (!strcmp(*xstr, str))
63 return 0;
64 xstr++;
65 }
66 if (!strncmp(str, "card", 4))
67 return 0;
68 return 1;
69}
70
Ingo Molnar1a60d4c2006-01-16 16:29:08 +010071static DEFINE_MUTEX(info_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Takashi Iwai24c1f932005-11-17 13:58:48 +010073struct snd_info_private_data {
74 struct snd_info_buffer *rbuffer;
75 struct snd_info_buffer *wbuffer;
76 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 void *file_private_data;
Takashi Iwai24c1f932005-11-17 13:58:48 +010078};
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80static int snd_info_version_init(void);
81static int snd_info_version_done(void);
Takashi Iwai746d4a02006-06-23 14:37:59 +020082static void snd_info_disconnect(struct snd_info_entry *entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84
Takashi Iwai7e4eeec2006-04-28 15:13:40 +020085/* resize the proc r/w buffer */
86static int resize_info_buffer(struct snd_info_buffer *buffer,
87 unsigned int nsize)
88{
89 char *nbuf;
90
91 nsize = PAGE_ALIGN(nsize);
Takashi Iwai9983aa62009-07-06 14:31:59 +020092 nbuf = krealloc(buffer->buffer, nsize, GFP_KERNEL);
Takashi Iwai7e4eeec2006-04-28 15:13:40 +020093 if (! nbuf)
94 return -ENOMEM;
95
Takashi Iwai7e4eeec2006-04-28 15:13:40 +020096 buffer->buffer = nbuf;
97 buffer->len = nsize;
98 return 0;
99}
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101/**
102 * snd_iprintf - printf on the procfs buffer
103 * @buffer: the procfs buffer
104 * @fmt: the printf format
105 *
106 * Outputs the string on the procfs buffer just like printf().
107 *
108 * Returns the size of output string.
109 */
Takashi Iwai4f7454a2009-09-08 14:29:58 +0200110int snd_iprintf(struct snd_info_buffer *buffer, const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 va_list args;
113 int len, res;
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200114 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Takashi Iwaif001c3a2006-04-28 15:13:41 +0200116 might_sleep();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 if (buffer->stop || buffer->error)
118 return 0;
119 len = buffer->len - buffer->size;
120 va_start(args, fmt);
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200121 for (;;) {
Takashi Iwaidbedca32006-10-18 19:09:46 +0200122 va_list ap;
123 va_copy(ap, args);
124 res = vsnprintf(buffer->buffer + buffer->curr, len, fmt, ap);
125 va_end(ap);
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200126 if (res < len)
127 break;
128 err = resize_info_buffer(buffer, buffer->len + PAGE_SIZE);
129 if (err < 0)
130 break;
131 len = buffer->len - buffer->size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 }
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200133 va_end(args);
134
135 if (err < 0)
136 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 buffer->curr += res;
138 buffer->size += res;
139 return res;
140}
141
Takashi Iwaic0d3fb32006-04-28 15:13:39 +0200142EXPORT_SYMBOL(snd_iprintf);
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144/*
145
146 */
147
Takashi Iwai6581f4e2006-05-17 17:14:51 +0200148static struct proc_dir_entry *snd_proc_root;
149struct snd_info_entry *snd_seq_root;
Takashi Iwaic0d3fb32006-04-28 15:13:39 +0200150EXPORT_SYMBOL(snd_seq_root);
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152#ifdef CONFIG_SND_OSSEMUL
Takashi Iwai6581f4e2006-05-17 17:14:51 +0200153struct snd_info_entry *snd_oss_root;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154#endif
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156static void snd_remove_proc_entry(struct proc_dir_entry *parent,
157 struct proc_dir_entry *de)
158{
159 if (de)
160 remove_proc_entry(de->name, parent);
161}
162
163static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig)
164{
Takashi Iwai24c1f932005-11-17 13:58:48 +0100165 struct snd_info_private_data *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 struct snd_info_entry *entry;
Takashi Iwai73029e02010-04-13 11:39:47 +0200167 loff_t ret = -EINVAL, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 data = file->private_data;
170 entry = data->entry;
Takashi Iwai5b5cd552010-04-07 18:33:57 +0200171 mutex_lock(&entry->access);
Takashi Iwai73029e02010-04-13 11:39:47 +0200172 if (entry->content == SNDRV_INFO_CONTENT_DATA &&
173 entry->c.ops->llseek) {
174 offset = entry->c.ops->llseek(entry,
175 data->file_private_data,
176 file, offset, orig);
177 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 }
Takashi Iwai73029e02010-04-13 11:39:47 +0200179 if (entry->content == SNDRV_INFO_CONTENT_DATA)
180 size = entry->size;
181 else
182 size = 0;
183 switch (orig) {
184 case SEEK_SET:
185 break;
186 case SEEK_CUR:
187 offset += file->f_pos;
188 break;
189 case SEEK_END:
190 if (!size)
191 goto out;
192 offset += size;
193 break;
194 default:
195 goto out;
196 }
197 if (offset < 0)
198 goto out;
199 if (size && offset > size)
200 offset = size;
201 file->f_pos = offset;
202 ret = offset;
203 out:
Takashi Iwai5b5cd552010-04-07 18:33:57 +0200204 mutex_unlock(&entry->access);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 return ret;
206}
207
208static ssize_t snd_info_entry_read(struct file *file, char __user *buffer,
209 size_t count, loff_t * offset)
210{
Takashi Iwai24c1f932005-11-17 13:58:48 +0100211 struct snd_info_private_data *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 struct snd_info_entry *entry;
Takashi Iwai24c1f932005-11-17 13:58:48 +0100213 struct snd_info_buffer *buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 size_t size = 0;
215 loff_t pos;
216
217 data = file->private_data;
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200218 if (snd_BUG_ON(!data))
219 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 pos = *offset;
221 if (pos < 0 || (long) pos != pos || (ssize_t) count < 0)
222 return -EIO;
223 if ((unsigned long) pos + (unsigned long) count < (unsigned long) pos)
224 return -EIO;
225 entry = data->entry;
226 switch (entry->content) {
227 case SNDRV_INFO_CONTENT_TEXT:
228 buf = data->rbuffer;
229 if (buf == NULL)
230 return -EIO;
231 if (pos >= buf->size)
232 return 0;
233 size = buf->size - pos;
234 size = min(count, size);
235 if (copy_to_user(buffer, buf->buffer + pos, size))
236 return -EFAULT;
237 break;
238 case SNDRV_INFO_CONTENT_DATA:
Takashi Iwaid97e1b72010-04-13 11:33:54 +0200239 if (pos >= entry->size)
240 return 0;
241 if (entry->c.ops->read) {
242 size = entry->size - pos;
243 size = min(count, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 size = entry->c.ops->read(entry,
245 data->file_private_data,
Takashi Iwaid97e1b72010-04-13 11:33:54 +0200246 file, buffer, size, pos);
247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 break;
249 }
250 if ((ssize_t) size > 0)
251 *offset = pos + size;
252 return size;
253}
254
255static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer,
256 size_t count, loff_t * offset)
257{
Takashi Iwai24c1f932005-11-17 13:58:48 +0100258 struct snd_info_private_data *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 struct snd_info_entry *entry;
Takashi Iwai24c1f932005-11-17 13:58:48 +0100260 struct snd_info_buffer *buf;
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200261 ssize_t size = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 loff_t pos;
Siqi Lin3f9219b2016-11-02 16:51:08 -0700263 unsigned long realloc_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 data = file->private_data;
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200266 if (snd_BUG_ON(!data))
267 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 entry = data->entry;
269 pos = *offset;
270 if (pos < 0 || (long) pos != pos || (ssize_t) count < 0)
271 return -EIO;
Siqi Lin3f9219b2016-11-02 16:51:08 -0700272 realloc_size = (unsigned long) pos + (unsigned long) count;
273 if (realloc_size < (unsigned long) pos || realloc_size > UINT_MAX)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 return -EIO;
275 switch (entry->content) {
276 case SNDRV_INFO_CONTENT_TEXT:
277 buf = data->wbuffer;
278 if (buf == NULL)
279 return -EIO;
Clemens Ladischf4a747f2006-05-02 15:33:25 +0200280 mutex_lock(&entry->access);
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200281 if (pos + count >= buf->len) {
282 if (resize_info_buffer(buf, pos + count)) {
283 mutex_unlock(&entry->access);
284 return -ENOMEM;
285 }
286 }
287 if (copy_from_user(buf->buffer + pos, buffer, count)) {
288 mutex_unlock(&entry->access);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 return -EFAULT;
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200290 }
291 buf->size = pos + count;
292 mutex_unlock(&entry->access);
293 size = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 break;
295 case SNDRV_INFO_CONTENT_DATA:
Takashi Iwaid97e1b72010-04-13 11:33:54 +0200296 if (entry->c.ops->write && count > 0) {
297 size_t maxsize = entry->size - pos;
298 count = min(count, maxsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 size = entry->c.ops->write(entry,
300 data->file_private_data,
301 file, buffer, count, pos);
Takashi Iwaid97e1b72010-04-13 11:33:54 +0200302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 break;
304 }
305 if ((ssize_t) size > 0)
306 *offset = pos + size;
307 return size;
308}
309
310static int snd_info_entry_open(struct inode *inode, struct file *file)
311{
Takashi Iwai24c1f932005-11-17 13:58:48 +0100312 struct snd_info_entry *entry;
313 struct snd_info_private_data *data;
314 struct snd_info_buffer *buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 struct proc_dir_entry *p;
316 int mode, err;
317
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100318 mutex_lock(&info_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 p = PDE(inode);
Takashi Iwai24c1f932005-11-17 13:58:48 +0100320 entry = p == NULL ? NULL : (struct snd_info_entry *)p->data;
Takashi Iwai746d4a02006-06-23 14:37:59 +0200321 if (entry == NULL || ! entry->p) {
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100322 mutex_unlock(&info_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 return -ENODEV;
324 }
325 if (!try_module_get(entry->module)) {
326 err = -EFAULT;
327 goto __error1;
328 }
329 mode = file->f_flags & O_ACCMODE;
330 if (mode == O_RDONLY || mode == O_RDWR) {
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200331 if ((entry->content == SNDRV_INFO_CONTENT_DATA &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 entry->c.ops->read == NULL)) {
333 err = -ENODEV;
334 goto __error;
335 }
336 }
337 if (mode == O_WRONLY || mode == O_RDWR) {
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200338 if ((entry->content == SNDRV_INFO_CONTENT_DATA &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 entry->c.ops->write == NULL)) {
340 err = -ENODEV;
341 goto __error;
342 }
343 }
Takashi Iwaica2c0962005-09-09 14:20:23 +0200344 data = kzalloc(sizeof(*data), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 if (data == NULL) {
346 err = -ENOMEM;
347 goto __error;
348 }
349 data->entry = entry;
350 switch (entry->content) {
351 case SNDRV_INFO_CONTENT_TEXT:
352 if (mode == O_RDONLY || mode == O_RDWR) {
Takashi Iwaica2c0962005-09-09 14:20:23 +0200353 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200354 if (buffer == NULL)
355 goto __nomem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 data->rbuffer = buffer;
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200357 buffer->len = PAGE_SIZE;
358 buffer->buffer = kmalloc(buffer->len, GFP_KERNEL);
359 if (buffer->buffer == NULL)
360 goto __nomem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362 if (mode == O_WRONLY || mode == O_RDWR) {
Takashi Iwaica2c0962005-09-09 14:20:23 +0200363 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200364 if (buffer == NULL)
365 goto __nomem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 data->wbuffer = buffer;
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200367 buffer->len = PAGE_SIZE;
368 buffer->buffer = kmalloc(buffer->len, GFP_KERNEL);
369 if (buffer->buffer == NULL)
370 goto __nomem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 }
372 break;
373 case SNDRV_INFO_CONTENT_DATA: /* data */
374 if (entry->c.ops->open) {
375 if ((err = entry->c.ops->open(entry, mode,
376 &data->file_private_data)) < 0) {
377 kfree(data);
378 goto __error;
379 }
380 }
381 break;
382 }
383 file->private_data = data;
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100384 mutex_unlock(&info_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 if (entry->content == SNDRV_INFO_CONTENT_TEXT &&
386 (mode == O_RDONLY || mode == O_RDWR)) {
387 if (entry->c.text.read) {
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100388 mutex_lock(&entry->access);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 entry->c.text.read(entry, data->rbuffer);
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100390 mutex_unlock(&entry->access);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 }
392 }
393 return 0;
394
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200395 __nomem:
396 if (data->rbuffer) {
397 kfree(data->rbuffer->buffer);
398 kfree(data->rbuffer);
399 }
400 if (data->wbuffer) {
401 kfree(data->wbuffer->buffer);
402 kfree(data->wbuffer);
403 }
404 kfree(data);
405 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 __error:
407 module_put(entry->module);
408 __error1:
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100409 mutex_unlock(&info_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 return err;
411}
412
413static int snd_info_entry_release(struct inode *inode, struct file *file)
414{
Takashi Iwai24c1f932005-11-17 13:58:48 +0100415 struct snd_info_entry *entry;
416 struct snd_info_private_data *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 int mode;
418
419 mode = file->f_flags & O_ACCMODE;
420 data = file->private_data;
421 entry = data->entry;
422 switch (entry->content) {
423 case SNDRV_INFO_CONTENT_TEXT:
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200424 if (data->rbuffer) {
425 kfree(data->rbuffer->buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 kfree(data->rbuffer);
427 }
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200428 if (data->wbuffer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 if (entry->c.text.write) {
430 entry->c.text.write(entry, data->wbuffer);
431 if (data->wbuffer->error) {
432 snd_printk(KERN_WARNING "data write error to %s (%i)\n",
433 entry->name,
434 data->wbuffer->error);
435 }
436 }
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200437 kfree(data->wbuffer->buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 kfree(data->wbuffer);
439 }
440 break;
441 case SNDRV_INFO_CONTENT_DATA:
442 if (entry->c.ops->release)
443 entry->c.ops->release(entry, mode,
444 data->file_private_data);
445 break;
446 }
447 module_put(entry->module);
448 kfree(data);
449 return 0;
450}
451
452static unsigned int snd_info_entry_poll(struct file *file, poll_table * wait)
453{
Takashi Iwai24c1f932005-11-17 13:58:48 +0100454 struct snd_info_private_data *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 struct snd_info_entry *entry;
456 unsigned int mask;
457
458 data = file->private_data;
459 if (data == NULL)
460 return 0;
461 entry = data->entry;
462 mask = 0;
463 switch (entry->content) {
464 case SNDRV_INFO_CONTENT_DATA:
465 if (entry->c.ops->poll)
466 return entry->c.ops->poll(entry,
467 data->file_private_data,
468 file, wait);
469 if (entry->c.ops->read)
470 mask |= POLLIN | POLLRDNORM;
471 if (entry->c.ops->write)
472 mask |= POLLOUT | POLLWRNORM;
473 break;
474 }
475 return mask;
476}
477
Ingo Molnard99e9882006-01-09 16:44:46 +0100478static long snd_info_entry_ioctl(struct file *file, unsigned int cmd,
479 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
Takashi Iwai24c1f932005-11-17 13:58:48 +0100481 struct snd_info_private_data *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 struct snd_info_entry *entry;
483
484 data = file->private_data;
485 if (data == NULL)
486 return 0;
487 entry = data->entry;
488 switch (entry->content) {
489 case SNDRV_INFO_CONTENT_DATA:
490 if (entry->c.ops->ioctl)
491 return entry->c.ops->ioctl(entry,
492 data->file_private_data,
493 file, cmd, arg);
494 break;
495 }
496 return -ENOTTY;
497}
498
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499static int snd_info_entry_mmap(struct file *file, struct vm_area_struct *vma)
500{
Josef Sipek7bc56322006-12-08 02:37:40 -0800501 struct inode *inode = file->f_path.dentry->d_inode;
Takashi Iwai24c1f932005-11-17 13:58:48 +0100502 struct snd_info_private_data *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 struct snd_info_entry *entry;
504
505 data = file->private_data;
506 if (data == NULL)
507 return 0;
508 entry = data->entry;
509 switch (entry->content) {
510 case SNDRV_INFO_CONTENT_DATA:
511 if (entry->c.ops->mmap)
512 return entry->c.ops->mmap(entry,
513 data->file_private_data,
514 inode, file, vma);
515 break;
516 }
517 return -ENXIO;
518}
519
Arjan van de Ven9c2e08c2007-02-12 00:55:37 -0800520static const struct file_operations snd_info_entry_operations =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521{
Ingo Molnard99e9882006-01-09 16:44:46 +0100522 .owner = THIS_MODULE,
523 .llseek = snd_info_entry_llseek,
524 .read = snd_info_entry_read,
525 .write = snd_info_entry_write,
526 .poll = snd_info_entry_poll,
527 .unlocked_ioctl = snd_info_entry_ioctl,
528 .mmap = snd_info_entry_mmap,
529 .open = snd_info_entry_open,
530 .release = snd_info_entry_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531};
532
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533int __init snd_info_init(void)
534{
535 struct proc_dir_entry *p;
536
Al Viroe55d92b2011-07-24 02:07:46 -0400537 p = proc_mkdir("asound", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 if (p == NULL)
539 return -ENOMEM;
540 snd_proc_root = p;
541#ifdef CONFIG_SND_OSSEMUL
542 {
Takashi Iwai24c1f932005-11-17 13:58:48 +0100543 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 if ((entry = snd_info_create_module_entry(THIS_MODULE, "oss", NULL)) == NULL)
545 return -ENOMEM;
546 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
547 if (snd_info_register(entry) < 0) {
548 snd_info_free_entry(entry);
549 return -ENOMEM;
550 }
551 snd_oss_root = entry;
552 }
553#endif
554#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
555 {
Takashi Iwai24c1f932005-11-17 13:58:48 +0100556 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 if ((entry = snd_info_create_module_entry(THIS_MODULE, "seq", NULL)) == NULL)
558 return -ENOMEM;
559 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
560 if (snd_info_register(entry) < 0) {
561 snd_info_free_entry(entry);
562 return -ENOMEM;
563 }
564 snd_seq_root = entry;
565 }
566#endif
567 snd_info_version_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 snd_minor_info_init();
569 snd_minor_info_oss_init();
570 snd_card_info_init();
571 return 0;
572}
573
574int __exit snd_info_done(void)
575{
576 snd_card_info_done();
577 snd_minor_info_oss_done();
578 snd_minor_info_done();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 snd_info_version_done();
580 if (snd_proc_root) {
581#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
Takashi Iwai746d4a02006-06-23 14:37:59 +0200582 snd_info_free_entry(snd_seq_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583#endif
584#ifdef CONFIG_SND_OSSEMUL
Takashi Iwai746d4a02006-06-23 14:37:59 +0200585 snd_info_free_entry(snd_oss_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586#endif
Alexey Dobriyanc74c1202008-04-29 01:01:44 -0700587 snd_remove_proc_entry(NULL, snd_proc_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 }
589 return 0;
590}
591
592/*
593
594 */
595
596
597/*
598 * create a card proc file
599 * called from init.c
600 */
Takashi Iwai24c1f932005-11-17 13:58:48 +0100601int snd_info_card_create(struct snd_card *card)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
603 char str[8];
Takashi Iwai24c1f932005-11-17 13:58:48 +0100604 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200606 if (snd_BUG_ON(!card))
607 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 sprintf(str, "card%i", card->number);
610 if ((entry = snd_info_create_module_entry(card->module, str, NULL)) == NULL)
611 return -ENOMEM;
612 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
613 if (snd_info_register(entry) < 0) {
614 snd_info_free_entry(entry);
615 return -ENOMEM;
616 }
617 card->proc_root = entry;
618 return 0;
619}
620
621/*
622 * register the card proc file
623 * called from init.c
624 */
Takashi Iwai24c1f932005-11-17 13:58:48 +0100625int snd_info_card_register(struct snd_card *card)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626{
627 struct proc_dir_entry *p;
628
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200629 if (snd_BUG_ON(!card))
630 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
632 if (!strcmp(card->id, card->proc_root->name))
633 return 0;
634
635 p = proc_symlink(card->id, snd_proc_root, card->proc_root->name);
636 if (p == NULL)
637 return -ENOMEM;
638 card->proc_root_link = p;
639 return 0;
640}
641
642/*
Jaroslav Kyselac2eb9c42008-11-12 16:31:37 +0100643 * called on card->id change
644 */
645void snd_info_card_id_change(struct snd_card *card)
646{
647 mutex_lock(&info_mutex);
648 if (card->proc_root_link) {
649 snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
650 card->proc_root_link = NULL;
651 }
652 if (strcmp(card->id, card->proc_root->name))
653 card->proc_root_link = proc_symlink(card->id,
654 snd_proc_root,
655 card->proc_root->name);
656 mutex_unlock(&info_mutex);
657}
658
659/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 * de-register the card proc file
661 * called from init.c
662 */
Takashi Iwai746d4a02006-06-23 14:37:59 +0200663void snd_info_card_disconnect(struct snd_card *card)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664{
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200665 if (!card)
666 return;
Takashi Iwai746d4a02006-06-23 14:37:59 +0200667 mutex_lock(&info_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 if (card->proc_root_link) {
669 snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
670 card->proc_root_link = NULL;
671 }
Takashi Iwai746d4a02006-06-23 14:37:59 +0200672 if (card->proc_root)
673 snd_info_disconnect(card->proc_root);
674 mutex_unlock(&info_mutex);
675}
676
677/*
678 * release the card proc file resources
679 * called from init.c
680 */
681int snd_info_card_free(struct snd_card *card)
682{
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200683 if (!card)
684 return 0;
Takashi Iwai746d4a02006-06-23 14:37:59 +0200685 snd_info_free_entry(card->proc_root);
686 card->proc_root = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 return 0;
688}
689
690
691/**
692 * snd_info_get_line - read one line from the procfs buffer
693 * @buffer: the procfs buffer
694 * @line: the buffer to store
695 * @len: the max. buffer size - 1
696 *
697 * Reads one line from the buffer and stores the string.
698 *
699 * Returns zero if successful, or 1 if error or EOF.
700 */
Takashi Iwai24c1f932005-11-17 13:58:48 +0100701int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702{
703 int c = -1;
704
705 if (len <= 0 || buffer->stop || buffer->error)
706 return 1;
707 while (--len > 0) {
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200708 c = buffer->buffer[buffer->curr++];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 if (c == '\n') {
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200710 if (buffer->curr >= buffer->size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 buffer->stop = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 break;
713 }
714 *line++ = c;
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200715 if (buffer->curr >= buffer->size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 buffer->stop = 1;
717 break;
718 }
719 }
720 while (c != '\n' && !buffer->stop) {
Takashi Iwai7e4eeec2006-04-28 15:13:40 +0200721 c = buffer->buffer[buffer->curr++];
722 if (buffer->curr >= buffer->size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 buffer->stop = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 }
725 *line = '\0';
726 return 0;
727}
728
Takashi Iwaic0d3fb32006-04-28 15:13:39 +0200729EXPORT_SYMBOL(snd_info_get_line);
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731/**
Henrik Kretzschmar856def82005-07-08 13:53:42 +0200732 * snd_info_get_str - parse a string token
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 * @dest: the buffer to store the string token
734 * @src: the original string
735 * @len: the max. length of token - 1
736 *
737 * Parses the original string and copy a token to the given
738 * string buffer.
739 *
740 * Returns the updated pointer of the original string so that
741 * it can be used for the next call.
742 */
Takashi Iwai4f7454a2009-09-08 14:29:58 +0200743const char *snd_info_get_str(char *dest, const char *src, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744{
745 int c;
746
747 while (*src == ' ' || *src == '\t')
748 src++;
749 if (*src == '"' || *src == '\'') {
750 c = *src++;
751 while (--len > 0 && *src && *src != c) {
752 *dest++ = *src++;
753 }
754 if (*src == c)
755 src++;
756 } else {
757 while (--len > 0 && *src && *src != ' ' && *src != '\t') {
758 *dest++ = *src++;
759 }
760 }
761 *dest = 0;
762 while (*src == ' ' || *src == '\t')
763 src++;
764 return src;
765}
766
Takashi Iwaic0d3fb32006-04-28 15:13:39 +0200767EXPORT_SYMBOL(snd_info_get_str);
768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769/**
770 * snd_info_create_entry - create an info entry
771 * @name: the proc file name
772 *
773 * Creates an info entry with the given file name and initializes as
774 * the default state.
775 *
776 * Usually called from other functions such as
777 * snd_info_create_card_entry().
778 *
779 * Returns the pointer of the new instance, or NULL on failure.
780 */
Takashi Iwai24c1f932005-11-17 13:58:48 +0100781static struct snd_info_entry *snd_info_create_entry(const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782{
Takashi Iwai24c1f932005-11-17 13:58:48 +0100783 struct snd_info_entry *entry;
Takashi Iwaica2c0962005-09-09 14:20:23 +0200784 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 if (entry == NULL)
786 return NULL;
Paulo Marques543537b2005-06-23 00:09:02 -0700787 entry->name = kstrdup(name, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 if (entry->name == NULL) {
789 kfree(entry);
790 return NULL;
791 }
792 entry->mode = S_IFREG | S_IRUGO;
793 entry->content = SNDRV_INFO_CONTENT_TEXT;
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100794 mutex_init(&entry->access);
Takashi Iwai746d4a02006-06-23 14:37:59 +0200795 INIT_LIST_HEAD(&entry->children);
796 INIT_LIST_HEAD(&entry->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 return entry;
798}
799
800/**
801 * snd_info_create_module_entry - create an info entry for the given module
802 * @module: the module pointer
803 * @name: the file name
804 * @parent: the parent directory
805 *
806 * Creates a new info entry and assigns it to the given module.
807 *
808 * Returns the pointer of the new instance, or NULL on failure.
809 */
Takashi Iwai24c1f932005-11-17 13:58:48 +0100810struct snd_info_entry *snd_info_create_module_entry(struct module * module,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 const char *name,
Takashi Iwai24c1f932005-11-17 13:58:48 +0100812 struct snd_info_entry *parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Takashi Iwai24c1f932005-11-17 13:58:48 +0100814 struct snd_info_entry *entry = snd_info_create_entry(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 if (entry) {
816 entry->module = module;
817 entry->parent = parent;
818 }
819 return entry;
820}
821
Takashi Iwaic0d3fb32006-04-28 15:13:39 +0200822EXPORT_SYMBOL(snd_info_create_module_entry);
823
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824/**
825 * snd_info_create_card_entry - create an info entry for the given card
826 * @card: the card instance
827 * @name: the file name
828 * @parent: the parent directory
829 *
830 * Creates a new info entry and assigns it to the given card.
831 *
832 * Returns the pointer of the new instance, or NULL on failure.
833 */
Takashi Iwai24c1f932005-11-17 13:58:48 +0100834struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 const char *name,
Takashi Iwai24c1f932005-11-17 13:58:48 +0100836 struct snd_info_entry * parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
Takashi Iwai24c1f932005-11-17 13:58:48 +0100838 struct snd_info_entry *entry = snd_info_create_entry(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 if (entry) {
840 entry->module = card->module;
841 entry->card = card;
842 entry->parent = parent;
843 }
844 return entry;
845}
846
Takashi Iwaic0d3fb32006-04-28 15:13:39 +0200847EXPORT_SYMBOL(snd_info_create_card_entry);
848
Takashi Iwai746d4a02006-06-23 14:37:59 +0200849static void snd_info_disconnect(struct snd_info_entry *entry)
850{
851 struct list_head *p, *n;
852 struct proc_dir_entry *root;
853
854 list_for_each_safe(p, n, &entry->children) {
855 snd_info_disconnect(list_entry(p, struct snd_info_entry, list));
856 }
857
858 if (! entry->p)
859 return;
860 list_del_init(&entry->list);
861 root = entry->parent == NULL ? snd_proc_root : entry->parent->p;
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200862 snd_BUG_ON(!root);
Takashi Iwai746d4a02006-06-23 14:37:59 +0200863 snd_remove_proc_entry(root, entry->p);
864 entry->p = NULL;
865}
866
Takashi Iwai24c1f932005-11-17 13:58:48 +0100867static int snd_info_dev_free_entry(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868{
Takashi Iwai24c1f932005-11-17 13:58:48 +0100869 struct snd_info_entry *entry = device->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 snd_info_free_entry(entry);
871 return 0;
872}
873
Takashi Iwai24c1f932005-11-17 13:58:48 +0100874static int snd_info_dev_register_entry(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
Takashi Iwai24c1f932005-11-17 13:58:48 +0100876 struct snd_info_entry *entry = device->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 return snd_info_register(entry);
878}
879
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880/**
881 * snd_card_proc_new - create an info entry for the given card
882 * @card: the card instance
883 * @name: the file name
884 * @entryp: the pointer to store the new info entry
885 *
886 * Creates a new info entry and assigns it to the given card.
887 * Unlike snd_info_create_card_entry(), this function registers the
888 * info entry as an ALSA device component, so that it can be
889 * unregistered/released without explicit call.
890 * Also, you don't have to register this entry via snd_info_register(),
891 * since this will be registered by snd_card_register() automatically.
892 *
893 * The parent is assumed as card->proc_root.
894 *
895 * For releasing this entry, use snd_device_free() instead of
896 * snd_info_free_entry().
897 *
898 * Returns zero if successful, or a negative error code on failure.
899 */
Takashi Iwai24c1f932005-11-17 13:58:48 +0100900int snd_card_proc_new(struct snd_card *card, const char *name,
901 struct snd_info_entry **entryp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902{
Takashi Iwai24c1f932005-11-17 13:58:48 +0100903 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 .dev_free = snd_info_dev_free_entry,
905 .dev_register = snd_info_dev_register_entry,
Takashi Iwai746d4a02006-06-23 14:37:59 +0200906 /* disconnect is done via snd_info_card_disconnect() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 };
Takashi Iwai24c1f932005-11-17 13:58:48 +0100908 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 int err;
910
911 entry = snd_info_create_card_entry(card, name, card->proc_root);
912 if (! entry)
913 return -ENOMEM;
914 if ((err = snd_device_new(card, SNDRV_DEV_INFO, entry, &ops)) < 0) {
915 snd_info_free_entry(entry);
916 return err;
917 }
918 if (entryp)
919 *entryp = entry;
920 return 0;
921}
922
Takashi Iwaic0d3fb32006-04-28 15:13:39 +0200923EXPORT_SYMBOL(snd_card_proc_new);
924
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925/**
926 * snd_info_free_entry - release the info entry
927 * @entry: the info entry
928 *
929 * Releases the info entry. Don't call this after registered.
930 */
Takashi Iwai24c1f932005-11-17 13:58:48 +0100931void snd_info_free_entry(struct snd_info_entry * entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932{
933 if (entry == NULL)
934 return;
Takashi Iwai746d4a02006-06-23 14:37:59 +0200935 if (entry->p) {
936 mutex_lock(&info_mutex);
937 snd_info_disconnect(entry);
938 mutex_unlock(&info_mutex);
939 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 kfree(entry->name);
941 if (entry->private_free)
942 entry->private_free(entry);
943 kfree(entry);
944}
945
Takashi Iwaic0d3fb32006-04-28 15:13:39 +0200946EXPORT_SYMBOL(snd_info_free_entry);
947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948/**
949 * snd_info_register - register the info entry
950 * @entry: the info entry
951 *
952 * Registers the proc info entry.
953 *
954 * Returns zero if successful, or a negative error code on failure.
955 */
Takashi Iwai24c1f932005-11-17 13:58:48 +0100956int snd_info_register(struct snd_info_entry * entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957{
958 struct proc_dir_entry *root, *p = NULL;
959
Takashi Iwai7eaa9432008-08-08 17:09:09 +0200960 if (snd_BUG_ON(!entry))
961 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 root = entry->parent == NULL ? snd_proc_root : entry->parent->p;
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100963 mutex_lock(&info_mutex);
Alexey Dobriyan99b76232009-03-25 22:48:06 +0300964 p = create_proc_entry(entry->name, entry->mode, root);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 if (!p) {
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100966 mutex_unlock(&info_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 return -ENOMEM;
968 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 if (!S_ISDIR(entry->mode))
970 p->proc_fops = &snd_info_entry_operations;
971 p->size = entry->size;
972 p->data = entry;
973 entry->p = p;
Takashi Iwai746d4a02006-06-23 14:37:59 +0200974 if (entry->parent)
975 list_add_tail(&entry->list, &entry->parent->children);
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100976 mutex_unlock(&info_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 return 0;
978}
979
Takashi Iwaic0d3fb32006-04-28 15:13:39 +0200980EXPORT_SYMBOL(snd_info_register);
981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982/*
983
984 */
985
Takashi Iwai6581f4e2006-05-17 17:14:51 +0200986static struct snd_info_entry *snd_info_version_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
Takashi Iwai24c1f932005-11-17 13:58:48 +0100988static void snd_info_version_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989{
990 snd_iprintf(buffer,
991 "Advanced Linux Sound Architecture Driver Version "
992 CONFIG_SND_VERSION CONFIG_SND_DATE ".\n"
993 );
994}
995
996static int __init snd_info_version_init(void)
997{
Takashi Iwai24c1f932005-11-17 13:58:48 +0100998 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
1000 entry = snd_info_create_module_entry(THIS_MODULE, "version", NULL);
1001 if (entry == NULL)
1002 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 entry->c.text.read = snd_info_version_read;
1004 if (snd_info_register(entry) < 0) {
1005 snd_info_free_entry(entry);
1006 return -ENOMEM;
1007 }
1008 snd_info_version_entry = entry;
1009 return 0;
1010}
1011
1012static int __exit snd_info_version_done(void)
1013{
Takashi Iwai746d4a02006-06-23 14:37:59 +02001014 snd_info_free_entry(snd_info_version_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 return 0;
1016}
1017
1018#endif /* CONFIG_PROC_FS */