From ccc95944127e451ce9a041827ddd8316572e4e3a Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Fri, 10 Aug 2018 22:40:07 -0500 Subject: [PATCH] Add support for ejecting NetDisk volumes. --- Makefile | 2 +- driver.c | 16 +++++++++++++--- session.c | 12 ++++++++++++ session.h | 3 +++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 session.c diff --git a/Makefile b/Makefile index 089649d..ebb5174 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ HTTPTEST_PROG = httptest MOUNTURL_OBJS = mounturl.a MOUNTURL_PROG = mounturl -NETDISKINIT_OBJS = initstart.a netdiskinit.a hostname.a http.a readtcp.a seturl.a strcasecmp.a tcpconnection.a urlparser.a driver.a installdriver.a asmglue.a driverwrapper.a +NETDISKINIT_OBJS = initstart.a netdiskinit.a hostname.a http.a readtcp.a seturl.a strcasecmp.a tcpconnection.a urlparser.a driver.a installdriver.a asmglue.a driverwrapper.a session.a # NETDISKINIT_RSRC = NETDISKINIT_PROG = NetDiskInit diff --git a/driver.c b/driver.c index 11b0581..0840342 100644 --- a/driver.c +++ b/driver.c @@ -7,6 +7,7 @@ #include "seturl.h" #include "http.h" #include "readtcp.h" +#include "tcpconnection.h" #include "asmglue.h" #include "version.h" @@ -215,11 +216,11 @@ static Word DoMountURL(struct GSOSDP *dp) { dp->transferCount = 0; return drvrNoResrc; } - dp->dibPointer->extendedDIBPtr = sess; enum SetURLResult setResult = SetURL(sess, (char*)dp->controlListPtr, TRUE, FALSE); if (setResult != SETURL_SUCCESSFUL) { // TODO arrange for more detailed error reporting + EndNetDiskSession(sess); dp->transferCount = 0; return drvrIOError; } @@ -227,6 +228,7 @@ static Word DoMountURL(struct GSOSDP *dp) { enum RequestResult requestResult = DoHTTPRequest(sess, 0, sizeof(sess->fileHeader) - 1); if (requestResult != REQUEST_SUCCESSFUL) { // TODO arrange for more detailed error reporting + EndNetDiskSession(sess); dp->transferCount = 0; return drvrIOError; } @@ -239,9 +241,12 @@ static Word DoMountURL(struct GSOSDP *dp) { Word checkResult = CheckTwoImg(sess); if (checkResult != 0) { + EndNetDiskSession(sess); // TODO error } + dp->dibPointer->extendedDIBPtr = sess; + //TODO report disk switch return 0; @@ -299,11 +304,16 @@ static Word DoStatus(struct GSOSDP *dp) { } static Word DoEject(struct GSOSDP *dp) { - //TODO + EndNetDiskSession(dp->dibPointer->extendedDIBPtr); + dp->dibPointer->extendedDIBPtr = NULL; + + dp->transferCount = 0; return 0; } static Word DoShutdown(struct GSOSDP *dp) { - //TODO + EndNetDiskSession(dp->dibPointer->extendedDIBPtr); + dp->dibPointer->extendedDIBPtr = NULL; + //TODO should return error unless all of our other DIBs are already shut down? return 0; } \ No newline at end of file diff --git a/session.c b/session.c new file mode 100644 index 0000000..a15029e --- /dev/null +++ b/session.c @@ -0,0 +1,12 @@ +#include +#include "session.h" +#include "tcpconnection.h" + +/* End a session and free associated data. */ +void EndNetDiskSession(Session *sess) { + if (sess != NULL) { + EndTCPConnection(sess); + free(sess->httpRequest); + free(sess); + } +} diff --git a/session.h b/session.h index 6e4e11e..06c112a 100644 --- a/session.h +++ b/session.h @@ -70,4 +70,7 @@ typedef struct Session { } fileHeader; } Session; + +void EndNetDiskSession(Session *sess); + #endif