aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-11-04 21:18:07 +0000
committerEric Andersen <andersen@codepoet.org>1999-11-04 21:18:07 +0000
commitd0246fb72b40320a74376af1bb944fef2c9b734f (patch)
tree9fa93d2acf052107f2b682ce2e77725eb7ec9d84 /util-linux
parent3ae0c789627a29dbd76793eb666efe19144b30f0 (diff)
downloadbusybox-w32-d0246fb72b40320a74376af1bb944fef2c9b734f.tar.gz
busybox-w32-d0246fb72b40320a74376af1bb944fef2c9b734f.tar.bz2
busybox-w32-d0246fb72b40320a74376af1bb944fef2c9b734f.zip
More stuff.
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/mount.c71
-rw-r--r--util-linux/umount.c68
2 files changed, 109 insertions, 30 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c
index 1efbdf407..8b5efe14f 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -41,11 +41,17 @@
41#include <ctype.h> 41#include <ctype.h>
42#include <fstab.h> 42#include <fstab.h>
43 43
44extern const char mtab_file[]; /* Defined in utility.c */
45
44static const char mount_usage[] = "Usage:\tmount [flags]\n" 46static const char mount_usage[] = "Usage:\tmount [flags]\n"
45 "\tmount [flags] device directory [-o options,more-options]\n" 47 "\tmount [flags] device directory [-o options,more-options]\n"
46 "\n" 48 "\n"
47 "Flags:\n" 49 "Flags:\n"
48 "\t-a:\tMount all file systems in fstab.\n" 50 "\t-a:\tMount all file systems in fstab.\n"
51#ifdef BB_MTAB
52 "\t-f:\t\"Fake\" mount. Add entry to mount table but don't mount it.\n"
53 "\t-n:\tDon't write a mount table entry.\n"
54#endif
49 "\t-o option:\tOne of many filesystem options, listed below.\n" 55 "\t-o option:\tOne of many filesystem options, listed below.\n"
50 "\t-r:\tMount the filesystem read-only.\n" 56 "\t-r:\tMount the filesystem read-only.\n"
51 "\t-t filesystem-type:\tSpecify the filesystem type.\n" 57 "\t-t filesystem-type:\tSpecify the filesystem type.\n"
@@ -62,6 +68,7 @@ static const char mount_usage[] = "Usage:\tmount [flags]\n"
62 "There are EVEN MORE flags that are specific to each filesystem.\n" 68 "There are EVEN MORE flags that are specific to each filesystem.\n"
63 "You'll have to see the written documentation for those.\n"; 69 "You'll have to see the written documentation for those.\n";
64 70
71
65struct mount_options { 72struct mount_options {
66 const char *name; 73 const char *name;
67 unsigned long and; 74 unsigned long and;
@@ -84,6 +91,29 @@ static const struct mount_options mount_options[] = {
84 {0, 0, 0} 91 {0, 0, 0}
85}; 92};
86 93
94#if ! defined BB_MTAB
95#define do_mount(specialfile, dir, filesystemtype, flags, string_flags, useMtab, fakeIt) \
96 mount(specialfile, dir, filesystemtype, flags, string_flags)
97#else
98static int
99do_mount(char* specialfile, char* dir, char* filesystemtype,
100 long flags, void* string_flags, int useMtab, int fakeIt)
101{
102 int status=0;
103
104 if (fakeIt==FALSE)
105 status=mount(specialfile, dir, filesystemtype, flags, string_flags);
106
107 if ( status == 0 ) {
108 if ( useMtab==TRUE )
109 write_mtab(specialfile, dir, filesystemtype, flags, string_flags);
110 return 0;
111 }
112 else
113 return( status);
114}
115#endif
116
87 117
88/* Seperate standard mount options from the nonstandard string options */ 118/* Seperate standard mount options from the nonstandard string options */
89static void 119static void
@@ -126,9 +156,8 @@ parse_mount_options ( char *options, unsigned long *flags, char *strflags)
126} 156}
127 157
128int 158int
129mount_one ( 159mount_one(char *blockDevice, char *directory, char *filesystemType,
130 char *blockDevice, char *directory, char *filesystemType, 160 unsigned long flags, char *string_flags, int useMtab, int fakeIt)
131 unsigned long flags, char *string_flags)
132{ 161{
133 int status = 0; 162 int status = 0;
134 163
@@ -152,16 +181,16 @@ mount_one (
152 filesystemType = buf; 181 filesystemType = buf;
153 filesystemType++; // hop past tab 182 filesystemType++; // hop past tab
154 183
155 status = mount (blockDevice, directory, filesystemType, 184 status = do_mount (blockDevice, directory, filesystemType,
156 flags | MS_MGC_VAL, string_flags); 185 flags | MS_MGC_VAL, string_flags, useMtab, fakeIt);
157 if (status == 0) 186 if (status == 0)
158 break; 187 break;
159 } 188 }
160 } 189 }
161 fclose (f); 190 fclose (f);
162 } else { 191 } else {
163 status = mount (blockDevice, directory, filesystemType, 192 status = do_mount (blockDevice, directory, filesystemType,
164 flags | MS_MGC_VAL, string_flags); 193 flags | MS_MGC_VAL, string_flags, useMtab, fakeIt);
165 } 194 }
166 195
167 if (status) { 196 if (status) {
@@ -180,15 +209,17 @@ extern int mount_main (int argc, char **argv)
180 char *device = NULL; 209 char *device = NULL;
181 char *directory = NULL; 210 char *directory = NULL;
182 struct stat statBuf; 211 struct stat statBuf;
183 int all = 0; 212 int all = FALSE;
213 int fakeIt = FALSE;
214 int useMtab = TRUE;
184 int i; 215 int i;
185 216
186 if (stat("/etc/fstab", &statBuf) < 0) 217 if (stat("/etc/fstab", &statBuf) < 0)
187 fprintf(stderr, "/etc/fstab file missing -- Please install one.\n\n"); 218 fprintf(stderr, "/etc/fstab file missing -- Please install one.\n\n");
188 219
189 if (argc == 1) { 220 if (argc == 1) {
190 FILE *mountTable; 221 FILE *mountTable = setmntent (mtab_file, "r");
191 if ((mountTable = setmntent ("/proc/mounts", "r"))) { 222 if (mountTable) {
192 struct mntent *m; 223 struct mntent *m;
193 while ((m = getmntent (mountTable)) != 0) { 224 while ((m = getmntent (mountTable)) != 0) {
194 struct fstab* fstabItem; 225 struct fstab* fstabItem;
@@ -203,6 +234,8 @@ extern int mount_main (int argc, char **argv)
203 m->mnt_type, m->mnt_opts); 234 m->mnt_type, m->mnt_opts);
204 } 235 }
205 endmntent (mountTable); 236 endmntent (mountTable);
237 } else {
238 perror(mtab_file);
206 } 239 }
207 exit( TRUE); 240 exit( TRUE);
208 } 241 }
@@ -241,6 +274,14 @@ extern int mount_main (int argc, char **argv)
241 case 'a': 274 case 'a':
242 all = TRUE; 275 all = TRUE;
243 break; 276 break;
277#ifdef BB_MTAB
278 case 'f':
279 fakeIt = TRUE;
280 break;
281 case 'n':
282 useMtab = FALSE;
283 break;
284#endif
244 case 'v': 285 case 'v':
245 case 'h': 286 case 'h':
246 case '-': 287 case '-':
@@ -263,7 +304,6 @@ extern int mount_main (int argc, char **argv)
263 } 304 }
264 305
265 if (all == TRUE) { 306 if (all == TRUE) {
266 long newFlags;
267 struct mntent *m; 307 struct mntent *m;
268 FILE *f = setmntent ("/etc/fstab", "r"); 308 FILE *f = setmntent ("/etc/fstab", "r");
269 309
@@ -279,17 +319,18 @@ extern int mount_main (int argc, char **argv)
279 (!strstr (m->mnt_type, "swap")) && 319 (!strstr (m->mnt_type, "swap")) &&
280 (!strstr (m->mnt_type, "nfs"))) 320 (!strstr (m->mnt_type, "nfs")))
281 { 321 {
282 newFlags = flags; 322 flags = 0;
283 *string_flags = '\0'; 323 *string_flags = '\0';
284 parse_mount_options(m->mnt_opts, &newFlags, string_flags); 324 parse_mount_options(m->mnt_opts, &flags, string_flags);
285 mount_one (m->mnt_fsname, m->mnt_dir, m->mnt_type, newFlags, string_flags); 325 mount_one (m->mnt_fsname, m->mnt_dir, m->mnt_type,
326 flags, string_flags, useMtab, fakeIt);
286 } 327 }
287 } 328 }
288 endmntent (f); 329 endmntent (f);
289 } else { 330 } else {
290 if (device && directory) { 331 if (device && directory) {
291 exit (mount_one (device, directory, filesystemType, 332 exit (mount_one (device, directory, filesystemType,
292 flags, string_flags)); 333 flags, string_flags, useMtab, fakeIt));
293 } else { 334 } else {
294 fprintf (stderr, "%s\n", mount_usage); 335 fprintf (stderr, "%s\n", mount_usage);
295 exit( FALSE); 336 exit( FALSE);
diff --git a/util-linux/umount.c b/util-linux/umount.c
index 95f7dfb3c..e749c5f0f 100644
--- a/util-linux/umount.c
+++ b/util-linux/umount.c
@@ -29,24 +29,54 @@
29#include <errno.h> 29#include <errno.h>
30 30
31static const char umount_usage[] = 31static const char umount_usage[] =
32"Usage: umount filesystem\n" 32"Usage: umount [flags] filesystem|directory\n"
33" or: umount directory\n" 33"Optional Flags:\n"
34" or: umount -a" 34"\t-a:\tUnmount all file systems"
35"to unmount all mounted file systems.\n"; 35#ifdef BB_MTAB
36" in /etc/mtab\n\t-n:\tDon't erase /etc/mtab entries\n"
37#else
38"\n"
39#endif
40;
41
42
43static int useMtab = TRUE;
44static int umountAll = FALSE;
45extern const char mtab_file[]; /* Defined in utility.c */
46
47#if ! defined BB_MTAB
48#define do_umount( blockDevice, useMtab) umount( blockDevice)
49#else
50static int
51do_umount(const char* name, int useMtab)
52{
53 int status = umount(name);
54
55 if ( status == 0 ) {
56 if ( useMtab==TRUE )
57 erase_mtab(name);
58 return 0;
59 }
60 else
61 return( status);
62}
63#endif
36 64
37static int 65static int
38umount_all() 66umount_all(int useMtab)
39{ 67{
40 int status; 68 int status;
41 struct mntent *m; 69 struct mntent *m;
42 FILE *mountTable; 70 FILE *mountTable;
43 71
44 if ((mountTable = setmntent ("/proc/mounts", "r"))) { 72 if ((mountTable = setmntent (mtab_file, "r"))) {
45 while ((m = getmntent (mountTable)) != 0) { 73 while ((m = getmntent (mountTable)) != 0) {
46 char *blockDevice = m->mnt_fsname; 74 char *blockDevice = m->mnt_fsname;
75#if ! defined BB_MTAB
47 if (strcmp (blockDevice, "/dev/root") == 0) 76 if (strcmp (blockDevice, "/dev/root") == 0)
48 blockDevice = (getfsfile ("/"))->fs_spec; 77 blockDevice = (getfsfile ("/"))->fs_spec;
49 status=umount (m->mnt_dir); 78#endif
79 status=do_umount (m->mnt_dir, useMtab);
50 if (status!=0) { 80 if (status!=0) {
51 /* Don't bother retrying the umount on busy devices */ 81 /* Don't bother retrying the umount on busy devices */
52 if (errno==EBUSY) { 82 if (errno==EBUSY) {
@@ -56,7 +86,7 @@ umount_all()
56 printf ("Trying to umount %s failed: %s\n", 86 printf ("Trying to umount %s failed: %s\n",
57 m->mnt_dir, strerror(errno)); 87 m->mnt_dir, strerror(errno));
58 printf ("Instead trying to umount %s\n", blockDevice); 88 printf ("Instead trying to umount %s\n", blockDevice);
59 status=umount (blockDevice); 89 status=do_umount (blockDevice, useMtab);
60 if (status!=0) { 90 if (status!=0) {
61 printf ("Couldn't umount %s on %s (type %s): %s\n", 91 printf ("Couldn't umount %s on %s (type %s): %s\n",
62 blockDevice, m->mnt_dir, m->mnt_type, strerror(errno)); 92 blockDevice, m->mnt_dir, m->mnt_type, strerror(errno));
@@ -69,27 +99,35 @@ umount_all()
69} 99}
70 100
71extern int 101extern int
72umount_main(int argc, char * * argv) 102umount_main(int argc, char** argv)
73{ 103{
74 104
75 if (argc < 2) { 105 if (argc < 2) {
76 usage( umount_usage); 106 usage( umount_usage);
77 } 107 }
78 argc--;
79 argv++;
80 108
81 /* Parse any options */ 109 /* Parse any options */
82 while (**argv == '-') { 110 while (argc-- > 0 && **(++argv) == '-') {
83 while (*++(*argv)) switch (**argv) { 111 while (*++(*argv)) switch (**argv) {
84 case 'a': 112 case 'a':
85 exit ( umount_all() ); 113 umountAll = TRUE;
114 break;
115#ifdef BB_MTAB
116 case 'n':
117 useMtab = FALSE;
86 break; 118 break;
119#endif
87 default: 120 default:
88 usage( umount_usage); 121 usage( umount_usage);
89 } 122 }
90 } 123 }
91 if ( umount(*argv) == 0 ) 124
92 exit (TRUE); 125
126 if(umountAll) {
127 exit(umount_all(useMtab));
128 }
129 if ( do_umount(*argv,useMtab) == 0 )
130 exit (TRUE);
93 else { 131 else {
94 perror("umount"); 132 perror("umount");
95 exit( FALSE); 133 exit( FALSE);