From ca565530449861d0dee5fbbfc452e779f801846a Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Tue, 5 Sep 2006 15:50:57 +0000 Subject: [PATCH] STABLE14-windows-vol-ntops-20060904 add nt_SetNonZLC() (cherry picked from commit 474df74c88464763d61889fbdcc1edd1167d4a94) --- src/vol/ntops.c | 51 ++++++++++++++++++++++++++++++++++--------- src/vol/ntops.h | 2 ++ src/vol/vol-salvage.c | 13 +++++++++-- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/src/vol/ntops.c b/src/vol/ntops.c index 4285885341..1daa3fb5b0 100644 --- a/src/vol/ntops.c +++ b/src/vol/ntops.c @@ -41,6 +41,8 @@ RCSID #define BASEFILEATTRIBUTE FILE_ATTRIBUTE_NORMAL +int Testing = 0; + static void AddToZLCDeleteList(char dir, char *name); /* nt_unlink - unlink a case sensitive name. @@ -837,13 +839,17 @@ nt_GetLCOffsetAndIndexFromIno(Inode ino, int *offset, int *index) * If lockit is set, lock the file and leave it locked upon a successful * return. */ -int -nt_GetLinkCount(FdHandle_t * h, Inode ino, int lockit) +static int +nt_GetLinkCountInternal(FdHandle_t * h, Inode ino, int lockit, int fixup) { unsigned short row = 0; - int junk; + DWORD bytesRead, bytesWritten; int offset, index; + /* there's no linktable yet. the salvager will create one later */ + if (h->fd_fd == INVALID_HANDLE_VALUE && fixup) + return 1; + nt_GetLCOffsetAndIndexFromIno(ino, &offset, &index); if (lockit) { @@ -854,10 +860,25 @@ nt_GetLinkCount(FdHandle_t * h, Inode ino, int lockit) if (!SetFilePointer(h->fd_fd, (LONG) offset, NULL, FILE_BEGIN)) goto bad_getLinkByte; - if (!ReadFile(h->fd_fd, (void *)&row, 2, &junk, NULL)) { + if (!ReadFile(h->fd_fd, (void *)&row, 2, &bytesRead, NULL)) goto bad_getLinkByte; + + if (bytesRead == 0 && fixup) { + LARGE_INTEGER size; + + if (!GetFileSizeEx(h->fd_fd, &size) || size.QuadPart >= offset+sizeof(row)) + goto bad_getLinkByte; + FDH_TRUNC(h, offset+sizeof(row)); + row = 1 << index; + rewrite: + WriteFile(h->fd_fd, (char *)&row, sizeof(row), &bytesWritten, NULL); } + if (fixup && !((row >> index) & NT_TAGMASK)) { + row |= 1<> index) & NT_TAGMASK); bad_getLinkByte: @@ -866,7 +887,17 @@ nt_GetLinkCount(FdHandle_t * h, Inode ino, int lockit) return -1; } +int +nt_GetLinkCount(FdHandle_t * h, Inode ino, int lockit) +{ + return nt_GetLinkCountInternal(h, ino, lockit, 0); +} +void +nt_SetNonZLC(FdHandle_t * h, Inode ino) +{ + (void)nt_GetLinkCountInternal(h, ino, 0, 1); +} /* nt_SetLinkCount @@ -878,7 +909,7 @@ nt_SetLinkCount(FdHandle_t * h, Inode ino, int count, int locked) { int offset, index; unsigned short row; - int junk; + DWORD bytesRead, bytesWritten; int code = -1; nt_GetLCOffsetAndIndexFromIno(ino, &offset, &index); @@ -896,16 +927,16 @@ nt_SetLinkCount(FdHandle_t * h, Inode ino, int count, int locked) } - if (!ReadFile(h->fd_fd, (void *)&row, 2, &junk, NULL)) { + if (!ReadFile(h->fd_fd, (void *)&row, 2, &bytesRead, NULL)) { errno = nterr_nt2unix(GetLastError(), EBADF); goto bad_SetLinkCount; } - if (junk == 0) + if (bytesRead == 0) row = 0; - junk = 7 << index; + bytesRead = 7 << index; count <<= index; - row &= (unsigned short)~junk; + row &= (unsigned short)~bytesRead; row |= (unsigned short)count; if (!SetFilePointer(h->fd_fd, (LONG) offset, NULL, FILE_BEGIN)) { @@ -913,7 +944,7 @@ nt_SetLinkCount(FdHandle_t * h, Inode ino, int count, int locked) goto bad_SetLinkCount; } - if (!WriteFile(h->fd_fd, (void *)&row, 2, &junk, NULL)) { + if (!WriteFile(h->fd_fd, (void *)&row, 2, &bytesWritten, NULL)) { errno = nterr_nt2unix(GetLastError(), EBADF); goto bad_SetLinkCount; } diff --git a/src/vol/ntops.h b/src/vol/ntops.h index f1f1f36a47..572e5ee1da 100644 --- a/src/vol/ntops.h +++ b/src/vol/ntops.h @@ -60,4 +60,6 @@ int ListViceInodes(char *devname, char *mountedOn, char *resultFile, int nt_HandleToName(char *name, IHandle_t * h); char *nt_HandleToVolDir(char *name, IHandle_t * h); +extern int Testing; + #endif /* _NTOPS_H_ */ diff --git a/src/vol/vol-salvage.c b/src/vol/vol-salvage.c index 909ce1b723..76da9cba3c 100644 --- a/src/vol/vol-salvage.c +++ b/src/vol/vol-salvage.c @@ -1977,11 +1977,20 @@ DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols) fdP = IH_OPEN(VGLinkH); /* Sync fake 1 link counts to the link table, now that it exists */ if (fdP) { +#ifdef AFS_NT40_ENV + nt_SetNonZLC(fdP, ino); +#else namei_SetNonZLC(fdP, ino); +#endif for (i = 0; i < nVols; i++) { ip = allInodes + isp[i].index; - for (j = isp[i].nSpecialInodes; j < isp[i].nInodes; j++) - namei_SetNonZLC(fdP, ip[j].inodeNumber); + for (j = isp[i].nSpecialInodes; j < isp[i].nInodes; j++) { +#ifdef AFS_NT40_ENV + nt_SetNonZLC(fdP, ip[j].inodeNumber); +#else + namei_SetNonZLC(fdP, ip[j].inodeNumber); +#endif + } } } }