umount.c (194880) | umount.c (201135) |
---|---|
1/*- 2 * Copyright (c) 1980, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 24 unchanged lines hidden (view full) --- 33 The Regents of the University of California. All rights reserved.\n"; 34#endif /* not lint */ 35 36#ifndef lint 37#if 0 38static char sccsid[] = "@(#)umount.c 8.8 (Berkeley) 5/8/95"; 39#endif 40static const char rcsid[] = | 1/*- 2 * Copyright (c) 1980, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 24 unchanged lines hidden (view full) --- 33 The Regents of the University of California. All rights reserved.\n"; 34#endif /* not lint */ 35 36#ifndef lint 37#if 0 38static char sccsid[] = "@(#)umount.c 8.8 (Berkeley) 5/8/95"; 39#endif 40static const char rcsid[] = |
41 "$FreeBSD: head/sbin/umount/umount.c 194880 2009-06-24 18:42:21Z dfr $"; | 41 "$FreeBSD: head/sbin/umount/umount.c 201135 2009-12-28 17:57:37Z delphij $"; |
42#endif /* not lint */ 43 44#include <sys/param.h> 45#include <sys/mount.h> 46#include <sys/socket.h> 47#include <sys/stat.h> 48 49#include <netdb.h> --- 20 unchanged lines hidden (view full) --- 70struct statfs *checkmntlist(char *); 71int checkvfsname (const char *, char **); 72struct statfs *getmntentry(const char *fromname, const char *onname, 73 fsid_t *fsid, dowhat what); 74char **makevfslist (const char *); 75size_t mntinfo (struct statfs **); 76int namematch (struct addrinfo *); 77int parsehexfsid(const char *hex, fsid_t *fsid); | 42#endif /* not lint */ 43 44#include <sys/param.h> 45#include <sys/mount.h> 46#include <sys/socket.h> 47#include <sys/stat.h> 48 49#include <netdb.h> --- 20 unchanged lines hidden (view full) --- 70struct statfs *checkmntlist(char *); 71int checkvfsname (const char *, char **); 72struct statfs *getmntentry(const char *fromname, const char *onname, 73 fsid_t *fsid, dowhat what); 74char **makevfslist (const char *); 75size_t mntinfo (struct statfs **); 76int namematch (struct addrinfo *); 77int parsehexfsid(const char *hex, fsid_t *fsid); |
78int sacmp (struct sockaddr *, struct sockaddr *); | 78int sacmp (void *, void *); |
79int umountall (char **); 80int checkname (char *, char **); 81int umountfs(struct statfs *sfs); 82void usage (void); 83int xdr_dir (XDR *, char *); 84 85int 86main(int argc, char *argv[]) --- 133 unchanged lines hidden (view full) --- 220 } while ((fs = getfsent()) != NULL); 221 return (0); 222} 223 224/* 225 * Do magic checks on mountpoint/device/fsid, and then call unmount(2). 226 */ 227int | 79int umountall (char **); 80int checkname (char *, char **); 81int umountfs(struct statfs *sfs); 82void usage (void); 83int xdr_dir (XDR *, char *); 84 85int 86main(int argc, char *argv[]) --- 133 unchanged lines hidden (view full) --- 220 } while ((fs = getfsent()) != NULL); 221 return (0); 222} 223 224/* 225 * Do magic checks on mountpoint/device/fsid, and then call unmount(2). 226 */ 227int |
228checkname(char *name, char **typelist) | 228checkname(char *mntname, char **typelist) |
229{ 230 char buf[MAXPATHLEN]; 231 struct statfs sfsbuf; 232 struct stat sb; 233 struct statfs *sfs; 234 char *delimp; 235 dev_t dev; 236 int len; 237 238 /* 239 * 1. Check if the name exists in the mounttable. 240 */ | 229{ 230 char buf[MAXPATHLEN]; 231 struct statfs sfsbuf; 232 struct stat sb; 233 struct statfs *sfs; 234 char *delimp; 235 dev_t dev; 236 int len; 237 238 /* 239 * 1. Check if the name exists in the mounttable. 240 */ |
241 sfs = checkmntlist(name); | 241 sfs = checkmntlist(mntname); |
242 /* 243 * 2. Remove trailing slashes if there are any. After that 244 * we look up the name in the mounttable again. 245 */ 246 if (sfs == NULL) { | 242 /* 243 * 2. Remove trailing slashes if there are any. After that 244 * we look up the name in the mounttable again. 245 */ 246 if (sfs == NULL) { |
247 len = strlen(name); 248 while (len > 1 && name[len - 1] == '/') 249 name[--len] = '\0'; 250 sfs = checkmntlist(name); | 247 len = strlen(mntname); 248 while (len > 1 && mntname[len - 1] == '/') 249 mntname[--len] = '\0'; 250 sfs = checkmntlist(mntname); |
251 } 252 /* 253 * 3. Check if the deprecated NFS syntax with an '@' has been used 254 * and translate it to the ':' syntax. Look up the name in the 255 * mount table again. 256 */ | 251 } 252 /* 253 * 3. Check if the deprecated NFS syntax with an '@' has been used 254 * and translate it to the ':' syntax. Look up the name in the 255 * mount table again. 256 */ |
257 if (sfs == NULL && (delimp = strrchr(name, '@')) != NULL) { 258 snprintf(buf, sizeof(buf), "%s:%.*s", delimp + 1, delimp - name, 259 name); | 257 if (sfs == NULL && (delimp = strrchr(mntname, '@')) != NULL) { 258 snprintf(buf, sizeof(buf), "%s:%.*s", delimp + 1, 259 (int)(delimp - mntname), mntname); |
260 len = strlen(buf); 261 while (len > 1 && buf[len - 1] == '/') 262 buf[--len] = '\0'; 263 sfs = checkmntlist(buf); 264 } 265 /* 266 * 4. Resort to a statfs(2) call. This is the last check so that 267 * hung NFS filesystems for example can be unmounted without 268 * potentially blocking forever in statfs() as long as the 269 * filesystem is specified unambiguously. This covers all the 270 * hard cases such as symlinks and mismatches between the 271 * mount list and reality. 272 * We also do this if an ambiguous mount point was specified. 273 */ | 260 len = strlen(buf); 261 while (len > 1 && buf[len - 1] == '/') 262 buf[--len] = '\0'; 263 sfs = checkmntlist(buf); 264 } 265 /* 266 * 4. Resort to a statfs(2) call. This is the last check so that 267 * hung NFS filesystems for example can be unmounted without 268 * potentially blocking forever in statfs() as long as the 269 * filesystem is specified unambiguously. This covers all the 270 * hard cases such as symlinks and mismatches between the 271 * mount list and reality. 272 * We also do this if an ambiguous mount point was specified. 273 */ |
274 if (sfs == NULL || (getmntentry(NULL, name, NULL, FIND) != NULL && 275 getmntentry(NULL, name, NULL, CHECKUNIQUE) == NULL)) { 276 if (statfs(name, &sfsbuf) != 0) { 277 warn("%s: statfs", name); 278 } else if (stat(name, &sb) != 0) { 279 warn("%s: stat", name); | 274 if (sfs == NULL || (getmntentry(NULL, mntname, NULL, FIND) != NULL && 275 getmntentry(NULL, mntname, NULL, CHECKUNIQUE) == NULL)) { 276 if (statfs(mntname, &sfsbuf) != 0) { 277 warn("%s: statfs", mntname); 278 } else if (stat(mntname, &sb) != 0) { 279 warn("%s: stat", mntname); |
280 } else if (S_ISDIR(sb.st_mode)) { | 280 } else if (S_ISDIR(sb.st_mode)) { |
281 /* Check that `name' is the root directory. */ | 281 /* Check that `mntname' is the root directory. */ |
282 dev = sb.st_dev; | 282 dev = sb.st_dev; |
283 snprintf(buf, sizeof(buf), "%s/..", name); | 283 snprintf(buf, sizeof(buf), "%s/..", mntname); |
284 if (stat(buf, &sb) != 0) { 285 warn("%s: stat", buf); 286 } else if (sb.st_dev == dev) { 287 warnx("%s: not a file system root directory", | 284 if (stat(buf, &sb) != 0) { 285 warn("%s: stat", buf); 286 } else if (sb.st_dev == dev) { 287 warnx("%s: not a file system root directory", |
288 name); | 288 mntname); |
289 return (1); 290 } else 291 sfs = &sfsbuf; 292 } 293 } 294 if (sfs == NULL) { | 289 return (1); 290 } else 291 sfs = &sfsbuf; 292 } 293 } 294 if (sfs == NULL) { |
295 warnx("%s: unknown file system", name); | 295 warnx("%s: unknown file system", mntname); |
296 return (1); 297 } 298 if (checkvfsname(sfs->f_fstypename, typelist)) 299 return (1); 300 return (umountfs(sfs)); 301} 302 303/* --- 160 unchanged lines hidden (view full) --- 464 } 465 466 if (what == CHECKUNIQUE && count == 1) 467 return (foundsfs); 468 return (NULL); 469} 470 471int | 296 return (1); 297 } 298 if (checkvfsname(sfs->f_fstypename, typelist)) 299 return (1); 300 return (umountfs(sfs)); 301} 302 303/* --- 160 unchanged lines hidden (view full) --- 464 } 465 466 if (what == CHECKUNIQUE && count == 1) 467 return (foundsfs); 468 return (NULL); 469} 470 471int |
472sacmp(struct sockaddr *sa1, struct sockaddr *sa2) | 472sacmp(void *sa1, void *sa2) |
473{ 474 void *p1, *p2; 475 int len; 476 | 473{ 474 void *p1, *p2; 475 int len; 476 |
477 if (sa1->sa_family != sa2->sa_family) | 477 if (((struct sockaddr *)sa1)->sa_family != 478 ((struct sockaddr *)sa2)->sa_family) |
478 return (1); 479 | 479 return (1); 480 |
480 switch (sa1->sa_family) { | 481 switch (((struct sockaddr *)sa1)->sa_family) { |
481 case AF_INET: 482 p1 = &((struct sockaddr_in *)sa1)->sin_addr; 483 p2 = &((struct sockaddr_in *)sa2)->sin_addr; 484 len = 4; 485 break; 486 case AF_INET6: 487 p1 = &((struct sockaddr_in6 *)sa1)->sin6_addr; 488 p2 = &((struct sockaddr_in6 *)sa2)->sin6_addr; --- 26 unchanged lines hidden (view full) --- 515 } 516 ai = ai->ai_next; 517 } 518 519 return (0); 520} 521 522struct statfs * | 482 case AF_INET: 483 p1 = &((struct sockaddr_in *)sa1)->sin_addr; 484 p2 = &((struct sockaddr_in *)sa2)->sin_addr; 485 len = 4; 486 break; 487 case AF_INET6: 488 p1 = &((struct sockaddr_in6 *)sa1)->sin6_addr; 489 p2 = &((struct sockaddr_in6 *)sa2)->sin6_addr; --- 26 unchanged lines hidden (view full) --- 516 } 517 ai = ai->ai_next; 518 } 519 520 return (0); 521} 522 523struct statfs * |
523checkmntlist(char *name) | 524checkmntlist(char *mntname) |
524{ 525 struct statfs *sfs; 526 fsid_t fsid; 527 528 sfs = NULL; | 525{ 526 struct statfs *sfs; 527 fsid_t fsid; 528 529 sfs = NULL; |
529 if (parsehexfsid(name, &fsid) == 0) | 530 if (parsehexfsid(mntname, &fsid) == 0) |
530 sfs = getmntentry(NULL, NULL, &fsid, FIND); 531 if (sfs == NULL) | 531 sfs = getmntentry(NULL, NULL, &fsid, FIND); 532 if (sfs == NULL) |
532 sfs = getmntentry(NULL, name, NULL, FIND); | 533 sfs = getmntentry(NULL, mntname, NULL, FIND); |
533 if (sfs == NULL) | 534 if (sfs == NULL) |
534 sfs = getmntentry(name, NULL, NULL, FIND); | 535 sfs = getmntentry(mntname, NULL, NULL, FIND); |
535 return (sfs); 536} 537 538size_t 539mntinfo(struct statfs **mntbuf) 540{ 541 static struct statfs *origbuf; 542 size_t bufsize; --- 55 unchanged lines hidden --- | 536 return (sfs); 537} 538 539size_t 540mntinfo(struct statfs **mntbuf) 541{ 542 static struct statfs *origbuf; 543 size_t bufsize; --- 55 unchanged lines hidden --- |