* Set the publicly exported filesystem (WebNFS). Currently, only * one public filesystem is possible in the spec (RFC 2054 and 2055) */
| 375 | * one public filesystem is possible in the spec (RFC 2054 and 2055) |
| 376 | */ |
| 377 | int |
| 378 | vfs_setpublicfs(struct mount *mp, struct netexport *nep, |
| 379 | struct export_args *argp) |
| 380 | { |
| 381 | int error; |
| 382 | struct vnode *rvp; |
| 383 | char *cp; |
| 384 | |
| 385 | /* |
| 386 | * mp == NULL -> invalidate the current info, the FS is |
| 387 | * no longer exported. May be called from either vfs_export |
| 388 | * or unmount, so check if it hasn't already been done. |
| 389 | */ |
| 390 | if (mp == NULL) { |
| 391 | if (nfs_pub.np_valid) { |
| 392 | nfs_pub.np_valid = 0; |
| 393 | if (nfs_pub.np_index != NULL) { |
| 394 | free(nfs_pub.np_index, M_TEMP); |
| 395 | nfs_pub.np_index = NULL; |
| 396 | } |
| 397 | } |
| 398 | return (0); |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * Only one allowed at a time. |
| 403 | */ |
| 404 | if (nfs_pub.np_valid != 0 && mp != nfs_pub.np_mount) |
| 405 | return (EBUSY); |
| 406 | |
| 407 | /* |
| 408 | * Get real filehandle for root of exported FS. |
| 409 | */ |
| 410 | bzero(&nfs_pub.np_handle, sizeof(nfs_pub.np_handle)); |
| 411 | nfs_pub.np_handle.fh_fsid = mp->mnt_stat.f_fsid; |
| 412 | |
| 413 | if ((error = VFS_ROOT(mp, LK_EXCLUSIVE, &rvp))) |
| 414 | return (error); |
| 415 | |
| 416 | if ((error = VOP_VPTOFH(rvp, &nfs_pub.np_handle.fh_fid))) |
| 417 | return (error); |
| 418 | |
| 419 | vput(rvp); |
| 420 | |
| 421 | /* |
| 422 | * If an indexfile was specified, pull it in. |
| 423 | */ |
| 424 | if (argp->ex_indexfile != NULL) { |
| 425 | if (nfs_pub.np_index == NULL) |
| 426 | nfs_pub.np_index = malloc(MAXNAMLEN + 1, M_TEMP, |
| 427 | M_WAITOK); |
| 428 | error = copyinstr(argp->ex_indexfile, nfs_pub.np_index, |
| 429 | MAXNAMLEN, (size_t *)0); |
| 430 | if (!error) { |
| 431 | /* |
| 432 | * Check for illegal filenames. |
| 433 | */ |
| 434 | for (cp = nfs_pub.np_index; *cp; cp++) { |