Home | History | Annotate | Line # | Download | only in fsck_ffs
      1 /* $NetBSD: pass6.c,v 1.5 2023/07/04 20:40:53 riastradh Exp $ */
      2 
      3 /*-
      4   * Copyright (c) 2010 Manuel Bouyer
      5   * All rights reserved.
      6   *
      7   * Redistribution and use in source and binary forms, with or without
      8   * modification, are permitted provided that the following conditions
      9   * are met:
     10   * 1. Redistributions of source code must retain the above copyright
     11   *    notice, this list of conditions and the following disclaimer.
     12   * 2. Redistributions in binary form must reproduce the above copyright
     13   *    notice, this list of conditions and the following disclaimer in the
     14   *    documentation and/or other materials provided with the distribution.
     15   *
     16   * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17   * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18   * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26   * POSSIBILITY OF SUCH DAMAGE.
     27   */
     28 
     29 #include <sys/param.h>
     30 #include <sys/time.h>
     31 
     32 #include <ufs/ufs/dinode.h>
     33 #include <ufs/ffs/fs.h>
     34 #include <ufs/ffs/ffs_extern.h>
     35 #include <ufs/ufs/ufs_bswap.h>
     36 
     37 #include <err.h>
     38 #include <string.h>
     39 #include <stdlib.h>
     40 #include <ufs/ufs/quota2.h>
     41 
     42 #include "fsutil.h"
     43 #include "fsck.h"
     44 #include "extern.h"
     45 
     46 const char *utname[] = {"USER", "GROUP"};
     47 
     48 void
     49 pass6(void)
     50 {
     51 	int ret1, ret2;
     52 	int i;
     53 	if ((sblock->fs_flags & FS_DOQUOTA2) == 0)
     54 		return;
     55 
     56 	for (i = 0; i < MAXQUOTAS; i++) {
     57 		if ((sblock->fs_quota_flags & FS_Q2_DO_TYPE(i)) == 0 &&
     58 		    sblock->fs_quotafile[i] != 0) {
     59 			if (preen || reply(
     60 				    i == 0 ? "CLEAR USER QUOTA INODE" :
     61 				    "CLEAR GROUP QUOTA INODE") != 0) {
     62 				if (preen)
     63 					printf("%s QUOTA INODE CLEARED\n",
     64 				    utname[i]);
     65 				freeino(sblock->fs_quotafile[i]);
     66 				sblock->fs_quotafile[i] = 0;
     67 				sbdirty();
     68 			} else
     69 				markclean = 0;
     70 		}
     71 	}
     72 	if ((sblock->fs_quota_flags &
     73 	    (FS_Q2_DO_TYPE(USRQUOTA) | FS_Q2_DO_TYPE(GRPQUOTA))) == 0) {
     74 		if (preen || reply("CLEAR SUPERBLOCK QUOTA FLAG") != 0) {
     75 			if (preen)
     76 				printf("SUPERBLOCK QUOTA FLAG CLEARED\n");
     77 			sblock->fs_flags &= ~FS_DOQUOTA2;
     78 			sbdirty();
     79 		} else
     80 			markclean = 0;
     81 	}
     82 
     83 	ret1 = quota2_check_inode(USRQUOTA);
     84 	ret2 = quota2_check_inode(GRPQUOTA);
     85 
     86 	if (ret1 == 0)
     87 		quota2_check_usage(USRQUOTA);
     88 	if (ret2 == 0)
     89 		quota2_check_usage(GRPQUOTA);
     90 }
     91