Esempio n. 1
0
bool GBAMPFileSystemNode::getChildren(AbstractFSList& dirList, ListMode mode, bool hidden) const {
//	consolePrintf("Listdir\n");

	//TODO: honor the hidden flag

	enum { TYPE_NO_MORE = 0, TYPE_FILE = 1, TYPE_DIR = 2 };

	char temp[128], fname[256], *path, *pathTemp;
	strcpy(temp, _path.c_str());

	path = temp + 3;

	pathTemp = path;
	while (*pathTemp) {
		if (*pathTemp == '\\') {
			*pathTemp = '/';
		}
		pathTemp++;
	}

	// consolePrintf("This dir: %s\n", path);
	FAT_chdir(path);

	int entryType = FAT_FindFirstFileLFN(fname);

	while (entryType != TYPE_NO_MORE) {

		if ( ((entryType == TYPE_DIR) && ((mode == Common::FSNode::kListDirectoriesOnly) || (mode == Common::FSNode::kListAll)))
		||   ((entryType == TYPE_FILE) && ((mode == Common::FSNode::kListFilesOnly) || (mode == Common::FSNode::kListAll))) ) {
			GBAMPFileSystemNode *dsfsn;

			//consolePrintf("Fname: %s\n", fname);

			if (strcmp(fname, ".") && strcmp(fname, "..")) {

				if (!strcmp(path, "/")) {
					dsfsn = new GBAMPFileSystemNode("mp:" + Common::String(path) + Common::String(fname), entryType == TYPE_DIR);
				} else {
					dsfsn = new GBAMPFileSystemNode("mp:" + Common::String(path) + Common::String("/") + Common::String(fname), entryType == TYPE_DIR);
				}

//				dsfsn->_isDirectory = entryType == DIR;
				dirList.push_back((dsfsn));
			}
		} else {
//			consolePrintf("Skipping %s\n", fname);
		}

		entryType = FAT_FindNextFileLFN(fname);
	}

//	consolePrintf("No more");

	FAT_chdir("/");

	return true;
}
Esempio n. 2
0
Common::StringArray GBAMPSaveFileManager::listSavefiles(const Common::String &pattern) {

	enum { TYPE_NO_MORE = 0, TYPE_FILE = 1, TYPE_DIR = 2 };
	char name[256];

	{
		char dir[128];
		strcpy(dir, getSavePath().c_str());
		char *realName = dir;

		if ((strlen(dir) >= 4) && (dir[0] == 'm') && (dir[1] == 'p') && (dir[2] == ':') && (dir[3] == '/')) {
			realName += 4;
		}

	//	consolePrintf("Real cwd:%d\n", realName);

		char *p = realName;
		while (*p) {
			if (*p == '\\') *p = '/';
			p++;
		}

	//	consolePrintf("Real cwd:%d\n", realName);
		FAT_chdir(realName);

	}

//	consolePrintf("Save path: '%s', pattern: '%s'\n", getSavePath(), pattern);


	int fileType = FAT_FindFirstFileLFN(name);

	Common::StringArray list;

	do {

		if (fileType == TYPE_FILE) {

			FAT_GetLongFilename(name);

			for (int r = 0; name[r] != 0; r++) {
				name[r] = tolower(name[r]);
			}


			if (Common::matchString(name, pattern.c_str())) {
				list.push_back(name);
			}
		}

	} while ((fileType = FAT_FindNextFileLFN(name)));

	FAT_chdir("/");

	return list;
}
Esempio n. 3
0
uint TestDir7(void)
{
  tIORes res;
  uint result = 1;
  uint i;
  char name[13];
  tFATFSStatus FSStatus1, FSStatus2;

  FAT_statvfs (&stdio_FATFS, &res, "\\", &FSStatus1);
  CHK(res == ior_OK);

  FAT_mkdir (&stdio_FATFS, &res, "level1", mt_S_IWUSR);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "level1", 0);
  CHK(res == ior_OK);

  for (i = 0; i < 257; i++)
  {
    sprintf (name, "%u", i);
    FAT_mkdir (&stdio_FATFS, &res, name, mt_S_IWUSR);
    CHK(res == ior_OK);
  }

  for (i = 0; i < 257; i++)
  {
    sprintf (name, "%u", i);
    FAT_rmdir (&stdio_FATFS, &res, name);
    CHK(res == ior_OK);
  }

  FAT_chdir (&stdio_FATFS, &res, "..", 0);
  CHK(res == ior_OK);

  FAT_rmdir (&stdio_FATFS, &res, "level1");
  CHK(res == ior_OK);

  FAT_statvfs (&stdio_FATFS, &res, "\\", &FSStatus2);
  CHK(res == ior_OK);
  CHK(FSStatus2.TotalFreeClusterCount == FSStatus1.TotalFreeClusterCount);

  result = 0;

