関数 | |
static void | umount_cifs_usage (void) |
static int | umount_check_perm (char *dir) |
static int | lock_mtab (void) |
static void | unlock_mtab (void) |
static int | remove_from_mtab (char *mountpoint) |
int | main (int argc, char **argv) |
変数 | |
static struct option | longopts [] |
const char * | thisprogram |
int | verboseflg = 0 |
static void umount_cifs_usage | ( | void | ) | [static] |
umount.cifs.c の 89 行で定義されています。
参照先 printf()・thisprogram.
参照元 main().
00090 { 00091 printf("\nUsage: %s <remotetarget> <dir>\n", thisprogram); 00092 printf("\nUnmount the specified directory\n"); 00093 printf("\nLess commonly used options:"); 00094 printf("\n\t-r\tIf mount fails, retry with readonly remount."); 00095 printf("\n\t-n\tDo not write to mtab."); 00096 printf("\n\t-f\tAttempt a forced unmount, even if the fs is busy."); 00097 printf("\n\t-l\tAttempt lazy unmount, Unmount now, cleanup later."); 00098 printf("\n\t-v\tEnable verbose mode (may be useful for debugging)."); 00099 printf("\n\t-h\tDisplay this help."); 00100 printf("\n\nOptions are described in more detail in the manual page"); 00101 printf("\n\tman 8 umount.cifs\n"); 00102 printf("\nTo display the version number of the cifs umount utility:"); 00103 printf("\n\t%s -V\n",thisprogram); 00104 printf("\nInvoking the umount utility on cifs mounts, can execute"); 00105 printf(" /sbin/umount.cifs (if present and umount -i is not specified.\n"); 00106 }
static int umount_check_perm | ( | char * | dir | ) | [static] |
umount.cifs.c の 108 行で定義されています。
参照先 errno・printf()・strerror()・thisprogram・verboseflg.
参照元 main().
00109 { 00110 int fileid; 00111 int rc; 00112 00113 /* allow root to unmount, no matter what */ 00114 if(getuid() == 0) 00115 return 0; 00116 00117 /* presumably can not chdir into the target as we do on mount */ 00118 fileid = open(dir, O_RDONLY | O_DIRECTORY | O_NOFOLLOW, 0); 00119 if(fileid == -1) { 00120 if(verboseflg) 00121 printf("error opening mountpoint %d %s",errno,strerror(errno)); 00122 return errno; 00123 } 00124 00125 rc = ioctl(fileid, CIFS_IOC_CHECKUMOUNT, NULL); 00126 00127 if(verboseflg) 00128 printf("ioctl returned %d with errno %d %s\n",rc,errno,strerror(errno)); 00129 00130 if(rc == ENOTTY) { 00131 printf("user unmounting via %s is an optional feature of",thisprogram); 00132 printf(" the cifs filesystem driver (cifs.ko)"); 00133 printf("\n\tand requires cifs.ko version 1.32 or later\n"); 00134 } else if (rc != 0) 00135 printf("user unmount of %s failed with %d %s\n",dir,errno,strerror(errno)); 00136 close(fileid); 00137 00138 return rc; 00139 }
static int lock_mtab | ( | void | ) | [static] |
umount.cifs.c の 141 行で定義されています。
参照先 errno・printf()・strerror().
参照元 remove_from_mtab().
00142 { 00143 int rc; 00144 00145 rc = mknod(MOUNTED_LOCK , 0600, 0); 00146 if(rc == -1) 00147 printf("\ngetting lock file %s failed with %s\n",MOUNTED_LOCK, 00148 strerror(errno)); 00149 00150 return rc; 00151 00152 }
static void unlock_mtab | ( | void | ) | [static] |
static int remove_from_mtab | ( | char * | mountpoint | ) | [static] |
umount.cifs.c の 159 行で定義されています。
参照先 errno・lock_mtab()・printf()・strerror()・unlock_mtab()・verboseflg.
参照元 main().
00160 { 00161 int rc; 00162 int num_matches; 00163 FILE * org_fd; 00164 FILE * new_fd; 00165 struct mntent * mount_entry; 00166 00167 /* Do we need to check if it is a symlink to e.g. /proc/mounts 00168 in which case we probably do not want to update it? */ 00169 00170 /* Do we first need to check if it is writable? */ 00171 00172 if (lock_mtab()) { 00173 printf("Mount table locked\n"); 00174 return -EACCES; 00175 } 00176 00177 if(verboseflg) 00178 printf("attempting to remove from mtab\n"); 00179 00180 org_fd = setmntent(MOUNTED, "r"); 00181 00182 if(org_fd == NULL) { 00183 printf("Can not open %s\n",MOUNTED); 00184 unlock_mtab(); 00185 return -EIO; 00186 } 00187 00188 new_fd = setmntent(MOUNTED_TEMP,"w"); 00189 if(new_fd == NULL) { 00190 printf("Can not open temp file %s", MOUNTED_TEMP); 00191 endmntent(org_fd); 00192 unlock_mtab(); 00193 return -EIO; 00194 } 00195 00196 /* BB fix so we only remove the last entry that matches BB */ 00197 num_matches = 0; 00198 while((mount_entry = getmntent(org_fd)) != NULL) { 00199 if(strcmp(mount_entry->mnt_dir, mountpoint) == 0) { 00200 num_matches++; 00201 } 00202 } 00203 if(verboseflg) 00204 printf("%d matching entries in mount table\n", num_matches); 00205 00206 /* Is there a better way to seek back to the first entry in mtab? */ 00207 endmntent(org_fd); 00208 org_fd = setmntent(MOUNTED, "r"); 00209 00210 if(org_fd == NULL) { 00211 printf("Can not open %s\n",MOUNTED); 00212 unlock_mtab(); 00213 return -EIO; 00214 } 00215 00216 while((mount_entry = getmntent(org_fd)) != NULL) { 00217 if(strcmp(mount_entry->mnt_dir, mountpoint) != 0) { 00218 addmntent(new_fd, mount_entry); 00219 } else { 00220 if(num_matches != 1) { 00221 addmntent(new_fd, mount_entry); 00222 num_matches--; 00223 } else if(verboseflg) 00224 printf("entry not copied (ie entry is removed)\n"); 00225 } 00226 } 00227 00228 if(verboseflg) 00229 printf("done updating tmp file\n"); 00230 rc = fchmod (fileno (new_fd), S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); 00231 if(rc < 0) { 00232 printf("error %s changing mode of %s\n", strerror(errno), 00233 MOUNTED_TEMP); 00234 } 00235 endmntent(new_fd); 00236 00237 rc = rename(MOUNTED_TEMP, MOUNTED); 00238 00239 if(rc < 0) { 00240 printf("failure %s renaming %s to %s\n",strerror(errno), 00241 MOUNTED_TEMP, MOUNTED); 00242 unlock_mtab(); 00243 return -EIO; 00244 } 00245 00246 unlock_mtab(); 00247 00248 return rc; 00249 }
int main | ( | int | argc, | |
char ** | argv | |||
) |
umount.cifs.c の 251 行で定義されています。
参照先 c・errno・flags・longopts・optind・printf()・remove_from_mtab()・strerror()・thisprogram・umount_check_perm()・umount_cifs_usage()・verboseflg.
00252 { 00253 int c; 00254 int rc; 00255 int flags = 0; 00256 int nomtab = 0; 00257 int retry_remount = 0; 00258 struct statfs statbuf; 00259 char * mountpoint; 00260 00261 if(argc && argv) { 00262 thisprogram = argv[0]; 00263 } else { 00264 umount_cifs_usage(); 00265 return -EINVAL; 00266 } 00267 00268 if(argc < 2) { 00269 umount_cifs_usage(); 00270 return -EINVAL; 00271 } 00272 00273 if(thisprogram == NULL) 00274 thisprogram = "umount.cifs"; 00275 00276 /* add sharename in opts string as unc= parm */ 00277 00278 while ((c = getopt_long (argc, argv, "afhilnrvV", 00279 longopts, NULL)) != -1) { 00280 switch (c) { 00281 /* No code to do the following option yet */ 00282 /* case 'a': 00283 ++umount_all; 00284 break; */ 00285 case '?': 00286 case 'h': /* help */ 00287 umount_cifs_usage(); 00288 exit(1); 00289 case 'n': 00290 ++nomtab; 00291 break; 00292 case 'f': 00293 flags |= MNT_FORCE; 00294 break; 00295 case 'l': 00296 flags |= MNT_DETACH; /* lazy unmount */ 00297 break; 00298 case 'e': 00299 flags |= MNT_EXPIRE; /* gradually timeout */ 00300 break; 00301 case 'r': 00302 ++retry_remount; 00303 break; 00304 case 'v': 00305 ++verboseflg; 00306 break; 00307 case 'V': 00308 printf ("umount.cifs version: %s.%s%s\n", 00309 UNMOUNT_CIFS_VERSION_MAJOR, 00310 UNMOUNT_CIFS_VERSION_MINOR, 00311 UNMOUNT_CIFS_VENDOR_SUFFIX); 00312 exit (0); 00313 default: 00314 printf("unknown unmount option %c\n",c); 00315 umount_cifs_usage(); 00316 exit(1); 00317 } 00318 } 00319 00320 /* move past the umount options */ 00321 argv += optind; 00322 argc -= optind; 00323 00324 mountpoint = argv[0]; 00325 00326 if((argc < 1) || (argv[0] == NULL)) { 00327 printf("\nMissing name of unmount directory\n"); 00328 umount_cifs_usage(); 00329 return -EINVAL; 00330 } 00331 00332 if(verboseflg) 00333 printf("optind %d unmount dir %s\n",optind, mountpoint); 00334 00335 /* check if running effectively root */ 00336 if(geteuid() != 0) { 00337 printf("Trying to unmount when %s not installed suid\n",thisprogram); 00338 if(verboseflg) 00339 printf("euid = %d\n",geteuid()); 00340 return -EACCES; 00341 } 00342 00343 /* fixup path if needed */ 00344 00345 /* Trim any trailing slashes */ 00346 while ((strlen(mountpoint) > 1) && 00347 (mountpoint[strlen(mountpoint)-1] == '/')) 00348 { 00349 mountpoint[strlen(mountpoint)-1] = '\0'; 00350 } 00351 00352 /* make sure that this is a cifs filesystem */ 00353 rc = statfs(mountpoint, &statbuf); 00354 00355 if(rc || (statbuf.f_type != CIFS_MAGIC_NUMBER)) { 00356 printf("This utility only unmounts cifs filesystems.\n"); 00357 return -EINVAL; 00358 } 00359 00360 /* check if our uid was the one who mounted */ 00361 rc = umount_check_perm(mountpoint); 00362 if (rc) { 00363 printf("Not permitted to unmount\n"); 00364 return rc; 00365 } 00366 00367 if(umount2(mountpoint, flags)) { 00368 /* remember to kill daemon on error */ 00369 switch (errno) { 00370 case 0: 00371 printf("unmount failed but no error number set\n"); 00372 break; 00373 default: 00374 printf("unmount error %d = %s\n",errno,strerror(errno)); 00375 } 00376 printf("Refer to the umount.cifs(8) manual page (man 8 umount.cifs)\n"); 00377 return -1; 00378 } else { 00379 if(verboseflg) 00380 printf("umount2 succeeded\n"); 00381 if(nomtab == 0) 00382 remove_from_mtab(mountpoint); 00383 } 00384 00385 return 0; 00386 }
struct option longopts[] [static] |
初期値:
{ { "all", 0, NULL, 'a' }, { "help",0, NULL, 'h' }, { "read-only", 0, NULL, 'r' }, { "ro", 0, NULL, 'r' }, { "verbose", 0, NULL, 'v' }, { "version", 0, NULL, 'V' }, { "expire", 0, NULL, 'e' }, { "force", 0, 0, 'f' }, { "lazy", 0, 0, 'l' }, { "no-mtab", 0, 0, 'n' }, { NULL, 0, NULL, 0 } }
umount.cifs.c の 72 行で定義されています。
const char* thisprogram |
umount.cifs.c の 86 行で定義されています。
int verboseflg = 0 |