4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 #include <sys/param.h>
31 #include <sys/types.h>
32 #include <sys/mkdev.h>
42 visit_dir(const char *path
, const struct stat
*st
,
43 int file_type
, struct FTW
*ft
)
45 const char *uid
, *gid
;
47 char symsrc
[MAXPATHLEN
];
48 char buffer
[MAXPATHLEN
];
50 char name
[MAXPATHLEN
];
51 char maj
[10], min
[10];
54 static int first_time
= 1;
58 * The first directory is the current directory '.',
59 * this is relevant in our protolist, so I throw it out.
63 if ((path
[0] == '.') && (path
[1] == '\0'))
67 abs_name
= (char *)(path
+ 2);
68 maj
[0] = min
[0] = symsrc
[0] = '-';
69 maj
[1] = min
[1] = symsrc
[1] = '\0';
71 (void) strcpy(name
, abs_name
);
73 * is this a relocatable object? if so set
74 * the symsrc appropriately.
76 * All relocatable objects start with /sun or /i86
83 #define ARCH_STR "sun"
85 #define ARCH_STR "i86"
87 #define ARCH_STR "prep"
89 #error "Unknown instruction set"
91 if (strncmp(abs_name
, ARCH_STR
, 3) == 0) {
92 if (((st
->st_mode
& S_IFMT
) == S_IFDIR
) ||
93 ((st
->st_mode
& S_IFMT
) == S_IFLNK
))
96 (void) strcpy(buffer
, abs_name
);
97 if (p
= index(buffer
, '/')) {
98 (void) strcpy(symsrc
, abs_name
);
100 (void) strcpy(name
, p
);
104 switch (st
->st_mode
& S_IFMT
) {
106 (void) sprintf(maj
, "%ld", major(st
->st_rdev
));
107 (void) sprintf(min
, "%ld", minor(st
->st_rdev
));
114 (void) sprintf(maj
, "%ld", major(st
->st_rdev
));
115 (void) sprintf(min
, "%ld", minor(st
->st_rdev
));
122 if ((c
= readlink(path
, symsrc
, MAXPATHLEN
)) == -1)
132 uid
= stdfindbyvalue(st
->st_uid
, usernames
);
136 gid
= stdfindbyvalue(st
->st_gid
, groupnames
);
139 if (st
->st_nlink
== 1)
144 (void) printf("%c %-30s %-20s %4lo %-5s %-5s %6d %2ld %2s %2s\n",
145 ftype
, name
, symsrc
, st
->st_mode
% 010000, uid
, gid
,
146 inum
, st
->st_nlink
, maj
, min
);
151 main(int argc
, char *argv
[])
155 (void) fprintf(stderr
, "usage: protolist <protodir>\n");
159 if (chdir(argv
[1]) < 0) {
164 if (nftw(".", visit_dir
, MAX_DEPTH
, FTW_PHYS
) != 0) {