1 /* $OpenBSD: mount_udf.c,v 1.6 2013/11/12 04:59:02 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/param.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 <stdlib.h> 29 #include <stdio.h> 30 31 #include "mntopts.h" 32 33 const struct mntopt opts[] = { MOPT_STDOPTS, { NULL } }; 34 35 u_int32_t lastblock(char *dev); 36 __dead void usage(void); 37 38 39 __dead void 40 usage(void) 41 { 42 extern char *__progname; 43 44 fprintf(stderr, "usage: %s [-o options] special node\n", __progname); 45 46 exit(EXIT_FAILURE); 47 } 48 49 /* Find out media's last block by looking at the LBA of the lead-out track. */ 50 u_int32_t 51 lastblock(char *dev) 52 { 53 int fd, error; 54 struct ioc_read_toc_entry t; 55 struct cd_toc_entry te; 56 57 fd = open(dev, O_RDONLY, 0); 58 if (fd < 0) 59 err(1, "open"); 60 61 t.address_format = CD_LBA_FORMAT; 62 t.starting_track = CD_TRACK_LEADOUT; 63 t.data_len = sizeof(struct cd_toc_entry); 64 t.data = &te; 65 66 error = ioctl(fd, CDIOREADTOCENTRIES, &t); 67 68 close(fd); 69 70 return (error == -1 ? 0 : te.addr.lba); 71 } 72 73 int 74 main(int argc, char **argv) 75 { 76 struct udf_args args; 77 char node[MAXPATHLEN]; 78 int ch, flags = 0; 79 80 while ((ch = getopt(argc, argv, "o:")) != -1) 81 switch (ch) { 82 case 'o': 83 getmntopts(optarg, opts, &flags); 84 break; 85 default: 86 usage(); 87 } 88 89 argc -= optind; 90 argv += optind; 91 92 if (argc != 2) 93 usage(); 94 95 args.fspec = argv[0]; 96 args.lastblock = lastblock(argv[0]); 97 98 if (realpath(argv[1], node) == NULL) 99 err(1, "realpath %s", argv[1]); 100 101 if (mount(MOUNT_UDF, node, flags, &args) < 0) 102 err(1, "mount"); 103 104 exit(0); 105 } 106