예제 #1
0
void fatUnmount (const char* name) {
	devoptab_t *devops;
	PARTITION* partition;

	if(!name)
		return;

	devops = (devoptab_t*)GetDeviceOpTab (name);
	if (!devops) {
		return;
	}

	// Perform a quick check to make sure we're dealing with a libfat controlled device
	if (devops->open_r != dotab_fat.open_r) {
		return;
	}

	if (RemoveDevice (name) == -1) {
		return;
	}

	partition = (PARTITION*)devops->deviceData;
	_FAT_partition_destructor (partition);
	_FAT_mem_free (devops);
}
예제 #2
0
//---------------------------------------------------------------------------------
static inline RAMDISK_PARTITION* ramdiskFS_getPartitionFromPath(const char* path) {
//---------------------------------------------------------------------------------
	const devoptab_t *devops = GetDeviceOpTab(path);
	if (!devops)
		return NULL;
	return *((RAMDISK_PARTITION**)devops->deviceData);
}
예제 #3
0
const devoptab_t *ntfsGetDevice (const char *path, bool useDefaultDevice)
{
    const devoptab_t *devoptab = NULL;
    char name[128] = {0};
    int i;

    // Get the device name from the path
    strncpy(name, path, 127);
    strtok(name, ":/");

    // Search the devoptab table for the specified device name
    // NOTE: We do this manually due to a 'bug' in GetDeviceOpTab
    //       which ignores names with suffixes and causes names
    //       like "ntfs" and "ntfs1" to be seen as equals
    for (i = 0; i < STD_MAX; i++) {
        devoptab = devoptab_list[i];
        if (devoptab && devoptab->name) {
            if (strcmp(name, devoptab->name) == 0) {
                return devoptab;
            }
        }
    }

    // If we reach here then we couldn't find the device name,
    // chances are that this path has no device name in it.
    // Call GetDeviceOpTab to get our default device (chdir).
    if (useDefaultDevice)
        return GetDeviceOpTab("");

    return NULL;
}
예제 #4
0
int _DRD_stat_r (struct _reent *r, const char *path, struct stat *st)
{
  const devoptab_t *devops;
  unsigned int i;

  st->st_dev = 0;
  st->st_ino = 0;
  st->st_mode = 0;
  st->st_nlink = 0;
  st->st_uid = 0;
  st->st_gid = 0;
  st->st_rdev = 0;
  st->st_size = 0;

  drd_printf("trying to stat('%s').\n", path);

  /* select ramdisk by specified path */
  devops = GetDeviceOpTab(path);

  if (!devops) {
    /* not found */
    drd_printf("stat('%s') failed. No ramdisk.\n", path);
    return -1;
  }

  /* move the path pointer to the start of the actual path */
  if (strchr (path, ':') != NULL) {
    path = strchr (path, ':') + 1;
  }

  /* abort if path contains more than one ":" */
  if (strchr (path, ':') != NULL) {
    drd_printf("stat('%s') failed. Only one ':' allowed in path.\n", path);
    return -1;
  }

  dolramdisk* this_ramdisk = devops->deviceData;

  /* loop through files, to find file by name */
  for (i = 0; i < this_ramdisk->numfiles; i++)
  {
    /* if file found */
    if (stricmp(this_ramdisk->filenames[i], path) == 0)
    {
      st->st_size = this_ramdisk->filesizes[i];

      drd_printf("stat('%s') succeeded, file size is %lu.\n",
                 this_ramdisk->filenames[i],
                 (unsigned long) this_ramdisk->filesizes[i]);
      return 0;
    }
  }

  /* file not found */
  drd_printf("stat('%s') failed. File not found.\n", path);
  return -1;
}
예제 #5
0
int _DRD_open_r (struct _reent *r, void *fileStruct, const char *path, int flags, int mode)
{
  FILE_STRUCT* fp = (FILE_STRUCT*) fileStruct;
  const devoptab_t *devops;
  unsigned int i;

  drd_printf("trying to open('%s').\n", path);

  /* select ramdisk by specified path */
  devops = GetDeviceOpTab(path);

  if (!devops) {
    /* not found */
    drd_printf("open('%s') failed. No ramdisk.\n", path);
    return -1;
  }

  /* file opened for writing only */
  if((flags & 0x03) == O_WRONLY) {
    drd_printf("open('%s') for writing failed. Readonly ramdisk.\n", path);
    return -1;
  }

  /* move the path pointer to the start of the actual path */
  if (strchr (path, ':') != NULL) {
    path = strchr (path, ':') + 1;
  }

  /* abort if path contains more than one ":" */
  if (strchr (path, ':') != NULL) {
    drd_printf("open('%s') failed. Only one ':' allowed in path.\n", path);
    return -1;
  }

  dolramdisk* this_ramdisk = devops->deviceData;

  /* loop through files, to find file by name */
  for (i = 0; i < this_ramdisk->numfiles; i++)
  {
    /* if file found */
    if (stricmp(this_ramdisk->filenames[i], path) == 0)
    {
      drd_printf("open('%s') succeeded.\n", path);
      fp->filesystem = this_ramdisk;
      fp->index = i;
      fp->offset = 0; /* begin of file */
      /* ok */
      return (int) fp;
    }
  }

  /* file not found */
  drd_printf("open('%s') failed. File not found.\n", path);
  return -1;
}
예제 #6
0
PARTITION* _FAT_partition_getPartitionFromPath (const char* path) {
	const devoptab_t *devops;

	devops = GetDeviceOpTab (path);

	if (!devops) {
		return NULL;
	}

	return (PARTITION*)devops->deviceData;
}
예제 #7
0
	void Init(void* buffer, int size_bytes)
	{
		gInstance = &sInstance;
		gInstance->buffer = buffer;
		gInstance->size_bytes = size_bytes;
		fatMountSimple("fat",&discio);
		gInstance->devops = GetDeviceOpTab(NULL);
		

		int zzz=9;
	}
