1 /* $NetBSD: mount_fs.c,v 1.2 2013/10/20 03:13:44 christos Exp $ */ 2 3 /* 4 * Copyright (c) 1997-2009 Erez Zadok 5 * Copyright (c) 1990 Jan-Simon Pendry 6 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 7 * Copyright (c) 1990 The Regents of the University of California. 8 * All rights reserved. 9 * 10 * This code is derived from software contributed to Berkeley by 11 * Jan-Simon Pendry at Imperial College, London. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 3. All advertising materials mentioning features or use of this software 22 * must display the following acknowledgment: 23 * This product includes software developed by the University of 24 * California, Berkeley and its contributors. 25 * 4. Neither the name of the University nor the names of its contributors 26 * may be used to endorse or promote products derived from this software 27 * without specific prior written permission. 28 * 29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 * SUCH DAMAGE. 40 * 41 * 42 * File: am-utils/libamu/mount_fs.c 43 * 44 */ 45 46 #ifdef HAVE_CONFIG_H 47 # include <config.h> 48 #endif /* HAVE_CONFIG_H */ 49 #include <am_defs.h> 50 #include <amu.h> 51 52 53 /* ensure that mount table options are delimited by a comma */ 54 #define append_opts(old, l, new) { \ 55 if (*(old) != '\0') \ 56 xstrlcat(old, ",", l); \ 57 xstrlcat(old, new, l); } 58 59 /* 60 * Standard mount flags 61 */ 62 struct opt_tab mnt_flags[] = 63 { 64 #if defined(MNT2_GEN_OPT_RDONLY) && defined(MNTTAB_OPT_RO) 65 {MNTTAB_OPT_RO, MNT2_GEN_OPT_RDONLY}, 66 #endif /* defined(MNT2_GEN_OPT_RDONLY) && defined(MNTTAB_OPT_RO) */ 67 68 #if defined(MNT2_GEN_OPT_NOCACHE) && defined(MNTTAB_OPT_NOCACHE) 69 {MNTTAB_OPT_NOCACHE, MNT2_GEN_OPT_NOCACHE}, 70 #endif /* defined(MNT2_GEN_OPT_NOCACHE) && defined(MNTTAB_OPT_NOCACHE) */ 71 72 /* the "grpid" mount option can be offered as generic of NFS */ 73 #ifdef MNTTAB_OPT_GRPID 74 # ifdef MNT2_GEN_OPT_GRPID 75 {MNTTAB_OPT_GRPID, MNT2_GEN_OPT_GRPID}, 76 # endif /* MNT2_GEN_OPT_GRPID */ 77 # ifdef MNT2_NFS_OPT_GRPID 78 {MNTTAB_OPT_GRPID, MNT2_NFS_OPT_GRPID}, 79 # endif /* MNT2_NFS_OPT_GRPID */ 80 #endif /* MNTTAB_OPT_GRPID */ 81 82 #if defined(MNT2_GEN_OPT_MULTI) && defined(MNTTAB_OPT_MULTI) 83 {MNTTAB_OPT_MULTI, MNT2_GEN_OPT_MULTI}, 84 #endif /* defined(MNT2_GEN_OPT_MULTI) && defined(MNTTAB_OPT_MULTI) */ 85 86 #if defined(MNT2_GEN_OPT_NODEV) && defined(MNTTAB_OPT_NODEV) 87 {MNTTAB_OPT_NODEV, MNT2_GEN_OPT_NODEV}, 88 #endif /* defined(MNT2_GEN_OPT_NODEV) && defined(MNTTAB_OPT_NODEV) */ 89 90 #if defined(MNT2_GEN_OPT_NOEXEC) && defined(MNTTAB_OPT_NOEXEC) 91 {MNTTAB_OPT_NOEXEC, MNT2_GEN_OPT_NOEXEC}, 92 #endif /* defined(MNT2_GEN_OPT_NOEXEC) && defined(MNTTAB_OPT_NOEXEC) */ 93 94 #if defined(MNT2_GEN_OPT_NOSUB) && defined(MNTTAB_OPT_NOSUB) 95 {MNTTAB_OPT_NOSUB, MNT2_GEN_OPT_NOSUB}, 96 #endif /* defined(MNT2_GEN_OPT_NOSUB) && defined(MNTTAB_OPT_NOSUB) */ 97 98 #if defined(MNT2_GEN_OPT_NOSUID) && defined(MNTTAB_OPT_NOSUID) 99 {MNTTAB_OPT_NOSUID, MNT2_GEN_OPT_NOSUID}, 100 #endif /* defined(MNT2_GEN_OPT_NOSUID) && defined(MNTTAB_OPT_NOSUID) */ 101 102 #if defined(MNT2_GEN_OPT_SYNC) && defined(MNTTAB_OPT_SYNC) 103 {MNTTAB_OPT_SYNC, MNT2_GEN_OPT_SYNC}, 104 #endif /* defined(MNT2_GEN_OPT_SYNC) && defined(MNTTAB_OPT_SYNC) */ 105 106 #if defined(MNT2_GEN_OPT_OVERLAY) && defined(MNTTAB_OPT_OVERLAY) 107 {MNTTAB_OPT_OVERLAY, MNT2_GEN_OPT_OVERLAY}, 108 #endif /* defined(MNT2_GEN_OPT_OVERLAY) && defined(MNTTAB_OPT_OVERLAY) */ 109 110 #if defined(MNT2_GEN_OPT_LOG) && defined(MNTTAB_OPT_LOG) 111 {MNTTAB_OPT_LOG, MNT2_GEN_OPT_LOG}, 112 #endif /* defined(MNT2_GEN_OPT_LOG) && defined(MNTTAB_OPT_LOG) */ 113 114 #if defined(MNT2_GEN_OPT_NOATIME) && defined(MNTTAB_OPT_NOATIME) 115 {MNTTAB_OPT_NOATIME, MNT2_GEN_OPT_NOATIME}, 116 #endif /* defined(MNT2_GEN_OPT_NOATIME) && defined(MNTTAB_OPT_NOATIME) */ 117 118 #if defined(MNT2_GEN_OPT_NODEVMTIME) && defined(MNTTAB_OPT_NODEVMTIME) 119 {MNTTAB_OPT_NODEVMTIME, MNT2_GEN_OPT_NODEVMTIME}, 120 #endif /* defined(MNT2_GEN_OPT_NODEVMTIME) && defined(MNTTAB_OPT_NODEVMTIME) */ 121 122 #if defined(MNT2_GEN_OPT_SOFTDEP) && defined(MNTTAB_OPT_SOFTDEP) 123 {MNTTAB_OPT_SOFTDEP, MNT2_GEN_OPT_SOFTDEP}, 124 #endif /* defined(MNT2_GEN_OPT_SOFTDEP) && defined(MNTTAB_OPT_SOFTDEP) */ 125 126 #if defined(MNT2_GEN_OPT_SYMPERM) && defined(MNTTAB_OPT_SYMPERM) 127 {MNTTAB_OPT_SYMPERM, MNT2_GEN_OPT_SYMPERM}, 128 #endif /* defined(MNT2_GEN_OPT_SYMPERM) && defined(MNTTAB_OPT_SYMPERM) */ 129 130 #if defined(MNT2_GEN_OPT_UNION) && defined(MNTTAB_OPT_UNION) 131 {MNTTAB_OPT_UNION, MNT2_GEN_OPT_UNION}, 132 #endif /* defined(MNT2_GEN_OPT_UNION) && defined(MNTTAB_OPT_UNION) */ 133 134 /* 135 * Do not define MNT2_NFS_OPT_* entries here! This is for generic 136 * mount(2) options only, not for NFS mount options. If you need to put 137 * something here, it's probably not the right place: see 138 * include/am_compat.h. 139 */ 140 141 {0, 0} 142 }; 143 144 145 /* compute generic mount flags */ 146 int 147 compute_mount_flags(mntent_t *mntp) 148 { 149 struct opt_tab *opt; 150 int flags = 0; 151 152 #ifdef MNT2_GEN_OPT_NEWTYPE 153 flags |= MNT2_GEN_OPT_NEWTYPE; 154 #endif /* MNT2_GEN_OPT_NEWTYPE */ 155 #ifdef MNT2_GEN_OPT_AUTOMOUNTED 156 flags |= MNT2_GEN_OPT_AUTOMOUNTED; 157 #endif /* not MNT2_GEN_OPT_AUTOMOUNTED */ 158 159 /* 160 * Crack basic mount options 161 */ 162 for (opt = mnt_flags; opt->opt; opt++) { 163 flags |= amu_hasmntopt(mntp, opt->opt) ? opt->flag : 0; 164 } 165 166 return flags; 167 } 168 169 170 /* compute generic mount flags for automounter mounts */ 171 int 172 compute_automounter_mount_flags(mntent_t *mntp) 173 { 174 int flags = 0; 175 176 #ifdef MNT2_GEN_OPT_IGNORE 177 flags |= MNT2_GEN_OPT_IGNORE; 178 #endif /* not MNT2_GEN_OPT_IGNORE */ 179 #ifdef MNT2_GEN_OPT_AUTOMNTFS 180 flags |= MNT2_GEN_OPT_AUTOMNTFS; 181 #endif /* not MNT2_GEN_OPT_AUTOMNTFS */ 182 183 return flags; 184 } 185 186 187 int 188 mount_fs(mntent_t *mnt, int flags, caddr_t mnt_data, int retry, MTYPE_TYPE type, u_long nfs_version, const char *nfs_proto, const char *mnttabname, int on_autofs) 189 { 190 int error = 0; 191 #ifdef MOUNT_TABLE_ON_FILE 192 char *zopts = NULL, *xopts = NULL; 193 size_t l; 194 #endif /* MOUNT_TABLE_ON_FILE */ 195 char *mnt_dir = NULL; 196 197 #ifdef NEED_AUTOFS_SPACE_HACK 198 char *old_mnt_dir = NULL; 199 /* perform space hack */ 200 if (on_autofs) { 201 old_mnt_dir = mnt->mnt_dir; 202 mnt->mnt_dir = mnt_dir = autofs_strdup_space_hack(old_mnt_dir); 203 } else 204 #endif /* NEED_AUTOFS_SPACE_HACK */ 205 mnt_dir = strdup(mnt->mnt_dir); 206 207 dlog("'%s' fstype " MTYPE_PRINTF_TYPE " (%s) flags %#x (%s)", 208 mnt_dir, type, mnt->mnt_type, flags, mnt->mnt_opts); 209 210 again: 211 error = MOUNT_TRAP(type, mnt, flags, mnt_data); 212 213 if (error < 0) { 214 plog(XLOG_ERROR, "'%s': mount: %m", mnt_dir); 215 /* 216 * The following code handles conditions which shouldn't 217 * occur. They are possible either because amd screws up 218 * in preparing for the mount, or because some human 219 * messed with the mount point. Both have been known to 220 * happen. -- stolcke 2/22/95 221 */ 222 if (errno == EBUSY) { 223 /* 224 * Also, sometimes unmount isn't called, e.g., because 225 * our mountlist is garbled. This leaves old mount 226 * points around which need to be removed before we 227 * can mount something new in their place. 228 */ 229 errno = umount_fs(mnt_dir, mnttabname, on_autofs); 230 if (errno != 0) 231 plog(XLOG_ERROR, "'%s': umount: %m", mnt_dir); 232 else { 233 plog(XLOG_WARNING, "extra umount required for '%s'", mnt_dir); 234 error = MOUNT_TRAP(type, mnt, flags, mnt_data); 235 } 236 } 237 } 238 239 if (error < 0 && --retry > 0) { 240 sleep(1); 241 goto again; 242 } 243 244 #ifdef NEED_AUTOFS_SPACE_HACK 245 /* Undo space hack */ 246 if (on_autofs) 247 mnt->mnt_dir = old_mnt_dir; 248 #endif /* NEED_AUTOFS_SPACE_HACK */ 249 250 if (error < 0) { 251 error = errno; 252 goto out; 253 } 254 255 #ifdef MOUNT_TABLE_ON_FILE 256 /* 257 * Allocate memory for options: 258 * dev=..., vers={2,3}, proto={tcp,udp} 259 */ 260 l = strlen(mnt->mnt_opts) + 48; 261 zopts = (char *) xmalloc(l); 262 263 /* copy standard options */ 264 xopts = mnt->mnt_opts; 265 266 xstrlcpy(zopts, xopts, l); 267 268 # ifdef MNTTAB_OPT_DEV 269 { 270 /* add the extra dev= field to the mount table */ 271 struct stat stb; 272 if (lstat(mnt_dir, &stb) == 0) { 273 char optsbuf[48]; 274 if (sizeof(stb.st_dev) == 2) /* e.g. SunOS 4.1 */ 275 xsnprintf(optsbuf, sizeof(optsbuf), "%s=%04lx", 276 MNTTAB_OPT_DEV, (u_long) stb.st_dev & 0xffff); 277 else /* e.g. System Vr4 */ 278 xsnprintf(optsbuf, sizeof(optsbuf), "%s=%08lx", 279 MNTTAB_OPT_DEV, (u_long) stb.st_dev); 280 append_opts(zopts, l, optsbuf); 281 } 282 } 283 # endif /* MNTTAB_OPT_DEV */ 284 285 # if defined(HAVE_FS_NFS3) && defined(MNTTAB_OPT_VERS) 286 /* 287 * add the extra vers={2,3} field to the mount table, 288 * unless already specified by user 289 */ 290 if (nfs_version == NFS_VERSION3 && 291 hasmntval(mnt, MNTTAB_OPT_VERS) != NFS_VERSION3) { 292 char optsbuf[48]; 293 xsnprintf(optsbuf, sizeof(optsbuf), 294 "%s=%d", MNTTAB_OPT_VERS, NFS_VERSION3); 295 append_opts(zopts, l, optsbuf); 296 } 297 # endif /* defined(HAVE_FS_NFS3) && defined(MNTTAB_OPT_VERS) */ 298 299 # ifdef MNTTAB_OPT_PROTO 300 /* 301 * add the extra proto={tcp,udp} field to the mount table, 302 * unless already specified by user. 303 */ 304 if (nfs_proto && !amu_hasmntopt(mnt, MNTTAB_OPT_PROTO)) { 305 char optsbuf[48]; 306 xsnprintf(optsbuf, sizeof(optsbuf), "%s=%s", MNTTAB_OPT_PROTO, nfs_proto); 307 append_opts(zopts, l, optsbuf); 308 } 309 # endif /* MNTTAB_OPT_PROTO */ 310 311 /* finally, store the options into the mount table structure */ 312 mnt->mnt_opts = zopts; 313 314 /* 315 * Additional fields in mntent_t 316 * are fixed up here 317 */ 318 # ifdef HAVE_MNTENT_T_MNT_CNODE 319 mnt->mnt_cnode = 0; 320 # endif /* HAVE_MNTENT_T_MNT_CNODE */ 321 322 # ifdef HAVE_MNTENT_T_MNT_RO 323 mnt->mnt_ro = (amu_hasmntopt(mnt, MNTTAB_OPT_RO) != NULL); 324 # endif /* HAVE_MNTENT_T_MNT_RO */ 325 326 # ifdef HAVE_MNTENT_T_MNT_TIME 327 # ifdef HAVE_MNTENT_T_MNT_TIME_STRING 328 { /* allocate enough space for a long */ 329 size_t l = 13 * sizeof(char); 330 char *str = (char *) xmalloc(l); 331 xsnprintf(str, l, "%ld", time((time_t *) NULL)); 332 mnt->mnt_time = str; 333 } 334 # else /* not HAVE_MNTENT_T_MNT_TIME_STRING */ 335 mnt->mnt_time = time((time_t *) NULL); 336 # endif /* not HAVE_MNTENT_T_MNT_TIME_STRING */ 337 # endif /* HAVE_MNTENT_T_MNT_TIME */ 338 339 write_mntent(mnt, mnttabname); 340 341 # ifdef MNTTAB_OPT_DEV 342 if (xopts) { 343 XFREE(mnt->mnt_opts); 344 mnt->mnt_opts = xopts; 345 } 346 # endif /* MNTTAB_OPT_DEV */ 347 #endif /* MOUNT_TABLE_ON_FILE */ 348 349 out: 350 XFREE(mnt_dir); 351 return error; 352 } 353 354 355 /* 356 * Compute all NFS attribute cache related flags separately. Note that this 357 * function now computes attribute-cache flags for both Amd's automount 358 * points (NFS) as well as any normal NFS mount that Amd performs. Edit 359 * with caution. 360 */ 361 static void 362 compute_nfs_attrcache_flags(nfs_args_t *nap, mntent_t *mntp) 363 { 364 int acval = 0; 365 int err_acval = 1; /* 1 means we found no 'actimeo' value */ 366 #if defined(HAVE_NFS_ARGS_T_ACREGMIN) || defined(HAVE_NFS_ARGS_T_ACREGMAX) || defined(HAVE_NFS_ARGS_T_ACDIRMIN) || defined(HAVE_NFS_ARGS_T_ACDIRMAX) 367 int err_acrdmm; /* for ac{reg,dir}{min,max} */ 368 #endif /* HAVE_NFS_ARGS_T_AC{REG,DIR}{MIN,MAX} */ 369 370 /************************************************************************/ 371 /*** ATTRIBUTE CACHES ***/ 372 /************************************************************************/ 373 /* 374 * acval is set to 0 at the top of the function. If actimeo mount option 375 * exists and defined in mntopts, then its acval is set to it. 376 * If the value is non-zero, then we set all attribute cache fields to it. 377 * If acval is zero, it means it was never defined in mntopts or the 378 * actimeo mount option does not exist, in which case we check for 379 * individual mount options per attribute cache. 380 * Regardless of the value of acval, mount flags are set based directly 381 * on the values of the attribute caches. 382 */ 383 #ifdef MNTTAB_OPT_ACTIMEO 384 err_acval = hasmntvalerr(mntp, MNTTAB_OPT_ACTIMEO, &acval); /* attr cache timeout (sec) */ 385 #endif /* MNTTAB_OPT_ACTIMEO */ 386 387 /*** acregmin ***/ 388 #ifdef HAVE_NFS_ARGS_T_ACREGMIN 389 err_acrdmm = 1; /* 1 means we found no acregmin value */ 390 if (!err_acval) { 391 nap->acregmin = acval; /* min ac timeout for reg files (sec) */ 392 } else { 393 # ifdef MNTTAB_OPT_ACREGMIN 394 err_acrdmm = hasmntvalerr(mntp, MNTTAB_OPT_ACREGMIN, (int *) &nap->acregmin); 395 # else /* not MNTTAB_OPT_ACREGMIN */ 396 nap->acregmin = 0; 397 # endif /* not MNTTAB_OPT_ACREGMIN */ 398 } 399 /* set this flag iff we changed acregmin (possibly to zero) */ 400 # ifdef MNT2_NFS_OPT_ACREGMIN 401 if (!err_acval || !err_acrdmm) 402 nap->flags |= MNT2_NFS_OPT_ACREGMIN; 403 # endif /* MNT2_NFS_OPT_ACREGMIN */ 404 #endif /* HAVE_NFS_ARGS_T_ACREGMIN */ 405 406 /*** acregmax ***/ 407 #ifdef HAVE_NFS_ARGS_T_ACREGMAX 408 err_acrdmm = 1; /* 1 means we found no acregmax value */ 409 if (!err_acval) { 410 nap->acregmax = acval; /* max ac timeout for reg files (sec) */ 411 } else { 412 # ifdef MNTTAB_OPT_ACREGMAX 413 err_acrdmm = hasmntvalerr(mntp, MNTTAB_OPT_ACREGMAX, (int *) &nap->acregmax); 414 # else /* not MNTTAB_OPT_ACREGMAX */ 415 nap->acregmax = 0; 416 # endif /* not MNTTAB_OPT_ACREGMAX */ 417 } 418 /* set this flag iff we changed acregmax (possibly to zero) */ 419 # ifdef MNT2_NFS_OPT_ACREGMAX 420 if (!err_acval || !err_acrdmm) 421 nap->flags |= MNT2_NFS_OPT_ACREGMAX; 422 # endif /* MNT2_NFS_OPT_ACREGMAX */ 423 #endif /* HAVE_NFS_ARGS_T_ACREGMAX */ 424 425 /*** acdirmin ***/ 426 #ifdef HAVE_NFS_ARGS_T_ACDIRMIN 427 err_acrdmm = 1; /* 1 means we found no acdirmin value */ 428 if (!err_acval) { 429 nap->acdirmin = acval; /* min ac timeout for dirs (sec) */ 430 } else { 431 # ifdef MNTTAB_OPT_ACDIRMIN 432 err_acrdmm = hasmntvalerr(mntp, MNTTAB_OPT_ACDIRMIN, (int *) &nap->acdirmin); 433 # else /* not MNTTAB_OPT_ACDIRMIN */ 434 nap->acdirmin = 0; 435 # endif /* not MNTTAB_OPT_ACDIRMIN */ 436 } 437 /* set this flag iff we changed acdirmin (possibly to zero) */ 438 # ifdef MNT2_NFS_OPT_ACDIRMIN 439 if (!err_acval || !err_acrdmm) 440 nap->flags |= MNT2_NFS_OPT_ACDIRMIN; 441 # endif /* MNT2_NFS_OPT_ACDIRMIN */ 442 #endif /* HAVE_NFS_ARGS_T_ACDIRMIN */ 443 444 /*** acdirmax ***/ 445 #ifdef HAVE_NFS_ARGS_T_ACDIRMAX 446 err_acrdmm = 1; /* 1 means we found no acdirmax value */ 447 if (!err_acval) { 448 nap->acdirmax = acval; /* max ac timeout for dirs (sec) */ 449 } else { 450 # ifdef MNTTAB_OPT_ACDIRMAX 451 err_acrdmm = hasmntvalerr(mntp, MNTTAB_OPT_ACDIRMAX, (int *) &nap->acdirmax); 452 # else /* not MNTTAB_OPT_ACDIRMAX */ 453 nap->acdirmax = 0; 454 # endif /* not MNTTAB_OPT_ACDIRMAX */ 455 } 456 /* set this flag iff we changed acdirmax (possibly to zero) */ 457 # ifdef MNT2_NFS_OPT_ACDIRMAX 458 if (!err_acval || !err_acrdmm) 459 nap->flags |= MNT2_NFS_OPT_ACDIRMAX; 460 # endif /* MNT2_NFS_OPT_ACDIRMAX */ 461 #endif /* HAVE_NFS_ARGS_T_ACDIRMAX */ 462 463 464 /* don't cache attributes */ 465 #if defined(MNTTAB_OPT_NOAC) && defined(MNT2_NFS_OPT_NOAC) 466 if (amu_hasmntopt(mntp, MNTTAB_OPT_NOAC) != NULL) 467 nap->flags |= MNT2_NFS_OPT_NOAC; 468 #endif /* defined(MNTTAB_OPT_NOAC) && defined(MNT2_NFS_OPT_NOAC) */ 469 (void)err_acval; 470 } 471 472 473 /* 474 * Fill in the many possible fields and flags of struct nfs_args. 475 * 476 * nap: pre-allocated structure to fill in. 477 * mntp: mount entry structure (includes options) 478 * genflags: generic mount flags already determined 479 * nfsncp: (TLI only) netconfig entry for this NFS mount 480 * ip_addr: IP address of file server 481 * nfs_version: 2, 3, (4 in the future), or 0 if unknown 482 * nfs_proto: "udp", "tcp", or NULL. 483 * fhp: file handle structure pointer 484 * host_name: name of remote NFS host 485 * fs_name: remote file system name to mount 486 */ 487 void 488 compute_nfs_args(nfs_args_t *nap, 489 mntent_t *mntp, 490 int genflags, 491 struct netconfig *nfsncp, 492 struct sockaddr_in *ip_addr, 493 u_long nfs_version, 494 char *nfs_proto, 495 am_nfs_handle_t *fhp, 496 char *host_name, 497 char *fs_name) 498 { 499 /* initialize just in case */ 500 memset((voidp) nap, 0, sizeof(nfs_args_t)); 501 502 /* compute all of the NFS attribute-cache flags */ 503 compute_nfs_attrcache_flags(nap, mntp); 504 505 /************************************************************************/ 506 /*** FILEHANDLE DATA AND LENGTH ***/ 507 /************************************************************************/ 508 #ifdef HAVE_FS_NFS3 509 if (nfs_version == NFS_VERSION3) { 510 # if defined(HAVE_NFS_ARGS_T_FHSIZE) || defined(HAVE_NFS_ARGS_T_FH_LEN) 511 /* 512 * Some systems (Irix/bsdi3) have a separate field in nfs_args for 513 * the length of the file handle for NFS V3. They insist that 514 * the file handle set in nfs_args be plain bytes, and not 515 * include the length field. 516 */ 517 NFS_FH_DREF(nap->NFS_FH_FIELD, &fhp->v3.am_fh3_data); 518 # else /* not defined(HAVE_NFS_ARGS_T_FHSIZE) || defined(HAVE_NFS_ARGS_T_FH_LEN) */ 519 NFS_FH_DREF(nap->NFS_FH_FIELD, &fhp->v3); 520 # endif /* not defined(HAVE_NFS_ARGS_T_FHSIZE) || defined(HAVE_NFS_ARGS_T_FH_LEN) */ 521 # ifdef MNT2_NFS_OPT_NFSV3 522 nap->flags |= MNT2_NFS_OPT_NFSV3; 523 # endif /* MNT2_NFS_OPT_NFSV3 */ 524 # ifdef MNT2_NFS_OPT_VER3 525 nap->flags |= MNT2_NFS_OPT_VER3; 526 # endif /* MNT2_NFS_OPT_VER3 */ 527 } else 528 #endif /* HAVE_FS_NFS3 */ 529 NFS_FH_DREF(nap->NFS_FH_FIELD, &fhp->v2); 530 531 #ifdef HAVE_NFS_ARGS_T_FHSIZE 532 # ifdef HAVE_FS_NFS3 533 if (nfs_version == NFS_VERSION3) 534 nap->fhsize = fhp->v3.am_fh3_length; 535 else 536 # endif /* HAVE_FS_NFS3 */ 537 nap->fhsize = FHSIZE; 538 #endif /* HAVE_NFS_ARGS_T_FHSIZE */ 539 540 /* this is the version of the nfs_args structure, not of NFS! */ 541 #ifdef HAVE_NFS_ARGS_T_FH_LEN 542 # ifdef HAVE_FS_NFS3 543 if (nfs_version == NFS_VERSION3) 544 nap->fh_len = fhp->v3.am_fh3_length; 545 else 546 # endif /* HAVE_FS_NFS3 */ 547 nap->fh_len = FHSIZE; 548 #endif /* HAVE_NFS_ARGS_T_FH_LEN */ 549 550 /************************************************************************/ 551 /*** HOST NAME ***/ 552 /************************************************************************/ 553 /* 554 * XXX: warning, using xstrlcpy in NFS_HN_DREF, which may corrupt a 555 * struct nfs_args, or truncate our concocted "hostname:/path" 556 * string prematurely. 557 */ 558 NFS_HN_DREF(nap->hostname, host_name); 559 #ifdef MNT2_NFS_OPT_HOSTNAME 560 nap->flags |= MNT2_NFS_OPT_HOSTNAME; 561 #endif /* MNT2_NFS_OPT_HOSTNAME */ 562 563 /************************************************************************/ 564 /*** IP ADDRESS OF REMOTE HOST ***/ 565 /************************************************************************/ 566 if (ip_addr) { 567 #ifdef HAVE_TRANSPORT_TYPE_TLI 568 nap->addr = ALLOC(struct netbuf); /* free()'ed at end of mount_nfs_fh() */ 569 #endif /* HAVE_TRANSPORT_TYPE_TLI */ 570 NFS_SA_DREF(nap, ip_addr); 571 } 572 573 /************************************************************************/ 574 /*** NFS PROTOCOL (UDP, TCP) AND VERSION ***/ 575 /************************************************************************/ 576 #ifdef MNT2_NFS_OPT_TCP 577 if (nfs_proto && STREQ(nfs_proto, "tcp")) 578 nap->flags |= MNT2_NFS_OPT_TCP; 579 #endif /* MNT2_NFS_OPT_TCP */ 580 581 #ifdef HAVE_NFS_ARGS_T_SOTYPE 582 /* bsdi3 uses this */ 583 if (nfs_proto) { 584 if (STREQ(nfs_proto, "tcp")) 585 nap->sotype = SOCK_STREAM; 586 else if (STREQ(nfs_proto, "udp")) 587 nap->sotype = SOCK_DGRAM; 588 } 589 #endif /* HAVE_NFS_ARGS_T_SOTYPE */ 590 591 #ifdef HAVE_NFS_ARGS_T_PROTO 592 nap->proto = 0; /* bsdi3 sets this field to zero */ 593 # ifdef IPPROTO_TCP 594 if (nfs_proto) { 595 if (STREQ(nfs_proto, "tcp")) /* AIX 4.2.x needs this */ 596 nap->proto = IPPROTO_TCP; 597 else if (STREQ(nfs_proto, "udp")) 598 nap->proto = IPPROTO_UDP; 599 } 600 # endif /* IPPROTO_TCP */ 601 #endif /* HAVE_NFS_ARGS_T_SOTYPE */ 602 603 #ifdef HAVE_NFS_ARGS_T_VERSION 604 # ifdef NFS_ARGSVERSION 605 nap->version = NFS_ARGSVERSION; /* BSDI 3.0 and OpenBSD 2.2 */ 606 # endif /* NFS_ARGSVERSION */ 607 # ifdef DG_MOUNT_NFS_VERSION 608 nap->version = DG_MOUNT_NFS_VERSION; /* dg-ux */ 609 # endif /* DG_MOUNT_NFS_VERSION */ 610 #endif /* HAVE_NFS_ARGS_VERSION */ 611 612 /************************************************************************/ 613 /*** OTHER NFS SOCKET RELATED OPTIONS AND FLAGS ***/ 614 /************************************************************************/ 615 #ifdef MNT2_NFS_OPT_NOCONN 616 /* check if user specified to use unconnected or connected sockets */ 617 if (amu_hasmntopt(mntp, MNTTAB_OPT_NOCONN) != NULL) 618 nap->flags |= MNT2_NFS_OPT_NOCONN; 619 else if (amu_hasmntopt(mntp, MNTTAB_OPT_CONN) != NULL) 620 nap->flags &= ~MNT2_NFS_OPT_NOCONN; 621 else { 622 /* 623 * Some OSs want you to set noconn always. Some want you to always turn 624 * it off. Others want you to turn it on/off only if NFS V.3 is used. 625 * And all of that changes from revision to another. This is 626 * particularly true of OpenBSD, NetBSD, and FreeBSD. So, rather than 627 * attempt to auto-detect this, I'm forced to "fix" it in the individual 628 * conf/nfs_prot/nfs_prot_*.h files. 629 */ 630 # ifdef USE_UNCONNECTED_NFS_SOCKETS 631 if (!(nap->flags & MNT2_NFS_OPT_NOCONN)) { 632 nap->flags |= MNT2_NFS_OPT_NOCONN; 633 plog(XLOG_WARNING, "noconn option not specified, and was just turned ON (OS override)! (May cause NFS hangs on some systems...)"); 634 } 635 # endif /* USE_UNCONNECTED_NFS_SOCKETS */ 636 # ifdef USE_CONNECTED_NFS_SOCKETS 637 if (nap->flags & MNT2_NFS_OPT_NOCONN) { 638 nap->flags &= ~MNT2_NFS_OPT_NOCONN; 639 plog(XLOG_WARNING, "noconn option specified, and was just turned OFF (OS override)! (May cause NFS hangs on some systems...)"); 640 } 641 # endif /* USE_CONNECTED_NFS_SOCKETS */ 642 } 643 #endif /* MNT2_NFS_OPT_NOCONN */ 644 645 #ifdef MNT2_NFS_OPT_RESVPORT 646 # ifdef MNTTAB_OPT_RESVPORT 647 if (amu_hasmntopt(mntp, MNTTAB_OPT_RESVPORT) != NULL) 648 nap->flags |= MNT2_NFS_OPT_RESVPORT; 649 # else /* not MNTTAB_OPT_RESVPORT */ 650 nap->flags |= MNT2_NFS_OPT_RESVPORT; 651 # endif /* not MNTTAB_OPT_RESVPORT */ 652 #endif /* MNT2_NFS_OPT_RESVPORT */ 653 654 /************************************************************************/ 655 /*** OTHER FLAGS AND OPTIONS ***/ 656 /************************************************************************/ 657 658 #ifdef HAVE_TRANSPORT_TYPE_TLI 659 /* set up syncaddr field */ 660 nap->syncaddr = (struct netbuf *) NULL; 661 662 /* set up knconf field */ 663 if (get_knetconfig(&nap->knconf, nfsncp, nfs_proto) < 0) { 664 plog(XLOG_FATAL, "cannot fill knetconfig structure for nfs_args"); 665 going_down(1); 666 } 667 /* update the flags field for knconf */ 668 nap->flags |= MNT2_NFS_OPT_KNCONF; 669 #endif /* HAVE_TRANSPORT_TYPE_TLI */ 670 671 #ifdef MNT2_NFS_OPT_FSNAME 672 nap->fsname = fs_name; 673 nap->flags |= MNT2_NFS_OPT_FSNAME; 674 #endif /* MNT2_NFS_OPT_FSNAME */ 675 676 nap->rsize = hasmntval(mntp, MNTTAB_OPT_RSIZE); 677 #ifdef MNT2_NFS_OPT_RSIZE 678 if (nap->rsize) 679 nap->flags |= MNT2_NFS_OPT_RSIZE; 680 #endif /* MNT2_NFS_OPT_RSIZE */ 681 if (nfs_version == NFS_VERSION && nap->rsize > 8192) 682 nap->rsize = 8192; 683 684 nap->wsize = hasmntval(mntp, MNTTAB_OPT_WSIZE); 685 #ifdef MNT2_NFS_OPT_WSIZE 686 if (nap->wsize) 687 nap->flags |= MNT2_NFS_OPT_WSIZE; 688 #endif /* MNT2_NFS_OPT_WSIZE */ 689 if (nfs_version == NFS_VERSION && nap->wsize > 8192) 690 nap->wsize = 8192; 691 692 nap->timeo = hasmntval(mntp, MNTTAB_OPT_TIMEO); 693 #ifdef MNT2_NFS_OPT_TIMEO 694 if (nap->timeo) 695 nap->flags |= MNT2_NFS_OPT_TIMEO; 696 #endif /* MNT2_NFS_OPT_TIMEO */ 697 698 nap->retrans = hasmntval(mntp, MNTTAB_OPT_RETRANS); 699 #ifdef MNT2_NFS_OPT_RETRANS 700 if (nap->retrans) 701 nap->flags |= MNT2_NFS_OPT_RETRANS; 702 #endif /* MNT2_NFS_OPT_RETRANS */ 703 704 #ifdef MNT2_NFS_OPT_BIODS 705 if ((nap->biods = hasmntval(mntp, MNTTAB_OPT_BIODS))) 706 nap->flags |= MNT2_NFS_OPT_BIODS; 707 #endif /* MNT2_NFS_OPT_BIODS */ 708 709 #ifdef MNT2_NFS_OPT_SOFT 710 if (amu_hasmntopt(mntp, MNTTAB_OPT_SOFT) != NULL) 711 nap->flags |= MNT2_NFS_OPT_SOFT; 712 #endif /* MNT2_NFS_OPT_SOFT */ 713 714 #ifdef MNT2_NFS_OPT_SPONGY 715 if (amu_hasmntopt(mntp, MNTTAB_OPT_SPONGY) != NULL) { 716 nap->flags |= MNT2_NFS_OPT_SPONGY; 717 if (nap->flags & MNT2_NFS_OPT_SOFT) { 718 plog(XLOG_USER, "Mount opts soft and spongy are incompatible - soft ignored"); 719 nap->flags &= ~MNT2_NFS_OPT_SOFT; 720 } 721 } 722 #endif /* MNT2_NFS_OPT_SPONGY */ 723 724 #if defined(MNT2_GEN_OPT_RONLY) && defined(MNT2_NFS_OPT_RONLY) 725 /* Ultrix has separate generic and NFS ro flags */ 726 if (genflags & MNT2_GEN_OPT_RONLY) 727 nap->flags |= MNT2_NFS_OPT_RONLY; 728 #endif /* defined(MNT2_GEN_OPT_RONLY) && defined(MNT2_NFS_OPT_RONLY) */ 729 730 #ifdef MNTTAB_OPT_INTR 731 if (amu_hasmntopt(mntp, MNTTAB_OPT_INTR) != NULL) 732 /* 733 * Either turn on the "allow interrupts" option, or 734 * turn off the "disallow interrupts" option" 735 */ 736 # ifdef MNT2_NFS_OPT_INTR 737 nap->flags |= MNT2_NFS_OPT_INTR; 738 # endif /* MNT2_NFS_OPT_INTR */ 739 # ifdef MNT2_NFS_OPT_NOINTR 740 nap->flags &= ~MNT2_NFS_OPT_NOINTR; 741 # endif /* MNT2_NFS_OPT_NOINTR */ 742 # ifdef MNT2_NFS_OPT_INT 743 nap->flags |= MNT2_NFS_OPT_INT; 744 # endif /* MNT2_NFS_OPT_INT */ 745 # ifdef MNT2_NFS_OPT_NOINT 746 nap->flags &= ~MNT2_NFS_OPT_NOINT; 747 # endif /* MNT2_NFS_OPT_NOINT */ 748 #endif /* MNTTAB_OPT_INTR */ 749 750 #ifdef MNTTAB_OPT_NODEVS 751 if (amu_hasmntopt(mntp, MNTTAB_OPT_NODEVS) != NULL) 752 nap->flags |= MNT2_NFS_OPT_NODEVS; 753 #endif /* MNTTAB_OPT_NODEVS */ 754 755 #ifdef MNTTAB_OPT_COMPRESS 756 if (amu_hasmntopt(mntp, MNTTAB_OPT_COMPRESS) != NULL) 757 nap->flags |= MNT2_NFS_OPT_COMPRESS; 758 #endif /* MNTTAB_OPT_COMPRESS */ 759 760 #ifdef MNTTAB_OPT_PRIVATE /* mount private, single-client tree */ 761 if (amu_hasmntopt(mntp, MNTTAB_OPT_PRIVATE) != NULL) 762 nap->flags |= MNT2_NFS_OPT_PRIVATE; 763 #endif /* MNTTAB_OPT_PRIVATE */ 764 765 #ifdef MNTTAB_OPT_SYMTTL /* symlink cache time-to-live */ 766 if ((nap->symttl = hasmntval(mntp, MNTTAB_OPT_SYMTTL))) 767 nap->flags |= MNT2_NFS_OPT_SYMTTL; 768 #endif /* MNTTAB_OPT_SYMTTL */ 769 770 #ifdef MNT2_NFS_OPT_PGTHRESH /* paging threshold */ 771 if ((nap->pg_thresh = hasmntval(mntp, MNTTAB_OPT_PGTHRESH))) 772 nap->flags |= MNT2_NFS_OPT_PGTHRESH; 773 #endif /* MNT2_NFS_OPT_PGTHRESH */ 774 775 #if defined(MNT2_NFS_OPT_NOCTO) && defined(MNTTAB_OPT_NOCTO) 776 if (amu_hasmntopt(mntp, MNTTAB_OPT_NOCTO) != NULL) 777 nap->flags |= MNT2_NFS_OPT_NOCTO; 778 #endif /* defined(MNT2_NFS_OPT_NOCTO) && defined(MNTTAB_OPT_NOCTO) */ 779 780 #if defined(MNT2_NFS_OPT_POSIX) && defined(MNTTAB_OPT_POSIX) 781 if (amu_hasmntopt(mntp, MNTTAB_OPT_POSIX) != NULL) { 782 nap->flags |= MNT2_NFS_OPT_POSIX; 783 # ifdef HAVE_NFS_ARGS_T_PATHCONF 784 nap->pathconf = NULL; 785 # endif /* HAVE_NFS_ARGS_T_PATHCONF */ 786 } 787 #endif /* MNT2_NFS_OPT_POSIX && MNTTAB_OPT_POSIX */ 788 789 #if defined(MNT2_NFS_OPT_PROPLIST) && defined(MNTTAB_OPT_PROPLIST) 790 if (amu_hasmntopt(mntp, MNTTAB_OPT_PROPLIST) != NULL) 791 nap->flags |= MNT2_NFS_OPT_PROPLIST; 792 #endif /* defined(MNT2_NFS_OPT_PROPLIST) && defined(MNTTAB_OPT_PROPLIST) */ 793 794 #if defined(MNT2_NFS_OPT_MAXGRPS) && defined(MNTTAB_OPT_MAXGROUPS) 795 nap->maxgrouplist = hasmntval(mntp, MNTTAB_OPT_MAXGROUPS); 796 if (nap->maxgrouplist != 0) 797 nap->flags |= MNT2_NFS_OPT_MAXGRPS; 798 #endif /* defined(MNT2_NFS_OPT_MAXGRPS) && defined(MNTTAB_OPT_MAXGROUPS) */ 799 800 #if defined(MNT2_NFS_OPT_NONLM) && defined(MNTTAB_OPT_NOLOCK) 801 if (amu_hasmntopt(mntp, MNTTAB_OPT_NOLOCK) != NULL) 802 nap->flags |= MNT2_NFS_OPT_NONLM; 803 #endif /* defined(MNT2_NFS_OPT_NONLM) && defined(MNTTAB_OPT_NOLOCK) */ 804 805 #if defined(MNT2_NFS_OPT_XLATECOOKIE) && defined(MNTTAB_OPT_XLATECOOKIE) 806 if (amu_hasmntopt(mntp, MNTTAB_OPT_XLATECOOKIE) != NULL) 807 nap->flags |= MNT2_NFS_OPT_XLATECOOKIE; 808 #endif /* defined(MNT2_NFS_OPT_XLATECOOKIE) && defined(MNTTAB_OPT_XLATECOOKIE) */ 809 810 #ifdef HAVE_NFS_ARGS_T_OPTSTR 811 nap->optstr = mntp->mnt_opts; 812 #endif /* HAVE_NFS_ARGS_T_OPTSTR */ 813 814 /************************************************************************/ 815 /*** FINAL ACTIONS ***/ 816 /************************************************************************/ 817 818 #ifdef HAVE_NFS_ARGS_T_GFS_FLAGS 819 /* Ultrix stores generic flags in nfs_args.gfs_flags. */ 820 nap->gfs_flags = genflags; 821 #endif /* HAVE_NFS_ARGS_T_FLAGS */ 822 823 return; /* end of compute_nfs_args() function */ 824 } 825 826 827 /* 828 * Fill in special values for flags and fields of nfs_args, for an 829 * automounter NFS mount. 830 */ 831 void 832 compute_automounter_nfs_args(nfs_args_t *nap, mntent_t *mntp) 833 { 834 #ifdef MNT2_NFS_OPT_SYMTTL 835 /* 836 * Don't let the kernel cache symbolic links we generate, or else lookups 837 * will bypass amd and fail to remount stuff as needed. 838 */ 839 plog(XLOG_INFO, "turning on NFS option symttl and setting value to 0"); 840 nap->flags |= MNT2_NFS_OPT_SYMTTL; 841 nap->symttl = 0; 842 #endif /* MNT2_NFS_OPT_SYMTTL */ 843 844 /* 845 * This completes the flags for the HIDE_MOUNT_TYPE code in the 846 * mount_amfs_toplvl() function in amd/amfs_toplvl.c. 847 * Some systems don't have a mount type, but a mount flag. 848 */ 849 #ifdef MNT2_NFS_OPT_AUTO 850 nap->flags |= MNT2_NFS_OPT_AUTO; 851 #endif /* MNT2_NFS_OPT_AUTO */ 852 #ifdef MNT2_NFS_OPT_IGNORE 853 nap->flags |= MNT2_NFS_OPT_IGNORE; 854 #endif /* MNT2_NFS_OPT_IGNORE */ 855 #ifdef MNT2_GEN_OPT_AUTOMNTFS 856 nap->flags |= MNT2_GEN_OPT_AUTOMNTFS; 857 #endif /* not MNT2_GEN_OPT_AUTOMNTFS */ 858 859 #ifdef MNT2_NFS_OPT_DUMBTIMR 860 /* 861 * Don't let the kernel start computing throughput of Amd. The numbers 862 * will be meaningless because of the way Amd does mount retries. 863 */ 864 plog(XLOG_INFO, "%s: disabling nfs congestion window", mntp->mnt_dir); 865 nap->flags |= MNT2_NFS_OPT_DUMBTIMR; 866 #endif /* MNT2_NFS_OPT_DUMBTIMR */ 867 868 /* compute all of the NFS attribute-cache flags */ 869 compute_nfs_attrcache_flags(nap, mntp); 870 871 /* 872 * Provide a slight bit more security by requiring the kernel to use 873 * reserved ports. 874 */ 875 #ifdef MNT2_NFS_OPT_RESVPORT 876 nap->flags |= MNT2_NFS_OPT_RESVPORT; 877 #endif /* MNT2_NFS_OPT_RESVPORT */ 878 } 879 880 881 #ifdef DEBUG 882 /* get string version (in hex) of identifier */ 883 static char * 884 get_hex_string(u_int len, const char *fhdata) 885 { 886 u_int i; 887 static char buf[128]; /* better not go over it! */ 888 char str[16]; 889 short int arr[64]; 890 891 if (!fhdata) 892 return NULL; 893 buf[0] = '\0'; 894 memset(&arr[0], 0, (64 * sizeof(short int))); 895 memcpy(&arr[0], &fhdata[0], len); 896 for (i=0; i<len/sizeof(unsigned short int); i++) { 897 xsnprintf(str, sizeof(str), "%04x", ntohs(arr[i])); 898 xstrlcat(buf, str, sizeof(buf)); 899 } 900 return buf; 901 } 902 903 904 /* 905 * print a subset of fields from "struct nfs_args" that are otherwise 906 * not being provided anywhere else. 907 */ 908 void 909 print_nfs_args(const nfs_args_t *nap, u_long nfs_version) 910 { 911 int fhlen = 32; /* default: NFS V.2 file handle length is 32 */ 912 #ifdef HAVE_TRANSPORT_TYPE_TLI 913 struct netbuf *nbp; 914 struct knetconfig *kncp; 915 #else /* not HAVE_TRANSPORT_TYPE_TLI */ 916 struct sockaddr_in *sap; 917 #endif /* not HAVE_TRANSPORT_TYPE_TLI */ 918 919 if (!nap) { 920 plog(XLOG_DEBUG, "NULL nfs_args!"); 921 return; 922 } 923 924 /* override default file handle size */ 925 #ifdef FHSIZE 926 fhlen = FHSIZE; 927 #endif /* FHSIZE */ 928 #ifdef NFS_FHSIZE 929 fhlen = NFS_FHSIZE; 930 #endif /* NFS_FHSIZE */ 931 932 #ifdef HAVE_TRANSPORT_TYPE_TLI 933 nbp = nap->addr; 934 plog(XLOG_DEBUG, "NA->addr {netbuf} (maxlen=%d, len=%d) = \"%s\"", 935 nbp->maxlen, nbp->len, 936 get_hex_string(nbp->len, nbp->buf)); 937 nbp = nap->syncaddr; 938 plog(XLOG_DEBUG, "NA->syncaddr {netbuf} %p", nbp); 939 kncp = nap->knconf; 940 plog(XLOG_DEBUG, "NA->knconf->semantics %lu", (u_long) kncp->knc_semantics); 941 plog(XLOG_DEBUG, "NA->knconf->protofmly \"%s\"", kncp->knc_protofmly); 942 plog(XLOG_DEBUG, "NA->knconf->proto \"%s\"", kncp->knc_proto); 943 plog(XLOG_DEBUG, "NA->knconf->rdev %lu", (u_long) kncp->knc_rdev); 944 /* don't print knconf->unused field */ 945 #else /* not HAVE_TRANSPORT_TYPE_TLI */ 946 # ifdef NFS_ARGS_T_ADDR_IS_POINTER 947 sap = (struct sockaddr_in *) nap->addr; 948 # else /* not NFS_ARGS_T_ADDR_IS_POINTER */ 949 sap = (struct sockaddr_in *) &nap->addr; 950 # endif /* not NFS_ARGS_T_ADDR_IS_POINTER */ 951 plog(XLOG_DEBUG, "NA->addr {sockaddr_in} (len=%d) = \"%s\"", 952 (int) sizeof(struct sockaddr_in), 953 get_hex_string(sizeof(struct sockaddr_in), (const char *)sap)); 954 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 955 /* as per POSIX, sin_len need not be set (used internally by kernel) */ 956 plog(XLOG_DEBUG, "NA->addr.sin_len = %d", sap->sin_len); 957 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */ 958 plog(XLOG_DEBUG, "NA->addr.sin_family = %d", sap->sin_family); 959 plog(XLOG_DEBUG, "NA->addr.sin_port = %d", sap->sin_port); 960 plog(XLOG_DEBUG, "NA->addr.sin_addr = \"%s\"", 961 get_hex_string(sizeof(struct in_addr), (const char *) &sap->sin_addr)); 962 #endif /* not HAVE_TRANSPORT_TYPE_TLI */ 963 #ifdef HAVE_NFS_ARGS_T_ADDRLEN 964 plog(XLOG_DEBUG, "NA->addrlen = %d", nap->addrlen); 965 #endif /* ifdef HAVE_NFS_ARGS_T_ADDRLEN */ 966 967 plog(XLOG_DEBUG, "NA->hostname = \"%s\"", nap->hostname ? nap->hostname : "null"); 968 #ifdef HAVE_NFS_ARGS_T_NAMLEN 969 plog(XLOG_DEBUG, "NA->namlen = %d", nap->namlen); 970 #endif /* HAVE_NFS_ARGS_T_NAMLEN */ 971 972 #ifdef MNT2_NFS_OPT_FSNAME 973 plog(XLOG_DEBUG, "NA->fsname = \"%s\"", nap->fsname ? nap->fsname : "null"); 974 #endif /* MNT2_NFS_OPT_FSNAME */ 975 976 #ifdef HAVE_NFS_ARGS_T_FHSIZE 977 plog(XLOG_DEBUG, "NA->fhsize = %d", nap->fhsize); 978 fhlen = nap->fhsize; 979 #endif /* HAVE_NFS_ARGS_T_FHSIZE */ 980 #ifdef HAVE_NFS_ARGS_T_FH_LEN 981 plog(XLOG_DEBUG, "NA->fh_len = %d", nap->fh_len); 982 fhlen = nap->fh_len; 983 #endif /* HAVE_NFS_ARGS_T_FH_LEN */ 984 985 /* 986 * XXX: need to figure out how to correctly print file handles, 987 * since some times they are pointers, and sometimes the real structure 988 * is stored in nfs_args. Even if it is a pointer, it can be the actual 989 * char[] array, or a structure containing multiple fields. 990 */ 991 plog(XLOG_DEBUG, "NA->filehandle = \"%s\"", 992 get_hex_string(fhlen, (const char *) &nap->NFS_FH_FIELD)); 993 994 #ifdef HAVE_NFS_ARGS_T_SOTYPE 995 plog(XLOG_DEBUG, "NA->sotype = %d", nap->sotype); 996 #endif /* HAVE_NFS_ARGS_T_SOTYPE */ 997 #ifdef HAVE_NFS_ARGS_T_PROTO 998 plog(XLOG_DEBUG, "NA->proto = %d", (int) nap->proto); 999 #endif /* HAVE_NFS_ARGS_T_PROTO */ 1000 #ifdef HAVE_NFS_ARGS_T_VERSION 1001 plog(XLOG_DEBUG, "NA->version = %d", nap->version); 1002 #endif /* HAVE_NFS_ARGS_T_VERSION */ 1003 1004 plog(XLOG_DEBUG, "NA->flags = 0x%x", (int) nap->flags); 1005 1006 plog(XLOG_DEBUG, "NA->rsize = %d", (int) nap->rsize); 1007 plog(XLOG_DEBUG, "NA->wsize = %d", (int) nap->wsize); 1008 #ifdef HAVE_NFS_ARGS_T_BSIZE 1009 plog(XLOG_DEBUG, "NA->bsize = %d", nap->bsize); 1010 #endif /* HAVE_NFS_ARGS_T_BSIZE */ 1011 plog(XLOG_DEBUG, "NA->timeo = %d", (int) nap->timeo); 1012 plog(XLOG_DEBUG, "NA->retrans = %d", (int) nap->retrans); 1013 1014 #ifdef HAVE_NFS_ARGS_T_ACREGMIN 1015 plog(XLOG_DEBUG, "NA->acregmin = %d", (int) nap->acregmin); 1016 plog(XLOG_DEBUG, "NA->acregmax = %d", (int) nap->acregmax); 1017 plog(XLOG_DEBUG, "NA->acdirmin = %d", (int) nap->acdirmin); 1018 plog(XLOG_DEBUG, "NA->acdirmax = %d", (int) nap->acdirmax); 1019 #endif /* HAVE_NFS_ARGS_T_ACREGMIN */ 1020 #ifdef MNTTAB_OPT_SYMTTL 1021 plog(XLOG_DEBUG, "NA->symttl = %d", nap->symttl); 1022 #endif /* MNTTAB_OPT_SYMTTL */ 1023 #ifdef MNTTAB_OPT_PG_THRESH 1024 plog(XLOG_DEBUG, "NA->pg_thresh = %d", nap->pg_thresh); 1025 #endif /* MNTTAB_OPT_PG_THRESH */ 1026 1027 #ifdef MNT2_NFS_OPT_BIODS 1028 plog(XLOG_DEBUG, "NA->biods = %d", nap->biods); 1029 #endif /* MNT2_NFS_OPT_BIODS */ 1030 1031 } 1032 #endif /* DEBUG */ 1033