5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER START
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The contents of this file are subject to the terms of the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Common Development and Distribution License (the "License").
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You may not use this file except in compliance with the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * or http://www.opensolaris.org/os/licensing.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * See the License for the specific language governing permissions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and limitations under the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * When distributing Covered Code, include this CDDL HEADER in each
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If applicable, add the following below this CDDL HEADER, with the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER END
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Use is subject to license terms.
bd93c05dbd9b8f1e8d2edf48c777bc881f927608Alexander Eremin * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * System includes
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * consolidation pkg command library includes
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * local pkg command library includes
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int match_mount; /* This holds the mount of interest. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* returned by already_mounted() */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* used with is_remote_src() */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Due to /etc/mnttab files containing entries for multiple nfs hosts
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * HOST_NM_LN needs to be accommodating. The recommended value in the sysinfo
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * man page of 257 needs to be expanded. See bugid 4076513.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * 1024 chars is defined in the mnttab.h header as the max size of an entry.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Utilities for getting filesystem information from the mount table.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Note: vanilla SVr4 code (pkginstall/dockspace.c) used the output from
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * popen() on the "/etc/mount" command. However, we need to get more
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * information about mounted filesystems, so we use the C interfaces to
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the mount table, which also happens to be much faster than running
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * another process. Since several of the pkg commands need access to the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the code has been placed here, to be included in the libinst library.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * fs_tab_ent_comp - compare fstable entries first by length in reverse
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * order, then alphabetically.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandfs_tab_ent_comp(const void *e1, const void *e2)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland struct fstable *fs1 = *((struct fstable **)e1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland struct fstable *fs2 = *((struct fstable **)e2);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This determines if the source of the mount is from another host. If it's
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * from this host, then it might be writable. This returns NOT_REMOTE if it's
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * pure local, REAL_REMOTE if it's being served from another host and
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * SELF_SERVE if it's being served by the current host.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char source_host[HOST_NM_LN], *src_ptr, *src_host_ptr;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Find out what host this is. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) sysinfo(SI_HOSTNAME, host_name, HOST_NM_LN);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (NOT_REMOTE); /* No server name, so it's local. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (NOT_REMOTE); /* it's a floppy disk or something */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Scan to the end of the hostname (find the ":"). */
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik /* Multiple hosts: failover with multiple servers; this is remote. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strncmp(source, host_name, hn_len) == 0 &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *(source+hn_len) == ':' || is_local_host(source_host))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (SELF_SERVE); /* Exporting from itself, it's local. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This determines if an apparently writeable filesystem is really writeable
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * or if it's been shared over the network with root-restrictive options.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(testfile, sizeof (testfile), "%s/testXXXXXX", mountpt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (0); /* may as well be read-only */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* LINTED do not use creat(); use open(path,... */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland else if ((fd = creat(testfile, 0777)) == -1)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (0); /* can't write */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* This returns the hostname portion of a remote path. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland static char hostname[HOST_NM_LN], *host_end;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return ("unknown source");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strcpy(hostname, fs_tab[n]->remote_name);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((host_end = strchr(hostname, ':')) == NULL) {
bd93c05dbd9b8f1e8d2edf48c777bc881f927608Alexander Eremin if ((strcmp(fs_tab[n]->fstype, MNTTYPE_AUTOFS)) == NULL)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return ("automounter");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return ("unknown source");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This pulls the path out of a hostpath which may be of the form host:path
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * where path is an absolute path. NOTE: If path turns out to be relative,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this returns NULL.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((host_end = strchr(hostpath, ':')) == NULL && hostpath[0] == '/')
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (hostpath); /* It's already legit. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (host_end+1); /* Here's the path part. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This scans the filesystems already mounted to see if this remote mount is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * already in place on the server. This scans the fs_tab for a remote_name
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * exactly matching the client's. It stores the current entry number
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * corresponding to this mount in the static match_mount.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * MNT_NOT Couldn't find it.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * MNT_EXACT This has actually been manually mounted for us
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * MNT_AVAIL This is mounted for the server, but needs to be
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * loopback mounted from the client's perspective.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandalready_mounted(struct vfstab *vfs, int is_local_host, char *client_path,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; i < fs_tab_used; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Determine if this has been manually mounted exactly as we
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * require. Begin by finding a mount on our current
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * mountpoint.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(fs_tab[i]->name, client_path) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Now see if it is really the same mount. This isn't
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * smart enough to find mounts on top of mounts, but
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * assuming there is no conspiracy to fool this
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * function, it will be good enough.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland strcmp(fs_tab[i]->remote_name, host_path) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Determine if this mount is available to the server. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(fs_tab[i]->remote_name, vfs->vfs_special) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function unmounts all of the loopback mounts created for the client.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If no client stuff is mounted, this is completely benign, it finds that
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * nothing is mounted up and returns. It returns "1" for unmounted everything
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * OK and "0" for failure.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* If the filesystem is mounted and this utility did it ... */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (fs_tab[n]->cl_mounted && fs_tab[n]->srvr_map) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* create arglist for umount command */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* flush standard i/o before creating new process */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * create new process to execute command in;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * vfork is being used to avoid duplicating the parents
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * memory space - this means that the child process may
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * not modify any of the parents memory including the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * standard i/o descriptors - all the child can do is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * adjust interrupts and open files as a prelude to a
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * call to exec().
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* fork failed! */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland logerr(WRN_BAD_FORK, errno, strerror(errno));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else if (pid > 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this is the parent process
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If the child was stopped or killed by a
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * signal or exied with any code but 0, we
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * assume the mount has failed.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this is the child process
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* reset any signals to default */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; i < NSIG; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Redirect output to /dev/null because the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * umount error message may be confusing to
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (i >= 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* close all file descriptors except stdio */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function creates the necessary loopback mounts to emulate the client
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * configuration with respect to the server. If this is being run on a
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * standalone or the installation is actually to the local system, this call
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is benign since srvr_map won't be set anywhere. It returns "1" for mounted
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * everything OK and "0" for failure.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If the filesystem is mounted (meaning available) and the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * apparent filesystem can be mapped to a local filesystem
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * AND the local filesystem is not the same as the target
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * filesystem, mount it.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (fs_tab[n]->mounted && fs_tab[n]->srvr_map) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* create arglist for mount command */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* flush standard i/o before creating new process */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * create new process to execute command in;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * vfork is being used to avoid duplicating the parents
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * memory space - this means that the child process may
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * not modify any of the parents memory including the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * standard i/o descriptors - all the child can do is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * adjust interrupts and open files as a prelude to a
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * call to exec().
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* fork failed! */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland logerr(WRN_BAD_FORK, errno, strerror(errno));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else if (pid > 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this is the parent process
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If the child was stopped or killed by a
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * signal or exied with any code but 0, we
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * assume the mount has failed.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this is the child process
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* reset all signals to default */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; i < NSIG; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Redirect output to /dev/null because the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * mount error message may be confusing to
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (i >= 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* close all file descriptors except stdio */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*NOTREACHED*/
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function maps path, on a loopback filesystem, back to the real server
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * filesystem. fsys_value is the fs_tab[] entry to which the loopback'd path is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * mapped. This returns a pointer to a static area. If the result is needed
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * for further processing, it should be strdup()'d or something.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* This function sets up the standard parts of the fs_tab. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic struct fstable *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Create the array if necessary. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (unsigned)sizeof (struct fstable),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "filesystem mount data");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland progerr(ERR_MALLOC, "fs_list", errno, strerror(errno));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Allocate an fstable entry for this mnttab entry.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((nfte = *(struct fstable **)ar_next_avail(fs_list))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland progerr(ERR_MALLOC, "nfte", errno, strerror(errno));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Point fs_tab at the head of the array again, since it may have
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * moved due to realloc in ar_next_avail(). If ar_next_avail() realizes
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * that there is no more room to grow the array, it reallocates the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * array. Because we stored pointer to that array in fs_tab, we need
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to make sure that it is updated as well.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((fs_tab = (struct fstable **)ar_get_head(fs_list)) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland progerr(ERR_NOTABLE, "mount", MOUNT_TABLE, strerror(errno));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Get the length of the 'mount point' name.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Allocate space for the 'mount point' name.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((nfte->name = malloc(nfte->namlen+1)) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland progerr(ERR_MALLOC, "name", errno, strerror(errno));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((nfte->fstype = malloc(strlen(fstype)+1)) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland progerr(ERR_MALLOC, "fstype", errno, strerror(errno));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* This function frees all memory associated with the filesystem table. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (n = 0; n < fs_tab_used; n++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* This function scans a string of mount options for a specific keyword. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (optptr = strrchr(vfs_options, ',')) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Now deal with the remainder. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function constructs a new filesystem table (fs_tab[]) entry based on
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * an /etc/mnttab entry. When it returns, the new entry has been inserted
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * into fs_tab[].
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Initialize fstable structure and make the standard entries.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((nfte = fs_tab_init(mt->mnt_mountp, mt->mnt_fstype)) == NULL)
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik * See if this is served from another host.
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik * Testing the type is cheap; finding the hostname is not.
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik * At this point, we're using the REAL mnttab; since we're not
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik * allowed to mount ourself with "NFS", "NFS" must be remote.
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik * The automount will translate "nfs:self" to a lofs mount.
bd93c05dbd9b8f1e8d2edf48c777bc881f927608Alexander Eremin if (strcmp(mt->mnt_fstype, MNTTYPE_AUTOFS) == 0 ||
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik is_remote_src(mt->mnt_special) == REAL_REMOTE)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* It's mounted now (by definition), so we don't have to remap it. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland nfte->remote_name = strdup(mt->mnt_special);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This checks the mount commands which establish the most
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * basic level of access. Later further tests may be
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * necessary to fully qualify this. We set this bit
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * preliminarily because we have access to the mount data
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland nfte->writeable = 0; /* Assume read-only. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * There's no network involved, so this
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * assessment is confirmed.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* read-only is read-only */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Is this coming to us from a server? */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function modifies an existing fs_tab[] entry. It was found mounted up
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * exactly the way we would have mounted it in mount_client() only at the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * time we didn't know it was for the client. Now we do, so we're setting the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * various permissions to conform to the client view.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandmod_existing(struct vfstab *vfsent, int fstab_entry, int is_remote)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Establish whether the client will see this as served.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (is_remote && hasopt(vfsent->vfs_mntopts, MNTOPT_RO))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function constructs a new fs_tab[] entry based on
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * an /etc/vfstab entry. When it returns, the new entry has been inserted
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * into fstab[].
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandconstruct_vfs(struct vfstab *vfsent, char *client_path, char *link_name,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((nfte = fs_tab_init(client_path, vfsent->vfs_fstype)) == NULL)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The file system mounted on the client may or may not be writeable.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * So we hand it over to fsys() to evaluate. This will have the same
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * read/write attributes as the corresponding mounted filesystem.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Deal here with mount points actually on a system remote
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * from the server.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This filesystem isn't in the current mount table
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * meaning it isn't mounted, the current host can't
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * write to it and there's no point to mapping it for
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the server.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else { /* It's MNT_AVAIL. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This filesystem is associated with a current
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * mountpoint. Since it's mounted, it needs to be
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * remapped and it is writable if the real mounted
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * filesystem is writeable.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland link_name = strdup(fs_tab[match_mount]->name);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland nfte->writeable = fs_tab[match_mount]->writeable;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland nfte->write_tested = fs_tab[match_mount]->write_tested;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else { /* local filesystem */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland nfte->writeable = fs_tab[fsys(link_name)]->writeable;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Now we establish whether the client will see this as served.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (is_remote && hasopt(vfsent->vfs_mntopts, MNTOPT_RO))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland nfte->remote_name = strdup(vfsent->vfs_special);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * get_mntinfo - get the mount table, now dynamically allocated. Returns 0 if
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * no problem and 1 if there's a fatal error.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandget_mntinfo(int map_client, char *vfstab_file)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Open the mount table for the current host and establish a global
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * table that holds data about current mount status.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((pp = setmntent(MOUNT_TABLE, "r")) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland progerr(ERR_NOTABLE, "mount", MOUNT_TABLE, strerror(errno));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * First, review the mounted filesystems on the managing host. This
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * may also be the target host but we haven't decided that for sure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Now, we see if this installation is to a client. If it is, we scan
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the client's vfstab to determine what filesystems are
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * inappropriate to write to. This simply adds the vfstab entries
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * representing what will be remote file systems for the client.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Everything that isn't remote to the client is already accounted
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * for in the fs_tab[] so far. If the remote filesystem is really on
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this server, we will write through to the server from this client.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (install_root && strcmp(install_root, "/") != 0 && map_client) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* OK, this is a legitimate remote client. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Since we use the fsys() function later, and it depends on
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * an ordered list, we have to sort the list here.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland sizeof (struct fstable *), fs_tab_ent_comp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Here's where the vfstab for the target is. If we can get
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to it, we'll scan it for what the client will see as
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * remote filesystems, otherwise, we'll just skip this.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(VFS_TABLE, sizeof (VFS_TABLE), "%s",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(VFS_TABLE, sizeof (VFS_TABLE), "%s%s",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Open the vfs table for the target host.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((pp = setmntent(VFS_TABLE, "r")) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Do this for each entry in the vfstab. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * We put it into the fs table if it's
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * remote mounted (even from this server) or
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * loopback mounted from the client's point
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland continue; /* not interesting */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Construct client_mountp by prepending the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * install_root to the 'mount point' name.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * We also skip the entry if the vfs_special
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * path and the client_path are the same.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Determine if this is already mounted. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland link_name = strdup(path_part(vfs->vfs_special));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else { /* MNT_NOT */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } /* end of if(access()) */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } /* end of if(install_root) */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* This next one may look stupid, but it can really happen. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Now that we have the complete list of mounted (or virtually
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * mounted) filesystems, we sort the mountpoints in reverse order
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * based on the length of the 'mount point' name.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland qsort(fs_tab, fs_tab_used, sizeof (struct fstable *), fs_tab_ent_comp);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (strcmp(fs_tab[fs_tab_used-1]->name, rn) != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland progerr(ERR_MNT_NOROOT, fs_tab[fs_tab_used-1]->name, rn, errno,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function supports dryrun mode by allowing the filesystem table to be
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * directly loaded from the continuation file.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandload_fsentry(struct fstable *fs_entry, char *name, char *fstype,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((nfte = fs_tab_init(name, fstype)) == NULL)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Grab the name and fstype from the new structure. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Copy the basic structure into place. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) memcpy(nfte, fs_entry, sizeof (struct fstable));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Allocate space for the 'special' name.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((nfte->remote_name = malloc(strlen(remote_name)+1)) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland progerr(ERR_MALLOC, "remote_name", errno, strerror(errno));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strcpy(nfte->remote_name, remote_name);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Given a path, return the table index of the filesystem the file apparently
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * resides on. This doesn't put any time into resolving filesystems that
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * refer to other filesystems. It just returns the entry containing this
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland register int i;
af1222373b60d56d6b0e630911372d4162b7787bJan Kryl * The loop below represents our best effort to identify real path of
af1222373b60d56d6b0e630911372d4162b7787bJan Kryl * a file, which doesn't need to exist. realpath() returns error for
af1222373b60d56d6b0e630911372d4162b7787bJan Kryl * nonexistent path, therefore we need to cut off trailing components
af1222373b60d56d6b0e630911372d4162b7787bJan Kryl * of path until we get path which exists and can be resolved by
af1222373b60d56d6b0e630911372d4162b7787bJan Kryl * realpath(). Lookup of "/dir/symlink/nonexistent-file" would fail
af1222373b60d56d6b0e630911372d4162b7787bJan Kryl * to resolve symlink without this.
af1222373b60d56d6b0e630911372d4162b7787bJan Kryl for (cp = dirname(path_copy); strlen(cp) > 1; cp = dirname(cp)) {
af1222373b60d56d6b0e630911372d4162b7787bJan Kryl /* fall back to original path in case of unexpected failure */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The following algorithm scans the list of attached file systems
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * for the one containing path. At this point the file names in
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * fs_tab[] are sorted by decreasing length to facilitate the scan.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The first for() scans past all the file system names too short to
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * contain path. The second for() does the actual string comparison.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * It tests first to assure that the comparison is against a complete
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * token by assuring that the end of the filesystem name aligns with
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the end of a token in path2use (ie: '/' or NULL) then it does a
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * string compare. -- JST
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; i < fs_tab_used; i++)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (; i < fs_tab_used; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If we're putting the file "/a/kernel" into the filesystem
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * "/a", then fs_namelen == 2 and term_char == '/'. If, we're
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * putting "/etc/termcap" into "/", fs_namelen == 1 and
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * term_char (unfortunately) == 'e'. In the case of
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * fs_namelen == 1, we check to make sure the filesystem is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * "/" and if it is, we have a guaranteed fit, otherwise we
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * do the string compare. -- JST
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((fs_namelen == 1 && *(fs_tab[i]->name) == '/') ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ((term_char == '/' || term_char == NULL) &&
e47aa97b65b6eaa7016357de7fb7974c1982858cSimon Klinkert strncmp(fs_tab[i]->name, path2use, fs_namelen) == 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * It only gets here if the root filesystem is fundamentally corrupt.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * (This can happen!)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function returns the entry in the fs_tab[] corresponding to the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * actual filesystem of record. It won't return a loopback filesystem entry,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * it will return the filesystem that the loopback filesystem is mounted
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* If this isn't a "real" filesystem, resolve the map. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strcpy(path2use, server_map(path2use, i));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function returns the srvr_map status based upon the fs_tab entry
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * number. This tells us if the server path constructed from the package
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * install root is really the target filesystem.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function returns the mount status based upon the fs_tab entry
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * number. This tells us if there is any hope of gaining access
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to this file system.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is_fs_writeable_n - given an fstab index, return 1
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if it's writeable, 0 if read-only.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If the write access permissions haven't been confirmed, do that
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * now. Note that the only reason we need to do the special check is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * in the case of an NFS mount (remote) because we can't determine if
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * root has access in any other way.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (fs_tab[n]->remote && fs_tab[n]->mounted &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (fs_tab[n]->writeable && !really_write(fs_tab[n]->name))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland fs_tab[n]->write_tested = 1; /* confirmed */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is_remote_fs_n - given an fstab index, return 1
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if it's a remote filesystem, 0 if local.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Note: Upon entry, a valid fsys() is required.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* index-driven is_served() */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This returns the number of blocks available on the indicated filesystem.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Note: Upon entry, a valid fsys() is required.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This returns the number of blocks being used on the indicated filesystem.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Note: Upon entry, a valid fsys() is required.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This returns the number of inodes available on the indicated filesystem.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Note: Upon entry, a valid fsys() is required.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This returns the number of inodes being used on the indicated filesystem.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Note: Upon entry, a valid fsys() is required.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Sets the number of blocks being used on the indicated filesystem.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Note: Upon entry, a valid fsys() is required.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* Get the filesystem block size. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* Get the filesystem fragment size. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This returns the name of the indicated filesystem.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else if (n >= fs_tab_used) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This returns the remote name of the indicated filesystem.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Note: Upon entry, a valid fsys() is required.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function returns the srvr_map status based upon the path.
e47aa97b65b6eaa7016357de7fb7974c1982858cSimon Klinkertuse_srvr_map(char *path, uint32_t *fsys_value)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function returns the mount status based upon the path.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is_fs_writeable - given a cfent entry, return 1
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if it's writeable, 0 if read-only.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Note: Upon exit, a valid fsys() is guaranteed. This is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * an interface requirement.
e47aa97b65b6eaa7016357de7fb7974c1982858cSimon Klinkertis_fs_writeable(char *path, uint32_t *fsys_value)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is_remote_fs - given a cfent entry, return 1
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if it's a remote filesystem, 0 if local.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Also Note: Upon exit, a valid fsys() is guaranteed. This is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * an interface requirement.
e47aa97b65b6eaa7016357de7fb7974c1982858cSimon Klinkertis_remote_fs(char *path, uint32_t *fsys_value)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function returns the served status of the filesystem. Served means a
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * client is getting this file from a server and it is not writeable by the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * client. It has nothing to do with whether or not this particular operation
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * (eg: pkgadd or pkgrm) will be writing to it.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * get_remote_path - given a filesystem table index, return the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * path of the filesystem on the remote system. Otherwise,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * return NULL if it's a local filesystem.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland p++; /* remote */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * get_mount_point - given a filesystem table index, return the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * path of the mount point. Otherwise,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * return NULL if it's a local filesystem.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else if (n >= fs_tab_used) {