Exemplo n.º 1
0
// store scene to sdcard at name
void files_store_scene_name(const char* name, u8 ext) {
  //u32 i;
  void* fp;
  char namebuf[64] = SCENES_PATH;
  u8* pScene;

  app_pause();

  strcat(namebuf, name);

  if(ext) {
    // weird..
    strip_space(namebuf, 32);
    strcat(namebuf, ".scn");
  }

  print_dbg("\r\n opening scene file for writing: ");
  print_dbg(namebuf);

  // fill the scene RAM buffer from current state of system
  scene_write_buf(); 
  // open FP for writing
  fp = fl_fopen(namebuf, "wb");
  pScene = (u8*)sceneData;
  fl_fwrite((const void*)pScene, sizeof(sceneData_t), 1, fp);
  fl_fclose(fp);
  // rescan
  list_scan(&sceneList, SCENES_PATH);
  delay_ms(10);

  app_resume();
}
int fl_remove( const char * filename )
{
	FL_FILE* file;
	int res = 0;

	FL_LOCK(&_fs);

	// Use read_file as this will check if the file is already open!
	file = fl_fopen((char*)filename, "r");
	if (file)
	{
		// Delete allocated space
		if (fatfs_free_cluster_chain(&_fs, file->startcluster))
		{
			// Remove directory entries
			if (fatfs_mark_file_deleted(&_fs, file->parentcluster, (char*)file->shortfilename))
			{
				// Close the file handle (this should not write anything to the file
				// as we have not changed the file since opening it!)
				fl_fclose(file);

				res = 1;
			}
		}
	}

	FL_UNLOCK(&_fs);

	return res;
}
Exemplo n.º 3
0
// search for specified scene file and load it
// return 1 on success, 0 on failure
u8 files_load_scene_name(const char* name) {
  void* fp;
  u32 size = 0;
  u8 ret = 0;

  app_pause();

  fp = list_open_file_name(&sceneList, name, "r", &size);

  if( fp != NULL) {	  
    fake_fread((volatile u8*)sceneData, sizeof(sceneData_t), fp);
    fl_fclose(fp);
    scene_read_buf();

    // try and load dsp module indicated by scene descriptor
    //// DUDE! NO!!! scene does this. when did this happen!
    //// probably snuck in in some merge.
    //    ret = files_load_dsp_name(sceneData->desc.moduleName);
  } else {
    print_dbg("\r\n error: fp was null in files_load_scene_name \r\n");
    ret = 0;
  } 
  app_resume();
  return ret;
}
Exemplo n.º 4
0
// search for named .dsc file and load into network param desc memory
extern u8 files_load_desc(const char* name) {
  char path[64] = DSP_PATH;
  void * fp;
  int nparams = -1;
  // word buffer for 4-byte unpickling
  u8 nbuf[4];
  // buffer for binary blob of single descriptor
  u8 dbuf[PARAM_DESC_PICKLE_BYTES];
  // unpacked descriptor
  ParamDesc desc;
  int i;
  u8 ret = 0;

  app_pause();

  strcat(path, name);
  strip_ext(path);
  strcat(path, ".dsc");

  print_dbg("\r\n  opening .dsc file at path: ");
  print_dbg(path);

  fp = fl_fopen(path, "r");
  if(fp == NULL) {
    print_dbg("... error opening .dsc file.");
    print_dbg(path);
    ret = 1;
  } else {

    // get number of parameters
    fake_fread(nbuf, 4, fp);
    unpickle_32(nbuf, (u32*)&nparams); 

    /// loop over params
    if(nparams > 0) {
      net_clear_params();
      //    net->numParams = nparams;

      for(i=0; i<nparams; i++) {
	//  FIXME: a little gross,
	// to be interleaving network and file manipulation like this...
	///....
	// read into desc buffer
	fake_fread(dbuf, PARAM_DESC_PICKLE_BYTES, fp);
	// unpickle directly into network descriptor memory
	pdesc_unpickle( &desc, dbuf );
	// copy descriptor to network and increment count
	net_add_param(i, (const ParamDesc*)(&desc));     
 
      }
    } else {
      print_dbg("\r\n error: crazy parameter count from descriptor file.");
      ret = 1;
    }
  }
  fl_fclose(fp);
  app_resume();
  return ret;
}
Exemplo n.º 5
0
// search for specified dsp file and load it
u8 files_load_dsp_name(const char* name) {
  void* fp;
  u32 size = 0;
  u8 ret;
  //  ModuleVersion modVers;

  delay_ms(10);

  app_pause();

  fp = list_open_file_name(&dspList, name, "r", &size);

  if( fp != NULL) {	  
    print_dbg("\r\n found file, loading dsp: ");
    print_dbg(name);
    fake_fread(bfinLdrData, size, fp);

    fl_fclose(fp);
    bfinLdrSize = size;

    if(bfinLdrSize > 0) {
      print_dbg("\r\n loading bfin from buf");
      // reboot the dsp with new firmware in RAM
      bfin_load_buf();
      print_dbg("\r\n finished load");
      // write module name in global scene data

      /////////////////
      /// FIXME: filename and reported modulename should be decoupled
      /// bees should search for aleph-module-x.y.z.ldr
      /// but try aleph-module*.ldr on failure
      ////
      /// query name and version to the scene data
      //      scene_query_module();
      /// now set it to the actual filename because we are dumb
      scene_set_module_name(name);
      ///////////////////////////

      print_dbg("\r\n sceneData->moduleName : ");
      print_dbg(name);

      ret = 1;
    } else {
      print_dbg("\r\n bfin ldr size was <=0, aborting");
      ret = 0;
    }
  } else {
    print_dbg("\r\n error: fp was null in files_load_dsp_name \r\n");
    ret = 0;
  }
  app_resume();
  return ret;
}
Exemplo n.º 6
0
// store scene to sdcard at name
void files_store_scene_name(const char* name, u8 ext) {
  //u32 i;
  void* fp;
  char namebuf[64] = SCENES_PATH;
  u8* pScene;

  app_pause();

  strcat(namebuf, name);

  if(ext) {
    // weird..
    strip_space(namebuf, 32);
    strcat(namebuf, ".scn");
  }

  print_dbg("\r\n opening scene file for writing: ");
  print_dbg(namebuf);

  // fill the scene RAM buffer from current state of system
  scene_write_buf(); 
  print_dbg("\r\n filled scene binary buffer");

  // open FP for writing
  fp = fl_fopen(namebuf, "wb");
  print_dbg("\r\n opened file for binary write at 0x");
  print_dbg_hex((u32)fp);

  pScene = (u8*)sceneData;
  print_dbg("\r\n writing data from scene buffer at 0x");
  print_dbg_hex((u32)pScene);
  print_dbg(", size : ");
  print_dbg_hex(sizeof(sceneData_t));
  

  // dump the scene data to debug output...

  fl_fwrite((const void*)pScene, sizeof(sceneData_t), 1, fp);
  fl_fclose(fp);

  print_dbg("\r\n ... finished writing, closed file pointer");

  // rescan
  list_scan(&sceneList, SCENES_PATH);
  delay_ms(10);

  print_dbg("\r\n re-scanned scene file list and waited.");

  app_resume();
}
Exemplo n.º 7
0
Arquivo: ottos.c Projeto: ottos/ottos
void fs_test() {
  file_t* file;
  char buffer[512];
  //char text[] = { 't', 'e', 's', 't', '\n', '\r' };
  char text[] = "new file\n\r\0";

  devices_init();
  mmchs_init();
  fs_init();
  fl_listdirectory("/");

  file = (file_t*) fl_fopen("/test/thenewest.txt", "a");
  fl_fwrite(text, sizeof(text), sizeof(text), file);
  fl_fclose(file);

  fl_listdirectory("/test/");

  file = (file_t*) fl_fopen("/test/thenewest.txt", "r");
  fl_fread(buffer, 512, sizeof(text), file);
  kernel_print(buffer);
  fl_fclose(file);


}
Exemplo n.º 8
0
// search for specified scene file and load it
// return 1 on success, 0 on failure
u8 files_load_scene_name(const char* name) {
  void* fp;
  u32 size = 0;
  u8 ret = 0;

    //// ahhhhh, i see.. 
    /// this is overwriting the descriptor in sceneData as well as the serialized blob.
    /// woud be fine, except it f***s up the comparison later.
    /// for now, let's do this ugly-ass workaround.

  char oldModuleName[MODULE_NAME_LEN];
  /// store extant module name
  strncpy(oldModuleName, sceneData->desc.moduleName, MODULE_NAME_LEN);

  app_pause();

  fp = list_open_file_name(&sceneList, name, "r", &size);

  if( fp != NULL) {	  
    print_dbg("\r\n reading binary into sceneData serialized data buffer...");
    fake_fread((volatile u8*)sceneData, sizeof(sceneData_t), fp);
    print_dbg(" done.");
    
    /// copy old name back to descriptor field... dumb dumb dumb.
    strncpy(sceneData->desc.moduleName, oldModuleName, MODULE_NAME_LEN);
    
    fl_fclose(fp);
    scene_read_buf();

    // try and load dsp module indicated by scene descriptor
    //// DUDE! NO!!! scene does this. when did this happen!
    //// probably snuck in in some merge.
    //    ret = files_load_dsp_name(sceneData->desc.moduleName);
  } else {
    print_dbg("\r\n error: fp was null in files_load_scene_name \r\n");
    ret = 0;
  } 

  app_resume();
  return ret;
}
Exemplo n.º 9
0
// search for specified scaler file and load it to specified buffer
// return 1 on success, 0 on failure
u8 files_load_scaler_name(const char* name, s32* dst, u32 dstSize) {
  void* fp;
  u32 size = 0;
  u32 i;
  union { u32 u; s32 s; u8 b[4]; } swap;
  u8 ret = 0;
  //// test
  //s32* p = dst;
  ///

  app_pause();
  fp = list_open_file_name(&scalerList, name, "r", &size);
  if( fp != NULL) {	  

    print_dbg("\r\n scaler file pointer: 0x");
    print_dbg_hex((u32)fp);
#ifdef SCALER_LE
    swap.b[3] = fl_fgetc(fp);
    swap.b[2] = fl_fgetc(fp);
    swap.b[1] = fl_fgetc(fp);
    swap.b[0] = fl_fgetc(fp);
#else
    swap.b[0] = fl_fgetc(fp);
    swap.b[1] = fl_fgetc(fp);
    swap.b[2] = fl_fgetc(fp);
    swap.b[3] = fl_fgetc(fp);
#endif
    size = swap.u;

    print_dbg("\r\n read size (words): 0x");
    print_dbg_ulong(size);

    if(size > dstSize) {
      print_dbg("\r\n warning: requested scaler data is > target, truncating");
      for(i=0; i<dstSize; ++i) {

#ifdef SCALER_LE
    swap.b[3] = fl_fgetc(fp);
    swap.b[2] = fl_fgetc(fp);
    swap.b[1] = fl_fgetc(fp);
    swap.b[0] = fl_fgetc(fp);
#else
    swap.b[0] = fl_fgetc(fp);
    swap.b[1] = fl_fgetc(fp);
    swap.b[2] = fl_fgetc(fp);
    swap.b[3] = fl_fgetc(fp);
#endif
	*dst++ = swap.s;
      }
    } else if (size < dstSize) {
      print_dbg("\r\n warning: requested scaler data is < target, padding");
      for(i=0; i<size; ++i) {
#ifdef SCALER_LE
    swap.b[3] = fl_fgetc(fp);
    swap.b[2] = fl_fgetc(fp);
    swap.b[1] = fl_fgetc(fp);
    swap.b[0] = fl_fgetc(fp);
#else
    swap.b[0] = fl_fgetc(fp);
    swap.b[1] = fl_fgetc(fp);
    swap.b[2] = fl_fgetc(fp);
    swap.b[3] = fl_fgetc(fp);
#endif
	*dst++ = swap.s;
      }
      // remainder
      size = dstSize - size;
      for(i=0; i<size; ++i) {
	*dst++ = 0;
      }
    } else {
      for(i=0; i<size; ++i) {
#ifdef SCALER_LE
    swap.b[3] = fl_fgetc(fp);
    swap.b[2] = fl_fgetc(fp);
    swap.b[1] = fl_fgetc(fp);
    swap.b[0] = fl_fgetc(fp);
#else
    swap.b[0] = fl_fgetc(fp);
    swap.b[1] = fl_fgetc(fp);
    swap.b[2] = fl_fgetc(fp);
    swap.b[3] = fl_fgetc(fp);
#endif
	*dst++ = swap.s;
      }
    }
    fl_fclose(fp);
    ret = 1;
  } else {
    print_dbg("\r\n error: fp was null in files_load_scaler_name \r\n");
    ret = 0;
  } 

  print_dbg("\r\n finished loading scaler file (?)");

  ///// TEST: verify
  /* for(i=0; i<size; i++) { */
  /*   print_dbg(" 0x"); print_dbg_hex(p[i]); if((i%4)==0) { print_dbg("\r\n"); } */
  /* } */

  app_resume();
  return ret;
}
Exemplo n.º 10
0
int
cmd_dd_exec(CLI *cli, char *argv[]) {
	int verbose = 0, seek = 0, skip = 0, count = -1, block = 32;
	int size, rc, err = 0, argc = cli_num_args(argv);
	char infile[PATH_MAX], outfile[PATH_MAX];
	char *inname = NULL, *outname = NULL;
	FL_FILE *in = NULL, *out = NULL;
	int c, opt_ind;
	//char *buffer = NULL;

	for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
		c = getopt_long(argc, argv, "vi:o:b:c:s:k:", long_options, &opt_ind);

		switch (c) {
			case 'v': verbose =           1;  break;
			case 'i': inname  =      optarg;  break;
			case 'o': outname =      optarg;  break;
			case 'b': block   = atoi(optarg); break;
			case 's': skip    = atoi(optarg); break;
			case 'c': count   = atoi(optarg); break;
			case 'k': seek    = atoi(optarg); break;
		}
	}

	if (verbose) {
		printf("inname  = %s\n", inname);
		printf("outname = %s\n", outname);
		printf("block   = %i\n", block);
		printf("skip    = %i\n", skip);
		printf("seek    = %i\n", seek);
		printf("count   = %i\n", count);
	}

	//buff = (char *)mall c(block);
	char buffer[block];

	if (argc - optind != 1) {
		printf("dd - incorrect number of arguments. Try 'man dd'\n");
		err++; goto cleanup;
	}

	if (buffer == NULL) {
		printf("dd: out of memory.\n");
		err++; goto cleanup;
	}

	if (inname) {
		cli_clean_path(cli, inname, infile);

		if (fl_is_dir(infile)) {
			printf("dd: '%s' is a directory\n", infile);
			err++; goto cleanup;
		}

		in = (FL_FILE *)fl_fopen(infile, "r");

		if (!in) {
			printf("dd: could not open '%s' for reading\n", infile);
			err++; goto cleanup;
		}

		fl_fseek(in, skip * block, SEEK_SET);
	} else {
		printf("dd: no input file specified - dumping zeros\n");
		memset(buffer, 0, block);
	}

	if (outname) {
		cli_clean_path(cli, outname, outfile);

		if (fl_is_dir(outfile)) {
			printf("dd: '%s' is a directory\n", outfile);
			err++; goto cleanup;
		}

		out = (FL_FILE *)fl_fopen(outfile, "r+");

		if (out) {
			rc = fl_fseek(out, seek * block, SEEK_SET);
			printf("WARNING: seeking in outfile beyond EOF is unsupported!\n");
		} else {
			out = (FL_FILE *)fl_fopen(outfile, "w");
		}

		if (!out) {
			printf("dd: could not open '%s' for writeing\n", outfile);
			err++; goto cleanup;
		}
	} else {
		printf("dd: no output file specified - using stdout\n");
	}

	if (count >= 0) {
		size = count;
	} else {
		// TODO size of (infile - skip) / block
	}

	while (size > 0) {
		int blk = count - size;

		if (verbose) printf("dd:  reading block %i\n", blk);

		if (in) {
			rc = fl_fread(buffer, block, 1, in);

			if (rc < 0) {
				printf("dd: Error reading block %i\n", blk);
				err++; goto cleanup;
			} else {
				// short read -> set block size to number of bytes read
				block = rc;
			}
		}

		if (verbose) printf("dd: writeing block %i\n", blk);

		if (out) {
			rc = fl_fwrite(buffer, block, 1, out);

			if (rc < 0) {
				printf("dd: Error writeing block %i\n", blk);
				err++; goto cleanup;
			}
		} else {
			printf("%s\n", buffer);
		}

		size--;
	}

	// TODO print summary

