"Fossies" - the Fresh Open Source Software Archive

Member "fuse-3.2.6/doc/html/null_8c_source.html" (11 May 2018, 21496 Bytes) of package /linux/misc/fuse-3.2.6.tar.xz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. Alternatively you can here view or download the uninterpreted raw source code. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

libfuse
null.c
Go to the documentation of this file.
1 /*
2  FUSE: Filesystem in Userspace
3  Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
4 
5  This program can be distributed under the terms of the GNU GPL.
6  See the file COPYING.
7 */
8 
25 #define FUSE_USE_VERSION 31
26 
27 #include <fuse.h>
28 #include <fuse_lowlevel.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <unistd.h>
32 #include <time.h>
33 #include <errno.h>
34 
35 static int null_getattr(const char *path, struct stat *stbuf,
36  struct fuse_file_info *fi)
37 {
38  (void) fi;
39 
40  if(strcmp(path, "/") != 0)
41  return -ENOENT;
42 
43  stbuf->st_mode = S_IFREG | 0644;
44  stbuf->st_nlink = 1;
45  stbuf->st_uid = getuid();
46  stbuf->st_gid = getgid();
47  stbuf->st_size = (1ULL << 32); /* 4G */
48  stbuf->st_blocks = 0;
49  stbuf->st_atime = stbuf->st_mtime = stbuf->st_ctime = time(NULL);
50 
51  return 0;
52 }
53 
54 static int null_truncate(const char *path, off_t size,
55  struct fuse_file_info *fi)
56 {
57  (void) size;
58  (void) fi;
59 
60  if(strcmp(path, "/") != 0)
61  return -ENOENT;
62 
63  return 0;
64 }
65 
66 static int null_open(const char *path, struct fuse_file_info *fi)
67 {
68  (void) fi;
69 
70  if(strcmp(path, "/") != 0)
71  return -ENOENT;
72 
73  return 0;
74 }
75 
76 static int null_read(const char *path, char *buf, size_t size,
77  off_t offset, struct fuse_file_info *fi)
78 {
79  (void) buf;
80  (void) offset;
81  (void) fi;
82 
83  if(strcmp(path, "/") != 0)
84  return -ENOENT;
85 
86  if (offset >= (1ULL << 32))
87  return 0;
88 
89  memset(buf, 0, size);
90  return size;
91 }
92 
93 static int null_write(const char *path, const char *buf, size_t size,
94  off_t offset, struct fuse_file_info *fi)
95 {
96  (void) buf;
97  (void) offset;
98  (void) fi;
99 
100  if(strcmp(path, "/") != 0)
101  return -ENOENT;
102 
103  return size;
104 }
105 
106 static struct fuse_operations null_oper = {
107  .getattr = null_getattr,
108  .truncate = null_truncate,
109  .open = null_open,
110  .read = null_read,
111  .write = null_write,
112 };
113 
114 int main(int argc, char *argv[])
115 {
116  struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
117  struct fuse_cmdline_opts opts;
118  struct stat stbuf;
119 
120  if (fuse_parse_cmdline(&args, &opts) != 0)
121  return 1;
122 
123  if (!opts.mountpoint) {
124  fprintf(stderr, "missing mountpoint parameter\n");
125  return 1;
126  }
127 
128  if (stat(opts.mountpoint, &stbuf) == -1) {
129  fprintf(stderr ,"failed to access mountpoint %s: %s\n",
130  opts.mountpoint, strerror(errno));
131  return 1;
132  }
133  if (!S_ISREG(stbuf.st_mode)) {
134  fprintf(stderr, "mountpoint is not a regular file\n");
135  return 1;
136  }
137 
138  return fuse_main(argc, argv, &null_oper, NULL);
139 }
int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts)
Definition: helper.c:197
int(* getattr)(const char *, struct stat *, struct fuse_file_info *fi)
Definition: fuse.h:311
#define FUSE_ARGS_INIT(argc, argv)
Definition: fuse_opt.h:123
#define fuse_main(argc, argv, op, private_data)
Definition: fuse.h:829