void vCreateAndVerifySampleFiles( void )
{
unsigned char ucStatus;

	/* First create the volume. */
	ucStatus = f_initvolume( ram_initfunc );

	/* It is expected that the volume is not formatted. */
	if( ucStatus == F_ERR_NOTFORMATTED )
	{
		/* Format the created volume. */
		ucStatus = f_format( F_FAT12_MEDIA );
	}

	if( ucStatus == F_NO_ERROR )
	{
		/* Create a set of files using f_write(). */
		prvCreateDemoFilesUsing_f_write();

		/* Read back and verify the files that were created using f_write(). */
		prvVerifyDemoFileUsing_f_read();

		/* Create sub directories two deep then create a file using putc. */
		prvCreateDemoFileUsing_f_putc();

		/* Read back and verify the file created by
		prvCreateDemoFileUsing_f_putc(). */
		prvVerifyDemoFileUsing_f_getc();
	}
}
Esempio n. 2
0
int main(void)
{
    tm4c123_spi_initialize();

    {
	F_FILE *file;
	unsigned int n;
	uint8_t data[512];

	f_initvolume();

	file = f_open("LOG00000.DAT", "w,32M");

	if (file)
	{
	    f_flush(file);

	    memset(data, 0xaa, sizeof(data));

	    for (n = 0; n < (32 * 1024 * 1024 / 512); n++)
	    {
		f_write(data, 512, 1, file);
	    }
  
	    f_close(file);
	}

	f_delvolume();
    }

    while (1) { };
}
Esempio n. 3
0
/* Format the media in drive number 'driveno'
   Returns 0 for success and error code for failure. */
int
fs_hfat_format (int driveno)
{
  int ret;
  uint32 blocks;
  uint16 bytes_per_block;
  uint32 total_mb = 0;

  /* Unprotect memory
   * Due to the time taken to format we do not grab the global lock
   * which allows other threads to operate concurrently if using flash.
   * In lieu of this we must first unprotect the memory segment before
   * we operate on the HFAT protected memory region. */
  fs_efs2_unprotect_memory ();

  /* We don't yet have an initialized drive. */
  ret = f_initvolume (driveno, hfat_device_init, driveno);

  /* An error indicating Not Formatted is OK */
  if ((ret != F_NO_ERROR) && (ret != F_ERR_NOTFORMATTED))
    goto cleanup;

  /* Now we have an initialized volume..  Get the size. */
  ret = hotplug_dev_get_size (hotplug_hdev (driveno),
                              &blocks, &bytes_per_block);

  /* HFAT only works with block sizes of 512 bytes */
  if (bytes_per_block == 512)
    total_mb = (blocks / (1024 / bytes_per_block)) / 1024;
  else
    ret = F_ERR_INVALIDDRIVE;

  /* Look at media size to determine FAT type */
  if (ret == 0)
  {
    int ftype = total_mb <= 64 ? F_FAT12_MEDIA :
      (total_mb <= 2048 ? F_FAT16_MEDIA : F_FAT32_MEDIA);

    ret = f_format (driveno, ftype);
  }

  /* Discard the volume */
  (void) f_delvolume (driveno);

 cleanup:
  /* Protect memory again */
  fs_efs2_protect_memory ();

  return hfat_to_efs_err (ret);
}
Esempio n. 4
0
/* Start the filesystem (called during mount). */
static int
e_hfat_start (const char *name)
{
  int ret;
  int driveno = hfat_driveno (name);

  /* Attempt to initialize the HFAT volume.  Reads the partition table
   * and verifies the formatting. */
  ret = f_initvolume (driveno, hfat_device_init, driveno);

  /* If that failed, we can not mount the volume */
  if (ret)
  {
    /* HFAT leaves the volume allocated, so we must delete it
       manually.  Discard the return value from f_delvolume() because
       the f_initvolume() error cause is more interesting. */
    (void) f_delvolume (driveno);
  }

  return hfat_to_efs_err (ret);
}
Esempio n. 5
0
/* Use to build file system (mount). */
uint8_t _f_poweron ( void )
{
  f_delvolume();
  return f_initvolume( ram_initfunc );
}