| 1 | /*
|
|---|
| 2 | Unmount utility program for Linux CIFS VFS (virtual filesystem) client
|
|---|
| 3 | Copyright (C) 2005 Steve French (sfrench@us.ibm.com)
|
|---|
| 4 |
|
|---|
| 5 | This program is free software; you can redistribute it and/or modify
|
|---|
| 6 | it under the terms of the GNU General Public License as published by
|
|---|
| 7 | the Free Software Foundation; either version 3 of the License, or
|
|---|
| 8 | (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This program is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | GNU General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License
|
|---|
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|---|
| 17 |
|
|---|
| 18 | #ifndef _GNU_SOURCE
|
|---|
| 19 | #define _GNU_SOURCE
|
|---|
| 20 | #endif
|
|---|
| 21 |
|
|---|
| 22 | #include <stdlib.h>
|
|---|
| 23 | #include <stdio.h>
|
|---|
| 24 | #include <unistd.h>
|
|---|
| 25 | #include <ctype.h>
|
|---|
| 26 | #include <sys/types.h>
|
|---|
| 27 | #include <sys/mount.h>
|
|---|
| 28 | #include <sys/ioctl.h>
|
|---|
| 29 | #include <sys/stat.h>
|
|---|
| 30 | #include <sys/vfs.h>
|
|---|
| 31 | #include <fcntl.h>
|
|---|
| 32 | #include <getopt.h>
|
|---|
| 33 | #include <errno.h>
|
|---|
| 34 | #include <string.h>
|
|---|
| 35 | #include <mntent.h>
|
|---|
| 36 | #include <limits.h>
|
|---|
| 37 | #include "mount.h"
|
|---|
| 38 |
|
|---|
| 39 | #define UNMOUNT_CIFS_VERSION_MAJOR "0"
|
|---|
| 40 | #define UNMOUNT_CIFS_VERSION_MINOR "6"
|
|---|
| 41 |
|
|---|
| 42 | #ifndef UNMOUNT_CIFS_VENDOR_SUFFIX
|
|---|
| 43 | #ifdef _SAMBA_BUILD_
|
|---|
| 44 | #include "version.h"
|
|---|
| 45 | #ifdef SAMBA_VERSION_VENDOR_SUFFIX
|
|---|
| 46 | #define UNMOUNT_CIFS_VENDOR_SUFFIX "-"SAMBA_VERSION_OFFICIAL_STRING"-"SAMBA_VERSION_VENDOR_SUFFIX
|
|---|
| 47 | #else
|
|---|
| 48 | #define UNMOUNT_CIFS_VENDOR_SUFFIX "-"SAMBA_VERSION_OFFICIAL_STRING
|
|---|
| 49 | #endif /* SAMBA_VERSION_OFFICIAL_STRING and SAMBA_VERSION_VENDOR_SUFFIX */
|
|---|
| 50 | #else
|
|---|
| 51 | #define UNMOUNT_CIFS_VENDOR_SUFFIX ""
|
|---|
| 52 | #endif /* _SAMBA_BUILD_ */
|
|---|
| 53 | #endif /* UNMOUNT_CIFS_VENDOR_SUFFIX */
|
|---|
| 54 |
|
|---|
| 55 | #ifndef MNT_DETACH
|
|---|
| 56 | #define MNT_DETACH 0x02
|
|---|
| 57 | #endif
|
|---|
| 58 |
|
|---|
| 59 | #ifndef MNT_EXPIRE
|
|---|
| 60 | #define MNT_EXPIRE 0x04
|
|---|
| 61 | #endif
|
|---|
| 62 |
|
|---|
| 63 | #ifndef MOUNTED_LOCK
|
|---|
| 64 | #define MOUNTED_LOCK "/etc/mtab~"
|
|---|
| 65 | #endif
|
|---|
| 66 | #ifndef MOUNTED_TEMP
|
|---|
| 67 | #define MOUNTED_TEMP "/etc/mtab.tmp"
|
|---|
| 68 | #endif
|
|---|
| 69 |
|
|---|
| 70 | #define CIFS_IOC_CHECKUMOUNT _IO(0xCF, 2)
|
|---|
| 71 | #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDU */
|
|---|
| 72 |
|
|---|
| 73 | static struct option longopts[] = {
|
|---|
| 74 | { "all", 0, NULL, 'a' },
|
|---|
| 75 | { "help",0, NULL, 'h' },
|
|---|
| 76 | { "read-only", 0, NULL, 'r' },
|
|---|
| 77 | { "ro", 0, NULL, 'r' },
|
|---|
| 78 | { "verbose", 0, NULL, 'v' },
|
|---|
| 79 | { "version", 0, NULL, 'V' },
|
|---|
| 80 | { "expire", 0, NULL, 'e' },
|
|---|
| 81 | { "force", 0, 0, 'f' },
|
|---|
| 82 | { "lazy", 0, 0, 'l' },
|
|---|
| 83 | { "no-mtab", 0, 0, 'n' },
|
|---|
| 84 | { NULL, 0, NULL, 0 }
|
|---|
| 85 | };
|
|---|
| 86 |
|
|---|
| 87 | const char * thisprogram;
|
|---|
| 88 | int verboseflg = 0;
|
|---|
| 89 |
|
|---|
| 90 | static void umount_cifs_usage(void)
|
|---|
| 91 | {
|
|---|
| 92 | printf("\nUsage: %s <remotetarget> <dir>\n", thisprogram);
|
|---|
| 93 | printf("\nUnmount the specified directory\n");
|
|---|
| 94 | printf("\nLess commonly used options:");
|
|---|
| 95 | printf("\n\t-r\tIf mount fails, retry with readonly remount.");
|
|---|
| 96 | printf("\n\t-n\tDo not write to mtab.");
|
|---|
| 97 | printf("\n\t-f\tAttempt a forced unmount, even if the fs is busy.");
|
|---|
| 98 | printf("\n\t-l\tAttempt lazy unmount, Unmount now, cleanup later.");
|
|---|
| 99 | printf("\n\t-v\tEnable verbose mode (may be useful for debugging).");
|
|---|
| 100 | printf("\n\t-h\tDisplay this help.");
|
|---|
| 101 | printf("\n\nOptions are described in more detail in the manual page");
|
|---|
| 102 | printf("\n\tman 8 umount.cifs\n");
|
|---|
| 103 | printf("\nTo display the version number of the cifs umount utility:");
|
|---|
| 104 | printf("\n\t%s -V\n",thisprogram);
|
|---|
| 105 | printf("\nInvoking the umount utility on cifs mounts, can execute");
|
|---|
| 106 | printf(" /sbin/umount.cifs (if present and umount -i is not specified.\n");
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | static int umount_check_perm(char * dir)
|
|---|
| 110 | |
|---|