Exemplo n.º 1
0
int main(int argc, char *argv[]){

	///////////////PARAMETER ERROR CHECKER/////////////////
	//This is to check to make sure that the user 
	//inputs the correct number of parameters.

	if(argc !=2){
		err_sys("Invalid Number of Parameters. Try Again");
		}
	//////////////End of Parameter Error Checker///////////
	int num = atoi(argv[1]); 
	storage = arrayalloc(num);
	directory = diralloc(num);
	diroffset = 0;
	int fd = openfile();
	int storagefd = openstorage();
	int endofile = 0;
	int count = 0;
	char * chunk = (char) 0;
	while(endofile !=-1){
		endofile = fillbuffer(&fd);
		count++;
		fprintf(stderr,"Here: %d times.\n",count);
		processbuffer(&fd, &storagefd, endofile);
	}
	fprintf(stderr,"\nNumber of Records: %d.\n",numorecords);
	close(fd);
	close(storagefd);
	return 0;
}
Exemplo n.º 2
0
int main(int argc, char *argv[]) {
   char *buf;
   int done[NUMOPS];
   int fd[NUMOPS];
   int i;
   int numbytes, numfiles;

   if (argc < 2) {
      fprintf(stderr, "Usage: %s filename1 filename2 ...\n", argv[0]);
      return 1;
   } else if (argc > NUMOPS + 1) {
      fprintf(stderr, "%s: only supports %d simultaneous operations\n",
              argv[0],  NUMOPS);
      return 1;
   }
   numfiles = argc - 1;

   for (i = 0; i < numfiles; i++)  {            /* set up the I/O operations */
      done[i] = 0;
      if ((fd[i] = open(argv[i+1], O_RDONLY)) == -1) {
         fprintf(stderr, "Failed to open %s:%s\n", argv[i+1], strerror(errno));
         return 1;
      }
      if (initaio(fd[i], i) == -1) {
         fprintf(stderr, "Failed to setup I/O op %d:%s\n", i, strerror(errno));
         return 1;
      }
      if (readstart(i) == -1) {
         fprintf(stderr, "Failed to start read %d:%s\n", i, strerror(errno));
         return 1;
      }
   }
   for (  ;  ;  ) {                                         /* loop and poll */
      dowork();
      for (i = 0; i < numfiles; i++) {
         if (done[i])
            continue;
         numbytes = readcheck(i, &buf);
         if ((numbytes == -1) && (errno == EINPROGRESS))
            continue;
         if (numbytes <= 0) {
            if (numbytes == 0)
               fprintf(stderr, "End of file on %d\n", i);
            else
               fprintf(stderr, "Failed to read %d:%s\n", i, strerror(errno));
            done[i] = 1;
            continue;
         }
         processbuffer(i, buf, numbytes);
         reinit(i);
         if (readstart(i) == -1) {
            fprintf(stderr, "Failed to start read %d:%s\n", i, strerror(errno));
            done[i] = 1;
         }
      }
   }
}