[BACK]Return to mount_udf.c CVS log [TXT][DIR] Up to [local] / src / sbin / mount_udf

File: [local] / src / sbin / mount_udf / mount_udf.c (download)

Revision 1.9, Sun Oct 24 21:24:22 2021 UTC (2 years, 7 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_7_5_BASE, OPENBSD_7_5, OPENBSD_7_4_BASE, OPENBSD_7_4, OPENBSD_7_3_BASE, OPENBSD_7_3, OPENBSD_7_2_BASE, OPENBSD_7_2, OPENBSD_7_1_BASE, OPENBSD_7_1, HEAD
Changes since 1.8: +2 -2 lines

For open/openat, if the flags parameter does not contain O_CREAT, the
3rd (variadic) mode_t parameter is irrelevant.  Many developers in the past
have passed mode_t (0, 044, 0644, or such), which might lead future people
to copy this broken idiom, and perhaps even believe this parameter has some
meaning or implication or application. Delete them all.
This comes out of a conversation where tb@ noticed that a strange (but
intentional) pledge behaviour is to always knock-out high-bits from
mode_t on a number of system calls as a safety factor, and his bewilderment
that this appeared to be happening against valid modes (at least visually),
but no sorry, they are all irrelevant junk.  They could all be 0xdeafbeef.
ok millert

/*	$OpenBSD: mount_udf.c,v 1.9 2021/10/24 21:24:22 deraadt Exp $	*/

/*
 * Copyright (c) 2005 Pedro Martelletto <pedro@ambientworks.net>
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/types.h>
#include <sys/mount.h>
#include <sys/ioctl.h>
#include <sys/cdio.h>

#include <err.h>
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>

#include "mntopts.h"

const struct mntopt opts[] = { MOPT_STDOPTS, { NULL } };

u_int32_t lastblock(char *dev);
__dead void usage(void);


__dead void
usage(void)
{
	extern char *__progname;

	fprintf(stderr, "usage: %s [-o options] special node\n", __progname);

	exit(EXIT_FAILURE);
}

/* Find out media's last block by looking at the LBA of the lead-out track. */
u_int32_t
lastblock(char *dev)
{
	int fd, error;
	struct ioc_read_toc_entry t;
	struct cd_toc_entry te;

	fd = open(dev, O_RDONLY);
	if (fd == -1)
		err(1, "open");

	t.address_format = CD_LBA_FORMAT;
	t.starting_track = CD_TRACK_LEADOUT;
	t.data_len = sizeof(struct cd_toc_entry);
	t.data = &te;

	error = ioctl(fd, CDIOREADTOCENTRIES, &t);

	close(fd);

	return (error == -1 ? 0 : te.addr.lba);
}

int
main(int argc, char **argv)
{
	struct udf_args args;
	char node[PATH_MAX];
	int ch, flags = 0;

	while ((ch = getopt(argc, argv, "o:")) != -1)
		switch (ch) {
		case 'o':
			getmntopts(optarg, opts, &flags);
			break;
		default:
			usage();
		}

	argc -= optind;
	argv += optind;

	if (argc != 2)
		usage();

	args.fspec = argv[0];
	args.lastblock = lastblock(argv[0]);

	if (realpath(argv[1], node) == NULL)
		err(1, "realpath %s", argv[1]);

	if (mount(MOUNT_UDF, node, flags, &args) == -1)
		err(1, "mount");

	exit(0);
}