[BACK]Return to filesys-os.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / rdistd

Annotation of src/usr.bin/rdistd/filesys-os.c, Revision 1.12

1.12    ! deraadt     1: /*     $OpenBSD: filesys-os.c,v 1.11 2014/07/05 10:21:24 guenther Exp $        */
1.3       deraadt     2:
1.1       dm          3: /*
                      4:  * Copyright (c) 1983 Regents of the University of California.
                      5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
1.9       millert    15:  * 3. Neither the name of the University nor the names of its contributors
1.1       dm         16:  *    may be used to endorse or promote products derived from this software
                     17:  *    without specific prior written permission.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     20:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     21:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     22:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     23:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     24:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     25:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     26:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     27:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     28:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     29:  * SUCH DAMAGE.
                     30:  */
                     31:
1.12    ! deraadt    32: #include <sys/types.h>
1.11      guenther   33: #include <sys/mount.h>
                     34:
1.8       millert    35: #include "defs.h"
1.1       dm         36:
                     37: /*
                     38:  * OS specific file system routines
                     39:  */
                     40:
                     41: static struct statfs   *mnt = NULL;
                     42: static int             entries_left;
                     43:
                     44: /*
                     45:  * getfsstat() version of get mount info routines.
                     46:  */
1.11      guenther   47: int
                     48: setmountent(void)
1.1       dm         49: {
1.5       millert    50:        long size;
1.1       dm         51:
1.4       kstailey   52:        size = getfsstat(NULL, 0, MNT_WAIT);
1.2       deraadt    53:        if (size == -1)
1.11      guenther   54:                return (0);
                     55:
                     56:        free(mnt);
1.1       dm         57:        size *= sizeof(struct statfs);
1.11      guenther   58:        mnt = xmalloc(size);
1.1       dm         59:
1.11      guenther   60:        entries_left = getfsstat(mnt, size, MNT_WAIT);
1.1       dm         61:        if (entries_left == -1)
1.11      guenther   62:                return (0);
1.1       dm         63:
1.11      guenther   64:        return (1);
1.1       dm         65: }
                     66:
                     67: /*
                     68:  * getfsstat() version of getmountent()
                     69:  */
1.8       millert    70: mntent_t *
1.11      guenther   71: getmountent(void)
1.1       dm         72: {
                     73:        static mntent_t mntstruct;
1.12    ! deraadt    74:        static char remote_dev[HOST_NAME_MAX+1 + PATH_MAX + 1];
1.1       dm         75:
                     76:        if (!entries_left)
1.11      guenther   77:                return (NULL);
1.1       dm         78:
1.11      guenther   79:        memset(&mntstruct, 0, sizeof(mntstruct));
1.1       dm         80:
                     81:        if (mnt->f_flags & MNT_RDONLY)
                     82:                mntstruct.me_flags |= MEFLAG_READONLY;
1.8       millert    83:
1.11      guenther   84:        if (strcmp(mnt->f_fstypename, "nfs") == 0) {
1.8       millert    85:                strlcpy(remote_dev, mnt->f_mntfromname, sizeof(remote_dev));
1.1       dm         86:                mntstruct.me_path = remote_dev;
                     87:                mntstruct.me_type = METYPE_NFS;
1.5       millert    88:        } else {
1.1       dm         89:                mntstruct.me_path = mnt->f_mntonname;
                     90:                mntstruct.me_type = METYPE_OTHER;
                     91:        }
                     92:
                     93:        mnt++;
                     94:        entries_left--;
                     95:
1.11      guenther   96:        return (&mntstruct);
1.1       dm         97: }
                     98:
                     99: /*
                    100:  * Done with iterations
                    101:  */
1.8       millert   102: void
1.11      guenther  103: endmountent(void)
1.1       dm        104: {
1.11      guenther  105:        free(mnt);
1.1       dm        106:        mnt = NULL;
                    107: }
                    108:
                    109: /*
                    110:  * Make a new (copy) of a mntent structure.
                    111:  */
1.8       millert   112: mntent_t *
                    113: newmountent(const mntent_t *old)
1.1       dm        114: {
                    115:        mntent_t *new;
                    116:
1.11      guenther  117:        new = xmalloc(sizeof *new);
1.6       millert   118:        new->me_path = xstrdup(old->me_path);
                    119:        new->me_type = xstrdup(old->me_type);
1.1       dm        120:        new->me_flags = old->me_flags;
                    121:
1.11      guenther  122:        return (new);
1.1       dm        123: }