xref: /netbsd-src/sbin/fsck_ffs/pass6.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /* $NetBSD: pass6.c,v 1.4 2012/08/26 09:34:17 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/param.h>
29 #include <sys/time.h>
30 
31 #include <ufs/ufs/dinode.h>
32 #include <ufs/ffs/fs.h>
33 #include <ufs/ffs/ffs_extern.h>
34 #include <ufs/ufs/ufs_bswap.h>
35 
36 #include <err.h>
37 #include <string.h>
38 #include <stdlib.h>
39 #include <ufs/ufs/quota2.h>
40 
41 #include "fsutil.h"
42 #include "fsck.h"
43 #include "extern.h"
44 
45 const char *utname[] = {"USER", "GROUP"};
46 
47 void
48 pass6(void)
49 {
50 	int ret1, ret2;
51 	int i;
52 	if ((sblock->fs_flags & FS_DOQUOTA2) == 0)
53 		return;
54 
55 	for (i = 0; i < MAXQUOTAS; i++) {
56 		if ((sblock->fs_quota_flags & FS_Q2_DO_TYPE(i)) == 0 &&
57 		    sblock->fs_quotafile[i] != 0) {
58 			if (preen || reply(
59 				    i == 0 ? "CLEAR USER QUOTA INODE" :
60 				    "CLEAR GROUP QUOTA INODE") != 0) {
61 				if (preen)
62 					printf("%s QUOTA INODE CLEARED\n",
63 				    utname[i]);
64 				freeino(sblock->fs_quotafile[i]);
65 				sblock->fs_quotafile[i] = 0;
66 				sbdirty();
67 			} else
68 				markclean = 0;
69 		}
70 	}
71 	if ((sblock->fs_quota_flags &
72 	    (FS_Q2_DO_TYPE(USRQUOTA) | FS_Q2_DO_TYPE(GRPQUOTA))) == 0) {
73 		if (preen || reply("CLEAR SUPERBLOCK QUOTA FLAG") != 0) {
74 			if (preen)
75 				printf("SUPERBLOCK QUOTA FLAG CLEARED\n");
76 			sblock->fs_flags &= ~FS_DOQUOTA2;
77 			sbdirty();
78 		} else
79 			markclean = 0;
80 	}
81 
82 	ret1 = quota2_check_inode(USRQUOTA);
83 	ret2 = quota2_check_inode(GRPQUOTA);
84 
85 	if (ret1 == 0)
86 		quota2_check_usage(USRQUOTA);
87 	if (ret2 == 0)
88 		quota2_check_usage(GRPQUOTA);
89 }
90 
91