Home | History | Annotate | Line # | Download | only in lfs
      1  1.4     skrll /*	$NetBSD: ulfs_quota1_subr.c,v 1.4 2021/07/25 06:10:01 skrll Exp $	*/
      2  1.1  dholland /*  from NetBSD: quota1_subr.c,v 1.7 2012/01/29 06:23:20 dholland Exp  */
      3  1.1  dholland 
      4  1.1  dholland /*-
      5  1.1  dholland   * Copyright (c) 2010 Manuel Bouyer
      6  1.1  dholland   * All rights reserved.
      7  1.1  dholland   *
      8  1.1  dholland   * Redistribution and use in source and binary forms, with or without
      9  1.1  dholland   * modification, are permitted provided that the following conditions
     10  1.1  dholland   * are met:
     11  1.1  dholland   * 1. Redistributions of source code must retain the above copyright
     12  1.1  dholland   *    notice, this list of conditions and the following disclaimer.
     13  1.1  dholland   * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  dholland   *    notice, this list of conditions and the following disclaimer in the
     15  1.1  dholland   *    documentation and/or other materials provided with the distribution.
     16  1.1  dholland   *
     17  1.1  dholland   * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     18  1.1  dholland   * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     19  1.1  dholland   * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20  1.1  dholland   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     21  1.1  dholland   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22  1.1  dholland   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23  1.1  dholland   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24  1.1  dholland   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25  1.1  dholland   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26  1.1  dholland   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27  1.1  dholland   * POSSIBILITY OF SUCH DAMAGE.
     28  1.1  dholland   */
     29  1.1  dholland 
     30  1.1  dholland #include <sys/cdefs.h>
     31  1.4     skrll __KERNEL_RCSID(0, "$NetBSD: ulfs_quota1_subr.c,v 1.4 2021/07/25 06:10:01 skrll Exp $");
     32  1.1  dholland 
     33  1.4     skrll #include <sys/param.h>
     34  1.1  dholland #include <sys/types.h>
     35  1.4     skrll #include <sys/quota.h>
     36  1.1  dholland 
     37  1.2  dholland #include <ufs/lfs/ulfs_quota1.h>
     38  1.1  dholland 
     39  1.1  dholland static uint64_t
     40  1.1  dholland dqblk2q2e_limit(uint32_t lim)
     41  1.1  dholland {
     42  1.1  dholland 	if (lim == 0)
     43  1.1  dholland 		return UQUAD_MAX;
     44  1.1  dholland 	else
     45  1.1  dholland 		return (lim - 1);
     46  1.1  dholland }
     47  1.1  dholland 
     48  1.1  dholland static uint32_t
     49  1.1  dholland q2e2dqblk_limit(uint64_t lim)
     50  1.1  dholland {
     51  1.1  dholland 	if (lim == UQUAD_MAX)
     52  1.1  dholland 		return 0;
     53  1.1  dholland 	else
     54  1.1  dholland 		return (lim + 1);
     55  1.1  dholland }
     56  1.1  dholland 
     57  1.1  dholland void
     58  1.3  dholland lfs_dqblk_to_quotavals(const struct dqblk *dqblk,
     59  1.1  dholland 		   struct quotaval *blocks, struct quotaval *files)
     60  1.1  dholland {
     61  1.1  dholland 	/* XXX is qv_grace getting handled correctly? */
     62  1.1  dholland 
     63  1.1  dholland 	blocks->qv_hardlimit  = dqblk2q2e_limit(dqblk->dqb_bhardlimit);
     64  1.1  dholland 	blocks->qv_softlimit  = dqblk2q2e_limit(dqblk->dqb_bsoftlimit);
     65  1.1  dholland 	blocks->qv_usage      = dqblk->dqb_curblocks;
     66  1.1  dholland 	blocks->qv_expiretime = dqblk->dqb_btime;
     67  1.1  dholland 
     68  1.1  dholland 	files->qv_hardlimit  = dqblk2q2e_limit(dqblk->dqb_ihardlimit);
     69  1.1  dholland 	files->qv_softlimit  = dqblk2q2e_limit(dqblk->dqb_isoftlimit);
     70  1.1  dholland 	files->qv_usage      = dqblk->dqb_curinodes;
     71  1.1  dholland 	files->qv_expiretime = dqblk->dqb_itime;
     72  1.1  dholland }
     73  1.1  dholland 
     74  1.1  dholland void
     75  1.3  dholland lfs_quotavals_to_dqblk(const struct quotaval *blocks, const struct quotaval *files,
     76  1.1  dholland 		   struct dqblk *dqblk)
     77  1.1  dholland {
     78  1.1  dholland 	/* XXX is qv_grace getting handled correctly? */
     79  1.1  dholland 
     80  1.1  dholland 	dqblk->dqb_bhardlimit = q2e2dqblk_limit(blocks->qv_hardlimit);
     81  1.1  dholland 	dqblk->dqb_bsoftlimit = q2e2dqblk_limit(blocks->qv_softlimit);
     82  1.1  dholland 	dqblk->dqb_curblocks  = blocks->qv_usage;
     83  1.1  dholland 	dqblk->dqb_btime      = blocks->qv_expiretime;
     84  1.1  dholland 
     85  1.1  dholland 	dqblk->dqb_ihardlimit = q2e2dqblk_limit(files->qv_hardlimit);
     86  1.1  dholland 	dqblk->dqb_isoftlimit = q2e2dqblk_limit(files->qv_softlimit);
     87  1.1  dholland 	dqblk->dqb_curinodes  = files->qv_usage;
     88  1.1  dholland 	dqblk->dqb_itime      = files->qv_expiretime;
     89  1.1  dholland }
     90  1.1  dholland 
     91