aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Bénony2015-12-01 18:53:52 +0100
committerVincent Bénony2016-01-06 15:35:17 +0100
commit108ce38443eda81032b72e81202237da53f922e8 (patch)
treef8c0865bb27ce8f42410dd152c69660ade82b8b1
parentcfa8d3bd8b7d624f4b04a02f1d42a89e2f3091c0 (diff)
downloadscummvm-rg350-108ce38443eda81032b72e81202237da53f922e8.tar.gz
scummvm-rg350-108ce38443eda81032b72e81202237da53f922e8.tar.bz2
scummvm-rg350-108ce38443eda81032b72e81202237da53f922e8.zip
IOS: Added a chroot like filesystem
This is needed because it is not possible to keep absolute paths to the iOS document directory, because a part of its name change between each installation / update.
-rw-r--r--backends/fs/chroot/chroot-fs-factory.cpp60
-rw-r--r--backends/fs/chroot/chroot-fs-factory.h41
-rw-r--r--backends/fs/chroot/chroot-fs.cpp111
-rw-r--r--backends/fs/chroot/chroot-fs.h54
-rw-r--r--backends/module.mk2
-rw-r--r--common/fs.h5
6 files changed, 271 insertions, 2 deletions
diff --git a/backends/fs/chroot/chroot-fs-factory.cpp b/backends/fs/chroot/chroot-fs-factory.cpp
new file mode 100644
index 0000000000..4030f4f502
--- /dev/null
+++ b/backends/fs/chroot/chroot-fs-factory.cpp
@@ -0,0 +1,60 @@
+/* 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.
+ *
+ */
+
+#if defined(POSIX)
+
+#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
+#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
+#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
+#define FORBIDDEN_SYMBOL_EXCEPTION_exit //Needed for IRIX's unistd.h
+
+#include "chroot-fs-factory.h"
+#include "backends/fs/chroot/chroot-fs.h"
+#include "backends/fs/posix/posix-fs-factory.h"
+
+ChRootFilesystemFactory::ChRootFilesystemFactory(Common::String root) {
+ _root = root;
+}
+
+AbstractFSNode *ChRootFilesystemFactory::makeRootFileNode() const {
+ return new ChRootFilesystemNode(_root, "/");
+}
+
+AbstractFSNode *ChRootFilesystemFactory::makeCurrentDirectoryFileNode() const {
+ char buf[MAXPATHLEN];
+ if (getcwd(buf, MAXPATHLEN) == NULL) {
+ return NULL;
+ }
+
+ if (Common::String(buf).hasPrefix(_root + Common::String("/"))) {
+ return new ChRootFilesystemNode(_root, buf + _root.size());
+ }
+
+ return new ChRootFilesystemNode(_root, "/");
+}
+
+AbstractFSNode *ChRootFilesystemFactory::makeFileNodePath(const Common::String &path) const {
+ assert(!path.empty());
+ return new ChRootFilesystemNode(_root, path);
+}
+
+#endif
diff --git a/backends/fs/chroot/chroot-fs-factory.h b/backends/fs/chroot/chroot-fs-factory.h
new file mode 100644
index 0000000000..2c05107b0f
--- /dev/null
+++ b/backends/fs/chroot/chroot-fs-factory.h
@@ -0,0 +1,41 @@
+/* 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 CHROOT_FS_FACTORY_H
+#define CHROOT_FS_FACTORY_H
+
+#include "backends/fs/fs-factory.h"
+
+class ChRootFilesystemFactory : public FilesystemFactory {
+private:
+ Common::String _root;
+
+protected:
+ virtual AbstractFSNode *makeRootFileNode() const;
+ virtual AbstractFSNode *makeCurrentDirectoryFileNode() const;
+ virtual AbstractFSNode *makeFileNodePath(const Common::String &path) const;
+
+public:
+ ChRootFilesystemFactory(Common::String root);
+};
+
+#endif /* CHROOT_FS_FACTORY_H */
diff --git a/backends/fs/chroot/chroot-fs.cpp b/backends/fs/chroot/chroot-fs.cpp
new file mode 100644
index 0000000000..1a2bc4c087
--- /dev/null
+++ b/backends/fs/chroot/chroot-fs.cpp
@@ -0,0 +1,111 @@
+/* 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.
+ *
+ */
+
+#if defined(POSIX)
+
+// Re-enable some forbidden symbols to avoid clashes with stat.h and unistd.h.
+// Also with clock() in sys/time.h in some Mac OS X SDKs.
+#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
+#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
+#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
+#define FORBIDDEN_SYMBOL_EXCEPTION_getenv
+#define FORBIDDEN_SYMBOL_EXCEPTION_exit //Needed for IRIX's unistd.h
+
+#include "backends/fs/chroot/chroot-fs.h"
+
+ChRootFilesystemNode::ChRootFilesystemNode(const Common::String &root, POSIXFilesystemNode *node) {
+ _root = Common::normalizePath(root, '/');
+ _realNode = node;
+}
+
+ChRootFilesystemNode::ChRootFilesystemNode(const Common::String &root, const Common::String &path) {
+ _root = Common::normalizePath(root, '/');
+ _realNode = new POSIXFilesystemNode(root.stringByAppendingPathComponent(path));
+}
+
+ChRootFilesystemNode::~ChRootFilesystemNode() {
+ delete _realNode;
+}
+
+bool ChRootFilesystemNode::exists() const {
+ return _realNode->exists();
+}
+
+Common::String ChRootFilesystemNode::getDisplayName() const {
+ return getName();
+}
+
+Common::String ChRootFilesystemNode::getName() const {
+ return _realNode->AbstractFSNode::getDisplayName();
+}
+
+Common::String ChRootFilesystemNode::getPath() const {
+ Common::String path = _realNode->getPath();
+ if (path.size() > _root.size()) {
+ return Common::String(path.c_str() + _root.size());
+ }
+ return Common::String("/");
+}
+
+bool ChRootFilesystemNode::isDirectory() const {
+ return _realNode->isDirectory();
+}
+
+bool ChRootFilesystemNode::isReadable() const {
+ return _realNode->isReadable();
+}
+
+bool ChRootFilesystemNode::isWritable() const {
+ return _realNode->isWritable();
+}
+
+AbstractFSNode *ChRootFilesystemNode::getChild(const Common::String &n) const {
+ return new ChRootFilesystemNode(_root, (POSIXFilesystemNode *) _realNode->getChild(n));
+}
+
+bool ChRootFilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool hidden) const {
+ AbstractFSList tmp;
+ if (!_realNode->getChildren(tmp, mode, hidden)) {
+ return false;
+ }
+
+ for (AbstractFSList::iterator i=tmp.begin(); i!=tmp.end(); ++i) {
+ list.push_back(new ChRootFilesystemNode(_root, (POSIXFilesystemNode *) *i));
+ }
+
+ return true;
+}
+
+AbstractFSNode *ChRootFilesystemNode::getParent() const {
+ if (getPath() == "/") return 0;
+ return new ChRootFilesystemNode(_root, (POSIXFilesystemNode *) _realNode->getParent());
+}
+
+Common::SeekableReadStream *ChRootFilesystemNode::createReadStream() {
+ return _realNode->createReadStream();
+}
+
+Common::WriteStream *ChRootFilesystemNode::createWriteStream() {
+ return _realNode->createWriteStream();
+}
+
+#endif
diff --git a/backends/fs/chroot/chroot-fs.h b/backends/fs/chroot/chroot-fs.h
new file mode 100644
index 0000000000..7dd62cb9a8
--- /dev/null
+++ b/backends/fs/chroot/chroot-fs.h
@@ -0,0 +1,54 @@
+/* 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 CHROOT_FS_H
+#define CHROOT_FS_H
+
+#include "backends/fs/posix/posix-fs.h"
+
+class ChRootFilesystemNode : public AbstractFSNode {
+ Common::String _root;
+ POSIXFilesystemNode *_realNode;
+
+ ChRootFilesystemNode(const Common::String &root, POSIXFilesystemNode *);
+
+public:
+ ChRootFilesystemNode(const Common::String &root, const Common::String &path);
+ virtual ~ChRootFilesystemNode();
+
+ virtual bool exists() const;
+ virtual Common::String getDisplayName() const;
+ virtual Common::String getName() const;
+ virtual Common::String getPath() const;
+ virtual bool isDirectory() const;
+ virtual bool isReadable() const;
+ virtual bool isWritable() const;
+
+ virtual AbstractFSNode *getChild(const Common::String &n) const;
+ virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const;
+ virtual AbstractFSNode *getParent() const;
+
+ virtual Common::SeekableReadStream *createReadStream();
+ virtual Common::WriteStream *createWriteStream();
+};
+
+#endif /* CHROOT_FS_H */
diff --git a/backends/module.mk b/backends/module.mk
index 7f2fb05489..d27e023012 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -90,6 +90,8 @@ ifdef POSIX
MODULE_OBJS += \
fs/posix/posix-fs.o \
fs/posix/posix-fs-factory.o \
+ fs/chroot/chroot-fs-factory.o \
+ fs/chroot/chroot-fs.o \
plugins/posix/posix-provider.o \
saves/posix/posix-saves.o \
taskbar/unity/unity-taskbar.o
diff --git a/common/fs.h b/common/fs.h
index b5b88ba8cb..e6f2fe18fe 100644
--- a/common/fs.h
+++ b/common/fs.h
@@ -58,10 +58,11 @@ class FSList : public Array<FSNode> {};
class FSNode : public ArchiveMember {
private:
SharedPtr<AbstractFSNode> _realNode;
- FSNode(AbstractFSNode *realNode);
public:
- /**
+ FSNode(AbstractFSNode *realNode);
+
+ /**
* Flag to tell listDir() which kind of files to list.
*/
enum ListMode {