Skip to contentSkip to conversation

stat nlink resolution fix

PATCH In review Chris Wedgwood 2 participants 3 messages Jun 15, 2004 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 stat nlink resolution fix

(As already discussed)

Linus,

Some filesystems can get overflows when their link-count exceeds 65534. This patch increases the kernels internal resolution for this and also has a check for the old-system call paths to return and error (-EOVERFLOW) as required (as suggested by Al Viro).

fs/stat.c +4 -0
diff -Nru a/fs/stat.c b/fs/stat.c
@@ -131,6 +131,8 @@
 	tmp.st_ino = stat->ino;
 	tmp.st_mode = stat->mode;
 	tmp.st_nlink = stat->nlink;
+	if (tmp.st_nlink != stat->nlink)
+		return -EOVERFLOW;
 	SET_UID(tmp.st_uid, stat->uid);
 	SET_GID(tmp.st_gid, stat->gid);
 	tmp.st_rdev = old_encode_dev(stat->rdev);
@@ -199,6 +201,8 @@
 	tmp.st_ino = stat->ino;
 	tmp.st_mode = stat->mode;
 	tmp.st_nlink = stat->nlink;
+	if (tmp.st_nlink != stat->nlink)
+		return -EOVERFLOW;
 	SET_UID(tmp.st_uid, stat->uid);
 	SET_GID(tmp.st_gid, stat->gid);
 #if BITS_PER_LONG == 32
include/linux/stat.h +1 -1
diff -Nru a/include/linux/stat.h b/include/linux/stat.h
@@ -60,7 +60,7 @@
 	unsigned long	ino;
 	dev_t		dev;
 	umode_t		mode;
-	nlink_t		nlink;
+	unsigned int	nlink;
 	uid_t		uid;
 	gid_t		gid;
 	dev_t		rdev;
#1 lore raw
Quoted 12 lines · Chris Wedgwood

Some filesystems can get overflows when their link-count exceeds 65534. This patch increases the kernels internal resolution for this and also has a check for the old-system call paths to return and error (-EOVERFLOW) as required (as suggested by Al Viro).

diff -Nru a/include/linux/stat.h b/include/linux/stat.h

include/linux/stat.h line 66

Quoted 8 lines
include/linux/stat.h +1 -1
@@ -60,7 +60,7 @@
 	unsigned long	ino;
 	dev_t		dev;
 	umode_t		mode;
-	nlink_t		nlink;
+	unsigned int	nlink;
 	uid_t		uid;
 	gid_t		gid;
 	dev_t		rdev;

Just for me to get a clue, what would break if the definition of nlink_t changed?

Jörn

Signature · 3 lines
Fancy algorithms are buggier than simple ones, and they're much harder
to implement. Use simple algorithms as well as simple data structures.
-- Rob Pike
#2 lore raw
Quoted 2 lines · J?rn Engel

Just for me to get a clue, what would break if the definition of nlink_t changed?

It's derived from __kernel_nlink_t which is exported to userspace (well, glibc headers).

--cw