aboutsummaryrefslogtreecommitdiff
path: root/backends/fs
diff options
context:
space:
mode:
authorCameron Cawley2019-11-09 18:30:21 +0000
committerCameron Cawley2019-11-09 18:30:21 +0000
commit48ab35f3589b27647279e51035581a6fee3c693d (patch)
treea55e220e3e7518b897fd3a355e12892f2e32ae12 /backends/fs
parent3544fe355ab8247101325264d92029e872ddc54c (diff)
downloadscummvm-rg350-48ab35f3589b27647279e51035581a6fee3c693d.tar.gz
scummvm-rg350-48ab35f3589b27647279e51035581a6fee3c693d.tar.bz2
scummvm-rg350-48ab35f3589b27647279e51035581a6fee3c693d.zip
RISCOS: Improve file system code
Diffstat (limited to 'backends/fs')
-rw-r--r--backends/fs/riscos/riscos-fs.cpp117
-rw-r--r--backends/fs/riscos/riscos-fs.h1
2 files changed, 66 insertions, 52 deletions
diff --git a/backends/fs/riscos/riscos-fs.cpp b/backends/fs/riscos/riscos-fs.cpp
index 338e7cfda5..5979ee4a5f 100644
--- a/backends/fs/riscos/riscos-fs.cpp
+++ b/backends/fs/riscos/riscos-fs.cpp
@@ -22,7 +22,6 @@
// Re-enable some forbidden symbols to avoid clashes with stat.h and unistd.h.
#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
-#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
#include "common/scummsys.h"
@@ -33,12 +32,9 @@
#include "backends/fs/stdiostream.h"
#include "common/algorithm.h"
-#include <limits.h>
-#include <stdio.h>
+// TODO: Replace use of access()
#include <unistd.h>
-#include <fcntl.h>
-#include <unixlib/local.h>
#include <kernel.h>
#include <swis.h>
@@ -55,11 +51,15 @@ bool RISCOSFilesystemNode::isWritable() const {
}
void RISCOSFilesystemNode::setFlags() {
- int type = _swi(OS_File, _INR(0,1)|_RETURN(0), 20, RISCOS_Utils::toRISCOS(_path).c_str());
- if (type == 0) {
+ _kernel_swi_regs regs;
+ regs.r[0] = 23;
+ regs.r[1] = (int)_nativePath.c_str();
+ _kernel_swi(OS_File, &regs, &regs);
+
+ if (regs.r[0] == 0) {
_isDirectory = false;
_isValid = false;
- } else if (type == 2) {
+ } else if (regs.r[0] == 2) {
_isDirectory = true;
_isValid = true;
} else {
@@ -71,9 +71,11 @@ void RISCOSFilesystemNode::setFlags() {
RISCOSFilesystemNode::RISCOSFilesystemNode(const Common::String &p) {
_path = p;
if (p == "/") {
+ _nativePath = "";
_isDirectory = true;
_isValid = true;
} else {
+ _nativePath = RISCOS_Utils::toRISCOS(p);
setFlags();
}
}
@@ -100,47 +102,60 @@ bool RISCOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bo
if (_path == "/") {
// Special case for the root dir: List all drives
- char fsname[PATH_MAX] = "";
+ char fsname[MAXPATHLEN] = "";
for (int fsNum = 0; fsNum < 256; fsNum += 1) {
- _swi(OS_FSControl, _INR(0,3), 33, fsNum, fsname, sizeof(fsname));
- if (strcmp(fsname, "") != 0) {
- if (!(fsNum == 46 || fsNum == 53 || fsNum == 99)) {
- int drives = 9;
- if (fsNum == 193)
- drives = 23;
-
- for (int discnum = 0; discnum <= drives; discnum += 1) {
- const Common::String path = Common::String::format("%s::%d.$", fsname, discnum);
- char outpath[PATH_MAX] = "";
- if(_swix(OS_FSControl, _INR(0,2)|_IN(5), 37, path.c_str(), outpath, sizeof(outpath)) == NULL) {
- int exist;
- if (_swix(OS_File, _INR(0,1)|_OUT(0), 23, outpath, &exist) != NULL || exist != 2)
- continue;
-
- RISCOSFilesystemNode *entry = new RISCOSFilesystemNode();
- entry->_isDirectory = true;
- entry->_isValid = true;
- entry->_path = Common::String::format("/%s", outpath);
- entry->_displayName = outpath;
- myList.push_back(entry);
- }
- }
- }
+ if (fsNum == 33 || fsNum == 46 || fsNum == 53 || fsNum == 99)
+ continue;
+
+ _kernel_swi_regs regs;
+ regs.r[0] = 33;
+ regs.r[1] = fsNum;
+ regs.r[2] = (int)fsname;
+ regs.r[3] = sizeof(fsname);
+ _kernel_swi(OS_FSControl, &regs, &regs);
+ if (fsname[0] == 0)
+ continue;
+
+ int drives = (fsNum == 193) ? 23 : 9;
+
+ for (int discnum = 0; discnum <= drives; discnum += 1) {
+ const Common::String path = Common::String::format("%s::%d.$", fsname, discnum);
+ char outpath[MAXPATHLEN] = "";
+ regs.r[0] = 37;
+ regs.r[1] = (int)path.c_str();
+ regs.r[2] = (int)outpath;
+ regs.r[3] = 0;
+ regs.r[4] = 0;
+ regs.r[5] = sizeof(outpath);
+ if (_kernel_swi(OS_FSControl, &regs, &regs) != NULL)
+ continue;
+
+ RISCOSFilesystemNode *entry = new RISCOSFilesystemNode();
+ entry->_nativePath = outpath;
+ entry->_path = Common::String('/') + outpath;
+ entry->_displayName = outpath;
+ entry->setFlags();
+ if (entry->_isDirectory)
+ myList.push_back(entry);
}
}
return true;
}
- int count = 0;
- int read = 0;
- char file[PATH_MAX];
- Common::String dir = _path;
-
- while (count != -1) {
- _swix(OS_GBPB, _INR(0,5)|_OUTR(3,4), 9, RISCOS_Utils::toRISCOS(dir).c_str(), file, 1, count, sizeof(file), &read, &count);
-
- if (count == -1)
- continue;
+ char file[MAXPATHLEN];
+ _kernel_swi_regs regs;
+ regs.r[0] = 9;
+ regs.r[1] = (int)_nativePath.c_str();
+ regs.r[2] = (int)file;
+ regs.r[3] = 1;
+ regs.r[4] = 0;
+ regs.r[5] = sizeof(file);
+ regs.r[6] = 0;
+ while (regs.r[4] != -1) {
+ _kernel_swi(OS_GBPB, &regs, &regs);
+
+ if (regs.r[4] == -1)
+ break;
// Start with a clone of this node, with the correct path set
RISCOSFilesystemNode entry(*this);
@@ -149,15 +164,10 @@ bool RISCOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bo
if (_path.lastChar() != '/')
entry._path += '/';
entry._path += entry._displayName;
-
- int type = _swi(OS_File, _INR(0,1)|_RETURN(0), 20, RISCOS_Utils::toRISCOS(entry._path).c_str());
- if (type == 0) {
+ entry._nativePath = RISCOS_Utils::toRISCOS(entry._path);
+ entry.setFlags();
+ if (!entry._isValid)
continue;
- } else if (type == 2) {
- entry._isDirectory = true;
- } else {
- entry._isDirectory = false;
- }
// Honor the chosen mode
if ((mode == Common::FSNode::kListFilesOnly && entry._isDirectory) ||
@@ -205,7 +215,10 @@ Common::WriteStream *RISCOSFilesystemNode::createWriteStream() {
}
bool RISCOSFilesystemNode::createDirectory() {
- if (_swix(OS_File, _INR(0,1), 8, RISCOS_Utils::toRISCOS(_path).c_str()) == NULL)
+ _kernel_swi_regs regs;
+ regs.r[0] = 8;
+ regs.r[1] = (int)_nativePath.c_str();
+ if (_kernel_swi(OS_File, &regs, &regs) == NULL)
setFlags();
return _isValid && _isDirectory;
diff --git a/backends/fs/riscos/riscos-fs.h b/backends/fs/riscos/riscos-fs.h
index f068022a9e..e3640e57ca 100644
--- a/backends/fs/riscos/riscos-fs.h
+++ b/backends/fs/riscos/riscos-fs.h
@@ -33,6 +33,7 @@
class RISCOSFilesystemNode : public AbstractFSNode {
protected:
Common::String _displayName;
+ Common::String _nativePath;
Common::String _path;
bool _isDirectory;
bool _isValid;