From unknown Sat Jun 21 03:21:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6268: Suggestion: truncate should allow -r and -s options together Resent-From: "Richard W.M. Jones" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Tue, 25 May 2010 15:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 6268 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 6268@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.127480207620100 (code B ref -1); Tue, 25 May 2010 15:42:02 +0000 Received: (at submit) by debbugs.gnu.org; 25 May 2010 15:41:16 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OGwFm-0005E8-Fi for submit@debbugs.gnu.org; Tue, 25 May 2010 11:41:15 -0400 Received: from mx10.gnu.org ([199.232.76.166]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OGvB8-0004hW-18 for submit@debbugs.gnu.org; Tue, 25 May 2010 10:32:23 -0400 Received: from lists.gnu.org ([199.232.76.165]:56678) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1OGvB2-0000P4-VO for submit@debbugs.gnu.org; Tue, 25 May 2010 10:32:17 -0400 Received: from [140.186.70.92] (port=44932 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGvB0-0006IG-Jy for bug-coreutils@gnu.org; Tue, 25 May 2010 10:32:15 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.1 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OGvAv-0005Gt-BB for bug-coreutils@gnu.org; Tue, 25 May 2010 10:32:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20330) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OGvAu-0005Gb-TT for bug-coreutils@gnu.org; Tue, 25 May 2010 10:32:09 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4PEW7ne015887 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 25 May 2010 10:32:07 -0400 Received: from localhost (vpn1-7-239.ams2.redhat.com [10.36.7.239]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4PEW5gc024216 for ; Tue, 25 May 2010 10:32:06 -0400 Date: Tue, 25 May 2010 15:32:05 +0100 From: "Richard W.M. Jones" Message-ID: <20100525143205.GB19557@amd.home.annexia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Spam-Score: -3.3 (---) X-Mailman-Approved-At: Tue, 25 May 2010 11:41:13 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.6 (----) The manpage for truncate says: Note that the -r and -s options are mutually exclusive. and indeed you cannot have both: $ truncate -r /tmp/ref -s +10M /tmp/new truncate: you must specify one of `--size' or `--reference' We suggest using the 'truncate' command in the 'virt-resize' documentation[1]. We want users to create a file which is the size of an existing file + some extra amount. Naturally this would be: truncate -r old-disk.img -s +1G new-disk.img but this does not work and we have to suggest that users use two separate 'truncate' commands[2]. Related to this feature request, it would be nice if you could suffix a size with a % sign to indicate that you want to increase a file by a certain percentage of the old or reference size, eg: truncate -r old-disk.img -s +10% new-disk.img truncate -r old-disk.img -s 110% new-disk.img Neither of these forms work at the moment. Rich. [1] http://libguestfs.org/virt-resize.1.html#expanding_a_virtual_machine_disk [2] http://git.annexia.org/?p=libguestfs.git;a=commitdiff;h=0e28e4104d96bf0bf5b88fb07bb7e5f9f6e6f41f#patch1 -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora From unknown Sat Jun 21 03:21:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6268: Suggestion: truncate should allow -r and -s options together Resent-From: =?UTF-8?Q?P=C3=A1draig?= Brady Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Wed, 26 May 2010 01:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6268 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: "Richard W.M. Jones" Cc: 6268@debbugs.gnu.org Received: via spool by 6268-submit@debbugs.gnu.org id=B6268.12748358616170 (code B ref 6268); Wed, 26 May 2010 01:05:02 +0000 Received: (at 6268) by debbugs.gnu.org; 26 May 2010 01:04:21 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OH52i-0001bT-LB for submit@debbugs.gnu.org; Tue, 25 May 2010 21:04:20 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1OH52f-0001bL-KC for 6268@debbugs.gnu.org; Tue, 25 May 2010 21:04:18 -0400 Received: (qmail 92602 invoked from network); 26 May 2010 01:04:13 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 26 May 2010 01:04:13 -0000 Message-ID: <4BFC72E5.9060908@draigBrady.com> Date: Wed, 26 May 2010 02:01:25 +0100 From: =?UTF-8?Q?P=C3=A1draig?= Brady User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 References: <20100525143205.GB19557@amd.home.annexia.org> In-Reply-To: <20100525143205.GB19557@amd.home.annexia.org> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -1.5 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.8 (--) On 25/05/10 15:32, Richard W.M. Jones wrote: > The manpage for truncate says: > > Note that the -r and -s options are mutually exclusive. > > and indeed you cannot have both: > > $ truncate -r /tmp/ref -s +10M /tmp/new > truncate: you must specify one of `--size' or `--reference' > > We suggest using the 'truncate' command in the 'virt-resize' > documentation[1]. We want users to create a file which is the size of > an existing file + some extra amount. Naturally this would be: > > truncate -r old-disk.img -s +1G new-disk.img > > but this does not work and we have to suggest that users use two > separate 'truncate' commands[2]. That seems like a worthwhile change. I.E. allow relative --size with -r. I'll cook up a patch in the morning. > Related to this feature request, it would be nice if you could suffix > a size with a % sign to indicate that you want to increase a file by a > certain percentage of the old or reference size, eg: > > truncate -r old-disk.img -s +10% new-disk.img > > truncate -r old-disk.img -s 110% new-disk.img I'm a little less enthusiastic about the need for that. Given how awkward it is to achieve then I might do it (as a separate patch). Here's how you'd might do it handling overflow currently: truncate -s$(echo "$(stat --format %s file) * 1.1" | bc | cut -d. -f1) file I guess it would be OK to truncate the result rather than round to nearest? cheers, Pádraig. From unknown Sat Jun 21 03:21:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6268: Suggestion: truncate should allow -r and -s options together Resent-From: =?UTF-8?Q?P=C3=A1draig?= Brady Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Wed, 26 May 2010 08:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6268 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: "Richard W.M. Jones" Cc: 6268@debbugs.gnu.org Received: via spool by 6268-submit@debbugs.gnu.org id=B6268.127486426618403 (code B ref 6268); Wed, 26 May 2010 08:58:02 +0000 Received: (at 6268) by debbugs.gnu.org; 26 May 2010 08:57:46 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OHCQr-0004mm-A9 for submit@debbugs.gnu.org; Wed, 26 May 2010 04:57:45 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1OHCQo-0004mh-9n for 6268@debbugs.gnu.org; Wed, 26 May 2010 04:57:43 -0400 Received: (qmail 43001 invoked from network); 26 May 2010 08:57:38 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 26 May 2010 08:57:38 -0000 Message-ID: <4BFCE1D7.5060308@draigBrady.com> Date: Wed, 26 May 2010 09:54:47 +0100 From: =?UTF-8?Q?P=C3=A1draig?= Brady User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 References: <20100525143205.GB19557@amd.home.annexia.org> <4BFC72E5.9060908@draigBrady.com> In-Reply-To: <4BFC72E5.9060908@draigBrady.com> X-Enigmail-Version: 1.0.1 Content-Type: multipart/mixed; boundary="------------000604010903040209050509" X-Spam-Score: -1.5 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.8 (--) This is a multi-part message in MIME format. --------------000604010903040209050509 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit On 26/05/10 02:01, Pádraig Brady wrote: > On 25/05/10 15:32, Richard W.M. Jones wrote: >> The manpage for truncate says: >> >> Note that the -r and -s options are mutually exclusive. >> >> and indeed you cannot have both: >> >> $ truncate -r /tmp/ref -s +10M /tmp/new >> truncate: you must specify one of `--size' or `--reference' >> >> We suggest using the 'truncate' command in the 'virt-resize' >> documentation[1]. We want users to create a file which is the size of >> an existing file + some extra amount. Naturally this would be: >> >> truncate -r old-disk.img -s +1G new-disk.img >> >> but this does not work and we have to suggest that users use two >> separate 'truncate' commands[2]. > > That seems like a worthwhile change. > I.E. allow relative --size with -r. > I'll cook up a patch in the morning Attached. >> Related to this feature request, it would be nice if you could suffix >> a size with a % sign to indicate that you want to increase a file by a >> certain percentage of the old or reference size, eg: >> >> truncate -r old-disk.img -s +10% new-disk.img >> >> truncate -r old-disk.img -s 110% new-disk.img > > I'm a little less enthusiastic about the need for that. > Given how awkward it is to achieve then I might do it > (as a separate patch). Here's how you'd might do it > handling overflow currently: > > truncate -s$(echo "$(stat --format %s file) * 1.1" | bc | cut -d. -f1) file > > I guess it would be OK to truncate the result > rather than round to nearest? With multi-precision expr now in fedora one could simplify to: truncate -s$(expr $(stat --format %s file) '*' 110 / 100) file I'm still not convinced it's worth bringing % calculations within truncate. cheers, Pádraig. --------------000604010903040209050509 Content-Type: text/x-patch; name="truncate-relative-to-file.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="truncate-relative-to-file.diff" >From 63786cdaf2189d326d837a868d936e62e855abcc Mon Sep 17 00:00:00 2001 From: =?utf-8?q?P=C3=A1draig=20Brady?= Date: Wed, 26 May 2010 09:27:53 +0100 Subject: [PATCH] truncate: support sizes relative to an existing file * doc/coreutils.texi (truncate invocation): Mention that --reference bases the --size rather than just setting it. * src/truncate.c (usage): Likewise. Also remove the clause describing --size and --reference as being mutually exclusive. (do_truncate): Add an extra parameter to hold the size of a referenced file, and use it if positive. (main): Pass the size of a referenced file to do_truncate(). * tests/misc/truncate-parameters: Adjust for the new combinations. * NEWS: Mention the change Suggested by Richard W.M. Jones --- NEWS | 1 + doc/coreutils.texi | 4 ++-- src/truncate.c | 36 ++++++++++++++++++++++-------------- tests/misc/truncate-parameters | 12 +++++++++++- 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index 19436fe..7a294f4 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ GNU coreutils NEWS -*- outline -*- sort -g now uses long doubles for greater range and precision. + truncate now supports setting file sizes relative to a reference file. * Noteworthy changes in release 8.5 (2010-04-23) [stable] diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 115e5fb..d1c3085 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -10767,13 +10767,13 @@ Treat @var{size} as number of I/O blocks of the @var{file} rather than bytes. @itemx --reference=@var{rfile} @opindex -r @opindex --reference -Set the size of each @var{file} to the same size as @var{rfile}. +Base the size of each @var{file} on the size of @var{rfile}. @item -s @var{size} @itemx --size=@var{size} @opindex -s @opindex --size -Set the size of each @var{file} to this @var{size}. +Set or adjust the size of each @var{file} according to @var{size}. @multiplierSuffixesNoBlocks{size} @var{size} may also be prefixed by one of the following to adjust diff --git a/src/truncate.c b/src/truncate.c index ece52ee..08090ab 100644 --- a/src/truncate.c +++ b/src/truncate.c @@ -115,8 +115,8 @@ Mandatory arguments to long options are mandatory for short options too.\n\ -o, --io-blocks treat SIZE as number of IO blocks instead of bytes\n\ "), stdout); fputs (_("\ - -r, --reference=FILE use this FILE's size\n\ - -s, --size=SIZE use this SIZE\n"), stdout); + -r, --reference=RFILE base size on RFILE\n\ + -s, --size=SIZE set or adjust the file size by SIZE\n"), stdout); fputs (HELP_OPTION_DESCRIPTION, stdout); fputs (VERSION_OPTION_DESCRIPTION, stdout); emit_size_note (); @@ -124,10 +124,6 @@ Mandatory arguments to long options are mandatory for short options too.\n\ SIZE may also be prefixed by one of the following modifying characters:\n\ `+' extend by, `-' reduce by, `<' at most, `>' at least,\n\ `/' round down to multiple of, `%' round up to multiple of.\n"), stdout); - fputs (_("\ -\n\ -Note that the -r and -s options are mutually exclusive.\n\ -"), stdout); emit_ancillary_info (); } exit (status); @@ -135,12 +131,13 @@ Note that the -r and -s options are mutually exclusive.\n\ /* return 1 on error, 0 on success */ static int -do_ftruncate (int fd, char const *fname, off_t ssize, rel_mode_t rel_mode) +do_ftruncate (int fd, char const *fname, off_t ssize, off_t rsize, + rel_mode_t rel_mode) { struct stat sb; off_t nsize; - if ((block_mode || rel_mode) && fstat (fd, &sb) != 0) + if ((block_mode || (rel_mode && rsize < 0)) && fstat (fd, &sb) != 0) { error (0, errno, _("cannot fstat %s"), quote (fname)); return 1; @@ -161,9 +158,9 @@ do_ftruncate (int fd, char const *fname, off_t ssize, rel_mode_t rel_mode) } if (rel_mode) { - uintmax_t const fsize = sb.st_size; + uintmax_t const fsize = rsize < 0 ? sb.st_size : rsize; - if (sb.st_size < 0) + if (rsize < 0 && sb.st_size < 0) { /* Complain only for a regular file, a directory, or a shared memory object, as POSIX 1003.1-2004 specifies @@ -248,6 +245,7 @@ main (int argc, char **argv) { bool got_size = false; off_t size IF_LINT (= 0); + off_t rsize = -1; rel_mode_t rel_mode = rm_abs; mode_t omode; int c, errors = 0, fd = -1, oflags; @@ -335,9 +333,16 @@ main (int argc, char **argv) argc -= optind; /* must specify either size or reference file */ - if ((ref_file && got_size) || (!ref_file && !got_size)) + if (!ref_file && !got_size) + { + error (0, 0, _("you must specify either %s or %s"), + quote_n (0, "--size"), quote_n (1, "--reference")); + usage (EXIT_FAILURE); + } + /* must specify a relative size with a reference file */ + if (ref_file && got_size && !rel_mode) { - error (0, 0, _("you must specify one of %s or %s"), + error (0, 0, _("you must specify a relative %s with %s"), quote_n (0, "--size"), quote_n (1, "--reference")); usage (EXIT_FAILURE); } @@ -360,7 +365,10 @@ main (int argc, char **argv) struct stat sb; if (stat (ref_file, &sb) != 0) error (EXIT_FAILURE, errno, _("cannot stat %s"), quote (ref_file)); - size = sb.st_size; + if (!got_size) + size = sb.st_size; + else + rsize = sb.st_size; } oflags = O_WRONLY | (no_create ? 0 : O_CREAT) | O_NONBLOCK; @@ -397,7 +405,7 @@ main (int argc, char **argv) if (fd != -1) { - errors += do_ftruncate (fd, fname, size, rel_mode); + errors += do_ftruncate (fd, fname, size, rsize, rel_mode); if (close (fd) != 0) { error (0, errno, _("closing %s"), quote (fname)); diff --git a/tests/misc/truncate-parameters b/tests/misc/truncate-parameters index 6524070..c2f7019 100755 --- a/tests/misc/truncate-parameters +++ b/tests/misc/truncate-parameters @@ -30,7 +30,7 @@ truncate --size=0 && fail=1 # must specify size. don't default to 0 truncate file && fail=1 -# mixture of size & reference not allowed +# mixture of absolute size & reference not allowed truncate --size=0 --reference=file file && fail=1 # blocks without size is not valid @@ -45,4 +45,14 @@ truncate --size=" >1" file || fail=1 #file now 1 truncate --size=" +1" file || fail=1 #file now 2 test $(stat --format %s file) = 2 || fail=1 +# reference allowed with relative size +truncate --size=" +1" -r file file || fail=1 #file now 3 +test $(stat --format %s file) = 3 || fail=1 + +# reference allowed alone also +truncate -r file file || fail=1 #file still 3 +test $(stat --format %s file) = 3 || fail=1 +truncate -r file file2 || fail=1 #file2 now 3 +test $(stat --format %s file2) = 3 || fail=1 + Exit $fail -- 1.6.2.5 --------------000604010903040209050509-- From unknown Sat Jun 21 03:21:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6268: Suggestion: truncate should allow -r and -s options together Resent-From: "Richard W.M. Jones" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Wed, 26 May 2010 12:30:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6268 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: =?UTF-8?Q?P=C3=A1draig?= Brady Cc: 6268@debbugs.gnu.org Received: via spool by 6268-submit@debbugs.gnu.org id=B6268.127487695326747 (code B ref 6268); Wed, 26 May 2010 12:30:04 +0000 Received: (at 6268) by debbugs.gnu.org; 26 May 2010 12:29:13 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OHFjS-0006xL-2i for submit@debbugs.gnu.org; Wed, 26 May 2010 08:29:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OHCHo-0004iY-AJ for 6268@debbugs.gnu.org; Wed, 26 May 2010 04:48:25 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4Q8mJQJ001390 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 26 May 2010 04:48:19 -0400 Received: from localhost (vpn1-4-20.ams2.redhat.com [10.36.4.20]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4Q8mIA7014159; Wed, 26 May 2010 04:48:18 -0400 Date: Wed, 26 May 2010 09:48:17 +0100 From: "Richard W.M. Jones" Message-ID: <20100526084817.GD3385@amd.home.annexia.org> References: <20100525143205.GB19557@amd.home.annexia.org> <4BFC72E5.9060908@draigBrady.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <4BFC72E5.9060908@draigBrady.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id o4Q8mJQJ001390 X-Spam-Score: -6.9 (------) X-Mailman-Approved-At: Wed, 26 May 2010 08:29:08 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -8.9 (--------) On Wed, May 26, 2010 at 02:01:25AM +0100, P=E1draig Brady wrote: > On 25/05/10 15:32, Richard W.M. Jones wrote: > > truncate -r old-disk.img -s +10% new-disk.img > >=20 > > truncate -r old-disk.img -s 110% new-disk.img >=20 > I'm a little less enthusiastic about the need for that. > Given how awkward it is to achieve then I might do it > (as a separate patch). Here's how you'd might do it > handling overflow currently: [...] > I guess it would be OK to truncate the result > rather than round to nearest? We offer a similar feature in virt-resize, and there we just truncate the result. Rich. --=20 Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rj= ones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/ From unknown Sat Jun 21 03:21:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6268: Suggestion: truncate should allow -r and -s options together Resent-From: "Richard W.M. Jones" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Wed, 26 May 2010 12:30:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6268 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: =?UTF-8?Q?P=C3=A1draig?= Brady Cc: 6268@debbugs.gnu.org Received: via spool by 6268-submit@debbugs.gnu.org id=B6268.127487695326756 (code B ref 6268); Wed, 26 May 2010 12:30:04 +0000 Received: (at 6268) by debbugs.gnu.org; 26 May 2010 12:29:13 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OHFjU-0006xS-7E for submit@debbugs.gnu.org; Wed, 26 May 2010 08:29:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OHCbI-0004rT-H7 for 6268@debbugs.gnu.org; Wed, 26 May 2010 05:08:33 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4Q98TJK003093 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 26 May 2010 05:08:29 -0400 Received: from localhost (vpn1-4-20.ams2.redhat.com [10.36.4.20]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4Q98OBf018240; Wed, 26 May 2010 05:08:28 -0400 Date: Wed, 26 May 2010 10:08:23 +0100 From: "Richard W.M. Jones" Message-ID: <20100526090823.GE3385@amd.home.annexia.org> References: <20100525143205.GB19557@amd.home.annexia.org> <4BFC72E5.9060908@draigBrady.com> <4BFCE1D7.5060308@draigBrady.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <4BFCE1D7.5060308@draigBrady.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id o4Q98TJK003093 X-Spam-Score: -8.4 (--------) X-Mailman-Approved-At: Wed, 26 May 2010 08:29:08 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -9.3 (---------) On Wed, May 26, 2010 at 09:54:47AM +0100, P=E1draig Brady wrote: > Attached. The patch looks good to me. Thanks, Rich. --=20 Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rj= ones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html From unknown Sat Jun 21 03:21:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6268: Suggestion: truncate should allow -r and -s options together Resent-From: Jim Meyering Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Fri, 28 May 2010 08:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6268 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: =?UTF-8?Q?P=C3=A1draig?= Brady Cc: 6268@debbugs.gnu.org, "Richard W.M. Jones" Received: via spool by 6268-submit@debbugs.gnu.org id=B6268.127503359214767 (code B ref 6268); Fri, 28 May 2010 08:00:02 +0000 Received: (at 6268) by debbugs.gnu.org; 28 May 2010 07:59:52 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OHuTv-0003q8-P2 for submit@debbugs.gnu.org; Fri, 28 May 2010 03:59:51 -0400 Received: from smtp1-g21.free.fr ([212.27.42.1]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OHuTs-0003q3-Uu for 6268@debbugs.gnu.org; Fri, 28 May 2010 03:59:50 -0400 Received: from mx.meyering.net (mx.meyering.net [82.230.74.64]) by smtp1-g21.free.fr (Postfix) with ESMTP id 0A51E9401E8 for <6268@debbugs.gnu.org>; Fri, 28 May 2010 09:59:40 +0200 (CEST) Received: by rho.meyering.net (Acme Bit-Twister, from userid 1000) id DA77DC50; Fri, 28 May 2010 09:59:39 +0200 (CEST) From: Jim Meyering In-Reply-To: <4BFCE1D7.5060308@draigBrady.com> =?UTF-8?Q?("P=C3=A1draig?= Brady"'s message of "Wed, 26 May 2010 09:54:47 +0100") References: <20100525143205.GB19557@amd.home.annexia.org> <4BFC72E5.9060908@draigBrady.com> <4BFCE1D7.5060308@draigBrady.com> Date: Fri, 28 May 2010 09:59:39 +0200 Message-ID: <87wruo8nis.fsf@meyering.net> Lines: 34 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.3 (---) P=C3=A1draig Brady wrote: > Subject: [PATCH] truncate: support sizes relative to an existing file > > * doc/coreutils.texi (truncate invocation): Mention that --reference > bases the --size rather than just setting it. > * src/truncate.c (usage): Likewise. Also remove the clause > describing --size and --reference as being mutually exclusive. > (do_truncate): Add an extra parameter to hold the size > of a referenced file, and use it if positive. > (main): Pass the size of a referenced file to do_truncate(). > * tests/misc/truncate-parameters: Adjust for the new combinations. > * NEWS: Mention the change > Suggested by Richard W.M. Jones Nice. Thanks! Not new with this change, but what about --ref=3Dnon-regular-file ? Perhaps truncate should refuse to use st_size info from a non-regular file. Here's a pathological example: $ echo abcdefgh > bar $ strace -e ftruncate ./truncate --ref=3D/dev/tty bar ftruncate(3, 0) =3D 0 $ wc -c bar 0 bar It's obvious that such an example is not likely in practice, but since currently truncate's --ref uses stat, it would follow a symlink, too. For a directory you'd get unportable and probably surprising results. Using such a reference size deserves at least a warning. From unknown Sat Jun 21 03:21:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6268: Suggestion: truncate should allow -r and -s options together Resent-From: =?UTF-8?Q?P=C3=A1draig?= Brady Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Fri, 28 May 2010 13:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6268 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Jim Meyering Cc: 6268@debbugs.gnu.org Received: via spool by 6268-submit@debbugs.gnu.org id=B6268.127505286625685 (code B ref 6268); Fri, 28 May 2010 13:22:02 +0000 Received: (at 6268) by debbugs.gnu.org; 28 May 2010 13:21:06 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OHzUo-0006gE-9b for submit@debbugs.gnu.org; Fri, 28 May 2010 09:21:06 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1OHzUm-0006fs-Uk for 6268@debbugs.gnu.org; Fri, 28 May 2010 09:21:05 -0400 Received: (qmail 30618 invoked from network); 28 May 2010 13:20:58 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 28 May 2010 13:20:58 -0000 Message-ID: <4BFFC286.3040605@draigBrady.com> Date: Fri, 28 May 2010 14:17:58 +0100 From: =?UTF-8?Q?P=C3=A1draig?= Brady User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 References: <20100525143205.GB19557@amd.home.annexia.org> <4BFC72E5.9060908@draigBrady.com> <4BFCE1D7.5060308@draigBrady.com> <87wruo8nis.fsf@meyering.net> In-Reply-To: <87wruo8nis.fsf@meyering.net> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.8 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.8 (--) > what about --ref=non-regular-file ? > > Perhaps truncate should refuse to use st_size info from > a non-regular file. > > Here's a pathological example: > > $ echo abcdefgh > bar > $ strace -e ftruncate ./truncate --ref=/dev/tty bar > ftruncate(3, 0) = 0 > $ wc -c bar > 0 bar > > It's obvious that such an example is not likely in practice, but since > currently truncate's --ref uses stat, it would follow a symlink, too. > > For a directory you'd get unportable and probably surprising results. > Using such a reference size deserves at least a warning. Yes that's safer. st_size is only defined for regular files (or shared mem), so I'll only allow regular files. I'll push a separate patch soon. Since we're only referencing the size, there is the argument that we should be trying harder to get the size of block devices for example. There are portability issues with that though, and doing outside of truncate is easy enough, so I'll leave that for now. cheers, Pádraig. From unknown Sat Jun 21 03:21:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6268: Suggestion: truncate should allow -r and -s options together Resent-From: =?UTF-8?Q?P=C3=A1draig?= Brady Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Sat, 29 May 2010 00:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6268 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Jim Meyering Cc: 6268@debbugs.gnu.org Received: via spool by 6268-submit@debbugs.gnu.org id=B6268.127509157810661 (code B ref 6268); Sat, 29 May 2010 00:07:02 +0000 Received: (at 6268) by debbugs.gnu.org; 29 May 2010 00:06:18 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OI9ZB-0002lu-3B for submit@debbugs.gnu.org; Fri, 28 May 2010 20:06:17 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1OI9Z9-0002lp-Fi for 6268@debbugs.gnu.org; Fri, 28 May 2010 20:06:16 -0400 Received: (qmail 40458 invoked from network); 29 May 2010 00:06:10 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 29 May 2010 00:06:10 -0000 Message-ID: <4C0059BC.80302@draigBrady.com> Date: Sat, 29 May 2010 01:03:08 +0100 From: =?UTF-8?Q?P=C3=A1draig?= Brady User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 References: <20100525143205.GB19557@amd.home.annexia.org> <4BFC72E5.9060908@draigBrady.com> <4BFCE1D7.5060308@draigBrady.com> <87wruo8nis.fsf@meyering.net> <4BFFC286.3040605@draigBrady.com> In-Reply-To: <4BFFC286.3040605@draigBrady.com> X-Enigmail-Version: 1.0.1 Content-Type: multipart/mixed; boundary="------------010102090407090706050304" X-Spam-Score: -2.8 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.8 (--) This is a multi-part message in MIME format. --------------010102090407090706050304 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 28/05/10 14:17, Pádraig Brady wrote: >> what about --ref=non-regular-file ? >> >> Perhaps truncate should refuse to use st_size info from >> a non-regular file. >> >> Here's a pathological example: >> >> $ echo abcdefgh > bar >> $ strace -e ftruncate ./truncate --ref=/dev/tty bar >> ftruncate(3, 0) = 0 >> $ wc -c bar >> 0 bar >> >> It's obvious that such an example is not likely in practice, but since >> currently truncate's --ref uses stat, it would follow a symlink, too. >> >> For a directory you'd get unportable and probably surprising results. >> Using such a reference size deserves at least a warning. > > Yes that's safer. st_size is only defined for regular files > (or shared mem), so I'll only allow regular files. > I'll push a separate patch soon. > > Since we're only referencing the size, there is the argument > that we should be trying harder to get the size of block devices > for example. There are portability issues with that though, > and doing outside of truncate is easy enough, so I'll leave that for now. I actually removed all ignoring of errors for non regular files, as well as not allowing one to reference st_size for non regular files. I'll push the attached tomorrow sometime. cheers, Pádraig. --------------010102090407090706050304 Content-Type: text/x-patch; name="truncate-non-files.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="truncate-non-files.diff" >From 0b9588c10cb3783ade69892302eb0d1379866af6 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?P=C3=A1draig=20Brady?= Date: Fri, 28 May 2010 19:25:23 +0100 Subject: [PATCH] truncate: improve handling of non regular files Previously we copied `dd` and suppressed error messages when truncating neither regular files or shared mem objects. This was valid for `dd`, as truncation is ancillary to copying it may also do, but for `truncate` we should display all errors. Also we used the st_size from non regular files which is undefined, so we display an error when the user tries this. * src/truncate (do_truncate): Error when referencing the size of non regular files or non shared memory objects. Display all errors returned by ftruncate(). (main): Error when referencing the size of non regular files or non shared memory objects. Don't suppress error messages for any file types that can't be opened for writing. * tests/misc/truncate-dir-fail: Check that referencing the size of a directory is not supported. * tests/misc/truncate-fifo: Ensure the test doesn't hang by using the `timeout` command. Don't test the return from running ftruncate on the fifo as it's system dependent as to whether this fails or not. --- src/truncate.c | 59 +++++++++++++----------------------------- tests/misc/truncate-dir-fail | 3 ++ tests/misc/truncate-fifo | 6 ++-- 3 files changed, 24 insertions(+), 44 deletions(-) diff --git a/src/truncate.c b/src/truncate.c index 08090ab..cfb5747 100644 --- a/src/truncate.c +++ b/src/truncate.c @@ -160,21 +160,21 @@ do_ftruncate (int fd, char const *fname, off_t ssize, off_t rsize, { uintmax_t const fsize = rsize < 0 ? sb.st_size : rsize; - if (rsize < 0 && sb.st_size < 0) + if (rsize < 0) /* fstat used above to get size. */ { - /* Complain only for a regular file, a directory, - or a shared memory object, as POSIX 1003.1-2004 specifies - ftruncate's behavior only for these file types. */ - if (S_ISREG (sb.st_mode) || S_ISDIR (sb.st_mode) - || S_TYPEISSHM (&sb)) + if (!S_ISREG (sb.st_mode) && !S_TYPEISSHM (&sb)) { - /* overflow is the only reason I can think - this would ever go negative for the above types */ + error (0, 0, _("cannot get the size of %s"), quote (fname)); + return 1; + } + if (sb.st_size < 0) + { + /* Sanity check. Overflow is the only reason I can think + this would ever go negative. */ error (0, 0, _("%s has unusable, apparently negative size"), quote (fname)); return 1; } - return 0; } if (rel_mode == rm_min) @@ -215,26 +215,10 @@ do_ftruncate (int fd, char const *fname, off_t ssize, off_t rsize, if (ftruncate (fd, nsize) == -1) /* note updates mtime & ctime */ { - /* Complain only when ftruncate fails on a regular file, a - directory, or a shared memory object, as POSIX 1003.1-2004 - specifies ftruncate's behavior only for these file types. - For example, do not complain when Linux kernel 2.4 ftruncate - fails on /dev/fd0. */ - int const ftruncate_errno = errno; - if (fstat (fd, &sb) != 0) - { - error (0, errno, _("cannot fstat %s"), quote (fname)); - return 1; - } - else if (S_ISREG (sb.st_mode) || S_ISDIR (sb.st_mode) - || S_TYPEISSHM (&sb)) - { - error (0, ftruncate_errno, - _("truncating %s at %" PRIdMAX " bytes"), quote (fname), - (intmax_t) nsize); - return 1; - } - return 0; + error (0, errno, + _("truncating %s at %" PRIdMAX " bytes"), quote (fname), + (intmax_t) nsize); + return 1; } return 0; @@ -362,9 +346,13 @@ main (int argc, char **argv) if (ref_file) { + /* FIXME: Maybe support getting size of block devices. */ struct stat sb; if (stat (ref_file, &sb) != 0) error (EXIT_FAILURE, errno, _("cannot stat %s"), quote (ref_file)); + if (!S_ISREG (sb.st_mode) && !S_TYPEISSHM (&sb)) + error (EXIT_FAILURE, 0, _("cannot get the size of %s"), + quote (ref_file)); if (!got_size) size = sb.st_size; else @@ -384,18 +372,7 @@ main (int argc, char **argv) `truncate -s0 .` should gen EISDIR error */ if (!(no_create && errno == ENOENT)) { - int const open_errno = errno; - struct stat sb; - if (stat (fname, &sb) == 0) - { - /* Complain only for a regular file, a directory, - or a shared memory object, as POSIX 1003.1-2004 specifies - ftruncate's behavior only for these file types. */ - if (!S_ISREG (sb.st_mode) && !S_ISDIR (sb.st_mode) - && !S_TYPEISSHM (&sb)) - continue; - } - error (0, open_errno, _("cannot open %s for writing"), + error (0, errno, _("cannot open %s for writing"), quote (fname)); errors++; } diff --git a/tests/misc/truncate-dir-fail b/tests/misc/truncate-dir-fail index d2ecf2f..fe33857 100755 --- a/tests/misc/truncate-dir-fail +++ b/tests/misc/truncate-dir-fail @@ -26,4 +26,7 @@ fi # truncate on dir not allowed truncate -s+0 . && fail=1 +# getting the size of a dir is not allowed +truncate -r. file && fail=1 + Exit $fail diff --git a/tests/misc/truncate-fifo b/tests/misc/truncate-fifo index 8e2276d..12d674c 100755 --- a/tests/misc/truncate-fifo +++ b/tests/misc/truncate-fifo @@ -1,5 +1,5 @@ #!/bin/sh -# Make sure truncate works on fifos without hanging or errors +# Make sure truncate works on fifos without hanging # Copyright (C) 2008-2010 Free Software Foundation, Inc. @@ -25,7 +25,7 @@ fi mkfifo_or_skip_ "fifo" - -truncate -s0 "fifo" || fail=1 +timeout 10 truncate -s0 "fifo" +test "$?" = 124 && fail=1 Exit $fail -- 1.6.2.5 --------------010102090407090706050304-- From unknown Sat Jun 21 03:21:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6268: Suggestion: truncate should allow -r and -s options together Resent-From: Jim Meyering Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Sat, 29 May 2010 08:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6268 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: =?UTF-8?Q?P=C3=A1draig?= Brady Cc: 6268@debbugs.gnu.org Received: via spool by 6268-submit@debbugs.gnu.org id=B6268.127512131723152 (code B ref 6268); Sat, 29 May 2010 08:22:02 +0000 Received: (at 6268) by debbugs.gnu.org; 29 May 2010 08:21:57 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OIHIq-00061N-VX for submit@debbugs.gnu.org; Sat, 29 May 2010 04:21:57 -0400 Received: from smtp1-g21.free.fr ([212.27.42.1]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OIHIo-00061I-Va for 6268@debbugs.gnu.org; Sat, 29 May 2010 04:21:56 -0400 Received: from mx.meyering.net (mx.meyering.net [82.230.74.64]) by smtp1-g21.free.fr (Postfix) with ESMTP id 5B1EB940041 for <6268@debbugs.gnu.org>; Sat, 29 May 2010 10:21:47 +0200 (CEST) Received: by rho.meyering.net (Acme Bit-Twister, from userid 1000) id 35AF4DD26; Sat, 29 May 2010 10:21:46 +0200 (CEST) From: Jim Meyering In-Reply-To: <4C0059BC.80302@draigBrady.com> =?UTF-8?Q?("P=C3=A1draig?= Brady"'s message of "Sat, 29 May 2010 01:03:08 +0100") References: <20100525143205.GB19557@amd.home.annexia.org> <4BFC72E5.9060908@draigBrady.com> <4BFCE1D7.5060308@draigBrady.com> <87wruo8nis.fsf@meyering.net> <4BFFC286.3040605@draigBrady.com> <4C0059BC.80302@draigBrady.com> Date: Sat, 29 May 2010 10:21:46 +0200 Message-ID: <874ohr2k4l.fsf@meyering.net> Lines: 69 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.5 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.3 (---) P=C3=A1draig Brady wrote: > Subject: [PATCH] truncate: improve handling of non regular files > > Previously we copied `dd` and suppressed error messages > when truncating neither regular files or shared mem objects. > This was valid for `dd`, as truncation is ancillary to copying > it may also do, but for `truncate` we should display all errors. > Also we used the st_size from non regular files which is undefined, > so we display an error when the user tries this. > > * src/truncate (do_truncate): Error when referencing the size > of non regular files or non shared memory objects. Display all > errors returned by ftruncate(). > (main): Error when referencing the size of non regular files or > non shared memory objects. Don't suppress error messages for > any file types that can't be opened for writing. > * tests/misc/truncate-dir-fail: Check that referencing the > size of a directory is not supported. > * tests/misc/truncate-fifo: Ensure the test doesn't hang > by using the `timeout` command. Don't test the return from > running ftruncate on the fifo as it's system dependent as > to whether this fails or not. Thanks again. This all looks fine. > - } > - else if (S_ISREG (sb.st_mode) || S_ISDIR (sb.st_mode) > - || S_TYPEISSHM (&sb)) > - { > - error (0, ftruncate_errno, > - _("truncating %s at %" PRIdMAX " bytes"), quote (fname), > - (intmax_t) nsize); > - return 1; > - } > - return 0; > + error (0, errno, > + _("truncating %s at %" PRIdMAX " bytes"), quote (fname), > + (intmax_t) nsize); It's slightly clearer to say "failed ...": _("failed to truncate %s at %" PRIdMAX " bytes"), quote (fn= ame), Otherwise, e.g., truncating FILE ...: permission denied might leave a user wondering whether or not the truncation actually succeeded. Sure, *we* know, but if they are not as familiar with how command-line diagnostics work and/or interpret the ":" as a "." or ";", then it looks like the truncation succeeded. ... > +++ b/tests/misc/truncate-fifo > @@ -1,5 +1,5 @@ > #!/bin/sh > -# Make sure truncate works on fifos without hanging or errors > +# Make sure truncate works on fifos without hanging > > # Copyright (C) 2008-2010 Free Software Foundation, Inc. > > @@ -25,7 +25,7 @@ fi > > mkfifo_or_skip_ "fifo" > > - > -truncate -s0 "fifo" || fail=3D1 > +timeout 10 truncate -s0 "fifo" Please remove the three sets of unneeded double quotes: s/"fifo"/fifo/. From unknown Sat Jun 21 03:21:40 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.427 (Entity 5.427) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: "Richard W.M. Jones" Subject: bug#6268: closed (Re: bug#6268: Suggestion: truncate should allow -r and -s options together) Message-ID: References: <4C00E1F2.5080202@draigBrady.com> <20100525143205.GB19557@amd.home.annexia.org> X-Gnu-PR-Message: they-closed 6268 X-Gnu-PR-Package: coreutils Reply-To: 6268@debbugs.gnu.org Date: Sat, 29 May 2010 09:48:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1275126482-25364-1" This is a multi-part message in MIME format... ------------=_1275126482-25364-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #6268: Suggestion: truncate should allow -r and -s options together which was filed against the coreutils package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 6268@debbugs.gnu.org. --=20 6268: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D6268 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1275126482-25364-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 6268-done) by debbugs.gnu.org; 29 May 2010 09:47:29 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OIIdd-0006as-8x for submit@debbugs.gnu.org; Sat, 29 May 2010 05:47:29 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1OIIda-0006am-OV for 6268-done@debbugs.gnu.org; Sat, 29 May 2010 05:47:27 -0400 Received: (qmail 3460 invoked from network); 29 May 2010 09:47:22 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 29 May 2010 09:47:22 -0000 Message-ID: <4C00E1F2.5080202@draigBrady.com> Date: Sat, 29 May 2010 10:44:18 +0100 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: 6268-done@debbugs.gnu.org Subject: Re: bug#6268: Suggestion: truncate should allow -r and -s options together References: <20100525143205.GB19557@amd.home.annexia.org> <4BFC72E5.9060908@draigBrady.com> <4BFCE1D7.5060308@draigBrady.com> <87wruo8nis.fsf@meyering.net> <4BFFC286.3040605@draigBrady.com> <4C0059BC.80302@draigBrady.com> <874ohr2k4l.fsf@meyering.net> In-Reply-To: <874ohr2k4l.fsf@meyering.net> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.8 (--) X-Debbugs-Envelope-To: 6268-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.8 (--) On 29/05/10 09:21, Jim Meyering wrote: > Pádraig Brady wrote: >> Subject: [PATCH] truncate: improve handling of non regular files >> > Thanks again. > This all looks fine. OK I pushed that with an addition to NEWS. cheers, Pádraig. ------------=_1275126482-25364-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 25 May 2010 15:41:16 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OGwFm-0005E8-Fi for submit@debbugs.gnu.org; Tue, 25 May 2010 11:41:15 -0400 Received: from mx10.gnu.org ([199.232.76.166]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OGvB8-0004hW-18 for submit@debbugs.gnu.org; Tue, 25 May 2010 10:32:23 -0400 Received: from lists.gnu.org ([199.232.76.165]:56678) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1OGvB2-0000P4-VO for submit@debbugs.gnu.org; Tue, 25 May 2010 10:32:17 -0400 Received: from [140.186.70.92] (port=44932 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGvB0-0006IG-Jy for bug-coreutils@gnu.org; Tue, 25 May 2010 10:32:15 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.1 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OGvAv-0005Gt-BB for bug-coreutils@gnu.org; Tue, 25 May 2010 10:32:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20330) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OGvAu-0005Gb-TT for bug-coreutils@gnu.org; Tue, 25 May 2010 10:32:09 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4PEW7ne015887 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 25 May 2010 10:32:07 -0400 Received: from localhost (vpn1-7-239.ams2.redhat.com [10.36.7.239]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4PEW5gc024216 for ; Tue, 25 May 2010 10:32:06 -0400 Date: Tue, 25 May 2010 15:32:05 +0100 From: "Richard W.M. Jones" To: bug-coreutils@gnu.org Subject: Suggestion: truncate should allow -r and -s options together Message-ID: <20100525143205.GB19557@amd.home.annexia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Spam-Score: -3.3 (---) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Tue, 25 May 2010 11:41:13 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.6 (----) The manpage for truncate says: Note that the -r and -s options are mutually exclusive. and indeed you cannot have both: $ truncate -r /tmp/ref -s +10M /tmp/new truncate: you must specify one of `--size' or `--reference' We suggest using the 'truncate' command in the 'virt-resize' documentation[1]. We want users to create a file which is the size of an existing file + some extra amount. Naturally this would be: truncate -r old-disk.img -s +1G new-disk.img but this does not work and we have to suggest that users use two separate 'truncate' commands[2]. Related to this feature request, it would be nice if you could suffix a size with a % sign to indicate that you want to increase a file by a certain percentage of the old or reference size, eg: truncate -r old-disk.img -s +10% new-disk.img truncate -r old-disk.img -s 110% new-disk.img Neither of these forms work at the moment. Rich. [1] http://libguestfs.org/virt-resize.1.html#expanding_a_virtual_machine_disk [2] http://git.annexia.org/?p=libguestfs.git;a=commitdiff;h=0e28e4104d96bf0bf5b88fb07bb7e5f9f6e6f41f#patch1 -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora ------------=_1275126482-25364-1-- From unknown Sat Jun 21 03:21:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6268: Suggestion: truncate should allow -r and -s options together Resent-From: "Voelker, Bernhard" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Mon, 31 May 2010 06:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6268 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: =?UTF-8?Q?P=C3=A1draig?= Brady , Jim Meyering Cc: "6268@debbugs.gnu.org" <6268@debbugs.gnu.org> Received: via spool by 6268-submit@debbugs.gnu.org id=B6268.127528751730429 (code B ref 6268); Mon, 31 May 2010 06:32:01 +0000 Received: (at 6268) by debbugs.gnu.org; 31 May 2010 06:31:57 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OIyXU-0007uk-9U for submit@debbugs.gnu.org; Mon, 31 May 2010 02:31:56 -0400 Received: from m0019.fra.mmp.de.bt.com ([62.180.227.30] helo=ms04.m0019.fra.mmp.de.bt.com) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OIyXS-0007uc-Lo for 6268@debbugs.gnu.org; Mon, 31 May 2010 02:31:55 -0400 Received: from senmx11-mx ([62.134.46.9] [62.134.46.9]) by ms04.m0020.fra.mmp.de.bt.com with ESMTP id BT-MMP-338183; Mon, 31 May 2010 08:31:50 +0200 Received: from MCHP063A.global-ad.net (unknown [172.29.37.61]) by senmx11-mx (Server) with ESMTP id 3E4E41EB82AE; Mon, 31 May 2010 08:31:50 +0200 (CEST) Received: from MCHP058A.global-ad.net ([172.29.37.55]) by MCHP063A.global-ad.net ([172.29.37.61]) with mapi; Mon, 31 May 2010 08:31:50 +0200 From: "Voelker, Bernhard" Date: Mon, 31 May 2010 08:31:49 +0200 Thread-Topic: bug#6268: Suggestion: truncate should allow -r and -s options together Thread-Index: Acr+aY0hbnTc7RwATwiuUaCwaXCJcwCIF1jQ Message-ID: <7856072A9D04C24B82DFE2B1112FE38AE0A7562B@MCHP058A.global-ad.net> References: <20100525143205.GB19557@amd.home.annexia.org> <4BFC72E5.9060908@draigBrady.com> <4BFCE1D7.5060308@draigBrady.com> <87wruo8nis.fsf@meyering.net> <4BFFC286.3040605@draigBrady.com> In-Reply-To: <4BFFC286.3040605@draigBrady.com> Accept-Language: de-DE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: de-DE, en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Spam-Score: -3.0 (---) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.0 (---) P=E1draig Brady wrote: > Jim Meyering wrote: >> what about --ref=3Dnon-regular-file ? > Yes that's safer. st_size is only defined for regular files > (or shared mem), so I'll only allow regular files. > I'll push a separate patch soon. what about --ref=3D- ? one wants to have a file with the size of a partition plus 5G, e.g. truncate --ref=3D/dev/sda5 -s +5G myfile This will fail and will be rejected with such a patch. So the user could use: truncate --ref=3D- -s +5G myfile < /dev/sda5 Just a thought ... Have a nice day, Berny From unknown Sat Jun 21 03:21:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6268: Suggestion: truncate should allow -r and -s options together Resent-From: =?UTF-8?Q?P=C3=A1draig?= Brady Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Mon, 31 May 2010 08:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6268 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: "Voelker, Bernhard" Cc: 6268@debbugs.gnu.org Received: via spool by 6268-submit@debbugs.gnu.org id=B6268.12752960442237 (code B ref 6268); Mon, 31 May 2010 08:55:02 +0000 Received: (at 6268) by debbugs.gnu.org; 31 May 2010 08:54:04 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJ0l1-0000a2-FO for submit@debbugs.gnu.org; Mon, 31 May 2010 04:54:03 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1OJ0l0-0000Zf-2N for 6268@debbugs.gnu.org; Mon, 31 May 2010 04:54:02 -0400 Received: (qmail 41863 invoked from network); 31 May 2010 08:53:58 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 31 May 2010 08:53:58 -0000 Message-ID: <4C037864.9070706@draigBrady.com> Date: Mon, 31 May 2010 09:50:44 +0100 From: =?UTF-8?Q?P=C3=A1draig?= Brady User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 References: <20100525143205.GB19557@amd.home.annexia.org> <4BFC72E5.9060908@draigBrady.com> <4BFCE1D7.5060308@draigBrady.com> <87wruo8nis.fsf@meyering.net> <4BFFC286.3040605@draigBrady.com> <7856072A9D04C24B82DFE2B1112FE38AE0A7562B@MCHP058A.global-ad.net> In-Reply-To: <7856072A9D04C24B82DFE2B1112FE38AE0A7562B@MCHP058A.global-ad.net> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.8 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.8 (--) On 31/05/10 07:31, Voelker, Bernhard wrote: > Pádraig Brady wrote: >> Jim Meyering wrote: >>> what about --ref=non-regular-file ? > >> Yes that's safer. st_size is only defined for regular files >> (or shared mem), so I'll only allow regular files. >> I'll push a separate patch soon. > > what about --ref=- ? > > one wants to have a file with the size > of a partition plus 5G, e.g. > truncate --ref=/dev/sda5 -s +5G myfile > This will fail and will be rejected with such a patch. > So the user could use: > truncate --ref=- -s +5G myfile < /dev/sda5 > > Just a thought ... Well we never supported referencing stdin as we stat() the name. Also one needs to use a separate operation to get the size of a block device, so before the patch we just returned 0 which was invalid. I wrote a comment in the code to say referencing the size of a block device is probably useful, but we'll need to worry about portability of that. cheers, Pádraig. From unknown Sat Jun 21 03:21:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6268: Suggestion: truncate should allow -r and -s options together Resent-From: "Richard W.M. Jones" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Tue, 01 Jun 2010 12:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6268 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Jim Meyering Cc: 6268@debbugs.gnu.org, =?UTF-8?Q?P=C3=A1draig?= Brady Received: via spool by 6268-submit@debbugs.gnu.org id=B6268.127539396125330 (code B ref 6268); Tue, 01 Jun 2010 12:06:01 +0000 Received: (at 6268) by debbugs.gnu.org; 1 Jun 2010 12:06:01 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJQEK-0006aU-0C for submit@debbugs.gnu.org; Tue, 01 Jun 2010 08:06:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJNpz-0004tn-Oo for 6268@debbugs.gnu.org; Tue, 01 Jun 2010 05:32:44 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o519Wgta018985 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 1 Jun 2010 05:32:43 -0400 Received: from localhost (vpn1-4-147.ams2.redhat.com [10.36.4.147]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o519Wf0w027362; Tue, 1 Jun 2010 05:32:41 -0400 Date: Tue, 1 Jun 2010 10:32:40 +0100 From: "Richard W.M. Jones" Message-ID: <20100601093240.GD10160@amd.home.annexia.org> References: <20100525143205.GB19557@amd.home.annexia.org> <4BFC72E5.9060908@draigBrady.com> <4BFCE1D7.5060308@draigBrady.com> <87wruo8nis.fsf@meyering.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <87wruo8nis.fsf@meyering.net> User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id o519Wgta018985 X-Spam-Score: -8.2 (--------) X-Mailman-Approved-At: Tue, 01 Jun 2010 08:05:58 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -9.5 (---------) On Fri, May 28, 2010 at 09:59:39AM +0200, Jim Meyering wrote: > P=E1draig Brady wrote: > > Subject: [PATCH] truncate: support sizes relative to an existing file > > > > * doc/coreutils.texi (truncate invocation): Mention that --reference > > bases the --size rather than just setting it. > > * src/truncate.c (usage): Likewise. Also remove the clause > > describing --size and --reference as being mutually exclusive. > > (do_truncate): Add an extra parameter to hold the size > > of a referenced file, and use it if positive. > > (main): Pass the size of a referenced file to do_truncate(). > > * tests/misc/truncate-parameters: Adjust for the new combinations. > > * NEWS: Mention the change > > Suggested by Richard W.M. Jones >=20 > Nice. Thanks! >=20 > Not new with this change, but what about --ref=3Dnon-regular-file ? >=20 > Perhaps truncate should refuse to use st_size info from > a non-regular file. >=20 > Here's a pathological example: >=20 > $ echo abcdefgh > bar > $ strace -e ftruncate ./truncate --ref=3D/dev/tty bar > ftruncate(3, 0) =3D 0 > $ wc -c bar > 0 bar >=20 > It's obvious that such an example is not likely in practice, but since > currently truncate's --ref uses stat, it would follow a symlink, too. >=20 > For a directory you'd get unportable and probably surprising results. > Using such a reference size deserves at least a warning. And of course the right behaviour for block devices might be to get their size (ie. blockdev --getsize64 or the equivalent set of ioctls). Rich. --=20 Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rj= ones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v From unknown Sat Jun 21 03:21:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6268: Suggestion: truncate should allow -r and -s options together Resent-From: Eric Blake Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Tue, 01 Jun 2010 15:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6268 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: =?UTF-8?Q?P=C3=A1draig?= Brady Cc: 6268@debbugs.gnu.org, "Voelker, Bernhard" Received: via spool by 6268-submit@debbugs.gnu.org id=B6268.12754076641487 (code B ref 6268); Tue, 01 Jun 2010 15:55:02 +0000 Received: (at 6268) by debbugs.gnu.org; 1 Jun 2010 15:54:24 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJTnM-0000Nw-9X for submit@debbugs.gnu.org; Tue, 01 Jun 2010 11:54:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJTnK-0000Nr-6Z for 6268@debbugs.gnu.org; Tue, 01 Jun 2010 11:54:23 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o51FsG65023867 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 1 Jun 2010 11:54:16 -0400 Received: from [10.3.242.3] (vpn-242-3.phx2.redhat.com [10.3.242.3]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o51FsFZi030886; Tue, 1 Jun 2010 11:54:15 -0400 Message-ID: <4C052D0C.7020309@redhat.com> Date: Tue, 01 Jun 2010 09:53:48 -0600 From: Eric Blake Organization: Red Hat User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100430 Fedora/3.0.4-3.fc13 Lightning/1.0b2pre Mnenhy/0.8.2 Thunderbird/3.0.4 MIME-Version: 1.0 References: <20100525143205.GB19557@amd.home.annexia.org> <4BFC72E5.9060908@draigBrady.com> <4BFCE1D7.5060308@draigBrady.com> <87wruo8nis.fsf@meyering.net> <4BFFC286.3040605@draigBrady.com> <7856072A9D04C24B82DFE2B1112FE38AE0A7562B@MCHP058A.global-ad.net> <4C037864.9070706@draigBrady.com> In-Reply-To: <4C037864.9070706@draigBrady.com> X-Enigmail-Version: 1.0.1 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig3FC0960E4E29C6E2EA59FFFC" X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-Spam-Score: -10.1 (----------) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -10.1 (----------) This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig3FC0960E4E29C6E2EA59FFFC Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 05/31/2010 02:50 AM, P=E1draig Brady wrote: >> So the user could use: >> truncate --ref=3D- -s +5G myfile < /dev/sda5 >> >> Just a thought ... >=20 > Well we never supported referencing stdin as > we stat() the name. Also one needs to use a separate > operation to get the size of a block device, > so before the patch we just returned 0 which was invalid. >=20 > I wrote a comment in the code to say referencing > the size of a block device is probably useful, > but we'll need to worry about portability of that. The only portable way to get the size of a block device is to open() it, then do lseek(fd,0,SEEK_END). Other more efficient methods, like an ioctl, may exist for some platforms, but then it could become a maintenance nightmare to figure out where the shortcuts are available. --=20 Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org --------------enig3FC0960E4E29C6E2EA59FFFC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJMBS0MAAoJEKeha0olJ0NqeaMIAIL7JvBPUwjSVMoq+WwISCOn f92jU5r2qemy3/8weml/dXmbv66aHuSHez1L76XTC4P+3DIed9oUpo2/PxKxz19/ 0umYDPDFUupDhPpOXw4JWca/JUsMwf7Q/xn3Hu6weYnDTn4Ps60t4qaCnLD0Oweg jXw7htoCQnf3DiJBKxzKZgeB9reOIJNY4jj3J6B3ECaKq3V/GBuRMQCUHARSvuQr nusWoPjQXfXDZI/8m/BTwHEclDT3WjhVR1bzeKZnsRO4LmSr8pY/rEcvDjFF0ENm VJlZZZeRcaYEr/t0H7BocAAj9Pj6xtmhF7MU900mRYOBRMESBaPizvHLaObL2UY= =VxSp -----END PGP SIGNATURE----- --------------enig3FC0960E4E29C6E2EA59FFFC--