/* Query the quota for uid and add it to qlist if successful. */ static void add_quota(confent_t *cp, List qlist, uid_t uid, char *name) { quota_t q; if (list_find_first(qlist, (ListFindF)quota_match_uid, &uid)) return; q = quota_create(cp->cf_label, cp->cf_rhost, cp->cf_rpath, cp->cf_thresh); if (quota_get(uid, q)) { quota_destroy(q); return; } if (name) quota_adduser (q, name); list_append(qlist, q); }
int main (int argc, char **argv) { u_int64_t old_quota; int id; time_t old_grace; argdata_t *argdata; quota_t *quota; char* tmpstr; /* parse commandline and fill argdata */ argdata = parse_commandline (argc, argv); if ( ! argdata ) { exit (ERR_PARSE); } /* initialize the id to use */ if ( ! argdata->id ) { id = 0; } /* numerical uid starting with ':', don't check uid/gid against system users/groups */ else if ( strlen(argdata->id) > 1 && argdata->id[0] == ':' && isdigit(argdata->id[1]) ) { argdata->id++; // skip leading ':' id = strtol(argdata->id, &tmpstr, 10); } else if ( argdata->id_type == QUOTA_USER ) { id = (int) system_getuid (argdata->id); } else { id = (int) system_getgid (argdata->id); } if ( id < 0 ) { exit (ERR_ARG); } /* get the quota info */ quota = quota_new (argdata->id_type, id, argdata->qfile); if ( ! quota ) { exit (ERR_SYS); } if ( ! quota_get(quota) ) { exit (ERR_SYS); } // FIXME: remote debug //output_info("BLOCKS_TO_KB(quota->block_soft): %llu\n", BLOCKS_TO_KB(quota->block_soft)); //output_info("DIV_UP(quota->block_soft, 1024): %llu\n", DIV_UP(quota->block_soft, 1024)); //output_info("DEBUG: quota->block_soft: %llu\n", quota->block_soft); if (argdata->dump_info) { time_t now = time(NULL); u_int64_t display_blocks_used = 0; output_info (""); output_info ("%s Filesystem blocks quota limit grace files quota limit grace", argdata->id_type == QUOTA_USER ? "uid" : "gid"); // quota->diskspace_used is bytes. Display in Kb display_blocks_used = DIV_UP(quota->diskspace_used, 1024); #ifdef HAVE_INTTYPES_H printf("%d %s %" PRIu64 " %" PRIu64 " %" PRIu64 " %lu %" PRIu64 " %" PRIu64 " %" PRIu64 " %lu\n", #else printf("%d %s %llu %llu %llu %lu %llu %llu %llu %lu\n", #endif id, argdata->qfile, display_blocks_used, BLOCKS_TO_KB(quota->block_soft), BLOCKS_TO_KB(quota->block_hard), #if ANY_BSD || PLATFORM_DARWIN (unsigned long) (( (quota->block_soft && (BYTES_TO_BLOCKS(quota->diskspace_used) >= quota->block_soft)) || (quota->block_hard && (BYTES_TO_BLOCKS(quota->diskspace_used) >= quota->block_hard)) ) ? quota->block_time - now : 0), #else (unsigned long) quota->block_time ? quota->block_time - now : 0, #endif /* ANY_BSD */ quota->inode_used, quota->inode_soft, quota->inode_hard, #if ANY_BSD || PLATFORM_DARWIN (unsigned long) (( (quota->inode_soft && (quota->inode_used >= quota->inode_soft)) || (quota->inode_hard && (quota->inode_used >= quota->inode_hard)) ) ? quota->inode_time - now : 0)); #else (unsigned long) quota->inode_time ? quota->inode_time - now : 0); #endif /* ANY_BSD */ exit(0); }
int main (int argc, char *argv[]) { if (argc < 3) usage (); char *command = argv[1]; char *path = argv[2]; char fpath[PATH_MAX]; if (realpath (path, fpath) == NULL) error ("main_realpath"); if (strcmp (command, "set") == 0) { if (argc < 4) usage (); int c = getopt (argc, argv, "u:"); enum units unit = (c < 0) ? BYTES : char_to_units (optarg[0]); unsigned long size = (unsigned long) atol (argv[3]); quota_set (fpath, size, unit); } else if (strcmp (command, "get") == 0) { int c = getopt (argc, argv, "u:"); enum units unit = (c < 0) ? BYTES : char_to_units (optarg[0]); long double size = quota_get (fpath, unit); printf ("%Lf\n", size); } else if (strcmp (command, "get-binding") == 0) { int c = getopt (argc, argv, "u:"); enum units unit = (c < 0) ? BYTES : char_to_units(optarg[0]); char binding_path[PATH_MAX]; long double size = quota_get_binding (fpath, unit, binding_path); printf("%Lf on %s\n", size, binding_path); } else if (strcmp (command, "exceeded") == 0) { if(quota_exceeded (path) == 0) printf("NOT "); printf("EXCEEDED\n"); } else if (strcmp (command, "unset") == 0) quota_unset (fpath); else if (strcmp (command, "mount") == 0) { if (argc < 4) usage (); if (realpath (argv[2], base) == NULL) error ("main_realpath"); int i = 1; for (; i < argc; i++) argv[i] = argv[i + 2]; argc -= 2; int ret = fuse_main (argc, argv, &fuse_ops, base); if (ret < 0) error ("fuse_main"); return ret; } else usage (); return 0; }