From 7c9e56cea427fb98d84056482f801c4d5264f40e Mon Sep 17 00:00:00 2001 From: Fritz Elfert Date: Mon, 28 Jun 1999 23:50:21 +0000 Subject: More work. --- plpnfsd/Makefile.am | 2 +- plpnfsd/main.cc | 125 +++++--- plpnfsd/mp_main.c | 2 +- plpnfsd/mp_mount.c | 26 +- plpnfsd/mp_pfs_ops.c | 30 +- plpnfsd/rfsv32.cc | 889 --------------------------------------------------- plpnfsd/rfsv32.h | 172 ---------- plpnfsd/rfsv_api.h | 2 + 8 files changed, 108 insertions(+), 1140 deletions(-) delete mode 100644 plpnfsd/rfsv32.cc delete mode 100644 plpnfsd/rfsv32.h (limited to 'plpnfsd') diff --git a/plpnfsd/Makefile.am b/plpnfsd/Makefile.am index 8ebc662..83e0b78 100644 --- a/plpnfsd/Makefile.am +++ b/plpnfsd/Makefile.am @@ -4,6 +4,6 @@ LIBS=../lib/libutils.a sbin_PROGRAMS = plpnfsd plpnfsd_SOURCES = mp_main.c mp_mount.c nfs_prot_svc.c nfs_prot_xdr.c \ - mp_pfs_ops.c mp_inode.c rfsv32.cc main.cc + mp_pfs_ops.c mp_inode.c main.cc EXTRA_plpnfsd_SOURCES = mount_aix.c diff --git a/plpnfsd/main.cc b/plpnfsd/main.cc index 6dc472b..c20b24d 100644 --- a/plpnfsd/main.cc +++ b/plpnfsd/main.cc @@ -34,13 +34,21 @@ extern "C" { #include "rfsv_api.h" } -static rfsv32 *a; +static rfsv32 *a = 0L; +static ppsocket *skt = 0L; + +long rfsv_isalive() { + if (!a) + return 0; + return (a->getStatus() == 0); +} long rfsv_dir(const char *file, dentry **e) { + if (!a) + return -1; bufferArray entries; dentry *tmp; long ret = a->dir(&(*file), &entries); - psion_alive = (a->getStatus() == 0); while (!entries.empty()) { bufferStore s; s = entries.popBuffer(); @@ -58,113 +66,121 @@ long rfsv_dir(const char *file, dentry **e) { } long rfsv_dircount(const char *file, long *count) { - long ret = a->dircount(&(*file), &(*count)); - psion_alive = (a->getStatus() == 0); - return ret; + if (!a) + return -1; + return a->dircount(&(*file), &(*count)); } long rfsv_rmdir(const char *name) { - long ret = a->rmdir(name); - psion_alive = (a->getStatus() == 0); - return ret; + if (!a) + return -1; + return a->rmdir(name); } long rfsv_mkdir(const char *file) { - long ret = a->mkdir(file); - psion_alive = (a->getStatus() == 0); - return ret; + if (!a) + return -1; + return a->mkdir(file); } long rfsv_remove(const char *file) { - long ret = a->remove(file); - psion_alive = (a->getStatus() == 0); - return ret; + if (!a) + return -1; + return a->remove(file); } long rfsv_fclose(long handle) { - long ret = a->fclose(handle); - psion_alive = (a->getStatus() == 0); - return ret; + if (!a) + return -1; + return a->fclose(handle); } long rfsv_fopen(long attr, const char *file, long *handle) { + if (!a) + return -1; long ph; long ret = a->fopen(attr, file, ph); *handle = ph; - psion_alive = (a->getStatus() == 0); return ret; } long rfsv_fcreate(long attr, const char *file, long *handle) { + if (!a) + return -1; long ph; long ret = a->fcreatefile(attr, file, ph); *handle = ph; - psion_alive = (a->getStatus() == 0); return ret; } long rfsv_read(char *buf, long offset, long len, long handle) { + if (!a) + return -1; long ret = a->fseek(handle, offset, rfsv32::PSEEK_SET); if (ret >= 0) ret = a->fread(handle, buf, len); - psion_alive = (a->getStatus() == 0); return ret; } long rfsv_write(char *buf, long offset, long len, long handle) { + if (!a) + return -1; long ret = a->fseek(handle, offset, rfsv32::PSEEK_SET); if (ret >= 0) ret = a->fwrite(handle, buf, len); - psion_alive = (a->getStatus() == 0); return ret; } long rfsv_setmtime(const char *name, long time) { - long ret = a->fsetmtime(name, time); - psion_alive = (a->getStatus() == 0); - return ret; + if (!a) + return -1; + return a->fsetmtime(name, time); } long rfsv_setsize(const char *name, long size) { + if (!a) + return -1; long ph; long ret = a->fopen(0x200, name, ph); if (!ret) { ret = a->fsetsize(ph, size); a->fclose(ph); } - psion_alive = (a->getStatus() == 0); return ret; } long rfsv_setattr(const char *name, long sattr, long dattr) { - long ret = a->fsetattr(name, dattr, sattr); - psion_alive = (a->getStatus() == 0); - return ret; + if (!a) + return -1; + return a->fsetattr(name, dattr, sattr); } long rfsv_getattr(const char *name, long *attr, long *size, long *time) { - long ret = a->fgeteattr(&(*name), &(*attr), &(*size), &(*time)); - psion_alive = (a->getStatus() == 0); - return ret; + if (!a) + return -1; + return a->fgeteattr(&(*name), &(*attr), &(*size), &(*time)); } long rfsv_statdev(char letter) { + if (!a) + return -1; long vfree, vtotal, vattr, vuniqueid; int devnum = letter - 'A'; char *name; name = a->devinfo(devnum, &vfree, &vtotal, &vattr, &vuniqueid); - psion_alive = (a->getStatus() == 0); return (name == NULL); } long rfsv_rename(const char *oldname, const char *newname) { - long ret = a->rename(oldname, newname); - psion_alive = (a->getStatus() == 0); - return ret; + if (!a) + return -1; + return a->rename(oldname, newname); } long rfsv_drivelist(int *cnt, device **dlist) { + if (!a) + return -1; *dlist = NULL; long devbits; long ret; @@ -190,26 +206,29 @@ long rfsv_drivelist(int *cnt, device **dlist) { } devbits >>= 1; } - psion_alive = (a->getStatus() == 0); return ret; } +void rfsv_startup() +{ + bool res; + + if (a) { + delete a; + a = 0L; + } + if (skt) { + delete skt; + skt = 0L; + } + skt = new ppsocket(); + skt->startup(); + res = skt->connect(NULL, DEFAULT_SOCKET); + a = new rfsv32(skt); +} + int main(int argc, char**argv) { - ppsocket *skt; - bool res; - - // Command line parameter processing - int sockNum = DEFAULT_SOCKET; - - skt = new ppsocket(); - skt->startup(); - res = skt->connect(NULL, sockNum); - - a = new rfsv32(skt); - - char *mp_args[] = { "mp_main", "-v", "-dir", "/mnt/psion", NULL }; - mp_main(4, mp_args); - - delete a; - return 0; + char *mp_args[] = { "mp_main", "-v", "-dir", "/mnt/psion", NULL }; + mp_main(4, mp_args); + return 0; } diff --git a/plpnfsd/mp_main.c b/plpnfsd/mp_main.c index 1bac5fe..e1dabb2 100644 --- a/plpnfsd/mp_main.c +++ b/plpnfsd/mp_main.c @@ -27,7 +27,7 @@ extern void nfs_program_2(); static char *user, *dir = DDIR; -int gmtoffset, debug, exiting, psion_alive, query_cache = 0; +int gmtoffset, debug, exiting, query_cache = 0; fattr root_fattr = { diff --git a/plpnfsd/mp_mount.c b/plpnfsd/mp_mount.c index d13dea5..e58a3e0 100644 --- a/plpnfsd/mp_mount.c +++ b/plpnfsd/mp_mount.c @@ -14,7 +14,6 @@ extern int inet_addr(char *); #include #include - #ifdef __sgi #include #endif @@ -94,7 +93,7 @@ extern int _rpc_dtablesize(); #include #include -#include "mp.h" +#include "rfsv_api.h" #ifdef __sgi #define vfork fork @@ -588,13 +587,22 @@ mount_and_run(char *dir, void (*proc)(), nfs_fh *root_fh) clean_cache(&attrcache); query_cache = 0; /* clear the GETDENTS "cache". */ } - ret = 1 /* FRITZ fd_is_still_alive(psionfd, 0) */ ; - if (isalive && !ret) { - if (debug) - printf("Disconnected...\n"); - } else if (!isalive && ret) { - if (debug) - printf("Connected...\n"); + ret = rfsv_isalive(); + if (isalive) { + if (!ret) { + if (debug) + printf("Disconnected...\n"); + rfsv_startup(); + } + } else { + if (ret) { + if (debug) + printf("Connected...\n"); + } else { + if (debug) + printf("Try connecting...\n"); + rfsv_startup(); + } } isalive = ret; } diff --git a/plpnfsd/mp_pfs_ops.c b/plpnfsd/mp_pfs_ops.c index 9b4d6f5..0967587 100644 --- a/plpnfsd/mp_pfs_ops.c +++ b/plpnfsd/mp_pfs_ops.c @@ -46,7 +46,7 @@ create_it(createargs *ca, int isdir) rfsv_ret = rfsv_fclose(phandle); } if (rfsv_ret) { - res.status = psion_alive ? NFSERR_NAMETOOLONG : NO_PSION; + res.status = rfsv_isalive() ? NFSERR_NAMETOOLONG : NO_PSION; return &res; } inode = get_nam(name); @@ -304,7 +304,7 @@ nfsproc_getattr_2(struct nfs_fh *fh) *fp = cp->attr; /* gotcha */ if (fp->type == NFDIR) { if (mp_dircount(inode, &dcount)) { - res.status = psion_alive ? NFSERR_NOENT : NO_PSION; + res.status = rfsv_isalive() ? NFSERR_NOENT : NO_PSION; return &res; } if (fp->nlink != (dcount + 2)) @@ -348,7 +348,7 @@ nfsproc_getattr_2(struct nfs_fh *fh) fp->mode |= 0200; fp->fileid = inode->inode; if (mp_dircount(inode, &dcount)) { - res.status = psion_alive ? NFSERR_NOENT : NO_PSION; + res.status = rfsv_isalive() ? NFSERR_NOENT : NO_PSION; return &res; } if (fp->nlink != (dcount + 2)) @@ -361,13 +361,13 @@ nfsproc_getattr_2(struct nfs_fh *fh) printf("\tgetattr:fileordir\n"); /* It's a normal file/dir */ if (rfsv_getattr(inode->name, &pattr, &psize, &ptime)) { - res.status = psion_alive ? NFSERR_NOENT : NO_PSION; + res.status = rfsv_isalive() ? NFSERR_NOENT : NO_PSION; return &res; } pattr2attr(pattr, psize, ptime, fp, (unsigned char *) fh->data); if (fp->type == NFDIR) { if (mp_dircount(inode, &dcount)) { - res.status = psion_alive ? NFSERR_NOENT : NO_PSION; + res.status = rfsv_isalive() ? NFSERR_NOENT : NO_PSION; return &res; } if (fp->nlink != (dcount + 2)) @@ -525,7 +525,7 @@ nfsproc_readdir_2(readdirargs *ra) if (debug) printf("\tnfsdir: dir\n"); if (rfsv_dir(dirname(inode->name), &e)) { - res.status = psion_alive ? NFSERR_NOENT : NO_PSION; + res.status = rfsv_isalive() ? NFSERR_NOENT : NO_PSION; return &res; } while (e) { @@ -576,7 +576,7 @@ nfsproc_setattr_2(sattrargs *sa) if (debug) printf("\t\tsetattr truncating to %d bytes\n", sa->attributes.size); if (rfsv_setsize(inode->name, sa->attributes.size) != 0) { - res.status = psion_alive ? NFSERR_ROFS : NO_PSION; + res.status = rfsv_isalive() ? NFSERR_ROFS : NO_PSION; return &res; } fp->size = sa->attributes.size; @@ -586,7 +586,7 @@ nfsproc_setattr_2(sattrargs *sa) if ((sa->attributes.mtime.seconds != fp->mtime.seconds) && (sa->attributes.mtime.seconds != -1)) { if (rfsv_setmtime(inode->name, sa->attributes.mtime.seconds)) { - res.status = (psion_alive) ? NFSERR_ACCES : NO_PSION; + res.status = (rfsv_isalive()) ? NFSERR_ACCES : NO_PSION; return &res; } fp->mtime.seconds = fp->atime.seconds = sa->attributes.mtime.seconds; @@ -598,7 +598,7 @@ nfsproc_setattr_2(sattrargs *sa) long psisattr, psidattr; attr2pattr(sa->attributes.mode, fp->mode, &psisattr, &psidattr); if (rfsv_setattr(inode->name, psisattr, psidattr)) { - res.status = (psion_alive) ? NFSERR_ACCES : NO_PSION; + res.status = (rfsv_isalive()) ? NFSERR_ACCES : NO_PSION; return &res; } fp->mode = sa->attributes.mode; @@ -630,7 +630,7 @@ remove_it(diropargs *da, int isdir) else rfsv_res = rfsv_remove(build_path(inode->name, da->name)); if (rfsv_res != 0) { - res = psion_alive ? NFSERR_ACCES : NO_PSION; + res = rfsv_isalive() ? NFSERR_ACCES : NO_PSION; return &res; } rem_cache(&attrcache, inode->inode); @@ -673,7 +673,7 @@ nfsproc_rename_2(renameargs *ra) printf("\tRename: %s -> %s\n", old, ldata + 1); res = NFS_OK; if (rfsv_rename(old, ldata + 1)) { - res = (psion_alive) ? NFSERR_ACCES : NO_PSION; + res = (rfsv_isalive()) ? NFSERR_ACCES : NO_PSION; return &res; } if (res == NFS_OK) { @@ -705,7 +705,7 @@ nfsproc_statfs_2(struct nfs_fh *fh) if (query_devices()) { /* Allow to mount it whithout the psion attached */ - if (psion_alive) + if (rfsv_isalive()) return &res; /* res.status = NO_PSION; Hmm */ } for (dp = devices; dp; dp = dp->next) { @@ -763,7 +763,7 @@ nfsproc_read_2(struct readargs *ra) return &res; } if (rfsv_fopen(1, inode->name, &phandle) != 0) { - res.status = psion_alive ? NFSERR_NOENT : NO_PSION; + res.status = rfsv_isalive() ? NFSERR_NOENT : NO_PSION; return &res; } if (rfsv_read(rop, ra->offset, @@ -940,14 +940,14 @@ nfsproc_write_2(writeargs *wa) if (rfsv_fopen(0x200, inode->name, &phandle) != 0) { if (debug) printf("write: open failed\n"); - res.status = psion_alive ? NFSERR_NOSPC : NO_PSION; + res.status = rfsv_isalive() ? NFSERR_NOSPC : NO_PSION; return &res; } if (rfsv_write(dcp->data, dcp->offset, dcp->len, phandle) != dcp->len) { rfsv_fclose(phandle); if (debug) printf("write: dump failed\n"); - res.status = psion_alive ? NFSERR_NOSPC : NO_PSION; + res.status = rfsv_isalive() ? NFSERR_NOSPC : NO_PSION; return &res; } rfsv_fclose(phandle); diff --git a/plpnfsd/rfsv32.cc b/plpnfsd/rfsv32.cc deleted file mode 100644 index b6105c5..0000000 --- a/plpnfsd/rfsv32.cc +++ /dev/null @@ -1,889 +0,0 @@ -// -// PLP - An implementation of the PSION link protocol -// -// Copyright (C) 1999 Philip Proudman -// -// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// e-mail philip.proudman@btinternet.com - -#include -#include -#include -#include -#include -#include - -#include "bool.h" -#include "bool.h" -#include "rfsv32.h" -#include "bufferstore.h" -#include "ppsocket.h" -#include "../defaults.h" -#include "bufferarray.h" - -rfsv32::rfsv32(ppsocket * _skt) : serNum(0) -{ - skt = _skt; - bufferStore a; - status = DISCONNECTED; - a.addStringT(getConnectName()); - if (skt->sendBufferStore(a)) { - if (skt->getBufferStore(a) == 1) { - if (strcmp(a.getString(0), "Ok")) - cerr << "Not got ok over socket\n"; - else - status = NONE; - } - } -} - -rfsv32::~rfsv32() -{ - bufferStore a; - a.addStringT("Close"); - if (status == NONE) - skt->sendBufferStore(a); - skt->closeSocket(); -} - -long rfsv32:: -getStatus() -{ - return status; -} - -const char *rfsv32:: -getConnectName() -{ - return "SYS$RFSV.*"; -} - -void rfsv32:: -convertSlash(const char *name) -{ - for (char *p = (char *)name; *p; p++) - if (*p == '/') - *p = '\\'; -} - -long rfsv32:: -fopen(long attr, const char *name, long &handle) -{ - bufferStore a; - a.addDWord(attr); - convertSlash(name); - a.addWord(strlen(name)); - a.addString(name); - sendCommand(OPEN_FILE, a); - - long res = getResponse(a); - if (!res && a.getLen() == 4) { - handle = a.getDWord(0); - return 0; - } - return res; -} - -long rfsv32:: -mktemp(long *handle, char *tmpname) -{ - bufferStore a; - sendCommand(TEMP_FILE, a); - long res = getResponse(a); - if (res == 0) { - *handle = a.getDWord(0); - strcpy(tmpname, a.getString(6)); - } - return res; -} - -long rfsv32:: -fcreatefile(long attr, const char *name, long &handle) -{ - bufferStore a; - a.addDWord(attr); - convertSlash(name); - a.addWord(strlen(name)); - a.addString(name); - sendCommand(CREATE_FILE, a); - long res = getResponse(a); - if (!res && a.getLen() == 4) - handle = a.getDWord(0); - return res; -} - -long rfsv32:: -freplacefile(long attr, const char *name, long &handle) -{ - bufferStore a; - convertSlash(name); - a.addDWord(attr); - a.addWord(strlen(name)); - a.addString(name); - sendCommand(REPLACE_FILE, a); - long res = getResponse(a); - if (!res && a.getLen() == 4) - handle = a.getDWord(0); - return res; -} - -long rfsv32:: -fopendir(long attr, const char *name, long &handle) -{ - bufferStore a; - convertSlash(name); - a.addDWord(attr); - a.addWord(strlen(name)); - a.addString(name); - sendCommand(OPEN_DIR, a); - long res = getResponse(a); - if (!res && a.getLen() == 4) - handle = a.getDWord(0); - return res; -} - -long rfsv32:: -fclose(long handle) -{ - bufferStore a; - a.addDWord(handle); - sendCommand(CLOSE_HANDLE, a); - return getResponse(a); -} - -/* Microseconds since 1.1.1980 00:00:00 */ -#define PSI_EPOCH_SECS8 0x0e8c52f4 -#define EPOCH_2H 7200 -#define EPOCH_DIFF_SECS (3652 * 24 * 60 * 60) - -unsigned long rfsv32:: -micro2time(unsigned long microHi, unsigned long microLo) -{ - unsigned long long micro = microHi; - unsigned long long pes = PSI_EPOCH_SECS8; - pes <<= 8; - micro <<= 32; - micro += microLo; - micro /= 1000000; - micro -= pes; - micro += EPOCH_DIFF_SECS; - micro -= EPOCH_2H; - return (long) micro; -} - -void rfsv32:: -time2micro(unsigned long time, unsigned long µHi, unsigned long µLo) -{ - unsigned long long micro = (unsigned long long)time; - unsigned long long pes = PSI_EPOCH_SECS8; - pes <<= 8; - micro += pes; - micro -= EPOCH_DIFF_SECS; - micro += EPOCH_2H; - micro *= (unsigned long long)1000000; - microLo = (micro & (unsigned long long)0x0FFFFFFFF); - micro >>= 32; - microHi = (micro & (unsigned long long)0x0FFFFFFFF); -} - -long rfsv32:: -dir(const char *name, bufferArray * files) -{ - long handle; - long res = fopendir(HIDDEN | SYSTEM | DIRECTORY, name, handle); - if (res != 0) - return res; - - while (1) { - bufferStore a; - a.addDWord(handle); - sendCommand(READ_DIR, a); - res = getResponse(a); - if (res) - break; - while (a.getLen() > 16) { - long shortLen = a.getDWord(0); - long attributes = a.getDWord(4); - long size = a.getDWord(8); - unsigned long modLow = a.getDWord(12); - unsigned long modHi = a.getDWord(16); - // long uid1 = a.getDWord(20); - // long uid2 = a.getDWord(24); - // long uid3 = a.getDWord(28); - long longLen = a.getDWord(32); - - long date = micro2time(modHi, modLow); - - bufferStore s; - if (!files) { - char dateBuff[100]; - struct tm *t; - t = localtime(&date); - strftime(dateBuff, 100, "%c", t); - cout << ((attributes & DIRECTORY) ? "d" : "-"); - cout << ((attributes & READ_ONLY) ? "-" : "w"); - cout << ((attributes & HIDDEN) ? "h" : "-"); - cout << ((attributes & SYSTEM) ? "s" : "-"); - cout << ((attributes & ARCHIVE) ? "a" : "-"); - cout << ((attributes & VOLUME) ? "v" : "-"); - cout << ((attributes & NORMAL) ? "n" : "-"); - cout << ((attributes & TEMPORARY) ? "t" : "-"); - cout << ((attributes & COMPRESSED) ? "c" : "-"); - cout << " " << dec << setw(10) << setfill(' ') << size; - cout << " " << dateBuff; - } else { - s.addDWord(date); - s.addDWord(size); - s.addDWord(attributes); - } - int d = 36; - for (int i = 0; i < longLen; i++, d++) - s.addByte(a.getByte(d)); - s.addByte(0); - while (d % 4) - d++; - if (!files) - cout << " " << s.getString() << endl; - else /* if ((attributes & DIRECTORY) == 0) */ - files->pushBuffer(s); - d += shortLen; - while (d % 4) - d++; - a.discardFirstBytes(d); - } - } - if (res == EoF) - res = 0; - fclose(handle); - return res; -} - -long rfsv32:: -fgetmtime(const char *name, long *mtime) -{ - bufferStore a; - convertSlash(name); - a.addWord(strlen(name)); - a.addString(name); - sendCommand(MODIFIED, a); - long res = getResponse(a); - if (res != 0) - return res; - *mtime = micro2time(a.getDWord(4), a.getDWord(0)); - return 0; -} - -long rfsv32:: -fsetmtime(const char *name, long mtime) -{ - bufferStore a; - unsigned long microLo, microHi; - time2micro(mtime, microHi, microLo); - convertSlash(name); - a.addDWord(microLo); - a.addDWord(microHi); - a.addWord(strlen(name)); - a.addString(name); - sendCommand(SET_MODIFIED, a); - long res = getResponse(a); - if (res != 0) - return res; - return 0; -} - -long rfsv32:: -fgetattr(const char *name, long *attr) -{ - bufferStore a; - convertSlash(name); - a.addWord(strlen(name)); - a.addString(name); - sendCommand(ATT, a); - long res = getResponse(a); - if (res != 0) - return res; - *attr = a.getDWord(0); - return 0; -} - -long rfsv32:: -fgeteattr(const char *name, long *attr, long *size, long *time) -{ - bufferStore a; - convertSlash(name); - a.addWord(strlen(name)); - a.addString(name); - sendCommand(REMOTE_ENTRY, a); - long res = getResponse(a); - if (res != 0) - return res; - // long shortLen = a.getDWord(0); - *attr = a.getDWord(4); - *size = a.getDWord(8); - unsigned long modLow = a.getDWord(12); - unsigned long modHi = a.getDWord(16); - // long uid1 = a.getDWord(20); - // long uid2 = a.getDWord(24); - // long uid3 = a.getDWord(28); - // long longLen = a.getDWord(32); - *time = micro2time(modHi, modLow); - return 0; -} - -long rfsv32:: -fsetattr(const char *name, long seta, long unseta) -{ - bufferStore a; - convertSlash(name); - a.addDWord(seta); - a.addDWord(unseta); - a.addWord(strlen(name)); - a.addString(name); - sendCommand(SET_ATT, a); - return getResponse(a); -} - -long rfsv32:: -dircount(const char *name, long *count) -{ - long handle; - convertSlash(name); - long res = fopendir(HIDDEN | SYSTEM | DIRECTORY, name, handle); - *count = 0; - if (res != 0) - return res; - - while (1) { - bufferStore a; - a.addDWord(handle); - sendCommand(READ_DIR, a); - res = getResponse(a); - if (res) - break; - while (a.getLen() > 16) { - int d = 36 + a.getDWord(32); - while (d % 4) - d++; - d += a.getDWord(0); - while (d % 4) - d++; - a.discardFirstBytes(d); - (*count)++; - } - } - fclose(handle); - if (res == EoF) - res = 0; - return res; -} - -long rfsv32:: -devlist(long *devbits) -{ - bufferStore a; - long res; - - sendCommand(GET_DRIVE_LIST, a); - res = getResponse(a); - *devbits = 0; - if ((res == 0) && (a.getLen() == 26)) { - for (int i = 25; i >= 0; i--) { - *devbits <<= 1; - if (a.getByte(i) != 0) - *devbits |= 1; - } - } - return res; -} - -char *rfsv32:: -devinfo(int devnum, long *vfree, long *vtotal, long *vattr, - long *vuniqueid) -{ - bufferStore a; - long res; - - a.addDWord(devnum); - sendCommand(DRIVE_INFO, a); - res = getResponse(a); - if (res == 0) { - *vattr = a.getDWord(0); - *vuniqueid = a.getDWord(16); - *vtotal = a.getDWord(20); - *vfree = a.getDWord(28); - // vnamelen = a.getDWord(36); - a.addByte(0); - return (strdup(a.getString(40))); - } - return NULL; -} - -bool rfsv32:: -sendCommand(enum commands cc, bufferStore & data) -{ - bufferStore a; - a.addWord(cc); - a.addWord(serNum); - if (serNum < 0xffff) - serNum++; - else - serNum = 0; - a.addBuff(data); - return skt->sendBufferStore(a); -} - -long rfsv32:: -getResponse(bufferStore & data) -{ - if (skt->getBufferStore(data) == 1 && - data.getWord(0) == 0x11) { - long ret = data.getDWord(4); - data.discardFirstBytes(8); - return ret; - } else - status = DISCONNECTED; - return (enum errs) GENERAL; -} - -char * rfsv32:: -opErr(long status) -{ - enum errs e = (enum errs) status; - switch (e) { - case NONE: - return ""; - case NOT_FOUND: - return "NOT_FOUND"; - case GENERAL: - return "GENERAL"; - break; - case CANCEL: - return "CANCEL"; - break; - case NO_MEMORY: - return "NO_MEMORY"; - break; - case NOT_SUPPORTED: - return "NOT_SUPPORTED"; - break; - case ARGUMENT: - return "ARGUMENT"; - break; - case TOTAL_LOSS_OF_PRECISION: - return "TOTAL_LOSS_OF_PRECISION"; - break; - case BAD_HANDLE: - return "BAD_HANDLE"; - break; - case OVERFLOW: - return "OVERFLOW"; - break; - case UNDERFLOW: - return "UNDERFLOW"; - break; - case ALREADY_EXISTS: - return "ALREADY_EXISTS"; - break; - case PATH_NOT_FOUND: - return "PATH_NOT_FOUND"; - break; - case DIED: - return "DIED"; - break; - case IN_USE: - return "IN_USE"; - break; - case SERVER_TERMINATED: - return "SERVER_TERMINATED"; - break; - case SERVER_BUSY: - return "SERVER_BUSY"; - break; - case COMPLETION: - return "COMPLETION"; - break; - case NOT_READY: - return "NOT_READY"; - break; - case UNKNOWN: - return "UNKNOWN"; - break; - case CORRUPT: - return "CORRUPT"; - break; - case ACCESS_DENIED: - return "ACCESS_DENIED"; - break; - case LOCKED: - return "LOCKED"; - break; - case WRITE: - return "WRITE"; - break; - case DISMOUNTED: - return "DISMOUNTED"; - break; - case EoF: - return "EOF"; - break; - case DISK_FULL: - return "DISK_FULL"; - break; - case BAD_DRIVER: - return "BAD_DRIVER"; - break; - case BAD_NAME: - return "BAD_NAME"; - break; - case COMMS_LINE_FAIL: - return "COMMS_LINE_FAIL"; - break; - case COMMS_FRAME: - return "COMMS_FRAME"; - break; - case COMMS_OVERRUN: - return "COMMS_OVERRUN"; - break; - case COMMS_PARITY: - return "COMMS_PARITY"; - break; - case PSI_TIMEOUT: - return "TIMEOUT"; - break; - case COULD_NOT_CONNECT: - return "COULD_NOT_CONNECT"; - break; - case COULD_NOT_DISCONNECT: - return "COULD_NOT_DISCONNECT"; - break; - case DISCONNECTED: - return "DISCONNECTED"; - break; - case BAD_LIBRARY_ENTRY_POINT: - return "BAD_LIBRARY_ENTRY_POINT"; - break; - case BAD_DESCRIPTOR: - return "BAD_DESCRIPTOR"; - break; - case ABORT: - return "ABORT"; - break; - case TOO_BIG: - return "TOO_BIG"; - break; - case DIVIDE_BY_ZERO: - return "DIVIDE_BY_ZERO"; - break; - case BAD_POWER: - return "BAD_POWER"; - break; - case DIR_FULL: - return "DIR_FULL"; - break; - default: - return "Unknown error"; - break; - } -} - -long rfsv32:: -fread(long handle, char *buf, long len) -{ - long res; - long count = 0; - - do { - bufferStore a; - a.addDWord(handle); - a.addDWord(((len-count) > 2000)?2000:(len-count)); - sendCommand(READ_FILE, a); - if ((res = getResponse(a)) != 0) - return res; - res = a.getLen(); - if (res > 0) { - memcpy(buf, a.getString(), res); - count += res; - buf += res; - } - } while ((count < len) && (res > 0)); - return (res < 0)?res:count; -} - -long rfsv32:: -fwrite(long handle, char *buf, long len) -{ - long res; - long total = 0; - long count; - - do { - count = ((len - total) > 2000)?2000:(len - total); - bufferStore a; - bufferStore tmp((unsigned char *)buf, count); - a.addDWord(handle); - a.addBuff(tmp); - sendCommand(WRITE_FILE, a); - if ((res = getResponse(a)) != 0) - return res; - total += count; - buf += count; - } while ((total < len) && (count > 0)); - return total; -} - -long rfsv32:: -copyFromPsion(const char *from, const char *to) -{ - long handle; - long res; - long len; - - if ((res = fopen(SHARE_READERS | BINARY, from, handle)) != 0) - return res; - ofstream op(to); - if (!op) { - fclose(handle); - return -1; - } - do { - char buf[2000]; - if ((len = fread(handle, buf, sizeof(buf))) > 0) - op.write(buf, len); - } while (len > 0); - - fclose(handle); - op.close(); - return len; -} - -long rfsv32:: -copyToPsion(const char *from, const char *to) -{ - long handle; - long res; - - ifstream ip(from); - if (!ip) - return NOT_FOUND; - res = fcreatefile(BINARY | SHARE_EXCLUSIVE | READ_WRITE, to, handle); - if (res != 0) { - res = freplacefile(BINARY | SHARE_EXCLUSIVE | READ_WRITE, to, handle); - if (res != 0) { - opErr(res); - cerr << endl; - return res; - } - } - unsigned char *buff = new unsigned char[RFSV_SENDLEN]; - int total = 0; - while (ip && !ip.eof()) { - ip.read(buff, RFSV_SENDLEN); - bufferStore tmp(buff, ip.gcount()); - total += tmp.getLen(); - if (tmp.getLen() == 0) - break; - bufferStore a; - a.addDWord(handle); - a.addBuff(tmp); - sendCommand(WRITE_FILE, a); - res = getResponse(a); - if (res) { - cerr << "Unknown response to fwrite - "; - opErr(res); - cerr << " " << a << endl; - fclose(handle); - return res; - } - } - fclose(handle); - ip.close(); - delete[]buff; - return 0; -} - -long rfsv32:: -fsetsize(long handle, long size) -{ - bufferStore a; - a.addDWord(handle); - a.addDWord(size); - sendCommand(SET_SIZE, a); - return getResponse(a); -} - -/* - * Unix-like implementation off fseek with one - * exception: If seeking beyond eof, the gap - * contains garbage instead of zeroes. - */ -long rfsv32:: -fseek(long handle, long pos, long mode) -{ - bufferStore a; - long res; - long savpos = 0; - long realpos; - long calcpos = 0; - -/* - seek-parameter for psion: - dword position - dword handle - dword mode - 1 = from start - 2 = from current pos - 3 = from end - ??no more?? 4 = sense recpos - ??no more?? 5 = set recpos - ??no more?? 6 = text-rewind - */ - - if ((mode < PSEEK_SET) || (mode > PSEEK_END)) - return ARGUMENT; - - if ((mode == PSEEK_CUR) && (pos >= 0)) { - /* get and save current position */ - a.addDWord(0); - a.addDWord(handle); - a.addDWord(PSEEK_CUR); - sendCommand(SEEK_FILE, a); - if ((res = getResponse(a)) != 0) - return res; - savpos = a.getDWord(0); - if (pos == 0) - return savpos; - a.init(); - } - if ((mode == PSEEK_END) && (pos >= 0)) { - /* get and save end position */ - a.addDWord(0); - a.addDWord(handle); - a.addDWord(PSEEK_END); - sendCommand(SEEK_FILE, a); - if ((res = getResponse(a)) != 0) - return res; - savpos = a.getDWord(0); - if (pos == 0) - return savpos; - /* Expand file */ - a.init(); - a.addDWord(handle); - a.addDWord(savpos + pos); - sendCommand(SET_SIZE, a); - if ((res = getResponse(a)) != 0) - return res; - pos = 0; - a.init(); - } - /* Now the real seek */ - a.addDWord(pos); - a.addDWord(handle); - a.addDWord(mode); - sendCommand(SEEK_FILE, a); - if ((res = getResponse(a)) != 0) { -cout << "seekRES(" << handle << ")=" << res << endl; - return res; -} - realpos = a.getDWord(0); -cout << "seekPOS=" << realpos << endl; - switch (mode) { - case PSEEK_SET: - calcpos = pos; - break; - case PSEEK_CUR: - calcpos = savpos + pos; - break; - case PSEEK_END: - return realpos; - break; - } - if (calcpos > realpos) { - /* Beyond end of file */ - a.init(); - a.addDWord(handle); - a.addDWord(calcpos); - sendCommand(SET_SIZE, a); - if ((res = getResponse(a)) != 0) - return res; - a.addDWord(calcpos); - a.addDWord(handle); - a.addDWord(PSEEK_SET); - sendCommand(SEEK_FILE, a); - if ((res = getResponse(a)) != 0) - return res; - realpos = a.getDWord(0); - } - return realpos; -} - -long rfsv32:: -mkdir(const char *name) -{ - bufferStore a; - convertSlash(name); - if (strlen(name) && (name[strlen(name) - 1] != '\\')) { - a.addWord(strlen(name) + 1); - a.addString(name); - a.addByte('\\'); - } else { - a.addWord(strlen(name)); - a.addString(name); - } - sendCommand(MK_DIR_ALL, a); - return getResponse(a); -} - -long rfsv32:: -rmdir(const char *name) -{ - bufferStore a; - convertSlash(name); - if (strlen(name) && (name[strlen(name) - 1] != '\\')) { - a.addWord(strlen(name) + 1); - a.addString(name); - a.addByte('\\'); - } else { - a.addWord(strlen(name)); - a.addString(name); - } - sendCommand(RM_DIR, a); - return getResponse(a); -} - -long rfsv32:: -rename(const char *oldname, const char *newname) -{ - bufferStore a; - convertSlash(oldname); - convertSlash(newname); - a.addWord(strlen(oldname)); - a.addString(oldname); - a.addWord(strlen(newname)); - a.addString(newname); - sendCommand(RENAME, a); - return getResponse(a); -} - -long rfsv32:: -remove(const char *name) -{ - bufferStore a; - convertSlash(name); - a.addWord(strlen(name)); - a.addString(name); - sendCommand(DELETE, a); - return getResponse(a); -} diff --git a/plpnfsd/rfsv32.h b/plpnfsd/rfsv32.h deleted file mode 100644 index 083bd3d..0000000 --- a/plpnfsd/rfsv32.h +++ /dev/null @@ -1,172 +0,0 @@ -#ifndef _rfsv32_h_ -#define _rfsv32_h_ - -class ppsocket; -class bufferStore; -class bufferArray; - -class rfsv32 { - public: - rfsv32(ppsocket * skt); - ~rfsv32(); - - long dir(const char *name, bufferArray * files); - long dircount(const char *name, long *count); - long copyFromPsion(const char *from, const char *to); - long copyToPsion(const char *from, const char *to); - long mkdir(const char *name); - long rmdir(const char *name); - long remove(const char *name); - long rename(const char *oldname, const char *newname); - long mktemp(long *handle, char *tmpname); - long fgeteattr(const char *name, long *attr, long *size, long *time); - long fgetattr(const char *name, long *attr); - long fsetattr(const char *name, long seta, long unseta); - long fgetmtime(const char *name, long *mtime); - long fsetmtime(const char *name, long mtime); - long fopendir(long attr, const char *name, long &handle); - long fopen(long attr, const char *name, long &handle); - long fcreatefile(long attr, const char *name, long &handle); - long freplacefile(long attr, const char *name, long &handle); - long fseek(long handle, long pos, long mode); - long fread(long handle, char *buf, long len); - long fwrite(long handle, char *buf, long len); - long fsetsize(long handle, long size); - long fclose(long handle); - - long devlist(long *devbits); - char *devinfo(int devnum, long *vfree, long *vtotal, long *vattr, long *vuiqueid); - long getStatus(); - char *opErr(long status); - - enum seek_mode { - PSEEK_SET = 1, - PSEEK_CUR = 2, - PSEEK_END = 3 - }; - - private: - enum commands { - CLOSE_HANDLE = 0x01, - OPEN_DIR = 0x10, - READ_DIR = 0x12, - GET_DRIVE_LIST = 0x13, - DRIVE_INFO = 0x14, - SET_VOLUME_LABEL = 0x15, - OPEN_FILE = 0x16, - TEMP_FILE = 0x17, - READ_FILE = 0x18, - WRITE_FILE = 0x19, - SEEK_FILE = 0x1a, - DELETE = 0x1b, - REMOTE_ENTRY = 0x1c, - FLUSH = 0x1d, - SET_SIZE = 0x1e, - RENAME = 0x1f, - MK_DIR_ALL = 0x20, - RM_DIR = 0x21, - SET_ATT = 0x22, - ATT = 0x23, - SET_MODIFIED = 0x24, - MODIFIED = 0x25, - SET_SESSION_PATH = 0x26, - SESSION_PATH = 0x27, - READ_WRITE_FILE = 0x28, - CREATE_FILE = 0x29, - REPLACE_FILE = 0x2a, - PATH_TEST = 0x2b, - LOCK = 0x2d, - UNLOCK = 0x2e, - OPEN_DIR_UID = 0x2f, - DRIVE_NAME = 0x30, - SET_DRIVE_NAME = 0x31, - REPLACE = 0x32 - }; - - enum file_attrib { - READ_ONLY = 0x0001, - HIDDEN = 0x0002, - SYSTEM = 0x0004, - DIRECTORY = 0x0010, - ARCHIVE = 0x0020, - VOLUME = 0x0040, - NORMAL = 0x0080, - TEMPORARY = 0x0100, - COMPRESSED = 0x0800 - }; - - enum open_mode { - SHARE_EXCLUSIVE = 0x0000, - SHARE_READERS = 0x0001, - SHARE_ANY = 0x0002, - BINARY = 0x0000, - TEXT = 0x0020, - READ_WRITE = 0x0200 - }; - - enum errs { - NONE = 0, - NOT_FOUND = -1, - GENERAL = -2, - CANCEL = -3, - NO_MEMORY = -4, - NOT_SUPPORTED = -5, - ARGUMENT = -6, - TOTAL_LOSS_OF_PRECISION = -7, - BAD_HANDLE = -8, - OVERFLOW = -9, - UNDERFLOW = -10, - ALREADY_EXISTS = -11, - PATH_NOT_FOUND = -12, - DIED = -13, - IN_USE = -14, - SERVER_TERMINATED = -15, - SERVER_BUSY = -16, - COMPLETION = -17, - NOT_READY = -18, - UNKNOWN = -19, - CORRUPT = -20, - ACCESS_DENIED = -21, - LOCKED = -22, - WRITE = -23, - DISMOUNTED = -24, - EoF = -25, - DISK_FULL = -26, - BAD_DRIVER = -27, - BAD_NAME = -28, - COMMS_LINE_FAIL = -29, - COMMS_FRAME = -30, - COMMS_OVERRUN = -31, - COMMS_PARITY = -32, - PSI_TIMEOUT = -33, - COULD_NOT_CONNECT = -34, - COULD_NOT_DISCONNECT = -35, - DISCONNECTED = -36, - BAD_LIBRARY_ENTRY_POINT = -37, - BAD_DESCRIPTOR = -38, - ABORT = -39, - TOO_BIG = -40, - DIVIDE_BY_ZERO = -41, - BAD_POWER = -42, - DIR_FULL = -43 - }; - - const char *getConnectName(); - - // Communication - bool sendCommand(enum commands c, bufferStore & data); - long getResponse(bufferStore & data); - void convertSlash(const char *name); - - // time-conversion - unsigned long micro2time(unsigned long microHi, unsigned long microLo); - void time2micro(unsigned long mtime, unsigned long µHi, unsigned long µLo); - - // Vars - ppsocket *skt; - int serNum; - long status; - int tDiff; -}; - -#endif diff --git a/plpnfsd/rfsv_api.h b/plpnfsd/rfsv_api.h index 18bd496..3633b53 100644 --- a/plpnfsd/rfsv_api.h +++ b/plpnfsd/rfsv_api.h @@ -25,5 +25,7 @@ extern long rfsv_setmtime(const char *name, long time); extern long rfsv_drivelist(int *cnt, device **devlist); extern long rfsv_dircount(const char *name, long *count); extern long rfsv_statdev(char letter); +extern long rfsv_isalive(); +extern void rfsv_startup(); #endif -- cgit v1.2.3