Xenomai API  2.6.5
vfile.h
Go to the documentation of this file.
1 
24 #ifndef _XENO_NUCLEUS_VFILE_H
25 #define _XENO_NUCLEUS_VFILE_H
26 
27 #if defined(CONFIG_XENO_OPT_VFILE) || defined(DOXYGEN_CPP)
28 
32 #include <linux/proc_fs.h>
33 #include <linux/seq_file.h>
34 #include <nucleus/types.h>
35 
36 struct xnvfile_directory;
39 struct xnvfile_lock_ops;
40 
41 struct xnvfile {
42  struct proc_dir_entry *pde;
43  struct file *file;
44  struct xnvfile_lock_ops *lockops;
45  int refcnt;
46  void *private;
47 };
48 
70  int (*get)(struct xnvfile *vfile);
78  void (*put)(struct xnvfile *vfile);
79 };
80 
81 /*
82  * XXX: struct semaphore is legacy for mutual exclusion, but supported
83  * on both 2.4 and 2.6 kernels. Will be changed to mutex when 2.4
84  * support is dropped from Xenomai.
85  */
86 struct xnvfile_hostlock_class {
87  struct xnvfile_lock_ops ops;
88  struct semaphore sem;
89 };
90 
91 struct xnvfile_nklock_class {
92  struct xnvfile_lock_ops ops;
93  spl_t s;
94 };
95 
96 struct xnvfile_input {
97  const char __user *u_buf;
98  size_t size;
99  struct xnvfile *vfile;
100 };
101 
129  int (*rewind)(struct xnvfile_regular_iterator *it);
162  void *(*begin)(struct xnvfile_regular_iterator *it);
189  void *(*next)(struct xnvfile_regular_iterator *it);
198  void (*end)(struct xnvfile_regular_iterator *it);
227  int (*show)(struct xnvfile_regular_iterator *it, void *data);
256  ssize_t (*store)(struct xnvfile_input *input);
257 };
258 
259 struct xnvfile_regular {
260  struct xnvfile entry;
261  size_t privsz;
262  struct xnvfile_regular_ops *ops;
263 };
264 
265 struct xnvfile_regular_template {
266  size_t privsz;
267  struct xnvfile_regular_ops *ops;
268  struct xnvfile_lock_ops *lockops;
269 };
270 
279  loff_t pos;
281  struct seq_file *seq;
283  struct xnvfile_regular *vfile;
288  char private[0];
289 };
290 
342  int (*rewind)(struct xnvfile_snapshot_iterator *it);
370  void *(*begin)(struct xnvfile_snapshot_iterator *it);
388  void (*end)(struct xnvfile_snapshot_iterator *it, void *buf);
421  int (*next)(struct xnvfile_snapshot_iterator *it, void *data);
450  int (*show)(struct xnvfile_snapshot_iterator *it, void *data);
480  ssize_t (*store)(struct xnvfile_input *input);
481 };
482 
492  int rev;
493 };
494 
495 struct xnvfile_snapshot_template {
496  size_t privsz;
497  size_t datasz;
498  struct xnvfile_rev_tag *tag;
499  struct xnvfile_snapshot_ops *ops;
500  struct xnvfile_lock_ops *lockops;
501 };
502 
515  struct xnvfile entry;
516  size_t privsz;
517  size_t datasz;
518  struct xnvfile_rev_tag *tag;
519  struct xnvfile_snapshot_ops *ops;
520 };
521 
530  int nrdata;
532  caddr_t databuf;
534  struct seq_file *seq;
538  void (*endfn)(struct xnvfile_snapshot_iterator *it, void *buf);
543  char private[0];
544 };
545 
546 struct xnvfile_directory {
547  struct xnvfile entry;
548 };
549 
550 struct xnvfile_link {
551  struct xnvfile entry;
552 };
553 
554 /* vfile.begin()=> */
555 #define VFILE_SEQ_EMPTY ((void *)-1)
556 /* =>vfile.show() */
557 #define VFILE_SEQ_START SEQ_START_TOKEN
558 /* vfile.next/show()=> */
559 #define VFILE_SEQ_SKIP 2
560 
561 #define xnvfile_printf(it, args...) seq_printf((it)->seq, ##args)
562 #define xnvfile_write(it, data, len) seq_write((it)->seq, (data),(len))
563 #define xnvfile_puts(it, s) seq_puts((it)->seq, (s))
564 #define xnvfile_putc(it, c) seq_putc((it)->seq, (c))
565 
566 static inline void xnvfile_touch_tag(struct xnvfile_rev_tag *tag)
567 {
568  tag->rev++;
569 }
570 
571 static inline void xnvfile_touch(struct xnvfile_snapshot *vfile)
572 {
573  xnvfile_touch_tag(vfile->tag);
574 }
575 
576 #define xnvfile_noentry \
577  { \
578  .pde = NULL, \
579  .private = NULL, \
580  .file = NULL, \
581  .refcnt = 0, \
582  }
583 
584 #define xnvfile_nodir { .entry = xnvfile_noentry }
585 #define xnvfile_nolink { .entry = xnvfile_noentry }
586 #define xnvfile_nofile { .entry = xnvfile_noentry }
587 
588 #define xnvfile_priv(e) ((e)->entry.private)
589 #define xnvfile_nref(e) ((e)->entry.refcnt)
590 #define xnvfile_file(e) ((e)->entry.file)
591 #define xnvfile_iterator_priv(it) ((void *)(&(it)->private))
592 
593 extern struct xnvfile_nklock_class xnvfile_nucleus_lock;
594 
595 extern struct xnvfile_directory nkvfroot;
596 
597 int xnvfile_init_root(void);
598 
599 void xnvfile_destroy_root(void);
600 
601 #ifdef __cplusplus
602 extern "C" {
603 #endif
604 
605 int xnvfile_init_snapshot(const char *name,
606  struct xnvfile_snapshot *vfile,
607  struct xnvfile_directory *parent);
608 
609 int xnvfile_init_regular(const char *name,
610  struct xnvfile_regular *vfile,
611  struct xnvfile_directory *parent);
612 
613 int xnvfile_init_dir(const char *name,
614  struct xnvfile_directory *vdir,
615  struct xnvfile_directory *parent);
616 
617 int xnvfile_init_link(const char *from,
618  const char *to,
619  struct xnvfile_link *vlink,
620  struct xnvfile_directory *parent);
621 
622 void xnvfile_destroy(struct xnvfile *vfile);
623 
624 ssize_t xnvfile_get_blob(struct xnvfile_input *input,
625  void *data, size_t size);
626 
627 ssize_t xnvfile_get_string(struct xnvfile_input *input,
628  char *s, size_t maxlen);
629 
630 ssize_t xnvfile_get_integer(struct xnvfile_input *input, long *valp);
631 
632 int __vfile_hostlock_get(struct xnvfile *vfile);
633 
634 void __vfile_hostlock_put(struct xnvfile *vfile);
635 
636 #ifdef __cplusplus
637 }
638 #endif
639 
640 static inline
641 void xnvfile_destroy_snapshot(struct xnvfile_snapshot *vfile)
642 {
643  xnvfile_destroy(&vfile->entry);
644 }
645 
646 static inline
647 void xnvfile_destroy_regular(struct xnvfile_regular *vfile)
648 {
649  xnvfile_destroy(&vfile->entry);
650 }
651 
652 static inline
653 void xnvfile_destroy_dir(struct xnvfile_directory *vdir)
654 {
655  xnvfile_destroy(&vdir->entry);
656 }
657 
658 static inline
659 void xnvfile_destroy_link(struct xnvfile_link *vlink)
660 {
661  xnvfile_destroy(&vlink->entry);
662 }
663 
664 #define DEFINE_VFILE_HOSTLOCK(name) \
665  struct xnvfile_hostlock_class name = { \
666  .ops = { \
667  .get = __vfile_hostlock_get, \
668  .put = __vfile_hostlock_put, \
669  }, \
670  .sem = __SEMAPHORE_INITIALIZER(name.sem, 1), \
671  }
672 
673 #else /* !CONFIG_XENO_OPT_VFILE */
674 
675 #define xnvfile_touch_tag(tag) do { } while (0)
676 
677 #define xnvfile_touch(vfile) do { } while (0)
678 
679 #endif /* !CONFIG_XENO_OPT_VFILE */
680 
683 #endif /* !_XENO_NUCLEUS_VFILE_H */
struct xnvfile_snapshot * vfile
Backlink to the vfile being read.
Definition: vfile.h:536
Snapshot-driven vfile iterator.
Definition: vfile.h:528
struct xnvfile_directory nkvfroot
Xenomai vfile root directory.
Definition: vfile.c:88
void(* endfn)(struct xnvfile_snapshot_iterator *it, void *buf)
Buffer release handler.
Definition: vfile.h:538
int(* show)(struct xnvfile_regular_iterator *it, void *data)
Definition: vfile.h:227
loff_t pos
Current record position while iterating.
Definition: vfile.h:279
Vfile locking operations.
Definition: vfile.h:57
ssize_t(* store)(struct xnvfile_input *input)
Definition: vfile.h:256
ssize_t(* store)(struct xnvfile_input *input)
Definition: vfile.h:480
struct seq_file * seq
Backlink to the host sequential file supporting the vfile.
Definition: vfile.h:534
Snapshot revision tag.
Definition: vfile.h:490
int xnvfile_init_dir(const char *name, struct xnvfile_directory *vdir, struct xnvfile_directory *parent)
Initialize a virtual directory entry.
Definition: vfile.c:695
Snapshot vfile operation descriptor.
Definition: vfile.h:301
int(* next)(struct xnvfile_snapshot_iterator *it, void *data)
Definition: vfile.h:421
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:741
int(* rewind)(struct xnvfile_regular_iterator *it)
Definition: vfile.h:129
void(* put)(struct xnvfile *vfile)
Definition: vfile.h:78
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:845
int xnvfile_init_regular(const char *name, struct xnvfile_regular *vfile, struct xnvfile_directory *parent)
Initialize a regular vfile.
Definition: vfile.c:651
struct xnvfile_regular * vfile
Backlink to the vfile being read.
Definition: vfile.h:283
Regular vfile iterator.
Definition: vfile.h:277
void(* end)(struct xnvfile_regular_iterator *it)
Definition: vfile.h:198
int(* show)(struct xnvfile_snapshot_iterator *it, void *data)
Definition: vfile.h:450
int rev
Current revision number.
Definition: vfile.h:492
caddr_t databuf
Address of record buffer.
Definition: vfile.h:532
int xnvfile_init_snapshot(const char *name, struct xnvfile_snapshot *vfile, struct xnvfile_directory *parent)
Initialize a snapshot-driven vfile.
Definition: vfile.c:412
Regular vfile operation descriptor.
Definition: vfile.h:111
struct seq_file * seq
Backlink to the host sequential file supporting the vfile.
Definition: vfile.h:281
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:803
int(* rewind)(struct xnvfile_snapshot_iterator *it)
Definition: vfile.h:342
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:895
void xnvfile_destroy(struct xnvfile *vfile)
Removes a virtual file entry.
Definition: vfile.c:772
void(* end)(struct xnvfile_snapshot_iterator *it, void *buf)
Definition: vfile.h:388
Snapshot vfile descriptor.
Definition: vfile.h:514
int nrdata
Number of collected records.
Definition: vfile.h:530