static void
passthrough(const char *target)
{
	int r;

	if (!assertMakeDir(target, 0775))
		return;

	/*
	 * Use cpio passthrough mode to copy files to another directory.
	 */
	r = systemf("%s -p %s <filelist >%s/stdout 2>%s/stderr",
	    testprog, target, target, target);
	failure("Error invoking %s -p", testprog);
	assertEqualInt(r, 0);

	assertChdir(target);

	/* Verify stderr. */
	failure("Error invoking %s -p in dir %s",
	    testprog, target);
	assertTextFileContents("1 block\n", "stderr");

	verify_files("passthrough");
	assertChdir("..");
}
Beispiel #2
0
int main( int argc, char **argv ) {
  FILE *master, *student;
  master = NULL;
  student = NULL;

  unsigned int mismatches;
  
  // Two arguments means that we are comparing two files where the first input
  // is the master and the second one is the student's.
  if ( argc == 3 ) {
    master = fopen( argv[1], "r" );
    student = fopen( argv[2], "r" );

    // Check if we failed to open the files.
    if ( !master ) {
      printf( "Error trying to open master file: [%s]\n", argv[1] );
      return ( -1 );
    }
    if ( !student ) {
      printf( "Error trying to open student file: [%s]\n", argv[2] );
    }
  }
  // 1 argument means that we just have the master file to compare against and
  // we are reading information from the student's program (stdin)
  else if ( argc == 2 ) {
    master = fopen( argv[1], "r" );
    
    // Check if we failed to open the files.
    if ( !master ) {
      printf( "Error trying to open master file: [%s]\n", argv[1] );
      return ( -1 );
    }
  }
  // Incorrect 
  else {
    fprintf( stderr, "Incorrect usage:\n" );
    fprintf( stderr, USAGE );
    return ( -1 );
  }

  printf( "Beginning diff check:\n\n" );
  // Verify that student file matches master file.
  mismatches = verify_files( master, student );

  // Clean up after ourselves.
  fclose( master );
  if ( student && student != stdin ) {
    fclose( student );
  }

  // Return
  if ( mismatches ) {
    return ( -1 );
  }

  return ( 0 );
}
Beispiel #3
0
int main( int argc, char **argv ) {
  FILE *master, *clnt, *srvr;
  master = NULL;
  clnt = NULL;
  srvr = NULL;

  unsigned int mismatches;
  
  // Two arguments means that we are comparing two files where the first input
  // is the master and the second one is the student's.
  if ( argc == 4 ) {
    master = fopen( argv[1], "r" );
    clnt = fopen( argv[2], "r" );
    srvr = fopen( argv[3], "r" );

    // Check if we failed to open the files.
    if ( !master ) {
      printf( "Error trying to open master file: [%s]\n", argv[1] );
      return ( -1 );
    }
    if ( !clnt ) {
      printf( "Error trying to open cliet file: [%s]\n", argv[2] );
    }
    if ( !srvr ) {
      printf( "Error trying to open srvr file: [%s]\n", argv[2] );
    }
  }
  // Incorrect 
  else {
    fprintf( stderr, "Incorrect usage:\n" );
    fprintf( stderr, USAGE );
    return ( -1 );
  }

  printf( "Beginning diff check:\n\n" );
  // Verify that student files match master file.
  mismatches = verify_files( master, clnt, srvr );

  // Clean up after ourselves.
  fclose( master );
  master = NULL;
  fclose( clnt );
  clnt = NULL;
  fclose( srvr );
  srvr = NULL;

  // Return
  if ( mismatches ) {
    return ( -1 );
  }

  return ( 0 );
}
static void
basic_cpio(const char *target,
    const char *pack_options,
    const char *unpack_options,
    const char *se, const char *se2)
{
	int r;

	if (!assertMakeDir(target, 0775))
	    return;

	/* Use the cpio program to create an archive. */
	r = systemf("%s -o %s < filelist >%s/archive 2>%s/pack.err",
	    testprog, pack_options, target, target);
	failure("Error invoking %s -o %s", testprog, pack_options);
	assertEqualInt(r, 0);

	assertChdir(target);

	/* Verify stderr. */
	failure("Expected: %s, options=%s", se, pack_options);
	assertTextFileContents(se, "pack.err");

	/*
	 * Use cpio to unpack the archive into another directory.
	 */
	r = systemf("%s -i %s< archive >unpack.out 2>unpack.err",
	    testprog, unpack_options);
	failure("Error invoking %s -i %s", testprog, unpack_options);
	assertEqualInt(r, 0);

	/* Verify stderr. */
	failure("Error invoking %s -i %s in dir %s", testprog, unpack_options, target);
	assertTextFileContents(se2, "unpack.err");

	verify_files(pack_options);

	assertChdir("..");
}
Beispiel #5
0
int main(int argc, char **argv){
	int ret;
	unsigned minor;
	size_t snap_size, bytes, blocks_to_read;
	sector_t total_chunks, total_blocks, i, j, blocks_done = 0, count = 0, err_count = 0;
	FILE *cow = NULL, *snap = NULL, *img = NULL;
	uint64_t *mappings = NULL;
	char *snap_path;
	char snap_path_buf[PATH_MAX];

	if(argc != 4) print_help(argv[0], EINVAL);

	//open snapshot
	snap = fopen(argv[1], "r");
	if(!snap){
		ret = errno;
		errno = 0;
		fprintf(stderr, "error opening snapshot\n");
		goto error;
	}

	//open cow file
	cow = fopen(argv[2], "r");
	if(!cow){
		ret = errno;
		errno = 0;
		fprintf(stderr, "error opening cow file\n");
		goto error;
	}

	//open original image
	img = fopen(argv[3], "r+");
	if(!img){
		ret = errno;
		errno = 0;
		fprintf(stderr, "error opening image\n");
		goto error;
	}

	//get the full path of the cow file
	snap_path = realpath(argv[1], snap_path_buf);
	if(!snap_path){
		ret = errno;
		errno = 0;
		fprintf(stderr, "error determining full path of snapshot\n");
		goto error;
	}

	//get the minor number of the snapshot
	ret = sscanf(snap_path, "/dev/datto%u", &minor);
	if(ret != 1){
		ret = errno;
		errno = 0;
		fprintf(stderr, "snapshot does not appear to be a dattobd snapshot device\n");
		goto error;
	}

	//verify all of the inputs before attempting to merge
	ret = verify_files(cow, minor);
	if(ret) goto error;

	//get size of snapshot, calculate other needed sizes
	fseeko(snap, 0, SEEK_END);
	snap_size = ftello(snap);
	total_blocks = (snap_size + COW_BLOCK_SIZE - 1) / COW_BLOCK_SIZE;
	total_chunks = (total_blocks + INDEX_BUFFER_SIZE - 1) / INDEX_BUFFER_SIZE;
	rewind(snap);

	printf("snapshot is %llu blocks large\n", total_blocks);

	//allocate mappings array
	mappings = malloc(INDEX_BUFFER_SIZE * sizeof(uint64_t));
	if(!mappings){
		ret = ENOMEM;
		fprintf(stderr, "error allocating mappings\n");
		goto error;
	}

	//count number of blocks changed while performing merge
	printf("copying blocks\n");
	for(i = 0; i < total_chunks; i++){
		//read a chunk of mappings from the cow file
		blocks_to_read = MIN(INDEX_BUFFER_SIZE, total_blocks - blocks_done);

		bytes = pread(fileno(cow), mappings, blocks_to_read * sizeof(uint64_t), COW_HEADER_SIZE + (INDEX_BUFFER_SIZE * sizeof(uint64_t) * i));
		if(bytes != blocks_to_read * sizeof(uint64_t)){
			ret = errno;
			errno = 0;
			fprintf(stderr, "error reading mappings into memory\n");
			goto error;
		}

		//copy blocks where the mapping is set
		for(j = 0; j < blocks_to_read; j++){
			if(!mappings[j]) continue;

			ret = copy_block(snap, img, (INDEX_BUFFER_SIZE * i) + j);
			if(ret) err_count++;

			count++;
		}

		blocks_done += blocks_to_read;
	}

	//print number of blocks changed
	printf("copying complete: %llu blocks changed, %llu errors\n", count, err_count);

	free(mappings);
	fclose(cow);
	fclose(snap);
	fclose(img);

	return 0;

error:
	if(mappings) free(mappings);
	if(cow) fclose(cow);
	if(snap) fclose(snap);
	if(img) fclose(img);

	return ret;
}
Beispiel #6
0
/**
 * @brief ...
 * @param argc
 * @param argv
 * @param lib
 */
