File: libvumod.h

package info (click to toggle)
vuos 0.9.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,616 kB
  • sloc: ansic: 22,155; python: 284; makefile: 28; sh: 4
file content (58 lines) | stat: -rw-r--r-- 2,320 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef VUMODLIB_H
#define VUMODLIB_H
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/vfs.h>
#include <sys/epoll.h>
#include <sys/mount.h>

/* pseudo file mgmt */

#define PSEUDOFILE_LOAD_CONTENTS 1
#define PSEUDOFILE_STORE_CLOSE 2
#define PSEUDOFILE_LOAD_DIRENTS 3

/* upcall: this is the prototype upcall function registered by pseudofile_open,
	 tag == PSEUDOFILE_LOAD_CONTENTS: upload the contents f-writing the file f
	 (this happens at first read/write/lseek)
	 tag == PSEUDOFILE_STORE_CLOSE: store/use the contents (and free any dynamic memory
	 allocated for pseudoprivate). f can be NULL if the file has been never read or written.
	 tag == PSEUDOFILE_LOAD_DIRENTS: populate the dir for getdents using pseudofile_filldir.
	 (this appens at first getdents64)
 */
typedef int (* pseudo_upcall)(int tag, FILE *f, int openflags, void *pseudoprivate);

/* helper function: convert struct stat's st_mode to struct dirent's d_type */
int pseudofile_mode2type(mode_t mode);

/* helper function: use path to fill in the buf of bufsiz bytes for readlink.
	 it returns -1/EINVAL if path is NULL */
ssize_t pseudofile_readlink_fill(char *path, char *buf, size_t bufsiz);

/* add an entry to the dir for getdents */
int pseudofile_filldir(FILE *f, char *name, ino_t ino, char type);

/* open a pseudofile: pseudoprivate is an opaque arg forwarded to the upcall.
 *private value must be stored and passed to all the other function here below.
 (e.g. using the private arg of the module's open syscall implementation */
int pseudofile_open(pseudo_upcall upcall, void *pseudoprivate, int flags, void **private);

/* syscall implementation for pseudofiles. The signature of these function has been
	 designed to be a drop in replacement for your module's functions. e.g. in yourmodule_init:
	 struct vu_service_t *s = vu_mod_getservice();
	 vu_syscall_handler(s, close) = pseudofile_close;
 */
int pseudofile_close(int fd, void *private);

int pseudofile_read(int fd, void *buf, size_t count, void *private);

int pseudofile_write(int fd, const void *buf, size_t count, void *private);

int pseudofile_lseek(int fd, off_t offset, int whence, void *private);

int pseudofile_getdents64(int fd,  struct dirent64 *dirp, unsigned int count, void *private);

#endif