[Scummvm-git-logs] scummvm master -> 1c5f923083268b1fc4df3522320f4b4f91006898

bgK bastien.bouclet at gmail.com
Tue Sep 15 05:13:05 UTC 2020


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
1c5f923083 PSP2: Simplify the filesystem code


Commit: 1c5f923083268b1fc4df3522320f4b4f91006898
    https://github.com/scummvm/scummvm/commit/1c5f923083268b1fc4df3522320f4b4f91006898
Author: Bastien Bouclet (bastien.bouclet at gmail.com)
Date: 2020-09-15T07:13:00+02:00

Commit Message:
PSP2: Simplify the filesystem code

The Vita SDK gained support for dirent at the end of 2017. There is no
need to have our own version anymore.

DrivesPOSIXFilesystemFactory allows to specify the contents of the
pseudo-root file system node. There is no need to hardcode them in
posix-fs.cpp anymore.

Changed paths:
  R backends/fs/psp2/psp2-dirent.cpp
  R backends/fs/psp2/psp2-dirent.h
  R backends/fs/psp2/psp2-fs-factory.cpp
  R backends/fs/psp2/psp2-fs-factory.h
    backends/fs/posix-drives/posix-drives-fs-factory.cpp
    backends/fs/posix-drives/posix-drives-fs.cpp
    backends/fs/posix/posix-fs.cpp
    backends/module.mk
    backends/platform/sdl/psp2/psp2.cpp


diff --git a/backends/fs/posix-drives/posix-drives-fs-factory.cpp b/backends/fs/posix-drives/posix-drives-fs-factory.cpp
index 848d527c6b..371d3b87e3 100644
--- a/backends/fs/posix-drives/posix-drives-fs-factory.cpp
+++ b/backends/fs/posix-drives/posix-drives-fs-factory.cpp
@@ -20,7 +20,7 @@
  *
  */
 
-#if defined(POSIX)
+#if defined(POSIX) || defined(PSP2)
 
 #define FORBIDDEN_SYMBOL_ALLOW_ALL
 
