From owner-svn-src-head@freebsd.org Fri Jun 9 11:17:09 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 83A3CBF2291; Fri, 9 Jun 2017 11:17:09 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5DDB8366D; Fri, 9 Jun 2017 11:17:09 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v59BH8UK034018; Fri, 9 Jun 2017 11:17:08 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v59BH89l034016; Fri, 9 Jun 2017 11:17:08 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201706091117.v59BH89l034016@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 9 Jun 2017 11:17:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r319734 - in head/sys: compat/freebsd32 kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Jun 2017 11:17:09 -0000 Author: kib Date: Fri Jun 9 11:17:08 2017 New Revision: 319734 URL: https://svnweb.freebsd.org/changeset/base/319734 Log: Enhance vfs.ino64_trunc_error sysctl. Provide a new mode "2" which returns a special overflow indicator in the non-representable field instead of the silent truncation (mode "0") or EOVERFLOW (mode "1"). In particular, the typical use of st_ino to detect hard links with mode "2" reports false positives, which might be more suitable for some uses. Discussed with: bde Sponsored by: The FreeBSD Foundation Modified: head/sys/compat/freebsd32/freebsd32_misc.c head/sys/kern/vfs_syscalls.c Modified: head/sys/compat/freebsd32/freebsd32_misc.c ============================================================================== --- head/sys/compat/freebsd32/freebsd32_misc.c Fri Jun 9 07:08:58 2017 (r319733) +++ head/sys/compat/freebsd32/freebsd32_misc.c Fri Jun 9 11:17:08 2017 (r319734) @@ -1911,11 +1911,31 @@ freebsd11_cvtstat32(struct stat *in, struct freebsd11_ { CP(*in, *out, st_ino); - if (in->st_ino != out->st_ino && ino64_trunc_error) - return (EOVERFLOW); + if (in->st_ino != out->st_ino) { + switch (ino64_trunc_error) { + default: + case 0: + break; + case 1: + return (EOVERFLOW); + case 2: + out->st_ino = UINT32_MAX; + break; + } + } CP(*in, *out, st_nlink); - if (in->st_nlink != out->st_nlink && ino64_trunc_error) - return (EOVERFLOW); + if (in->st_nlink != out->st_nlink) { + switch (ino64_trunc_error) { + default: + case 0: + break; + case 1: + return (EOVERFLOW); + case 2: + out->st_nlink = UINT16_MAX; + break; + } + } CP(*in, *out, st_dev); CP(*in, *out, st_mode); CP(*in, *out, st_uid); Modified: head/sys/kern/vfs_syscalls.c ============================================================================== --- head/sys/kern/vfs_syscalls.c Fri Jun 9 07:08:58 2017 (r319733) +++ head/sys/kern/vfs_syscalls.c Fri Jun 9 11:17:08 2017 (r319734) @@ -2117,12 +2117,32 @@ freebsd11_cvtstat(struct stat *st, struct freebsd11_st ost->st_dev = st->st_dev; ost->st_ino = st->st_ino; - if (ost->st_ino != st->st_ino && ino64_trunc_error) - return (EOVERFLOW); + if (ost->st_ino != st->st_ino) { + switch (ino64_trunc_error) { + default: + case 0: + break; + case 1: + return (EOVERFLOW); + case 2: + ost->st_ino = UINT32_MAX; + break; + } + } ost->st_mode = st->st_mode; ost->st_nlink = st->st_nlink; - if (ost->st_nlink != st->st_nlink && ino64_trunc_error) - return (EOVERFLOW); + if (ost->st_nlink != st->st_nlink) { + switch (ino64_trunc_error) { + default: + case 0: + break; + case 1: + return (EOVERFLOW); + case 2: + ost->st_nlink = UINT16_MAX; + break; + } + } ost->st_uid = st->st_uid; ost->st_gid = st->st_gid; ost->st_rdev = st->st_rdev; @@ -3751,8 +3771,19 @@ freebsd11_kern_getdirentries(struct thread *td, int fd dstdp.d_type = dp->d_type; dstdp.d_namlen = dp->d_namlen; dstdp.d_fileno = dp->d_fileno; /* truncate */ - if (dstdp.d_fileno != dp->d_fileno && ino64_trunc_error) - continue; + if (dstdp.d_fileno != dp->d_fileno) { + switch (ino64_trunc_error) { + default: + case 0: + break; + case 1: + error = EOVERFLOW; + goto done; + case 2: + dstdp.d_fileno = UINT32_MAX; + break; + } + } dstdp.d_reclen = sizeof(dstdp) - sizeof(dstdp.d_name) + ((dp->d_namlen + 1 + 3) &~ 3); bcopy(dp->d_name, dstdp.d_name, dstdp.d_namlen);