GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: sbin/mount_cd9660/mount_cd9660.c Lines: 0 42 0.0 %
Date: 2017-11-13 Branches: 0 19 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: mount_cd9660.c,v 1.21 2015/01/16 06:39:59 deraadt Exp $	*/
2
/*	$NetBSD: mount_cd9660.c,v 1.3 1996/04/13 01:31:08 jtc Exp $	*/
3
4
/*
5
 * Copyright (c) 1992, 1993, 1994
6
 *      The Regents of the University of California.  All rights reserved.
7
 *
8
 * This code is derived from software contributed to Berkeley
9
 * by Pace Willisson (pace@blitz.com).  The Rock Ridge Extension
10
 * Support code is derived from software contributed to Berkeley
11
 * by Atsushi Murai (amurai@spec.co.jp).
12
 *
13
 * Redistribution and use in source and binary forms, with or without
14
 * modification, are permitted provided that the following conditions
15
 * are met:
16
 * 1. Redistributions of source code must retain the above copyright
17
 *    notice, this list of conditions and the following disclaimer.
18
 * 2. Redistributions in binary form must reproduce the above copyright
19
 *    notice, this list of conditions and the following disclaimer in the
20
 *    documentation and/or other materials provided with the distribution.
21
 * 3. Neither the name of the University nor the names of its contributors
22
 *    may be used to endorse or promote products derived from this software
23
 *    without specific prior written permission.
24
 *
25
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35
 * SUCH DAMAGE.
36
 */
37
38
#include <sys/types.h>
39
#define CD9660
40
#include <sys/mount.h>
41
42
#include <err.h>
43
#include <errno.h>
44
#include <stdint.h>
45
#include <stdlib.h>
46
#include <stdio.h>
47
#include <string.h>
48
#include <unistd.h>
49
#include <limits.h>
50
51
#include "mntopts.h"
52
53
const struct mntopt mopts[] = {
54
	MOPT_STDOPTS,
55
	MOPT_UPDATE,
56
	{ NULL }
57
};
58
59
void	usage(void);
60
61
int
62
main(int argc, char *argv[])
63
{
64
	struct iso_args args;
65
	int ch, mntflags, opts, sess = 0;
66
	char *dev, dir[PATH_MAX];
67
	const char *errstr;
68
69
	mntflags = opts = 0;
70
	while ((ch = getopt(argc, argv, "egjo:Rs:")) != -1)
71
		switch (ch) {
72
		case 'e':
73
			opts |= ISOFSMNT_EXTATT;
74
			break;
75
		case 'g':
76
			opts |= ISOFSMNT_GENS;
77
			break;
78
		case 'j':
79
			opts |= ISOFSMNT_NOJOLIET;
80
			break;
81
		case 'o':
82
			getmntopts(optarg, mopts, &mntflags);
83
			break;
84
		case 'R':
85
			opts |= ISOFSMNT_NORRIP;
86
			break;
87
		case 's':
88
			opts |= ISOFSMNT_SESS;
89
			sess = strtonum(optarg, 0, INT32_MAX, &errstr);
90
			if (errstr)
91
				errx(1, "session number is %s: %s", errstr,
92
				    optarg);
93
			break;
94
		case '?':
95
		default:
96
			usage();
97
		}
98
	argc -= optind;
99
	argv += optind;
100
101
	if (argc != 2)
102
		usage();
103
104
	dev = argv[0];
105
	if (realpath(argv[1], dir) == NULL)
106
		err(1, "realpath %s", argv[1]);
107
108
#define DEFAULT_ROOTUID	-2
109
	args.fspec = dev;
110
	args.export_info.ex_root = DEFAULT_ROOTUID;
111
112
	mntflags |= MNT_RDONLY;
113
	if (mntflags & MNT_RDONLY)
114
		args.export_info.ex_flags = MNT_EXRDONLY;
115
	else
116
		args.export_info.ex_flags = 0;
117
	args.flags = opts;
118
	args.sess = sess;
119
120
	if (mount(MOUNT_CD9660, dir, mntflags, &args) < 0) {
121
		if (errno == EOPNOTSUPP)
122
			errx(1, "%s: Filesystem not supported by kernel", dir);
123
		else
124
			err(1, "%s on %s", args.fspec, dir);
125
	}
126
	exit(0);
127
}
128
129
void
130
usage(void)
131
{
132
	(void)fprintf(stderr,
133
		"usage: mount_cd9660 [-egjR] [-o options] [-s offset] "
134
		"special node\n");
135
	exit(1);
136
}