implement ping using new network stack
[barebox-mini2440.git] / commands / mount.c
blob8e4388ecd873b56d76b8cf375ed76638577ffc93
1 /*
2 * mount.c - mount devices
4 * Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
6 * See file CREDITS for list of people who contributed to this
7 * project.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 /**
24 * @file
25 * @brief Filesystem mounting support
28 #include <common.h>
29 #include <command.h>
30 #include <fs.h>
31 #include <errno.h>
33 static int do_mount(struct command *cmdtp, int argc, char *argv[])
35 int ret = 0;
36 struct mtab_entry *entry = NULL;
38 if (argc == 1) {
39 do {
40 entry = mtab_next_entry(entry);
41 if (entry) {
42 printf("%s on %s type %s\n",
43 entry->parent_device ? entry->parent_device->name : "none",
44 entry->path,
45 entry->dev->name);
47 } while (entry);
48 return 0;
51 if (argc != 4)
52 return COMMAND_ERROR_USAGE;
54 if ((ret = mount(argv[1], argv[2], argv[3]))) {
55 perror("mount");
56 return 1;
58 return 0;
61 static const __maybe_unused char cmd_mount_help[] =
62 "Usage: mount: list mounted filesystems\n"
63 "or: mount <device> <fstype> <mountpoint>\n"
64 "\n"
65 "Mount a filesystem of a given type to a mountpoint.\n"
66 "<device> can be one of /dev/* or some arbitrary string if no\n"
67 "device is needed for this driver (for example ramfs).\n"
68 "<fstype> is the filesystem driver to use. Try the 'devinfo' command\n"
69 "for a list of available drivers.\n"
70 "<mountpoint> must be an empty directory descending directly from the\n"
71 "root directory.\n";
73 BAREBOX_CMD_START(mount)
74 .cmd = do_mount,
75 .usage = "mount a filesystem to a device",
76 BAREBOX_CMD_HELP(cmd_mount_help)
77 BAREBOX_CMD_END
79 /** @page mount_command mount
80 * Usage: mount [\<device> \<fstype> \<mountpoint>]
82 * Mounts a filesystem of a given \<fstype> on a \<device> to a \<mountpoint>.
83 * \<device> can be one of /dev/ * or some arbitrary string if no
84 * device is needed for this driver (for example ramfs).
86 * \<fstype> is the filesystem driver to use. Try the 'devinfo' command
87 * for a list of available drivers.
89 * \<mountpoint> must be an empty directory descending directly from the
90 * root directory.
93 /** @page how_mount_works How mount works in barebox
95 * Mounting a filesystem ontop of a device is working like devices and drivers
96 * are finding together.
98 * The mount command creates a new device with the filesystem name as the
99 * driver for this "device". So the framework is able to merge both parts
100 * together.
102 * By the way: With this feature its impossible to accidentely remove
103 * partitions in use. A partition is internally also a device. If its mounted
104 * it will be marked as busy, so an delpart command fails, until the filesystem
105 * has been unmounted.