NetDisk/mounturl.c
Stephen Heumann 92649e33ee Enhance mounturl command-line utility.
It now accepts a flag "-c" to disable caching, and can also print meaningful error messages.
2018-10-02 18:04:22 -05:00

53 lines
1.2 KiB
C

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <locator.h>
#include "mounturl.h"
#include "netdiskerror.h"
static void usage(void) {
fprintf(stderr, "Usage: mounturl [-c] url\n");
exit(EXIT_FAILURE);
}
int main(int argc, char **argv) {
struct MountURLRec mountURLRec = {sizeof(struct MountURLRec)};
int i = 1;
int flags = flgUseCache;
while (i < argc && argv[i][0] == '-') {
switch(argv[i][1]) {
case 'c':
flags &= ~flgUseCache;
break;
default:
usage();
}
i++;
}
if (i >= argc)
usage();
mountURLRec.result = NETDISK_NOT_PRESENT;
mountURLRec.url = argv[i];
mountURLRec.flags = flags;
SendRequest(MountURL, sendToName|stopAfterOne, (Long)NETDISK_REQUEST_NAME,
(Long)&mountURLRec, NULL);
if (mountURLRec.result != OPERATION_SUCCESSFUL) {
char *errString = ErrorString(mountURLRec.result);
if (strchr(errString, '*') == NULL) {
fprintf(stderr, "%s\n", errString);
} else {
fprintf(stderr, "NetDisk error %u.\n", mountURLRec.result);
}
return 1;
}
return 0;
}