From 0bef3159d3698a941154bd21352eb35bd94edb8c Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sun, 11 Nov 2012 22:00:07 -0500 Subject: [PATCH] afsio: process windows file paths consistently Windows file paths can use either '\' or '/' as a path separator. libafscp on the other hand requires '/' and argv[0] will always use '\'. Introduce a new function ConvertAFSPath() which converts the input path to '/' and converts \\afs to /afs. A future commit should access the registry and make use of the NetbiosName and MountRoot values to perform the conversion correctly. Change-Id: I14f5f45234ec4beab58751783a25206b3e7eff45 Reviewed-on: http://gerrit.openafs.org/8430 Reviewed-by: Derrick Brashear Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman --- src/venus/afsio.c | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/venus/afsio.c b/src/venus/afsio.c index 5bdc787195..6e52ea9a2f 100644 --- a/src/venus/afsio.c +++ b/src/venus/afsio.c @@ -187,6 +187,23 @@ summarizeMD5(char *fname) htonl(md5int[1]), htonl(md5int[2]), htonl(md5int[3]), p); } /* summarizeMD5 */ +#ifdef AFS_NT40_ENV +static void +ConvertAFSPath(char **fnp) +{ + char *p; + + for (p = *fnp; *p; p++) { + if (*p == '\\') + *p = '/'; + } + + p = *fnp; + if (p[0] == '/' && p[1] == '/') + *fnp = p+1; +} +#endif /* AFS_NT40_ENV */ + /*! * parses all command-line arguments * @@ -232,11 +249,15 @@ CmdProlog(struct cmd_syndesc *as, char **cellp, char **realmp, else if (strcmp(pdp->name, "-cell") == 0) { cellGiven = 1; /* global */ *cellp = pdp->items->data; - } else if ( (strcmp(pdp->name, "-file") == 0) || - (strcmp(pdp->name, "-fid") == 0) || - (strcmp(pdp->name, "-vnode") == 0) ) + } else if ( strcmp(pdp->name, "-file") == 0) { *fnp = pdp->items->data; - else if (strcmp(pdp->name, "-force") == 0) +#ifdef AFS_NT40_ENV + ConvertAFSPath(fnp); +#endif /* AFS_NT40_ENV */ + } else if ( (strcmp(pdp->name, "-fid") == 0) || + (strcmp(pdp->name, "-vnode") == 0) ) { + *fnp = pdp->items->data; + } else if (strcmp(pdp->name, "-force") == 0) force = 1; /* global */ else if (strcmp(pdp->name, "-synthesize") == 0) *slp = pdp->items->data; @@ -256,9 +277,18 @@ main(int argc, char **argv) { struct cmd_syndesc *ts; char baseName[AFSNAMEMAX]; + int code; /* try to get only the base name of this executable for use in logs */ - if (BreakUpPath(argv[0], NULL, baseName, AFSNAMEMAX) > 0) +#ifdef AFS_NT40_ENV + char *p = strdup(argv[0]); + ConvertAFSPath(&p); + code = BreakUpPath(p, NULL, baseName, AFSNAMEMAX); + free(p); +#else + code = BreakUpPath(argv[0], NULL, baseName, AFSNAMEMAX); +#endif + if (code > 0) strlcpy(pnp, baseName, AFSNAMEMAX); else strlcpy(pnp, argv[0], AFSPATHMAX); @@ -551,11 +581,7 @@ BreakUpPath(char *fullPath, char *dirName, char *baseName, size_t baseNameSize) /* would be pointless to continue -- must be error in call */ return code; } -#ifdef AFS_NT40_ENV - lastSlash = strrchr(fullPath, '\\'); -#else lastSlash = strrchr(fullPath, '/'); -#endif if (lastSlash != NULL) { /* then lastSlash points to the last path separator in fullPath */ if (useDirName) {