Esempio n. 1
0
File: main.c Progetto: jds0102/osp3
// Main
int main( int argc, char* argv[]){
  // Declarations of variables
  char * filename;
  char c;
  char * endptr;
  FILE * fd = 0;
  
  // Make sure number of args is 11 or 12 (verbose optional)
  if (argc != 11 && argc != 12){
    errorMsgInput();
  }
    
  // Structure to keep all command args  
  static struct option long_options[] =
  {
    {"level",  required_argument, 0, 'a'},
    {"strip",  required_argument, 0, 'b'},
    {"disks",  required_argument, 0, 'c'},
    {"size",   required_argument, 0, 'd'},
    {"trace",  required_argument, 0, 'e'},
    {"verbose", no_argument, 0, 'f'},
    {0, 0, 0, 0}
  };
    
  int option_index = 0;
  
  
  while ((c = getopt_long_only(argc, argv, "a:b:c:d:e:f", long_options, &option_index)) != -1) {
    
    switch (c) {
      // LEVEL  
      case 'a':
	level = strtol(optarg, &endptr, 10);
	// Not an int
	if (endptr == optarg){
	  errorMsgInput();
	} else if (level == 0 || level == 10 || level == 4 || level == 5){    
	  //Do not need to do anything
	}else { // Not valid RAID number
	  errorMsgInput();
	}
	break;
	
      //STRIP
      case 'b':
	strip = strtol(optarg, &endptr, 10);
	// Not an int
	if (endptr == optarg){
	  errorMsgInput();
	} else if (strip < 1){ // 0 or negative blocks per strip
	  errorMsgInput();
	}
	break;
	    
      // DISKS
      case 'c':
	disks = strtol(optarg, &endptr, 10);
	// Not an int
	if (endptr == optarg){
	  errorMsgInput();
	} else if (disks < 1){ // 0 or negative disks
	  errorMsgInput();
	}
	break;
	
	// SIZE
	case 'd':
	  blockSize = strtol(optarg, &endptr, 10);
	  // Not an int
	  if (endptr == optarg){
	    errorMsgInput();
	  } else if (blockSize < 1){// 0 or negative blocks per disk
	    errorMsgInput();
	  }
	  break;
	  
       // TRACE
       case 'e':
	 filename = malloc(sizeof(char*)*strlen(optarg));
	 strcpy(filename, optarg);
	 fd = fopen(filename, "r");
	 if (fd == 0){
	   errorMsgInput();
	 }
	 break;
	 
       // Verbose case
       case 'f':
	 verbose = 1;
	 break;
	 
       // Default
       default:
	 errorMsgInput();
     }
  }
    
  // Input checking for number of disks vs level
  // Check that if it is RAID 10 there are an even # of disks
  if ((level == 10) && ((disks % 2) != 0)){
    errorMsgInput();
  }
  // Check that both levels 4 and 5 have more than 2 disks
  if (level == 4 && disks < 3){
    errorMsgInput();
  }
  if (level == 5 && disks < 3){
    errorMsgInput();
  }
    
  // Create a disk array
  char * virtualDiskArray = "OurVirutalDisk";
  diskArray = disk_array_create(virtualDiskArray, disks, blockSize);
  
  // Gets the line from the trace file
  char buf[1000];
  while (fgets(buf,1000, fd)!=NULL){
    buf[strlen(buf) - 1] = '\0'; 
    parseLine(buf);
  }
  exit(0);
}
Esempio n. 2
0
int main(int argc, char * argv[]){


	//has appropiate amount of arguments?
	if((argc != 11) || (argc != 13)){
		write(STDERR_FILENO, error_msg, strlen(error_msg));
		exit(-1);
	}

	//set
	for(counter = 0; counter < (argc - 1)/2; ++counter){
		if(strcmp("-level", argv[2*counter+1]) == 0){
			level = atoi(argv[2*counter+2]);

		}else if(strcmp("-strip", argv[2*counter+1]) == 0){
			strip = atoi(argv[2*counter+2]);

		}else if(strcmp("-disks", argv[2*counter+1]) == 0){
			disks = atoi(argv[2*counter+2]);

		}else if(strcmp("-size", argv[2*counter+1]) == 0){
			size = atoi(argv[2*counter+2]);

		}else if(strcmp("-trace", argv[2*counter+1]) == 0){
			trace = argv[2*counter+å2];
		
		}else if(strcmp("-verbose", argv[2*counter+1]) == 0){
			verbose = argv[2*counter+2];
		}
	}

	//CHECK ARGUMENT VALUES
	//valid level of RAID?
	if((level != 0) && (level != 10) && (level != 4) && (level != 5)){
		flag = 1;
		//debugging
		printf("%s\n","Invalid or Not Provided Level");
	}

	/*******************************
	COMPLETE
		CHECK
			ARGUMENT
				VALUES
	*******************************/

	//exit if flag was raised
	if(flag == 1){
		write(STDERR_FILENO, error_msg, strlen(error_msg));
		exit(-1);
	}

	
	//create disk array
	disk_array_t my_disk_array = disk_array_create("MyVirtualDiskArray", disks, size);
	if(!my_disk_array){
		//debugging
		printf("%s\n","Unable to Create Virtual Disks");
		
		write(STDERR_FILENO, error_msg, strlen(error_msg));		
		exit(-1);
	}

	
	chooseSystem(level);
	
	
}