#include #include "diskquotaconf.h" #include "diskquotaconf.m" #include #include static HELP_FILE help_quotacheck ("diskquotaconf","quotacheck"); static bool quota_fileexist (const char *dirfs, const char *fname) { char path[PATH_MAX]; if (strcmp(dirfs,"/")==0){ sprintf (path,"/%s",fname); }else{ sprintf (path,"%s/%s",dirfs,fname); } return file_type(path)!=-1; } static void quota_checkone(FSTAB_ENTRY *e) { const char *dirfs = e->getmpoint(); const char *dirfsmsg = strcmp(dirfs,"/")== 0 ? "" : dirfs; const char *uflag = ""; /* There is no way to probe which quota support is in the kernel unless it is enabled. So we check for the presence of one file or the other. quotacheck will have to create the proper format. The only issue arises when someone install a Linus kernel over a distribution using a new quota format kernel: quotacheck will fail to create the proper file. This is an issue... */ if (e->has_quota_u()){ static const char *new_quota_user_file = "aquota.user"; static const char *old_quota_user_file = "quota.user"; if (!quota_fileexist (dirfs,new_quota_user_file) && !quota_fileexist(dirfs,old_quota_user_file)){ uflag = "-u"; net_prtlog (NETLOG_WHY,MSG_U(I_WHYQUOTAUSER ,"User quota is enabled for partition %s, but %s/(a)%s is missing\n") ,e->getsource(),dirfsmsg,old_quota_user_file); } } const char *gflag = ""; if (e->has_quota_g()){ static const char *new_quota_group_file = "aquota.group"; static const char *old_quota_group_file = "quota.group"; if (!quota_fileexist (dirfs,new_quota_group_file) && !quota_fileexist(dirfs,old_quota_group_file)){ gflag = "-g"; net_prtlog (NETLOG_WHY,MSG_U(I_WHYQUOTAGROUP ,"Group quota is enabled for partition %s, but %s/(a)%s is missing\n") ,e->getsource(),dirfsmsg,old_quota_group_file); } } if (uflag[0] != '\0' || gflag[0] != '\0'){ bool yes = true; if (!simul_ison()){ char msg[10000]; sprintf (msg,MSG_U(I_QUOTACHECK ,"You have enable disk quota management on\n" "the file-system %s.\n" "To make this effective, we must run the quotacheck utility.\n" "It will browse through the directories and update the current\n" "disk usage for each users and groups. This will take a while\n" "\n" "Should we do this now ?") ,dirfs); yes = dialog_yesno ( MSG_U(T_QUOTACHECK,"Installing quota on a file-system") ,msg,help_quotacheck)==MENU_YES; } if (yes){ char opt[PATH_MAX+10]; const char *mflag = strcmp(dirfs,"/")==0 ? "-m" : ""; sprintf (opt,"-c %s %s %s %s",mflag,uflag,gflag,dirfs); netconf_system_if ("quotacheck",opt); sprintf (opt,"%s %s %s",uflag,gflag,dirfs); netconf_system_if ("quotaon",opt); /* #Specification: quota / after quotacheck / apply all There is a sequence where the quota defaults are not enforced properly. # The user set the quota flags on one partition. Linuxconf update the fstab, but nothing else is happening. The user visits the quota defaults and sets various limits. When he accept the limit, linuxconf try to apply those defaults by walking all users and groups, computing the effective limits for each. But this does not work since the quotacheck has not been done yet. The user quit from linuxconf. Linuxcong signals that quotacheck must be run. Fine, but the limits are not set. So at the end of the quotacheck, after the quotaon, Linuxconf force a walk of all users and groups to make sure the limits are properly entered. */ if (!simul_ison()) quota_applyall(e->getsource()); } } } int diskquotaconf_checkfs() { FSTAB fstab; MTAB mtab; int nbfs = fstab.getnb(); int ret = 0; for (int i=0; iis_valid()){ FSTAB_ENTRY_TYPE type = efs->gettype(); const char *mpoint = efs->getmpoint(); FSTAB_ENTRY *emt = mtab.locate_mpoint(mpoint); if (type == FSTAB_ENTRY_LOCAL){ if (emt != NULL){ quota_checkone(efs); } } } } return ret; }