2 * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * LATCHESAR IONKOV AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
23 #define _XOPEN_SOURCE 600
34 static Npfile
* null_first(Npfile
*);
35 static Npfile
* null_next(Npfile
*, Npfile
*);
36 static int null_read(Npfilefid
*, u64
, u32
, u8
*, Npreq
*);
37 static int null_write(Npfilefid
*, u64
, u32
, u8
*, Npreq
*);
38 static int null_wstat(Npfile
*, Npstat
*);
39 static void null_connclose(Npconn
*);
44 static Npdirops rootops
= {
49 static Npfileops nullops
= {
58 fprintf(stderr
, "nullfs: -d -w nthreads mount-point\n");
63 main(int argc
, char **argv
)
65 int c
, debuglevel
, nwthreads
;
72 user
= np_default_users
->uid2user(np_default_users
, getuid());
73 while ((c
= getopt(argc
, argv
, "dw:")) != -1) {
80 nwthreads
= strtol(optarg
, &s
, 10);
86 fprintf(stderr
, "invalid option\n");
94 fprintf(stderr
, "invalid user\n");
110 root
= npfile_alloc(NULL
, strdup(""), 0755|Dmdir
, 0, &rootops
, NULL
);
113 root
->atime
= time(NULL
);
114 root
->mtime
= root
->atime
;
116 root
->gid
= user
->dfltgroup
;
119 null
= npfile_alloc(root
, strdup("null"), 0644, 1, &nullops
, NULL
);
121 root
->dirfirst
= null
;
122 root
->dirlast
= null
;
124 srv
= np_pipesrv_create(nwthreads
);
128 srv
->debuglevel
= debuglevel
;
129 srv
->connclose
= null_connclose
;
130 npfile_init_srv(srv
, root
);
132 np_pipesrv_mount(srv
, argv
[optind
], user
->uname
, 0, opts
);
143 null_connclose(Npconn
*conn
)
149 null_first(Npfile
*dir
)
152 npfile_incref(dir
->dirfirst
);
154 return dir
->dirfirst
;
158 null_next(Npfile
*dir
, Npfile
*prevchild
)
161 npfile_incref(prevchild
->next
);
163 return prevchild
->next
;
167 null_read(Npfilefid
* file
, u64 offset
, u32 count
, u8
* data
, Npreq
*req
)
169 memset(data
, 0, count
);
174 null_write(Npfilefid
* file
, u64 offset
, u32 count
, u8
* data
, Npreq
*req
)
180 null_wstat(Npfile
* file
, Npstat
* stat
)