clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name mount.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/sbin/mount/obj -resource-dir /usr/local/lib/clang/13.0.0 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/sbin/mount/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/sbin/mount/mount.c
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | #include <sys/types.h> |
| 34 | #include <sys/mount.h> |
| 35 | #include <sys/socket.h> |
| 36 | #include <sys/wait.h> |
| 37 | |
| 38 | #include <nfs/rpcv2.h> |
| 39 | #include <nfs/nfsproto.h> |
| 40 | #include <nfs/nfs.h> |
| 41 | |
| 42 | #include <err.h> |
| 43 | #include <errno.h> |
| 44 | #include <fstab.h> |
| 45 | #include <netdb.h> |
| 46 | #include <signal.h> |
| 47 | #include <stdio.h> |
| 48 | #include <stdlib.h> |
| 49 | #include <string.h> |
| 50 | #include <unistd.h> |
| 51 | #include <limits.h> |
| 52 | #include <util.h> |
| 53 | |
| 54 | #include "pathnames.h" |
| 55 | |
| 56 | int debug, verbose, skip; |
| 57 | char **typelist = NULL; |
| 58 | enum { NONET_FILTER, NET_FILTER } filter = NONET_FILTER; |
| 59 | |
| 60 | int selected(const char *); |
| 61 | char *catopt(char *, const char *); |
| 62 | char *flags2opts(u_int32_t); |
| 63 | struct statfs |
| 64 | *getmntpt(const char *); |
| 65 | int hasopt(const char *, const char *); |
| 66 | void maketypelist(char *); |
| 67 | void mangle(char *, int *, const char **, int); |
| 68 | int mountfs(const char *, const char *, const char *, const char *, |
| 69 | const char *, int); |
| 70 | void prmount(struct statfs *); |
| 71 | int disklabelcheck(struct fstab *); |
| 72 | __dead void usage(void); |
| 73 | |
| 74 | |
| 75 | static struct opt { |
| 76 | int o_opt; |
| 77 | int o_silent; |
| 78 | const char *o_name; |
| 79 | const char *o_optname; |
| 80 | } optnames[] = { |
| 81 | { MNT_ASYNC, 0, "asynchronous", "async" }, |
| 82 | { MNT_DEFEXPORTED, 1, "exported to the world", "" }, |
| 83 | { MNT_EXPORTED, 0, "NFS exported", "" }, |
| 84 | { MNT_EXPORTANON, 1, "anon uid mapping", "" }, |
| 85 | { MNT_EXRDONLY, 1, "exported read-only", "" }, |
| 86 | { MNT_LOCAL, 0, "local", "" }, |
| 87 | { MNT_NOATIME, 0, "noatime", "noatime" }, |
| 88 | { MNT_NODEV, 0, "nodev", "nodev" }, |
| 89 | { MNT_NOEXEC, 0, "noexec", "noexec" }, |
| 90 | { MNT_NOSUID, 0, "nosuid", "nosuid" }, |
| 91 | { MNT_NOPERM, 0, "noperm", "noperm" }, |
| 92 | { MNT_WXALLOWED, 0, "wxallowed", "wxallowed" }, |
| 93 | { MNT_QUOTA, 0, "with quotas", "" }, |
| 94 | { MNT_RDONLY, 0, "read-only", "ro" }, |
| 95 | { MNT_ROOTFS, 1, "root file system", "" }, |
| 96 | { MNT_SYNCHRONOUS, 0, "synchronous", "sync" }, |
| 97 | { MNT_SOFTDEP, 0, "softdep", "softdep" }, |
| 98 | { 0, 0, "", "" } |
| 99 | }; |
| 100 | |
| 101 | int |
| 102 | main(int argc, char * const argv[]) |
| 103 | { |
| 104 | const char *mntonname, *vfstype; |
| 105 | struct fstab *fs; |
| 106 | struct statfs *mntbuf; |
| 107 | FILE *mountdfp; |
| 108 | pid_t pid; |
| 109 | int all, ch, forceall, i, mntsize, rval, new; |
| 110 | char *options, mntpath[PATH_MAX]; |
| 111 | |
| 112 | all = forceall = 0; |
| 113 | options = NULL; |
| 114 | vfstype = "ffs"; |
| 115 | while ((ch = getopt(argc, argv, "AadfNo:rswt:uv")) != -1) |
| 1 | Assuming the condition is false | |
|
| 2 | | Loop condition is false. Execution continues on line 165 | |
|
| 116 | switch (ch) { |
| 117 | case 'A': |
| 118 | all = forceall = 1; |
| 119 | break; |
| 120 | case 'a': |
| 121 | all = 1; |
| 122 | break; |
| 123 | case 'd': |
| 124 | debug = 1; |
| 125 | break; |
| 126 | case 'f': |
| 127 | if (!hasopt(options, "force")) |
| 128 | options = catopt(options, "force"); |
| 129 | break; |
| 130 | case 'N': |
| 131 | filter = NET_FILTER; |
| 132 | break; |
| 133 | case 'o': |
| 134 | if (*optarg) |
| 135 | options = catopt(options, optarg); |
| 136 | break; |
| 137 | case 'r': |
| 138 | if (!hasopt(options, "ro")) |
| 139 | options = catopt(options, "ro"); |
| 140 | break; |
| 141 | case 's': |
| 142 | skip = 1; |
| 143 | break; |
| 144 | case 't': |
| 145 | if (typelist != NULL) |
| 146 | errx(1, "only one -t option may be specified."); |
| 147 | maketypelist(optarg); |
| 148 | vfstype = optarg; |
| 149 | break; |
| 150 | case 'u': |
| 151 | if (!hasopt(options, "update")) |
| 152 | options = catopt(options, "update"); |
| 153 | break; |
| 154 | case 'v': |
| 155 | verbose = 1; |
| 156 | break; |
| 157 | case 'w': |
| 158 | if (!hasopt(options, "rw")) |
| 159 | options = catopt(options, "rw"); |
| 160 | break; |
| 161 | case '?': |
| 162 | default: |
| 163 | usage(); |
| 164 | } |
| 165 | argc -= optind; |
| 166 | argv += optind; |
| 167 | |
| 168 | if (typelist == NULL && argc == 2) { |
| 3 | | Assuming 'argc' is equal to 2 | |
|
| |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | if (strpbrk(argv[0], ":@") != NULL) |
| 5 | | Assuming the condition is true | |
|
| |
| 176 | vfstype = "nfs"; |
| 177 | else { |
| 178 | char *labelfs = readlabelfs(argv[0], 0); |
| 179 | if (labelfs != NULL) |
| 180 | vfstype = labelfs; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | if (pledge("stdio rpath disklabel proc exec", NULL) == -1) |
| 7 | | Assuming the condition is false | |
|
| |
| 185 | err(1, "pledge"); |
| 186 | |
| 187 | #define BADTYPE(type) \ |
| 188 | (strcmp(type, FSTAB_RO) && \ |
| 189 | strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ)) |
| 190 | |
| 191 | rval = 0; |
| 192 | new = 0; |
| 193 | switch (argc) { |
| 9 | | Control jumps to 'case 2:' at line 278 | |
|
| 194 | case 0: |
| 195 | if (all) |
| 196 | while ((fs = getfsent()) != NULL) { |
| 197 | if (BADTYPE(fs->fs_type)) |
| 198 | continue; |
| 199 | switch (filter) { |
| 200 | case NET_FILTER: |
| 201 | if (!hasopt(fs->fs_mntops, "net")) |
| 202 | continue; |
| 203 | break; |
| 204 | case NONET_FILTER: |
| 205 | if (hasopt(fs->fs_mntops, "net")) |
| 206 | continue; |
| 207 | break; |
| 208 | } |
| 209 | if (!selected(fs->fs_vfstype)) |
| 210 | continue; |
| 211 | if (hasopt(fs->fs_mntops, "noauto")) |
| 212 | continue; |
| 213 | if (disklabelcheck(fs)) |
| 214 | continue; |
| 215 | if (mountfs(fs->fs_vfstype, fs->fs_spec, |
| 216 | fs->fs_file, options, |
| 217 | fs->fs_mntops, !forceall)) |
| 218 | rval = 1; |
| 219 | else |
| 220 | ++new; |
| 221 | } |
| 222 | else { |
| 223 | if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) |
| 224 | err(1, "getmntinfo"); |
| 225 | for (i = 0; i < mntsize; i++) { |
| 226 | if (!selected(mntbuf[i].f_fstypename)) |
| 227 | continue; |
| 228 | prmount(&mntbuf[i]); |
| 229 | } |
| 230 | return (rval); |
| 231 | } |
| 232 | break; |
| 233 | case 1: |
| 234 | if (typelist != NULL) |
| 235 | usage(); |
| 236 | |
| 237 | if (realpath(*argv, mntpath) == NULL) |
| 238 | strlcpy(mntpath, *argv, sizeof(mntpath)); |
| 239 | if (hasopt(options, "update")) { |
| 240 | if ((mntbuf = getmntpt(mntpath)) == NULL) |
| 241 | errx(1, |
| 242 | "unknown special file or file system %s.", |
| 243 | mntpath); |
| 244 | if ((mntbuf->f_flags & MNT_ROOTFS) && |
| 245 | !strcmp(mntbuf->f_mntfromname, "root_device")) { |
| 246 | |
| 247 | fs = getfsfile(mntbuf->f_mntonname); |
| 248 | if (fs == NULL) |
| 249 | errx(1, |
| 250 | "can't find fstab entry for %s.", |
| 251 | mntpath); |
| 252 | } else { |
| 253 | if ((fs = malloc(sizeof(*fs))) == NULL) |
| 254 | err(1, NULL); |
| 255 | fs->fs_vfstype = mntbuf->f_fstypename; |
| 256 | fs->fs_spec = mntbuf->f_mntfromname; |
| 257 | } |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | fs->fs_mntops = flags2opts(mntbuf->f_flags); |
| 264 | mntonname = mntbuf->f_mntonname; |
| 265 | } else { |
| 266 | if ((fs = getfsfile(mntpath)) == NULL && |
| 267 | (fs = getfsspec(mntpath)) == NULL) |
| 268 | errx(1, "can't find fstab entry for %s.", |
| 269 | mntpath); |
| 270 | if (BADTYPE(fs->fs_type)) |
| 271 | errx(1, "%s has unknown file system type.", |
| 272 | mntpath); |
| 273 | mntonname = fs->fs_file; |
| 274 | } |
| 275 | rval = mountfs(fs->fs_vfstype, fs->fs_spec, |
| 276 | mntonname, options, fs->fs_mntops, skip); |
| 277 | break; |
| 278 | case 2: |
| 279 | rval = mountfs(vfstype, argv[0], argv[1], options, NULL, skip); |
| |
| 280 | break; |
| 281 | default: |
| 282 | usage(); |
| 283 | } |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | if ((rval == 0 || new) && getuid() == 0 && |
| 291 | (mountdfp = fopen(_PATH_MOUNTDPID, "r")) != NULL) { |
| 292 | if (fscanf(mountdfp, "%d", &pid) == 1 && |
| 293 | pid > 0 && kill(pid, SIGHUP) == -1 && errno != ESRCH) |
| 294 | err(1, "signal mountd"); |
| 295 | (void)fclose(mountdfp); |
| 296 | } |
| 297 | |
| 298 | return (rval); |
| 299 | } |
| 300 | |
| 301 | int |
| 302 | hasopt(const char *mntopts, const char *option) |
| 303 | { |
| 304 | int found; |
| 305 | char *opt, *optbuf; |
| 306 | |
| 307 | if (mntopts == NULL) |
| 308 | return (0); |
| 309 | if ((optbuf = strdup(mntopts)) == NULL) |
| 310 | err(1, NULL); |
| 311 | found = 0; |
| 312 | for (opt = optbuf; !found && opt != NULL; strsep(&opt, ",")) |
| 313 | found = !strncmp(opt, option, strlen(option)); |
| 314 | free(optbuf); |
| 315 | return (found); |
| 316 | } |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | char* |
| 322 | flags2opts(u_int32_t flags) |
| 323 | { |
| 324 | char *optlist; |
| 325 | struct opt *p; |
| 326 | |
| 327 | optlist = NULL; |
| 328 | for (p = optnames; p->o_opt; p++) { |
| 329 | if (flags & p->o_opt && *p->o_optname) |
| 330 | optlist = catopt(optlist, p->o_optname); |
| 331 | } |
| 332 | |
| 333 | return(optlist); |
| 334 | } |
| 335 | |
| 336 | int |
| 337 | mountfs(const char *vfstype, const char *spec, const char *name, |
| 338 | const char *options, const char *mntopts, int skipmounted) |
| 339 | { |
| 340 | char *cp; |
| 341 | |
| 342 | |
| 343 | static const char *edirs[] = { |
| 344 | _PATH_SBIN, |
| 345 | _PATH_USRSBIN, |
| 346 | NULL |
| 347 | }; |
| 348 | const char **argv, **edir; |
| 349 | struct statfs sf; |
| 350 | pid_t pid; |
| 351 | int argc, i, status, argvsize; |
| 352 | char *optbuf, execname[PATH_MAX], mntpath[PATH_MAX]; |
| 353 | |
| 354 | if (realpath(name, mntpath) == NULL) { |
| 11 | | Assuming the condition is false | |
|
| |
| 355 | warn("realpath %s", name); |
| 356 | return (1); |
| 357 | } |
| 358 | |
| 359 | name = mntpath; |
| 360 | |
| 361 | if (mntopts == NULL) |
| |
| 362 | mntopts = ""; |
| 363 | |
| 364 | if (options == NULL) { |
| |
| 365 | if (*mntopts == '\0') |
| |
| 366 | options = "rw"; |
| 367 | else { |
| 368 | options = mntopts; |
| 369 | mntopts = ""; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | |
| 374 | if ((cp = strdup(mntopts)) == NULL) |
| 16 | | Assuming the condition is false | |
|
| |
| 375 | err(1, NULL); |
| 376 | optbuf = catopt(cp, options); |
| |
| 24 | | Returned allocated memory | |
|
| 377 | |
| 378 | if (strcmp(name, "/") == 0) { |
| 25 | | Assuming the condition is false | |
|
| |
| 379 | if (!hasopt(optbuf, "update")) |
| 380 | optbuf = catopt(optbuf, "update"); |
| 381 | } else if (skipmounted) { |
| 27 | | Assuming 'skipmounted' is not equal to 0 | |
|
| |
| 382 | if (statfs(name, &sf) == -1) { |
| 29 | | Assuming the condition is true | |
|
| |
| 383 | warn("statfs %s", name); |
| 31 | | Potential leak of memory pointed to by 'optbuf' |
|
| 384 | return (1); |
| 385 | } |
| 386 | |
| 387 | if (strncmp(name, sf.f_mntonname, MNAMELEN) == 0 && |
| 388 | strncmp(vfstype, sf.f_fstypename, MFSNAMELEN) == 0) { |
| 389 | if (verbose) { |
| 390 | printf("%s", sf.f_mntfromname); |
| 391 | if (strncmp(sf.f_mntfromname, |
| 392 | sf.f_mntfromspec, MNAMELEN) != 0) |
| 393 | printf(" (%s)", sf.f_mntfromspec); |
| 394 | printf(" on %s type %.*s: %s\n", |
| 395 | sf.f_mntonname, |
| 396 | MFSNAMELEN, sf.f_fstypename, |
| 397 | "already mounted"); |
| 398 | } |
| 399 | return (0); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | argvsize = 64; |
| 404 | if((argv = reallocarray(NULL, argvsize, sizeof(char *))) == NULL) |
| 405 | err(1, NULL); |
| 406 | argc = 0; |
| 407 | argv[argc++] = NULL; |
| 408 | mangle(optbuf, &argc, argv, argvsize - 4); |
| 409 | argv[argc++] = spec; |
| 410 | argv[argc++] = name; |
| 411 | argv[argc] = NULL; |
| 412 | |
| 413 | if (debug) { |
| 414 | (void)printf("exec: mount_%s", vfstype); |
| 415 | for (i = 1; i < argc; i++) |
| 416 | (void)printf(" %s", argv[i]); |
| 417 | (void)printf("\n"); |
| 418 | free(optbuf); |
| 419 | free(argv); |
| 420 | return (0); |
| 421 | } |
| 422 | |
| 423 | switch ((pid = fork())) { |
| 424 | case -1: |
| 425 | warn("fork"); |
| 426 | free(optbuf); |
| 427 | free(argv); |
| 428 | return (1); |
| 429 | case 0: |
| 430 | |
| 431 | edir = edirs; |
| 432 | do { |
| 433 | (void)snprintf(execname, |
| 434 | sizeof(execname), "%s/mount_%s", *edir, vfstype); |
| 435 | argv[0] = execname; |
| 436 | execv(execname, (char * const *)argv); |
| 437 | if (errno != ENOENT) |
| 438 | warn("exec %s for %s", execname, name); |
| 439 | } while (*++edir != NULL); |
| 440 | |
| 441 | if (errno == ENOENT) |
| 442 | warn("no mount helper program found for %s", vfstype); |
| 443 | _exit(1); |
| 444 | default: |
| 445 | free(optbuf); |
| 446 | free(argv); |
| 447 | |
| 448 | if (waitpid(pid, &status, 0) == -1) { |
| 449 | warn("waitpid"); |
| 450 | return (1); |
| 451 | } |
| 452 | |
| 453 | if (WIFEXITED(status)) { |
| 454 | if (WEXITSTATUS(status) != 0) |
| 455 | return (WEXITSTATUS(status)); |
| 456 | } else if (WIFSIGNALED(status)) { |
| 457 | warnx("%s: %s", name, strsignal(WTERMSIG(status))); |
| 458 | return (1); |
| 459 | } |
| 460 | |
| 461 | if (verbose) { |
| 462 | if (statfs(name, &sf) == -1) { |
| 463 | warn("statfs %s", name); |
| 464 | return (1); |
| 465 | } |
| 466 | prmount(&sf); |
| 467 | } |
| 468 | break; |
| 469 | } |
| 470 | |
| 471 | return (0); |
| 472 | } |
| 473 | |
| 474 | void |
| 475 | prmount(struct statfs *sf) |
| 476 | { |
| 477 | int flags; |
| 478 | struct opt *o; |
| 479 | int f = 0; |
| 480 | |
| 481 | printf("%s", sf->f_mntfromname); |
| 482 | if (verbose && |
| 483 | strncmp(sf->f_mntfromname, sf->f_mntfromspec, MNAMELEN) != 0) |
| 484 | printf(" (%s)", sf->f_mntfromspec); |
| 485 | printf(" on %s type %.*s", sf->f_mntonname, |
| 486 | MFSNAMELEN, sf->f_fstypename); |
| 487 | |
| 488 | flags = sf->f_flags & MNT_VISFLAGMASK; |
| 489 | if (verbose && !(flags & MNT_RDONLY)) |
| 490 | (void)printf("%s%s", !f++ ? " (" : ", ", "rw"); |
| 491 | for (o = optnames; flags && o->o_opt; o++) |
| 492 | if (flags & o->o_opt) { |
| 493 | if (!o->o_silent) |
| 494 | (void)printf("%s%s", !f++ ? " (" : ", ", |
| 495 | o->o_name); |
| 496 | flags &= ~o->o_opt; |
| 497 | } |
| 498 | if (flags) |
| 499 | (void)printf("%sunknown flag%s %#x", !f++ ? " (" : ", ", |
| 500 | flags & (flags - 1) ? "s" : "", flags); |
| 501 | |
| 502 | |
| 503 | if (verbose) { |
| 504 | char buf[26]; |
| 505 | time_t t = sf->f_ctime; |
| 506 | |
| 507 | ctime_r(&t, buf); |
| 508 | buf[24] = '\0'; |
| 509 | printf(", ctime=%s", buf); |
| 510 | } |
| 511 | |
| 512 | |
| 513 | |
| 514 | |
| 515 | |
| 516 | |
| 517 | if (strcmp(sf->f_fstypename, MOUNT_NFS) == 0) { |
| 518 | struct protoent *pr; |
| 519 | struct nfs_args *nfs_args = &sf->mount_info.nfs_args; |
| 520 | |
| 521 | (void)printf("%s%s", !f++ ? " (" : ", ", |
| 522 | (nfs_args->flags & NFSMNT_NFSV3) ? "v3" : "v2"); |
| 523 | if (nfs_args->proto && (pr = getprotobynumber(nfs_args->proto))) |
| 524 | (void)printf("%s%s", !f++ ? " (" : ", ", pr->p_name); |
| 525 | else |
| 526 | (void)printf("%s%s", !f++ ? " (" : ", ", |
| 527 | (nfs_args->sotype == SOCK_DGRAM) ? "udp" : "tcp"); |
| 528 | if (nfs_args->flags & NFSMNT_SOFT) |
| 529 | (void)printf("%s%s", !f++ ? " (" : ", ", "soft"); |
| 530 | else if (verbose) |
| 531 | (void)printf("%s%s", !f++ ? " (" : ", ", "hard"); |
| 532 | if (nfs_args->flags & NFSMNT_INT) |
| 533 | (void)printf("%s%s", !f++ ? " (" : ", ", "intr"); |
| 534 | if (nfs_args->flags & NFSMNT_NOCONN) |
| 535 | (void)printf("%s%s", !f++ ? " (" : ", ", "noconn"); |
| 536 | if (nfs_args->flags & NFSMNT_RDIRPLUS) |
| 537 | (void)printf("%s%s", !f++ ? " (" : ", ", "rdirplus"); |
| 538 | if (verbose || nfs_args->wsize != NFS_WSIZE) |
| 539 | (void)printf("%s%s=%d", !f++ ? " (" : ", ", |
| 540 | "wsize", nfs_args->wsize); |
| 541 | if (verbose || nfs_args->rsize != NFS_RSIZE) |
| 542 | (void)printf("%s%s=%d", !f++ ? " (" : ", ", |
| 543 | "rsize", nfs_args->rsize); |
| 544 | if (verbose || nfs_args->readdirsize != NFS_READDIRSIZE) |
| 545 | (void)printf("%s%s=%d", !f++ ? " (" : ", ", |
| 546 | "rdirsize", nfs_args->readdirsize); |
| 547 | if (verbose || nfs_args->timeo != 10) |
| 548 | (void)printf("%s%s=%d", !f++ ? " (" : ", ", |
| 549 | "timeo", nfs_args->timeo); |
| 550 | if (verbose || nfs_args->retrans != NFS_RETRANS) |
| 551 | (void)printf("%s%s=%d", !f++ ? " (" : ", ", |
| 552 | "retrans", nfs_args->retrans); |
| 553 | if (verbose || nfs_args->maxgrouplist != NFS_MAXGRPS) |
| 554 | (void)printf("%s%s=%d", !f++ ? " (" : ", ", |
| 555 | "maxgrouplist", nfs_args->maxgrouplist); |
| 556 | if (verbose || nfs_args->readahead != NFS_DEFRAHEAD) |
| 557 | (void)printf("%s%s=%d", !f++ ? " (" : ", ", |
| 558 | "readahead", nfs_args->readahead); |
| 559 | if (verbose) { |
| 560 | (void)printf("%s%s=%d", !f++ ? " (" : ", ", |
| 561 | "acregmin", nfs_args->acregmin); |
| 562 | (void)printf(", %s=%d", |
| 563 | "acregmax", nfs_args->acregmax); |
| 564 | (void)printf(", %s=%d", |
| 565 | "acdirmin", nfs_args->acdirmin); |
| 566 | (void)printf(", %s=%d", |
| 567 | "acdirmax", nfs_args->acdirmax); |
| 568 | } |
| 569 | } else if (strcmp(sf->f_fstypename, MOUNT_MFS) == 0) { |
| 570 | int headerlen; |
| 571 | long blocksize; |
| 572 | char *header; |
| 573 | |
| 574 | header = getbsize(&headerlen, &blocksize); |
| 575 | (void)printf("%s%s=%lu %s", !f++ ? " (" : ", ", |
| 576 | "size", sf->mount_info.mfs_args.size / blocksize, header); |
| 577 | } else if (strcmp(sf->f_fstypename, MOUNT_MSDOS) == 0) { |
| 578 | struct msdosfs_args *msdosfs_args = &sf->mount_info.msdosfs_args; |
| 579 | |
| 580 | if (verbose || msdosfs_args->uid || msdosfs_args->gid) |
| 581 | (void)printf("%s%s=%u, %s=%u", !f++ ? " (" : ", ", |
| 582 | "uid", msdosfs_args->uid, "gid", msdosfs_args->gid); |
| 583 | if (verbose || msdosfs_args->mask != 0755) |
| 584 | (void)printf("%s%s=0%o", !f++ ? " (" : ", ", |
| 585 | "mask", msdosfs_args->mask); |
| 586 | if (msdosfs_args->flags & MSDOSFSMNT_SHORTNAME) |
| 587 | (void)printf("%s%s", !f++ ? " (" : ", ", "short"); |
| 588 | if (msdosfs_args->flags & MSDOSFSMNT_LONGNAME) |
| 589 | (void)printf("%s%s", !f++ ? " (" : ", ", "long"); |
| 590 | if (msdosfs_args->flags & MSDOSFSMNT_NOWIN95) |
| 591 | (void)printf("%s%s", !f++ ? " (" : ", ", "nowin95"); |
| 592 | } else if (strcmp(sf->f_fstypename, MOUNT_CD9660) == 0) { |
| 593 | struct iso_args *iso_args = &sf->mount_info.iso_args; |
| 594 | |
| 595 | if (iso_args->flags & ISOFSMNT_NORRIP) |
| 596 | (void)printf("%s%s", !f++ ? " (" : ", ", "norrip"); |
| 597 | if (iso_args->flags & ISOFSMNT_GENS) |
| 598 | (void)printf("%s%s", !f++ ? " (" : ", ", "gens"); |
| 599 | if (iso_args->flags & ISOFSMNT_EXTATT) |
| 600 | (void)printf("%s%s", !f++ ? " (" : ", ", "extatt"); |
| 601 | } else if (strcmp(sf->f_fstypename, MOUNT_TMPFS) == 0) { |
| 602 | struct tmpfs_args *tmpfs_args = &sf->mount_info.tmpfs_args; |
| 603 | |
| 604 | if (verbose || tmpfs_args->ta_root_uid || tmpfs_args->ta_root_gid) |
| 605 | (void)printf("%s%s=%u, %s=%u", !f++ ? " (" : ", ", |
| 606 | "uid", tmpfs_args->ta_root_uid, "gid", tmpfs_args->ta_root_gid); |
| 607 | if (verbose || tmpfs_args->ta_root_mode != 040755) |
| 608 | (void)printf("%s%s=%04o", !f++ ? " (" : ", ", |
| 609 | "mode", tmpfs_args->ta_root_mode & 07777); |
| 610 | if (verbose || tmpfs_args->ta_size_max) |
| 611 | (void)printf("%s%s=%lu", !f++ ? " (" : ", ", |
| 612 | "size", (unsigned long)tmpfs_args->ta_size_max); |
| 613 | if (verbose || tmpfs_args->ta_nodes_max) |
| 614 | (void)printf("%s%s=%lu", !f++ ? " (" : ", ", |
| 615 | "inodes", (unsigned long)tmpfs_args->ta_nodes_max); |
| 616 | } |
| 617 | (void)printf(f ? ")\n" : "\n"); |
| 618 | } |
| 619 | |
| 620 | struct statfs * |
| 621 | getmntpt(const char *name) |
| 622 | { |
| 623 | struct statfs *mntbuf; |
| 624 | int i, mntsize; |
| 625 | |
| 626 | mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); |
| 627 | for (i = 0; i < mntsize; i++) |
| 628 | if (strcmp(mntbuf[i].f_mntfromname, name) == 0 || |
| 629 | strcmp(mntbuf[i].f_mntonname, name) == 0) |
| 630 | return (&mntbuf[i]); |
| 631 | return (NULL); |
| 632 | } |
| 633 | |
| 634 | static enum { IN_LIST, NOT_IN_LIST } which; |
| 635 | |
| 636 | int |
| 637 | selected(const char *type) |
| 638 | { |
| 639 | char **av; |
| 640 | |
| 641 | |
| 642 | if (typelist == NULL) |
| 643 | return (1); |
| 644 | for (av = typelist; *av != NULL; ++av) |
| 645 | if (!strncmp(type, *av, MFSNAMELEN)) |
| 646 | return (which == IN_LIST ? 1 : 0); |
| 647 | return (which == IN_LIST ? 0 : 1); |
| 648 | } |
| 649 | |
| 650 | void |
| 651 | maketypelist(char *fslist) |
| 652 | { |
| 653 | int i; |
| 654 | char *nextcp, **av; |
| 655 | |
| 656 | if ((fslist == NULL) || (fslist[0] == '\0')) |
| 657 | errx(1, "empty type list"); |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | if (fslist[0] == 'n' && fslist[1] == 'o') { |
| 665 | fslist += 2; |
| 666 | which = NOT_IN_LIST; |
| 667 | } else |
| 668 | which = IN_LIST; |
| 669 | |
| 670 | |
| 671 | for (i = 1, nextcp = fslist; (nextcp = strchr(nextcp, ',')); i++) |
| 672 | ++nextcp; |
| 673 | |
| 674 | |
| 675 | if ((av = typelist = reallocarray(NULL, i + 1, sizeof(char *))) == NULL) |
| 676 | err(1, NULL); |
| 677 | av[0] = fslist; |
| 678 | for (i = 1, nextcp = fslist; (nextcp = strchr(nextcp, ',')); i++) { |
| 679 | *nextcp = '\0'; |
| 680 | av[i] = ++nextcp; |
| 681 | } |
| 682 | |
| 683 | av[i] = NULL; |
| 684 | } |
| 685 | |
| 686 | char * |
| 687 | catopt(char *s0, const char *s1) |
| 688 | { |
| 689 | char *cp; |
| 690 | |
| 691 | if (s0 && *s0) { |
| 19 | | Assuming the condition is false | |
|
| |
| 692 | if (asprintf(&cp, "%s,%s", s0, s1) == -1) |
| 693 | err(1, NULL); |
| 694 | } else { |
| 695 | if ((cp = strdup(s1)) == NULL) |
| |
| 22 | | Assuming the condition is false | |
|
| |
| 696 | err(1, NULL); |
| 697 | } |
| 698 | |
| 699 | free(s0); |
| 700 | return cp; |
| 701 | } |
| 702 | |
| 703 | void |
| 704 | mangle(char *options, int *argcp, const char **argv, int argcmax) |
| 705 | { |
| 706 | char *p, *s; |
| 707 | int argc; |
| 708 | |
| 709 | argcmax -= 2; |
| 710 | argc = *argcp; |
| 711 | for (s = options; argc <= argcmax && (p = strsep(&s, ",")) != NULL;) |
| 712 | if (*p != '\0') { |
| 713 | if (*p == '-') { |
| 714 | argv[argc++] = p; |
| 715 | p = strchr(p, '='); |
| 716 | if (p) { |
| 717 | *p = '\0'; |
| 718 | argv[argc++] = p + 1; |
| 719 | } |
| 720 | } else { |
| 721 | argv[argc++] = "-o"; |
| 722 | argv[argc++] = p; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | *argcp = argc; |
| 727 | } |
| 728 | |
| 729 | __dead void |
| 730 | usage(void) |
| 731 | { |
| 732 | (void)fprintf(stderr, |
| 733 | "usage: mount [-AadfNruvw] [-t type]\n" |
| 734 | " mount [-dfrsuvw] special | node\n" |
| 735 | " mount [-dfruvw] [-o options] [-t type] special node\n"); |
| 736 | exit(1); |
| 737 | } |
| 738 | |
| 739 | int |
| 740 | disklabelcheck(struct fstab *fs) |
| 741 | { |
| 742 | char *labelfs; |
| 743 | |
| 744 | if (strcmp(fs->fs_vfstype, "nfs") != 0 || |
| 745 | strpbrk(fs->fs_spec, ":@") == NULL) { |
| 746 | labelfs = readlabelfs(fs->fs_spec, 0); |
| 747 | if (labelfs == NULL || |
| 748 | strcmp(labelfs, fs->fs_vfstype) == 0) |
| 749 | return (0); |
| 750 | if (strcmp(fs->fs_vfstype, "ufs") == 0 && |
| 751 | strcmp(labelfs, "ffs") == 0) { |
| 752 | warnx("%s: fstab uses outdated type 'ufs' -- fix please", |
| 753 | fs->fs_spec); |
| 754 | return (0); |
| 755 | } |
| 756 | if (strcmp(fs->fs_vfstype, "mfs") == 0 && |
| 757 | strcmp(labelfs, "ffs") == 0) |
| 758 | return (0); |
| 759 | warnx("%s: fstab type %s != disklabel type %s", |
| 760 | fs->fs_spec, fs->fs_vfstype, labelfs); |
| 761 | return (1); |
| 762 | } |
| 763 | return (0); |
| 764 | } |