117049c45SAxel Dörfler /* 2*da6d1a70SAxel Dörfler * Copyright 2001-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3*da6d1a70SAxel Dörfler * Distributed under the terms of the MIT License. 417049c45SAxel Dörfler */ 517049c45SAxel Dörfler 617049c45SAxel Dörfler /** Mounts a volume with the specified file system */ 717049c45SAxel Dörfler 817049c45SAxel Dörfler 917049c45SAxel Dörfler #include <fs_volume.h> 1017049c45SAxel Dörfler 1117049c45SAxel Dörfler #include <sys/stat.h> 1217049c45SAxel Dörfler #include <unistd.h> 1317049c45SAxel Dörfler #include <stdio.h> 1417049c45SAxel Dörfler #include <string.h> 1517049c45SAxel Dörfler 1617049c45SAxel Dörfler 1717049c45SAxel Dörfler static void 1817049c45SAxel Dörfler usage(const char *programName) 1917049c45SAxel Dörfler { 2017049c45SAxel Dörfler 2117049c45SAxel Dörfler printf("usage: %s [-ro] [-t fstype] device directory\n" 2217049c45SAxel Dörfler "\t-ro\tmounts the volume read-only\n" 2317049c45SAxel Dörfler "\t-t\tspecifies the file system to use (defaults to automatic recognition)\n",programName); 2417049c45SAxel Dörfler exit(0); 2517049c45SAxel Dörfler } 2617049c45SAxel Dörfler 2717049c45SAxel Dörfler 2817049c45SAxel Dörfler int 2917049c45SAxel Dörfler main(int argc, char **argv) 3017049c45SAxel Dörfler { 3117049c45SAxel Dörfler const char *programName = argv[0]; 3217049c45SAxel Dörfler const char *device, *mountPoint; 3317049c45SAxel Dörfler const char *parameter = NULL; 3417049c45SAxel Dörfler const char *fs = NULL; 3517049c45SAxel Dörfler struct stat mountStat; 36*da6d1a70SAxel Dörfler dev_t device; 3717049c45SAxel Dörfler uint32 flags = 0; 3817049c45SAxel Dörfler 3917049c45SAxel Dörfler /* prettify the program name */ 4017049c45SAxel Dörfler 4117049c45SAxel Dörfler if (strrchr(programName, '/')) 4217049c45SAxel Dörfler programName = strrchr(programName, '/') + 1; 4317049c45SAxel Dörfler 4417049c45SAxel Dörfler /* get all options */ 4517049c45SAxel Dörfler 4617049c45SAxel Dörfler while (*++argv) { 4717049c45SAxel Dörfler char *arg = *argv; 4817049c45SAxel Dörfler if (*arg != '-') 4917049c45SAxel Dörfler break; 5017049c45SAxel Dörfler 5117049c45SAxel Dörfler if (!strcmp(++arg, "ro") && (flags & B_MOUNT_READ_ONLY) == 0) 5217049c45SAxel Dörfler flags |= B_MOUNT_READ_ONLY; 5317049c45SAxel Dörfler else if (!strcmp(arg, "t") && fs == NULL) 5417049c45SAxel Dörfler fs = *++argv; 5517049c45SAxel Dörfler else if (!strcmp(arg, "p") && parameter == NULL) 5617049c45SAxel Dörfler parameter = *++argv; 5717049c45SAxel Dörfler else 5817049c45SAxel Dörfler usage(programName); 5917049c45SAxel Dörfler } 6017049c45SAxel Dörfler 6117049c45SAxel Dörfler /* check the arguments */ 6217049c45SAxel Dörfler 6317049c45SAxel Dörfler device = argv[0]; 6417049c45SAxel Dörfler mountPoint = argv[1]; 6517049c45SAxel Dörfler 6617049c45SAxel Dörfler if (device == NULL || mountPoint == NULL) 6717049c45SAxel Dörfler usage(programName); 6817049c45SAxel Dörfler 6917049c45SAxel Dörfler if (stat(mountPoint, &mountStat) < 0) { 7017049c45SAxel Dörfler fprintf(stderr, "%s: The mount point '%s' is not accessible\n", programName, mountPoint); 7117049c45SAxel Dörfler return -1; 7217049c45SAxel Dörfler } 7317049c45SAxel Dörfler if (!S_ISDIR(mountStat.st_mode)) { 7417049c45SAxel Dörfler fprintf(stderr, "%s: The mount point '%s' is not a directory\n", programName, mountPoint); 7517049c45SAxel Dörfler return -1; 7617049c45SAxel Dörfler } 7717049c45SAxel Dörfler 7817049c45SAxel Dörfler /* do the work */ 7917049c45SAxel Dörfler 80*da6d1a70SAxel Dörfler device = fs_mount_volume(mountPoint, device, fs, flags, parameter); 81*da6d1a70SAxel Dörfler if (device < B_OK) { 82*da6d1a70SAxel Dörfler fprintf(stderr, "%s: %s\n", programName, strerror(device)); 8317049c45SAxel Dörfler return -1; 8417049c45SAxel Dörfler } 8517049c45SAxel Dörfler return 0; 8617049c45SAxel Dörfler } 8717049c45SAxel Dörfler 88