diff options
| author | Rob Landley <rob@landley.net> | 2006-09-01 08:10:44 +0000 |
|---|---|---|
| committer | Rob Landley <rob@landley.net> | 2006-09-01 08:10:44 +0000 |
| commit | 89d9d4d5f74a86a005a7ea4de51252ac7e52d062 (patch) | |
| tree | 9c7d83525721350196428990adeac18bdf7fe9e4 /util-linux/mount.c | |
| parent | f5bbc692a0329ee34f1644ac42efa5e3a8c48296 (diff) | |
| download | busybox-w32-89d9d4d5f74a86a005a7ea4de51252ac7e52d062.tar.gz busybox-w32-89d9d4d5f74a86a005a7ea4de51252ac7e52d062.tar.bz2 busybox-w32-89d9d4d5f74a86a005a7ea4de51252ac7e52d062.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.)
Diffstat (limited to 'util-linux/mount.c')
| -rw-r--r-- | util-linux/mount.c | 57 |
1 files changed, 49 insertions, 8 deletions
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 | ||
| 260 | static int singlemount(struct mntent *mp, int ignore_busy) | 259 | static 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 | |||
| 358 | report_error: | 397 | report_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); |