cleanup:
	fl_fclose(in);
	fl_fclose(out);
	//free(buffer);

	return (err ? -1 : 0);
}
Exemplo n.º 11
0
//-----------------------------------------------------------------
// Main: Test bench file to create 5 files with psuedo random
// sequences in of varying lengths - read them back and complete
// then remove them.
//-----------------------------------------------------------------
void main()
{
	int i,j,x;

	FL_FILE * files[5];
	FL_FILE *readFile;
	char filenames[5][260];
	BYTE fileData[5][10000];
	BYTE readBuffer[10000];
	int fileLengths[5];
	BYTE *massiveData;
	time_t timeStart, timeEnd;

#define TESTFILES 6
	char *testfile[] = { "X:\\1", "X:\\1.bin", "X:\\12345678.321",
						 "X:\\mylongfilename", "X:\\mylongfilename.bin",
						 "X:\\the Quick Brown Fox jumped over the lazy dog.elf.binfile.jar"	};

	srand(time(NULL));

	// Initialise
	FAT32_InitDrive();

	fl_init();

	if (fl_attach_media(FAT_ReadSector, FAT_WriteSector) != FAT_INIT_OK)
		return;

	// List directory
	fl_listdirectory("C:\\");
//	return ;

test_start:

	// Generate 5 random files
	memset(filenames, 0x00, 260*5);
	for (j=0;j<5;j++)
	{
		// Length
		fileLengths[j] = GetRandom(9999);

		// Data
		for (x=0;x<fileLengths[j];x++)
			fileData[j][x] = (BYTE)GetRandom(255);

		// Names
		sprintf(filenames[j], "X:\\Auto Generated Filename Number %d", j+1);
	}

	// Create some files
	for (j=0;j<5;j++)
	{
		printf("Creating File: %s [%d bytes]\n", filenames[j], fileLengths[j]);

		// Create File
		files[j] = fl_fopen(filenames[j], "w");
		if (files[j]!=NULL)
		{
			if (fl_fwrite(fileData[j], 1, fileLengths[j], files[j])!=fileLengths[j])
			{
				printf("ERROR: File Write Block Failed File %s Length %d\n", filenames[j], fileLengths[j]);
				fl_assert(0);
			}
		}
		else
		{
			printf("ERROR: Error Creating File %s\n", filenames[j]);
			fl_assert(0);
		}

		fl_fclose(files[j]);

		// Clear buffer
		for (i=0;i<sizeof(readBuffer);i++)
			readBuffer[i] = 0;

		// Verify File
		readFile = fl_fopen(filenames[j], "r");
		if (readFile!=NULL)
		{
			int failed = FALSE;

			printf("File %s Read Check (fread whole file) [%d bytes]\n", filenames[j], fileLengths[j]);

			if (fl_fread(readBuffer, 1, fileLengths[j], readFile)!=fileLengths[j])
			{
				printf("ERROR: File %s Read Length Error %d\n", filenames[j], fileLengths[j]);
				fl_assert(0);
			}

			for (i=0;i<fileLengths[j];i++)
				if ( fileData[j][i] != (BYTE)readBuffer[i] )
					failed = TRUE;

			if (failed)
			{
				printf("ERROR: File %s Data Verify Failed\n", filenames[j]);
				fl_assert(0);
			}
		}
		fl_fclose(readFile);

		// Clear buffer
		for (i=0;i<sizeof(readBuffer);i++)
			readBuffer[i] = 0;

		// Verify File using fgetc
		readFile = fl_fopen(filenames[j], "r");
		if (readFile!=NULL)
		{
			int failed = FALSE;

			printf("File %s Read Check (fgetc) [%d bytes]\n", filenames[j], fileLengths[j]);

			i = 0;
			while (i < fileLengths[j])
			{
				int res = fl_fgetc(readFile);
				if (res == -1)
					break;

				readBuffer[i++] = (BYTE)res;
			}

			if (i != fileLengths[j])
			{
				printf("ERROR: File %s Read Length Error %d\n", filenames[j], fileLengths[j]);
				fl_assert(0);
			}

			for (i=0;i<fileLengths[j];i++)
				if ( fileData[j][i] != (BYTE)readBuffer[i] )
					failed = TRUE;

			if (failed)
			{
				printf("ERROR: File %s Data Verify Failed\n", filenames[j]);
				fl_assert(0);
			}
		}
		fl_fclose(readFile);

		// Clear buffer
		for (i=0;i<sizeof(readBuffer);i++)
			readBuffer[i] = 0;

		// Verify File chunks
		readFile = fl_fopen(filenames[j], "r");
		if (readFile!=NULL)
		{
			int failed = FALSE;

			printf("File %s Read Check (fread chunks) [%d bytes]\n", filenames[j], fileLengths[j]);

			i = 0;
			while (i < fileLengths[j])
			{
				int read_length = GetRandom(1025);

				if (read_length > (fileLengths[j] - i))
					read_length = fileLengths[j] - i;

				if (fl_fread(readBuffer + i, 1, read_length, readFile) != read_length)
				{
					printf("ERROR: File %s fread error\n", filenames[j]);
					fl_assert(0);
					break;
				}

				i += read_length;
			}

			if (i != fileLengths[j])
			{
				printf("ERROR: File %s Read Length Error %d\n", filenames[j], fileLengths[j]);
				fl_assert(0);
			}

			for (i=0;i<fileLengths[j];i++)
				if ( fileData[j][i] != (BYTE)readBuffer[i] )
				{
					failed = TRUE;
					break;
				}

			if (failed)
			{
				printf("ERROR: File %s Data Verify Failed at %d\n", filenames[j], i);
				fl_assert(0);
			}
		}
		fl_fclose(readFile);

		// Delete File
		if (fl_remove(filenames[j])<0)
			printf("ERROR: Delete File %s Failed\n", filenames[j]);

		// Verify file is no longer present!
		readFile = fl_fopen(filenames[j], "r");
		if (readFile != NULL)
		{
			printf("ERROR: File %s still present after delete!\n", filenames[j]);
			fl_assert(0);
			fl_fclose(readFile);
		}
	}

	// Create folder
	fl_createdirectory("C:\\folder1");

#if 0

	// Create massive file
#define MASSIVE_FILE_LEN (1024 * 1024)
	printf("Creating Massive File [%d bytes]\n", MASSIVE_FILE_LEN);

	massiveData = malloc(MASSIVE_FILE_LEN);
	if (!massiveData)
	{
		printf("ERROR: Could not allocate memory for massive array!\n");
		fl_assert(0);
		fl_shutdown();
		return ;
	}

	// Create random data for file
	for (x=0;x<MASSIVE_FILE_LEN;x++)
		massiveData[x] = (BYTE)GetRandom(255);

	// Remove if it already exists!
	fl_remove("X:\\folder1\\massive file.bin");

	timeStart = time(NULL);

	// Create Large File
	readFile = fl_fopen("X:\\folder1\\massive file.bin", "w");
	if (readFile != NULL)
	{
		if (fl_fwrite(massiveData, 1, MASSIVE_FILE_LEN, readFile) != MASSIVE_FILE_LEN)
		{
			printf("ERROR: File Write Block Failed for massive file (Length %d)\n", MASSIVE_FILE_LEN);
			fl_assert(0);
		}
	}
	else
	{
		printf("ERROR: Error Creating massive file\n");
		fl_assert(0);
	}

	fl_fclose(readFile);

	// Verify Massive File
	readFile = fl_fopen("X:\\folder1\\massive file.bin", "r");
	if (readFile!=NULL)
	{
		int failed = FALSE;

		printf("File Massive File Read Check (fread whole file) [%d bytes]\n", MASSIVE_FILE_LEN);

		i = 0;
		while (i < MASSIVE_FILE_LEN)
		{
			int read_length = GetRandom(2048) + 128;

			if (read_length > (MASSIVE_FILE_LEN - i))
				read_length = MASSIVE_FILE_LEN - i;

			if (fl_fread(readBuffer, 1, read_length, readFile) != read_length)
			{
				printf("ERROR: File massive file fread error\n");
				fl_assert(0);
				break;
			}

			for (j=0;j<read_length;j++)
				if ( massiveData[i+j] != (BYTE)readBuffer[j] )
				{
					printf("ERROR: File Massive File Data Verify Failed at %d\n", i+j);
					fl_assert(0);
					break;
				}

			i += read_length;
		}

		if (i != MASSIVE_FILE_LEN)
		{
			printf("ERROR: File massive file Read Length Error %d\n", MASSIVE_FILE_LEN);
			fl_assert(0);
		}
	}
	fl_fclose(readFile);

	timeEnd = time(NULL);
	printf("Time taken %d seconds\n", (int)(timeEnd-timeStart));

	free(massiveData);
#endif

	// Filename test
	for (i=0;i<TESTFILES;i++)
	{
		// Create File
		readFile = fl_fopen(testfile[i], "w");
		if (readFile != NULL)
			;
		else
		{
			printf("ERROR: Error Creating File %s\n", testfile[i]);
			fl_assert(0);
		}

		fl_fputc(0, readFile);
		fl_fclose(readFile);

		readFile = fl_fopen(testfile[i], "r");
		assert(readFile);
		fl_fclose(readFile);
	}

	// List directory
	fl_listdirectory("C:\\");

	for (i=0;i<TESTFILES;i++)
	{
		// Delete File
		if (fl_remove(testfile[i])<0)
		{
			printf("ERROR: Delete File %s Failed\n", testfile[i]);
			fl_assert(0);
		}
	}

	fl_shutdown();

	printf("\r\nCompleted\r\n");

	// List directory
	fl_listdirectory("C:\\");
}
Exemplo n.º 12
0
void file_close(file_handle_t handle)
{
    fl_fclose(handle);
}
Exemplo n.º 13
0
int
cmd_hd_exec(CLI *cli, char *argv[]) {
	int argc = cli_num_args(argv);
	char buffer[16], path[PATH_MAX];
	int eof = 0, rc, line = 0, i;
	FL_FILE *file;

	if (argc != 2) {
		printf("hd - incorrect number of arguments. Try 'man hd'\n");

		return (-1);
	}

	cli_clean_path(cli, argv[1], path);

	if (fl_is_dir(path)) {
		printf("hd: '%s' is a directory\n", path);

		return (-1);
	}

	file = (FL_FILE *)fl_fopen(path, "r");

	if (!file) {
		printf("hd: Could not open '%s'\n", path);

		return (-1);
	}

	while (rc != EOF) {
		rc = fl_fread(buffer, 16, 1, file);

		printf("%04hhx:%04hhx  ", line * 16, line * 16 + rc -1);

		for (i=0; i<rc; i++) {
			printf("%02hhx ", buffer[i]);
			if (i == 7) printf(" ");
		}

		for (i=rc; i<16; i++) {
			printf("   ");
			if (i == 7) printf(" ");
		}

		printf(" |");
		for (i=0; i<rc; i++) {
			if ((buffer[i] < 32) || (buffer[i] > 127)) {
				printf(".");
			} else {
				printf("%c", buffer[i]);
			}
		}
		printf("|\n");

		if (rc < 16) break;

		line++;
	}

	fl_fclose(file);

	return (0);
}
Exemplo n.º 14
0
void LOS_proc(unsigned char tid, void* msg)
{
    //static int file_num = 0;
	//static int size;
	static LOS_state_t last_st;
	int i;
    
#ifndef __LOCAL_STORE_ACCEL_MODE__
	if (LOS_queue.numBytes > 0)
#else
    if (LS_num_accel_queue > 0)
#endif
	{
		switch (st)
		{
		case LOS_NONE:
			//probe_high();
			last_st = st;
			st = LOS_CREATE_START;
		case LOS_CREATE_START:
			i = fl_fopen("/file.txt", "w", (void**)&mFile[LOS_open_file_index], TRUE);
			switch (i)
			{
			case 0:
				st = LOS_OPEN_START;
				break;
			case -1:
				return;
			default:
				if (mFile[LOS_open_file_index])
				{
					last_st = st;
					st = LOS_CREATE_DONE;
				}
				else
				{
					st = LOS_OPEN_START;
				}
			}
		case LOS_OPEN_START:
			if (st == LOS_OPEN_START)
			{
#ifdef PROBE_ENABLED
				probe_low();
#endif
				i = fl_fopen("/file.txt", "w", (void**)mFile[LOS_open_file_index], TRUE);
				switch (i)
				{
				case 0:
					st = LOS_NONE;
					return;
				case -1:
					return;
				default:
					if (mFile[LOS_open_file_index])
					{
						last_st = st;
						st = LOS_OPEN_DONE;
					}
					else
					{
						st = LOS_NONE;
						return;
					}
				}
			}
		case LOS_CREATE_DONE:
		case LOS_OPEN_DONE:
			//probe_low();
			last_st = st;
#ifndef __LOCAL_STORE_ACCEL_MODE__
			if (LOS_queue.outCount == LOS_queue.inCount)
			{
				st = LOS_WRITE_HEAD;
			}
			else if (LOS_queue.outCount > LOS_queue.inCount)
			{
				size = LOS_queue.maxBytes - LOS_queue.outCount;
				st = LOS_WRITE_HEAD;
			}
			else
			{
				size = LOS_queue.numBytes;
				st = LOS_WRITE_ALL;
			}
		case LOS_WRITE_HEAD:
			if (st == LOS_WRITE_HEAD)
			{
				i = fl_fwrite(&LOS_queue.buffer[LOS_queue.outCount], 1, size, mFile[LOS_open_file_index]);
				switch (i)
				{
				case -1:
					printf("ERROR: Write file failed\n");
					st = last_st;
					return;
				case -2:
					return;
				}
				st = last_st;
				if (i == size)
				{
					LOS_queue.numBytes -= size;
					LOS_queue.outCount = 0;
				}
				else
				{
					printf("ERROR: Write file failed\n");
				}
				return;
			}
		case LOS_WRITE_ALL:
			if (st == LOS_WRITE_ALL)
			{
				i = fl_fwrite(&LOS_queue.buffer[LOS_queue.outCount], 1, size, mFile[LOS_open_file_index]);
				switch (i)
				{
				case -1:
					printf("ERROR: Write file failed\n");
					st = last_st;
					return;
				case -2:
					return;
				default:
					if (i == size)
					{
						LOS_queue.numBytes -= size;
						LOS_queue.outCount += size;
#ifdef PROBE_ENABLED
						probe2_change(0);
#endif
						if (mFile[LOS_open_file_index]->filelength > MAX_FILE_SIZE)
						{
							st = LOS_CLOSE_START;
						}
						else
						{
							st = last_st;
							return;
						}
					}
					else
					{
						printf("ERROR: Write file failed\n");
						st = last_st;
						return;
					}
				}
			}
#else 
            if (LS_get_accel_string())
            {
                st = LOS_WRITE;
            }
            else
            {
                st = last_st;
                return;
            }
        case LOS_WRITE:
            if (st == LOS_WRITE)
            {
                i = fl_fwrite(LS_accel_string, 1, LS_accel_string_size, mFile[LOS_open_file_index]);
                switch (i)
                {
                case -1:
                    printf("ERROR: Write file failed\n");
                    st = last_st;
                    return;
                case -2:
                    return;
                }
                st = last_st;
                if (i == LS_accel_string_size)
                {
                    LS_accel_queue_out_count = (LS_accel_queue_out_count + 1) % MAX_LS_ACCEL_ITEMS;
                    --LS_num_accel_queue;
#ifdef PROBE_ENABLED
                    probe2_change(0);
#endif
					if (mFile[LOS_open_file_index]->filelength > MAX_FILE_SIZE)
					{
						st = LOS_CLOSE_START;
					}
					else
					{
						st = last_st;
						return;
					}
                }
                else
                {
                    st = last_st;
                    return;
                }
            }
#endif
		case LOS_CLOSE_START:
			i = fl_fclose(mFile[LOS_open_file_index]);
			switch (i)
			{
			case 0:
				printf("ERROR: Close file failed\n");
				return;
			case -1:
				i = 0;
				return;
			}
			st = LOS_NONE;
		}
	}
}