bool Ps2ReadFile::open(const char *name) { assert(_fd < 0); _fd = fio.open(name, O_RDONLY); if (_fd >= 0) { _fileSize = fio.seek(_fd, 0, SEEK_END); fio.seek(_fd, 0, SEEK_SET); return true; } else return false; }
bool Ps2File::open(const char *name, int mode) { #if 1 _fd = fio.open(name, mode); dbg_printf("open %s [%d]\n", name, _fd); if (_fd >= 0) { _mode = mode; _filePos = 0; if (_mode == O_RDONLY) { _fileSize = fio.seek(_fd, 0, SEEK_END); fio.seek(_fd, 0, SEEK_SET); } else _fileSize = 0; dbg_printf(" _mode = %x\n", _mode); dbg_printf(" _fileSize = %d\n", _fileSize); // dbg_printf(" _filePos = %d\n", _filePos); return true; } return false; #else uint32 r; // hack: FIO does not reports size for RW (?) _fd = fio.open(name, O_RDONLY); if (_fd >= 0) { _fileSize = fio.seek(_fd, 0, SEEK_END); fio.seek(_fd, 0, SEEK_SET); /* rewind ! */ if (_fileSize && mode != O_RDONLY) { fio.read(_fd, _cacheBuf, _fileSize); r = fio.sync(_fd); dbg_printf(" sz=%d, read=%d\n", _fileSize, r); assert(r == _fileSize); } fio.close(_fd); } else _fileSize = 0; /* new file */ _fd = fio.open(name, mode); dbg_printf("open %s [%d]\n", name, _fd); if (_fd >= 0) { _mode = mode; _filePos = 0; if (_fileSize) { /* existing data */ if (mode == O_RDONLY) { /* DANGER: for w* modes it will truncate your fine files */ fio.seek(_fd, 0, SEEK_SET); } else if (_mode & O_APPEND) { fio.seek(_fd, 0, _fileSize); _filePos = _fileSize; } #if 0 /* file already trunc'd when opened as w* -> moved up */ if (mode != O_RDONLY) { fio.read(_fd, _cacheBuf, _fileSize); r = fio.sync(_fd); dbg_printf(" sz=%d, read=%d\n", _fileSize, r); assert(r == _fileSize); // _fileSize = fio.seek(_fd, 0, SEEK_END); } #endif } dbg_printf(" _mode = %x\n", _mode); dbg_printf(" _fileSize = %d\n", _fileSize); dbg_printf(" _filePos = %d\n", _filePos); return true; } else return false; #endif }
void Ps2FilesystemNode::doverify(void) { PS2Device medium; int fd; if (_verified) return; _verified = true; dbg_printf(" verify: %s -> ", _path.c_str()); #if 0 if (_path.empty()) { dbg_printf("PlayStation 2 Root !\n"); _verified = true; return; } if (_path.lastChar() == ':') { dbg_printf("Dev: %s\n", _path.c_str()); _verified = true; return; } #endif if (_path[3] != ':' && _path[4] != ':') { dbg_printf("relative path !\n"); _isHere = false; _isDirectory = false; return; } medium = _getDev(_path); if (medium == ERR_DEV) { _isHere = false; _isDirectory = false; return; } switch (medium) { #if 0 case HD_DEV: /*stat*/ case USB_DEV: iox_stat_t stat; fileXioGetStat(_path.c_str(), &stat); fileXioWaitAsync(FXIO_WAIT, &fd); if (!fd) { dbg_printf(" yes [stat]\n"); return true; } break; #endif case CD_DEV: /*no stat*/ case HD_DEV: case USB_DEV: case HOST_DEV: case MC_DEV: #if 1 fd = fio.open(_path.c_str(), O_RDONLY); dbg_printf("_path = %s -- fio.open -> %d\n", _path.c_str(), fd); if (fd >=0) { fio.close(fd); dbg_printf(" yes [open]\n"); _isHere = true; if (medium==MC_DEV && _path.lastChar()=='/') _isDirectory = true; else _isDirectory = false; return; } fd = fio.dopen(_path.c_str()); if (fd >=0) { fio.dclose(fd); dbg_printf(" yes [dopen]\n"); _isHere = true; _isDirectory = true; return; } #else fileXioOpen(_path.c_str(), O_RDONLY, DEFAULT_MODE); fileXioWaitAsync(FXIO_WAIT, &fd); if (fd>=0) { fileXioClose(fd); fileXioWaitAsync(FXIO_WAIT, &fd); return true; } fileXioDopen(_path.c_str()); fileXioWaitAsync(FXIO_WAIT, &fd); if (fd>=0) { fileXioDclose(fd); fileXioWaitAsync(FXIO_WAIT, &fd); return true; } #endif break; case ERR_DEV: _isHere = false; _isDirectory = false; break; } _isHere = false; _isDirectory = false; dbg_printf(" no\n"); return; }
bool Ps2WriteFile::open(const char *name) { _fd = fio.open(name, O_WRONLY | O_CREAT | O_TRUNC); return (_fd >= 0); }