示例#1
0
int do_ls_cif(CIFBLK *cif)
{
    int rc;
    U32 cyl;
    U8  head, rec;
    U16 rlen;
    U8  klen;
    unsigned char *vol1data;
    FORMAT4_DSCB *f4dscb;
    char volser[7];

    rc = read_block(cif, 0, 0, 3, 0, 0, &vol1data, &rlen);
    if (rc < 0)
        return -1;
    if (rc > 0) 
    {
        fprintf( stderr, MSG( HHC02471, "E", "VOL1" ) );
        return -1;
    }

    make_asciiz(volser, sizeof(volser), vol1data+4, 6);
    cyl = (vol1data[11] << 8) | vol1data[12];
    head = (vol1data[13] << 8) | vol1data[14];
    rec = vol1data[15];

    rc = read_block(cif, cyl, head, rec, (void *)&f4dscb, &klen, 0, 0);
    if (rc < 0)
        return -1;
    if (rc > 0) 
    {
        fprintf( stderr, MSG( HHC02471, "E", "Format 4 DSCB" ) );
        return -1;
    }
    return list_contents(cif, volser, &f4dscb->ds4vtoce);
}
示例#2
0
int do_ls_cif(CIFBLK *cif)
{
    int rc, cyl, head, rec, len;
    unsigned char *vol1data;
    FORMAT4_DSCB *f4dscb;
    char volser[7];

    rc = read_block(cif, 0, 0, 3, 0, 0, &vol1data, &len);
    if (rc < 0)
        return -1;
    if (rc > 0) {
        fprintf(stderr, "VOL1 record not found\n");
        return -1;
    }

    make_asciiz(volser, sizeof(volser), vol1data+4, 6);
    cyl = (vol1data[11] << 8) | vol1data[12];
    head = (vol1data[13] << 8) | vol1data[14];
    rec = vol1data[15];

    rc = read_block(cif, cyl, head, rec, (void *)&f4dscb, &len, 0, 0);
    if (rc < 0)
        return -1;
    if (rc > 0) {
        fprintf(stderr, "F4DSCB record not found\n");
        return -1;
    }
    return list_contents(cif, volser, &f4dscb->ds4vtoce);
}
示例#3
0
/**
 * Main daemon routine
 */
