#include <direct.h>
#endif
-#include <afs/afs_assert.h>
#include <lock.h>
#include <afs/afsutil.h>
#include <lwp.h>
return -1;
nBytes = FDH_PREAD(fdP, buf, size, offset);
- FDH_CLOSE(fdP);
+ if (nBytes < 0)
+ FDH_REALLYCLOSE(fdP);
+ else
+ FDH_CLOSE(fdP);
return nBytes;
}
return -1;
nBytes = FDH_PWRITE(fdP, buf, size, offset);
- FDH_CLOSE(fdP);
+ if (nBytes < 0)
+ FDH_REALLYCLOSE(fdP);
+ else
+ FDH_CLOSE(fdP);
return nBytes;
}
}
static int
-CheckOGM(namei_t *name, FdHandle_t *fdP, int p1)
+SetWinOGM(FD_t fd, int p1, int p2)
{
- WIN32_FIND_DATA info;
- HANDLE dirH;
+ BOOL code;
+ FILETIME ftime;
+
+ ftime.dwHighDateTime = p1;
+ ftime.dwLowDateTime = p2;
+
+ code = SetFileTime(fd, &ftime, NULL /*access*/, NULL /*write*/);
+ if (!code)
+ return -1;
+ return 0;
+}
+
+static int
+GetWinOGM(FD_t fd, int *p1, int *p2)
+{
+ BOOL code;
+ FILETIME ftime;
+
+ code = GetFileTime(fd, &ftime, NULL /*access*/, NULL /*write*/);
+ if (!code)
+ return -1;
- dirH =
- FindFirstFileEx(name->n_path, FindExInfoStandard, &info,
- FindExSearchNameMatch, NULL,
- FIND_FIRST_EX_CASE_SENSITIVE);
+ *p1 = ftime.dwHighDateTime;
+ *p2 = ftime.dwLowDateTime;
- if (!dirH)
- return -1; /* Can't get info, leave alone */
+ return 0;
+}
- FindClose(dirH);
+static int
+CheckOGM(FdHandle_t *fdP, int p1)
+{
+ int ogm_p1, ogm_p2;
- if (info.ftCreationTime.dwHighDateTime != (unsigned int)p1)
+ if (GetWinOGM(fdP->fd_fd, &ogm_p1, &ogm_p2)) {
return -1;
+ }
+
+ if (ogm_p1 != p1) {
+ return -1;
+ }
return 0;
}
}
static int
-CheckOGM(namei_t *name, FdHandle_t *fdP, int p1)
+GetOGM(FdHandle_t *fdP, int *parm, int *tag)
{
struct afs_stat_st status;
- int parm, tag;
if (afs_fstat(fdP->fd_fd, &status) < 0)
return -1;
+ GetOGMFromStat(&status, parm, tag);
+ return 0;
+}
- GetOGMFromStat(&status, &parm, &tag);
+static int
+CheckOGM(FdHandle_t *fdP, int p1)
+{
+ int parm, tag;
+
+ if (GetOGM(fdP, &parm, &tag) < 0)
+ return -1;
if (parm != p1)
return -1;
FdHandle_t *fdP;
FdHandle_t tfd;
int type, tag;
- FILETIME ftime;
+ int ogm_p1, ogm_p2;
char *p;
b32_string_t str1;
* p3 - type
* p4 - parent volume id
*/
- ftime.dwHighDateTime = p1;
- ftime.dwLowDateTime = p2;
+ ogm_p1 = p1;
+ ogm_p2 = p2;
type = p3;
tmp.ih_vid = p4; /* Use parent volume id, where this file will be. */
tmp.ih_ino = namei_MakeSpecIno(p1, p3);
tmp.ih_vid = p1;
tmp.ih_ino = (Inode) p2;
- ftime.dwHighDateTime = p3;
- ftime.dwLowDateTime = p4;
+ ogm_p1 = p3;
+ ogm_p2 = p4;
}
namei_HandleToName(&name, &tmp);
p++;
for (tag = 0; tag < NAMEI_MAXVOLS; tag++) {
*p = *int_to_base32(str1, tag);
- fd = OS_OPEN((char *)&name.n_path, O_CREAT | O_RDWR | O_TRUNC | O_EXCL, 0666);
+ fd = OS_OPEN((char *)&name.n_path, O_CREAT | O_RDWR | O_EXCL, 0666);
if (fd == INVALID_FD) {
if (errno == ENOTDIR || errno == ENOENT) {
if (namei_CreateDataDirectories(&name, &created_dir) == 0)
- fd = OS_OPEN((char *)&name.n_path, O_CREAT | O_RDWR | O_TRUNC | O_EXCL, 0666);
+ fd = OS_OPEN((char *)&name.n_path, O_CREAT | O_RDWR | O_EXCL, 0666);
}
}
tmp.ih_ino |= (((Inode) tag) << NAMEI_TAGSHIFT);
if (!code) {
- if (!SetFileTime((HANDLE) fd, &ftime, NULL, NULL)) {
+ if (SetWinOGM(fd, ogm_p1, ogm_p2)) {
errno = OS_ERROR(EBADF);
code = -1;
}
}
namei_HandleToName(&name, &tmp);
- fd = OS_OPEN(name.n_path, O_CREAT | O_EXCL | O_TRUNC | O_RDWR, 0);
+ fd = OS_OPEN(name.n_path, O_CREAT | O_EXCL | O_RDWR, 0);
if (fd == INVALID_FD) {
if (errno == ENOTDIR || errno == ENOENT) {
if (namei_CreateDataDirectories(&name, &created_dir) < 0)
goto bad;
- fd = OS_OPEN(name.n_path, O_CREAT | O_EXCL | O_TRUNC | O_RDWR,
+ fd = OS_OPEN(name.n_path, O_CREAT | O_EXCL | O_RDWR,
0);
if (fd == INVALID_FD)
goto bad;
return -1;
}
- if (CheckOGM(&name, fdP, p1) < 0) {
+ if (CheckOGM(fdP, p1) < 0) {
FDH_REALLYCLOSE(fdP);
IH_RELEASE(tmp);
errno = OS_ERROR(EINVAL);
/* Try to remove directory. If it fails, that's ok.
* Salvage will clean up.
*/
+ char *slash = strrchr(name.n_path, OS_DIRSEPC);
+ if (slash) {
+ /* avoid an rmdir() on the file we just unlinked */
+ *slash = '\0';
+ }
(void)namei_RemoveDataDirectories(&name);
}
}
if (!fdP)
return EIO;
snprintf(path, sizeof(path), "%s-tmp", name.n_path);
- fd = OS_OPEN(path, O_CREAT | O_EXCL | O_TRUNC | O_RDWR, 0);
+ fd = OS_OPEN(path, O_CREAT | O_EXCL | O_RDWR, 0);
if (fd == INVALID_FD) {
FDH_CLOSE(fdP);
return EIO;
}
rc = FDH_PREAD(h, (char*)&row, sizeof(row), offset);
+ if (rc == -1)
+ goto bad_getLinkByte;
+
if ((rc == 0 || !((row >> index) & NAMEI_TAGMASK)) && fixup && nowrite)
return 1;
if (rc == 0 && fixup) {
if (FDH_PWRITE(fdP, (char *)&row, sizeof(row), offset) != sizeof(row)) {
goto badGetFreeTag;
}
- FDH_SYNC(fdP);
+ (void)FDH_SYNC(fdP);
FDH_UNLOCKFILE(fdP, offset);
FDH_CLOSE(fdP);
return col;
errno = OS_ERROR(EBADF);
goto bad_SetLinkCount;
}
- FDH_SYNC(fdP);
+ (void)FDH_SYNC(fdP);
nBytes = 0;
}
t_ih.ih_ino = namei_MakeSpecIno(ih->ih_vid, VI_VOLINFO);
namei_HandleToName(&n, &t_ih);
- fd2 = OS_OPEN(n.n_path, O_CREAT | O_EXCL | O_TRUNC | O_RDWR, 0);
+ fd2 = OS_OPEN(n.n_path, O_CREAT | O_EXCL | O_RDWR, 0);
if (fd2 == INVALID_FD) {
Log("1 namei_ConvertROtoRWvolume: could not create RW info file: %s\n", n.n_path);
OS_CLOSE(fd);