xref: /netbsd-src/lib/libutil/stat_flags.3 (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1.\" $NetBSD: stat_flags.3,v 1.4 2006/12/23 09:55:47 wiz Exp $
2.\"
3.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Christos Zoulas.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd December 14, 2006
38.Dt STAT_FLAGS 3
39.Os
40.Sh NAME
41.Nm string_to_flags ,
42.Nm flags_to_string
43.Nd Stat flags parsing and printing functions
44.Sh LIBRARY
45.Lb libutil
46.Sh SYNOPSIS
47.In util.h
48.Ft char *
49.Fn flags_to_string "u_long flags" "const char *def"
50.Ft int
51.Fn string_to_flags "char **stringp" "u_long *setp" "u_long clrp"
52.Sh DESCRIPTION
53The
54.Fn flags_to_string
55and
56.Fn string_to_flags
57functions are used by
58programs such as
59.Xr ls 1 ,
60.Xr mtree 8 ,
61.Xr makefs 8 ,
62etc., to parse and/or print the
63.Dv st_flags field in the
64.Xr stat 2
65structure.
66.Pp
67They recognize the following flags:
68.Bl -tag -width "schg (SF_IMMUTABLE)"
69.It Dv arch Pq Dv SF_ARCHIVED
70file is archived.
71.It Dv nodump Pq Dv UF_NODUMP
72do not dump file.
73.It Dv opaque Pq Dv UF_OPAQUE
74directory is opaque in union filesystems.
75.It Dv sappnd Pq Dv SF_APPEND
76writes to the file may only append (superuser only).
77.It Dv schg Pq Dv SF_IMMUTABLE
78file cannot be changed, is immutable (superuser only).
79.It Dv snap Pq Dv SF_SNAPSHOT
80file is snapshot inode.
81.It Dv uappnd Pq Dv UF_APPEND
82writes to the file may only append (user only).
83.It Dv uchg Pq Dv UF_IMMUTABLE
84file cannot be changed, is immutable (user only).
85.El
86.Pp
87The
88.Fn flags_to_string
89function converts the bits set in the
90.Fa flags
91argument to a comma-separated string and returns it.
92If no flags are set, then the
93.Fa def
94string is returned.
95The returned string is allocated via
96.Xr malloc 3
97and it is the responsibility of the caller to
98.Xr free 3
99it.
100.Pp
101The
102.Fn string_to_flags
103function takes a
104.Fa stringp
105of space, comma, or tab separated flag names
106and places their bit value on the
107.Fa setp
108argument.
109If the flag name is prefixed by:
110.Dq no ,
111then the bit value is placed on the
112.Fa clrp
113argument.
114.Sh RETURN VALUES
115.Fn flags_to_string
116returns the symbolic representation of flags, the default string, or
117.Dv NULL
118if allocation failed.
119.Pp
120.Fn string_to_flags
121returns
122.Dv 0
123on success and
124.Dv 1
125if it fails to parse the string, setting
126.Fa stringp
127to point to the first string that it failed to parse.
128.Sh SEE ALSO
129.Xr stat 2
130