1 /* $NetBSD: pnullfs.c,v 1.17 2008/09/12 14:40:46 christos Exp $ */
4 * Copyright (c) 2007 Antti Kantee. All Rights Reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * pnullfs: puffs nullfs example
38 static void usage(void);
44 errx(1, "usage: %s [-s] [-o mntopts] nullpath mountpath",
49 main(int argc
, char *argv
[])
51 struct puffs_usermount
*pu
;
52 struct puffs_ops
*pops
;
53 struct puffs_pathobj
*po_root
;
54 struct puffs_node
*pn_root
;
66 pflags
= mntflags
= 0;
68 while ((ch
= getopt(argc
, argv
, "o:s")) != -1) {
71 mp
= getmntopts(optarg
, puffsmopts
, &mntflags
, &pflags
);
81 pflags
|= PUFFS_FLAG_BUILDPATH
;
85 if (pflags
& PUFFS_FLAG_OPDUMP
)
91 if (lstat(argv
[0], &sb
) == -1)
92 err(1, "stat %s", argv
[0]);
93 if ((sb
.st_mode
& S_IFDIR
) == 0)
94 errx(1, "%s is not a directory", argv
[0]);
97 puffs_null_setops(pops
);
99 if ((pu
= puffs_init(pops
, argv
[0], "pnullfs", NULL
, pflags
)) == NULL
)
102 pn_root
= puffs_pn_new(pu
, NULL
);
104 err(1, "puffs_pn_new");
105 puffs_setroot(pu
, pn_root
);
106 puffs_setfhsize(pu
, 0, PUFFS_FHFLAG_PASSTHROUGH
);
108 po_root
= puffs_getrootpathobj(pu
);
110 err(1, "getrootpathobj");
111 po_root
->po_path
= argv
[0];
112 po_root
->po_len
= strlen(argv
[0]);
113 puffs_stat2vattr(&pn_root
->pn_va
, &sb
);
116 if (puffs_daemon(pu
, 1, 1) == -1)
117 err(1, "puffs_daemon");
119 if (puffs_mount(pu
, argv
[1], mntflags
, pn_root
) == -1)
120 err(1, "puffs_mount");
121 if (puffs_mainloop(pu
) == -1)