Problems with support of file locks for ARC (maybe for other targets too)

Yuriy Kolerov Yuriy.Kolerov at synopsys.com
Tue Aug 9 17:06:21 UTC 2016


Hi,

I have some questions about uClibc and support of ARC targets.

1. uClibc does not support OFD locks (https://lwn.net/Articles/586904/). fcntl.h headers for all targets are not synchronized with Linux source tree and does not contain these defines:

------------------------ 8< ------------------------
#define F_OFD_GETLK 36
#define F_OFD_SETLK 37
#define F_OFD_SETLKW 38
------------------------ 8< ------------------------

Also appropriate changes must be done in "libc/sysdeps/linux/common/__syscall_fcntl.c". I am not sure how to do it in the proper manner because it involves a lot of duplication for each target...

2. uClibc uses fcntl64 instead of fcntl by default:
http://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/libc/sysdeps/linux/common/__syscall_fcntl.c

Also if you want to use file locks you need to pass flock or flock64 structure to fcntl which are defined in fcntl.h for each target. E.g. for ARC:
http://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/libc/sysdeps/linux/arc/bits/fcntl.h

So if fcntl64 is used by default then flock must be identical to flock64 in this case. That is why flock and flock64 are defined this way:

------------------------ 8< ------------------------
struct flock
  {
    short int l_type;	/* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.	*/
    short int l_whence;	/* Where `l_start' is relative to (like `lseek').  */
#ifndef __USE_FILE_OFFSET64
    __off_t l_start;	/* Offset where the lock begins.  */
    __off_t l_len;	/* Size of the locked area; zero means until EOF.  */
#else
    __off64_t l_start;	/* Offset where the lock begins.  */
    __off64_t l_len;	/* Size of the locked area; zero means until EOF.  */
#endif
    __pid_t l_pid;	/* Process holding the lock.  */
  };

#ifdef __USE_LARGEFILE64
struct flock64
  {
    short int l_type;	/* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.	*/
    short int l_whence;	/* Where `l_start' is relative to (like `lseek').  */
    __off64_t l_start;	/* Offset where the lock begins.  */
    __off64_t l_len;	/* Size of the locked area; zero means until EOF.  */
    __pid_t l_pid;	/* Process holding the lock.  */
  };
#endif
------------------------ 8< ------------------------

Macros __USE_FILE_OFFSET64 and __USE_LARGEFILE64 are defined in features.h when the compiler have these defines:

------------------------ 8< ------------------------
#define _FILE_OFFSET_BITS 64
#define _LARGEFILE64_SOURCE
------------------------ 8< ------------------------

So if you want to use locks you should always define those macros. Moreover the whole uClibc and every application must be compiled with those macros. Here is my question. Is it acceptable just to compile toolchain itself using CFLAGS_FOR_TARGET with those macros and don't define them manually in each application?

Regards,
Yuriy Kolerov



More information about the uClibc mailing list