From d6557a9cf7b76af62cba986428cf0362d42eae9a Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Wed, 23 Mar 2011 14:30:18 -0500 Subject: [PATCH] salvager: Fix conversion from stdio calls Commit 5247fa38a4faebfdffba178ca01e5b419f034d5d converted some I/O calls in the salvager from stdio to OS_OPEN/OS_WRITE/etc. Fix some of the conversions, including: - We need to pass O_CREAT to OS_OPEN calls, since we are creating these files - OS_WRITE returns the number of bytes written on success, not the number of "elements" like in stdio Change-Id: I789b7549c1eabeb821591bf9f42d810252fb11e1 Reviewed-on: http://gerrit.openafs.org/4293 Tested-by: BuildBot Reviewed-by: Jeffrey Altman Reviewed-by: Derrick Brashear --- src/vol/listinodes.c | 8 ++++---- src/vol/namei_ops.c | 4 ++-- src/vol/vol-salvage.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/vol/listinodes.c b/src/vol/listinodes.c index 8c3574997..32f57a663 100644 --- a/src/vol/listinodes.c +++ b/src/vol/listinodes.c @@ -298,7 +298,7 @@ ListViceInodes(char *devname, char *mountedOn, FD_t inodeFile, continue; if (inodeFile != INVALID_FD) { - if (OS_WRITE(inodeFile, &info, sizeof(info) * 1) != 1) { + if (OS_WRITE(inodeFile, &info, sizeof(info)) != sizeof(info)) { Log("Error writing inode file for partition %s\n", partition); goto out; } @@ -745,7 +745,7 @@ xfs_ListViceInodes(char *devname, char *mountedOn, FD_t inodeFile, if (inodeFile != INVALID_FD) { if (OS_WRITE (inodeFile, &info.ili_info, sizeof(vice_inode_info_t)) - != 1) { + != sizeof(vice_inode_info_t)) { Log("Error writing inode file for partition %s\n", mountedOn); goto err1_exit; } @@ -964,7 +964,7 @@ ListViceInodes(char *devname, char *mountedOn, FD_t inodeFile, if (judgeInode && (*judgeInode) (&info, judgeParam, rock) == 0) continue; if (inodeFile != INVALID_FD) { - if (OS_WRITE(inodeFile, &info, sizeof(info)) != 1) { + if (OS_WRITE(inodeFile, &info, sizeof(info)) != sizeof(info)) { Log("Error writing inode file for partition %s\n", partition); goto out; } @@ -1175,7 +1175,7 @@ ListViceInodes(char *devname, char *mountedOn, FD_t inodeFile, if (judgeInode && (*judgeInode) (&info, judgeParam, rock) == 0) continue; if (inodeFile != INVALID_FD) { - if (OS_WRITE(inodeFile, &info, sizeof(info)) != 1) { + if (OS_WRITE(inodeFile, &info, sizeof(info)) != sizeof(info)) { Log("Error writing inode file for partition %s\n", partition); goto out; diff --git a/src/vol/namei_ops.c b/src/vol/namei_ops.c index cb69e91e8..5601980f7 100644 --- a/src/vol/namei_ops.c +++ b/src/vol/namei_ops.c @@ -1596,7 +1596,7 @@ WriteInodeInfo(FD_t fp, struct ViceInodeInfo *info, char *dir, char *name) { size_t n; n = OS_WRITE(fp, info, sizeof(*info)); - return (n == 1) ? 0 : -2; + return (n == sizeof(*info)) ? 0 : -2; } @@ -1674,7 +1674,7 @@ ListViceInodes(char *devname, char *mountedOn, FD_t inodeFile, /* * Paranoia: check that the file is really the right size */ - if (OS_SIZE(inodeFile) * sizeof(struct ViceInodeInfo)) { + if (OS_SIZE(inodeFile) != ninodes * sizeof(struct ViceInodeInfo)) { Log("Wrong size (%d instead of %lu) in inode file for %s\n", (int) OS_SIZE(inodeFile), (long unsigned int) ninodes * sizeof(struct ViceInodeInfo), diff --git a/src/vol/vol-salvage.c b/src/vol/vol-salvage.c index 5fd41bf88..5ce3147da 100644 --- a/src/vol/vol-salvage.c +++ b/src/vol/vol-salvage.c @@ -823,7 +823,7 @@ SalvageFileSys1(struct DiskPartition64 *partP, VolumeId singleVolumeNumber) getpid()); #endif - inodeFile = OS_OPEN(inodeListPath, O_RDWR|O_TRUNC, 0666); + inodeFile = OS_OPEN(inodeListPath, O_RDWR|O_TRUNC|O_CREAT, 0666); if (inodeFile == INVALID_FD) { Abort("Error %d when creating inode description file %s; not salvaged\n", errno, inodeListPath); } @@ -1179,7 +1179,7 @@ GetInodeSummary(struct SalvInfo *salvinfo, FD_t inodeFile, VolumeId singleVolume (void)afs_snprintf(summaryFileName, sizeof summaryFileName, "%s" OS_DIRSEP "salvage.temp.%d", tdir, getpid()); #endif - summaryFile = OS_OPEN(summaryFileName, O_RDWR|O_APPEND, 0666); + summaryFile = OS_OPEN(summaryFileName, O_RDWR|O_APPEND|O_CREAT, 0666); if (summaryFile == INVALID_FD) { Abort("Unable to create inode summary file\n"); } -- 2.39.5