int my_main(int argc, char *argv[], char lib)
{
    char *wchars = NULL;
    char *preftype = NULL;
    static char outbuf[BUFSIZ];
    int arglen, old_argc;
    char *cpd = NULL;
    char *Cmd = *argv;
    /* Pointer to name of $(LIBDIR)/dict */
    char *LibDict = NULL; 

    islib = lib;
    old_argc = argc;
    Trynum = 0;
    sprintf(hashname, "%s/%s", LIBDIR, DEFHASH);
    strcpy(signs, DEFAULT_SIGNS);

    argv++;
    argc--;
    while (argc && **argv == '-') {
		/*
		 * Trying to add a new flag?  Can't remember what's been used?
		 * Here's a handy guide:
		 *
		 * Used:
		 *        ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789
		 *        ^^^^       ^^^ ^  ^^ ^^
		 *        abcdefghijklmnopqrstuvwxyz
		 *        ^^^^^^*    ^^^*^  ^^*^^^*
		 */
		arglen = strlen(*argv);
		add_inc = 0;
	
		switch ((*argv)[1]) {
		case 'v':
		    option_v(Cmd, argc, argv, arglen);
		    break;
		case 'n':
		    preftype = option_n(Cmd, preftype, arglen);
		    break;
		case 't': /* TeX mode */
		    preftype = option_t(Cmd, preftype, arglen);
		    break;
		case 'T': /* Set preferred file type */
		    preftype = option_T(Cmd, argc, argv);
		    break;
		case 'A':
		    option_A(Cmd, arglen);
		    break;
		case 'a':
		    option_a(Cmd, arglen);
		    break;
		case 'D':
		    option_D(Cmd, arglen);
		    break;
		case 'J':
		    option_J(Cmd, arglen);
		    break;
		case 'e':
		    option_e(Cmd, arglen, argv);
		    break;
		case 'c':
		    option_c(Cmd, arglen, argv);
		    break;
		case 'b':
		    option_b(Cmd, arglen);
		    break;
		case 'x':
		    option_x(Cmd, arglen);
		    break;
		case 'f':
		    option_f(Cmd, argc, argv); 
		    break;
		case 'L':
		    option_L(Cmd, argc, argv);
		    break;
		case 'l':
		    option_l(Cmd, arglen);
		    break;
		case 'S':
		    option_S(Cmd, arglen);
		    break;
		case 'B':   /* -B: report missing blanks */
		    option_B(Cmd, arglen);
		    break;
		case 'C':   /* -C: compound words are acceptable */
		    option_C(Cmd, arglen);
		    break;
		case 'P':   /* -P: don't gen non-dict poss's */
		    option_P(Cmd, arglen);
		    break;
		case 'm':   /* -m: make all poss affix combos*/
		    option_m(Cmd, arglen);
		    break;
		case 'N':   /* -N:  suppress minimenu */
		    option_N(Cmd, arglen);
		    break;
		case 'M':
		    option_M(Cmd, arglen);
		    break;   /* -M:  force minimenu */
		case 'p':
		    option_p(LibDict, &cpd, Cmd, argc, argv);
		    break;
		case 'd':
		    option_d(LibDict, cpd, Cmd, argc, argv);
		    break;
		case 'V':    /* Display 8-bit characters as M-xxx */
		    option_V(Cmd, arglen);
		    break;
		case 'w':
		    wchars = (*argv)+2;
		    if (*wchars == '\0') {
				argv++; argc--;
				if (argc == 0)
				    usage(Cmd);
				wchars = *argv;
		    }
		    break;
		case 'W':
		    option_W(Cmd, argc, argv);
		    break;
		case 'o':
		    option_o(Cmd, argc, argv); 
		    break;
		case 'g':
		    option_g(Cmd, arglen);
		    break;
		case 'u':
		    option_u(Cmd, arglen);
		    break;
		case 'y':
		    option_y(Cmd, arglen);
		    break;
		case 'z':
		    option_z(Cmd, arglen);
		    break;
		default:
		    usage(Cmd);
		}  /* end switch */
	
		if (add_inc) {
		    argv++; argc--;
		}
		argv++; argc--;
    }

    if (!argc  &&  !lflag  &&  !aflag   &&  !eflag  &&  !dumpflag)
		usage(Cmd);

    verify_files(argc, argv);

    if (!oflag) strcpy(o_form, DEF_OUT);
	if (linit() < 0) exit(1); /* Force an error */

    det_prefstringchar(preftype);

    if (prefstringchar < 0)
		defdupchar = 0;
    else
		defdupchar = prefstringchar;

    if (missingspaceflag < 0)
		missingspaceflag = hashheader.defspaceflag;
    if (tryhardflag < 0)
		tryhardflag = hashheader.defhardflag;

    initckch(wchars);

    process_LibDict(LibDict, cpd);

    if (process_a_e_and_d_flags() == 0)
		return 0;

    if (!islib)
		setbuf(stdout, outbuf);

    /* process lflag (also used with the -c option) */
    if (lflag) {
		infile = stdin;
		outfile = stdout;
		if (!islib)
	    	checkfile();
		return 0;
    }

    /* n. of parameters advanced */
    return old_argc - argc; 
}