lend:
  return result;
}
Esempio n. 4
0
FILE *std_fopen(const char *name, const char *mode) {
	if (!inited) {
		for (int r = 0; r < MAX_FILE_HANDLES; r++) {
			s_handle[r].used = false;
		}
		inited = true;
		currentDir[0] = '\0';
	}

	char realName[MAXPATHLEN];

	// Remove file system prefix
	if ((name[0] == 'd') && (name[1] == 's') && (name[2] == ':') && (name[3] == '/')) {
		strlcpy(realName, name + 4, MAXPATHLEN);
	} else if ((name[0] == 'm') && (name[1] == 'p') && (name[2] == ':') && (name[3] == '/')) {
		strlcpy(realName, name + 4, MAXPATHLEN);
	} else {
		strlcpy(realName, name, MAXPATHLEN);
	}

//	consolePrintf("Open file:");
//	consolePrintf("'%s', [%s]", name, realName);

	if (DS::isGBAMPAvailable()) {
		FAT_chdir("/");

		// Turn all back slashes into forward slashes for gba_nds_fat
		char *p = realName;
		while (*p) {
			if (*p == '\\')
				*p = '/';
			p++;
		}

		FAT_FILE *result = FAT_fopen(realName, mode);

		if (result == 0) {
//			consolePrintf("Error code %d\n", result);
			//consolePrintf("Opening file %s\n", realName);
		} else {
//			consolePrintf("Opened file %d\n", result);
		}
//		MT_memoryReport();

		return (FILE *)result;
	}

	// Fail to open file for writing.  It's in ROM!

	// Allocate a file handle
	int r = 0;
	while (s_handle[r].used) {
		r++;
		assert(r < MAX_FILE_HANDLES);
	}

	char *data;

	ZipFile *zip = DSFileSystemNode::getZip();
	if (!zip) {
//		consolePrintf("No zip yet!");
		return NULL;
	}

	// Grab the data if it exists

	zip->setAllFilesVisible(true);

	if (currentDir[0] != 0) {
		char nameWithPath[128];
		sprintf(nameWithPath, "%s\\%s", currentDir, realName);
		strcpy(realName, nameWithPath);
	}

//	consolePrintf("fopen(%s, %s)\n", realName, name);

	if (zip->findFile(realName)) {
		data = zip->getFile();
		zip->setAllFilesVisible(false);

		// Allocate a file handle
		r = 0;
		while (s_handle[r].used)
			r++;


		s_handle[r].used = true;
		s_handle[r].pos = 0;
		s_handle[r].data = data;
		s_handle[r].size = zip->getFileSize();

//		consolePrintf("Opened file %d: %s (%s)   ", r, realName, name);
		return &s_handle[r];
	} else {
		zip->setAllFilesVisible(false);
//		consolePrintf("Not found: %s (%s)  ", realName, name);
		return NULL;
	}
}
Esempio n. 5
0
uint TestDir9(void)
{
  tIORes res;
  uint result = 1;
  tFATFSStatus FSStatus1, FSStatus2;

  FAT_statvfs (&stdio_FATFS, &res, "\\", &FSStatus1);
  CHK(res == ior_OK);

  FAT_mkdir (&stdio_FATFS, &res, "level1", mt_S_IWUSR);
  CHK(res == ior_OK);

  FAT_mkdir (&stdio_FATFS, &res, "level1\\level2", mt_S_IWUSR);
  CHK(res == ior_OK);

  FAT_mkdir (&stdio_FATFS, &res, "level1\\level2\\level3", mt_S_IWUSR);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "level1\\level2\\level3", 0);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "..", 0);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "..", 0);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "..", 0);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "level1\\level2\\level3", 0);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "..\\..", 0);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "..", 0);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "level1\\level2\\level3", 0);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "..", 0);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "..\\..", 0);
  CHK(res == ior_OK);

  FAT_rmdir (&stdio_FATFS, &res, "level1\\level2\\level3");
  CHK(res == ior_OK);

  FAT_rmdir (&stdio_FATFS, &res, "level1\\level2");
  CHK(res == ior_OK);

  FAT_rmdir (&stdio_FATFS, &res, "level1");
  CHK(res == ior_OK);

  FAT_statvfs (&stdio_FATFS, &res, "\\", &FSStatus2);
  CHK(res == ior_OK);
  CHK(FSStatus2.TotalFreeClusterCount == FSStatus1.TotalFreeClusterCount);

  result = 0;

