Xenomai 3.3.2
Loading...
Searching...
No Matches
vfile.h
1/*
2 * Copyright (C) 2010 Philippe Gerum <rpm@xenomai.org>
3 *
4 * Xenomai is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#ifndef _COBALT_KERNEL_VFILE_H
20#define _COBALT_KERNEL_VFILE_H
21
22#if defined(CONFIG_XENO_OPT_VFILE) || defined(DOXYGEN_CPP)
23
24#include <linux/proc_fs.h>
25#include <linux/seq_file.h>
26#include <cobalt/kernel/lock.h>
27
33struct xnvfile_directory;
36struct xnvfile_lock_ops;
37
38struct xnvfile {
39 struct proc_dir_entry *pde;
40 struct file *file;
41 struct xnvfile_lock_ops *lockops;
42 struct mutex mutex;
43 int refcnt;
44 void *private;
45};
46
68 int (*get)(struct xnvfile *vfile);
76 void (*put)(struct xnvfile *vfile);
77};
78
79struct xnvfile_hostlock_class {
80 struct xnvfile_lock_ops ops;
81 struct mutex mutex;
82};
83
84struct xnvfile_nklock_class {
85 struct xnvfile_lock_ops ops;
86 spl_t s;
87};
88
89struct xnvfile_input {
90 const char __user *u_buf;
91 size_t size;
92 struct xnvfile *vfile;
93};
94
155 void *(*begin)(struct xnvfile_regular_iterator *it);
182 void *(*next)(struct xnvfile_regular_iterator *it);
191 void (*end)(struct xnvfile_regular_iterator *it);
220 int (*show)(struct xnvfile_regular_iterator *it, void *data);
249 ssize_t (*store)(struct xnvfile_input *input);
250};
251
252struct xnvfile_regular {
253 struct xnvfile entry;
254 size_t privsz;
255 struct xnvfile_regular_ops *ops;
256};
257
258struct xnvfile_regular_template {
259 size_t privsz;
260 struct xnvfile_regular_ops *ops;
261 struct xnvfile_lock_ops *lockops;
262};
263
272 loff_t pos;
274 struct seq_file *seq;
276 struct xnvfile_regular *vfile;
281 char private[0];
282};
283
363 void *(*begin)(struct xnvfile_snapshot_iterator *it);
381 void (*end)(struct xnvfile_snapshot_iterator *it, void *buf);
414 int (*next)(struct xnvfile_snapshot_iterator *it, void *data);
443 int (*show)(struct xnvfile_snapshot_iterator *it, void *data);
473 ssize_t (*store)(struct xnvfile_input *input);
474};
475
485 int rev;
486};
487
488struct xnvfile_snapshot_template {
489 size_t privsz;
490 size_t datasz;
491 struct xnvfile_rev_tag *tag;
492 struct xnvfile_snapshot_ops *ops;
493 struct xnvfile_lock_ops *lockops;
494};
495
508 struct xnvfile entry;
509 size_t privsz;
510 size_t datasz;
511 struct xnvfile_rev_tag *tag;
512 struct xnvfile_snapshot_ops *ops;
513};
514
525 caddr_t databuf;
527 struct seq_file *seq;
531 void (*endfn)(struct xnvfile_snapshot_iterator *it, void *buf);
536 char private[0];
537};
538
539struct xnvfile_directory {
540 struct xnvfile entry;
541};
542
543struct xnvfile_link {
544 struct xnvfile entry;
545};
546
547/* vfile.begin()=> */
548#define VFILE_SEQ_EMPTY ((void *)-1)
549/* =>vfile.show() */
550#define VFILE_SEQ_START SEQ_START_TOKEN
551/* vfile.next/show()=> */
552#define VFILE_SEQ_SKIP 2
553
554#define xnvfile_printf(it, args...) seq_printf((it)->seq, ##args)
555#define xnvfile_write(it, data, len) seq_write((it)->seq, (data),(len))
556#define xnvfile_puts(it, s) seq_puts((it)->seq, (s))
557#define xnvfile_putc(it, c) seq_putc((it)->seq, (c))
558
559static inline void xnvfile_touch_tag(struct xnvfile_rev_tag *tag)
560{
561 tag->rev++;
562}
563
564static inline void xnvfile_touch(struct xnvfile_snapshot *vfile)
565{
566 xnvfile_touch_tag(vfile->tag);
567}
568
569#define xnvfile_noentry \
570 { \
571 .pde = NULL, \
572 .private = NULL, \
573 .file = NULL, \
574 .refcnt = 0, \
575 }
576
577#define xnvfile_nodir { .entry = xnvfile_noentry }
578#define xnvfile_nolink { .entry = xnvfile_noentry }
579#define xnvfile_nofile { .entry = xnvfile_noentry }
580
581#define xnvfile_priv(e) ((e)->entry.private)
582#define xnvfile_nref(e) ((e)->entry.refcnt)
583#define xnvfile_file(e) ((e)->entry.file)
584#define xnvfile_iterator_priv(it) ((void *)(&(it)->private))
585
586extern struct xnvfile_nklock_class xnvfile_nucleus_lock;
587
588extern struct xnvfile_directory cobalt_vfroot;
589
590int xnvfile_init_root(void);
591
592void xnvfile_destroy_root(void);
593
594int xnvfile_init_snapshot(const char *name,
595 struct xnvfile_snapshot *vfile,
596 struct xnvfile_directory *parent);
597
598int xnvfile_init_regular(const char *name,
599 struct xnvfile_regular *vfile,
600 struct xnvfile_directory *parent);
601
602int xnvfile_init_dir(const char *name,
603 struct xnvfile_directory *vdir,
604 struct xnvfile_directory *parent);
605
606int xnvfile_init_link(const char *from,
607 const char *to,
608 struct xnvfile_link *vlink,
609 struct xnvfile_directory *parent);
610
611void xnvfile_destroy(struct xnvfile *vfile);
612
613ssize_t xnvfile_get_blob(struct xnvfile_input *input,
614 void *data, size_t size);
615
616ssize_t xnvfile_get_string(struct xnvfile_input *input,
617 char *s, size_t maxlen);
618
619ssize_t xnvfile_get_integer(struct xnvfile_input *input, long *valp);
620
621int __vfile_hostlock_get(struct xnvfile *vfile);
622
623void __vfile_hostlock_put(struct xnvfile *vfile);
624
625static inline
626void xnvfile_destroy_snapshot(struct xnvfile_snapshot *vfile)
627{
628 xnvfile_destroy(&vfile->entry);
629}
630
631static inline
632void xnvfile_destroy_regular(struct xnvfile_regular *vfile)
633{
634 xnvfile_destroy(&vfile->entry);
635}
636
637static inline
638void xnvfile_destroy_dir(struct xnvfile_directory *vdir)
639{
640 xnvfile_destroy(&vdir->entry);
641}
642
643static inline
644void xnvfile_destroy_link(struct xnvfile_link *vlink)
645{
646 xnvfile_destroy(&vlink->entry);
647}
648
649#define DEFINE_VFILE_HOSTLOCK(name) \
650 struct xnvfile_hostlock_class name = { \
651 .ops = { \
652 .get = __vfile_hostlock_get, \
653 .put = __vfile_hostlock_put, \
654 }, \
655 .mutex = __MUTEX_INITIALIZER(name.mutex), \
656 }
657
658#else /* !CONFIG_XENO_OPT_VFILE */
659
660#define xnvfile_touch_tag(tag) do { } while (0)
661
662#define xnvfile_touch(vfile) do { } while (0)
663
664#endif /* !CONFIG_XENO_OPT_VFILE */
665
668#endif /* !_COBALT_KERNEL_VFILE_H */
ssize_t xnvfile_get_integer(struct xnvfile_input *input, long *valp)
Evaluate the string written to the vfile as a long integer.
Definition vfile.c:907
struct xnvfile_directory cobalt_vfroot
Xenomai vfile root directory.
Definition vfile.c:88
int xnvfile_init_link(const char *from, const char *to, struct xnvfile_link *vlink, struct xnvfile_directory *parent)
Initialize a virtual link entry.
Definition vfile.c:745
void xnvfile_destroy(struct xnvfile *vfile)
Removes a virtual file entry.
Definition vfile.c:777
ssize_t xnvfile_get_blob(struct xnvfile_input *input, void *data, size_t size)
Read in a data bulk written to the vfile.
Definition vfile.c:810
int xnvfile_init_regular(const char *name, struct xnvfile_regular *vfile, struct xnvfile_directory *parent)
Initialize a regular vfile.
Definition vfile.c:653
int xnvfile_init_snapshot(const char *name, struct xnvfile_snapshot *vfile, struct xnvfile_directory *parent)
Initialize a snapshot-driven vfile.
Definition vfile.c:405
int xnvfile_init_dir(const char *name, struct xnvfile_directory *vdir, struct xnvfile_directory *parent)
Initialize a virtual directory entry.
Definition vfile.c:698
ssize_t xnvfile_get_string(struct xnvfile_input *input, char *s, size_t maxlen)
Read in a C-string written to the vfile.
Definition vfile.c:854
Vfile locking operations .
Definition vfile.h:55
void(* put)(struct xnvfile *vfile)
This handler should release the lock previously grabbed by the get() handler.
Definition vfile.h:76
int(* get)(struct xnvfile *vfile)
This handler should grab the desired lock.
Definition vfile.h:68
Regular vfile iterator .
Definition vfile.h:270
struct seq_file * seq
Backlink to the host sequential file supporting the vfile.
Definition vfile.h:274
loff_t pos
Current record position while iterating.
Definition vfile.h:272
struct xnvfile_regular * vfile
Backlink to the vfile being read.
Definition vfile.h:276
Regular vfile operation descriptor .
Definition vfile.h:104
void(* end)(struct xnvfile_regular_iterator *it)
This handler is called after all records have been output.
Definition vfile.h:191
int(* show)(struct xnvfile_regular_iterator *it, void *data)
This handler should format and output a record.
Definition vfile.h:220
ssize_t(* store)(struct xnvfile_input *input)
This handler receives data written to the vfile, likely for updating some kernel setting,...
Definition vfile.h:249
int(* rewind)(struct xnvfile_regular_iterator *it)
This handler is called only once, when the virtual file is opened, before the begin() handler is invo...
Definition vfile.h:122
Snapshot revision tag .
Definition vfile.h:483
int rev
Current revision number.
Definition vfile.h:485
Snapshot-driven vfile iterator .
Definition vfile.h:521
struct xnvfile_snapshot * vfile
Backlink to the vfile being read.
Definition vfile.h:529
int nrdata
Number of collected records.
Definition vfile.h:523
void(* endfn)(struct xnvfile_snapshot_iterator *it, void *buf)
Buffer release handler.
Definition vfile.h:531
struct seq_file * seq
Backlink to the host sequential file supporting the vfile.
Definition vfile.h:527
caddr_t databuf
Address of record buffer.
Definition vfile.h:525
Snapshot vfile operation descriptor .
Definition vfile.h:294
int(* next)(struct xnvfile_snapshot_iterator *it, void *data)
This handler fetches the next record, as part of the snapshot data to be sent back to the reader via ...
Definition vfile.h:414
ssize_t(* store)(struct xnvfile_input *input)
This handler receives data written to the vfile, likely for updating the associated Xenomai object's ...
Definition vfile.h:473
void(* end)(struct xnvfile_snapshot_iterator *it, void *buf)
This handler releases the memory buffer previously obtained from begin().
Definition vfile.h:381
int(* show)(struct xnvfile_snapshot_iterator *it, void *data)
This handler should format and output a record from the collected data.
Definition vfile.h:443
int(* rewind)(struct xnvfile_snapshot_iterator *it)
This handler (re-)initializes the data collection, moving the seek pointer at the first record.
Definition vfile.h:335
Snapshot vfile descriptor .
Definition vfile.h:507