[linux-cifs-client] ENOSPC without O_SYNC

Oliver Martin oliver.martin at student.tuwien.ac.at
Fri Jul 18 15:21:05 GMT 2008


Hello,

as of 2.6.26, the cifs kernel driver doesn't return ENOSPC on write()
if the file system on the server is full if the file is opened without
O_SYNC. ENOSPC is only returned on close(), but the man page doesn't
even mention it as a possible errno value there. It works correctly with
O_SYNC set.
Is that intended? It caused problems for me when I made a backup with
dar and forgot to tell it to pause after each slice so I could mount
another share. It's supposed to stop when it runs out of space, but it
kept copying data right into nowhere.
It dosen't matter if the server is Samba or Windows and it works with
fusesmb, so I suspect the problem is in the cifs module. Unfortunately,
I couldn't try smbfs because Debian has replaced mount.smbfs with a
wrapper around mount.cifs and I don't have any other distro here at the
moment.

Simple way to reproduce: Make a small loopback device, share it with
Samba, and fill it with something. Then use this small program to try
to create new files with and without O_SYNC and see the difference.

Kind regards,
Oliver

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char *argv[]) {
	int file, ret;
	char buf[10000];
	int sync = 0;

	if (argc != 2 && argc != 3) {
		printf("Usage: %s filename [sync]\n", argv[0]);
		return -1;
	}
	if (argc == 3 && strcmp(argv[2], "sync") == 0)
		sync = O_SYNC;

	memset(buf, 'a', sizeof(buf));
	file = open(argv[1], O_CREAT | O_RDWR | sync, 0644);
	printf("open()=%d; errno=%d\n", file, errno);
	ret = write(file, buf, sizeof(buf));
	printf("write()=%d; errno=%d\n", ret, errno);
	ret = close(file);
	printf("close()=%d; errno=%d\n", ret, errno);

	return 0;
}


More information about the linux-cifs-client mailing list