Beispiel #1
0
int
main(int argc, char *argv[])
{
	FTS *fts;
	FTSENT *p;
	long blocksize;
	quad_t totalblocks;
	int ftsoptions, listdirs, listfiles;
	int Hflag, Lflag, aflag, cflag, hflag, kflag, sflag;
	int ch, notused, rval;
	char **save;

	save = argv;
	Hflag = Lflag = aflag = cflag = hflag = kflag = sflag = 0;
	totalblocks = 0;
	ftsoptions = FTS_PHYSICAL;
	while ((ch = getopt(argc, argv, "HLPachksxr")) != -1)
		switch (ch) {
		case 'H':
			Hflag = 1;
			Lflag = 0;
			break;
		case 'L':
			Lflag = 1;
			Hflag = 0;
			break;
		case 'P':
			Hflag = Lflag = 0;
			break;
		case 'a':
			aflag = 1;
			break;
		case 'c':
			cflag = 1;
			break;
		case 'h':
			hflag = 1;
			kflag = 0;
			break;
		case 'k':
			kflag = 1;
			hflag = 0;
			break;
		case 's':
			sflag = 1;
			break;
		case 'r':
			break;
		case 'x':
			ftsoptions |= FTS_XDEV;
			break;
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	/*
	 * XXX
	 * Because of the way that fts(3) works, logical walks will not count
	 * the blocks actually used by symbolic links.  We rationalize this by
	 * noting that users computing logical sizes are likely to do logical
	 * copies, so not counting the links is correct.  The real reason is
	 * that we'd have to re-implement the kernel's symbolic link traversing
	 * algorithm to get this right.  If, for example, you have relative
	 * symbolic links referencing other relative symbolic links, it gets
	 * very nasty, very fast.  The bottom line is that it's documented in
	 * the man page, so it's a feature.
	 */
	if (Hflag)
		ftsoptions |= FTS_COMFOLLOW;
	if (Lflag) {
		ftsoptions &= ~FTS_PHYSICAL;
		ftsoptions |= FTS_LOGICAL;
	}

	if (aflag) {
		if (sflag)
			usage();
		listdirs = listfiles = 1;
	} else if (sflag)
		listdirs = listfiles = 0;
	else {
		listfiles = 0;
		listdirs = 1;
	}

	if (!*argv) {
		argv = save;
		argv[0] = ".";
		argv[1] = NULL;
	}

	if (hflag)
		blocksize = 512;
	else if (kflag)
		blocksize = 1024;
	else
		(void)getbsize(&notused, &blocksize);
	blocksize /= 512;

	if ((fts = fts_open(argv, ftsoptions, NULL)) == NULL)
		err(1, "fts_open");

	for (rval = 0; (p = fts_read(fts)) != NULL;)
		switch (p->fts_info) {
		case FTS_D:			/* Ignore. */
			break;
		case FTS_DP:
			p->fts_parent->fts_number += 
			    p->fts_number += p->fts_statp->st_blocks;
			if (cflag)
				totalblocks += p->fts_statp->st_blocks;
			/*
			 * If listing each directory, or not listing files
			 * or directories and this is post-order of the
			 * root of a traversal, display the total.
			 */
			if (listdirs ||
			    (!listfiles && p->fts_level == FTS_ROOTLEVEL)) {
				prtout((quad_t)howmany(p->fts_number,
				    (unsigned long)blocksize), p->fts_path,
				    hflag);
			}
			break;
		case FTS_DC:			/* Ignore. */
			break;
		case FTS_DNR:			/* Warn, continue. */
		case FTS_ERR:
		case FTS_NS:
			warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
			rval = 1;
			break;
		default:
			if (p->fts_statp->st_nlink > 1 && linkchk(p))
				break;
			/*
			 * If listing each file, or a non-directory file was
			 * the root of a traversal, display the total.
			 */
			if (listfiles || p->fts_level == FTS_ROOTLEVEL)
				prtout(howmany(p->fts_statp->st_blocks,
				    blocksize), p->fts_path, hflag);
			p->fts_parent->fts_number += p->fts_statp->st_blocks;
			if (cflag)
				totalblocks += p->fts_statp->st_blocks;
		}
	if (errno)
		err(1, "fts_read");
	if (cflag) {
		prtout((quad_t)howmany(totalblocks, blocksize), "total", hflag);
	}
	exit(rval);
}
Beispiel #2
0
/* MAIN PROGRAM */
int main(int argc, char *argv[]) 
{
/* DATA DECLARATIONS */
    FILE *ifp;											/* Input File Pointer 
														*/
	FILE *ofp;											/* Output File Pointer
														*/
	float rec[INREC_ROWS][INREC_COLS][INREC_VALUES];			/* Input Record Data
															  Row 0:  Asset Data
															  Row 1:  Delta P(dis) Data
															  Row 2:  Delta P(def) Data
															  Row 3:  Delta P(den) Data
															  Row 4:  Delta P(dim) Data
															               0  1    2        3      4      5      6      7      8
															  Asset Data:  ID Type Location P(dis) P(def) P(den) P(dim) %(dam) Theta
															               0    1   2   3   4   5   6   7   8   9   10
															  Delta Data:  #pts pt1 pt2 pt3 pt4 pt5 pt6 pt7 pt8 pt9 pt10
															               0            1
															  Point Data:  delta-theta	cost
														*/
	int		dis_pts, def_pts, den_pts, dim_pts,
			disx, defx, denx, dimx;
	float	dis_dtheta, dis_cost, 
			def_dtheta, def_cost,
			den_dtheta, den_cost,
			dim_dtheta, dim_cost,
			dis_prop, def_prop, den_prop, dim_prop,
			dis_tsave, dis_csave,
			def_tsave, def_csave,
			den_tsave, den_csave,
			dim_tsave, dim_csave;
	float	theta_prop, theta_cost, theta_max;

	float	outrec[OUTREC_COLS];						/* Output Record Data
														      <=========== same as input record format ===========>
															  0  1    2        3      4      5      6      7      8		9	   10	 11	    12	   13	  14	 15
															  ID Type Location P(dis) P(def) P(den) P(dim) %(dam) Theta DTheta TCost D(dis) D(def) D(den) D(dim) Run#
														*/

/* DATA PROCESSING */
	printf ("Start Program...\n");
    
	/* Get input file name. */
    if (argc == 1)
    {
        printf ("  No input file specified.\n");
        return -1;
    }
    
	/* Get output file name. */
    if (argc == 2)
    {
        printf ("  No output file specified.\n");
        return -1;
    }

	/* Open input and output files */
    ifp = fopen (argv[1], "r+");
	ofp = fopen (argv[2], "w+");

	printf (" Process Asset Records...\n");

	/* Process each asset record */
	while (getnext (ifp, rec))
	{
		/* Find optimum theta/cost combinations for each asset */
		dis_pts = rec [ROW_DPDIS][IDX_POINTS][IDX_DATA];
		def_pts = rec [ROW_DPDEF][IDX_POINTS][IDX_DATA];
		den_pts = rec [ROW_DPDEN][IDX_POINTS][IDX_DATA];
		dim_pts = rec [ROW_DPDIM][IDX_POINTS][IDX_DATA];

		/* P(dis) */
		dis_tsave = 0;
		dis_csave = 0;
		dis_prop  = 0;
		for (disx = 0; disx < dis_pts; disx++)
		{
			dis_dtheta = rec[ROW_DPDIS][disx+1][IDX_DTHETA];
			dis_cost   = rec[ROW_DPDIS][disx+1][IDX_COST];

			if (dis_dtheta / dis_cost > dis_prop)
			{
				dis_prop  = dis_dtheta / dis_cost;
				dis_tsave = dis_dtheta;
				dis_csave = dis_cost;
			}
		}

		/* P(def) */
		def_tsave = 0;
		def_csave = 0;
		def_prop  = 0;
		for (defx = 0; defx < def_pts; defx++)
		{
			def_dtheta = rec[ROW_DPDEF][defx+1][IDX_DTHETA];
			def_cost   = rec[ROW_DPDEF][defx+1][IDX_COST];

			if (def_dtheta / def_cost > def_prop)
			{
				def_prop  = def_dtheta / def_cost;
				def_tsave = def_dtheta;
				def_csave = def_cost;
			}
		}

		/* P(den) */
		den_tsave = 0;
		den_csave = 0;
		den_prop  = 0;
		for (denx = 0; denx < den_pts; denx++)
		{
			den_dtheta = rec[ROW_DPDEN][denx+1][IDX_DTHETA];
			den_cost   = rec[ROW_DPDEN][denx+1][IDX_COST];

			if (den_dtheta / den_cost > den_prop)
			{
				den_prop  = den_dtheta / den_cost;
				den_tsave = den_dtheta;
				den_csave = den_cost;
			}
		}


		/* P(dim) */
		dim_tsave = 0;
		dim_csave = 0;
		dim_prop  = 0;
		for (dimx = 0; dimx < dim_pts; dimx++)
		{
			dim_dtheta = rec[ROW_DPDIM][dimx+1][IDX_DTHETA];
			dim_cost   = rec[ROW_DPDIM][dimx+1][IDX_COST];

			if (dim_dtheta / dim_cost > dim_prop)
			{
				dim_prop  = dim_dtheta / dim_cost;
				dim_tsave = dim_dtheta;
				dim_csave = dim_cost;
			}
		}
		
		/* Prepare output record */
		outrec[COL_ID]     = rec[ROW_ASSET][COL_ID]   [IDX_DATA];
		outrec[COL_TYPE]   = rec[ROW_ASSET][COL_TYPE] [IDX_DATA];
		outrec[COL_LOC]    = rec[ROW_ASSET][COL_LOC]  [IDX_DATA];
		outrec[COL_PDIS]   = rec[ROW_ASSET][COL_PDIS] [IDX_DATA] + dis_tsave;
		outrec[COL_PDEF]   = rec[ROW_ASSET][COL_PDEF] [IDX_DATA] + def_tsave;
		outrec[COL_PDEN]   = rec[ROW_ASSET][COL_PDEN] [IDX_DATA] + den_tsave;
		outrec[COL_PDIM]   = rec[ROW_ASSET][COL_PDIM] [IDX_DATA] + dim_tsave;
		outrec[COL_PDAM]   = rec[ROW_ASSET][COL_PDAM] [IDX_DATA];
		outrec[COL_THETA]  = outrec[COL_PDIS] * outrec[COL_PDEF] * outrec[COL_PDEN] * 
							 outrec[COL_PDIM] * outrec[COL_PDAM];
		/* Recalculate previous theta to avert precision errors */
		outrec[COL_DTHETA] = outrec[COL_THETA] - 
							 (rec[ROW_ASSET][COL_PDIS][IDX_DATA] *
							  rec[ROW_ASSET][COL_PDEF][IDX_DATA] *
							  rec[ROW_ASSET][COL_PDEN][IDX_DATA] *
							  rec[ROW_ASSET][COL_PDIM][IDX_DATA] *
							  rec[ROW_ASSET][COL_PDAM][IDX_DATA] );
		/* Adjust for precision errors from very small numbers */
		if ((dis_tsave + def_tsave + den_tsave + dim_tsave) == 0) 
		{
			outrec[COL_THETA]  = rec[ROW_ASSET][COL_THETA][IDX_DATA];
			outrec[COL_DTHETA] = 0; 
		}
		outrec[COL_TCOST]  = dis_csave + def_csave + den_csave + dim_csave;
		outrec[COL_DDIS]   = dis_csave;
		outrec[COL_DDEF]   = def_csave;
		outrec[COL_DDEN]   = den_csave;
		outrec[COL_DDIM]   = dim_csave;

		prtout (ofp, outrec);
	}

	fclose (ifp);

	/* Append EOF to end of output file */
	fprintf (ofp, "%d\n", EOF);
	fclose (ofp);

	printf ("End Program...\n");
    return 0;
}
Beispiel #3
0
void print_channel3(glite_transfer_Channel3 * ch){
    int i = 0;
    printf("Channel: %s\n",                     ch->channelName);
    printf("Between: %s and %s\n",              ch->sourceSite,ch->destSite);
    printf("State: %s\n",                       glite_channel_state_str(ch->state));
    printf("Contact: %s\n",                     ch->contact);
    printf("Bandwidth: %d\n",                   ch->bandwidth);
    printf("Nominal throughput: %d\n",          ch->nominalThroughput);
    printf("Number of files: %d, streams: %d\n",ch->numberOfFiles, ch->numberOfStreams);
    printf("TCP buffer size: %s\n",             val(ch->tcpBufferSize,"default"));
    printf("Message: %s\n",                     val(ch->message,"no message"));
    printf("Last modification by: %s\n",        ch->lastModifierDn);
    prtime("Last modification time",            &(ch->lastModificationTime));
    prtime("Last active time",                  &(ch->lastActiveTime));
#if 0 
    // do not show these values...
    printf("Storage Element limit: %d\n",       ch->seLimit);
    printf("Chanel type: %s",                   val(ch->channelType,"undefined"));
#endif
    prtout("First transfer marker timeout",     ch->urlCopyFirstTxmarkTo);
    printf("Check target directory: %s\n",      ch->targetDirCheck ? "Y" : "N");
    
    printf("Block size: %s\n",                  val(ch->blockSize,"default"));
    prtout("Http timeout",                      ch->httpTimeout);
    printf("Transfer log level: %s\n",          val(ch->transferLogLevel,"default"));
    printf("SRM negotiations/transfers : %f\n", ch->preparingFilesRatio);
    printf("Transfer type: %s\n",               val(ch->transferType,"NOT SET"));
    prtout("Put timeout",                       ch->urlCopyPutTimeout);
    prtout("Put done timeout",                  ch->urlCopyPutDoneTimeout);
    prtout("Get timeout",                       ch->urlCopyGetTimeout);
    prtout("Get done timeout",                  ch->urlCopyGetDoneTimeout);
    prtout("Url copy transfer timeout",         ch->urlCopyTransferTimeout);
    prtout("Transfer markers timeout",          ch->urlCopyTransferMarkersTimeout);
    prtout("No progress timeout",               ch->urlCopyNoProgressTimeout);
    if (ch->urlCopyTransferTimeoutPerMB > 0){
        printf("Size-based additional timeout: %f (secs/MB)\n",ch->urlCopyTransferTimeoutPerMB);
    } else {
        printf("Size-based additional timeout: unset\n");
    }
    printf("Srm copy direction: %s\n",          val(ch->srmCopyDirection,"default"));
    prtout("Srm copy timeout",                  ch->srmCopyTimeout);
    prtout("Srm copy refresh timeout",          ch->srmCopyRefreshTimeout);
    
    printf("Number of VO shares: %d\n", ch->__sizeVOShares);
    for (i = 0; i < ch->__sizeVOShares; ++i) {
        if ( ! strcmp(ch->VOLimits[i]->limit, "0") ) {
            printf("VO '%s' share is: %s and is not limited\n",ch->VOShares[i]->VOName,ch->VOShares[i]->share);
        } else {
            printf("VO '%s' share is: %s and is limited to %s transfers\n",
                ch->VOShares[i]->VOName,ch->VOShares[i]->share,ch->VOLimits[i]->limit);
        }
    }
}