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