mirror of
https://github.com/sheumann/NetDisk.git
synced 2025-01-17 09:29:58 +00:00
Switch to using a struct for the MountURL DControl call.
This allows us to return a better error code and provides for future extensibility.
This commit is contained in:
parent
8fe8bbdf7e
commit
8b09d6bb7d
19
driver.c
19
driver.c
@ -9,6 +9,7 @@
|
|||||||
#include "readtcp.h"
|
#include "readtcp.h"
|
||||||
#include "tcpconnection.h"
|
#include "tcpconnection.h"
|
||||||
#include "asmglue.h"
|
#include "asmglue.h"
|
||||||
|
#include "mounturl.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
#define BLOCK_SIZE 512
|
#define BLOCK_SIZE 512
|
||||||
@ -221,23 +222,33 @@ static enum NetDiskError CheckTwoImg(Session *sess) {
|
|||||||
|
|
||||||
static Word DoMountURL(struct GSOSDP *dp) {
|
static Word DoMountURL(struct GSOSDP *dp) {
|
||||||
enum NetDiskError err;
|
enum NetDiskError err;
|
||||||
|
struct MountURLRec *mountURLRec = (struct MountURLRec *)dp->controlListPtr;
|
||||||
|
|
||||||
|
if (mountURLRec->byteCount != sizeof(struct MountURLRec)
|
||||||
|
|| mountURLRec->byteCount != dp->requestCount)
|
||||||
|
{
|
||||||
|
dp->transferCount = 0;
|
||||||
|
return drvrBadParm;
|
||||||
|
}
|
||||||
|
|
||||||
if (dp->dibPointer->extendedDIBPtr != NULL) {
|
if (dp->dibPointer->extendedDIBPtr != NULL) {
|
||||||
dp->transferCount = 0;
|
dp->transferCount = 0;
|
||||||
|
mountURLRec->result = DISK_ALREADY_MOUNTED;
|
||||||
return drvrBusy;
|
return drvrBusy;
|
||||||
}
|
}
|
||||||
|
|
||||||
Session *sess = calloc(sizeof(*sess), 1);
|
Session *sess = calloc(sizeof(*sess), 1);
|
||||||
if (sess == NULL) {
|
if (sess == NULL) {
|
||||||
dp->transferCount = 0;
|
dp->transferCount = 0;
|
||||||
|
mountURLRec->result = OUT_OF_MEMORY;
|
||||||
return drvrNoResrc;
|
return drvrNoResrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = SetURL(sess, (char*)dp->controlListPtr, TRUE, FALSE);
|
err = SetURL(sess, mountURLRec->url, TRUE, FALSE);
|
||||||
if (err != OPERATION_SUCCESSFUL) {
|
if (err != OPERATION_SUCCESSFUL) {
|
||||||
// TODO arrange for more detailed error reporting
|
|
||||||
EndNetDiskSession(sess);
|
EndNetDiskSession(sess);
|
||||||
dp->transferCount = 0;
|
dp->transferCount = 0;
|
||||||
|
mountURLRec->result = err;
|
||||||
return drvrIOError;
|
return drvrIOError;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,6 +257,7 @@ static Word DoMountURL(struct GSOSDP *dp) {
|
|||||||
// TODO arrange for more detailed error reporting
|
// TODO arrange for more detailed error reporting
|
||||||
EndNetDiskSession(sess);
|
EndNetDiskSession(sess);
|
||||||
dp->transferCount = 0;
|
dp->transferCount = 0;
|
||||||
|
mountURLRec->result = err;
|
||||||
return drvrIOError;
|
return drvrIOError;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,8 +270,8 @@ static Word DoMountURL(struct GSOSDP *dp) {
|
|||||||
err = CheckTwoImg(sess);
|
err = CheckTwoImg(sess);
|
||||||
if (err != OPERATION_SUCCESSFUL) {
|
if (err != OPERATION_SUCCESSFUL) {
|
||||||
EndNetDiskSession(sess);
|
EndNetDiskSession(sess);
|
||||||
// TODO better error
|
|
||||||
dp->transferCount = 0;
|
dp->transferCount = 0;
|
||||||
|
mountURLRec->result = err;
|
||||||
return drvrIOError;
|
return drvrIOError;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,6 +279,7 @@ static Word DoMountURL(struct GSOSDP *dp) {
|
|||||||
|
|
||||||
//TODO report disk switch
|
//TODO report disk switch
|
||||||
|
|
||||||
|
mountURLRec->result = OPERATION_SUCCESSFUL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
http.c
6
http.c
@ -206,7 +206,11 @@ netRetry:
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
result = UNSUPPORTED_RESPONSE;
|
if (sess->responseCode < 400 || sess->responseCode > 599) {
|
||||||
|
result = UNSUPPORTED_RESPONSE;
|
||||||
|
} else {
|
||||||
|
result = sess->responseCode;
|
||||||
|
}
|
||||||
goto errorReturn;
|
goto errorReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
mounturl.c
16
mounturl.c
@ -1,19 +1,27 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <gsos.h>
|
#include <gsos.h>
|
||||||
|
#include "mounturl.h"
|
||||||
#define MountURL 0x8080
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
struct MountURLRec mountURLRec;
|
||||||
DAccessRecGS controlRec = {5};
|
DAccessRecGS controlRec = {5};
|
||||||
|
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
mountURLRec.byteCount = sizeof(mountURLRec);
|
||||||
|
mountURLRec.url = argv[2];
|
||||||
|
|
||||||
controlRec.devNum = strtoul(argv[1], NULL, 0);
|
controlRec.devNum = strtoul(argv[1], NULL, 0);
|
||||||
controlRec.code = MountURL;
|
controlRec.code = MountURL;
|
||||||
controlRec.list = argv[2];
|
controlRec.list = (Pointer)&mountURLRec;
|
||||||
controlRec.requestCount = strlen(argv[2]) + 1;
|
controlRec.requestCount = sizeof(mountURLRec);
|
||||||
|
|
||||||
DControl(&controlRec);
|
DControl(&controlRec);
|
||||||
|
|
||||||
|
if (mountURLRec.result != OPERATION_SUCCESSFUL) {
|
||||||
|
fprintf(stderr, "MountURL error %u\n", mountURLRec.result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
15
mounturl.h
Normal file
15
mounturl.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef MOUNTURL_H
|
||||||
|
#define MOUNTURL_H
|
||||||
|
|
||||||
|
#include "netdiskerror.h"
|
||||||
|
|
||||||
|
/* Custom DControl code and request code for MountURL operation */
|
||||||
|
#define MountURL 0x8080
|
||||||
|
|
||||||
|
struct MountURLRec {
|
||||||
|
Word byteCount;
|
||||||
|
enum NetDiskError result; /* output value */
|
||||||
|
char *url; /* C-string; will be modified */
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -4,8 +4,11 @@
|
|||||||
enum NetDiskError {
|
enum NetDiskError {
|
||||||
OPERATION_SUCCESSFUL = 0,
|
OPERATION_SUCCESSFUL = 0,
|
||||||
|
|
||||||
|
DISK_ALREADY_MOUNTED = 100,
|
||||||
|
OUT_OF_MEMORY,
|
||||||
|
|
||||||
/* SetURL errors */
|
/* SetURL errors */
|
||||||
URL_TOO_LONG = 100,
|
URL_TOO_LONG = 200,
|
||||||
INVALID_CHARACTER_IN_URL,
|
INVALID_CHARACTER_IN_URL,
|
||||||
BAD_URL_SYNTAX,
|
BAD_URL_SYNTAX,
|
||||||
UNSUPPORTED_URL_SCHEME,
|
UNSUPPORTED_URL_SCHEME,
|
||||||
@ -16,10 +19,9 @@ enum NetDiskError {
|
|||||||
IPV6_NOT_SUPPORTED,
|
IPV6_NOT_SUPPORTED,
|
||||||
HOSTNAME_TOO_LONG,
|
HOSTNAME_TOO_LONG,
|
||||||
NAME_LOOKUP_FAILED,
|
NAME_LOOKUP_FAILED,
|
||||||
OUT_OF_MEMORY,
|
|
||||||
|
|
||||||
/* StartTCPConnection and DoHTTPRequest errors */
|
/* StartTCPConnection and DoHTTPRequest errors */
|
||||||
NETWORK_ERROR = 200,
|
NETWORK_ERROR = 300,
|
||||||
NO_RESPONSE,
|
NO_RESPONSE,
|
||||||
INVALID_RESPONSE,
|
INVALID_RESPONSE,
|
||||||
EXCESSIVE_REDIRECTS,
|
EXCESSIVE_REDIRECTS,
|
||||||
@ -29,8 +31,11 @@ enum NetDiskError {
|
|||||||
NOT_DESIRED_CONTENT,
|
NOT_DESIRED_CONTENT,
|
||||||
DIFFERENT_LENGTH, /* Might be considered successful later */
|
DIFFERENT_LENGTH, /* Might be considered successful later */
|
||||||
|
|
||||||
|
/* Error values of 4xx and 5xx mean we got the corresponding HTTP error */
|
||||||
|
HTTP_ERROR = 400,
|
||||||
|
|
||||||
/* File format errors */
|
/* File format errors */
|
||||||
UNSUPPORTED_2IMG_FILE = 300,
|
UNSUPPORTED_2IMG_FILE = 600,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user