Home | History | Annotate | Line # | Download | only in chfs
chfs_vnode.c revision 1.8
      1  1.8  ttoth /*	$NetBSD: chfs_vnode.c,v 1.8 2012/10/19 12:44:39 ttoth Exp $	*/
      2  1.1  ahoka 
      3  1.1  ahoka /*-
      4  1.1  ahoka  * Copyright (c) 2010 Department of Software Engineering,
      5  1.1  ahoka  *		      University of Szeged, Hungary
      6  1.1  ahoka  * Copyright (C) 2010 Tamas Toth <ttoth (at) inf.u-szeged.hu>
      7  1.1  ahoka  * Copyright (C) 2010 Adam Hoka <ahoka (at) NetBSD.org>
      8  1.1  ahoka  * All rights reserved.
      9  1.1  ahoka  *
     10  1.1  ahoka  * This code is derived from software contributed to The NetBSD Foundation
     11  1.1  ahoka  * by the Department of Software Engineering, University of Szeged, Hungary
     12  1.1  ahoka  *
     13  1.1  ahoka  * Redistribution and use in source and binary forms, with or without
     14  1.1  ahoka  * modification, are permitted provided that the following conditions
     15  1.1  ahoka  * are met:
     16  1.1  ahoka  * 1. Redistributions of source code must retain the above copyright
     17  1.1  ahoka  *    notice, this list of conditions and the following disclaimer.
     18  1.1  ahoka  * 2. Redistributions in binary form must reproduce the above copyright
     19  1.1  ahoka  *    notice, this list of conditions and the following disclaimer in the
     20  1.1  ahoka  *    documentation and/or other materials provided with the distribution.
     21  1.1  ahoka  *
     22  1.1  ahoka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1  ahoka  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1  ahoka  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1  ahoka  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1  ahoka  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     27  1.1  ahoka  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     28  1.1  ahoka  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     29  1.1  ahoka  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     30  1.1  ahoka  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1  ahoka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1  ahoka  * SUCH DAMAGE.
     33  1.1  ahoka  */
     34  1.1  ahoka 
     35  1.1  ahoka #include "chfs.h"
     36  1.1  ahoka #include "chfs_inode.h"
     37  1.1  ahoka #include <sys/malloc.h>
     38  1.1  ahoka #include <sys/kauth.h>
     39  1.1  ahoka #include <sys/namei.h>
     40  1.1  ahoka #include <sys/uio.h>
     41  1.1  ahoka #include <sys/buf.h>
     42  1.1  ahoka 
     43  1.3   elad #include <miscfs/genfs/genfs.h>
     44  1.3   elad 
     45  1.8  ttoth /* chfs_vnode_lookup - lookup for a vnode */
     46  1.1  ahoka struct vnode *
     47  1.1  ahoka chfs_vnode_lookup(struct chfs_mount *chmp, ino_t vno)
     48  1.1  ahoka {
     49  1.1  ahoka 	struct vnode *vp;
     50  1.1  ahoka 	struct chfs_inode *ip;
     51  1.1  ahoka 
     52  1.1  ahoka 	TAILQ_FOREACH(vp, &chmp->chm_fsmp->mnt_vnodelist, v_mntvnodes) {
     53  1.1  ahoka 		ip = VTOI(vp);
     54  1.1  ahoka 		if (ip && ip->ino == vno)
     55  1.1  ahoka 			return vp;
     56  1.1  ahoka 	}
     57  1.1  ahoka 	return NULL;
     58  1.1  ahoka }
     59  1.1  ahoka 
     60  1.8  ttoth /* chfs_readvnode - reads a vnode from the flash and setups its inode */
     61  1.1  ahoka int
     62  1.8  ttoth chfs_readvnode(struct mount *mp, ino_t ino, struct vnode **vpp)
     63  1.1  ahoka {
     64  1.1  ahoka 	struct ufsmount* ump = VFSTOUFS(mp);
     65  1.1  ahoka 	struct chfs_mount *chmp = ump->um_chfs;
     66  1.1  ahoka 	struct chfs_vnode_cache *chvc;
     67  1.1  ahoka 	struct chfs_flash_vnode *chfvn;
     68  1.1  ahoka 	struct chfs_inode *ip;
     69  1.1  ahoka 	int err;
     70  1.1  ahoka 	char* buf;
     71  1.1  ahoka 	size_t retlen, len;
     72  1.1  ahoka 	struct vnode* vp = NULL;
     73  1.2    agc 	dbg("readvnode | ino: %llu\n", (unsigned long long)ino);
     74  1.1  ahoka 
     75  1.1  ahoka 	len = sizeof(struct chfs_flash_vnode);
     76  1.1  ahoka 
     77  1.1  ahoka 	KASSERT(vpp != NULL);
     78  1.1  ahoka 
     79  1.1  ahoka 	if (vpp != NULL) {
     80  1.1  ahoka 		vp = *vpp;
     81  1.1  ahoka 	}
     82  1.1  ahoka 
     83  1.1  ahoka 	ip = VTOI(vp);
     84  1.1  ahoka 	chvc = ip->chvc;
     85  1.1  ahoka 
     86  1.8  ttoth 	/* root node is in-memory only */
     87  1.1  ahoka 	if (chvc && ino != CHFS_ROOTINO) {
     88  1.7  ttoth 		dbg("offset: %" PRIu32 ", lnr: %d\n",
     89  1.1  ahoka 		    CHFS_GET_OFS(chvc->v->nref_offset), chvc->v->nref_lnr);
     90  1.1  ahoka 
     91  1.1  ahoka 		KASSERT((void *)chvc != (void *)chvc->v);
     92  1.1  ahoka 
     93  1.8  ttoth 		/* reading */
     94  1.1  ahoka 		buf = kmem_alloc(len, KM_SLEEP);
     95  1.1  ahoka 		err = chfs_read_leb(chmp, chvc->v->nref_lnr, buf,
     96  1.1  ahoka 		    CHFS_GET_OFS(chvc->v->nref_offset), len, &retlen);
     97  1.1  ahoka 		if (err)
     98  1.1  ahoka 			return err;
     99  1.1  ahoka 		if (retlen != len) {
    100  1.1  ahoka 			chfs_err("Error reading vnode: read: %zu insted of: %zu\n",
    101  1.1  ahoka 			    len, retlen);
    102  1.1  ahoka 			return EIO;
    103  1.1  ahoka 		}
    104  1.1  ahoka 		chfvn = (struct chfs_flash_vnode*)buf;
    105  1.8  ttoth 
    106  1.8  ttoth 		/* setup inode fields */
    107  1.1  ahoka 		chfs_set_vnode_size(vp, chfvn->dn_size);
    108  1.1  ahoka 		ip->mode = chfvn->mode;
    109  1.4  ttoth 		ip->ch_type = IFTOCHT(ip->mode);
    110  1.4  ttoth 		vp->v_type = CHTTOVT(ip->ch_type);
    111  1.1  ahoka 		ip->version = chfvn->version;
    112  1.1  ahoka 		ip->uid = chfvn->uid;
    113  1.1  ahoka 		ip->gid = chfvn->gid;
    114  1.1  ahoka 		ip->atime = chfvn->atime;
    115  1.1  ahoka 		ip->mtime = chfvn->mtime;
    116  1.1  ahoka 		ip->ctime = chfvn->ctime;
    117  1.8  ttoth 
    118  1.1  ahoka 		kmem_free(buf, len);
    119  1.1  ahoka 	}
    120  1.1  ahoka 
    121  1.1  ahoka 
    122  1.1  ahoka 	*vpp = vp;
    123  1.1  ahoka 	return 0;
    124  1.1  ahoka }
    125  1.1  ahoka 
    126  1.8  ttoth /*
    127  1.8  ttoth  * chfs_readddirent -
    128  1.8  ttoth  * reads a directory entry from flash and adds it to its inode
    129  1.8  ttoth  */
    130  1.1  ahoka int
    131  1.1  ahoka chfs_readdirent(struct mount *mp, struct chfs_node_ref *chnr, struct chfs_inode *pdir)
    132  1.1  ahoka {
    133  1.1  ahoka 	struct ufsmount *ump = VFSTOUFS(mp);
    134  1.1  ahoka 	struct chfs_mount *chmp = ump->um_chfs;
    135  1.1  ahoka 	struct chfs_flash_dirent_node chfdn;
    136  1.8  ttoth 	struct chfs_dirent *fd;
    137  1.1  ahoka 	size_t len = sizeof(struct chfs_flash_dirent_node);
    138  1.1  ahoka 	size_t retlen;
    139  1.1  ahoka 	int err = 0;
    140  1.1  ahoka 
    141  1.8  ttoth 	/* read flash_dirent_node */
    142  1.1  ahoka 	err = chfs_read_leb(chmp, chnr->nref_lnr, (char *)&chfdn,
    143  1.1  ahoka 	    CHFS_GET_OFS(chnr->nref_offset), len, &retlen);
    144  1.1  ahoka 	if (err) {
    145  1.1  ahoka 		return err;
    146  1.1  ahoka 	}
    147  1.1  ahoka 	if (retlen != len) {
    148  1.1  ahoka 		chfs_err("Error reading vnode: read: %zu insted of: %zu\n",
    149  1.1  ahoka 		    retlen, len);
    150  1.1  ahoka 		return EIO;
    151  1.1  ahoka 	}
    152  1.1  ahoka 
    153  1.8  ttoth 	/* set fields of dirent */
    154  1.1  ahoka 	fd = chfs_alloc_dirent(chfdn.nsize + 1);
    155  1.1  ahoka 	fd->version = chfdn.version;
    156  1.1  ahoka 	fd->vno = chfdn.vno;
    157  1.1  ahoka 	fd->type = chfdn.dtype;
    158  1.1  ahoka 	fd->nsize = chfdn.nsize;
    159  1.1  ahoka 
    160  1.8  ttoth 	/* read the name of the dirent */
    161  1.1  ahoka 	err = chfs_read_leb(chmp, chnr->nref_lnr, fd->name,
    162  1.1  ahoka 	    CHFS_GET_OFS(chnr->nref_offset) + len, chfdn.nsize, &retlen);
    163  1.1  ahoka 	if (err) {
    164  1.1  ahoka 		return err;
    165  1.1  ahoka 	}
    166  1.1  ahoka 
    167  1.1  ahoka 	if (retlen != chfdn.nsize) {
    168  1.1  ahoka 		chfs_err("Error reading vnode: read: %zu insted of: %zu\n",
    169  1.1  ahoka 		    len, retlen);
    170  1.1  ahoka 		return EIO;
    171  1.1  ahoka 	}
    172  1.1  ahoka 
    173  1.1  ahoka 	fd->name[fd->nsize] = 0;
    174  1.1  ahoka 	fd->nref = chnr;
    175  1.1  ahoka 
    176  1.8  ttoth 	/* add to inode */
    177  1.1  ahoka 	chfs_add_fd_to_inode(chmp, pdir, fd);
    178  1.1  ahoka 	return 0;
    179  1.1  ahoka }
    180  1.1  ahoka 
    181  1.8  ttoth /* chfs_makeinode - makes a new file and initializes its structures */
    182  1.1  ahoka int
    183  1.1  ahoka chfs_makeinode(int mode, struct vnode *dvp, struct vnode **vpp,
    184  1.4  ttoth     struct componentname *cnp, enum vtype type)
    185  1.1  ahoka {
    186  1.1  ahoka 	struct chfs_inode *ip, *pdir;
    187  1.1  ahoka 	struct vnode *vp;
    188  1.1  ahoka 	struct ufsmount* ump = VFSTOUFS(dvp->v_mount);
    189  1.1  ahoka 	struct chfs_mount* chmp = ump->um_chfs;
    190  1.1  ahoka 	struct chfs_vnode_cache* chvc;
    191  1.3   elad 	int error;
    192  1.1  ahoka 	ino_t vno;
    193  1.8  ttoth 	struct chfs_dirent *nfd;
    194  1.1  ahoka 
    195  1.1  ahoka 	dbg("makeinode\n");
    196  1.1  ahoka 	pdir = VTOI(dvp);
    197  1.1  ahoka 
    198  1.1  ahoka 	*vpp = NULL;
    199  1.1  ahoka 
    200  1.8  ttoth 	/* number of vnode will be the new maximum */
    201  1.1  ahoka 	vno = ++(chmp->chm_max_vno);
    202  1.1  ahoka 
    203  1.1  ahoka 	error = VFS_VGET(dvp->v_mount, vno, &vp);
    204  1.1  ahoka 	if (error)
    205  1.1  ahoka 		return (error);
    206  1.1  ahoka 
    207  1.8  ttoth 	/* setup vnode cache */
    208  1.1  ahoka 	mutex_enter(&chmp->chm_lock_vnocache);
    209  1.1  ahoka 	chvc = chfs_vnode_cache_get(chmp, vno);
    210  1.1  ahoka 
    211  1.1  ahoka 	chvc->pvno = pdir->ino;
    212  1.1  ahoka 	chvc->vno_version = kmem_alloc(sizeof(uint64_t), KM_SLEEP);
    213  1.1  ahoka 	*(chvc->vno_version) = 1;
    214  1.1  ahoka 	if (type != VDIR)
    215  1.1  ahoka 		chvc->nlink = 1;
    216  1.1  ahoka 	else
    217  1.1  ahoka 		chvc->nlink = 2;
    218  1.1  ahoka 	chvc->state = VNO_STATE_CHECKEDABSENT;
    219  1.6  ttoth 	mutex_exit(&chmp->chm_lock_vnocache);
    220  1.1  ahoka 
    221  1.8  ttoth 	/* setup inode */
    222  1.1  ahoka 	ip = VTOI(vp);
    223  1.1  ahoka 	ip->ino = vno;
    224  1.1  ahoka 
    225  1.1  ahoka 	if (type == VDIR)
    226  1.1  ahoka 		chfs_set_vnode_size(vp, 512);
    227  1.1  ahoka 	else
    228  1.1  ahoka 		chfs_set_vnode_size(vp, 0);
    229  1.1  ahoka 
    230  1.1  ahoka 	ip->uid = kauth_cred_geteuid(cnp->cn_cred);
    231  1.1  ahoka 	ip->gid = kauth_cred_getegid(cnp->cn_cred);
    232  1.1  ahoka 	ip->version = 1;
    233  1.1  ahoka 	ip->iflag |= (IN_ACCESS | IN_CHANGE | IN_UPDATE);
    234  1.1  ahoka 
    235  1.1  ahoka 	ip->chvc = chvc;
    236  1.1  ahoka 	ip->target = NULL;
    237  1.1  ahoka 
    238  1.1  ahoka 	ip->mode = mode;
    239  1.4  ttoth 	vp->v_type = type;		/* Rest init'd in getnewvnode(). */
    240  1.4  ttoth 	ip->ch_type = VTTOCHT(vp->v_type);
    241  1.3   elad 
    242  1.8  ttoth 	/* authorize setting SGID if needed */
    243  1.3   elad 	if (ip->mode & ISGID) {
    244  1.3   elad 		error = kauth_authorize_vnode(cnp->cn_cred, KAUTH_VNODE_WRITE_SECURITY,
    245  1.3   elad 		    vp, NULL, genfs_can_chmod(vp->v_type, cnp->cn_cred, ip->uid,
    246  1.3   elad 		    ip->gid, mode));
    247  1.3   elad 		if (error)
    248  1.3   elad 			ip->mode &= ~ISGID;
    249  1.3   elad 	}
    250  1.1  ahoka 
    251  1.8  ttoth 	/* write vnode information to the flash */
    252  1.1  ahoka 	chfs_update(vp, NULL, NULL, UPDATE_WAIT);
    253  1.1  ahoka 
    254  1.1  ahoka 	mutex_enter(&chmp->chm_lock_mountfields);
    255  1.1  ahoka 
    256  1.1  ahoka 	error = chfs_write_flash_vnode(chmp, ip, ALLOC_NORMAL);
    257  1.1  ahoka 	if (error) {
    258  1.1  ahoka 		mutex_exit(&chmp->chm_lock_mountfields);
    259  1.1  ahoka 		vput(vp);
    260  1.1  ahoka 		vput(dvp);
    261  1.1  ahoka 		return error;
    262  1.1  ahoka 	}
    263  1.8  ttoth 
    264  1.8  ttoth 	/* update parent's vnode information and write it to the flash */
    265  1.1  ahoka 	pdir->iflag |= (IN_ACCESS | IN_CHANGE | IN_MODIFY | IN_UPDATE);
    266  1.1  ahoka 	chfs_update(dvp, NULL, NULL, UPDATE_WAIT);
    267  1.1  ahoka 
    268  1.1  ahoka 	error = chfs_write_flash_vnode(chmp, pdir, ALLOC_NORMAL);
    269  1.1  ahoka 	if (error) {
    270  1.1  ahoka 		mutex_exit(&chmp->chm_lock_mountfields);
    271  1.1  ahoka 		vput(vp);
    272  1.1  ahoka 		vput(dvp);
    273  1.1  ahoka 		return error;
    274  1.1  ahoka 	}
    275  1.1  ahoka 	vput(dvp);
    276  1.1  ahoka 
    277  1.8  ttoth 	/* setup directory entry */
    278  1.1  ahoka 	nfd = chfs_alloc_dirent(cnp->cn_namelen + 1);
    279  1.1  ahoka 	nfd->vno = ip->ino;
    280  1.1  ahoka 	nfd->version = (++pdir->chvc->highest_version);
    281  1.4  ttoth 	nfd->type = ip->ch_type;
    282  1.1  ahoka 	nfd->nsize = cnp->cn_namelen;
    283  1.1  ahoka 	memcpy(&(nfd->name), cnp->cn_nameptr, cnp->cn_namelen);
    284  1.1  ahoka 	nfd->name[nfd->nsize] = 0;
    285  1.1  ahoka 	nfd->nhash = hash32_buf(nfd->name, cnp->cn_namelen, HASH32_BUF_INIT);
    286  1.1  ahoka 
    287  1.8  ttoth 	/* write out */
    288  1.1  ahoka 	error = chfs_write_flash_dirent(chmp, pdir, ip, nfd, ip->ino, ALLOC_NORMAL);
    289  1.1  ahoka 	if (error) {
    290  1.1  ahoka         mutex_exit(&chmp->chm_lock_mountfields);
    291  1.1  ahoka 		vput(vp);
    292  1.1  ahoka 		return error;
    293  1.1  ahoka 	}
    294  1.1  ahoka 
    295  1.1  ahoka 	//TODO set parent's dir times
    296  1.1  ahoka 
    297  1.8  ttoth 	/* add dirent to parent */
    298  1.1  ahoka 	chfs_add_fd_to_inode(chmp, pdir, nfd);
    299  1.8  ttoth 
    300  1.1  ahoka 	pdir->chvc->nlink++;
    301  1.1  ahoka 
    302  1.1  ahoka 	mutex_exit(&chmp->chm_lock_mountfields);
    303  1.1  ahoka 
    304  1.1  ahoka 	*vpp = vp;
    305  1.1  ahoka 	return (0);
    306  1.1  ahoka }
    307  1.1  ahoka 
    308  1.8  ttoth /* chfs_set_vnode_size - updates size of vnode and also inode */
    309  1.1  ahoka void
    310  1.1  ahoka chfs_set_vnode_size(struct vnode *vp, size_t size)
    311  1.1  ahoka {
    312  1.1  ahoka 	struct chfs_inode *ip;
    313  1.1  ahoka 
    314  1.1  ahoka 	KASSERT(vp != NULL);
    315  1.1  ahoka 
    316  1.1  ahoka 	ip = VTOI(vp);
    317  1.1  ahoka 	KASSERT(ip != NULL);
    318  1.1  ahoka 
    319  1.1  ahoka 	ip->size = size;
    320  1.1  ahoka 	vp->v_size = vp->v_writesize = size;
    321  1.1  ahoka 	return;
    322  1.1  ahoka }
    323  1.1  ahoka 
    324  1.8  ttoth /*
    325  1.8  ttoth  * chfs_change_size_free - updates free size
    326  1.8  ttoth  * "change" parameter is positive if we have to increase the size
    327  1.8  ttoth  * and negative if we have to decrease it
    328  1.8  ttoth  */
    329  1.1  ahoka void
    330  1.1  ahoka chfs_change_size_free(struct chfs_mount *chmp,
    331  1.1  ahoka 	struct chfs_eraseblock *cheb, int change)
    332  1.1  ahoka {
    333  1.1  ahoka 	KASSERT(mutex_owned(&chmp->chm_lock_sizes));
    334  1.1  ahoka 	KASSERT((int)(chmp->chm_free_size + change) >= 0);
    335  1.1  ahoka 	KASSERT((int)(cheb->free_size + change) >= 0);
    336  1.1  ahoka 	KASSERT((int)(cheb->free_size + change) <= chmp->chm_ebh->eb_size);
    337  1.1  ahoka 	chmp->chm_free_size += change;
    338  1.1  ahoka 	cheb->free_size += change;
    339  1.1  ahoka 	return;
    340  1.1  ahoka }
    341  1.1  ahoka 
    342  1.8  ttoth /*
    343  1.8  ttoth  * chfs_change_size_dirty - updates dirty size
    344  1.8  ttoth  * "change" parameter is positive if we have to increase the size
    345  1.8  ttoth  * and negative if we have to decrease it
    346  1.8  ttoth  */
    347  1.1  ahoka void
    348  1.1  ahoka chfs_change_size_dirty(struct chfs_mount *chmp,
    349  1.1  ahoka 	struct chfs_eraseblock *cheb, int change)
    350  1.1  ahoka {
    351  1.1  ahoka 	KASSERT(mutex_owned(&chmp->chm_lock_sizes));
    352  1.1  ahoka 	KASSERT((int)(chmp->chm_dirty_size + change) >= 0);
    353  1.1  ahoka 	KASSERT((int)(cheb->dirty_size + change) >= 0);
    354  1.1  ahoka 	KASSERT((int)(cheb->dirty_size + change) <= chmp->chm_ebh->eb_size);
    355  1.1  ahoka 	chmp->chm_dirty_size += change;
    356  1.1  ahoka 	cheb->dirty_size += change;
    357  1.1  ahoka 	return;
    358  1.1  ahoka }
    359  1.1  ahoka 
    360  1.8  ttoth /*
    361  1.8  ttoth  * chfs_change_size_unchecked - updates unchecked size
    362  1.8  ttoth  * "change" parameter is positive if we have to increase the size
    363  1.8  ttoth  * and negative if we have to decrease it
    364  1.8  ttoth  */
    365  1.1  ahoka void
    366  1.1  ahoka chfs_change_size_unchecked(struct chfs_mount *chmp,
    367  1.1  ahoka 	struct chfs_eraseblock *cheb, int change)
    368  1.1  ahoka {
    369  1.1  ahoka 	KASSERT(mutex_owned(&chmp->chm_lock_sizes));
    370  1.1  ahoka 	KASSERT((int)(chmp->chm_unchecked_size + change) >= 0);
    371  1.1  ahoka 	KASSERT((int)(cheb->unchecked_size + change) >= 0);
    372  1.1  ahoka 	KASSERT((int)(cheb->unchecked_size + change) <= chmp->chm_ebh->eb_size);
    373  1.1  ahoka 	chmp->chm_unchecked_size += change;
    374  1.1  ahoka 	cheb->unchecked_size += change;
    375  1.1  ahoka 	return;
    376  1.1  ahoka }
    377  1.1  ahoka 
    378  1.8  ttoth /*
    379  1.8  ttoth  * chfs_change_size_used - updates used size
    380  1.8  ttoth  * "change" parameter is positive if we have to increase the size
    381  1.8  ttoth  * and negative if we have to decrease it
    382  1.8  ttoth  */
    383  1.1  ahoka void
    384  1.1  ahoka chfs_change_size_used(struct chfs_mount *chmp,
    385  1.1  ahoka 	struct chfs_eraseblock *cheb, int change)
    386  1.1  ahoka {
    387  1.1  ahoka 	KASSERT(mutex_owned(&chmp->chm_lock_sizes));
    388  1.1  ahoka 	KASSERT((int)(chmp->chm_used_size + change) >= 0);
    389  1.1  ahoka 	KASSERT((int)(cheb->used_size + change) >= 0);
    390  1.1  ahoka 	KASSERT((int)(cheb->used_size + change) <= chmp->chm_ebh->eb_size);
    391  1.1  ahoka 	chmp->chm_used_size += change;
    392  1.1  ahoka 	cheb->used_size += change;
    393  1.1  ahoka 	return;
    394  1.1  ahoka }
    395  1.1  ahoka 
    396  1.8  ttoth /*
    397  1.8  ttoth  * chfs_change_size_wasted - updates wasted size
    398  1.8  ttoth  * "change" parameter is positive if we have to increase the size
    399  1.8  ttoth  * and negative if we have to decrease it
    400  1.8  ttoth  */
    401  1.1  ahoka void
    402  1.1  ahoka chfs_change_size_wasted(struct chfs_mount *chmp,
    403  1.1  ahoka 	struct chfs_eraseblock *cheb, int change)
    404  1.1  ahoka {
    405  1.1  ahoka 	KASSERT(mutex_owned(&chmp->chm_lock_sizes));
    406  1.1  ahoka 	KASSERT((int)(chmp->chm_wasted_size + change) >= 0);
    407  1.1  ahoka 	KASSERT((int)(cheb->wasted_size + change) >= 0);
    408  1.1  ahoka 	KASSERT((int)(cheb->wasted_size + change) <= chmp->chm_ebh->eb_size);
    409  1.1  ahoka 	chmp->chm_wasted_size += change;
    410  1.1  ahoka 	cheb->wasted_size += change;
    411  1.1  ahoka 	return;
    412  1.1  ahoka }
    413  1.1  ahoka 
    414