lend:
  return result;
}
Esempio n. 6
0
uint TestDir6(void)
{
  tIORes res;
  uint result = 1;
  tFATFSStatus FSStatus1, FSStatus2;
  char name[128];

  FAT_statvfs (&stdio_FATFS, &res, "\\", &FSStatus1);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "a:", 0);
  CHK(res == ior_OK);

  FAT_getcwd (&stdio_FATFS, &res, name, sizeof(name));
  CHK(res == ior_OK);
  res = (strcmp (name, "A:\\") == 0) ? ior_OK : ior_BAD_NAME;
  CHK(res == ior_OK);

// bad chars: \"*+,./:;<=>?[\]|

  FAT_mkdir (&stdio_FATFS, &res, "\x05\xE5", mt_S_IWUSR);
  CHK(res == ior_OK);

  FAT_rmdir (&stdio_FATFS, &res, "\x05\xE5");
  CHK(res == ior_OK);

  FAT_mkdir (&stdio_FATFS, &res, "a.b", mt_S_IWUSR);
  CHK(res == ior_OK);

  FAT_rmdir (&stdio_FATFS, &res, "a.b");
  CHK(res == ior_OK);

  FAT_mkdir (&stdio_FATFS, &res, "level1\\", mt_S_IWUSR);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "level", 0);
  CHK(res == ior_NOT_FOUND);

  FAT_chdir (&stdio_FATFS, &res, "level11\\", 0);
  CHK(res == ior_NOT_FOUND); // ior_BAD_NAME

  FAT_chdir (&stdio_FATFS, &res, "level1\\", 0);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "a:", 1);
  CHK(res == ior_OK);

  FAT_rmdir (&stdio_FATFS, &res, "\\level1");
  CHK(res == ior_PROHIBITED);

  FAT_rmdir (&stdio_FATFS, &res, "..\\level1");
  CHK(res == ior_PROHIBITED);

  FAT_rmdir (&stdio_FATFS, &res, ".");
  CHK(res == ior_PROHIBITED);

  FAT_rmdir (&stdio_FATFS, &res, "..");
  CHK(res == ior_PROHIBITED);

  FAT_getcwd (&stdio_FATFS, &res, name, sizeof(name));
  CHK(res == ior_OK);
  res = (strcmp (name, "A:\\LEVEL1") == 0) ? ior_OK : ior_BAD_NAME;
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "..", 0);
  CHK(res == ior_OK);

  FAT_rmdir (&stdio_FATFS, &res, "level1");
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "z:", 0);
  CHK(res == ior_BAD_NAME);

  FAT_chdir (&stdio_FATFS, &res, "[:", 0);
  CHK(res == ior_BAD_NAME);

  FAT_chdir (&stdio_FATFS, &res, "a:", 1);
  CHK(res == ior_OK);

  FAT_mkdir (&stdio_FATFS, &res, "level1.dir", mt_S_IWUSR);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "level1.dir", 0);
  CHK(res == ior_OK);

  CHK(FAT_getcwd (&stdio_FATFS, &res, name, sizeof(name)) == name);
  CHK(res == ior_OK);
  res = (strcmp (name, "A:\\LEVEL1.DIR") == 0) ? ior_OK : ior_BAD_NAME;
  CHK(res == ior_OK);

  CHK(FAT_getcwd (&stdio_FATFS, &res, name, strlen("A:\\LEVEL1.DIR")) == NULL);
  CHK(res == ior_ARGUMENT_OUT_OF_RANGE);

  CHK(FAT_getcwd (&stdio_FATFS, &res, name, strlen("A:\\LEVEL1.DIR")+1) == name);
  CHK(res == ior_OK);
  res = (strcmp (name, "A:\\LEVEL1.DIR") == 0) ? ior_OK : ior_BAD_NAME;
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "..", 0);
  CHK(res == ior_OK);

  FAT_rmdir (&stdio_FATFS, &res, "level1.dir");
  CHK(res == ior_OK);

  FAT_statvfs (&stdio_FATFS, &res, "\\", &FSStatus2);
  CHK(res == ior_OK);
  CHK(FSStatus2.TotalFreeClusterCount == FSStatus1.TotalFreeClusterCount);

  result = 0;

