From nobody@FreeBSD.org  Fri Jun  6 11:57:29 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id E9B751065674
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  6 Jun 2008 11:57:29 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id CDD188FC1D
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  6 Jun 2008 11:57:29 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m56BvTc4054696
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 6 Jun 2008 11:57:29 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m56BvTCe054695;
	Fri, 6 Jun 2008 11:57:29 GMT
	(envelope-from nobody)
Message-Id: <200806061157.m56BvTCe054695@www.freebsd.org>
Date: Fri, 6 Jun 2008 11:57:29 GMT
From: Ighighi <ighighi@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch]: stat(1) should interpret st_flags as it does with st_mode
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         124349
>Category:       bin
>Synopsis:       [patch]: stat(1) should interpret st_flags as it does with st_mode
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jilles
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jun 06 12:00:11 UTC 2008
>Closed-Date:    Tue May 04 21:58:04 UTC 2010
>Last-Modified:  Tue May  4 22:00:12 UTC 2010
>Originator:     Ighighi
>Release:        6.3-STABLE (RELENG_6)
>Organization:
>Environment:
FreeBSD orion 6.3-STABLE FreeBSD 6.3-STABLE #0: Wed May 28 17:18:08 VET 2008
>Description:
Currently, the only output for st_flags in stat(1) is numeric.
I suggest adding support for string output as it's done with
st_mode, st_uid, st_gid, etc, so instead of just:

$ /usr/bin/stat -f '%f %N' /usr/bin/su
131072 /usr/bin/su

we may also see (without the need to use "ls -ldo"):

$ ./stat -f '%Sf %N' /usr/bin/su
schg /usr/bin/su


Quoting stat(1):

     The special output specifier S may be used to indicate that the
     output, if applicable, should be in string format.  May be used
     in combination with:

     [...]

     gu      Display group or user name.

     p       Display the mode of file as in ls -lTd.


I also patched the manpage to add this line:

     f       Display the flags of file as in ls -lTdo.

>How-To-Repeat:

>Fix:
Available patch built and tested on 6.3-STABLE and -CURRENT

Patch attached with submission follows:

--- src/usr.bin/stat/stat.1.orig	2007-04-27 14:23:32.000000000 -0400
+++ src/usr.bin/stat/stat.1	2008-06-06 07:02:14.415211295 -0430
@@ -239,6 +239,11 @@ Display date in
 format.
 .It Cm dr
 Display actual device name.
+.It Cm f
+Display the flags of
+.Ar file
+as in
+.Nm ls Fl lTdo .
 .It Cm gu
 Display group or user name.
 .It Cm p
--- src/usr.bin/stat/stat.c.orig	2003-10-05 21:55:17.000000000 -0400
+++ src/usr.bin/stat/stat.c	2008-06-06 07:07:07.202401287 -0430
@@ -187,6 +187,7 @@ int	format1(const struct stat *,	/* stat
 	    char *, size_t,		/* a place to put the output */
 	    int, int, int, int,		/* the parsed format */
 	    int, int);
+char   *xfflagstostr(unsigned long);
 
 char *timefmt;
 int linkfail;
@@ -329,6 +330,21 @@ main(int argc, char *argv[])
 	return (am_readlink ? linkfail : errs);
 }
 
