Ejemplo n.º 1
0
int64_t ParseSize(const UnicodeString & SizeStr)
{
  AnsiString AnsiSizeStr = AnsiString(SizeStr);
  return parse_blocksize(AnsiSizeStr.c_str());
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
	int longindex, ch;
	int bs = SECTOR_SIZE, count = 1, i;
	int rw = READ_10, max_outstanding = 32, ret;

	while ((ch = getopt_long(argc, argv, "b:c:wo:h", long_options,
				 &longindex)) >= 0) {
		switch (ch) {
		case 'b':
			bs = parse_blocksize(optarg);
			break;
		case 'c':
			count = atoi(optarg);
			break;
		case 'w':
			rw = WRITE_10;
			break;
		case 'o':
			max_outstanding = atoi(optarg);
			break;
		case 'h':
			usage(0);
			break;
		default:
			usage(1);
			break;
		}
	}

	if (bs % SECTOR_SIZE) {
		fprintf(stderr, "The I/O size should be a multiple of %d\n",
			SECTOR_SIZE);
		exit(1);
	}

	if (!max_outstanding) {
		fprintf(stderr, "The number outstanding shouldn't be zero\n");
		exit(1);
	}

	if (!count) {
		fprintf(stderr, "The number requests shouldn't be zero\n");
		exit(1);
	}

	if (max_outstanding > count)
		max_outstanding = count;

	if (argc == optind) {
		fprintf(stderr, "specify a bsg device\n");
		usage(1);
	}

	if (argc - optind > MAX_DEVICE_NR) {
		fprintf(stderr, "too many devices, the max is %d\n",
			MAX_DEVICE_NR);
		exit(1);
	}

	for (i = 0; i < argc - optind; i++) {
		bi[i].fd = open_bsg_dev(argv[optind + i]);
		if (bi[i].fd < 0)
			exit(1);

		ret = get_capacity(bi[i].fd, &(bi[i].size));
		if (ret) {
			fprintf(stderr, "can't get the capacity\n");
			exit(1);
		}
	}

	loop(argc - optind, count, max_outstanding, bs, rw);

	return 0;
}
Ejemplo n.º 3
0
//---------------------------------------------------------------------------
__int64 __fastcall ParseSize(UnicodeString SizeStr)
{
  AnsiString AnsiSizeStr = SizeStr;
  return parse_blocksize(AnsiSizeStr.c_str());
}
Ejemplo n.º 4
0
int 
main(int argc, char *argv[])
{
    confent_t *conf;
    int c;
    int dopt = 0;
    int popt = 0;
    unsigned long bsize = 1024*1024;
    char *fsname = NULL;
    List qlist;
    int Fopt = 0;
    int ropt = 0;
    int sopt = 0;
    int Hopt = 0;
    int Uopt = 0;
    int nopt = 0;
    int hopt = 0;
    List uids = NULL;
    char *conf_path = _PATH_QUOTA_CONF;
    conf_t config;

    prog = basename(argv[0]);
    while ((c = GETOPT(argc, argv, OPTIONS, longopts)) != EOF) {
        switch(c) {
            case 'd':   /* --dirscan */
                dopt++;
                break;
            case 'p':   /* --pwscan */
                popt++;
                break;
            case 'b':   /* --blocksize */
                if (parse_blocksize(optarg, &bsize)) {
                    fprintf(stderr, "%s: error parsing blocksize\n", prog); 
                    exit(1);
                }
                break;
            case 'u':   /* --uid-range */
                uids = listint_create(optarg);
                if (uids == NULL) {
                    fprintf(stderr, "%s: error parsing uid-range\n", prog);
                    exit(1);
                }
                break;
            case 'r':   /* --reverse */
                ropt++;
                break;
            case 'F':   /* --files-sort */
                Fopt++;
                break;
            case 's':   /* --space-sort */
                sopt++;
                break;
            case 'U':   /* --usage-only */
                Uopt++;
                break;
            case 'H':   /* --suppress-heading */
                Hopt++;
                break;
            case 'f':   /* --config */
                conf_path = optarg;
                break;
            case 'T':   /* --selftest */
#ifndef NDEBUG
                listint_test();
                exit(0);
#else
                fprintf(stderr, "%s: not built with debugging enabled\n", prog);
                exit(1);
#endif
                break;
            case 'D':   /* --debug */
                debug = 1;
                break;
            case 'n':   /* --nouserlookup */
                nopt = 1;
                break;
            case 'h':   /* --human-readable */
                hopt = 1;
                break;
            default:
                usage();
        }
    }
    if (Fopt && sopt) {
        fprintf(stderr, "%s: -f and -s are mutually exclusive\n", prog);
        exit(1);
    }
    if (popt && dopt) {
        fprintf(stderr, "%s: -p and -d are mutually exclusive\n", prog);
        exit(1);
    }
    if (!popt && !dopt && !uids) {
        fprintf(stderr, "%s: need at least one of -pdu\n", prog);
        exit(1);
    }
    if (optind < argc)
        fsname = argv[optind++];
    else
        usage();
    if (optind < argc)
        usage();
    config = conf_init(conf_path); /* exit/perror on error */

    if (!(conf = conf_get_bylabel(config, fsname, 0))) {
        fprintf(stderr, "%s: %s: not found in quota.conf\n", prog, fsname);
        exit(1);
    }
        
    /* Scan.
     */
    qlist = list_create((ListDelF)quota_destroy);
    if (popt)
        pwscan(conf, qlist, uids, !nopt);
    if (dopt) 
        dirscan(conf, qlist, uids, !nopt);
    if (!dopt && !popt)
        uidscan(conf, qlist, uids, !nopt);


    /* Sort.
     */
    if (ropt) {
        if (sopt)
            list_sort(qlist, (ListCmpF)quota_cmp_bytes_reverse);
        else if (Fopt)
            list_sort(qlist, (ListCmpF)quota_cmp_files_reverse);
        else
            list_sort(qlist, (ListCmpF)quota_cmp_uid_reverse);
    } else {
        if (sopt)
            list_sort(qlist, (ListCmpF)quota_cmp_bytes);
        else if (Fopt)
            list_sort(qlist, (ListCmpF)quota_cmp_files);
        else
            list_sort(qlist, (ListCmpF)quota_cmp_uid);
    }

    /* Report.
     */
    if (!Hopt) {

        if (hopt)
            printf("Quota report for %s\n", fsname);
        else {
            char tmpstr[16];
            size2str(bsize, tmpstr, sizeof(tmpstr));
            printf("Quota report for %s (blocksize %s)\n", fsname, tmpstr);
        }
    }
    if (Uopt) {
        if (!Hopt)
            quota_report_heading_usageonly();
        if (hopt)
            list_for_each(qlist, (ListForF)quota_report_usageonly_h, &bsize);
        else
            list_for_each(qlist, (ListForF)quota_report_usageonly, &bsize);
    } else {
        if (!Hopt)
            quota_report_heading();
        if (hopt)
            list_for_each(qlist, (ListForF)quota_report_h, &bsize);
        else
            list_for_each(qlist, (ListForF)quota_report, &bsize);
    }

    if (qlist)
        list_destroy(qlist);
    if (uids)
        listint_destroy(uids);
    conf_fini(config);

    return 0;
}