xref: /netbsd-src/sbin/fsck_ffs/pass6.c (revision 7a6a7ae08ac6c612f0fbb0d4425825c6be2a9050)
1 /* $NetBSD: pass6.c,v 1.2 2011/03/06 17:08:16 bouyer Exp $ */
2 /*-
3   * Copyright (c) 2010 Manuel Bouyer
4   * All rights reserved.
5   * This software is distributed under the following condiions
6   * compliant with the NetBSD foundation policy.
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/param.h>
31 #include <sys/time.h>
32 
33 #include <ufs/ufs/dinode.h>
34 #include <ufs/ffs/fs.h>
35 #include <ufs/ffs/ffs_extern.h>
36 #include <ufs/ufs/ufs_bswap.h>
37 
38 #include <err.h>
39 #include <string.h>
40 #include <malloc.h>
41 #include <ufs/ufs/quota2.h>
42 
43 #include "fsutil.h"
44 #include "fsck.h"
45 #include "extern.h"
46 
47 const char *utname[] = {"USER", "GROUP"};
48 
49 void
50 pass6(void)
51 {
52 	int ret1, ret2;
53 	int i;
54 	if ((sblock->fs_flags & FS_DOQUOTA2) == 0)
55 		return;
56 
57 	for (i = 0; i < MAXQUOTAS; i++) {
58 		if ((sblock->fs_quota_flags & FS_Q2_DO_TYPE(i)) == 0 &&
59 		    sblock->fs_quotafile[i] != 0) {
60 			if (preen || reply(
61 				    i == 0 ? "CLEAR USER QUOTA INODE" :
62 				    "CLEAR GROUP QUOTA INODE") != 0) {
63 				if (preen)
64 					printf("%s QUOTA INODE CLEARED\n",
65 				    utname[i]);
66 				freeino(sblock->fs_quotafile[i]);
67 				sblock->fs_quotafile[i] = 0;
68 				sbdirty();
69 			} else
70 				markclean = 0;
71 		}
72 	}
73 	if ((sblock->fs_quota_flags &
74 	    (FS_Q2_DO_TYPE(USRQUOTA) | FS_Q2_DO_TYPE(GRPQUOTA))) == 0) {
75 		if (preen || reply("CLEAR SUPERBLOCK QUOTA FLAG") != 0) {
76 			if (preen)
77 				printf("SUPERBLOCK QUOTA FLAG CLEARED\n");
78 			sblock->fs_flags &= ~FS_DOQUOTA2;
79 			sbdirty();
80 		} else
81 			markclean = 0;
82 	}
83 
84 	ret1 = quota2_check_inode(USRQUOTA);
85 	ret2 = quota2_check_inode(GRPQUOTA);
86 
87 	if (ret1 == 0)
88 		quota2_check_usage(USRQUOTA);
89 	if (ret2 == 0)
90 		quota2_check_usage(GRPQUOTA);
91 }
92 
93