1/* $NetBSD: quota1_subr.c,v 1.7 2012/01/29 06:23:20 dholland 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.7 2012/01/29 06:23:20 dholland Exp $");
30
31#include <sys/types.h>
32#include <machine/limits.h>
33
34#include <sys/quota.h>
35#include <ufs/ufs/quota1.h>
36
37static uint64_t
38dqblk2q2e_limit(uint32_t lim)
39{
40 if (lim == 0)
41 return UQUAD_MAX;
42 else
43 return (lim - 1);
44}
45
46static uint32_t
47q2e2dqblk_limit(uint64_t lim)
48{
49 if (lim == UQUAD_MAX)
50 return 0;
51 else
52 return (lim + 1);
53}
54
55void
56dqblk_to_quotavals(const struct dqblk *dqblk,
57 struct quotaval *blocks, struct quotaval *files)
58{
59 /* XXX is qv_grace getting handled correctly? */
60
61 blocks->qv_hardlimit = dqblk2q2e_limit(dqblk->dqb_bhardlimit);
62 blocks->qv_softlimit = dqblk2q2e_limit(dqblk->dqb_bsoftlimit);
63 blocks->qv_usage = dqblk->dqb_curblocks;
64 blocks->qv_expiretime = dqblk->dqb_btime;
65
66 files->qv_hardlimit = dqblk2q2e_limit(dqblk->dqb_ihardlimit);
67 files->qv_softlimit = dqblk2q2e_limit(dqblk->dqb_isoftlimit);
68 files->qv_usage = dqblk->dqb_curinodes;
69 files->qv_expiretime = dqblk->dqb_itime;
70}
71
72void
73quotavals_to_dqblk(const struct quotaval *blocks, const struct quotaval *files,
74 struct dqblk *dqblk)
75{
76 /* XXX is qv_grace getting handled correctly? */
77
78 dqblk->dqb_bhardlimit = q2e2dqblk_limit(blocks->qv_hardlimit);
79 dqblk->dqb_bsoftlimit = q2e2dqblk_limit(blocks->qv_softlimit);
80 dqblk->dqb_curblocks = blocks->qv_usage;
81 dqblk->dqb_btime = blocks->qv_expiretime;
82
83 dqblk->dqb_ihardlimit = q2e2dqblk_limit(files->qv_hardlimit);
84 dqblk->dqb_isoftlimit = q2e2dqblk_limit(files->qv_softlimit);
85 dqblk->dqb_curinodes = files->qv_usage;
86 dqblk->dqb_itime = files->qv_expiretime;
87}
88
89