1 /***********************************************************************/
2 /* Open Visualization Data Explorer */
3 /* (C) Copyright IBM Corp. 1989,1999 */
4 /* ALL RIGHTS RESERVED */
5 /* This code licensed under the */
6 /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */
7 /***********************************************************************/
8
9 #include <dxconfig.h>
10
11
12
13 #include <dx/dx.h>
14
15 #include "dxpfsmgr.h"
16
17 #ifndef DXD_HAS_LIBIOP
18
_dxf_pfsmgr(int argc,char ** argv)19 Error _dxf_pfsmgr(int argc, char **argv)
20 {
21 DXSetError(ERROR_DATA_INVALID, "#8200");
22 return ERROR;
23 }
24
25 #else /* has libiop */
26
27 #include <sys/types.h>
28 #include <stdlib.h>
29 #include <time.h>
30 #include <string.h>
31
32 #include <iop/pfs.h> /* partition file system */
33
34 #define DXPARTITION "dx:"
35 #define pfsname(x) strchr(x, ':')
36
37 static Error dxdf();
38 static Error dxrm(char *dataset);
39 static Error dxlist(char *partname);
40
41
42 /*
43 * entry point for dx interface to pfs manager calls. inputs are argc, argv
44 * command line arguments. argv[0] is NOT "pfsmgr".
45 */
46
_dxf_pfsmgr(int argc,char ** argv)47 Error _dxf_pfsmgr(int argc, char **argv)
48 {
49 int rc;
50 char *partname;
51
52 /* valid commands: df (disk free space for all partitions)
53 * ls part: (ls -l for that partition)
54 * rm part:dataset (remove - no wildcards allowed)
55 *
56 * default is to list the dx: partition
57 */
58 if ((partname = getenv("PFSDRIVE")) == NULL)
59 partname = DXPARTITION;
60
61 if (argc > 0) {
62
63 if (!strcmp(argv[0], "ls")) {
64 if (argc > 1)
65 rc = dxlist(argv[1]);
66 else
67 rc = dxlist(partname);
68 goto done;
69 }
70
71 else if (!strcmp(argv[0], "df")) {
72 rc = dxdf();
73 goto done;
74 }
75
76 else if (!strcmp(argv[0], "rm") ||
77 !strcmp(argv[0], "del") ||
78 !strcmp(argv[0], "delete")) {
79 if (argc <= 1) {
80 DXSetError(ERROR_BAD_PARAMETER, "#8210", argv[0]);
81 rc = ERROR;
82 goto done;
83 }
84 rc = dxrm(argv[1]);
85 goto done;
86 }
87
88 else {
89 DXSetError(ERROR_BAD_PARAMETER, "#8220");
90 rc = ERROR;
91 goto done;
92 }
93 }
94
95 else
96 rc = dxlist(partname);
97
98 done:
99 if (rc == OK)
100 return OK;
101
102 #if 1 /* temp - remove when exec prints error returns from here */
103 DXPrintError("pfs");
104 #endif
105 return rc;
106 }
107
108
109 /* df (disk freespace) command
110 */
dxdf()111 static Error dxdf()
112 {
113 char dname[PFS_NAME_LEN];
114 int rc, i, j;
115 u_int tsize, fsize;
116
117 /* is there a config file for the array disk? with partitions? */
118 i = pfs_drive_count();
119 if (i <= 0) {
120 DXSetError(ERROR_DATA_INVALID, "#8230");
121 return ERROR;
122 }
123
124 DXBeginLongMessage();
125
126 /* make sure at least one of the defined drives is valid */
127 for(j = 0; j < i; j++) {
128 rc = pfs_drive_list(j, dname);
129 if (rc < 0)
130 continue;
131
132 strcat(dname, ":");
133 rc = pfs_size(dname, &tsize);
134 if (rc < 0)
135 continue;
136
137 rc = pfs_free(dname, &fsize);
138 if (rc < 0)
139 continue;
140
141 DXMessage("%-20s %5d total blocks, %5d blocks free\n",dname,tsize,fsize);
142
143 }
144
145 DXEndLongMessage();
146
147 return OK;
148 }
149
150 /* ls (list) a partition
151 */
dxlist(char * partname)152 Error dxlist(char *partname)
153 {
154 int i, n;
155 char buf[PFS_NAME_LEN];
156 char *gm_buf = NULL;
157 time_t t;
158 pfs_stat_t ps;
159
160 n = pfs_count(partname);
161 if (n <= 0) {
162 DXSetError(ERROR_DATA_INVALID, "#8240", partname);
163 return ERROR;
164 }
165
166 gm_buf = (char *)DXAllocate(n * PFS_NAME_LEN);
167 if (!gm_buf)
168 return ERROR;
169
170 if (pfs_list(partname, gm_buf, 0, &n) < 0) {
171 DXSetError(ERROR_DATA_INVALID, pfs_errmsg(pfs_errno));
172 return ERROR;
173 }
174
175 strcpy(buf, partname);
176
177 DXBeginLongMessage();
178
179 for(i=0; i<n; i++) {
180
181 strcpy(buf+strlen(partname), gm_buf + i * PFS_NAME_LEN);
182
183 if (pfs_stat(buf, &ps) < 0) {
184 DXSetError(ERROR_DATA_INVALID, pfs_errmsg(pfs_errno));
185 return ERROR;
186 }
187
188 t = (time_t)ps.ps_dat_m;
189 DXMessage("%-25s %5d 64Kblks, modified %s",
190 gm_buf + i * PFS_NAME_LEN, ps.ps_blk, ctime(&t));
191
192 }
193
194 DXEndLongMessage();
195
196 DXFree((Pointer) gm_buf);
197 return OK;
198 }
199
200 /* rm (remove) command
201 */
dxrm(char * dataset)202 static Error dxrm(char *dataset)
203 {
204 int rc, i;
205 pfs_stat_t ps;
206
207
208 /* no wildcards allowed, because there is no confirmation message -
209 * are you really sure you want to delete *?
210 */
211 if (strchr(dataset, '*') || strchr(dataset, '?')) {
212 DXSetError(ERROR_DATA_INVALID, "#8250");
213 return ERROR;
214 }
215
216 if (pfs_stat(dataset, &ps) < 0) {
217 DXSetError(ERROR_DATA_INVALID, pfs_errmsg(pfs_errno));
218 return ERROR;
219 }
220
221 #if 0
222 DXMessage("would be calling pfs_delete(%s) here", dataset);
223 #else
224 if (pfs_delete(dataset) < 0) {
225 DXSetError(ERROR_DATA_INVALID, pfs_errmsg(pfs_errno));
226 return ERROR;
227 }
228 #endif
229
230 return OK;
231 }
232
233
234 #endif /* DXD_HAS_LIBIOP */
235