+/*
+ * fflagstostr() wrapper that leaks only once
+ */
+char *
+xfflagstostr(unsigned long fflags)
+{
+	static char *str = NULL;
+
+	if (str != NULL)
+		free(str);
+
+	str = fflagstostr(fflags);
+	return (str);
+}
+
 void
 usage(const char *synopsis)
 {
@@ -721,8 +737,9 @@ format1(const struct stat *st,
 	case SHOW_st_flags:
 		small = (sizeof(st->st_flags) == 4);
 		data = st->st_flags;
-		sdata = NULL;
-		formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
+		sdata = xfflagstostr(st->st_flags);
+		formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
+		    FMTF_STRING;
 		if (ofmt == 0)
 			ofmt = FMTF_UNSIGNED;
 		break;
@@ -979,7 +996,7 @@ format1(const struct stat *st,
 	(void)strcat(lfmt, "ll");
 	switch (ofmt) {
 	case FMTF_DECIMAL:	(void)strcat(lfmt, "d");	break;
-	case FMTF_OCTAL:		(void)strcat(lfmt, "o");	break;
+	case FMTF_OCTAL:	(void)strcat(lfmt, "o");	break;
 	case FMTF_UNSIGNED:	(void)strcat(lfmt, "u");	break;
 	case FMTF_HEX:		(void)strcat(lfmt, "x");	break;
 	}


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: jilles 
State-Changed-When: Sat Apr 24 13:54:20 UTC 2010 
State-Changed-Why:  
Applied with small changes to head, thanks. 


Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Sat Apr 24 13:54:20 UTC 2010 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=124349 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/124349: commit references a PR
Date: Sat, 24 Apr 2010 13:53:26 +0000 (UTC)

 Author: jilles
 Date: Sat Apr 24 13:53:12 2010
 New Revision: 207153
 URL: http://svn.freebsd.org/changeset/base/207153
 
 Log:
   stat: Allow -f %Sf to display the file flags symbolically.
   
   I have changed the patch slightly to show '-' if there are no flags just
   like ls -ldo does.
   
   PR:		124349
   Submitted by:	Ighighi
   MFC after:	1 week
 
 Modified:
   head/usr.bin/stat/stat.1
   head/usr.bin/stat/stat.c
 
 Modified: head/usr.bin/stat/stat.1
 ==============================================================================
 --- head/usr.bin/stat/stat.1	Sat Apr 24 12:49:52 2010	(r207152)
 +++ head/usr.bin/stat/stat.1	Sat Apr 24 13:53:12 2010	(r207153)
 @@ -29,7 +29,7 @@
  .\"
  .\" $FreeBSD$
  .\"
 -.Dd April 27, 2007
 +.Dd April 24, 2010
  .Dt STAT 1
  .Os
  .Sh NAME
 @@ -232,6 +232,11 @@ Display date in
  format.
  .It Cm dr
  Display actual device name.
 +.It Cm f
 +Display the flags of
 +.Ar file
 +as in
 +.Nm ls Fl lTdo .
  .It Cm gu
  Display group or user name.
  .It Cm p
 
 Modified: head/usr.bin/stat/stat.c
 ==============================================================================
 --- head/usr.bin/stat/stat.c	Sat Apr 24 12:49:52 2010	(r207152)
 +++ head/usr.bin/stat/stat.c	Sat Apr 24 13:53:12 2010	(r207153)
 @@ -182,6 +182,9 @@ int	format1(const struct stat *,	/* stat
  	    char *, size_t,		/* a place to put the output */
  	    int, int, int, int,		/* the parsed format */
  	    int, int);
 +#if HAVE_STRUCT_STAT_ST_FLAGS
 +char   *xfflagstostr(unsigned long);
 +#endif
  
  char *timefmt;
  int linkfail;
 @@ -333,6 +336,25 @@ main(int argc, char *argv[])
  	return (am_readlink ? linkfail : errs);
  }
  
 +#if HAVE_STRUCT_STAT_ST_FLAGS
 +/*
 + * fflagstostr() wrapper that leaks only once
 + */
 +char *
 +xfflagstostr(unsigned long fflags)
 +{
 +	static char *str = NULL;
 +
 +	if (str != NULL)
 +		free(str);
 +
 +	str = fflagstostr(fflags);
 +	if (str == NULL)
 +		err(1, "fflagstostr");
 +	return (str);
 +}
 +#endif /* HAVE_STRUCT_STAT_ST_FLAGS */
 +
  void
  usage(const char *synopsis)
  {
 @@ -725,8 +747,11 @@ format1(const struct stat *st,
  	case SHOW_st_flags:
  		small = (sizeof(st->st_flags) == 4);
  		data = st->st_flags;
 -		sdata = NULL;
 -		formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
 +		sdata = xfflagstostr(st->st_flags);
 +		if (*sdata == '\0')
 +			sdata = "-";
 +		formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
 +		    FMTF_STRING;
  		if (ofmt == 0)
  			ofmt = FMTF_UNSIGNED;
  		break;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/124349: commit references a PR
Date: Sat,  1 May 2010 14:36:18 +0000 (UTC)

 Author: jilles
 Date: Sat May  1 14:36:04 2010
 New Revision: 207466
 URL: http://svn.freebsd.org/changeset/base/207466
 
 Log:
   MFC r207153: stat: Allow -f %Sf to display the file flags symbolically.
   
   PR:		124349
 
 Modified:
   stable/8/usr.bin/stat/stat.1
   stable/8/usr.bin/stat/stat.c
 Directory Properties:
   stable/8/usr.bin/stat/   (props changed)
 
 Modified: stable/8/usr.bin/stat/stat.1
 ==============================================================================
 --- stable/8/usr.bin/stat/stat.1	Sat May  1 14:33:26 2010	(r207465)
 +++ stable/8/usr.bin/stat/stat.1	Sat May  1 14:36:04 2010	(r207466)
 @@ -36,7 +36,7 @@
  .\"
  .\" $FreeBSD$
  .\"
 -.Dd April 27, 2007
 +.Dd April 24, 2010
  .Dt STAT 1
  .Os
  .Sh NAME
 @@ -239,6 +239,11 @@ Display date in
  format.
  .It Cm dr
  Display actual device name.
 +.It Cm f
 +Display the flags of
 +.Ar file
 +as in
 +.Nm ls Fl lTdo .
  .It Cm gu
  Display group or user name.
  .It Cm p
 
 Modified: stable/8/usr.bin/stat/stat.c
 ==============================================================================
 --- stable/8/usr.bin/stat/stat.c	Sat May  1 14:33:26 2010	(r207465)
 +++ stable/8/usr.bin/stat/stat.c	Sat May  1 14:36:04 2010	(r207466)
 @@ -189,6 +189,9 @@ int	format1(const struct stat *,	/* stat
  	    char *, size_t,		/* a place to put the output */
  	    int, int, int, int,		/* the parsed format */
  	    int, int);
 +#if HAVE_STRUCT_STAT_ST_FLAGS
 +char   *xfflagstostr(unsigned long);
 +#endif
  
  char *timefmt;
  int linkfail;
 @@ -340,6 +343,25 @@ main(int argc, char *argv[])
  	return (am_readlink ? linkfail : errs);
  }
  
 +#if HAVE_STRUCT_STAT_ST_FLAGS
 +/*
 + * fflagstostr() wrapper that leaks only once
 + */
 +char *
 +xfflagstostr(unsigned long fflags)
 +{
 +	static char *str = NULL;
 +
 +	if (str != NULL)
 +		free(str);
 +
 +	str = fflagstostr(fflags);
 +	if (str == NULL)
 +		err(1, "fflagstostr");
 +	return (str);
 +}
 +#endif /* HAVE_STRUCT_STAT_ST_FLAGS */
 +
  void
  usage(const char *synopsis)
  {
 @@ -732,8 +754,11 @@ format1(const struct stat *st,
  	case SHOW_st_flags:
  		small = (sizeof(st->st_flags) == 4);
  		data = st->st_flags;
 -		sdata = NULL;
 -		formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
 +		sdata = xfflagstostr(st->st_flags);
 +		if (*sdata == '\0')
 +			sdata = "-";
 +		formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
 +		    FMTF_STRING;
  		if (ofmt == 0)
  			ofmt = FMTF_UNSIGNED;
  		break;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: jilles 
State-Changed-When: Tue May 4 21:58:03 UTC 2010 
State-Changed-Why:  
Committed to 9.x, 8.x, 7.x. No MFC to 6.x planned. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=124349 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/124349: commit references a PR
Date: Tue,  4 May 2010 21:56:25 +0000 (UTC)

 Author: jilles
 Date: Tue May  4 21:56:16 2010
 New Revision: 207636
 URL: http://svn.freebsd.org/changeset/base/207636
 
 Log:
   MFC r207153: stat: Allow -f %Sf to display the file flags symbolically.
   
   PR:		124349
 
 Modified:
   stable/7/usr.bin/stat/stat.1
   stable/7/usr.bin/stat/stat.c
 Directory Properties:
   stable/7/usr.bin/stat/   (props changed)
 
 Modified: stable/7/usr.bin/stat/stat.1
 ==============================================================================
 --- stable/7/usr.bin/stat/stat.1	Tue May  4 21:23:59 2010	(r207635)
 +++ stable/7/usr.bin/stat/stat.1	Tue May  4 21:56:16 2010	(r207636)
 @@ -36,7 +36,7 @@
  .\"
  .\" $FreeBSD$
  .\"
 -.Dd April 27, 2007
 +.Dd April 24, 2010
  .Dt STAT 1
  .Os
  .Sh NAME
 @@ -239,6 +239,11 @@ Display date in
  format.
  .It Cm dr
  Display actual device name.
 +.It Cm f
 +Display the flags of
 +.Ar file
 +as in
 +.Nm ls Fl lTdo .
  .It Cm gu
  Display group or user name.
  .It Cm p
 
 Modified: stable/7/usr.bin/stat/stat.c
 ==============================================================================
 --- stable/7/usr.bin/stat/stat.c	Tue May  4 21:23:59 2010	(r207635)
 +++ stable/7/usr.bin/stat/stat.c	Tue May  4 21:56:16 2010	(r207636)
 @@ -187,6 +187,9 @@ int	format1(const struct stat *,	/* stat
  	    char *, size_t,		/* a place to put the output */
  	    int, int, int, int,		/* the parsed format */
  	    int, int);
 +#if HAVE_STRUCT_STAT_ST_FLAGS
 +char   *xfflagstostr(unsigned long);
 +#endif
  
  char *timefmt;
  int linkfail;
 @@ -329,6 +332,25 @@ main(int argc, char *argv[])
  	return (am_readlink ? linkfail : errs);
  }
  
 +#if HAVE_STRUCT_STAT_ST_FLAGS
 +/*
 + * fflagstostr() wrapper that leaks only once
 + */
 +char *
 +xfflagstostr(unsigned long fflags)
 +{
 +	static char *str = NULL;
 +
 +	if (str != NULL)
 +		free(str);
 +
 +	str = fflagstostr(fflags);
 +	if (str == NULL)
 +		err(1, "fflagstostr");
 +	return (str);
 +}
 +#endif /* HAVE_STRUCT_STAT_ST_FLAGS */
 +
  void
  usage(const char *synopsis)
  {
 @@ -721,8 +743,11 @@ format1(const struct stat *st,
  	case SHOW_st_flags:
  		small = (sizeof(st->st_flags) == 4);
  		data = st->st_flags;
 -		sdata = NULL;
 -		formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX;
 +		sdata = xfflagstostr(st->st_flags);
 +		if (*sdata == '\0')
 +			sdata = "-";
 +		formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |
 +		    FMTF_STRING;
  		if (ofmt == 0)
  			ofmt = FMTF_UNSIGNED;
  		break;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
