aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-09-01 08:10:44 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-09-01 08:10:44 +0000
commita9565218a19f516394a987a3703906479a73e6cd (patch)
tree9c7d83525721350196428990adeac18bdf7fe9e4
parentaeaec5602941ec466d0ffa7df15bf566117bd0c2 (diff)
downloadbusybox-w32-a9565218a19f516394a987a3703906479a73e6cd.tar.gz
busybox-w32-a9565218a19f516394a987a3703906479a73e6cd.tar.bz2
busybox-w32-a9565218a19f516394a987a3703906479a73e6cd.zip
Vladimir Dronnikov also submitted a CIFS support patch to mount, which I
heavily reworked here and probably broke. Tomorrow I need to set up a copy of samba to test against. (This compiles, I make no promises beyond that.) git-svn-id: svn://busybox.net/trunk/busybox@16023 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--util-linux/Config.in6
-rw-r--r--util-linux/mount.c57
2 files changed, 55 insertions, 8 deletions
diff --git a/util-linux/Config.in b/util-linux/Config.in
index 2222e5c38..aacf55775 100644
--- a/util-linux/Config.in
+++ b/util-linux/Config.in
@@ -372,6 +372,12 @@ config CONFIG_FEATURE_MOUNT_NFS
372 help 372 help
373 Enable mounting of NFS file systems. 373 Enable mounting of NFS file systems.
374 374
375config CONFIG_FEATURE_MOUNT_CIFS
376 bool "Support mounting CIFS/SMB file systems"
377 default n
378 depends on CONFIG_MOUNT
379 help
380 Enable support for samba mounts.
375config CONFIG_FEATURE_MOUNT_FLAGS 381config CONFIG_FEATURE_MOUNT_FLAGS
376 depends on CONFIG_MOUNT 382 depends on CONFIG_MOUNT
377 bool "Support lots of -o flags in mount." 383 bool "Support lots of -o flags in mount."
diff --git a/util-linux/mount.c b/util-linux/mount.c
index 93a94bc77..fef5f3f28 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -253,8 +253,7 @@ static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts)
253 return rc; 253 return rc;
254} 254}
255 255
256 256// Mount one directory. Handles CIFS, NFS, loopback, autobind, and filesystem type
257// Mount one directory. Handles NFS, loopback, autobind, and filesystem type
258// detection. Returns 0 for success, nonzero for failure. 257// detection. Returns 0 for success, nonzero for failure.
259 258
260static int singlemount(struct mntent *mp, int ignore_busy) 259static int singlemount(struct mntent *mp, int ignore_busy)
@@ -270,6 +269,50 @@ static int singlemount(struct mntent *mp, int ignore_busy)
270 269
271 if (mp->mnt_type && !strcmp(mp->mnt_type,"auto")) mp->mnt_type = 0; 270 if (mp->mnt_type && !strcmp(mp->mnt_type,"auto")) mp->mnt_type = 0;
272 271
272 // Might this be an CIFS filesystem?
273
274 if(ENABLE_FEATURE_MOUNT_CIFS &&
275 (!mp->mnt_type || !strcmp(mp->mnt_type,"cifs")) &&
276 (mp->mnt_fsname[0]==mp->mnt_fsname[1] && (mp->mnt_fsname[0]=='/' || mp->mnt_fsname[0]=='\\')))
277 {
278 struct hostent *he;
279 char ip[32], *s;
280
281 rc = 1;
282 // Replace '/' with '\' and verify that unc points to "//server/share".
283
284 for (s = mp->mnt_fsname; *s; ++s)
285 if (*s == '/') *s = '\\';
286
287 // get server IP
288
289 s = strrchr(mp->mnt_fsname, '\\');
290 if (s == mp->mnt_fsname+1) goto report_error;
291 *s = 0;
292 he = gethostbyname(mp->mnt_fsname+2);
293 *s = '\\';
294 if (!he) goto report_error;
295
296 // Insert ip=... option into string flags. (NOTE: Add IPv6 support.)
297
298 sprintf(ip, "ip=%d.%d.%d.%d", he->h_addr[0], he->h_addr[1],
299 he->h_addr[2], he->h_addr[3]);
300 parse_mount_options(ip, &filteropts);
301
302 // compose new unc '\\server-ip\share'
303
304 s = xasprintf("\\\\%s\\%s",ip+3,strchr(mp->mnt_fsname+2,'\\'));
305 if (ENABLE_FEATURE_CLEAN_UP) free(mp->mnt_fsname);
306 mp->mnt_fsname = s;
307
308 // lock is required
309 vfsflags |= MS_MANDLOCK;
310
311 mp->mnt_type = "cifs";
312 rc = mount_it_now(mp, vfsflags, filteropts);
313 goto report_error;
314 }
315
273 // Might this be an NFS filesystem? 316 // Might this be an NFS filesystem?
274 317
275 if (ENABLE_FEATURE_MOUNT_NFS && 318 if (ENABLE_FEATURE_MOUNT_NFS &&
@@ -278,15 +321,12 @@ static int singlemount(struct mntent *mp, int ignore_busy)
278 { 321 {
279 if (nfsmount(mp->mnt_fsname, mp->mnt_dir, &vfsflags, &filteropts, 1)) { 322 if (nfsmount(mp->mnt_fsname, mp->mnt_dir, &vfsflags, &filteropts, 1)) {
280 bb_perror_msg("nfsmount failed"); 323 bb_perror_msg("nfsmount failed");
281 goto report_error;
282 } else { 324 } else {
283 // Strangely enough, nfsmount() doesn't actually mount() anything. 325 // Strangely enough, nfsmount() doesn't actually mount() anything.
284 mp->mnt_type = "nfs"; 326 mp->mnt_type = "nfs";
285 rc = mount_it_now(mp, vfsflags, filteropts); 327 rc = mount_it_now(mp, vfsflags, filteropts);
286 if (ENABLE_FEATURE_CLEAN_UP) free(filteropts);
287
288 goto report_error;
289 } 328 }
329 goto report_error;
290 } 330 }
291 331
292 // Look at the file. (Not found isn't a failure for remount, or for 332 // Look at the file. (Not found isn't a failure for remount, or for
@@ -344,8 +384,6 @@ static int singlemount(struct mntent *mp, int ignore_busy)
344 } 384 }
345 } 385 }
346 386
347 if (ENABLE_FEATURE_CLEAN_UP) free(filteropts);
348
349 // If mount failed, clean up loop file (if any). 387 // If mount failed, clean up loop file (if any).
350 388
351 if (ENABLE_FEATURE_MOUNT_LOOP && rc && loopFile) { 389 if (ENABLE_FEATURE_MOUNT_LOOP && rc && loopFile) {
@@ -355,7 +393,10 @@ static int singlemount(struct mntent *mp, int ignore_busy)
355 free(mp->mnt_fsname); 393 free(mp->mnt_fsname);
356 } 394 }
357 } 395 }
396
358report_error: 397report_error:
398 if (ENABLE_FEATURE_CLEAN_UP) free(filteropts);
399
359 if (rc && errno == EBUSY && ignore_busy) rc = 0; 400 if (rc && errno == EBUSY && ignore_busy) rc = 0;
360 if (rc < 0) 401 if (rc < 0)
361 bb_perror_msg("Mounting %s on %s failed", mp->mnt_fsname, mp->mnt_dir); 402 bb_perror_msg("Mounting %s on %s failed", mp->mnt_fsname, mp->mnt_dir);