FreeBSD/usr.sbin/edquota/edquota.c
/*
 * Merge changes to an ASCII file into a quotause list.
 */
Merge changes to an ASCII file into a quotause list.
Merge changes to an ASCII file into a quotause list .
int
readprivs(struct quotause *quplist, char *inname)
{
	struct quotause *qup;
	FILE *fd;
	uintmax_t hardlimit, softlimit, curitems;
	char hardunits, softunits, curitemunits;
	int cnt;
	char *cp;
	struct dqblk dqblk;
	char *fsp, line1[BUFSIZ], line2[BUFSIZ];
	fd = fopen(inname, "r");
	if (fd == NULL) {
		warnx("can't re-read temp file!!");
		return (0);
	}
	(void) fgets(line1, sizeof (line1), fd);
	while (fgets(line1, sizeof (line1), fd) != NULL &&
	       fgets(line2, sizeof (line2), fd) != NULL) {
		if ((fsp = strtok(line1, " \t:")) == NULL) {
			warnx("%s: bad format", line1);
			return (0);
		}
		if ((cp = strtok((char *)0, "\n")) == NULL) {
			warnx("%s: %s: bad format", fsp, &fsp[strlen(fsp) + 1]);
			return (0);
		}
		cnt = sscanf(cp,
		    " in use: %ju%c, limits (soft = %ju%c, hard = %ju%c)",
		    &curitems, &curitemunits, &softlimit, &softunits,
		    &hardlimit, &hardunits);
		if (cnt != 6)
			cnt = sscanf(cp,
			 " in use: %ju%c, limits (soft = %ju%c hard = %ju%c",
			    &curitems, &curitemunits, &softlimit,
			    &softunits, &hardlimit, &hardunits);
		if (cnt != 6)
			cnt = sscanf(cp,
			" in use: %ju%c, limits (soft = %ju%c hard = %ju%c)",
			    &curitems, &curitemunits, &softlimit,
			    &softunits, &hardlimit, &hardunits);
		if (cnt != 6)
			cnt = sscanf(cp,
			" in use: %ju%c, limits (soft = %ju%c, hard = %ju%c",
			    &curitems, &curitemunits, &softlimit,
			    &softunits, &hardlimit, &hardunits);
		if (cnt != 6) {
			warnx("%s:%s: bad format", fsp, cp);
			return (0);
		}
		dqblk.dqb_curblocks = cvtblkval(curitems, curitemunits,
		    "current block count");
		dqblk.dqb_bsoftlimit = cvtblkval(softlimit, softunits,
		    "block soft limit");
		dqblk.dqb_bhardlimit = cvtblkval(hardlimit, hardunits,
		    "block hard limit");
		if ((cp = strtok(line2, "\n")) == NULL) {
			warnx("%s: %s: bad format", fsp, line2);
			return (0);
		}
		cnt = sscanf(&cp[7],
		    " in use: %ju%c limits (soft = %ju%c, hard = %ju%c)",
		    &curitems, &curitemunits, &softlimit,
		    &softunits, &hardlimit, &hardunits);
		if (cnt != 6)
			cnt = sscanf(&cp[7],
			 " in use: %ju%c limits (soft = %ju%c hard = %ju%c",
			    &curitems, &curitemunits, &softlimit,
			    &softunits, &hardlimit, &hardunits);
		if (cnt != 6)
			cnt = sscanf(&cp[7],
			" in use: %ju%c limits (soft = %ju%c hard = %ju%c)",
			    &curitems, &curitemunits, &softlimit,
			    &softunits, &hardlimit, &hardunits);
		if (cnt != 6)
			cnt = sscanf(&cp[7],
			" in use: %ju%c limits (soft = %ju%c, hard = %ju%c",
			    &curitems, &curitemunits, &softlimit,
			    &softunits, &hardlimit, &hardunits);
		if (cnt != 6) {
			warnx("%s: %s: bad format cnt %d", fsp, &cp[7], cnt);
			return (0);
		}
		dqblk.dqb_curinodes = cvtinoval(curitems, curitemunits,
		    "current inode count");
		dqblk.dqb_isoftlimit = cvtinoval(softlimit, softunits,
		    "inode soft limit");
		dqblk.dqb_ihardlimit = cvtinoval(hardlimit, hardunits,
		    "inode hard limit");
		for (qup = quplist; qup; qup = qup->next) {
			if (strcmp(fsp, qup->fsname))
				continue;
			if (dqblk.dqb_bsoftlimit &&
			    qup->dqblk.dqb_curblocks >= dqblk.dqb_bsoftlimit &&
			    (qup->dqblk.dqb_bsoftlimit == 0 ||
			     qup->dqblk.dqb_curblocks <
			     qup->dqblk.dqb_bsoftlimit))
				qup->dqblk.dqb_btime = 0;
			if (dqblk.dqb_isoftlimit &&
			    qup->dqblk.dqb_curinodes >= dqblk.dqb_isoftlimit &&
			    (qup->dqblk.dqb_isoftlimit == 0 ||
			     qup->dqblk.dqb_curinodes <
			     qup->dqblk.dqb_isoftlimit))
				qup->dqblk.dqb_itime = 0;
			qup->dqblk.dqb_bsoftlimit = dqblk.dqb_bsoftlimit;
			qup->dqblk.dqb_bhardlimit = dqblk.dqb_bhardlimit;
			qup->dqblk.dqb_isoftlimit = dqblk.dqb_isoftlimit;
			qup->dqblk.dqb_ihardlimit = dqblk.dqb_ihardlimit;
			qup->flags |= FOUND;
			if (hflag ||
			    (dqblk.dqb_curblocks == qup->dqblk.dqb_curblocks &&
			     dqblk.dqb_curinodes == qup->dqblk.dqb_curinodes))
				break;
			warnx("%s: cannot change current allocation", fsp);
			break;
		}
	}
	fclose(fd);
	for (qup = quplist; qup; qup = qup->next) {
		if (qup->flags & FOUND) {
			qup->flags &= ~FOUND;
			continue;
		}
		qup->dqblk.dqb_bsoftlimit = 0;
		qup->dqblk.dqb_bhardlimit = 0;
		qup->dqblk.dqb_isoftlimit = 0;
		qup->dqblk.dqb_ihardlimit = 0;
	}
	return (1);
}
int readprivs ( struct quotause * quplist , char * inname ) { struct quotause * qup ; FILE * fd ; uintmax_t hardlimit , softlimit , curitems ; char hardunits , softunits , curitemunits ; int cnt ; char * cp ; struct dqblk dqblk ; char * fsp , line1 [ BUFSIZ ] , line2 [ BUFSIZ ] ; fd = fopen ( inname , " " ) ; if ( fd == NULL ) { warnx ( " " ) ; return ( 0 ) ; } ( void ) fgets ( line1 , sizeof ( line1 ) , fd ) ; while ( fgets ( line1 , sizeof ( line1 ) , fd ) != NULL && fgets ( line2 , sizeof ( line2 ) , fd ) != NULL ) { if ( ( fsp = strtok ( line1 , " \t " ) ) == NULL ) { warnx ( " " , line1 ) ; return ( 0 ) ; } if ( ( cp = strtok ( ( char * ) 0 , " \n " ) ) == NULL ) { warnx ( " " , fsp , & fsp [ strlen ( fsp ) + 1 ] ) ; return ( 0 ) ; } cnt = sscanf ( cp , " " , & curitems , & curitemunits , & softlimit , & softunits , & hardlimit , & hardunits ) ; if ( cnt != 6 ) cnt = sscanf ( cp , " " , & curitems , & curitemunits , & softlimit , & softunits , & hardlimit , & hardunits ) ; if ( cnt != 6 ) cnt = sscanf ( cp , " " , & curitems , & curitemunits , & softlimit , & softunits , & hardlimit , & hardunits ) ; if ( cnt != 6 ) cnt = sscanf ( cp , " " , & curitems , & curitemunits , & softlimit , & softunits , & hardlimit , & hardunits ) ; if ( cnt != 6 ) { warnx ( " " , fsp , cp ) ; return ( 0 ) ; } dqblk . dqb_curblocks = cvtblkval ( curitems , curitemunits , " " ) ; dqblk . dqb_bsoftlimit = cvtblkval ( softlimit , softunits , " " ) ; dqblk . dqb_bhardlimit = cvtblkval ( hardlimit , hardunits , " " ) ; if ( ( cp = strtok ( line2 , " \n " ) ) == NULL ) { warnx ( " " , fsp , line2 ) ; return ( 0 ) ; } cnt = sscanf ( & cp [ 7 ] , " " , & curitems , & curitemunits , & softlimit , & softunits , & hardlimit , & hardunits ) ; if ( cnt != 6 ) cnt = sscanf ( & cp [ 7 ] , " " , & curitems , & curitemunits , & softlimit , & softunits , & hardlimit , & hardunits ) ; if ( cnt != 6 ) cnt = sscanf ( & cp [ 7 ] , " " , & curitems , & curitemunits , & softlimit , & softunits , & hardlimit , & hardunits ) ; if ( cnt != 6 ) cnt = sscanf ( & cp [ 7 ] , " " , & curitems , & curitemunits , & softlimit , & softunits , & hardlimit , & hardunits ) ; if ( cnt != 6 ) { warnx ( " " , fsp , & cp [ 7 ] , cnt ) ; return ( 0 ) ; } dqblk . dqb_curinodes = cvtinoval ( curitems , curitemunits , " " ) ; dqblk . dqb_isoftlimit = cvtinoval ( softlimit , softunits , " " ) ; dqblk . dqb_ihardlimit = cvtinoval ( hardlimit , hardunits , " " ) ; for ( qup = quplist ; qup ; qup = qup -> next ) { if ( strcmp ( fsp , qup -> fsname ) ) continue ; if ( dqblk . dqb_bsoftlimit && qup -> dqblk . dqb_curblocks >= dqblk . dqb_bsoftlimit && ( qup -> dqblk . dqb_bsoftlimit == 0 || qup -> dqblk . dqb_curblocks < qup -> dqblk . dqb_bsoftlimit ) ) qup -> dqblk . dqb_btime = 0 ; if ( dqblk . dqb_isoftlimit && qup -> dqblk . dqb_curinodes >= dqblk . dqb_isoftlimit && ( qup -> dqblk . dqb_isoftlimit == 0 || qup -> dqblk . dqb_curinodes < qup -> dqblk . dqb_isoftlimit ) ) qup -> dqblk . dqb_itime = 0 ; qup -> dqblk . dqb_bsoftlimit = dqblk . dqb_bsoftlimit ; qup -> dqblk . dqb_bhardlimit = dqblk . dqb_bhardlimit ; qup -> dqblk . dqb_isoftlimit = dqblk . dqb_isoftlimit ; qup -> dqblk . dqb_ihardlimit = dqblk . dqb_ihardlimit ; qup -> flags |= FOUND ; if ( hflag || ( dqblk . dqb_curblocks == qup -> dqblk . dqb_curblocks && dqblk . dqb_curinodes == qup -> dqblk . dqb_curinodes ) ) break ; warnx ( " " , fsp ) ; break ; } } fclose ( fd ) ; for ( qup = quplist ; qup ; qup = qup -> next ) { if ( qup -> flags & FOUND ) { qup -> flags &= ~ FOUND ; continue ; } qup -> dqblk . dqb_bsoftlimit = 0 ; qup -> dqblk . dqb_bhardlimit = 0 ; qup -> dqblk . dqb_isoftlimit = 0 ; qup -> dqblk . dqb_ihardlimit = 0 ; } return ( 1 ) ; }
Merge changes to an ASCII file into a quotause list.
Merge changes to an ASCII file into a quotause list .
/*
	 * Discard title line, then read pairs of lines to process.
	 */ /*
		 * The next three check for old-style input formats.
		 */ /*
		 * The next three check for old-style input formats.
		 */ /*
			 * Cause time limit to be reset when the quota
			 * is next used if previously had no soft limit
			 * or were under it, but now have a soft limit
			 * and are over it.
			 */ /* Humanized input returns only approximate counts */ /*
	 * Disable quotas for any filesystems that have not been found.
	 */