Xenomai  3.0.5
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 
33 struct xnvfile_directory;
36 struct xnvfile_lock_ops;
37 
38 struct xnvfile {
39  struct proc_dir_entry *pde;
40  struct file *file;
41  struct xnvfile_lock_ops *lockops;
42  int refcnt;
43  void *private;
44 };
45 
67  int (*get)(struct xnvfile *vfile);
75  void (*put)(struct xnvfile *vfile);
76 };
77 
78 struct xnvfile_hostlock_class {
79  struct xnvfile_lock_ops ops;
80  struct mutex mutex;
81 };
82 
83 struct xnvfile_nklock_class {
84  struct xnvfile_lock_ops ops;
85  spl_t s;
86 };
87 
88 struct xnvfile_input {
89  const char __user *u_buf;
90  size_t size;
91  struct xnvfile *vfile;
92 };
93 
121  int (*rewind)(struct xnvfile_regular_iterator *it);
154  void *(*begin)(struct xnvfile_regular_iterator *it);
181  void *(*next)(struct xnvfile_regular_iterator *it);
190  void (*end)(struct xnvfile_regular_iterator *it);
219  int (*show)(struct xnvfile_regular_iterator *it, void *data);
248  ssize_t (*store)(struct xnvfile_input *input);
249 };
250 
251 struct xnvfile_regular {
252  struct xnvfile entry;
253  size_t privsz;
254  struct xnvfile_regular_ops *ops;
255 };
256 
257 struct xnvfile_regular_template {
258  size_t privsz;
259  struct xnvfile_regular_ops *ops;
260  struct xnvfile_lock_ops *lockops;
261 };
262 
271  loff_t pos;
273  struct seq_file *seq;
275  struct xnvfile_regular *vfile;
280  char private[0];
281 };
282 
334  int (*rewind)(struct xnvfile_snapshot_iterator *it);
362  void *(*begin)(struct xnvfile_snapshot_iterator *it);
380  void (*end)(struct xnvfile_snapshot_iterator *it, void *buf);
413  int (*next)(struct xnvfile_snapshot_iterator *it, void *data);
442  int (*show)(struct xnvfile_snapshot_iterator *it, void *data);
472  ssize_t (*store)(struct xnvfile_input *input);
473 };
474 
484  int rev;
485 };
486 
487 struct xnvfile_snapshot_template {
488  size_t privsz;
489  size_t datasz;
490  struct xnvfile_rev_tag *tag;
491  struct xnvfile_snapshot_ops *ops;
492  struct xnvfile_lock_ops *lockops;
493 };
494 
507  struct xnvfile entry;
508  size_t privsz;
509  size_t datasz;
510  struct xnvfile_rev_tag *tag;
511  struct xnvfile_snapshot_ops *ops;
512 };
513 
522  int nrdata;
524  caddr_t databuf;
526  struct seq_file *seq;
530  void (*endfn)(struct xnvfile_snapshot_iterator *it, void *buf);
535  char private[0];
536 };
537 
538 struct xnvfile_directory {
539  struct xnvfile entry;
540 };
541 
542 struct xnvfile_link {
543  struct xnvfile entry;
544 };
545 
546 /* vfile.begin()=> */
547 #define VFILE_SEQ_EMPTY ((void *)-1)
548 /* =>vfile.show() */
549 #define VFILE_SEQ_START SEQ_START_TOKEN
550 /* vfile.next/show()=> */
551 #define VFILE_SEQ_SKIP 2
552 
553 #define xnvfile_printf(it, args...) seq_printf((it)->seq, ##args)
554 #define xnvfile_write(it, data, len) seq_write((it)->seq, (data),(len))
555 #define xnvfile_puts(it, s) seq_puts((it)->seq, (s))
556 #define xnvfile_putc(it, c) seq_putc((it)->seq, (c))
557 
558 static inline void xnvfile_touch_tag(struct xnvfile_rev_tag *tag)
559 {
560  tag->rev++;
561 }
562 
563 static inline void xnvfile_touch(struct xnvfile_snapshot *vfile)
564 {
565  xnvfile_touch_tag(vfile->tag);
566 }
567 
568 #define xnvfile_noentry \
569  { \
570  .pde = NULL, \
571  .private = NULL, \
572  .file = NULL, \
573  .refcnt = 0, \
574  }
575 
576 #define xnvfile_nodir { .entry = xnvfile_noentry }
577 #define xnvfile_nolink { .entry = xnvfile_noentry }
578 #define xnvfile_nofile { .entry = xnvfile_noentry }
579 
580 #define xnvfile_priv(e) ((e)->entry.private)
581 #define xnvfile_nref(e) ((e)->entry.refcnt)
582 #define xnvfile_file(e) ((e)->entry.file)
583 #define xnvfile_iterator_priv(it) ((void *)(&(it)->private))
584 
585 extern struct xnvfile_nklock_class xnvfile_nucleus_lock;
586 
587 extern struct xnvfile_directory cobalt_vfroot;
588 
589 int xnvfile_init_root(void);
590 
591 void xnvfile_destroy_root(void);
592 
593 int xnvfile_init_snapshot(const char *name,
594  struct xnvfile_snapshot *vfile,
595  struct xnvfile_directory *parent);
596 
597 int xnvfile_init_regular(const char *name,
598  struct xnvfile_regular *vfile,
599  struct xnvfile_directory *parent);
600 
601 int xnvfile_init_dir(const char *name,
602  struct xnvfile_directory *vdir,
603  struct xnvfile_directory *parent);
604 
605 int xnvfile_init_link(const char *from,
606  const char *to,
607  struct xnvfile_link *vlink,
608  struct xnvfile_directory *parent);
609 
610 void xnvfile_destroy(struct xnvfile *vfile);
611 
612 ssize_t xnvfile_get_blob(struct xnvfile_input *input,
613  void *data, size_t size);
614 
615 ssize_t xnvfile_get_string(struct xnvfile_input *input,
616  char *s, size_t maxlen);
617 
618 ssize_t xnvfile_get_integer(struct xnvfile_input *input, long *valp);
619 
620 int __vfile_hostlock_get(struct xnvfile *vfile);
621 
622 void __vfile_hostlock_put(struct xnvfile *vfile);
623 
624 static inline
625 void xnvfile_destroy_snapshot(struct xnvfile_snapshot *vfile)
626 {
627  xnvfile_destroy(&vfile->entry);
628 }
629 
630 static inline
631 void xnvfile_destroy_regular(struct xnvfile_regular *vfile)
632 {
633  xnvfile_destroy(&vfile->entry);
634 }
635 
636 static inline
637 void xnvfile_destroy_dir(struct xnvfile_directory *vdir)
638 {
639  xnvfile_destroy(&vdir->entry);
640 }
641 
642 static inline
643 void xnvfile_destroy_link(struct xnvfile_link *vlink)
644 {
645  xnvfile_destroy(&vlink->entry);
646 }
647 
648 #define DEFINE_VFILE_HOSTLOCK(name) \
649  struct xnvfile_hostlock_class name = { \
650  .ops = { \
651  .get = __vfile_hostlock_get, \
652  .put = __vfile_hostlock_put, \
653  }, \
654  .mutex = __MUTEX_INITIALIZER(name.mutex), \
655  }
656 
657 #else /* !CONFIG_XENO_OPT_VFILE */
658 
659 #define xnvfile_touch_tag(tag) do { } while (0)
660 
661 #define xnvfile_touch(vfile) do { } while (0)
662 
663 #endif /* !CONFIG_XENO_OPT_VFILE */
664 
667 #endif /* !_COBALT_KERNEL_VFILE_H */
struct xnvfile_snapshot * vfile
Backlink to the vfile being read.
Definition: vfile.h:528
Snapshot-driven vfile iterator.
Definition: vfile.h:520
void xnvfile_destroy(struct xnvfile *vfile)
Removes a virtual file entry.
Definition: vfile.c:758
loff_t pos
Current record position while iterating.
Definition: vfile.h:271
Vfile locking operations.
Definition: vfile.h:54
struct seq_file * seq
Backlink to the host sequential file supporting the vfile.
Definition: vfile.h:526
Snapshot revision tag.
Definition: vfile.h:482
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:726
Snapshot vfile operation descriptor.
Definition: vfile.h:293
int xnvfile_init_regular(const char *name, struct xnvfile_regular *vfile, struct xnvfile_directory *parent)
Initialize a regular vfile.
Definition: vfile.c:635
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:888
struct xnvfile_regular * vfile
Backlink to the vfile being read.
Definition: vfile.h:275
Regular vfile iterator.
Definition: vfile.h:269
int rev
Current revision number.
Definition: vfile.h:484
caddr_t databuf
Address of record buffer.
Definition: vfile.h:524
int xnvfile_init_snapshot(const char *name, struct xnvfile_snapshot *vfile, struct xnvfile_directory *parent)
Initialize a snapshot-driven vfile.
Definition: vfile.c:396
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:835
Regular vfile operation descriptor.
Definition: vfile.h:103
struct seq_file * seq
Backlink to the host sequential file supporting the vfile.
Definition: vfile.h:273
int xnvfile_init_dir(const char *name, struct xnvfile_directory *vdir, struct xnvfile_directory *parent)
Initialize a virtual directory entry.
Definition: vfile.c:679
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:791
Snapshot vfile descriptor.
Definition: vfile.h:506
int nrdata
Number of collected records.
Definition: vfile.h:522