From owner-freebsd-current@FreeBSD.ORG Fri Jun 27 23:06:56 2014 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3F33F912; Fri, 27 Jun 2014 23:06:56 +0000 (UTC) Received: from anubis.delphij.net (anubis.delphij.net [64.62.153.212]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "anubis.delphij.net", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 205862776; Fri, 27 Jun 2014 23:06:55 +0000 (UTC) Received: from zeta.ixsystems.com (unknown [69.198.165.132]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by anubis.delphij.net (Postfix) with ESMTPSA id 9B7051EF64; Fri, 27 Jun 2014 16:06:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=delphij.net; s=anubis; t=1403910414; bh=W52KwIB6MWvXjtFUgm+D66s28ER1OAhbdV+3w7P4Na0=; h=Date:From:Reply-To:To:CC:Subject:References:In-Reply-To; b=QzedTZ3rQLbMki5pg3RRLNwQLGNPpxuiueb2ZOeuUkgBKluGixArIXmrveOBJNEh9 FfZjrwbFWfodiI2F6RNfl9046xv3rCCOss/i1gVBB9yRZju9bhqoSi0RwEKCeJbJZr T8wj952M3RDAZRw9yNnNPCtwqzkewV2kN5lvbssc= Message-ID: <53ADF90D.2030707@delphij.net> Date: Fri, 27 Jun 2014 16:06:53 -0700 From: Xin Li Reply-To: d@delphij.net Organization: The FreeBSD Project MIME-Version: 1.0 To: Jilles Tjoelker , Xin LI Subject: Re: svn commit: r267977 - head/bin/mv References: <201406271957.s5RJvs6j074326@svn.freebsd.org> <20140627222323.GA43131@stack.nl> In-Reply-To: <20140627222323.GA43131@stack.nl> X-Enigmail-Version: 1.6 Content-Type: multipart/mixed; boundary="------------020002050206020306060303" Cc: FreeBSD Current , "Kenneth D. Merry" X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Jun 2014 23:06:56 -0000 This is a multi-part message in MIME format. --------------020002050206020306060303 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit [moving discussion to freebsd-current@] On 06/27/14 15:23, Jilles Tjoelker wrote: > On Fri, Jun 27, 2014 at 07:57:54PM +0000, Xin LI wrote: >> Author: delphij >> Date: Fri Jun 27 19:57:54 2014 >> New Revision: 267977 >> URL: http://svnweb.freebsd.org/changeset/base/267977 > >> Log: >> Always set UF_ARCHIVE on target (because they are by definition new files >> and should be archived) and ignore error when we can't set it (e.g. NFS). > >> Reviewed by: ken >> MFC after: 2 weeks > >> Modified: >> head/bin/mv/mv.c > >> Modified: head/bin/mv/mv.c >> ============================================================================== >> --- head/bin/mv/mv.c Fri Jun 27 19:50:30 2014 (r267976) >> +++ head/bin/mv/mv.c Fri Jun 27 19:57:54 2014 (r267977) >> @@ -337,8 +337,8 @@ err: if (unlink(to)) >> * on a file that we copied, i.e., that we didn't create.) >> */ >> errno = 0; >> - if (fchflags(to_fd, sbp->st_flags)) >> - if (errno != EOPNOTSUPP || sbp->st_flags != 0) >> + if (fchflags(to_fd, sbp->st_flags | UF_ARCHIVE)) >> + if (errno != EOPNOTSUPP || ((sbp->st_flags & ~UF_ARCHIVE) != 0)) >> warn("%s: set flags (was: 0%07o)", to, sbp->st_flags); >> >> tval[0].tv_sec = sbp->st_atime; > > The part ignoring failures to set UF_ARCHIVE is OK. However, it seems > inconsistent to set UF_ARCHIVE on a cross-filesystem mv of a single > file, but not on a cross-filesystem mv of a directory tree or a file > newly created via shell output redirection. > > If UF_ARCHIVE is supposed to be set automatically, I think this should > be done in the kernel, like msdosfs already does. However, I'm not sure > this is actually a useful feature: backup programs are smarter than an > archive attribute these days. The flag is supposed to be set automatically (as my understanding of the ZFS portion of implementation). However in order to implement that way, we will have to stat() the target file (attached). Personally, I think this is a little bit wasteful, but it would probably something that we have to do if we implement a switch to turn off automatic UF_ARCHIVE behavior. Cheers -- Xin LI https://www.delphij.net/ FreeBSD - The Power to Serve! Live free or die --------------020002050206020306060303 Content-Type: text/plain; charset=UTF-8; name="mv.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="mv.diff" Index: bin/mv/mv.c =================================================================== --- bin/mv/mv.c (revision 267984) +++ bin/mv/mv.c (working copy) @@ -278,6 +278,7 @@ fastcopy(const char *from, const char *to, struct static char *bp = NULL; mode_t oldmode; int nread, from_fd, to_fd; + struct stat to_sb; if ((from_fd = open(from, O_RDONLY, 0)) < 0) { warn("fastcopy: open() failed (from): %s", from); @@ -329,6 +330,7 @@ err: if (unlink(to)) */ preserve_fd_acls(from_fd, to_fd, from, to); (void)close(from_fd); + /* * XXX * NFS doesn't support chflags; ignore errors unless there's reason @@ -336,10 +338,19 @@ err: if (unlink(to)) * if the server supports flags and we were trying to *remove* flags * on a file that we copied, i.e., that we didn't create.) */ - errno = 0; - if (fchflags(to_fd, sbp->st_flags | UF_ARCHIVE)) - if (errno != EOPNOTSUPP || ((sbp->st_flags & ~UF_ARCHIVE) != 0)) - warn("%s: set flags (was: 0%07o)", to, sbp->st_flags); + if (fstat(to_fd, &to_sb) == 0) { + if ((sbp->st_flags & ~UF_ARCHIVE) != + (to_sb.st_flags & ~UF_ARCHIVE)) { + errno = 0; + if (fchflags(to_fd, + sbp->st_flags | (to_sb.st_flags & UF_ARCHIVE))) + if (errno != EOPNOTSUPP || + ((sbp->st_flags & ~UF_ARCHIVE) != 0)) + warn("%s: set flags (was: 0%07o)", + to, sbp->st_flags); + } + } else + warn("%s: can not stat", to); tval[0].tv_sec = sbp->st_atime; tval[1].tv_sec = sbp->st_mtime; --------------020002050206020306060303--