FreeBSD/lib/libutil/quotafile.c
/*
 * Check to see if a particular quota is to be enabled.
 */
Check to see if a particular quota is to be enabled.
Check to see if a particular quota is to be enabled .
static int
hasquota(struct fstab *fs, int type, char *qfnamep, int qfbufsize)
{
	char *opt;
	char *cp;
	struct statfs sfb;
	char buf[BUFSIZ];
	static char initname, usrname[100], grpname[100];
	if (!initname) {
		(void)snprintf(usrname, sizeof(usrname), "%s%s",
		    qfextension[USRQUOTA], QUOTAFILENAME);
		(void)snprintf(grpname, sizeof(grpname), "%s%s",
		    qfextension[GRPQUOTA], QUOTAFILENAME);
		initname = 1;
	}
	strcpy(buf, fs->fs_mntops);
	for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
		if ((cp = strchr(opt, '=')))
			*cp++ = '\0';
		if (type == USRQUOTA && strcmp(opt, usrname) == 0)
			break;
		if (type == GRPQUOTA && strcmp(opt, grpname) == 0)
			break;
	}
	if (!opt)
		return (0);
	if (statfs(fs->fs_file, &sfb) != 0 ||
	    strcmp(fs->fs_file, sfb.f_mntonname)) {
		return (0);
	}
	if (cp) {
		strncpy(qfnamep, cp, qfbufsize);
	} else {
		(void)snprintf(qfnamep, qfbufsize, "%s/%s.%s", fs->fs_file,
		    QUOTAFILENAME, qfextension[type]);
	}
	return (1);
}
static int hasquota ( struct fstab * fs , int type , char * qfnamep , int qfbufsize ) { char * opt ; char * cp ; struct statfs sfb ; char buf [ BUFSIZ ] ; static char initname , usrname [ 100 ] , grpname [ 100 ] ; if ( ! initname ) { ( void ) snprintf ( usrname , sizeof ( usrname ) , " " , qfextension [ USRQUOTA ] , QUOTAFILENAME ) ; ( void ) snprintf ( grpname , sizeof ( grpname ) , " " , qfextension [ GRPQUOTA ] , QUOTAFILENAME ) ; initname = 1 ; } strcpy ( buf , fs -> fs_mntops ) ; for ( opt = strtok ( buf , " " ) ; opt ; opt = strtok ( NULL , " " ) ) { if ( ( cp = strchr ( opt , ' ' ) ) ) * cp ++ = ' \0 ' ; if ( type == USRQUOTA && strcmp ( opt , usrname ) == 0 ) break ; if ( type == GRPQUOTA && strcmp ( opt , grpname ) == 0 ) break ; } if ( ! opt ) return ( 0 ) ; if ( statfs ( fs -> fs_file , & sfb ) != 0 || strcmp ( fs -> fs_file , sfb . f_mntonname ) ) { return ( 0 ) ; } if ( cp ) { strncpy ( qfnamep , cp , qfbufsize ) ; } else { ( void ) snprintf ( qfnamep , qfbufsize , " " , fs -> fs_file , QUOTAFILENAME , qfextension [ type ] ) ; } return ( 1 ) ; }
Check to see if a particular quota is to be enabled.
Check to see if a particular quota is to be enabled .
/*
	 * 1) we only need one of these
	 * 2) fstab may specify a different filename
	 */ /*
	 * Ensure that the filesystem is mounted.
	 */