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
File Mode Size
COPYING.LIB -rw-r--r-- 24.7 KB
GENbzero.S -rw-r--r-- 3.2 KB
GENcopy_from_user.S -rw-r--r-- 577 bytes
GENcopy_to_user.S -rw-r--r-- 697 bytes
GENmemcpy.S -rw-r--r-- 1.9 KB
GENpage.S -rw-r--r-- 1.6 KB
GENpatch.S -rw-r--r-- 874 bytes
Makefile -rw-r--r-- 1.7 KB
NG2copy_from_user.S -rw-r--r-- 703 bytes
NG2copy_to_user.S -rw-r--r-- 955 bytes
NG2memcpy.S -rw-r--r-- 11.8 KB
NG2patch.S -rw-r--r-- 877 bytes
NG4clear_page.S -rw-r--r-- 642 bytes
NG4copy_from_user.S -rw-r--r-- 580 bytes
NG4copy_page.S -rw-r--r-- 1.5 KB
NG4copy_to_user.S -rw-r--r-- 829 bytes
NG4memcpy.S -rw-r--r-- 8.1 KB
NG4memset.S -rw-r--r-- 2.2 KB
NG4patch.S -rw-r--r-- 1.4 KB
NGbzero.S -rw-r--r-- 3.3 KB
NGcopy_from_user.S -rw-r--r-- 679 bytes
NGcopy_to_user.S -rw-r--r-- 752 bytes
NGmemcpy.S -rw-r--r-- 9.4 KB
NGpage.S -rw-r--r-- 3.5 KB
NGpatch.S -rw-r--r-- 866 bytes
PeeCeeI.c -rw-r--r-- 3.9 KB
U1copy_from_user.S -rw-r--r-- 720 bytes
U1copy_to_user.S -rw-r--r-- 716 bytes
U1memcpy.S -rw-r--r-- 14.5 KB
U3copy_from_user.S -rw-r--r-- 406 bytes
U3copy_to_user.S -rw-r--r-- 706 bytes
U3memcpy.S -rw-r--r-- 9.1 KB
U3patch.S -rw-r--r-- 881 bytes
VISsave.S -rw-r--r-- 2.9 KB
ashldi3.S -rw-r--r-- 462 bytes
ashrdi3.S -rw-r--r-- 556 bytes
atomic32.c -rw-r--r-- 2.8 KB
atomic_64.S -rw-r--r-- 2.8 KB
bitext.c -rw-r--r-- 2.8 KB
bitops.S -rw-r--r-- 2.4 KB
blockops.S -rw-r--r-- 2.5 KB
bzero.S -rw-r--r-- 3.3 KB
checksum_32.S -rw-r--r-- 16.8 KB
checksum_64.S -rw-r--r-- 3.8 KB
clear_page.S -rw-r--r-- 2.4 KB
cmpdi2.c -rw-r--r-- 435 bytes
copy_in_user.S -rw-r--r-- 1.6 KB
copy_page.S -rw-r--r-- 5.8 KB
copy_user.S -rw-r--r-- 10.4 KB
csum_copy.S -rw-r--r-- 6.9 KB
csum_copy_from_user.S -rw-r--r-- 439 bytes
csum_copy_to_user.S -rw-r--r-- 431 bytes
divdi3.S -rw-r--r-- 5.5 KB
ffs.S -rw-r--r-- 1.2 KB
hweight.S -rw-r--r-- 846 bytes
iomap.c -rw-r--r-- 522 bytes
ipcsum.S -rw-r--r-- 616 bytes
ksyms.c -rw-r--r-- 4.1 KB
libgcc.h -rw-r--r-- 262 bytes
locks.S -rw-r--r-- 1.9 KB
lshrdi3.S -rw-r--r-- 315 bytes
mcount.S -rw-r--r-- 2.5 KB
memcmp.S -rw-r--r-- 478 bytes
memcpy.S -rw-r--r-- 11.3 KB
memmove.S -rw-r--r-- 589 bytes
memscan_32.S -rw-r--r-- 1.8 KB
memscan_64.S -rw-r--r-- 2.2 KB
memset.S -rw-r--r-- 3.7 KB
muldi3.S -rw-r--r-- 1.9 KB
strlen.S -rw-r--r-- 1.5 KB
strncmp_32.S -rw-r--r-- 1.2 KB
strncmp_64.S -rw-r--r-- 449 bytes
ucmpdi2.c -rw-r--r-- 501 bytes
udivdi3.S -rw-r--r-- 5.3 KB
user_fixup.c -rw-r--r-- 1.8 KB
xor.S -rw-r--r-- 15.6 KB

back to top