source: mainline/uspace/app/bdsh/cmds/modules/mount/mount.c@ 6e5562a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6e5562a was 8ffedd8, checked in by Jakub Jermar <jakub@…>, 8 years ago

Partially revive support for mount table listing and walking

This implementation is purely client-based. Using a simple file system
traversal, the library figures out what are the actual mountpoints. It
only discovers mountpoints that it can reach from its VFS root.

The benefit is that this works and produces reasonable results even in
the environment of per-client VFS roots, whereas a global mount table
would present paths that might not make any sense to the client
(notwithstanding the fact that VFS no longer knows the mountpoint
paths).

Listing of file system names is still broken as of this commit.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * Copyright (c) 2009 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <loc.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <str_error.h>
33#include <vfs/vfs.h>
34#include <vfs/vfs_mtab.h>
35#include <adt/list.h>
36#include <errno.h>
37#include <getopt.h>
38#include <inttypes.h>
39#include "config.h"
40#include "util.h"
41#include "errors.h"
42#include "entry.h"
43#include "mount.h"
44#include "cmds.h"
45
46static const char *cmdname = "mount";
47
48static struct option const long_options[] = {
49 { "help", no_argument, 0, 'h' },
50 { "instance", required_argument, 0, 'i' },
51 { 0, 0, 0, 0 }
52};
53
54
55/* Displays help for mount in various levels */
56void help_cmd_mount(unsigned int level)
57{
58 static char helpfmt[] =
59 "Usage: %s <fstype> <mp> [dev] [<moptions>]\n";
60 if (level == HELP_SHORT) {
61 printf("'%s' mounts a file system.\n", cmdname);
62 } else {
63 help_cmd_mount(HELP_SHORT);
64 printf(helpfmt, cmdname);
65 }
66 return;
67}
68
69static void print_mtab_list(void)
70{
71 LIST_INITIALIZE(mtab_list);
72 mtab_ent_t *old_ent = NULL;
73 char *svc_name;
74 int rc;
75
76 vfs_get_mtab_list(&mtab_list);
77
78 list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) {
79 if (old_ent)
80 free(old_ent);
81
82 old_ent = mtab_ent;
83
84 printf("%s", mtab_ent->fs_name);
85
86 printf(" %s", mtab_ent->mp);
87
88 rc = loc_service_get_name(mtab_ent->service_id, &svc_name);
89 if (rc == EOK) {
90 printf(" %s", svc_name);
91 free(svc_name);
92 } else {
93 printf(" (%" PRIun ")", mtab_ent->service_id);
94 }
95
96 putchar('\n');
97 }
98
99 if (old_ent)
100 free(old_ent);
101}
102
103/* Main entry point for mount, accepts an array of arguments */
104int cmd_mount(char **argv)
105{
106 unsigned int argc;
107 const char *mopts = "";
108 const char *dev = "";
109 int rc, c, opt_ind;
110 unsigned int instance = 0;
111 bool instance_set = false;
112 char **t_argv;
113
114 argc = cli_count_args(argv);
115
116 for (c = 0, optreset = 1, optind = 0, opt_ind = 0; c != -1;) {
117 c = getopt_long(argc, argv, "i:h", long_options, &opt_ind);
118 switch (c) {
119 case 'h':
120 help_cmd_mount(HELP_LONG);
121 return CMD_SUCCESS;
122 case 'i':
123 instance = (unsigned int) strtol(optarg, NULL, 10);
124 instance_set = true;
125 break;
126 }
127 }
128
129 if (instance_set) {
130 argc -= 2;
131 t_argv = &argv[2];
132 } else
133 t_argv = &argv[0];
134
135 if ((argc == 2) || (argc > 5)) {
136 printf("%s: invalid number of arguments. Try `mount --help'\n",
137 cmdname);
138 return CMD_FAILURE;
139 }
140 if (argc == 1) {
141 print_mtab_list();
142 return CMD_SUCCESS;
143 }
144 if (argc > 3)
145 dev = t_argv[3];
146 if (argc == 5)
147 mopts = t_argv[4];
148
149 rc = mount(t_argv[1], t_argv[2], dev, mopts, 0, instance);
150 if (rc != EOK) {
151 printf("Unable to mount %s filesystem to %s on %s (rc=%s)\n",
152 t_argv[1], t_argv[2], t_argv[3], str_error(rc));
153 return CMD_FAILURE;
154 }
155
156 return CMD_SUCCESS;
157}
158
Note: See TracBrowser for help on using the repository browser.