Home | History | Annotate | Line # | Download | only in ufs
      1 /* $NetBSD: quota1_subr.c,v 1.9 2026/01/22 03:23:36 riastradh Exp $ */
      2 /*-
      3   * Copyright (c) 2010 Manuel Bouyer
      4   * All rights reserved.
      5   *
      6   * Redistribution and use in source and binary forms, with or without
      7   * modification, are permitted provided that the following conditions
      8   * are met:
      9   * 1. Redistributions of source code must retain the above copyright
     10   *    notice, this list of conditions and the following disclaimer.
     11   * 2. Redistributions in binary form must reproduce the above copyright
     12   *    notice, this list of conditions and the following disclaimer in the
     13   *    documentation and/or other materials provided with the distribution.
     14   *
     15   * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16   * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17   * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25   * POSSIBILITY OF SUCH DAMAGE.
     26   */
     27 
     28 #include <sys/cdefs.h>
     29 __KERNEL_RCSID(0, "$NetBSD: quota1_subr.c,v 1.9 2026/01/22 03:23:36 riastradh Exp $");
     30 
     31 #include <sys/types.h>
     32 
     33 #include <sys/quota.h>
     34 
     35 #include <machine/limits.h>
     36 
     37 #include <ufs/ufs/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 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 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