From owner-freebsd-fs@FreeBSD.ORG Tue Apr 5 15:27:51 2011 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9752A106567F for ; Tue, 5 Apr 2011 15:27:51 +0000 (UTC) (envelope-from gljennjohn@googlemail.com) Received: from mail-wy0-f182.google.com (mail-wy0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id 287348FC1A for ; Tue, 5 Apr 2011 15:27:50 +0000 (UTC) Received: by wyf23 with SMTP id 23so483828wyf.13 for ; Tue, 05 Apr 2011 08:27:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:date:from:to:cc:subject:message-id:in-reply-to :references:reply-to:x-mailer:mime-version:content-type :content-transfer-encoding; bh=Qr8F+n/BOROgiQpKXB+baGVyZ/2Kf+xR9D8quzYSxwk=; b=hP/QjDMlIE+Ziw0kkNcvj3BQSBLCOayTjDoOQZbkjE72WtqBnCT9ruhODBcMttSAlm PC0HIOzO31rl492ujO8IC2l0uTPN7Nb5typWlr93hjcG5jVsZU8d7WCX4/TeM6sa4jQE u5Jj//MQCgGrQEY1GQ2jBAQIlbefq8cBsl76M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=date:from:to:cc:subject:message-id:in-reply-to:references:reply-to :x-mailer:mime-version:content-type:content-transfer-encoding; b=GUC8NB2jA38mahPyOmGj5/sn0yWaw42cvj79mnGa031M1QTiiJxR1FW4+jwvuMbb8E PgYWJ+wbWd4Qg5s/vKixrAr9qllV3L/k3LklljnpeB+p3LdBtqHMV5R3QApvpqnItJMw AD8J6asqNX84gceyxLywyqjqbM+5rlZ4junks= Received: by 10.227.147.196 with SMTP id m4mr8515652wbv.179.1302017270024; Tue, 05 Apr 2011 08:27:50 -0700 (PDT) Received: from ernst.jennejohn.org (p578E33EC.dip.t-dialin.net [87.142.51.236]) by mx.google.com with ESMTPS id ed10sm3635314wbb.32.2011.04.05.08.27.48 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Apr 2011 08:27:49 -0700 (PDT) Date: Tue, 5 Apr 2011 17:27:46 +0200 From: Gary Jennejohn To: Kostik Belousov Message-ID: <20110405172746.4a02fe42@ernst.jennejohn.org> In-Reply-To: <20110405141631.GA78089@deviant.kiev.zoral.com.ua> References: <20110405141631.GA78089@deviant.kiev.zoral.com.ua> X-Mailer: Claws Mail 3.7.8 (GTK+ 2.18.7; amd64-portbld-freebsd9.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-fs@freebsd.org Subject: Re: Knob to turn off _POSIX_NO_TRUNC X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: gljennjohn@googlemail.com List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Apr 2011 15:27:51 -0000 On Tue, 5 Apr 2011 17:16:31 +0300 Kostik Belousov wrote: > From very old and gloomy SysV times I remembered filesystem behaviour > that silently truncated the file name components to the NAME_MAX limit, > that was, AFAIR, 14. To much of my dismay, I met some usermode software > recently that blindly tried to create the file from externally provided > name, and sometimes failed with ENAMETOOLONG in similar situation. > The authors are not cooperative. > > I ended up with the following hack, which almost turns off the > _POSIX_NO_TRUNC behaviour, globally on the system. Patch allowed me > to proceed. The cost in the default case is a single check, which is > performed only on ENAMETOOLONG path. > > I am too chicken to commit it without prior discussion. > > diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c > index 50a2570..e9e7697 100644 > --- a/sys/kern/vfs_lookup.c > +++ b/sys/kern/vfs_lookup.c > @@ -99,6 +99,11 @@ SYSCTL_INT(_vfs, OID_AUTO, lookup_shared, CTLFLAG_RW, &lookup_shared, 0, > "Enables/Disables shared locks for path name translation"); > TUNABLE_INT("vfs.lookup_shared", &lookup_shared); > > +static int lookup_trim; > +SYSCTL_INT(_vfs, OID_AUTO, lookup_trim, CTLFLAG_RW, &lookup_trim, 0, > + "Enables/Disables trim of the long path component instead of ENAMETOOLONG"); > +TUNABLE_INT("vfs.lookup_trim", &lookup_trim); > + > /* > * Convert a pathname into a pointer to a locked vnode. > * > @@ -514,8 +519,14 @@ dirloop: > continue; > cnp->cn_namelen = cp - cnp->cn_nameptr; > if (cnp->cn_namelen > NAME_MAX) { > - error = ENAMETOOLONG; > - goto bad; > + if (!lookup_trim) { I would intuitively expect trimming to be enabled when the sysctl is set to 1, but this is exactly the opposite of that. I personally would initialize it to 1. > + error = ENAMETOOLONG; > + goto bad; > + } > + ndp->ni_pathlen -= cnp->cn_namelen - NAME_MAX; > + cnp->cn_namelen = NAME_MAX; > + strcpy(cnp->cn_nameptr + cnp->cn_namelen, cp); > + cp = cnp->cn_nameptr + cnp->cn_namelen; > } > #ifdef NAMEI_DIAGNOSTIC > { char c = *cp; I must admit that I don't care for hacks like this to suit the vagaries of some idiot software developers who never heard of POSIX. But as long as it's off by default, then I guess it would be acceptable. -- Gary Jennejohn (gj@)