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

1.1     ! dm          1: /*
        !             2:  * Copyright (c) 1983 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms, with or without
        !             6:  * modification, are permitted provided that the following conditions
        !             7:  * are met:
        !             8:  * 1. Redistributions of source code must retain the above copyright
        !             9:  *    notice, this list of conditions and the following disclaimer.
        !            10:  * 2. Redistributions in binary form must reproduce the above copyright
        !            11:  *    notice, this list of conditions and the following disclaimer in the
        !            12:  *    documentation and/or other materials provided with the distribution.
        !            13:  * 3. All advertising materials mentioning features or use of this software
        !            14:  *    must display the following acknowledgement:
        !            15:  *     This product includes software developed by the University of
        !            16:  *     California, Berkeley and its contributors.
        !            17:  * 4. Neither the name of the University nor the names of its contributors
        !            18:  *    may be used to endorse or promote products derived from this software
        !            19:  *    without specific prior written permission.
        !            20:  *
        !            21:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            22:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            23:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            24:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            25:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            26:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            27:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            28:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            29:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            30:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            31:  * SUCH DAMAGE.
        !            32:  */
        !            33:
        !            34: #ifndef lint
        !            35: static char RCSid[] =
        !            36: "$Id: filesys-os.c,v 6.17 1996/01/17 21:02:45 mcooper Exp $";
        !            37:
        !            38: static char sccsid[] = "@(#)filesys-os.c";
        !            39:
        !            40: static char copyright[] =
        !            41: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
        !            42:  All rights reserved.\n";
        !            43: #endif /* not lint */
        !            44:
        !            45: /*
        !            46:  * OS specific file system routines
        !            47:  */
        !            48:
        !            49: #include "defs.h"
        !            50: #include "filesys.h"
        !            51:
        !            52: #if    FSI_TYPE == FSI_GETFSSTAT
        !            53: static struct statfs   *mnt = NULL;
        !            54: typedef u_long                 ulong;
        !            55: #if    FSTYPENAME
        !            56: #define f_type_eq(a, b) (! strcmp (((struct statfs *) (a))->f_fstypename, (b)))
        !            57: #else  /* !FSTYPENAME */
        !            58: #define        f_type_eq(a, b) (((struct statfs *) a)->f_type == (b))
        !            59: #endif /* !FSTYPENAME */
        !            60: #endif /* FSI_GETFSSTAT */
        !            61:
        !            62: #if    FSI_TYPE == FSI_MNTCTL
        !            63: static struct vmount   *mnt = NULL;
        !            64: #endif /* FSI_MNTCTL */
        !            65:
        !            66: #if    (FSI_TYPE == FSI_MNTCTL) || (FSI_TYPE == FSI_GETFSSTAT)
        !            67: static char           *mntbuf = NULL;
        !            68: static int             entries_left;
        !            69: #endif /* FSI_MNTCTL || FSI_GETFSSTAT */
        !            70:
        !            71: #if    FSI_TYPE == FSI_MNTCTL
        !            72: /*
        !            73:  * AIX version of setmountent()
        !            74:  */
        !            75: FILE *setmountent(file, mode)
        !            76:        /*ARGSUSED*/
        !            77:        char *file;
        !            78:        char *mode;
        !            79: {
        !            80:        ulong size;
        !            81:
        !            82:        if (mntbuf)
        !            83:                (void) free(mntbuf);
        !            84:
        !            85:        mntctl(MCTL_QUERY, sizeof(size), &size);
        !            86:        mntbuf = (char *) xmalloc(size);
        !            87:
        !            88:        entries_left = mntctl(MCTL_QUERY, size, mntbuf);
        !            89:        if (!entries_left)
        !            90:                return((FILE *)NULL);
        !            91:
        !            92:        mnt = (struct vmount *)mntbuf;
        !            93:        return((FILE *) 1);
        !            94: }
        !            95: #endif /* FSI_MNTCTL */
        !            96:
        !            97: #if    FSI_TYPE == FSI_GETFSSTAT
        !            98: /*
        !            99:  * getfsstat() version of get mount info routines.
        !           100:  */
        !           101: FILE *setmountent(file, mode)
        !           102:        /*ARGSUSED*/
        !           103:        char *file;
        !           104:        char *mode;
        !           105: {
        !           106:        ulong size;
        !           107:
        !           108:        if (mntbuf)
        !           109:                (void) free(mntbuf);
        !           110:
        !           111:        size = getfsstat((struct statfs *) NULL, 0, MNT_WAIT);
        !           112:        size *= sizeof(struct statfs);
        !           113:        mntbuf = (char *) xmalloc(size);
        !           114:
        !           115:        entries_left = getfsstat((struct statfs *)mntbuf, size, MNT_WAIT);
        !           116:        if (entries_left == -1)
        !           117:                return((FILE *) NULL);
        !           118:
        !           119:        mnt = (struct statfs *) mntbuf;
        !           120:
        !           121:        return((FILE *) 1);
        !           122: }
        !           123: #endif /* FSI_GETFSSTAT */
        !           124:
        !           125: #if    FSI_TYPE == FSI_MNTCTL
        !           126: /*
        !           127:  * AIX version of getmountent()
        !           128:  */
        !           129: /*
        !           130:  * Iterate over mount entries
        !           131:  */
        !           132: mntent_t *getmountent(fptr)
        !           133:        /*ARGSUSED*/
        !           134:        FILE *fptr;
        !           135: {
        !           136:        static mntent_t mntstruct;
        !           137:
        !           138:        if (!entries_left)
        !           139:                return((mntent_t*)0);
        !           140:
        !           141:        bzero((char *) &mntstruct, sizeof(mntstruct));
        !           142:
        !           143:        if (mnt->vmt_flags & MNT_READONLY)
        !           144:                mntstruct.me_flags |= MEFLAG_READONLY;
        !           145:
        !           146:        mntstruct.me_path = vmt2dataptr(mnt, VMT_STUB);
        !           147:        switch ((ulong)(struct vmount*)mnt->vmt_gfstype) {
        !           148:              case MNT_NFS:
        !           149:                mntstruct.me_type = METYPE_NFS;
        !           150:                break;
        !           151:              default:
        !           152:                mntstruct.me_type = METYPE_OTHER;
        !           153:                break;
        !           154:        }
        !           155:
        !           156:        mnt = (struct vmount*)((mnt->vmt_length)+(char *)mnt);
        !           157:        entries_left--;
        !           158:
        !           159:        return(&mntstruct);
        !           160: }
        !           161: #endif /* FSI_MNTCTL */
        !           162:
        !           163: #if    FSI_TYPE == FSI_GETFSSTAT
        !           164: /*
        !           165:  * getfsstat() version of getmountent()
        !           166:  */
        !           167: mntent_t *getmountent(fptr)
        !           168:        /*ARGSUSED*/
        !           169:        FILE *fptr;
        !           170: {
        !           171:        static mntent_t mntstruct;
        !           172:        static char remote_dev[MAXHOSTNAMELEN+MAXPATHLEN+1];
        !           173:
        !           174:        if (!entries_left)
        !           175:                return((mntent_t*)0);
        !           176:
        !           177:        bzero((char *) &mntstruct, sizeof(mntstruct));
        !           178:
        !           179: #if    defined(MNT_RDONLY)
        !           180:        if (mnt->f_flags & MNT_RDONLY)
        !           181:                mntstruct.me_flags |= MEFLAG_READONLY;
        !           182: #endif
        !           183: #if    defined(M_RDONLY)
        !           184:        if (mnt->f_flags & M_RDONLY)
        !           185:                mntstruct.me_flags |= MEFLAG_READONLY;
        !           186: #endif
        !           187:        if (f_type_eq (mnt, MOUNT_NFS)) {
        !           188:                (void) sprintf(remote_dev, "%s", mnt->f_mntfromname);
        !           189:                mntstruct.me_path = remote_dev;
        !           190:                mntstruct.me_type = METYPE_NFS;
        !           191:        }
        !           192:        else {
        !           193:                mntstruct.me_path = mnt->f_mntonname;
        !           194:                mntstruct.me_type = METYPE_OTHER;
        !           195:        }
        !           196:
        !           197:        mnt++;
        !           198:        entries_left--;
        !           199:
        !           200:        return(&mntstruct);
        !           201: }
        !           202: #endif
        !           203:
        !           204: #if    (FSI_TYPE == FSI_MNTCTL) || (FSI_TYPE == FSI_GETFSSTAT)
        !           205: /*
        !           206:  * Done with iterations
        !           207:  */
        !           208: void endmountent(fptr)
        !           209:        /*ARGSUSED*/
        !           210:        FILE *fptr;
        !           211: {
        !           212:        mnt = NULL;
        !           213:
        !           214:        if (mntbuf) {
        !           215:                (void) free(mntbuf);
        !           216:                mntbuf = (char *) NULL;
        !           217:        }
        !           218: }
        !           219: #endif /* FSI_MNTCTL || FSI_GETFSSTAT */
        !           220:
        !           221: #if    FSI_TYPE == FSI_GETMNTENT2
        !           222: /*
        !           223:  * Prepare to iterate over mounted filesystem list
        !           224:  */
        !           225: FILE *setmountent(file, mode)
        !           226:        /*ARGSUSED*/
        !           227:        char *file;
        !           228:        char *mode;
        !           229: {
        !           230:        return(fopen(file, mode));
        !           231: }
        !           232:
        !           233: /*
        !           234:  * Done with iteration
        !           235:  */
        !           236: void endmountent(fptr)
        !           237:        /*ARGSUSED*/
        !           238:        FILE *fptr;
        !           239: {
        !           240:        fclose(fptr);
        !           241: }
        !           242:
        !           243: /*
        !           244:  * Iterate over mount entries
        !           245:  */
        !           246: mntent_t *getmountent(fptr)
        !           247:        FILE *fptr;
        !           248: {
        !           249:        static mntent_t me;
        !           250:        static struct mnttab mntent;
        !           251:
        !           252:        bzero((char *)&me, sizeof(mntent_t));
        !           253:
        !           254: #if     defined(UNICOS)
        !           255:         if (getmntent(fptr, &mntent) != NULL) {
        !           256: #else
        !           257:         if (getmntent(fptr, &mntent) != -1) {
        !           258: #endif
        !           259:                me.me_path = mntent.mnt_mountp;
        !           260:                me.me_type = mntent.mnt_fstype;
        !           261:                if (mntent.mnt_mntopts && hasmntopt(&mntent, MNTOPT_RO))
        !           262:                        me.me_flags |= MEFLAG_READONLY;
        !           263:
        !           264: #if    defined(MNTTYPE_IGNORE)
        !           265:                if (strcmp(mntent.mnt_fstype, MNTTYPE_IGNORE) == 0)
        !           266:                        me.me_flags |= MEFLAG_IGNORE;
        !           267: #endif /* MNTTYPE_IGNORE */
        !           268: #if    defined(MNTTYPE_SWAP)
        !           269:                if (strcmp(mntent.mnt_fstype, MNTTYPE_SWAP) == 0)
        !           270:                        me.me_flags |= MEFLAG_IGNORE;
        !           271: #endif /* MNTTYPE_SWAP */
        !           272:
        !           273:                return(&me);
        !           274:        } else
        !           275:                return((mntent_t *) NULL);
        !           276: }
        !           277: #endif /* FSI_GETMNTNET2 */
        !           278:
        !           279: #if    FSI_TYPE == FSI_GETMNTENT
        !           280: /*
        !           281:  * Prepare to iterate over mounted filesystem list
        !           282:  */
        !           283: FILE *setmountent(file, mode)
        !           284:        /*ARGSUSED*/
        !           285:        char *file;
        !           286:        char *mode;
        !           287: {
        !           288:        return(setmntent(file, mode));
        !           289: }
        !           290:
        !           291: /*
        !           292:  * Done with iteration
        !           293:  */
        !           294: void endmountent(fptr)
        !           295:        /*ARGSUSED*/
        !           296:        FILE *fptr;
        !           297: {
        !           298:        endmntent(fptr);
        !           299: }
        !           300:
        !           301: /*
        !           302:  * Iterate over mount entries
        !           303:  */
        !           304: mntent_t *getmountent(fptr)
        !           305:        FILE *fptr;
        !           306: {
        !           307:        static mntent_t me;
        !           308:        struct mntent *mntent;
        !           309:
        !           310:        bzero((char *)&me, sizeof(mntent_t));
        !           311:
        !           312:        if (mntent = getmntent(fptr)) {
        !           313:                me.me_path = mntent->mnt_dir;
        !           314:                me.me_type = mntent->mnt_type;
        !           315:                if (mntent->mnt_opts && hasmntopt(mntent, MNTOPT_RO))
        !           316:                        me.me_flags |= MEFLAG_READONLY;
        !           317:
        !           318: #if    defined(MNTTYPE_IGNORE)
        !           319:                if (strcmp(mntent->mnt_type, MNTTYPE_IGNORE) == 0)
        !           320:                        me.me_flags |= MEFLAG_IGNORE;
        !           321: #endif /* MNTTYPE_IGNORE */
        !           322: #if    defined(MNTTYPE_SWAP)
        !           323:                if (strcmp(mntent->mnt_type, MNTTYPE_SWAP) == 0)
        !           324:                        me.me_flags |= MEFLAG_IGNORE;
        !           325: #endif /* MNTTYPE_SWAP */
        !           326:
        !           327:                return(&me);
        !           328:        } else
        !           329:                return((mntent_t *) NULL);
        !           330: }
        !           331: #endif /* FSI_GETMNTNET */
        !           332:
        !           333: #if    FSI_TYPE == FSI_GETMNT
        !           334: /*
        !           335:  * getmnt() interface (Ultrix)
        !           336:  */
        !           337:
        !           338: #include <sys/fs_types.h>
        !           339:
        !           340: static int startmounts = 0;
        !           341:
        !           342: FILE *setmountent(file, mode)
        !           343:        /*ARGSUSED*/
        !           344:        char *file;
        !           345:        char *mode;
        !           346: {
        !           347:        startmounts = 0;
        !           348: }
        !           349:
        !           350: void endmountent(fptr)
        !           351:        /*ARGSUSED*/
        !           352:        FILE *fptr;
        !           353: {
        !           354:        /* NOOP */
        !           355: }
        !           356:
        !           357: /*
        !           358:  * Iterate over mounted filesystems using getmnt()
        !           359:  */
        !           360: mntent_t *getmountent(fptr)
        !           361:        /*ARGSUSED*/
        !           362:        FILE *fptr;
        !           363: {
        !           364:        struct fs_data fs_data;
        !           365:        static mntent_t me;
        !           366:
        !           367:        if (getmnt(&startmounts, &fs_data, sizeof(fs_data), NOSTAT_MANY,
        !           368:                   (char *) NULL) <= 0)
        !           369:                return((mntent_t *) NULL);
        !           370:
        !           371:        bzero((char *)&me, sizeof(mntent_t));
        !           372:        me.me_path = fs_data.fd_path;
        !           373:        if (fs_data.fd_fstype == GT_NFS)
        !           374:                me.me_type = METYPE_NFS;
        !           375:        else
        !           376:                me.me_type = METYPE_OTHER;
        !           377:
        !           378:        if (fs_data.fd_flags & M_RONLY)
        !           379:                me.me_flags |= MEFLAG_READONLY;
        !           380:
        !           381:        return(&me);
        !           382: }
        !           383: #endif /* FSI_GETMNT */
        !           384:
        !           385: /*
        !           386:  * Make a new (copy) of a mntent structure.
        !           387:  */
        !           388: mntent_t *newmountent(old)
        !           389:        mntent_t *old;
        !           390: {
        !           391:        mntent_t *new;
        !           392:
        !           393:        if (!old)
        !           394:                return((mntent_t *) NULL);
        !           395:
        !           396:        new = (mntent_t *) xcalloc(1, sizeof(mntent_t));
        !           397:        new->me_path = strdup(old->me_path);
        !           398:        new->me_type = strdup(old->me_type);
        !           399:        new->me_flags = old->me_flags;
        !           400:
        !           401:        return(new);
        !           402: }