#include <sys/file.h>
#include <sys/param.h>
#include <lock.h>
-#ifdef AFS_AIX_ENV
-#include <sys/lockf.h>
-#endif
#if defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV)
#include <unistd.h>
#endif
/*@printflike@*/ extern void Log(const char *format, ...);
+#ifndef LOCK_SH
+#define LOCK_SH 1 /* shared lock */
+#define LOCK_EX 2 /* exclusive lock */
+#define LOCK_NB 4 /* don't block when locking */
+#define LOCK_UN 8 /* unlock */
+#endif
+
+#ifndef HAVE_FLOCK
+#include <fcntl.h>
+
+/*
+ * This function emulates a subset of flock()
+ */
+int
+emul_flock(int fd, int cmd)
+{ struct flock f;
+
+ memset(&f, 0, sizeof (f));
+
+ if (cmd & LOCK_UN)
+ f.l_type = F_UNLCK;
+ if (cmd & LOCK_SH)
+ f.l_type = F_RDLCK;
+ if (cmd & LOCK_EX)
+ f.l_type = F_WRLCK;
+
+ return fcntl(fd, (cmd & LOCK_NB) ? F_SETLK : F_SETLKW, &f);
+}
+
+#define flock(f,c) emul_flock(f,c)
+#endif
+
extern char *volutil_PartitionName_r(int volid, char *buf, int buflen);
int Testing=0;
namei_GetLCOffsetAndIndexFromIno(ino, &offset, &index);
if (lockit) {
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV)
- if (lockf(h->fd_fd, F_LOCK, 0) < 0)
-#else
if (flock(h->fd_fd, LOCK_EX) < 0)
-#endif
return -1;
}
bad_getLinkByte:
if (lockit)
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV)
- lockf(h->fd_fd, F_ULOCK, 0);
-#else
flock(h->fd_fd, LOCK_UN);
-#endif
return -1;
}
return -1;
/* Only one manipulates at a time. */
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV)
- if (lockf(fdP->fd_fd, F_LOCK, 0) < 0) {
-#else
if (flock(fdP->fd_fd, LOCK_EX) < 0) {
-#endif
FDH_REALLYCLOSE(fdP);
return -1;
}
goto badGetFreeTag;
}
FDH_SYNC(fdP);
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV)
- lockf(fdP->fd_fd, F_ULOCK, 0);
-#else
flock(fdP->fd_fd, LOCK_UN);
-#endif
FDH_REALLYCLOSE(fdP);
return col;;
badGetFreeTag:
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV)
- lockf(fdP->fd_fd, F_ULOCK, 0);
-#else
flock(fdP->fd_fd, LOCK_UN);
-#endif
FDH_REALLYCLOSE(fdP);
return -1;
}
namei_GetLCOffsetAndIndexFromIno(ino, &offset, &index);
if (!locked) {
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV)
- if (lockf(fdP->fd_fd, F_LOCK, 0) < 0) {
-#else
if (flock(fdP->fd_fd, LOCK_EX) < 0) {
-#endif
return -1;
}
}
bad_SetLinkCount:
-#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV)
- lockf(fdP->fd_fd, F_ULOCK, 0);
-#else
flock(fdP->fd_fd, LOCK_UN);
-#endif
return code;
}