[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.13

1.13    ! guenther    1: /*     $OpenBSD: filesys-os.c,v 1.12 2015/01/16 06:40:11 deraadt 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>
1.13    ! guenther   34: #include <stdlib.h>
        !            35: #include <string.h>
1.11      guenther   36:
1.13    ! guenther   37: #include "server.h"
1.1       dm         38:
                     39: /*
                     40:  * OS specific file system routines
                     41:  */
                     42:
                     43: static struct statfs   *mnt = NULL;
                     44: static int             entries_left;
                     45:
                     46: /*
                     47:  * getfsstat() version of get mount info routines.
                     48:  */
1.11      guenther   49: int
                     50: setmountent(void)
1.1       dm         51: {
1.5       millert    52:        long size;
1.1       dm         53:
1.4       kstailey   54:        size = getfsstat(NULL, 0, MNT_WAIT);
1.2       deraadt    55:        if (size == -1)
1.11      guenther   56:                return (0);
                     57:
                     58:        free(mnt);
1.1       dm         59:        size *= sizeof(struct statfs);
1.11      guenther   60:        mnt = xmalloc(size);
1.1       dm         61:
1.11      guenther   62:        entries_left = getfsstat(mnt, size, MNT_WAIT);
1.1       dm         63:        if (entries_left == -1)
1.11      guenther   64:                return (0);
1.1       dm         65:
1.11      guenther   66:        return (1);
1.1       dm         67: }
                     68:
                     69: /*
                     70:  * getfsstat() version of getmountent()
                     71:  */
1.8       millert    72: mntent_t *
1.11      guenther   73: getmountent(void)
1.1       dm         74: {
                     75:        static mntent_t mntstruct;
1.12      deraadt    76:        static char remote_dev[HOST_NAME_MAX+1 + PATH_MAX + 1];
1.1       dm         77:
                     78:        if (!entries_left)
1.11      guenther   79:                return (NULL);
1.1       dm         80:
1.11      guenther   81:        memset(&mntstruct, 0, sizeof(mntstruct));
1.1       dm         82:
                     83:        if (mnt->f_flags & MNT_RDONLY)
                     84:                mntstruct.me_flags |= MEFLAG_READONLY;
1.8       millert    85:
1.11      guenther   86:        if (strcmp(mnt->f_fstypename, "nfs") == 0) {
1.8       millert    87:                strlcpy(remote_dev, mnt->f_mntfromname, sizeof(remote_dev));
1.1       dm         88:                mntstruct.me_path = remote_dev;
1.13    ! guenther   89:                mntstruct.me_flags |= MEFLAG_NFS;
        !            90:        } else
1.1       dm         91:                mntstruct.me_path = mnt->f_mntonname;
                     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);
1.1       dm        119:        new->me_flags = old->me_flags;
                    120:
1.11      guenther  121:        return (new);
1.1       dm        122: }