xfs
[Top] [All Lists]

Re: [PATCH v2]: Shell script for printing XFS quota project id for files

To: Arkadiusz Miśkiewicz <arekm@xxxxxxxx>
Subject: Re: [PATCH v2]: Shell script for printing XFS quota project id for files.
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Tue, 13 Nov 2012 09:14:24 +1100
Cc: xfs@xxxxxxxxxxx
In-reply-to: <1352745628-15451-1-git-send-email-arekm@xxxxxxxx>
References: <1352745235-14922-1-git-send-email-arekm@xxxxxxxx> <1352745628-15451-1-git-send-email-arekm@xxxxxxxx>
User-agent: Mutt/1.5.21 (2010-09-15)
On Mon, Nov 12, 2012 at 07:40:28PM +0100, Arkadiusz Miśkiewicz wrote:
> Simple script that prints project id for files:
> 
> $ sh quota/xfs_lsprojid.sh quota/[fl]*
> quota/freebsd.c: 232
> quota/free.c: 0
> quota/free.o: 222
> quota/linux.c: 21344
> quota/linux.o: 0
> 
> Signed-off-by: Arkadiusz Miśkiewicz <arekm@xxxxxxxx>
> ---
.....
> @@ -0,0 +1,11 @@
> +#!/bin/sh
> +#
> +# Copyright (c) 2012 Arkadiusz Miśkiewicz.

Best to use only 7-bit ascii in code.

> +#
> +
> +for file in "$@"; do
> +        xfs_io -p "$0" -r -c "stat" "$file" | awk '
> +        /^fd\.path =/ { projid=""; gsub(/^fd\.path = \"/, ""); gsub(/\"$/, 
> ""); path=$0 }
> +        /^fsxattr\.projid =/ { projid=$3; print path ": " projid; }
> +        '
> +done

Can you write it in a way that looks a little less like line
noise? This is much easier to understand:

        xfs_io -p "$0" -r -c "stat" "$file" | awk '
                /^fd\.path =/ {
                        projid="";
                        gsub(/^fd\.path = \"/, "");
                        gsub(/\"$/, "");
                        path=$0
                }
                /^fsxattr\.projid =/ {
                        projid=$3;
                        print path ": " projid;
                }'

It also needs a usage message when no files are given, and probably
a version output (-V option) as well.

Cheers,

Dave.
-- 
Dave Chinner
david@xxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>