예제 #8
0
void fatGetVolumeLabel (const char* name, char *label) {
	devoptab_t *devops;
	PARTITION* partition;
	char *buf;
	int namelen,i;

	if(!name || !label)
		return;

	namelen = strlen(name);
	buf=(char*)_FAT_mem_allocate(sizeof(char)*namelen+2);	
	strcpy(buf,name);

	if (name[namelen-1] == '/') {
		buf[namelen-1]='\0';
		namelen--;
	}

	if (name[namelen-1] != ':') {
		buf[namelen]=':';
		buf[namelen+1]='\0';
	}

	devops = (devoptab_t*)GetDeviceOpTab(buf);

	for(i=0;buf[i]!='\0' && buf[i]!=':';i++);  
	if (!devops || strncasecmp(buf,devops->name,i)) {
		_FAT_mem_free(buf);
		return;
	}

	_FAT_mem_free(buf);

	// Perform a quick check to make sure we're dealing with a libfat controlled device
	if (devops->open_r != dotab_fat.open_r) {
		return;
	}	

	partition = (PARTITION*)devops->deviceData;

	if(!_FAT_directory_getVolumeLabel(partition, label)) { 
		strncpy(label,partition->label,11);
		label[11]='\0';
	}
	if(!strncmp(label, "NO NAME", 7)) label[0]='\0';
}
예제 #9
0
//---------------------------------------------------------------------------------
void ramdiskFS_Unmount(const char* mountpoint) {
//---------------------------------------------------------------------------------
	RAMDISK_PARTITION *partition;
	devoptab_t *devops = (devoptab_t*)GetDeviceOpTab(mountpoint);
	
	if (!devops)
		return;

	// Perform a quick check to make sure we're dealing with a ramdiskFS_ controlled device
	if (devops->open_r != ramdiskFS_devoptab.open_r)
		return;
	
	if (RemoveDevice (mountpoint) == -1)
		return;

	partition = *((RAMDISK_PARTITION **)devops->deviceData);
	if(partition->automount)
		delete partition;
	free (devops); 
}
예제 #10
0
void flushFatCache() {
    // This involves things from libfat which aren't normally visible
    devoptab_t* devops = (devoptab_t*)GetDeviceOpTab ("sd");
    PARTITION* partition = (PARTITION*)devops->deviceData;
    _FAT_cache_flush(partition->cache); // Flush the cache manually
}