Пример #1
0
/* fatfsLs():
 * The incoming string is assumed to be some directory name.
 * If NULL, then it is assumed to be the CF's top-most level.
 */ 
static int
fatfsLs(char *dirname)
{
	int	ftot;
	DIRENT de;
	DIRINFO di;
	char *dir;

	if (dirname)
		dir = dirname;
	else
		dir = "";

	di.scratch = sector;
	if (DFS_OpenDir(&vi, (uint8_t *)dir, &di)) {
		printf("Can't open dir: <%s>\n",dirname);
		return(CMD_FAILURE);
	}

	ftot = 0;
	while (!DFS_GetNext(&vi, &di, &de)) {
		char tmp[32]; 

		if (de.name[0] && ((de.attr & ATTR_LONG_NAME) != ATTR_LONG_NAME)) {
			if ((de.attr & ATTR_VOLUME_ID) > 0) {
				de.name[8] = 0;
				printf("Volume:     %s\n",de.name);
				continue;
            }
			ftot++;

			printf("%02d/%02d/%4d  %02d:%02d   ",
				CREATE_MON(de), CREATE_DAY(de), CREATE_YEAR(de),
				CREATE_HR(de), CREATE_MIN(de));

			if ((de.attr & ATTR_DIRECTORY) > 0) {
				// truncate the extension
				de.name[8] = 0;

				printf("<DIR>            %-8s",de.name);
			}
			else {
				DFS_DirToCanonical((uint8_t *)tmp,de.name);
				printf("       %8d  %-12s",FILESIZE(de), tmp);
			}

			printf("  %c%c%c%c%c\n",
				(( de.attr & ATTR_VOLUME_ID) ? 'V' : ' '),
				(( de.attr & ATTR_READ_ONLY) ? 'R' : ' '),
				(( de.attr & ATTR_ARCHIVE  ) ? 'A' : ' '),
				(( de.attr & ATTR_SYSTEM   ) ? 'S' : ' '),
				(( de.attr & ATTR_HIDDEN   ) ? 'H' : ' '));
		}
	}
	shell_sprintf(FATFS_FTOT_STR,"%d",ftot);
	return(0);
}
Пример #2
0
static void cm_open(struct cache *c,struct jpf_value *conf,void *priv) {
  struct cache_mmap *cm = (struct cache_mmap *)priv;
  struct jpf_value *path;
  int r;
 
  path = jpfv_lookup(conf,"filename");
  if(!path) { die("No path to cachefile specified"); }
  cm->fd = open(path->v.string,O_CREAT|O_RDWR|O_TRUNC,0666);
  if(cm->fd<0) { die("Cannot create/open cache file"); }
  if(ftruncate(cm->fd,FILESIZE(c))<0) { die("Cannot extend cache file"); }
  log_info(("allocating cache file. Will be slow on old filesystem types"));
  if((r=posix_fallocate(cm->fd,0,FILESIZE(c)))) {
    errno = r;
    die("Cannot fallocate space for cache file");
  }
  log_info(("cache file allocated"));
  cm->data = mmap(0,FILESIZE(c),PROT_READ|PROT_WRITE,MAP_SHARED,cm->fd,0);
  log_debug(("mmap %s at %p-%p",
             path->v.string,cm->data,cm->data+FILESIZE(c)));
  if(cm->data==((void *)-1)) { die("Cannot mmap cachemmap file"); }
}
Пример #3
0
void DOSMOUNT() // DOSMOUNT
{
  unsigned short int a;
  a = Pop(); // >R
  INIT(); // INIT
  while(1)
  {
    Push(a); // I
    FCBPFAS(); // FCBPFAS
    Push(Read16(Pop())); //  @
    Push(pp__i_FCB); // 'FCB
    Store(); // !
    SMARTOPEN(); // SMARTOPEN
    Push(Read16(regsp)); // DUP
    if (Pop() == 0) break;

    Pop(); // DROP
    FLUSH(); // FLUSH
    INIT(); // INIT
    Push(a); // I
    FCBPFAS(); // FCBPFAS
    Push(Read16(Pop())); //  @
    Push(pp__i_FCB); // 'FCB
    Store(); // !
    Push(pp_ASKMOUNT); // ASKMOUNT
    GetEXECUTE(); // @EXECUTE
  }
  Push(0x0400);
  RECSIZE(); // RECSIZE
  Store(); // !
  FILESIZE(); // FILESIZE
  _2_at_(); // 2@
  SWAP(); // SWAP
  Push(0x0400);
  M_slash_(); // M/
  SWAP(); // SWAP
  Pop(); // DROP
  DRV(); // DRV
  Push(Read16(Pop())&0xFF); //  C@
  Push(a); // R>
  DRIVENUMBERS(); // DRIVENUMBERS
  C_ex__2(); // C!_2
}
Пример #4
0
int npost_parse( int argc, char **argv, npost_param_t *param )
{

    npost_param_default( param );

    // First check for help
    if ( argc == 1 )
    {
        help( param );
        exit( 0 );
    }
    for( optind = 0;; )
    {
        int c = getopt_long( argc, argv, short_options, long_options, NULL );

        if( c == -1 )
            break;
        else if( c == 'h' )
        {
            help( param );
            exit(0);
        }
    }

    // Check for other options
    for( optind = 0;; )
    {
        int c = getopt_long( argc, argv, short_options, long_options, NULL );

        if( c == -1 )
            break;

        switch( c )
        {
            case 'v':
                npost_print_version();
                exit(0);
            case 's':
                param->server = strdup( optarg );
                break;
            case 'o':
                param->port = atoi( optarg );
                break;
            case 'u':
                param->username = strdup( optarg );
                break;
            case 'p':
                param->password = strdup( optarg );
                break;
            case 't':
                param->threads = atoi( optarg );
                break;
            case 'f':
                free( param->name );
                param->name = strdup( optarg );
                break;
            case 'e':
                free( param->email );
                param->email = strdup( optarg );
                break;
            case 'n':
                free( param->newsgroups );
                param->newsgroups = strdup( optarg );
                break;
            case 'c':
                param->comment = strdup( optarg );
                break;
            case 'l':
                param->lines = atoi( optarg );
                break;
            case 'x':
                param->split = atol( optarg );
                switch( optarg[strlen(optarg) - 1] )
                {
                    case 'K':
                        param->split *= 1000;
                        break;
                    case 'k':
                        param->split <<= 10;
                        break;
                    case 'M':
                        param->split *= 1000000;
                        break;
                    case 'm':
                        param->split <<= 20;
                        break;
                    case 'G':
                        param->split *= 1000000000;
                        break;
                    case 'g':
                        param->split <<= 30;
                        break;
                    default:
                        break;
                }
                break;
            default:
                printf( "Error: getopt returned character code 0%o = %c\n", c, c );
                return -1;
        }
    }

    if ( optind < argc )
        param->n_input_files = argc - optind;


    // Parameter checking
    int b_error = 0;
    if( param->n_input_files < 1 )
    {
        printf( "You have to give me a file to post.\n" );
        b_error |= 1;
    }

    if( param->comment == NULL && param->n_input_files > 1 )
    {
        printf( "You have to specify the comment when posting more than one file.\n" );
        b_error |= 1;
    }

    if( param->server == NULL )
    {
        printf( "--server is required.\n" );
        b_error |= 1;
    }

    if( param->username == NULL )
    {
        printf( "--user is required.\n" );
        b_error |= 1;
    }

    if( param->password == NULL )
    {
        printf( "--password is required.\n" );
        b_error |= 1;
    }

    if( param->split != 0 && param->split < (1 << 10) )
    {
        printf( "--split: Can't split smaller than 1kB.\n" );
        b_error |= 1;
    }

    if( b_error )
        return -1;

    if ( param->threads < 1 )
        param->threads = 1;

    // First open all files, check if they exist, and get their filesize
    param->input_files = malloc( param->n_input_files * sizeof(diskfile_t) );

    for ( int i = 0; i < param->n_input_files; i++ )
    {
        diskfile_t *df = &param->input_files[i];

        df->filename_in = strdup( argv[optind++] );
        df->filename_out = strdup( df->filename_in );
        df->offset   = 0;
        df->filesize = FILESIZE( df->filename_in );
        if( df->filesize == 0 )
        {
            printf( "Error opening file: %s\n", df->filename_in );
            return -1;
        }
        df->filesize = df->filesize - df->offset;
    }

    // Set the comment to be the filename if the comment was unset
    if( param->comment == NULL && param->n_input_files == 1 )
        param->comment = strdup( param->input_files[0].filename_in );

    // Now count how many virtual diskfiles we need if we split
    if( param->split )
    {
        param->n_split_files = 0;

        for( int i = 0; i < param->n_input_files; i++ )
        {
            diskfile_t *df = &param->input_files[i];
            param->n_split_files += (df->filesize + param->split - 1) / param->split;
        }
    }
    else
        param->n_split_files = param->n_input_files;

    // Generate the list of virtual files
    param->split_files = malloc( param->n_split_files * sizeof(diskfile_t) );

    for( int i = 0, t = 0; i < param->n_input_files; i++ )
    {
        diskfile_t *df_in  = &param->input_files[i];

        // Else we start splitting~:
        char split_fnformat[100];
        int split_parts    = param->split ? (df_in->filesize + param->split - 1) / param->split : 1;
        int split_digits   = snprintf( 0, 0, "%d", split_parts );
        int split_fnlength = strlen( df_in->filename_out ) + split_digits + 2; // one dot, and one terminating zero

        sprintf( split_fnformat, "%%s.%%0%dd", split_digits );

        for( int j = 0; j < split_parts; j++ )
        {
            diskfile_t *df_out = &param->split_files[t++];

            // If we don't have to split, just copy stuff
            if( !param->split || split_parts == 1 )
            {
                memcpy( df_out, df_in, sizeof(diskfile_t) );
                df_out->filename_in = strdup( df_in->filename_in );
                df_out->filename_out = strdup( df_in->filename_out );
                continue;
            }

            df_out->filename_in = strdup( df_in->filename_in );
            df_out->filename_out = malloc( split_fnlength );
            snprintf( df_out->filename_out, split_fnlength, split_fnformat, df_in->filename_out, j+1 );

            df_out->offset = j * param->split;

            df_out->filesize = MIN(df_in->filesize - df_out->offset, param->split);
        }
    }

    return 0;
}
Пример #5
0
static int
fatfsQry(char *fatfspath, int verbose)
{
	DIRENT de;
	DIRINFO di;
	char *lastslash, *fname, *dir, pathcopy[80], matchname[80];
	int flen, flen1, fsize, pathlen, match, ftot;

	if (!fatfspath)
		return(-1);

	/* Prior to each 'ls', clear the content of the name and
	 * size shell variables...
	 */
	setenv(FATFS_FNAME_STR,0);
	setenv(FATFS_FSIZE_STR,0);
	setenv(FATFS_FTOT_STR,0);

	pathlen = strlen(fatfspath);
	if (pathlen > sizeof(pathcopy)) {
		printf("path too big\n");
		return(-1);
	}
	strcpy(pathcopy, fatfspath);
	lastslash = strrchr(pathcopy,DIR_SEPARATOR);

	if (lastslash == 0) {
		dir = "";
		fname = pathcopy;
	}
	else {
		*lastslash = 0;
		dir = pathcopy;
		fname = lastslash+1;
	}

	flen = strlen(fname);
	if (verbose > 1)
		printf("Qry opening dir <%s>, fname <%s>...\n",dir,fname);

	di.scratch = sector;
	if (DFS_OpenDir(&vi, (uint8_t *)dir, &di)) {
		printf("error opening subdirectory\n");
		return(CMD_FAILURE);
	}

	match = fsize = ftot = flen1 = 0;
	while (!DFS_GetNext(&vi, &di, &de)) {
		int i;
		char dosname[16];

		memset(dosname,0,sizeof(dosname));
		if (de.name[0] && ((de.attr & ATTR_LONG_NAME) != ATTR_LONG_NAME)) {
			if ((de.attr & ATTR_VOLUME_ID) || (de.attr & ATTR_DIRECTORY)) {
				for(i=0;i<8;i++) {
					if (de.name[i] != ' ') {
						dosname[i] = de.name[i];
					}
					else {
						dosname[i] = 0;
						break;
					}
				}
				dosname[8] = 0;
			}
			else
				DFS_DirToCanonical((uint8_t *)dosname,de.name);
	
			flen1 = strlen(dosname);

			if ((fname[0] == '*') && (fname[flen-1] == '*')) {
				fname[flen-1] = 0;
				if (strstr(dosname,fname+1))
					match = 1;
				fname[flen-1] = '*';
			}
			else if (fname[0] == '*') {
				if (!strcmp(dosname+(flen1-flen+1),fname+1))
					match = 1;
			}
			else if (fname[flen-1] == '*') {
				fname[flen-1] = 0;
				if (!strncmp(dosname,fname,flen-1))
					match = 1;
				fname[flen-1] = '*';
			}
			else if (!strcmp(dosname,fname)) {
				match = 1;
			}
			if (match) {
				strcpy(matchname,dosname);
				fsize = FILESIZE(de);
				ftot++;
				match = 0;
				if (verbose)
					printf("  %s (%d)\n",dosname,fsize);
			}
		}
	}
	shell_sprintf(FATFS_FTOT_STR,"%d",ftot);
	if (ftot) {
		shell_sprintf(FATFS_FSIZE_STR,"%d",fsize);
		setenv(FATFS_FNAME_STR,matchname);
	}
	return(0);
}