@@ -43,8 +43,12 @@ AbstractFSNode *DrivesPOSIXFilesystemFactory::makeRootFileNode() const {
 }
 
 AbstractFSNode *DrivesPOSIXFilesystemFactory::makeCurrentDirectoryFileNode() const {
+#if defined(PSP2) // The Vita does not have getcwd
+	return makeRootFileNode();
+#else
 	char buf[MAXPATHLEN];
-	return getcwd(buf, MAXPATHLEN) ? new DrivePOSIXFilesystemNode(buf, _config) : nullptr;
+	return getcwd(buf, MAXPATHLEN) ? new DrivePOSIXFilesystemNode(buf, _config) : makeRootFileNode();
+#endif
 }
 
 AbstractFSNode *DrivesPOSIXFilesystemFactory::makeFileNodePath(const Common::String &path) const {
diff --git a/backends/fs/posix-drives/posix-drives-fs.cpp b/backends/fs/posix-drives/posix-drives-fs.cpp
index 43297f15b1..4ad5a3bbf6 100644
--- a/backends/fs/posix-drives/posix-drives-fs.cpp
+++ b/backends/fs/posix-drives/posix-drives-fs.cpp
@@ -20,7 +20,7 @@
  *
  */
 
-#if defined(POSIX)
+#if defined(POSIX) || defined(PSP2)
 
 #define FORBIDDEN_SYMBOL_ALLOW_ALL
 
diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp
index a908729dd7..a6cc818eae 100644
--- a/backends/fs/posix/posix-fs.cpp
+++ b/backends/fs/posix/posix-fs.cpp
@@ -42,11 +42,9 @@
 #include <sys/types.h>
 #endif
 #ifdef PSP2
-#include "backends/fs/psp2/psp2-dirent.h"
 #define mkdir sceIoMkdir
-#else
-#include <dirent.h>
 #endif
+#include <dirent.h>
 #include <stdio.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -83,16 +81,6 @@ void POSIXFilesystemNode::setFlags() {
 POSIXFilesystemNode::POSIXFilesystemNode(const Common::String &p) {
 	assert(p.size() > 0);
 
-#ifdef PSP2
-	if (p == "/") {
-		_isDirectory = true;
-		_isValid = false;
-		_path = p;
-		_displayName = p;
-		return;
-	}
-#endif
-
 	// Expand "~/" to the value of the HOME env variable
 	if (p.hasPrefix("~/") || p == "~") {
 		const char *home = getenv("HOME");
@@ -183,15 +171,6 @@ bool POSIXFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, boo
 		return true;
 	}
 #endif
-#ifdef PSP2
-	if (_path == "/") {
-		POSIXFilesystemNode *entry1 = new POSIXFilesystemNode("ux0:");
-		myList.push_back(entry1);
-		POSIXFilesystemNode *entry2 = new POSIXFilesystemNode("uma0:");
-		myList.push_back(entry2);
-		return true;
-	}
-#endif
 
 #if defined(__ANDROID__) && !defined(ANDROIDSDL)
 	if (_path == "/") {
@@ -287,10 +266,6 @@ AbstractFSNode *POSIXFilesystemNode::getParent() const {
 		// This is a root directory of a drive
 		return makeNode("/");   // return a virtual root for a list of drives
 #endif
-#ifdef PSP2
-	if (_path.hasSuffix(":"))
-		return makeNode("/");
-#endif
 
 	const char *start = _path.c_str();
 	const char *end = start + _path.size();
diff --git a/backends/fs/psp2/psp2-dirent.cpp b/backends/fs/psp2/psp2-dirent.cpp
deleted file mode 100644
index aefd1a067d..0000000000
--- a/backends/fs/psp2/psp2-dirent.cpp
+++ /dev/null
@@ -1,241 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-/*
-
-Copyright (C) 2016, David "Davee" Morgan
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
-THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
-
-*/
-
-#include "psp2-dirent.h"
-#include <errno.h>
-#include <malloc.h>
-#include <string.h>
-
-#include <psp2/types.h>
-#include <psp2/io/dirent.h>
-#include <psp2/kernel/threadmgr.h>
-
-#define SCE_ERRNO_MASK 0xFF
-
-
-struct DIR_ {
-	SceUID uid;
-	struct dirent dir;
-	int refcount;
-	char *dirname;
-	int index;
-};
-
-static inline void grab_dir(DIR *dirp) {
-	__sync_add_and_fetch(&dirp->refcount, 1);
-}
-
-static inline void drop_dir(DIR *dirp) {
-	if (__sync_add_and_fetch(&dirp->refcount, 1) == 0) {
-		free(dirp->dirname);
-		free(dirp);
-	}
-}
-
-static inline void release_drop_dir(DIR *dirp) {
-	if (__sync_add_and_fetch(&dirp->refcount, 2) == 0) {
-		free(dirp->dirname);
-		free(dirp);
-	}
-}
-
-static inline void atomic_exchange(int *obj, int desired) {
-	__sync_synchronize();
-	__sync_lock_test_and_set(obj, desired);
-}
-
-#ifdef F_closedir
-int	closedir(DIR *dirp) {
-	if (!dirp) {
-		errno = EBADF;
-		return -1;
-	}
-
-	grab_dir(dirp);
-
-	int res = sceIoDclose(dirp->uid);
-
-	if (res < 0) {
-		errno = res & SCE_ERRNO_MASK;
-		drop_dir(dirp);
-		return -1;
-	}
-
-	release_drop_dir(dirp);
-
-	errno = 0;
-	return 0;
-}
-#endif
-
-#if F_opendir
-DIR *opendir(const char *dirname) {
-	SceUID uid = sceIoDopen(dirname);
-
-	if (uid < 0) {
-		errno = uid & SCE_ERRNO_MASK;
-		return NULL;
-	}
-
-	DIR *dirp = (DIR *)calloc(1, sizeof(DIR));
-
-	if (!dirp) {
-		sceIoDclose(uid);
-		errno = ENOMEM;
-		return NULL;
-	}
-
-	dirp->refcount = 1;
-	dirp->uid = uid;
-	dirp->dirname = strdup(dirname);
-	dirp->index = 0;
-
-	errno = 0;
-	return dirp;
-}
-#endif
-
-#ifdef F_readdir
-struct dirent *readdir(DIR *dirp) {
-	if (!dirp) {
-		errno = EBADF;
-		return NULL;
-	}
-
-	grab_dir(dirp);
-
-	int res = sceIoDread(dirp->uid, (SceIoDirent *)&dirp->dir);
-
-	if (res < 0) {
-		errno = res & SCE_ERRNO_MASK;
-		drop_dir(dirp);
-		return NULL;
-	}
-
-	if (res == 0) {
-		errno = 0;
-		drop_dir(dirp);
-		return NULL;
-	}
-
-	__sync_add_and_fetch(&dirp->index, 1);
-
-	struct dirent *dir = &dirp->dir;
-	drop_dir(dirp);
-	return dir;
-}
-#endif
-#ifdef F_readdir_r
-int	readdir_r(DIR *dirp, struct dirent *x, struct dirent **y) {
-	errno = ENOSYS;
-	return -1;
-}
-#endif
-
-#ifdef F_rewinddir
-void rewinddir(DIR *dirp) {
-	if (!dirp) {
-		errno = EBADF;
-		return;
-	}
-
-	grab_dir(dirp);
-
-	SceUID dirfd = sceIoDopen(dirp->dirname);
-
-	if (dirfd < 0) {
-		errno = dirfd & SCE_ERRNO_MASK;
-		drop_dir(dirp);
-		return;
-	}
-
-	sceIoDclose(dirp->uid);
-	atomic_exchange(&dirp->uid, dirfd);
-	atomic_exchange(&dirp->index, 0);
-
-	drop_dir(dirp);
-}
-#endif
-
-#ifdef F_seekdir
-void seekdir(DIR *dirp, long int index) {
-	if (!dirp) {
-		errno = EBADF;
-		return;
-	}
-
-	grab_dir(dirp);
-
-	if (index < dirp->index)
-		rewinddir(dirp);
-
-	if (index < dirp->index) {
-		drop_dir(dirp);
-		return;
-	}
-
-	while (index != dirp->index) {
-		if (!readdir(dirp)) {
-			errno = ENOENT;
-			drop_dir(dirp);
-			return;
-		}
-	}
-
-	drop_dir(dirp);
-}
-#endif
-
-#ifdef F_telldir
-long int telldir(DIR *dirp) {
-	if (!dirp) {
-		errno = EBADF;
-		return -1;
-	}
-
-	return dirp->index;
-}
-#endif
diff --git a/backends/fs/psp2/psp2-dirent.h b/backends/fs/psp2/psp2-dirent.h
deleted file mode 100644
index 0e56976404..0000000000
--- a/backends/fs/psp2/psp2-dirent.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
-
-Copyright (C) 2016, David "Davee" Morgan
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
-THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
-
-*/
-
-#ifndef _PSP2_DIRENT_H_
-#define	_PSP2_DIRENT_H_
-
-#include <sys/types.h>
-#include <sys/time.h>
-
-#include <psp2/io/dirent.h>
-
-#define F_opendir 1
-#define F_readdir 1
-#define F_closedir 1
-
-struct dirent
-{
-	/** File status. */
-	SceIoStat	d_stat;
-	/** File name. */
-	char	d_name[256];
-	/** Device-specific data. */
-	void	*d_private;
-	int	dummy;
-};
-
-struct DIR_;
-typedef struct DIR_ DIR;
-
-int            closedir(DIR *);
-DIR           *opendir(const char *);
-struct dirent *readdir(DIR *);
-int            readdir_r(DIR *, struct dirent *, struct dirent **);
-void           rewinddir(DIR *);
-void           seekdir(DIR *, long int);
-long int       telldir(DIR *);
-
-#endif /* _PSP2_DIRENT_H_ */
diff --git a/backends/fs/psp2/psp2-fs-factory.cpp b/backends/fs/psp2/psp2-fs-factory.cpp
deleted file mode 100644
index fcd7709803..0000000000
--- a/backends/fs/psp2/psp2-fs-factory.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "backends/fs/posix/posix-fs-factory.h"
-#include "backends/fs/posix/posix-fs.h"
-#include "backends/fs/psp2/psp2-fs-factory.h"
-
-AbstractFSNode *PSP2FilesystemFactory::makeRootFileNode() const {
-	return new POSIXFilesystemNode("/");
-}
-
-AbstractFSNode *PSP2FilesystemFactory::makeCurrentDirectoryFileNode() const {
-	return makeRootFileNode();
-}
-
-AbstractFSNode *PSP2FilesystemFactory::makeFileNodePath(const Common::String &path) const {
-	assert(!path.empty());
-	return new POSIXFilesystemNode(path);
-}
diff --git a/backends/fs/psp2/psp2-fs-factory.h b/backends/fs/psp2/psp2-fs-factory.h
deleted file mode 100644
index 3429b815ae..0000000000
--- a/backends/fs/psp2/psp2-fs-factory.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef PSP2_FILESYSTEM_FACTORY_H
-#define PSP2_FILESYSTEM_FACTORY_H
-
-#include "backends/fs/posix/posix-fs-factory.h"
-
-/**
- * Creates PSP2FilesystemFactory objects.
- *
- * Parts of this class are documented in the base interface class, FilesystemFactory.
- */
-
-class PSP2FilesystemFactory : public FilesystemFactory {
-protected:
-	virtual AbstractFSNode *makeRootFileNode() const;
-	virtual AbstractFSNode *makeCurrentDirectoryFileNode() const;
-	virtual AbstractFSNode *makeFileNodePath(const Common::String &path) const;
-};
-
-#endif /*PSP2_FILESYSTEM_FACTORY_H*/
diff --git a/backends/module.mk b/backends/module.mk
index c2228d96fe..0b2fe2a8e1 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -329,8 +329,8 @@ ifeq ($(BACKEND),psp2)
 MODULE_OBJS += \
 	fs/posix/posix-fs.o \
 	fs/posix/posix-iostream.o \
-	fs/psp2/psp2-fs-factory.o \
-	fs/psp2/psp2-dirent.o \
+	fs/posix-drives/posix-drives-fs.o \
+	fs/posix-drives/posix-drives-fs-factory.o \
 	events/psp2sdl/psp2sdl-events.o \
 	graphics/psp2sdl/psp2sdl-graphics.o
 endif
diff --git a/backends/platform/sdl/psp2/psp2.cpp b/backends/platform/sdl/psp2/psp2.cpp
index c815de5551..aa8e7a3519 100644
--- a/backends/platform/sdl/psp2/psp2.cpp
+++ b/backends/platform/sdl/psp2/psp2.cpp
@@ -30,13 +30,13 @@
 #include "backends/platform/sdl/psp2/psp2.h"
 #include "backends/graphics/psp2sdl/psp2sdl-graphics.h"
 #include "backends/saves/default/default-saves.h"
-
-#include "backends/fs/psp2/psp2-fs-factory.h"
+#include "backends/fs/posix-drives/posix-drives-fs-factory.h"
 #include "backends/events/psp2sdl/psp2sdl-events.h"
-#include "backends/fs/psp2/psp2-dirent.h"
 #include "backends/keymapper/hardware-input.h"
 #include <sys/stat.h>
 
+#include <psp2/io/stat.h>
+
 #ifdef __PSP2_DEBUG__
 #include <psp2shell.h>
 #endif
@@ -81,11 +81,16 @@ void OSystem_PSP2::init() {
 	gDebugLevel = 3;
 #endif
 
-	// Initialze File System Factory
+	// Initialize File System Factory
 	sceIoMkdir("ux0:data", 0755);
 	sceIoMkdir("ux0:data/scummvm", 0755);
 	sceIoMkdir("ux0:data/scummvm/saves", 0755);
-	_fsFactory = new PSP2FilesystemFactory();
+
+	DrivesPOSIXFilesystemFactory *fsFactory = new DrivesPOSIXFilesystemFactory();
+	fsFactory->addDrive("ux0:");
+	fsFactory->addDrive("uma0:");
+
+	_fsFactory = fsFactory;
 
 	// Invoke parent implementation of this method
 	OSystem_SDL::init();




More information about the Scummvm-git-logs mailing list