xref: /freebsd/lib/libc/string/strmode.3 (revision 069ac184)
1.\" Copyright (c) 1990, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd July 28, 1994
29.Dt STRMODE 3
30.Os
31.Sh NAME
32.Nm strmode
33.Nd convert inode status information into a symbolic string
34.Sh LIBRARY
35.Lb libc
36.Sh SYNOPSIS
37.In string.h
38.Ft void
39.Fn strmode "mode_t mode" "char *bp"
40.Sh DESCRIPTION
41The
42.Fn strmode
43function
44converts a file
45.Fa mode
46(the type and permission information associated with an inode, see
47.Xr stat 2 )
48into a symbolic string which is stored in the location referenced by
49.Fa bp .
50This stored string is eleven characters in length plus a trailing
51.Dv NUL .
52.Pp
53The first character is the inode type, and will be one of the following:
54.Pp
55.Bl -tag -width flag -offset indent -compact
56.It \-
57regular file
58.It b
59block special
60.It c
61character special
62.It d
63directory
64.It l
65symbolic link
66.It p
67fifo
68.It s
69socket
70.It w
71whiteout
72.It ?
73unknown inode type
74.El
75.Pp
76The next nine characters encode three sets of permissions, in three
77characters each.
78The first three characters are the permissions for the owner of the
79file, the second three for the group the file belongs to, and the
80third for the ``other'', or default, set of users.
81.Pp
82Permission checking is done as specifically as possible.
83If read permission is denied to the owner of a file in the first set
84of permissions, the owner of the file will not be able to read the file.
85This is true even if the owner is in the file's group and the group
86permissions allow reading or the ``other'' permissions allow reading.
87.Pp
88If the first character of the three character set is an ``r'', the file is
89readable for that set of users; if a dash ``\-'', it is not readable.
90.Pp
91If the second character of the three character set is a ``w'', the file is
92writable for that set of users; if a dash ``\-'', it is not writable.
93.Pp
94The third character is the first of the following characters that apply:
95.Bl -tag -width xxxx
96.It S
97If the character is part of the owner permissions and the file is not
98executable or the directory is not searchable by the owner, and the
99set-user-id bit is set.
100.It S
101If the character is part of the group permissions and the file is not
102executable or the directory is not searchable by the group, and the
103set-group-id bit is set.
104.It T
105If the character is part of the other permissions and the file is not
106executable or the directory is not searchable by others, and the ``sticky''
107.Pq Dv S_ISVTX
108bit is set.
109.It s
110If the character is part of the owner permissions and the file is
111executable or the directory searchable by the owner, and the set-user-id
112bit is set.
113.It s
114If the character is part of the group permissions and the file is
115executable or the directory searchable by the group, and the set-group-id
116bit is set.
117.It t
118If the character is part of the other permissions and the file is
119executable or the directory searchable by others, and the ``sticky''
120.Pq Dv S_ISVTX
121bit is set.
122.It x
123The file is executable or the directory is searchable.
124.It \-
125None of the above apply.
126.El
127.Pp
128The last character will always be a space.
129.Sh SEE ALSO
130.Xr chmod 1 ,
131.Xr find 1 ,
132.Xr stat 2 ,
133.Xr getmode 3 ,
134.Xr setmode 3
135.Sh HISTORY
136The
137.Fn strmode
138function first appeared in
139.Bx 4.4 .
140