Exemple #1
0
int main(int argc, char *argv[])
{
    int fuseargcount=1;
    char *fuseargv[6];
    struct fuse_operations capfs_oper;
    capfs_oper.init        = capfs_init,
               capfs_oper.destroy     = capfs_destroy,
                          capfs_oper.getattr     = capfs_getattr,
                                     capfs_oper.fgetattr    = capfs_fgetattr,
                                                capfs_oper.access      = capfs_access,
                                                           capfs_oper.readlink    = capfs_readlink,
                                                                      capfs_oper.readdir     = capfs_readdir,
                                                                                 capfs_oper.mknod       = capfs_mknod,
                                                                                            capfs_oper.mkdir       = capfs_mkdir,
                                                                                                       capfs_oper.symlink     = capfs_symlink,
                                                                                                                  capfs_oper.unlink      = capfs_unlink,
                                                                                                                             capfs_oper.rmdir       = capfs_rmdir,
                                                                                                                                        capfs_oper.rename      = capfs_rename,
                                                                                                                                                   capfs_oper.link        = capfs_link,
                                                                                                                                                              capfs_oper.chmod       = capfs_chmod,
                                                                                                                                                                         capfs_oper.chown       = capfs_chown,
                                                                                                                                                                                    capfs_oper.truncate    = capfs_truncate,
                                                                                                                                                                                               capfs_oper.ftruncate   = capfs_ftruncate,
                                                                                                                                                                                                          capfs_oper.utimens     = capfs_utimens,
                                                                                                                                                                                                                     capfs_oper.create      = capfs_create,
                                                                                                                                                                                                                                capfs_oper.open        = capfs_open,
                                                                                                                                                                                                                                           capfs_oper.read        = capfs_read,
                                                                                                                                                                                                                                                      capfs_oper.write       = capfs_write,
                                                                                                                                                                                                                                                                 capfs_oper.statfs      = capfs_statfs,
                                                                                                                                                                                                                                                                            capfs_oper.release     = capfs_release,
                                                                                                                                                                                                                                                                                       capfs_oper.opendir     = capfs_opendir,
                                                                                                                                                                                                                                                                                                  capfs_oper.releasedir  = capfs_releasedir,
                                                                                                                                                                                                                                                                                                             capfs_oper.fsync       = capfs_fsync,
                                                                                                                                                                                                                                                                                                                        capfs_oper.flush       = capfs_flush,
                                                                                                                                                                                                                                                                                                                                   capfs_oper.fsyncdir    = capfs_fsyncdir,
                                                                                                                                                                                                                                                                                                                                              capfs_oper.lock        = capfs_lock,
                                                                                                                                                                                                                                                                                                                                                         capfs_oper.bmap        = capfs_bmap,
                                                                                                                                                                                                                                                                                                                                                                    capfs_oper.ioctl       = capfs_ioctl,
                                                                                                                                                                                                                                                                                                                                                                               capfs_oper.poll        = capfs_poll,
                                                                                                                                                                                                                                                                                                                                                                                          capfs_oper.setxattr    = capfs_setxattr,
                                                                                                                                                                                                                                                                                                                                                                                                     capfs_oper.getxattr    = capfs_getxattr,
                                                                                                                                                                                                                                                                                                                                                                                                                capfs_oper.listxattr   = capfs_listxattr,
                                                                                                                                                                                                                                                                                                                                                                                                                           capfs_oper.removexattr = capfs_removexattr,
                                                                                                                                                                                                                                                                                                                                                                                                                                      capfs_oper.flag_nullpath_ok = 0;
    fuseargv[0]=argv[0];
    if ((argc > 1) && (argv[1][0] == '-')) {
        fuseargv[1]=argv[1];
        fuseargcount=2;
    }
    string_literal_wrapper mino("-o");
    fuseargv[fuseargcount]=mino;     //After the argv[0] and optionaly a -d argument set some options:
    string_literal_wrapper allow_other("allow_other");
    fuseargv[fuseargcount+1]=allow_other;  //* allow all users to access the filesystem.
    string_literal_wrapper mins("-s");
    fuseargv[fuseargcount+2]=mins; //Run the filesystem as single threaded.
    string_literal_wrapper mountpoint("/minorfs/cap");
    fuseargv[fuseargcount+3]=mountpoint;
    return fuse_main(4+fuseargcount, fuseargv, &capfs_oper,NULL);
}
Exemple #2
0
void meson_ASCII_IO(char *filename, int rec_seek, int msg_seek)
{ 
    int i,j,k=0,l=0;
    char buf[MAXBUF];
    LimeReader *r;
    int status;
    twopt_mom *corr;
    n_uint64_t nbytes, bytes_left, bytes_to_copy, read_bytes;
    int rec, msg;
    char *lime_type;
    size_t bytes_pad;
    int MB_flag, ME_flag;
    FILE *fin=NULL;
  
    corr=malloc(NMOM_MAX*sizeof(twopt_mom));
  
    fin=fopen(filename,"r");
    error_root(fin == (FILE *)NULL,0,"meson_ASCII_IO [IOarchive.c]",
               "IOarchive: Unable to open file %s for reading\n", filename);
    /* Open LIME reader */
    r = limeCreateReader(fin);
    error_root(r == (LimeReader *)NULL,0,"meson_ASCII_IO [IOarchive.c]",
               "Unable to open LimeReader\n");
    /* Loop over records */
    rec = 0;
    msg = 0;
    while( (status = limeReaderNextRecord(r)) != LIME_EOF ){
    error_root(status != LIME_SUCCESS,0,"meson_ASCII_IO [IOarchive.c]",
             "IOarchive: limeReaderNextRecord returned status = %d\n",status);
    

    nbytes    = limeReaderBytes(r);
    lime_type = limeReaderType(r);
    bytes_pad = limeReaderPadBytes(r);
    MB_flag   = limeReaderMBFlag(r);
    ME_flag   = limeReaderMEFlag(r);

    /* Update message and record numbers */
    if(MB_flag == 1){
      msg++;
      rec = 0;
    }

    rec++;

    /* Skip to next record until target record is reached */
    if (msg != msg_seek || rec != rec_seek) continue;
    
    /* Buffered copy */
    bytes_left = nbytes;
    while(bytes_left > (n_uint64_t)0){
      bytes_to_copy = mino((n_uint64_t)(NMOM_MAX*sizeof(twopt_mom)),bytes_left);
      read_bytes = bytes_to_copy;
      error_root((int)read_bytes>MAXBUF,0,"meson_ASCII_IO [IOarchive.c]",
             "read_bytes exceeds MAXBUF");
      status = limeReaderReadData((void *)buf, &read_bytes, r);
      error_root(status<0 && status !=LIME_EOR,1,"meson_ASCII_IO [IOarchive.c]",
             "LIME read error occurred: status= %d", status);
      error_root(read_bytes != bytes_to_copy,1,"meson_ASCII_IO [IOarchive.c]",
             "Read error %lld bytes wanted,%lld read\n",
                (unsigned long long)nbytes, (unsigned long long)read_bytes);
    
      /* Print to stdout */
      corr=(twopt_mom*)buf;  
      l=0;
      for(i=0;i<NMOM_MAX;i++){
       for(j=0;j<TT;j++)
        {
            printf("%d %s %d %d %d %d %d %d %.16e %.16e\n",
  		k,lime_type,
		(*(corr+l)).musrc,
		(*(corr+l)).musnk,
		(*(corr+l)).p[0],
		(*(corr+l)).p[1],
		(*(corr+l)).p[2],
		j,
		(*(corr+l)).corr[j].re,
		(*(corr+l)).corr[j].im);
        }
       l++;
       k++;
      }
      bytes_left -= bytes_to_copy;
    }
    /* Quit at this record */
    break;
  }
  limeDestroyReader(r);
  fclose(fin);

}
Exemple #3
0
int read_qdppp_scidac_binary_data(char *buff_out, long int buff_size, char *fin)
{

  char buf[MAXBUF];  /* auxilary buffer for using a buffer copy. Bytes first copied to buf then from buf to buff_out*/
  LimeReader *reader;
  int status;
  n_uint64_t nbytes, bytes_left, bytes_to_copy, read_bytes;
  int rec_seek,msg_seek;
  int rec, msg;
  char *lime_type;
  size_t bytes_pad;
  int MB_flag, ME_flag;

  int i;
  /* Open file */
  FILE *fp = fopen(fin, "r");
  if(fp == NULL) { 
    fprintf(stderr,"Unable to open file %s for reading\n", fin);
    return EXIT_FAILURE;
  }



  /* Open LIME reader */
  reader = limeCreateReader(fp);
  if( reader == (LimeReader *)NULL ) { 
    fprintf(stderr, "Unable to open LimeReader\n");
    return EXIT_FAILURE;
  }


  /* Loop over records */
  msg=0;
  rec=0; 
  while( (status = limeReaderNextRecord(reader)) != LIME_EOF ){
    
    if( status != LIME_SUCCESS ) { 
      fprintf(stderr, "limeReaderNextRecord returned status = %d\n", 
	      status);
      return EXIT_FAILURE;
    }

    nbytes    = limeReaderBytes(reader);
    lime_type = limeReaderType(reader);
    bytes_pad = limeReaderPadBytes(reader);
    MB_flag   = limeReaderMBFlag(reader);
    ME_flag   = limeReaderMEFlag(reader);

    /* Update message and record numbers */
    if(MB_flag == 1){
      msg++;
      rec = 0;
    }

    rec++;

#if 1
    printf("\n\n");
    printf("Type:           %s\n",   lime_type);
    printf("Data Length:    %ld\n",  nbytes);
    printf("Padding Length: %zd\n",   bytes_pad);
    printf("MB flag:        %d\n",   MB_flag);
    printf("ME flag:        %d\n",   ME_flag);
#endif


    /* Skip to next record until target record is reached */
    /*if (msg != msg_seek || rec != rec_seek) continue;*/
    if (strcmp(lime_type,"scidac-binary-data") != 0) continue;
    
    /*check that the data record has the expected number of byutes*/
    if(nbytes != buff_size)
    {
      fprintf(stderr,"Error, expecting %ld bytes but data has %ld bytes\n",buff_size,nbytes);
      return EXIT_FAILURE;
    }


    /* Buffered copy */
    
    bytes_left = nbytes;
    int bcopied=0;
    while(bytes_left > (n_uint64_t)0){
      bytes_to_copy = mino((n_uint64_t)MAXBUF,bytes_left);
      read_bytes = bytes_to_copy;
      status = limeReaderReadData((void *)buf, &read_bytes, reader);
    
      if( status < 0 && status != LIME_EOR ) { 
	fprintf(stderr, "LIME read error occurred: status= %d\n", status);
	exit(EXIT_FAILURE);
      }
      if (read_bytes != bytes_to_copy) {
	fprintf(stderr, "Read error %lld bytes wanted,%lld read\n", 
		(unsigned long long)nbytes, (unsigned long long)read_bytes);
	return EXIT_FAILURE;
      }
    
      /* copy to the output buffer */
      for(i=0; i<read_bytes; i++)
        buff_out[bcopied+i]=buf[i];

      bcopied += read_bytes;
      bytes_left -= bytes_to_copy;
    }

    /* Quit at this record */
    break;
  }

  limeDestroyReader(reader);
  DCAP(fclose)(fp);

  return EXIT_SUCCESS;
}