lend:
  return result;
}
Esempio n. 7
0
uint TestDirFileMixup1(void)
{
  tIORes res;
  uint result = 1;
  tFATFile file;
  tFATFSStatus FSStatus1, FSStatus2;

  FAT_statvfs (&stdio_FATFS, &res, "\\", &FSStatus1);
  CHK(res == ior_OK);

  FAT_fopen (&stdio_FATFS, &res, &file, "file1", "wb");
  CHK(res == ior_OK);

  FAT_fclose (&stdio_FATFS, &res, &file);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "file1", 0);
  CHK(res == ior_FILE_FOUND);

  FAT_mkdir (&stdio_FATFS, &res, "file1", mt_S_IWUSR);
  CHK(res == ior_FILE_FOUND);

  FAT_rmdir (&stdio_FATFS, &res, "file1");
  CHK(res == ior_FILE_FOUND);

  FAT_unlink (&stdio_FATFS, &res, "file1");
  CHK(res == ior_OK);

  FAT_fopen (&stdio_FATFS, &res, &file, "file1", "rb");
  CHK(res == ior_NOT_FOUND);

  FAT_mkdir (&stdio_FATFS, &res, "level1", mt_S_IWUSR);
  CHK(res == ior_OK);

  FAT_fopen (&stdio_FATFS, &res, &file, "level1", "rb");
  CHK(res == ior_DIR_FOUND);

  FAT_unlink (&stdio_FATFS, &res, "level1");
  CHK(res == ior_DIR_FOUND);

  FAT_chdir (&stdio_FATFS, &res, "level1", 0);
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "..", 0);
  CHK(res == ior_OK);

  FAT_rmdir (&stdio_FATFS, &res, "level1");
  CHK(res == ior_OK);

  FAT_chdir (&stdio_FATFS, &res, "..", 0);
  CHK(res == ior_NOT_FOUND);

  FAT_statvfs (&stdio_FATFS, &res, "\\", &FSStatus2);
  CHK(res == ior_OK);
  CHK(FSStatus2.TotalFreeClusterCount == FSStatus1.TotalFreeClusterCount);

  result = 0;

lend:
  return result;
}