From owner-freebsd-bugs@FreeBSD.ORG Fri Nov 9 16:50:02 2007 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 298EC16A468 for ; Fri, 9 Nov 2007 16:50:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id EF1DC13C4A6 for ; Fri, 9 Nov 2007 16:50:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.1/8.14.1) with ESMTP id lA9Go1Go027368 for ; Fri, 9 Nov 2007 16:50:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.1/8.14.1/Submit) id lA9Go1tI027367; Fri, 9 Nov 2007 16:50:01 GMT (envelope-from gnats) Resent-Date: Fri, 9 Nov 2007 16:50:01 GMT Resent-Message-Id: <200711091650.lA9Go1tI027367@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Giorgos Keramidas Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E9D4116A417; Fri, 9 Nov 2007 16:46:13 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id 5701213C480; Fri, 9 Nov 2007 16:46:13 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (vader.bytemobile-rio.ondsl.gr [83.235.57.37]) (authenticated bits=128) by igloo.linux.gr (8.14.1/8.14.1/Debian-9) with ESMTP id lA9GQs0u022988 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 9 Nov 2007 18:27:01 +0200 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.1/8.14.1) with ESMTP id lA9GQnYG015455; Fri, 9 Nov 2007 18:26:49 +0200 (EET) (envelope-from keramida@kobe.laptop) Received: (from keramida@localhost) by kobe.laptop (8.14.1/8.14.1/Submit) id lA9GQn6S015454; Fri, 9 Nov 2007 18:26:49 +0200 (EET) (envelope-from keramida) Message-Id: <200711091626.lA9GQn6S015454@kobe.laptop> Date: Fri, 9 Nov 2007 18:26:49 +0200 (EET) From: Giorgos Keramidas To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: ru@FreeBSD.org Subject: bin/117944: [PATCH] add a du(1) -l option to count hardlinks multiple times X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Giorgos Keramidas List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Nov 2007 16:50:02 -0000 >Number: 117944 >Category: bin >Synopsis: [PATCH] add a du(1) -l option to count hardlinks multiple times >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Nov 09 16:50:01 UTC 2007 >Closed-Date: >Last-Modified: >Originator: Giorgos Keramidas >Release: FreeBSD 8.0-CURRENT i386 >Organization: >Environment: System: FreeBSD kobe 8.0-CURRENT FreeBSD 8.0-CURRENT #0: Sun Nov 4 06:20:54 EET 2007 build@kobe:/home/build/obj/home/build/src/sys/KOBE i386 >Description: While testing an Ubuntu installation at home, I discovered the -l option of du(1), which allows one to count hardlinked files multiple times. This was useful when trying to count the disk size of two Mercurial repository clones, which by default use hard-links for their metadata directories. With our current du(1) utility, one sees: keramida@kobe:/home/keramida/hg/doc$ du -sk bsd/.hg el/.hg 8312 bsd/.hg 698 el/.hg keramida@kobe:/home/keramida/hg/doc$ du -sk el/.hg 8288 el/.hg keramida@kobe:/home/keramida/hg/doc$ Now it's obvious that hard links in el/.hg would require that we either run du(1) many times, or patch our du(1) utility to make the hard link checks optional. The Linux version of du(1) uses the -l option to turn off the hard link checks, so I wrote from scratch a short patch to do the same. The patch attached below is also available at: http://people.freebsd.org/~keramida/diff/du-hardlinks-00.patch >How-To-Repeat: >Fix: --- du-hardlinks-00.patch begins here --- diff -r 2d7179484ba4 du.1 --- a/du.1 Fri Nov 09 18:17:29 2007 +0200 +++ b/du.1 Fri Nov 09 18:25:17 2007 +0200 @@ -32,7 +32,7 @@ .\" @(#)du.1 8.2 (Berkeley) 4/1/94 .\" $FreeBSD: src/usr.bin/du/du.1,v 1.32 2006/09/29 15:20:44 ru Exp $ .\" -.Dd May 6, 2006 +.Dd November 9, 2007 .Dt DU 1 .Os .Sh NAME @@ -43,6 +43,7 @@ .Op Fl H | L | P .Op Fl a | s | d Ar depth .Op Fl c +.Op Fl l .Op Fl h | k | m .Op Fl n .Op Fl x @@ -94,6 +95,15 @@ Display a grand total. Display a grand total. .It Fl k Display block counts in 1024-byte (1-Kbyte) blocks. +.It Fl l +If a file has multiple hard links, count its size many times. +The default behavior of +.Nm +is to count files with multiple hard links only once. +When the +.Fl l +option is specified, the hard link checks are disabled, and these files +are counted (and displayed) as many times as they are found. .It Fl m Display block counts in 1048576-byte (1-Mbyte) blocks. .It Fl n @@ -120,11 +130,6 @@ or .Fl L options are specified, storage used by any symbolic links which are followed is not counted or displayed. -.Pp -Files having multiple hard links are counted (and displayed) a single -time per -.Nm -execution. .Sh ENVIRONMENT .Bl -tag -width BLOCKSIZE .It Ev BLOCKSIZE diff -r 2d7179484ba4 du.c --- a/du.c Fri Nov 09 18:17:29 2007 +0200 +++ b/du.c Fri Nov 09 18:25:17 2007 +0200 @@ -90,20 +90,22 @@ main(int argc, char *argv[]) int ftsoptions; int listall; int depth; - int Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag, hflag, ch, notused, rval; + int Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag, + hflag, lflag, ch, notused, rval; char **save; static char dot[] = "."; setlocale(LC_ALL, ""); - Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag = 0; + Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag = + lflag = 0; save = argv; ftsoptions = 0; depth = INT_MAX; SLIST_INIT(&ignores); - while ((ch = getopt(argc, argv, "HI:LPasd:chkmnrx")) != -1) + while ((ch = getopt(argc, argv, "HI:LPasd:chklmnrx")) != -1) switch (ch) { case 'H': Hflag = 1; @@ -149,6 +151,9 @@ main(int argc, char *argv[]) hflag = 0; if (setenv("BLOCKSIZE", "1024", 1) == -1) warnx("setenv: cannot set BLOCKSIZE=1024"); + break; + case 'l': + lflag = 1; break; case 'm': hflag = 0; @@ -261,7 +266,7 @@ main(int argc, char *argv[]) if (ignorep(p)) break; - if (p->fts_statp->st_nlink > 1 && linkchk(p)) + if (lflag == 0 && p->fts_statp->st_nlink > 1 && linkchk(p)) break; if (listall || p->fts_level == 0) { @@ -447,7 +452,8 @@ usage(void) usage(void) { (void)fprintf(stderr, - "usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k | -m] [-n] [-x] [-I mask] [file ...]\n"); + "usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] " + "[-l] [-h | -k | -m] [-n] [-x] [-I mask] [file ...]\n"); exit(EX_USAGE); } --- du-hardlinks-00.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted: