From 003113ca69bd87955a5399415343d8eac533a037 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Thu, 20 Jan 2011 01:51:26 -0500 Subject: [PATCH] vol: use OS_DIRSEP in many more places For consistency use OS_DIRSEP and OS_DIRSEPC throughout the package. (cherry picked from commit 259a0e886a29874420010544e33a789cac1692c1) Reviewed-on: http://gerrit.openafs.org/3702 Reviewed-by: Derrick Brashear Tested-by: BuildBot Change-Id: Id18bbe7759bc96f83c7a00a0a8698a868fc54c2a Reviewed-on: http://gerrit.openafs.org/3900 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/vol/devname.c | 8 ++++---- src/vol/fssync-server.c | 4 ++-- src/vol/listinodes.c | 4 ++-- src/vol/namei_ops.c | 30 +++++++++++++++--------------- src/vol/nuke.c | 2 +- src/vol/partition.c | 8 ++++---- src/vol/vol-info.c | 2 +- src/vol/vol-salvage.c | 18 +++++++++--------- src/vol/volume.c | 10 +++++----- 9 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/vol/devname.c b/src/vol/devname.c index 2a0a6908f..e884ecb67 100644 --- a/src/vol/devname.c +++ b/src/vol/devname.c @@ -198,14 +198,14 @@ vol_DevName(dev_t adev, char *wpath) #endif if (wpath) { strcpy(pbuf, pbuffer); - ptr = (char *)strrchr(pbuf, '/'); + ptr = (char *)strrchr(pbuf, OS_DIRSEPC); if (ptr) { *ptr = '\0'; strcpy(wpath, pbuf); } else return NULL; } - ptr = (char *)strrchr(pbuffer, '/'); + ptr = (char *)strrchr(pbuffer, OS_DIRSEPC); if (ptr) { strcpy(pbuffer, ptr + 1); return pbuffer; @@ -241,7 +241,7 @@ afs_rawname(char *devfile) i = strlen(devfile); while (i >= 0) { strcpy(rawname, devfile); - if (devfile[i] == '/') { + if (devfile[i] == OS_DIRSEPC) { rawname[i + 1] = 'r'; rawname[i + 2] = 0; strcat(rawname, &devfile[i + 1]); @@ -251,7 +251,7 @@ afs_rawname(char *devfile) if (!code && S_ISCHR(statbuf.st_mode)) return rawname; - while ((--i >= 0) && (devfile[i] != '/')); + while ((--i >= 0) && (devfile[i] != OS_DIRSEPC)); } return NULL; diff --git a/src/vol/fssync-server.c b/src/vol/fssync-server.c index 78d3bee10..633551110 100644 --- a/src/vol/fssync-server.c +++ b/src/vol/fssync-server.c @@ -750,7 +750,7 @@ FSYNC_com_VolOn(FSSYNC_VolOp_command * vcom, SYNC_response * res) VDeregisterVolOp_r(vp); } #else /* !AFS_DEMAND_ATTACH_FS */ - tvolName[0] = '/'; + tvolName[0] = OS_DIRSEPC; snprintf(&tvolName[1], sizeof(tvolName)-1, VFORMAT, afs_printable_uint32_lu(vcom->vop->volume)); tvolName[sizeof(tvolName)-1] = '\0'; @@ -1924,7 +1924,7 @@ FSYNC_Drop(osi_socket fd) Volume *vp; - tvolName[0] = '/'; + tvolName[0] = OS_DIRSEPC; sprintf(&tvolName[1], VFORMAT, afs_printable_uint32_lu(p[i].volumeID)); vp = VAttachVolumeByName_r(&error, p[i].partName, tvolName, V_VOLUPD); diff --git a/src/vol/listinodes.c b/src/vol/listinodes.c index 9c52462fb..b47ef3792 100644 --- a/src/vol/listinodes.c +++ b/src/vol/listinodes.c @@ -1365,13 +1365,13 @@ getDevName(char *pbuffer, char *wpath) { char pbuf[128], *ptr; strcpy(pbuf, pbuffer); - ptr = (char *)strrchr(pbuf, '/'); + ptr = (char *)strrchr(pbuf, OS_DIRSEPC); if (ptr) { *ptr = '\0'; strcpy(wpath, pbuf); } else return NULL; - ptr = (char *)strrchr(pbuffer, '/'); + ptr = (char *)strrchr(pbuffer, OS_DIRSEPC); if (ptr) { strcpy(pbuffer, ptr + 1); return pbuffer; diff --git a/src/vol/namei_ops.c b/src/vol/namei_ops.c index 0bc23c721..0ce41e303 100644 --- a/src/vol/namei_ops.c +++ b/src/vol/namei_ops.c @@ -405,7 +405,7 @@ namei_CreateDataDirectories(namei_t * name, int *created) int i; *created = 0; - afs_snprintf(tmp, 256, "%s\\%s", name->n_drive, name->n_voldir); + afs_snprintf(tmp, 256, "%s" OS_DIRSEP "%s", name->n_drive, name->n_voldir); if (mkdir(tmp) < 0) { if (errno != EEXIST) @@ -416,7 +416,7 @@ namei_CreateDataDirectories(namei_t * name, int *created) s = tmp; s += strlen(tmp); - *s++ = '\\'; + *s++ = OS_DIRSEPC; *(s + 1) = '\0'; for (i = 'A'; i <= 'R'; i++) { *s = (char)i; @@ -439,7 +439,7 @@ do { \ #define create_nextdir(A) \ do { \ - strcat(tmp, "/"); strcat(tmp, A); create_dir(); \ + strcat(tmp, OS_DIRSEP); strcat(tmp, A); create_dir(); \ } while(0) static int @@ -492,7 +492,7 @@ delTree(char *root, char *tree, int *errp) if (*tree) { /* delete the children first */ - cp = strchr(tree, '/'); + cp = strchr(tree, OS_DIRSEPC); if (cp) { delTree(root, cp + 1, errp); *cp = '\0'; @@ -509,7 +509,7 @@ delTree(char *root, char *tree, int *errp) /* since root is big enough, we reuse the space to * concatenate the dirname to the current tree */ - strcat(root, "/"); + strcat(root, OS_DIRSEP); strcat(root, dirp->d_name); if (afs_stat(root, &st) == 0 && S_ISDIR(st.st_mode)) { /* delete this subtree */ @@ -563,11 +563,11 @@ namei_RemoveDataDirectories(namei_t * name) char tmp[256]; int i; - afs_snprintf(tmp, 256, "%s\\%s", name->n_drive, name->n_voldir); + afs_snprintf(tmp, 256, "%s" OS_DIRSEP "%s", name->n_drive, name->n_voldir); path = tmp; path += strlen(path); - *path++ = '\\'; + *path++ = OS_DIRSEPC; *(path + 1) = '\0'; for (i = 'A'; i <= 'R'; i++) { *path = (char)i; @@ -2476,7 +2476,7 @@ namei_ListAFSSubDirs(IHandle_t * dirIH, dp2->d_name); #else /* Now we've got to the actual data */ - afs_snprintf(path3, sizeof(path3), "%s\\%s", path1, + afs_snprintf(path3, sizeof(path3), "%s" OS_DIRSEP "%s", path1, dp1->d_name); #endif dirp3 = opendir(path3); @@ -2614,7 +2614,7 @@ DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info, FdHandle_t linkHandle; char dirl; - afs_snprintf(fpath, sizeof(fpath), "%s\\%s", dpath, name); + afs_snprintf(fpath, sizeof(fpath), "%s" OS_DIRSEP "%s", dpath, name); dirH = FindFirstFileEx(fpath, FindExInfoStandard, &data, FindExSearchNameMatch, NULL, @@ -2650,8 +2650,8 @@ DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info, else { /* Open this handle */ char lpath[1024]; - (void)sprintf(lpath, "%s\\%s", fpath, data.cFileName); - linkHandle.fd_fd = nt_open(lpath, O_RDONLY, 0666); + (void)sprintf(lpath, "%s" OS_DIRSEP "%s", fpath, data.cFileName); + linkHandle.fd_fd = afs_open(lpath, O_RDONLY, 0666); info->linkCount = namei_GetLinkCount(&linkHandle, (Inode) 0, 0, 0, 0); } @@ -2660,11 +2660,11 @@ DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info, namei_GetLinkCount(&linkHandle, info->inodeNumber, 0, 0, 0); if (info->linkCount == 0) { #ifdef DELETE_ZLC - Log("Found 0 link count file %s\\%s, deleting it.\n", + Log("Found 0 link count file %s" OS_DIRSEP "%s, deleting it.\n", fpath, data.cFileName); AddToZLCDeleteList(dirl, data.cFileName); #else - Log("Found 0 link count file %s\\%s.\n", path, + Log("Found 0 link count file %s" OS_DIRSEP "%s.\n", path, data.cFileName); #endif } else { @@ -3070,7 +3070,7 @@ AddToZLCDeleteList(char dir, char *name) } if (dir) - (void)sprintf(zlcCur->zlc_names[zlcCur->zlc_n], "%c\\%s", dir, name); + (void)sprintf(zlcCur->zlc_names[zlcCur->zlc_n], "%c" OS_DIRSEP "%s", dir, name); else (void)sprintf(zlcCur->zlc_names[zlcCur->zlc_n], "%s", name); @@ -3087,7 +3087,7 @@ DeleteZLCFiles(char *path) for (z = zlcAnchor; z; z = z->zlc_next) { for (i = 0; i < z->zlc_n; i++) { if (path) - (void)sprintf(fname, "%s\\%s", path, z->zlc_names[i]); + (void)sprintf(fname, "%s" OS_DIRSEP "%s", path, z->zlc_names[i]); else (void)sprintf(fname, "%s", z->zlc_names[i]); if (namei_unlink(fname) < 0) { diff --git a/src/vol/nuke.c b/src/vol/nuke.c index c5e5a89c7..be8d1a790 100644 --- a/src/vol/nuke.c +++ b/src/vol/nuke.c @@ -154,7 +154,7 @@ nuke(char *aname, afs_int32 avolid) strcpy(devName, tfile); /* save this from the static buffer */ } /* aim lastDevComp at the 'foo' of '/dev/foo' */ - lastDevComp = strrchr(devName, '/'); + lastDevComp = strrchr(devName, OS_DIRSEPC); /* either points at slash, or there is no slash; adjust appropriately */ if (lastDevComp) lastDevComp++; diff --git a/src/vol/partition.c b/src/vol/partition.c index 4d302a78f..a6f9e27ff 100644 --- a/src/vol/partition.c +++ b/src/vol/partition.c @@ -258,7 +258,7 @@ VInitPartition_r(char *path, char *devname, Device dev) /* Create a lockfile for the partition, of the form /vicepa/Lock/vicepa */ dp->devName = (char *)malloc(2 * strlen(path) + 6); strcpy(dp->devName, path); - strcat(dp->devName, "/"); + strcat(dp->devName, OS_DIRSEP); strcat(dp->devName, "Lock"); mkdir(dp->devName, 0700); strcat(dp->devName, path); @@ -426,7 +426,7 @@ VIsAlwaysAttach(char *part, int *awouldattach) } strncpy(checkfile, part, 100); - strcat(checkfile, "/"); + strcat(checkfile, OS_DIRSEP); strcat(checkfile, VICE_ALWAYSATTACH_FILE); ret = afs_stat(checkfile, &st); @@ -450,9 +450,9 @@ VAttachPartitions2(void) char pname[32]; int wouldattach; - dirp = opendir("/"); + dirp = opendir(OS_DIRSEP); while ((de = readdir(dirp))) { - strcpy(pname, "/"); + strcpy(pname, OS_DIRSEP); strncat(pname, de->d_name, 20); pname[sizeof(pname) - 1] = '\0'; diff --git a/src/vol/vol-info.c b/src/vol/vol-info.c index 2e4f4ad1b..53e0aa35a 100644 --- a/src/vol/vol-info.c +++ b/src/vol/vol-info.c @@ -361,7 +361,7 @@ FindCurrentPartition(void) perror("pwd"); exit(1); } - p = strchr(&partName[1], '/'); + p = strchr(&partName[1], OS_DIRSEPC); if (p) { tmp = *p; *p = '\0'; diff --git a/src/vol/vol-salvage.c b/src/vol/vol-salvage.c index 3342d972e..5bee47e86 100644 --- a/src/vol/vol-salvage.c +++ b/src/vol/vol-salvage.c @@ -638,7 +638,7 @@ SalvageFileSysParallel(struct DiskPartition64 *partP) ShowLog = 0; for (fd = 0; fd < 16; fd++) close(fd); - open("/", 0); + open(OS_DIRSEP, 0); dup2(0, 1); dup2(0, 2); #ifndef AFS_NT40_ENV @@ -703,13 +703,13 @@ get_DevName(char *pbuffer, char *wpath) { char pbuf[128], *ptr; strcpy(pbuf, pbuffer); - ptr = (char *)strrchr(pbuf, '/'); + ptr = (char *)strrchr(pbuf, OS_DIRSEPC); if (ptr) { *ptr = '\0'; strcpy(wpath, pbuf); } else return NULL; - ptr = (char *)strrchr(pbuffer, '/'); + ptr = (char *)strrchr(pbuffer, OS_DIRSEPC); if (ptr) { strcpy(pbuffer, ptr + 1); return pbuffer; @@ -754,7 +754,7 @@ SalvageFileSys1(struct DiskPartition64 *partP, VolumeId singleVolumeNumber) #ifdef AFS_NT40_ENV /* Opendir can fail on "C:" but not on "C:\" if C is empty! */ - (void)sprintf(fileSysPath, "%s\\", fileSysPathName); + (void)sprintf(fileSysPath, "%s" OS_DIRSEP, fileSysPathName); name = partP->devName; #else fileSysPath = fileSysPathName; @@ -815,7 +815,7 @@ SalvageFileSys1(struct DiskPartition64 *partP, VolumeId singleVolumeNumber) char npath[1024]; Log("Removing old salvager temp files %s\n", dp->d_name); strcpy(npath, fileSysPath); - strcat(npath, "/"); + strcat(npath, OS_DIRSEP); strcat(npath, dp->d_name); unlink(npath); } @@ -827,7 +827,7 @@ SalvageFileSys1(struct DiskPartition64 *partP, VolumeId singleVolumeNumber) (void)_putenv("TMP="); /* If "TMP" is set, then that overrides tdir. */ (void)strncpy(inodeListPath, _tempnam(tdir, "salvage.inodes."), 255); #else - snprintf(inodeListPath, 255, "%s/salvage.inodes.%s.%d", tdir, name, + snprintf(inodeListPath, 255, "%s" OS_DIRSEP "salvage.inodes.%s.%d", tdir, name, getpid()); #endif @@ -1150,7 +1150,7 @@ GetInodeSummary(FILE *inodeFile, VolumeId singleVolumeNumber) (void)strcpy(summaryFileName, _tempnam(tdir, "salvage.temp")); #else (void)afs_snprintf(summaryFileName, sizeof summaryFileName, - "%s/salvage.temp.%d", tdir, getpid()); + "%s" OS_DIRSEP "salvage.temp.%d", tdir, getpid()); #endif summaryFile = afs_fopen(summaryFileName, "a+"); if (summaryFile == NULL) { @@ -1520,7 +1520,7 @@ RecordHeader(struct DiskPartition64 *dp, const char *name, /* check if the header file is incorrectly named */ int badname = 0; - const char *base = strrchr(name, '/'); + const char *base = strrchr(name, OS_DIRSEPC); if (base) { base++; } else { @@ -3235,7 +3235,7 @@ GetDirName(VnodeId vnode, struct VnodeEssence *vp, char *path) } if (vp->parent && vp->name && (parentvp = CheckVnodeNumber(vp->parent)) && GetDirName(vp->parent, parentvp, path)) { - strcat(path, "/"); + strcat(path, OS_DIRSEP); strcat(path, vp->name); return path; } diff --git a/src/vol/volume.c b/src/vol/volume.c index 7d294161e..421d5de6c 100644 --- a/src/vol/volume.c +++ b/src/vol/volume.c @@ -2372,7 +2372,7 @@ VAttachVolumeByName_r(Error * ec, char *partition, char *name, int mode) VOL_UNLOCK; - strcat(path, "/"); + strcat(path, OS_DIRSEP); strcat(path, name); if (!vp) { @@ -2570,7 +2570,7 @@ VAttachVolumeByVp_r(Error * ec, Volume * vp, int mode) VOL_UNLOCK; - strcat(path, "/"); + strcat(path, OS_DIRSEP); strcat(path, name); /* do volume attach @@ -5985,7 +5985,7 @@ VGetVolumePath(Error * ec, VolId volumeId, char **partitionp, char **namep) struct DiskPartition64 *dp; *ec = 0; - name[0] = '/'; + name[0] = OS_DIRSEPC; (void)afs_snprintf(&name[1], (sizeof name) - 1, VFORMAT, afs_printable_uint32_lu(volumeId)); for (dp = DiskPartitionList; dp; dp = dp->next) { struct afs_stat status; @@ -6014,14 +6014,14 @@ VGetVolumePath(Error * ec, VolId volumeId, char **partitionp, char **namep) * @return volume number * * @note the string must be of the form VFORMAT. the only permissible - * deviation is a leading '/' character. + * deviation is a leading OS_DIRSEPC character. * * @see VFORMAT */ int VolumeNumber(char *name) { - if (*name == '/') + if (*name == OS_DIRSEPC) name++; return atoi(name + 1); } -- 2.39.5