[linux-cifs-client] CIFS lock conversion issue

Jan Engelhardt jengelh at computergmbh.de
Tue Sep 4 15:08:51 GMT 2007


Hi,


when mount.cifs does not use UNIX extensions, then it is not possible to 
convert a read lock to a write lock, as demonstrated by below's 
testcase. To reproduce, mount a share from a UNIXless server (e.g. 
w2k3), or have unix extensions = no in smb.conf.

Result:
	0 [0 Success]
	-1 [13 Permission denied]

Is this behavior normal, and how could I upgrade the lock from read to 
write without races?

thanks,
	Jan
==
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(int argc, const char **argv)
{
	struct flock fl = {
		.l_whence = SEEK_SET,
		.l_type   = F_RDLCK,
		.l_start = 0,
		.l_len = 0,
	};
	struct flock flw = {
		.l_whence= SEEK_SET,
		.l_type=F_WRLCK,
		.l_start=0,
		.l_len=0,
	};
	int fd, ret;
	if (argc < 2) {
		fprintf(stderr, "Usage: %s FILENAME\n", *argv);
		return EXIT_FAILURE;
	}
	fd = open(argv[1], O_RDWR);
	ret = fcntl(fd, F_SETLK, &fl);
	printf("%d [%d, %s]\n", ret, errno, strerror(errno));
	ret = fcntl(fd, F_SETLK, &flw);
	printf("%d [%d, %s]\n", ret, errno, strerror(errno));
	return 0;
}


More information about the linux-cifs-client mailing list