int main( int argc, char **argv )
{
    int            c, option_index = 0;
    char          *bin = basename( argv[0] );

    char           config_file[MAX_OPT_LEN] = "";
    int            force_log_level = FALSE;
    int            log_level = 0;
    int            rc;
    int            chgd = 0;
    char           err_msg[4096];
    int            neg = 0;
    char           badcfg[RBH_PATH_MAX];

    /* parse command line options */
    while ((c = getopt_long_only(argc, argv, SHORT_OPT_STRING, option_tab,
                            &option_index )) != -1)
    {
        switch ( c )
        {
        case '!':
            neg = 1;
            break;
        case 'u':
            toggle_option(match_user, "user");
            prog_options.user = optarg;
            prog_options.userneg = neg;
            neg = 0;
            break;
        case 'g':
            toggle_option(match_group, "group");
            prog_options.group = optarg;
            prog_options.groupneg = neg;
            neg = 0;
            break;
        case 'U': /* match numerical (non resolved) users */
            toggle_option(match_user, "user");
            prog_options.user = "******";
            prog_options.userneg = neg;
            neg = 0;
            break;
        case 'G': /* match numerical (non resolved) groups */
            toggle_option(match_group, "group");
            prog_options.group = "[0-9]*";
            prog_options.groupneg = neg;
            neg = 0;
            break;
        case 'n':
            toggle_option(match_name, "name");
            prog_options.name = optarg;
            prog_options.nameneg = neg;
            neg = 0;
            break;
#ifdef _LUSTRE
        case 'o':
            toggle_option(match_ost, "ost");
            prog_options.ost_idx = str2int(optarg);
            if (prog_options.ost_idx == (unsigned int)-1)
            {
                fprintf(stderr, "invalid ost index '%s': unsigned integer expected\n", optarg);
                exit(1);
            }
            if (neg) {
                fprintf(stderr, "! () is not supported for ost criteria\n");
                exit(1);
            }
            break;
        case 'P':
            toggle_option(match_pool, "pool");
            prog_options.pool = optarg;
            break;
        case 'O':
            prog_options.lsost = 1;
            prog_options.print = 0;
            disp_mask |= LSOST_DISPLAY_MASK;
            if (neg) {
                fprintf(stderr, "! (-not) unexpected before -lsost option\n");
                exit(1);
            }
            break;
#endif
        case 't':
            toggle_option(match_type, "type");
            prog_options.type = opt2type(optarg);
            if (prog_options.type == NULL)
            {
                fprintf(stderr, "invalid type '%s': expected types: "TYPE_HELP".\n", optarg);
                exit(1);
            }
            if (neg) {
                fprintf(stderr, "! (-not) is not supported for type criteria\n");
                exit(1);
            }
            break;
        case 's':
            toggle_option(match_size, "size");
            if (set_size_filter(optarg))
                exit(1);
            if (neg) {
                fprintf(stderr, "! (-not) is not supported for size criteria\n");
                exit(1);
            }
            break;

        case 'A':
            toggle_option(match_atime, "atime/amin");
            if (set_time_filter(optarg, 0, TRUE, atime))
                exit(1);
            if (neg) {
                fprintf(stderr, "! (-not) is not supported for time criteria\n");
                exit(1);
            }
            break;

        case 'a':
            toggle_option(match_atime, "atime/amin");
            if (set_time_filter(optarg, 60, TRUE, atime))
                exit(1);
            if (neg) {
                fprintf(stderr, "! (-not) is not supported for time criteria\n");
                exit(1);
            }
            break;

        case 'C':
            toggle_option(match_crtime, "crtime");
            if (set_time_filter(optarg, 0, TRUE, rh_crtime))
                exit(1);
            if (neg) {
                fprintf(stderr, "! (-not) is not supported for time criteria\n");
                exit(1);
            }
            break;

        case 'M':
            toggle_option(match_mtime, "mtime/mmin/msec");
            if (set_time_filter(optarg, 0, TRUE, mtime))
                exit(1);
            if (neg) {
                fprintf(stderr, "! (-not) is not supported for time criteria\n");
                exit(1);
            }
            break;

        case 'm':
            toggle_option(match_mtime, "mtime/mmin/msec");
            if (set_time_filter(optarg, 60, FALSE, mtime)) /* don't allow suffix (multiplier is 1min) */
                exit(1);
            if (neg) {
                fprintf(stderr, "! (-not) is not supported for time criteria\n");
                exit(1);
            }
            break;

        case 'z':
            toggle_option(match_mtime, "mtime/mmin/msec");
            if (set_time_filter(optarg, 1, FALSE, mtime)) /* don't allow suffix (multiplier is 1sec) */
                exit(1);
            if (neg) {
                fprintf(stderr, "! (-not) is not supported for time criteria\n");
                exit(1);
            }
            break;


#ifdef ATTR_INDEX_status
        case 'S':
            toggle_option(match_status, "status");
            prog_options.status = status2dbval(optarg);
            if ( prog_options.status == (file_status_t)-1 )
            {
                fprintf(stderr, "Unknown status '%s'. Allowed status: %s.\n", optarg,
                        allowed_status());
                exit(1);
            }
            prog_options.statusneg = neg;
            neg = 0;
            break;
#endif
        case 'l':
            prog_options.ls = 1;
            prog_options.print = 0;
            disp_mask |= LS_DISPLAY_MASK;
            if (neg) {
                fprintf(stderr, "! (-not) unexpected before -ls option\n");
                exit(1);
            }
            break;
        case 'p':
            prog_options.print = 1;
            disp_mask |= LS_DISPLAY_MASK;
            if (neg) {
                fprintf(stderr, "! (-not) unexpected before -ls option\n");
                exit(1);
            }
            break;

        case 'E':
            toggle_option(exec, "exec");
            prog_options.exec_cmd = optarg;
            prog_options.print = 0;
            break;
        case 'f':
            rh_strncpy(config_file, optarg, MAX_OPT_LEN);
            if (neg) {
                fprintf(stderr, "! (-not) unexpected before -f option\n");
                exit(1);
            }
            break;
        case 'd':
            force_log_level = TRUE;
            log_level = str2debuglevel( optarg );
            if ( log_level == -1 )
            {
                fprintf(stderr,
                        "Unsupported log level '%s'. CRIT, MAJOR, EVENT, VERB, DEBUG or FULL expected.\n",
                        optarg);
                exit(1);
            }
            if (neg) {
                fprintf(stderr, "! (-not) unexpected before -d option\n");
                exit(1);
            }
            break;
        case 'b':
            prog_options.bulk = force_nobulk;
            break;
        case 'h':
            display_help( bin );
            exit( 0 );
            break;
        case 'V':
            display_version( bin );
            exit( 0 );
            break;
        case ':':
        case '?':
        default:
            display_help( bin );
            exit( 1 );
            break;
        }
    }

    /* get default config file, if not specified */
    if (SearchConfig(config_file, config_file, &chgd, badcfg, MAX_OPT_LEN) != 0)
    {
        fprintf(stderr, "No config file (or too many) found matching %s\n", badcfg);
        exit(2);
    }
    else if (chgd)
    {
        fprintf(stderr, "Using config file '%s'.\n", config_file );
    }

    /* only read ListMgr config */

    if ( ReadRobinhoodConfig( 0, config_file, err_msg, &config, FALSE ) )
    {
        fprintf( stderr, "Error reading configuration file '%s': %s\n", config_file, err_msg );
        exit( 1 );
    }
    process_config_file = config_file;

    /* set global configuration */
    global_config = config.global_config;

    /* set policies info */
    policies = config.policies;

    if ( force_log_level )
        config.log_config.debug_level = log_level;
    else
        config.log_config.debug_level = LVL_MAJOR; /* no event message */

    /* Set logging to stderr */
    strcpy( config.log_config.log_file, "stderr" );
    strcpy( config.log_config.report_file, "stderr" );
    strcpy( config.log_config.alert_file, "stderr" );

    /* Initialize logging */
    rc = InitializeLogs( bin, &config.log_config );
    if ( rc )
    {
        fprintf( stderr, "Error opening log files: rc=%d, errno=%d: %s\n",
                 rc, errno, strerror( errno ) );
        exit( rc );
    }

    /* Initialize filesystem access */
    rc = InitFS();
    if (rc)
        exit(rc);

    /* Initialize list manager */
    rc = ListMgr_Init( &config.lmgr_config, TRUE );
    if ( rc )
    {
        DisplayLog( LVL_CRIT, FIND_TAG, "Error %d initializing list manager", rc );
        exit( rc );
    }
    else
        DisplayLog( LVL_DEBUG, FIND_TAG, "ListManager successfully initialized" );

    if (CheckLastFS(  ) != 0)
        exit(1);

    /* Create database access */
    rc = ListMgr_InitAccess(&lmgr);
    if (rc)
    {
        DisplayLog( LVL_CRIT, FIND_TAG, "Error %d: cannot connect to database", rc );
        exit(rc);
    }

    if (argc == optind)
    {
        /* no argument: default is root
         * => switch to bulk mode (unless nobulk is specified)
         */
        if (prog_options.bulk != force_nobulk)
        {
            DisplayLog(LVL_DEBUG, FIND_TAG, "Optimization: switching to bulk DB request mode");
            mkfilters(FALSE); /* keep dirs */
            return list_bulk();
        }
        else
        {
            char *id = config.global_config.fs_path;
            mkfilters(TRUE); /* exclude dirs */
            /* no path specified, list all entries */
            rc = list_contents(&id, 1);
        }
    }
    else
    {
        mkfilters(TRUE); /* exclude dirs */
        rc = list_contents(argv+optind, argc-optind);
    }

    ListMgr_CloseAccess( &lmgr );

    return rc;
}
示例#4
0
int main(int numarg,char** argo){
  int opzione=0;
  int show_help=0;
  int show_version=0;
  int list=0;
  int current_argument;
  int ingresso;
  int uscita;
  char* output_file_name=NULL;
  char* override_entry_name=NULL;
  char* temporary_file_name;
  char* end;
  int append_WAV=0;
  int WAV_descriptor;
  filetype type;
  int count,used,total,used_entries;
  int start_address,end_address,offset;
  char entry_name[17];
  struct entry_element* current_file;
  int first_done=0;
  int dsp_output=0;
  int sample_speed;

  /* Get options */

  while ((opzione=getopt(numarg,argo,"hiloe:v"))!=EOF){
    switch(opzione){
    case 'h':
      show_help=1;
      break;
    case 'i':
      inverted_waveform=1;
      break;
    case 'l':
      list=1;
      break;
    case 'o':
      output_file_name=(char*)malloc(strlen(optarg)+4);
      strcpy(output_file_name,optarg);
      break;
    case 'e':
      override_entry=1;
      override_entry_name=(char*)malloc(strlen(optarg)+4);
      strcpy(override_entry_name,optarg);
      break;
   case 'v':
      show_version=1;
      break;
   default:
      help();
      return 1;
    };
  }
  if (show_help==1){
    help();
    return 0;
  };
  if (show_version==1){
    version();
    return 0;
  };
  if (output_file_name==NULL){ /* -o is not used */
    dsp_output=1;
    output_file_name=(char*)malloc(strlen(SOUNDDEV)+1);
    strcpy(output_file_name,SOUNDDEV);
  };

  current_argument=optind;
  if (current_argument==numarg){
    printf("No input files specified!\n");
    help();
    return 1;
  }
  if (!list){
    if (dsp_output){
      if ((uscita=open(SOUNDDEV,O_WRONLY))==-1){
	printf("Could not open file %s\n",SOUNDDEV);
	return 3;
      }
      sample_speed = 44100;
        if (ioctl(uscita, SNDCTL_DSP_SPEED, &sample_speed) != 0 || sample_speed != 44100){
  	printf("Could not set playback speed to 44100 Hz in file %s\n",SOUNDDEV);
  	return 3;
        } 
    }
    else{
      if((uscita=open(temporary_file_name=tempnam("/tmp","prg2w"),O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))==-1){
	printf("Could not create temporary file in /tmp directory\n");
	return 5;
      };
      if (strlen(output_file_name)<5) append_WAV=1;
      else{
	end=output_file_name+strlen(output_file_name)-4;
	if((strcmp(end,".WAV"))&&(strcmp(end,".wav"))) append_WAV=1;
      };
      if (append_WAV) strcat(output_file_name,".wav");
      if((WAV_descriptor=open(output_file_name,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))==-1){
	printf("Could not create file %s\n",output_file_name);
	unlink(temporary_file_name);
	return 5;
      };
    }
  }
  while (current_argument<numarg){
    if ((ingresso=open(argo[current_argument],O_RDONLY))==-1){
      printf("Could not open file %s\n",argo[current_argument]);
      goto fine;
    };
    switch(type=detect_type(ingresso)){
    case t64:
      printf("%s: T64 file\n",argo[current_argument]);
      break;
    case p00:
      printf("%s: P00 file\n",argo[current_argument]);
      break;
    case prg:
      printf("%s: program file\n",argo[current_argument]);
      break;
    default:
      printf("%s is not a recognized file type\n",argo[current_argument]);
      goto fine;
    };
    if (list){
      list_contents(ingresso);
      goto fine;
    };
    switch(type){
    case t64:
      used_entries=get_used_entries(ingresso);
      total=get_total_entries(ingresso);
      empty_list(files_to_convert);
      files_to_convert=0;
      if (used_entries==1){
	for(count=1;count<=total;count++)
	  if(used=get_entry(count,ingresso,&start_address,&end_address,&offset,
			    entry_name)) set_range(count,count,ingresso);
      }

      /* If there is only one used entry, */
      /* Only the used one will be */
      /* converted */
      /* otherwise ask the user */

      else get_range_from_keyboard(ingresso); 
      current_file=files_to_convert;
      while(current_file!=0){
	count=current_file->entry;
	get_entry(count,ingresso,&start_address,&end_address,&offset,
		  entry_name);
	if (!first_done) first_done=1;
	else add_silence(uscita);
	printf("Converting %d (%s)\n",count,entry_name);
	convert(ingresso,uscita,start_address,end_address,offset,entry_name);
	current_file=current_file->next;
      }
      break;
    case p00:
    case prg:
      if (!first_done) first_done=1;
      else add_silence(uscita);
      printf("Converting %s\n",argo[current_argument]);
      get_entry(count,ingresso,&start_address,&end_address,&offset,
		entry_name);
      if(override_entry) {
        int ix;
        for(ix = 0; ix < strlen(override_entry_name); ix++) {
          entry_name[ix] = toupper(override_entry_name[ix]);
        }
      }
      printf("Entry Name: %s (%d)\n",entry_name,strlen(entry_name));
      convert(ingresso,uscita,start_address,end_address,offset,entry_name);
    };

  fine:   
    ++current_argument;
  };
  close(uscita);
  if((!list)&&(!dsp_output)){
    if(first_done){
      printf("Creating WAV file...\n");
      create_WAV(temporary_file_name,WAV_descriptor);
    }
    else unlink(output_file_name);
  }
}