1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 1996-2003 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate #include <locale.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
32*7c478bd9Sstevel@tonic-gate #include <stdio.h>
33*7c478bd9Sstevel@tonic-gate #include <dirent.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/acl.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_fs.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_dlog.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_ioctl.h>
38*7c478bd9Sstevel@tonic-gate #include <errno.h>
39*7c478bd9Sstevel@tonic-gate #include <string.h>
40*7c478bd9Sstevel@tonic-gate
41*7c478bd9Sstevel@tonic-gate extern int verbose;
42*7c478bd9Sstevel@tonic-gate
43*7c478bd9Sstevel@tonic-gate /*
44*7c478bd9Sstevel@tonic-gate * Function used by -d option to display pathname
45*7c478bd9Sstevel@tonic-gate */
46*7c478bd9Sstevel@tonic-gate int
prtfn(char * pathnam,char * fnam,DIR * dirp,int depth)47*7c478bd9Sstevel@tonic-gate prtfn(char *pathnam, char *fnam, DIR *dirp, int depth)
48*7c478bd9Sstevel@tonic-gate {
49*7c478bd9Sstevel@tonic-gate printf("%s\n", pathnam);
50*7c478bd9Sstevel@tonic-gate return (0);
51*7c478bd9Sstevel@tonic-gate }
52*7c478bd9Sstevel@tonic-gate
53*7c478bd9Sstevel@tonic-gate /*
54*7c478bd9Sstevel@tonic-gate * Function used by -p option to pack pathname
55*7c478bd9Sstevel@tonic-gate */
56*7c478bd9Sstevel@tonic-gate int
packfn(char * pathnam,char * fnam,DIR * dirp,int depth)57*7c478bd9Sstevel@tonic-gate packfn(char *pathnam, char *fnam, DIR *dirp, int depth)
58*7c478bd9Sstevel@tonic-gate {
59*7c478bd9Sstevel@tonic-gate cachefsio_pack_t pack;
60*7c478bd9Sstevel@tonic-gate int xx;
61*7c478bd9Sstevel@tonic-gate int len;
62*7c478bd9Sstevel@tonic-gate
63*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
64*7c478bd9Sstevel@tonic-gate printf("packfn: pathnam = %s", pathnam);
65*7c478bd9Sstevel@tonic-gate fflush(stdout);
66*7c478bd9Sstevel@tonic-gate if (fnam != NULL) {
67*7c478bd9Sstevel@tonic-gate printf(" fnam = %s\n", fnam);
68*7c478bd9Sstevel@tonic-gate } else {
69*7c478bd9Sstevel@tonic-gate printf("\n");
70*7c478bd9Sstevel@tonic-gate }
71*7c478bd9Sstevel@tonic-gate printf("packfn: dirp = %x depth = %d\n", dirp, depth);
72*7c478bd9Sstevel@tonic-gate fflush(stdout);
73*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
74*7c478bd9Sstevel@tonic-gate if (fnam != NULL) {
75*7c478bd9Sstevel@tonic-gate len = strlen(fnam);
76*7c478bd9Sstevel@tonic-gate if (len >= sizeof (pack.p_name)) {
77*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext(
78*7c478bd9Sstevel@tonic-gate "cachefspack: file name too long - %s\n"),
79*7c478bd9Sstevel@tonic-gate pathnam);
80*7c478bd9Sstevel@tonic-gate return (-1);
81*7c478bd9Sstevel@tonic-gate }
82*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
83*7c478bd9Sstevel@tonic-gate printf("packfn: len = %d\n", len);
84*7c478bd9Sstevel@tonic-gate fflush(stdout);
85*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
86*7c478bd9Sstevel@tonic-gate while (fnam[len-1] == '/') {
87*7c478bd9Sstevel@tonic-gate len--;
88*7c478bd9Sstevel@tonic-gate }
89*7c478bd9Sstevel@tonic-gate strncpy(pack.p_name, fnam, len);
90*7c478bd9Sstevel@tonic-gate } else {
91*7c478bd9Sstevel@tonic-gate len = 0;
92*7c478bd9Sstevel@tonic-gate }
93*7c478bd9Sstevel@tonic-gate pack.p_name[len] = '\0';
94*7c478bd9Sstevel@tonic-gate pack.p_status = 0;
95*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
96*7c478bd9Sstevel@tonic-gate printf("packfn: pack.p_name = %s pack.p_status = %x\n",
97*7c478bd9Sstevel@tonic-gate pack.p_name, pack.p_status);
98*7c478bd9Sstevel@tonic-gate fflush(stdout);
99*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
100*7c478bd9Sstevel@tonic-gate
101*7c478bd9Sstevel@tonic-gate xx = ioctl(dirp->dd_fd, CACHEFSIO_PACK, &pack);
102*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
103*7c478bd9Sstevel@tonic-gate printf("packfn: xx = %x errno = %d\n", xx, errno);
104*7c478bd9Sstevel@tonic-gate fflush(stdout);
105*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
106*7c478bd9Sstevel@tonic-gate if (xx) {
107*7c478bd9Sstevel@tonic-gate if (errno == ENOTTY) {
108*7c478bd9Sstevel@tonic-gate return (0);
109*7c478bd9Sstevel@tonic-gate }
110*7c478bd9Sstevel@tonic-gate if (errno == ENOSYS) {
111*7c478bd9Sstevel@tonic-gate return (0);
112*7c478bd9Sstevel@tonic-gate }
113*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("cachefspack: %s - "), pathnam);
114*7c478bd9Sstevel@tonic-gate perror(gettext("can't pack file"));
115*7c478bd9Sstevel@tonic-gate return (-1);
116*7c478bd9Sstevel@tonic-gate }
117*7c478bd9Sstevel@tonic-gate return (0);
118*7c478bd9Sstevel@tonic-gate }
119*7c478bd9Sstevel@tonic-gate
120*7c478bd9Sstevel@tonic-gate /*
121*7c478bd9Sstevel@tonic-gate * Function used by -p option to unpack pathname
122*7c478bd9Sstevel@tonic-gate */
123*7c478bd9Sstevel@tonic-gate int
unpackfn(char * pathnam,char * fnam,DIR * dirp,int depth)124*7c478bd9Sstevel@tonic-gate unpackfn(char *pathnam, char *fnam, DIR *dirp, int depth)
125*7c478bd9Sstevel@tonic-gate {
126*7c478bd9Sstevel@tonic-gate cachefsio_pack_t pack;
127*7c478bd9Sstevel@tonic-gate int xx;
128*7c478bd9Sstevel@tonic-gate int len;
129*7c478bd9Sstevel@tonic-gate
130*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
131*7c478bd9Sstevel@tonic-gate printf("unpackfn: pathnam = %s ", pathnam);
132*7c478bd9Sstevel@tonic-gate if (fnam != NULL) {
133*7c478bd9Sstevel@tonic-gate printf(" fnam = %s\n", fnam);
134*7c478bd9Sstevel@tonic-gate } else {
135*7c478bd9Sstevel@tonic-gate printf("\n");
136*7c478bd9Sstevel@tonic-gate }
137*7c478bd9Sstevel@tonic-gate printf("unpackfn: dirp = %x depth = %d\n", dirp, depth);
138*7c478bd9Sstevel@tonic-gate fflush(stdout);
139*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
140*7c478bd9Sstevel@tonic-gate if (fnam != NULL) {
141*7c478bd9Sstevel@tonic-gate len = strlen(fnam);
142*7c478bd9Sstevel@tonic-gate if (len >= sizeof (pack.p_name)) {
143*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext(
144*7c478bd9Sstevel@tonic-gate "cachefspack: file name too long - %s\n"), pathnam);
145*7c478bd9Sstevel@tonic-gate return (-1);
146*7c478bd9Sstevel@tonic-gate }
147*7c478bd9Sstevel@tonic-gate while (fnam[len-1] == '/') {
148*7c478bd9Sstevel@tonic-gate len--;
149*7c478bd9Sstevel@tonic-gate }
150*7c478bd9Sstevel@tonic-gate strncpy(pack.p_name, fnam, len);
151*7c478bd9Sstevel@tonic-gate } else {
152*7c478bd9Sstevel@tonic-gate len = 0;
153*7c478bd9Sstevel@tonic-gate }
154*7c478bd9Sstevel@tonic-gate pack.p_name[len] = '\0';
155*7c478bd9Sstevel@tonic-gate pack.p_status = 0;
156*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
157*7c478bd9Sstevel@tonic-gate printf("unpackfn: pack.p_name = %s pack.p_status = %x\n",
158*7c478bd9Sstevel@tonic-gate pack.p_name, pack.p_status);
159*7c478bd9Sstevel@tonic-gate fflush(stdout);
160*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
161*7c478bd9Sstevel@tonic-gate
162*7c478bd9Sstevel@tonic-gate xx = ioctl(dirp->dd_fd, CACHEFSIO_UNPACK, &pack);
163*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
164*7c478bd9Sstevel@tonic-gate printf("unpackfn: pack.p_name = %s pack.p_status = %x\n",
165*7c478bd9Sstevel@tonic-gate pack.p_name, pack.p_status);
166*7c478bd9Sstevel@tonic-gate fflush(stdout);
167*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
168*7c478bd9Sstevel@tonic-gate if (xx) {
169*7c478bd9Sstevel@tonic-gate if (errno == ENOTTY) {
170*7c478bd9Sstevel@tonic-gate return (0);
171*7c478bd9Sstevel@tonic-gate }
172*7c478bd9Sstevel@tonic-gate if (errno == ENOSYS) {
173*7c478bd9Sstevel@tonic-gate return (0);
174*7c478bd9Sstevel@tonic-gate }
175*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("cachefspack: %s - "), pathnam);
176*7c478bd9Sstevel@tonic-gate perror(gettext("can't unpack file"));
177*7c478bd9Sstevel@tonic-gate return (-1);
178*7c478bd9Sstevel@tonic-gate }
179*7c478bd9Sstevel@tonic-gate return (0);
180*7c478bd9Sstevel@tonic-gate }
181*7c478bd9Sstevel@tonic-gate
182*7c478bd9Sstevel@tonic-gate /*
183*7c478bd9Sstevel@tonic-gate * Function used by -i option to print status of pathname
184*7c478bd9Sstevel@tonic-gate */
185*7c478bd9Sstevel@tonic-gate int
inquirefn(char * pathnam,char * fnam,DIR * dirp,int depth)186*7c478bd9Sstevel@tonic-gate inquirefn(char *pathnam, char *fnam, DIR *dirp, int depth)
187*7c478bd9Sstevel@tonic-gate {
188*7c478bd9Sstevel@tonic-gate cachefsio_pack_t pack;
189*7c478bd9Sstevel@tonic-gate int xx;
190*7c478bd9Sstevel@tonic-gate int len;
191*7c478bd9Sstevel@tonic-gate
192*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
193*7c478bd9Sstevel@tonic-gate printf("inquirefn: pathnam = %s ", pathnam);
194*7c478bd9Sstevel@tonic-gate if (fnam != NULL) {
195*7c478bd9Sstevel@tonic-gate printf("fnam = %s\n", fnam);
196*7c478bd9Sstevel@tonic-gate } else {
197*7c478bd9Sstevel@tonic-gate printf("\n");
198*7c478bd9Sstevel@tonic-gate }
199*7c478bd9Sstevel@tonic-gate printf("inquirefn: dirp = %x depth = %d\n", dirp, depth);
200*7c478bd9Sstevel@tonic-gate fflush(stdout);
201*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
202*7c478bd9Sstevel@tonic-gate if (fnam != NULL) {
203*7c478bd9Sstevel@tonic-gate len = strlen(fnam);
204*7c478bd9Sstevel@tonic-gate if (len >= sizeof (pack.p_name)) {
205*7c478bd9Sstevel@tonic-gate fprintf(stderr,
206*7c478bd9Sstevel@tonic-gate gettext("cachefspack: file name too long - %s\n"),
207*7c478bd9Sstevel@tonic-gate pathnam);
208*7c478bd9Sstevel@tonic-gate return (-1);
209*7c478bd9Sstevel@tonic-gate }
210*7c478bd9Sstevel@tonic-gate while (fnam[len-1] == '/') {
211*7c478bd9Sstevel@tonic-gate len--;
212*7c478bd9Sstevel@tonic-gate }
213*7c478bd9Sstevel@tonic-gate strncpy(pack.p_name, fnam, len);
214*7c478bd9Sstevel@tonic-gate } else {
215*7c478bd9Sstevel@tonic-gate len = 0;
216*7c478bd9Sstevel@tonic-gate }
217*7c478bd9Sstevel@tonic-gate pack.p_name[len] = '\0';
218*7c478bd9Sstevel@tonic-gate pack.p_status = 0;
219*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
220*7c478bd9Sstevel@tonic-gate printf("inquirefn: pack.p_name = %s pack.p_status = %x\n",
221*7c478bd9Sstevel@tonic-gate pack.p_name, pack.p_status);
222*7c478bd9Sstevel@tonic-gate fflush(stdout);
223*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
224*7c478bd9Sstevel@tonic-gate
225*7c478bd9Sstevel@tonic-gate xx = ioctl(dirp->dd_fd, CACHEFSIO_PACKINFO, &pack);
226*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
227*7c478bd9Sstevel@tonic-gate printf("inquirefn: xx = %x errno = %d\n", xx, errno);
228*7c478bd9Sstevel@tonic-gate fflush(stdout);
229*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
230*7c478bd9Sstevel@tonic-gate if (xx) {
231*7c478bd9Sstevel@tonic-gate if ((errno == ENOTTY) || (errno == ENOSYS)) {
232*7c478bd9Sstevel@tonic-gate #ifdef CFS_MSG
233*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("cachefspack: "));
234*7c478bd9Sstevel@tonic-gate fprintf(stderr,
235*7c478bd9Sstevel@tonic-gate gettext("%s - is not in a cacheFS file system\n"),
236*7c478bd9Sstevel@tonic-gate pathnam);
237*7c478bd9Sstevel@tonic-gate #endif /* CFS_MSG */
238*7c478bd9Sstevel@tonic-gate return (-1);
239*7c478bd9Sstevel@tonic-gate }
240*7c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("cachefspack: %s - "), pathnam);
241*7c478bd9Sstevel@tonic-gate perror(gettext("can't get info"));
242*7c478bd9Sstevel@tonic-gate return (-2);
243*7c478bd9Sstevel@tonic-gate }
244*7c478bd9Sstevel@tonic-gate
245*7c478bd9Sstevel@tonic-gate printf(gettext("cachefspack: file %s "), pathnam);
246*7c478bd9Sstevel@tonic-gate printf(gettext("marked packed %s, packed %s\n"),
247*7c478bd9Sstevel@tonic-gate (pack.p_status & CACHEFS_PACKED_FILE) ? "YES" : "NO",
248*7c478bd9Sstevel@tonic-gate (pack.p_status & CACHEFS_PACKED_DATA) ? "YES" : "NO");
249*7c478bd9Sstevel@tonic-gate if (verbose) {
250*7c478bd9Sstevel@tonic-gate printf(gettext(" nocache %s\n"),
251*7c478bd9Sstevel@tonic-gate (pack.p_status & CACHEFS_PACKED_NOCACHE) ?
252*7c478bd9Sstevel@tonic-gate "YES" : "NO");
253*7c478bd9Sstevel@tonic-gate }
254*7c478bd9Sstevel@tonic-gate return (0);
255*7c478bd9Sstevel@tonic-gate }
256