Skip to content
Snippets Groups Projects
Commit 6000b760 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Clean up the OFD check/decision, make use of fcntl() locks easier to opt-in

parent b5ae6469
No related branches found
No related tags found
No related merge requests found
...@@ -70,24 +70,28 @@ off_t filelength(int fd) ...@@ -70,24 +70,28 @@ off_t filelength(int fd)
return(st.st_size); return(st.st_size);
} }
// See https://patchwork.kernel.org/patch/9289177/ /*************************************/
#if defined(F_OFD_SETLK) && _FILE_OFFSET_BITS != 64 /* Use OFD fcntl() locks when we can */
#undef F_OFD_SETLK /*************************************/
#endif #if defined __linux__
#define USE_FCNTL_LOCKS
#if defined(__linux__) && !defined(F_OFD_SETLK) // See https://patchwork.kernel.org/patch/9289177/
#warning Linux OFD locks not enabled! #if defined F_OFD_SETLK && _FILE_OFFSET_BITS != 64
#endif #undef F_OFD_SETLK
#endif
#if defined(F_OFD_SETLK)
#undef F_SETLK #if defined F_OFD_SETLK
#define F_SETLK F_OFD_SETLK #undef F_SETLK
#define F_SETLK F_OFD_SETLK
#else
#warning Linux OFD locks not enabled!
#endif
#endif #endif
/* Sets a lock on a portion of a file */ /* Sets a lock on a portion of a file */
int lock(int fd, off_t pos, off_t len) int lock(int fd, off_t pos, off_t len)
{ {
#if !defined(BSD) #if defined USE_FCNTL_LOCKS
struct flock alock = {0}; struct flock alock = {0};
// fcntl() will return EBADF if we try to set a write lock a file opened O_RDONLY // fcntl() will return EBADF if we try to set a write lock a file opened O_RDONLY
...@@ -117,7 +121,7 @@ int lock(int fd, off_t pos, off_t len) ...@@ -117,7 +121,7 @@ int lock(int fd, off_t pos, off_t len)
int unlock(int fd, off_t pos, off_t len) int unlock(int fd, off_t pos, off_t len)
{ {
#if !defined(BSD) #if defined USE_FCNTL_LOCKS
struct flock alock = {0}; struct flock alock = {0};
alock.l_type = F_UNLCK; /* remove the lock */ alock.l_type = F_UNLCK; /* remove the lock */
...@@ -195,7 +199,7 @@ int sopen(const char *fn, int sh_access, int share, ...) ...@@ -195,7 +199,7 @@ int sopen(const char *fn, int sh_access, int share, ...)
if (share == SH_DENYNO || share == SH_COMPAT) /* no lock needed */ if (share == SH_DENYNO || share == SH_COMPAT) /* no lock needed */
return fd; return fd;
#if !defined(BSD) #if defined USE_FCNTL_LOCKS
struct flock alock = {0}; // lock entire file from offset 0 struct flock alock = {0}; // lock entire file from offset 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment