📄 mom_mach.c
字号:
log_err(-1, id, extra_parm); rm_errno = RM_ERR_BADPARAM; return NULL; } if (statfs(procfs, &fsbuf, sizeof(struct statfs), 0) == -1) { log_err(errno, id, "statfs"); rm_errno = RM_ERR_SYSTEM; return NULL; } DBPRT(("%s: bsize=%d bfree=%d\n", id, fsbuf.f_bsize, fsbuf.f_bfree)) sprintf(ret_string, "%d", fsbuf.f_bsize * fsbuf.f_bfree); return ret_string;}static char *ncpus(attrib)struct rm_attribute *attrib;{ char *id = "ncpus"; if (attrib) { log_err(-1, id, extra_parm); rm_errno = RM_ERR_BADPARAM; return NULL; } sprintf(ret_string, "%ld", tinfo.mc_ncpu); return ret_string;}static char *physmem(attrib)struct rm_attribute *attrib;{ char *id = "physmem"; if (attrib) { log_err(-1, id, extra_parm); rm_errno = RM_ERR_BADPARAM; return NULL; } sprintf(ret_string, "%ld", tinfo.mc_msz * sizeof(int)); return ret_string;}char *size_fs(param)char *param;{ char *id = "size_fs"; FILE *mf; struct mntent *mp; struct statfs fsbuf; if (param[0] != '/') { sprintf(log_buffer, "%s: not full path filesystem name: %s\n", id, param); log_err(-1, id, log_buffer); rm_errno = RM_ERR_BADPARAM; return NULL; } if (statfs(param, &fsbuf, sizeof(struct statfs), 0) == -1) { log_err(errno, id, "statfs"); rm_errno = RM_ERR_BADPARAM; return NULL; } sprintf(ret_string, "%lukb", (unsigned long)((fsbuf.f_bsize * fsbuf.f_bfree) >> 10)); return ret_string;}char *size_file(param)char *param;{ char *id = "size_file"; struct stat sbuf; if (param[0] != '/') { sprintf(log_buffer, "%s: not full path filesystem name: %s\n", id, param); log_err(-1, id, log_buffer); rm_errno = RM_ERR_BADPARAM; return NULL; } if (stat(param, &sbuf) == -1) { log_err(errno, id, "stat"); rm_errno = RM_ERR_BADPARAM; return NULL; } sprintf(ret_string, "%d", sbuf.st_size); return ret_string;}char *size(attrib)struct rm_attribute *attrib;{ char *id = "size"; char *param; if (attrib == NULL) { log_err(-1, id, no_parm); rm_errno = RM_ERR_NOPARAM; return NULL; } if (momgetattr(NULL)) { log_err(-1, id, extra_parm); rm_errno = RM_ERR_BADPARAM; return NULL; } param = attrib->a_value; if (strcmp(attrib->a_qualifier, "file") == 0) return (size_file(param)); else if (strcmp(attrib->a_qualifier, "fs") == 0) return (size_fs(param)); else { rm_errno = RM_ERR_BADPARAM; return NULL; }}time_t maxtm;voidsetmax(dev)char *dev;{ struct stat sb; if (stat(dev, &sb) == -1) return; if (maxtm < sb.st_atime) maxtm = sb.st_atime; return;}char *idletime(attrib)struct rm_attribute *attrib;{ char *id = "idletime"; DIR *dp; struct dirent *de; char ttyname[50]; time_t curtm; if (attrib) { log_err(-1, id, extra_parm); rm_errno = RM_ERR_BADPARAM; return NULL; } if ((dp=opendir("/dev")) == NULL) { log_err(errno, id, "opendir /dev"); rm_errno = RM_ERR_SYSTEM; return NULL; } maxtm = 0; curtm = time(NULL); while ((de=readdir(dp)) != NULL) { if (maxtm >= curtm) break; if (strncmp(de->d_name, "tty", 3)) continue; sprintf(ttyname, "/dev/%s", de->d_name); setmax(ttyname); } closedir(dp); sprintf(ret_string, "%d", MAX(0, curtm - maxtm)); return ret_string;}static intquotasize(blocks)int blocks;{ if (QFV_MINVALUE <= blocks && blocks <= QFV_MAXVALUE) { sprintf(ret_string, "%ld", BSIZE * blocks); return 0; } switch (blocks) { case QFV_DEFAULT: strcpy(ret_string, "default"); return 1; case QFV_NOEVAL: strcpy(ret_string, "infinity"); break; case QFV_PREVENT: strcpy(ret_string, "prevent"); break; default: strcpy(ret_string, "unspecified"); break; } return 0;}typedef int (*ifunc)();static char *quota(attrib)struct rm_attribute *attrib;{ char *id = "quota"; time_t now; int ident; char dirname[FILENAME_MAX]; struct q_request qi; struct qf_header header; struct q_entry *qu; static char *bean_type[] = { "account", /* 0 */ "group", /* 1 */ "user" /* 2 */ }; static ifunc bean_func[] = { nam2acid, nam2gid, nam2uid }; enum bean_name { account, group, user, bean_end } bean; static char *type_array[] = { "harddata", "softdata", "currdata", "hardfile", "softfile", "currfile", "timedata", "timefile", "snap_avail", /* srfs */ "ares_avail", /* srfs */ "res_total", /* srfs */ "soft_res", /* srfs */ "delta", /* srfs */ "reserve", /* srfs */ }; enum type_name { harddata, softdata, currdata, hardfile, softfile, currfile, timedata, timefile, snap_avail, ares_avail, res_total, soft_res, delta, reserve, type_end } type; if (attrib == NULL) { log_err(-1, id, no_parm); rm_errno = RM_ERR_NOPARAM; return NULL; } if (strcmp(attrib->a_qualifier, "type")) { sprintf(log_buffer, "unknown qualifier %s", attrib->a_qualifier); log_err(-1, id, log_buffer); rm_errno = RM_ERR_BADPARAM; return NULL; } for (type=0; type<type_end; type++) { if (strcmp(attrib->a_value, type_array[type]) == 0) break; } if (type == type_end) { /* check to see if command is legal */ sprintf(log_buffer, "bad param: %s=%s", attrib->a_qualifier, attrib->a_value); log_err(-1, id, log_buffer); rm_errno = RM_ERR_BADPARAM; return NULL; } if ((attrib = momgetattr(NULL)) == NULL) { log_err(-1, id, no_parm); rm_errno = RM_ERR_NOPARAM; return NULL; } if (strcmp(attrib->a_qualifier, "dir") != 0) { sprintf(log_buffer, "bad param: %s=%s", attrib->a_qualifier, attrib->a_value); log_err(-1, id, log_buffer); rm_errno = RM_ERR_BADPARAM; return NULL; } if (attrib->a_value[0] == '/') /* must be absolute path */ strcpy(dirname, attrib->a_value); else { sprintf(log_buffer, "not an absolute path: %s", attrib->a_value); log_err(-1, id, log_buffer); rm_errno = RM_ERR_BADPARAM; return NULL; }/*** See if it's a srfs request. They don't need an id.*/ if (type >= snap_avail) { if (momgetattr(NULL)) { log_err(-1, id, extra_parm); rm_errno = RM_ERR_BADPARAM; return NULL; } log_err(errno, id, no_srfs); rm_errno = RM_ERR_SYSTEM; return NULL; }/*** Check type of id: user, group or acct.*/ if ((attrib = momgetattr(NULL)) == NULL) { log_err(-1, id, no_parm); rm_errno = RM_ERR_NOPARAM; return NULL; } for (bean=0; bean<bean_end; bean++) { if (strcmp(attrib->a_qualifier, bean_type[bean]) == 0) break; } if (bean == bean_end) { sprintf(log_buffer, "bad param: %s=%s", attrib->a_qualifier, attrib->a_value); log_err(-1, id, log_buffer); rm_errno = RM_ERR_BADPARAM; return NULL; } ident = atoi(attrib->a_value); if (ident == 0) { ident = bean_func[bean](attrib->a_value); if (ident == -1) { sprintf(log_buffer, "%s not found: %s", bean_type[bean], attrib->a_value); log_err(-1, id, log_buffer); rm_errno = RM_ERR_EXIST; return NULL; } } if (momgetattr(NULL)) { log_err(-1, id, extra_parm); rm_errno = RM_ERR_BADPARAM; return NULL; } qi.qf_entry.id = ident; qi.qf_magic = QF_MAGIC; if (quotactl(dirname, Q_GETQUOTA, (caddr_t)&qi) == -1) { log_err(errno, id, "quotactl(Q_GETQUOTA)"); rm_errno = RM_ERR_SYSTEM; return NULL; } qu = NULL; switch (bean) { case account: if (qi.acct) qu = &qi.qf_entry.acct_q; break; case group: if (qi.group) qu = &qi.qf_entry.group_q; break; case user: if (qi.user) qu = &qi.qf_entry.user_q; break; } if (qu == NULL) { sprintf(log_buffer, "%s quota information not returned", bean_type[bean]); log_err(-1, id, log_buffer); rm_errno = RM_ERR_EXIST; return NULL; } switch (type) { case harddata: if (quotasize(qu->f_quota)) break; return ret_string; case softdata: if (quotasize(qu->f_warn)) break; return ret_string; case currdata: sprintf(ret_string, "%ld", BSIZE*qu->f_use); return ret_string; case hardfile: if (quotasize(qu->i_quota)) break; return ret_string; case softfile: if (quotasize(qu->i_warn)) break; return ret_string; case currfile: sprintf(ret_string, "%ld", qu->i_use); return ret_string; case timedata: case timefile: now = time((time_t *)NULL); if (qu->f_wtime > now) /* time is in the future */ sprintf(ret_string, "%ld", qu->f_wtime - now); else strcpy(ret_string, "0"); return ret_string; } /* ** If we get here, the default number is needed. */ DBPRT(("%s: getting default info\n", id)) header.qf_magic = QF_MAGIC; if (quotactl(dirname, Q_GETHEADER, (caddr_t)&header) == -1) { log_err(errno, id, "quotactl(Q_GETHEADER)"); rm_errno = RM_ERR_SYSTEM; return NULL; } switch (type) { case harddata: (void)quotasize(header.user_h.def_fq); return ret_string; case softdata: (void)quotasize(header.user_h.warn_fq); return ret_string; case hardfile: sprintf(ret_string, "%ld", header.user_h.def_iq); return ret_string; case softfile: sprintf(ret_string, "%ld", header.user_h.warn_iq); return ret_string; } return ret_string;}static char *srfs_reserve(attrib)struct rm_attribute *attrib;{ char *id = "srfs_reserve"; log_err(errno, id, no_srfs); rm_errno = RM_ERR_SYSTEM; return NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -