https://github.com/torvalds/linux
Revision b928095b0a7cff7fb9fcf4c706348ceb8ab2c295 authored by Miklos Szeredi on 24 September 2014, 15:56:17 UTC, committed by Al Viro on 27 September 2014, 01:16:42 UTC
If overwriting an empty directory with rename, then need to drop the extra
nlink.

Test prog:

#include <stdio.h>
#include <fcntl.h>
#include <err.h>
#include <sys/stat.h>

int main(void)
{
	const char *test_dir1 = "test-dir1";
	const char *test_dir2 = "test-dir2";
	int res;
	int fd;
	struct stat statbuf;

	res = mkdir(test_dir1, 0777);
	if (res == -1)
		err(1, "mkdir(\"%s\")", test_dir1);

	res = mkdir(test_dir2, 0777);
	if (res == -1)
		err(1, "mkdir(\"%s\")", test_dir2);

	fd = open(test_dir2, O_RDONLY);
	if (fd == -1)
		err(1, "open(\"%s\")", test_dir2);

	res = rename(test_dir1, test_dir2);
	if (res == -1)
		err(1, "rename(\"%s\", \"%s\")", test_dir1, test_dir2);

	res = fstat(fd, &statbuf);
	if (res == -1)
		err(1, "fstat(%i)", fd);

	if (statbuf.st_nlink != 0) {
		fprintf(stderr, "nlink is %lu, should be 0\n", statbuf.st_nlink);
		return 1;
	}

	return 0;
}

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Cc: stable@vger.kernel.org
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 0f33be0
History
Tip revision: b928095b0a7cff7fb9fcf4c706348ceb8ab2c295 authored by Miklos Szeredi on 24 September 2014, 15:56:17 UTC
shmem: fix nlink for rename overwrite directory
Tip revision: b928095
File Mode Size
Makefile -rw-r--r-- 943 bytes
datagram.c -rw-r--r-- 21.0 KB
dev.c -rw-r--r-- 181.0 KB
dev_addr_lists.c -rw-r--r-- 20.8 KB
dev_ioctl.c -rw-r--r-- 12.7 KB
drop_monitor.c -rw-r--r-- 9.7 KB
dst.c -rw-r--r-- 10.1 KB
ethtool.c -rw-r--r-- 45.0 KB
fib_rules.c -rw-r--r-- 17.9 KB
filter.c -rw-r--r-- 30.4 KB
flow.c -rw-r--r-- 12.4 KB
flow_dissector.c -rw-r--r-- 9.4 KB
gen_estimator.c -rw-r--r-- 8.4 KB
gen_stats.c -rw-r--r-- 7.1 KB
iovec.c -rw-r--r-- 4.1 KB
link_watch.c -rw-r--r-- 5.4 KB
neighbour.c -rw-r--r-- 76.2 KB
net-procfs.c -rw-r--r-- 9.6 KB
net-sysfs.c -rw-r--r-- 33.3 KB
net-sysfs.h -rw-r--r-- 368 bytes
net-traces.c -rw-r--r-- 888 bytes
net_namespace.c -rw-r--r-- 15.3 KB
netclassid_cgroup.c -rw-r--r-- 2.5 KB
netevent.c -rw-r--r-- 2.1 KB
netpoll.c -rw-r--r-- 19.4 KB
netprio_cgroup.c -rw-r--r-- 6.4 KB
pktgen.c -rw-r--r-- 93.8 KB
ptp_classifier.c -rw-r--r-- 7.2 KB
request_sock.c -rw-r--r-- 7.0 KB
rtnetlink.c -rw-r--r-- 73.8 KB
scm.c -rw-r--r-- 7.6 KB
secure_seq.c -rw-r--r-- 4.1 KB
skbuff.c -rw-r--r-- 99.8 KB
sock.c -rw-r--r-- 73.5 KB
sock_diag.c -rw-r--r-- 5.5 KB
stream.c -rw-r--r-- 5.1 KB
sysctl_net_core.c -rw-r--r-- 9.3 KB
timestamping.c -rw-r--r-- 2.7 KB
tso.c -rw-r--r-- 2.0 KB
user_dma.c -rw-r--r-- 3.3 KB
utils.c -rw-r--r-- 8.8 KB

back to top