GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: sbin/mount_udf/mount_udf.c Lines: 0 32 0.0 %
Date: 2017-11-07 Branches: 0 12 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: mount_udf.c,v 1.7 2015/01/16 06:39:59 deraadt Exp $	*/
2
3
/*
4
 * Copyright (c) 2005 Pedro Martelletto <pedro@ambientworks.net>
5
 * All rights reserved.
6
 *
7
 * Permission to use, copy, modify, and distribute this software for any
8
 * purpose with or without fee is hereby granted, provided that the above
9
 * copyright notice and this permission notice appear in all copies.
10
 *
11
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
 */
19
20
#include <sys/types.h>
21
#include <sys/mount.h>
22
#include <sys/ioctl.h>
23
#include <sys/cdio.h>
24
25
#include <err.h>
26
#include <fcntl.h>
27
#include <unistd.h>
28
#include <limits.h>
29
#include <stdlib.h>
30
#include <stdio.h>
31
32
#include "mntopts.h"
33
34
const struct mntopt opts[] = { MOPT_STDOPTS, { NULL } };
35
36
u_int32_t lastblock(char *dev);
37
__dead void usage(void);
38
39
40
__dead void
41
usage(void)
42
{
43
	extern char *__progname;
44
45
	fprintf(stderr, "usage: %s [-o options] special node\n", __progname);
46
47
	exit(EXIT_FAILURE);
48
}
49
50
/* Find out media's last block by looking at the LBA of the lead-out track. */
51
u_int32_t
52
lastblock(char *dev)
53
{
54
	int fd, error;
55
	struct ioc_read_toc_entry t;
56
	struct cd_toc_entry te;
57
58
	fd = open(dev, O_RDONLY, 0);
59
	if (fd < 0)
60
		err(1, "open");
61
62
	t.address_format = CD_LBA_FORMAT;
63
	t.starting_track = CD_TRACK_LEADOUT;
64
	t.data_len = sizeof(struct cd_toc_entry);
65
	t.data = &te;
66
67
	error = ioctl(fd, CDIOREADTOCENTRIES, &t);
68
69
	close(fd);
70
71
	return (error == -1 ? 0 : te.addr.lba);
72
}
73
74
int
75
main(int argc, char **argv)
76
{
77
	struct udf_args args;
78
	char node[PATH_MAX];
79
	int ch, flags = 0;
80
81
	while ((ch = getopt(argc, argv, "o:")) != -1)
82
		switch (ch) {
83
		case 'o':
84
			getmntopts(optarg, opts, &flags);
85
			break;
86
		default:
87
			usage();
88
		}
89
90
	argc -= optind;
91
	argv += optind;
92
93
	if (argc != 2)
94
		usage();
95
96
	args.fspec = argv[0];
97
	args.lastblock = lastblock(argv[0]);
98
99
	if (realpath(argv[1], node) == NULL)
100
		err(1, "realpath %s", argv[1]);
101
102
	if (mount(MOUNT_UDF, node, flags, &args) < 0)
103
		err(1, "mount");
104
105
	exit(0);
106
}