[BACK]Return to ufs_vfsops.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / ufs / ufs

Annotation of src/sys/ufs/ufs/ufs_vfsops.c, Revision 1.33.2.1

1.33.2.1! mjf         1: /*     $NetBSD: ufs_vfsops.c,v 1.34 2007/06/30 09:37:54 pooka Exp $    */
1.2       cgd         2:
1.1       mycroft     3: /*
                      4:  * Copyright (c) 1991, 1993, 1994
                      5:  *     The Regents of the University of California.  All rights reserved.
                      6:  * (c) UNIX System Laboratories, Inc.
                      7:  * All or some portions of this file are derived from material licensed
                      8:  * to the University of California by American Telephone and Telegraph
                      9:  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
                     10:  * the permission of UNIX System Laboratories, Inc.
                     11:  *
                     12:  * Redistribution and use in source and binary forms, with or without
                     13:  * modification, are permitted provided that the following conditions
                     14:  * are met:
                     15:  * 1. Redistributions of source code must retain the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer.
                     17:  * 2. Redistributions in binary form must reproduce the above copyright
                     18:  *    notice, this list of conditions and the following disclaimer in the
                     19:  *    documentation and/or other materials provided with the distribution.
1.18      agc        20:  * 3. Neither the name of the University nor the names of its contributors
1.1       mycroft    21:  *    may be used to endorse or promote products derived from this software
                     22:  *    without specific prior written permission.
                     23:  *
                     24:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     25:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     26:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     27:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     28:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     29:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     30:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     31:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     32:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     33:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     34:  * SUCH DAMAGE.
                     35:  *
1.6       fvdl       36:  *     @(#)ufs_vfsops.c        8.8 (Berkeley) 5/20/95
1.1       mycroft    37:  */
1.13      lukem      38:
                     39: #include <sys/cdefs.h>
1.33.2.1! mjf        40: __KERNEL_RCSID(0, "$NetBSD: ufs_vfsops.c,v 1.34 2007/06/30 09:37:54 pooka Exp $");
1.7       scottr     41:
1.21      dbj        42: #if defined(_KERNEL_OPT)
1.24      thorpej    43: #include "opt_ffs.h"
1.7       scottr     44: #include "opt_quota.h"
1.21      dbj        45: #endif
1.1       mycroft    46:
                     47: #include <sys/param.h>
                     48: #include <sys/mbuf.h>
                     49: #include <sys/mount.h>
                     50: #include <sys/proc.h>
                     51: #include <sys/buf.h>
                     52: #include <sys/vnode.h>
                     53: #include <sys/malloc.h>
1.27      elad       54: #include <sys/kauth.h>
1.1       mycroft    55:
                     56: #include <miscfs/specfs/specdev.h>
                     57:
                     58: #include <ufs/ufs/quota.h>
                     59: #include <ufs/ufs/inode.h>
                     60: #include <ufs/ufs/ufsmount.h>
                     61: #include <ufs/ufs/ufs_extern.h>
1.22      rumble     62: #ifdef UFS_DIRHASH
                     63: #include <ufs/ufs/dirhash.h>
                     64: #endif
1.1       mycroft    65:
1.10      jdolecek   66: /* how many times ufs_init() was called */
1.23      thorpej    67: static int ufs_initcount = 0;
1.10      jdolecek   68:
1.33.2.1! mjf        69: struct pool ufs_direct_pool;
1.20      hannken    70:
1.1       mycroft    71: /*
                     72:  * Make a filesystem operational.
                     73:  * Nothing to do at the moment.
                     74:  */
                     75: /* ARGSUSED */
                     76: int
1.31      christos   77: ufs_start(struct mount *mp, int flags, struct lwp *l)
1.1       mycroft    78: {
                     79:
                     80:        return (0);
                     81: }
                     82:
                     83: /*
                     84:  * Return the root of a filesystem.
                     85:  */
                     86: int
1.23      thorpej    87: ufs_root(struct mount *mp, struct vnode **vpp)
1.1       mycroft    88: {
                     89:        struct vnode *nvp;
                     90:        int error;
                     91:
1.16      thorpej    92:        if ((error = VFS_VGET(mp, (ino_t)ROOTINO, &nvp)) != 0)
1.1       mycroft    93:                return (error);
                     94:        *vpp = nvp;
                     95:        return (0);
                     96: }
                     97:
                     98: /*
                     99:  * Do operations associated with quotas
                    100:  */
                    101: int
1.26      christos  102: ufs_quotactl(struct mount *mp, int cmds, uid_t uid, void *arg, struct lwp *l)
1.1       mycroft   103: {
                    104:
                    105: #ifndef QUOTA
1.30      thorpej   106:        (void) mp;
                    107:        (void) cmds;
                    108:        (void) uid;
                    109:        (void) arg;
                    110:        (void) l;
1.1       mycroft   111:        return (EOPNOTSUPP);
                    112: #else
1.4       christos  113:        int cmd, type, error;
                    114:
1.1       mycroft   115:        if (uid == -1)
1.28      ad        116:                uid = kauth_cred_getuid(l->l_cred);
1.1       mycroft   117:        cmd = cmds >> SUBCMDSHIFT;
                    118:
                    119:        switch (cmd) {
1.3       cgd       120:        case Q_SYNC:
                    121:                break;
1.1       mycroft   122:        case Q_GETQUOTA:
1.28      ad        123:                if (uid == kauth_cred_getuid(l->l_cred))
1.1       mycroft   124:                        break;
                    125:                /* fall through */
                    126:        default:
1.28      ad        127:                if ((error = kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER,
1.32      elad      128:                    NULL)) != 0)
1.1       mycroft   129:                        return (error);
                    130:        }
                    131:
1.3       cgd       132:        type = cmds & SUBCMDMASK;
1.1       mycroft   133:        if ((u_int)type >= MAXQUOTAS)
                    134:                return (EINVAL);
1.6       fvdl      135:        if (vfs_busy(mp, LK_NOWAIT, 0))
                    136:                return (0);
1.1       mycroft   137:
                    138:        switch (cmd) {
                    139:
                    140:        case Q_QUOTAON:
1.26      christos  141:                error = quotaon(l, mp, type, arg);
1.6       fvdl      142:                break;
1.1       mycroft   143:
                    144:        case Q_QUOTAOFF:
1.26      christos  145:                error = quotaoff(l, mp, type);
1.6       fvdl      146:                break;
1.1       mycroft   147:
                    148:        case Q_SETQUOTA:
1.6       fvdl      149:                error = setquota(mp, uid, type, arg);
                    150:                break;
1.1       mycroft   151:
                    152:        case Q_SETUSE:
1.6       fvdl      153:                error = setuse(mp, uid, type, arg);
                    154:                break;
1.1       mycroft   155:
                    156:        case Q_GETQUOTA:
1.8       mrg       157:                error = getquota(mp, uid, type, arg);
1.6       fvdl      158:                break;
1.1       mycroft   159:
                    160:        case Q_SYNC:
1.17      fvdl      161:                error = qsync(mp);
1.6       fvdl      162:                break;
1.1       mycroft   163:
                    164:        default:
1.6       fvdl      165:                error = EINVAL;
1.1       mycroft   166:        }
1.6       fvdl      167:        vfs_unbusy(mp);
                    168:        return (error);
1.1       mycroft   169: #endif
                    170: }
                    171:
                    172: /*
1.9       wrstuden  173:  * This is the generic part of fhtovp called after the underlying
                    174:  * filesystem has validated the file handle.
                    175:  */
                    176: int
1.23      thorpej   177: ufs_fhtovp(struct mount *mp, struct ufid *ufhp, struct vnode **vpp)
1.9       wrstuden  178: {
                    179:        struct vnode *nvp;
1.11      augustss  180:        struct inode *ip;
1.9       wrstuden  181:        int error;
                    182:
1.16      thorpej   183:        if ((error = VFS_VGET(mp, ufhp->ufid_ino, &nvp)) != 0) {
1.1       mycroft   184:                *vpp = NULLVP;
                    185:                return (error);
                    186:        }
                    187:        ip = VTOI(nvp);
1.14      fvdl      188:        if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen) {
1.1       mycroft   189:                vput(nvp);
                    190:                *vpp = NULLVP;
                    191:                return (ESTALE);
                    192:        }
                    193:        *vpp = nvp;
                    194:        return (0);
1.6       fvdl      195: }
                    196:
                    197: /*
                    198:  * Initialize UFS filesystems, done only once.
                    199:  */
                    200: void
1.23      thorpej   201: ufs_init(void)
1.6       fvdl      202: {
1.10      jdolecek  203:        if (ufs_initcount++ > 0)
                    204:                return;
1.6       fvdl      205:
1.21      dbj       206:        pool_init(&ufs_direct_pool, sizeof(struct direct), 0, 0, 0, "ufsdirpl",
1.33      ad        207:            &pool_allocator_nointr, IPL_NONE);
1.20      hannken   208:
1.6       fvdl      209:        ufs_ihashinit();
                    210: #ifdef QUOTA
                    211:        dqinit();
1.12      chs       212: #endif
1.22      rumble    213: #ifdef UFS_DIRHASH
                    214:        ufsdirhash_init();
                    215: #endif
1.33.2.1! mjf       216: #ifdef UFS_EXTATTR
        !           217:        ufs_extattr_init();
        !           218: #endif
1.12      chs       219: }
                    220:
                    221: void
1.23      thorpej   222: ufs_reinit(void)
1.12      chs       223: {
                    224:        ufs_ihashreinit();
                    225: #ifdef QUOTA
                    226:        dqreinit();
1.10      jdolecek  227: #endif
                    228: }
                    229:
                    230: /*
                    231:  * Free UFS filesystem resources, done only once.
                    232:  */
                    233: void
1.23      thorpej   234: ufs_done(void)
1.10      jdolecek  235: {
                    236:        if (--ufs_initcount > 0)
                    237:                return;
                    238:
                    239:        ufs_ihashdone();
                    240: #ifdef QUOTA
                    241:        dqdone();
1.6       fvdl      242: #endif
1.20      hannken   243:        pool_destroy(&ufs_direct_pool);
1.22      rumble    244: #ifdef UFS_DIRHASH
                    245:        ufsdirhash_done();
                    246: #endif
1.33.2.1! mjf       247: #ifdef UFS_EXTATTR
        !           248:        ufs_extattr_done();
        !           249: #endif
1.1       mycroft   250: }

CVSweb <webmaster@jp.NetBSD.org>