|
|
1.1 root 1: # include <ingres.h>
2: # include <access.h>
3: # include <sys/file.h>
4: # include <pwd.h>
5: # include <errno.h>
6: # include <signal.h>
7: # include <sccs.h>
8:
9: SCCSID(@(#)ingconv.q 8.5 1/16/85)
10:
11: /*
12: ** INGRES.H -- basic header file for ingres.
13: **
14: ** See also aux.h for definitions used by some but not all.
15: **
16: ** Version:
17: ** @(#)ingres.h 7.1 2/5/81
18: */
19:
20:
21: /*
22: ** RELATION relation struct
23: **
24: ** The RELATION relation contains one tuple for each relation
25: ** in the database. This relation contains information which
26: ** describes how each relation is actually stored in the
27: ** database, who the owner is, information about its size,
28: ** assorted operation information, etc.
29: */
30:
31: struct orelation
32: {
33: c_12 relid[MAXNAME]; /* relation name */
34: c_2 relowner[2]; /* code of relation owner */
35: i_1 relspec; /* storage mode of relation */
36: /* M_HEAP unsorted paged heap */
37: /* -M_HEAP compressed heap */
38: /* M_ISAM isam */
39: /* -M_ISAM compressed isam */
40: /* M_HASH hashed */
41: /* -M_HASH compressed hash */
42: i_1 relindxd; /* -1 rel is an index, 0 not indexed, 1 indexed */
43: i_2 relstat2; /* more status bits */
44: i_2 relstat; /* relation status bits */
45: i_4 relsave; /*unix time until which relation is saved*/
46: i_4 reltups; /*number of tuples in relation */
47: i_2 relatts; /*number of attributes in relation */
48: i_2 relwid; /*width (in bytes) of relation */
49: i_4 relprim; /*no. of primary pages in relation*/
50: i_4 relfree; /* head of freelist (b-trees only) */
51: i_4 relstamp; /*time of last mod*/
52: };
53:
54:
55: /*
56: ** Definitions for the range table.
57: **
58: ** Version:
59: ** @(#)range.h 7.1 2/5/81
60: */
61:
62:
63:
64: /*
65: ** DESCRIPTOR struct
66: **
67: ** The DESCRIPTOR struct is initialized by OPENR to describe any
68: ** open relation. The first part of the descriptor is the tuple
69: ** from the RELATION relation. The remainder contains some magic
70: ** numbers and a template initialized from the ATTRIBUTE relation.
71: **
72: ** This structure also defines the range table.
73: */
74:
75: struct odescriptor
76: {
77: struct orelation reldum;
78: /*the above part of the descriptor struct is identical
79: to the relation struct and the inormation in this
80: part of the struct is read directly from the
81: relation tuple by openr. the rest of the descriptor
82: struct is calculated by openr. */
83: char relvname[MAXNAME]; /* range variable name */
84: i_2 relfp; /*filep for relation , if open */
85: i_2 relopn; /*indicates if relation is really open*/
86: tid_type reltid; /*when relation is open, this indicates
87: the tid in the relation relation for
88: this relation */
89: i_4 reladds; /*no. of additions of tuples during this open*/
90: i_2 reloff[MAXDOM]; /*reloff[i] is offset to domain i */
91: c_1 relfrmt[MAXDOM]; /* format of domain i
92: ** INT, FLOAT, or CHAR */
93: c_1 relfrml[MAXDOM]; /* relfrml[i] is an unsigned integer
94: which indicates length
95: in bytes of domain */
96: c_1 relxtra[MAXDOM]; /*relxtra[i] is non-zero if domain i is
97: ** a key domain for the relation */
98: c_1 relgiven[MAXDOM]; /*cleared by openr and set before
99: call to find to indicate value of this
100: domain has been supplied in the key*/
101: };
102:
103: #
104: /*
105: ** ACCESS.H -- definitions relating to the access methods.
106: **
107: ** Version:
108: ** @(#)access.h 7.1 2/5/81
109: */
110:
111:
112: /*
113: ** ADMIN file struct
114: **
115: ** The ADMIN struct describes the initial part of the ADMIN file
116: ** which exists in each database. This file is used to initially
117: ** create the database, to maintain some information about the
118: ** database, and to access the RELATION and ATTRIBUTE relations
119: ** on OPENR calls.
120: */
121:
122:
123: struct oadmin
124: {
125: struct adminhdr adhdr;
126: struct odescriptor adreld;
127: struct odescriptor adattd;
128: };
129: /*
130: ** VERSION.H -- system version definition file.
131: **
132: ** NOTICE:
133: ** Version numbers stored in files are SCCS id's
134: ** and may not correspond to the external distribution
135: ** version number. The distribution number applies to
136: ** the entire system and not to any particular file.
137: ** This file defines a "release" number, used for
138: ** creating file names. The entire system version
139: ** number (including mod number) is defined by
140: ** conf/version.c.
141: **
142: ** Version:
143: ** @(#)version.h 8.1 12/31/84
144: */
145:
146:
147: /*
148: ** VERSION is the version number of this incarnation of INGRES
149: ** for purposes of creating file names.
150: ** DBVERCODE is the code for this database version stored in
151: ** the admin file.
152: ** PATHEXT is an extension for the path as derived from the
153: ** "ingres" entry in the password file to determine
154: ** the "Pathname" variable. If it is not defined,
155: ** no extension is made.
156: */
157:
158: # define VERSION "8" /* version number */
159: # define DBVERCODE 1 /* database version code */
160: /* # define PATHEXT "/x" /* the root path extension */
161: extern struct oadmin OAdmin;
162: struct admin Admin;
163: char Ingcode[3]; /* Ingres code of ingres */
164: char User[3]; /* Ingres code for DBA of this database */
165:
166:
167: /*
168: ** Ingconv
169: ** Convert version 7 databases into version 8 databases.
170: ** We assume that there is a $P/bin7 to fake everything with.
171: */
172: main(argc,argv)
173: int argc;
174: char **argv;
175: {
176:
177: struct passwd *pwd;
178: int fd;
179: int i;
180: int oldsigint;
181: int oldsigquit;
182: char relname[15];
183: char attname[15];
184: char orelname[15];
185: char oattname[15];
186: char buffer[1000];
187: char *path;
188: int sflag = 0;
189: extern int errno;
190: extern int goodbye();
191: extern int (*ExitFn)();
192: extern char *getenv();
193:
194: argc--;
195: argv++;
196:
197: ExitFn = goodbye;
198:
199: if ( argc != 1 )
200: {
201: if ( argc == 2 && strcmp(*argv,"-s") == 0 )
202: {
203: sflag = 1;
204: argc--;
205: argv++;
206: }
207: else
208: syserr("ingconv: wrong number of arguments, useage 'ingconv [-s] database'");
209: }
210:
211: if ( (pwd = getpwnam("ingres")) == 0 )
212: syserr("ingconv: can't find ingres in password file");
213:
214: /*
215: ** Wander into ~ingres/bin7, and then make sure
216: ** that the Ingres we get is the one here. This will
217: ** be a version 7 ingres.
218: */
219: if ( chdir(pwd->pw_dir) == -1 )
220: syserr("can't chdir to %s",pwd->pw_dir);
221: if ( chdir("bin7") == -1 )
222: syserr("can't chdir to bin7");
223: if ( (path = getenv("PATH")) == 0 )
224: syserr("No PATH environment");
225: strcpy(path,":.:");
226:
227: printf("converting database '%s'\n",*argv);
228: /*
229: ** Make new versions of the relation relation, and
230: ** attribute relations. Store these new things as
231: ** "_rtempv8" and "_atempv8".
232: */
233: changerels(*argv);
234:
235:
236: /*
237: ** Now we go into the data/base/database, and do some magic
238: ** disgusting stuff.
239: */
240: if ( chdir(pwd->pw_dir) == -1 )
241: syserr("can't chdir to %s",pwd->pw_dir);
242: if ( chdir("data/base") == -1 )
243: syserr("can't chdir to data/base");
244:
245: errno = 0;
246: if ( chdir(*argv) == -1 )
247: {
248: if ( errno == ENOTDIR )
249: syserr("can't handle indirect files, change it into a symbolic link first");
250: syserr("no database '%s'",*argv);
251: }
252:
253: bzero(&Admin, sizeof (Admin));
254: bzero(&OAdmin, sizeof (OAdmin));
255:
256: if ( (fd = open("admin",O_RDONLY)) == -1 )
257: syserr("can't open admin file");
258:
259: /*
260: ** Read in the old admin relation, then write out a new
261: ** version into _admin.
262: */
263: startadmin(fd);
264: close(fd);
265: Admin.adhdr = OAdmin.adhdr;
266: descasign(&OAdmin.adreld, &Admin.adreld);
267: descasign(&OAdmin.adattd, &Admin.adattd);
268: Admin.adhdr.adreldsz = Admin.adhdr.adattdsz = sizeof Admin.adreld;
269:
270: if ( (fd = open("_admin",O_WRONLY|O_CREAT,0600)) == -1 )
271: syserr("can't create '_admin' temp file");
272: if ( write(fd,&Admin, sizeof (Admin)) != sizeof (Admin) )
273: syserr("can't write _admin file");
274: close(fd);
275:
276:
277:
278: strcpy(orelname,"relation ");
279: strcat(orelname,User);
280: strcpy(relname,"_rtempv8 ");
281: strcat(relname,Ingcode);
282:
283: strcpy(oattname,"attribute ");
284: strcat(oattname,User);
285: strcpy(attname,"_atempv8 ");
286: strcat(attname,Ingcode);
287: /*
288: ** Up to now, we can be interrupted, now we come to the
289: ** magic stuff that might leave us undefended...
290: */
291: oldsigint = (int) signal(SIGINT,SIG_IGN);
292: oldsigquit = (int) signal(SIGQUIT,SIG_IGN);
293: for ( i = 1 ; i < NSIG ; i++ )
294: signal(i,SIG_IGN);
295:
296: if ( rename(attname,oattname) == -1 )
297: syserr("Could not rename '%s' to '%s'",attname, oattname);
298: if ( rename(relname,orelname) == -1 )
299: syserr("Could not rename '%s' to '%s', database is now corrupted!!!!, restore the attribute relation from tape.",relname, orelname);
300: if ( rename("_admin","admin") == -1 )
301: syserr("Could not rename '_admin' to 'admin'. Database is now corrupted, read the attribute and relation relations in from tape.");
302:
303: /*
304: ** Turn the interrupts back on, now that the
305: ** critical section is over.
306: */
307: for ( i = 1 ; i < NSIG ; i++ )
308: signal(i,SIG_DFL);
309: signal(SIGINT,oldsigint);
310: signal(SIGQUIT,oldsigquit);
311: if ( sflag )
312: sprintf(buffer,"%s/bin/sysmod -s %s",pwd->pw_dir,*argv);
313: else
314: sprintf(buffer,"%s/bin/sysmod %s",pwd->pw_dir,*argv);
315: printf("%s\n",buffer);
316: system(buffer);
317: printf("Database '%s' is now a version 8 database.\n",*argv);
318: }
319:
320: /*
321: ** Assign an old descriptor to a new descriptor.
322: */
323: descasign(a,b)
324: struct odescriptor *a;
325: struct descriptor *b;
326: {
327: struct orelation *orel;
328: struct relation *rel;
329:
330: strcpy(b->relvname,a->relvname);
331: b->relfp = a->relfp;
332: b->relopn = a->relopn;
333: b->reltid = a->reltid;
334: b->reladds = a->reladds;
335: bcopy(a->reloff,b->reloff,(sizeof (i_2)) * MAXDOM);
336: bcopy(a->relfrmt,b->relfrmt,(sizeof (c_1)) * MAXDOM);
337: bcopy(a->relfrml,b->relfrml,(sizeof (c_1)) * MAXDOM);
338: bcopy(a->relxtra,b->relxtra,(sizeof (c_1)) * MAXDOM);
339: bcopy(a->relgiven,b->relgiven,(sizeof (c_1)) * MAXDOM);
340:
341: orel = &a->reldum;
342: rel = &b->reldum;
343:
344: bcopy(orel->relid,rel->relid,MAXNAME);
345: bcopy(orel->relowner,rel->relowner,2);
346: rel->relspec = orel->relspec;
347: rel->relindxd = orel->relindxd;
348: rel->relstat2 = orel->relstat2;
349: rel->relstat = orel->relstat;
350: rel->relsave = orel->relsave;
351: rel->reltups = orel->reltups;
352: rel->relatts = orel->relatts;
353: rel->relwid = orel->relwid;
354: rel->relprim = orel->relprim;
355: rel->relfree = orel->relfree;
356: rel->relstamp = orel->relstamp;
357: }
358:
359: goodbye()
360: {
361: exit(1);
362: }
363:
364:
365:
366: struct oadmin OAdmin;
367:
368: /*
369: ** STARTADMIN -- starts admin file version, etc.
370: **
371: ** The checks for database version code and whatnot are
372: ** factored out into this routine. When this routine returns,
373: ** the admin file should be legible to this program.
374: ** If the admin file is not legible, it will syserr.
375: **
376: ** Parameters:
377: ** fd -- open file descriptor for admin file. Only
378: ** read access is required.
379: **
380: ** Returns:
381: ** nothing if ok.
382: ** not at all (or via syserr) if not ok.
383: **
384: ** Side Effects:
385: ** The OAdmin.adhdr struct will be filled in.
386: */
387:
388: startadmin(fd)
389: register int fd;
390: {
391: register int i;
392: register int k;
393:
394: i = ((char *) &OAdmin.adhdr.adversion) - ((char *) &OAdmin.adhdr);
395: if (read(fd, (char *) &OAdmin.adhdr, i) != i)
396: syserr("readadmin: admin read err 1");
397: if (!bitset(A_NEWFMT, OAdmin.adhdr.adflags))
398: syserr("readadmin: cannot use old databases");
399:
400: /* read in remainder of admin header */
401: i = sizeof OAdmin.adhdr;
402: if (OAdmin.adhdr.adlength < i)
403: i = OAdmin.adhdr.adlength;
404: i -= ((char *) &OAdmin.adhdr.adversion) - ((char *) &OAdmin.adhdr);
405: if (i <= 0)
406: syserr("readadmin: adlen=%d, hdrsz=%d, ct=%d", OAdmin.adhdr.adlength, sizeof OAdmin.adhdr, i);
407: if ((k = read(fd, (char *) &OAdmin.adhdr.adversion, i)) != i)
408: syserr("readadmin: admin read err 2, i=%d k=%d", i, k);
409:
410: /* check versions here */
411: if (OAdmin.adhdr.adversion != DBVERCODE)
412: syserr("cannot handle code %d databases (current code is %d)",
413: OAdmin.adhdr.adversion, DBVERCODE);
414: if (OAdmin.adhdr.adreldsz != sizeof OAdmin.adreld)
415: syserr("checkadmin: descriptor size mismatch, dec=%d, actual=%d",
416: OAdmin.adhdr.adreldsz, sizeof OAdmin.adreld);
417:
418: /* get to beginning of descriptors */
419: if (lseek(fd, (long) OAdmin.adhdr.adlength, 0) < 0)
420: syserr("checkadmin: seek");
421:
422: /* read the descriptors */
423: if (read(fd, (char *) &OAdmin.adreld, OAdmin.adhdr.adreldsz) != OAdmin.adhdr.adreldsz)
424: syserr("checkadmin: reld read sz=%d", OAdmin.adhdr.adreldsz);
425: if (read(fd, (char *) &OAdmin.adattd, OAdmin.adhdr.adattdsz) != OAdmin.adhdr.adattdsz)
426: syserr("checkadmin: attd read sz=%d", OAdmin.adhdr.adattdsz);
427: }
428:
429: changerels(database)
430: ## char *database;
431: {
432: ## char *user;
433: ## int sysmod;
434: ## char *delname;
435: char data[3];
436: extern char Ingcode[];
437: extern char User[];
438:
439: user = data;
440: user[0] = user[1] = user[2] = '\0';
441: sysmod = -1;
442: delname = "delim";
443:
444:
445: ## ingres database "-rheap"
446: ## range of r is relation
447: ## range of a is attribute
448:
449: ## retrieve ( sysmod = r.relspec ) where r.relid = "_rtempv8"
450:
451: if ( sysmod != -1 )
452: syserr("The data base '%s' has a the relation '_rtempv8'. Please remove, or change this relation before using this program");
453:
454: ## retrieve ( sysmod = r.relspec ) where r.relid = "_rtempv8"
455:
456: if ( sysmod != -1 )
457: syserr("The data base '%s' has a the relation '_atempv8'. Please remove, or change this name before using this program");
458:
459: ## create _rtempv8(relid=c12, relowner=c2, relspec=i1, relindxd=i1,
460: ## relstat2=i2, relstat=i2, relsave=i4, reltups=i4,
461: ## relatts=i2, relwid=i2, relprim=i4, relfree=i4,
462: ## relstamp=i4, reldim=i2)
463:
464:
465: ## retrieve ( user = r.relowner ) where r.relid = "relation"
466: User[0] = user[0];
467: User[1] = user[1];
468: User[2] = '\0';
469:
470: ## create rdelim (order=i4, group=c12, delname=c12, type=i4, bitmap=c16)
471: ## modify rdelim to isam on order,group,delname
472:
473: ## retrieve into _rtempv81 (r.all, reldim = 0)
474: ## range of t is _rtempv81
475: ## append _rtempv8 (t.all)
476: ## destroy _rtempv81
477: ## range of t is _rtempv8
478: ## delete t where t.relid = "_rtempv8" or t.relid = "_rtempv81"
479: ## replace t ( relsave = 0, relstat = 275, relspec = 11) where t.relid = "rdelim"
480: ## replace t ( reltups = t.reltups -1, relatts = t.relatts + 1, relwid = t.relwid + 2) where
481: ## t.relid = "relation"
482:
483:
484: ## retrieve into _atempv8 (a.all)
485: ## append _atempv8(attrelid="relation",attowner=user, attid=14, attname="reldim", attoff=44, attfrmt="i", attfrml=2, attxtra=0)
486:
487: ## range of t is _atempv8
488: ## delete t where t.attrelid = "_rtempv8" or t.attrelid = "_rtempv81" or t.attrelid = "_atempv8"
489:
490: sysmod = 0;
491:
492: ## retrieve ( sysmod = r.relspec ) where r.relid = "relation" and r.relowner = user
493:
494: if ( sysmod != 5 )
495: {
496: ## modify _rtempv8 to hash on relid
497: ## modify _atempv8 to hash on attrelid,attowner
498: }
499:
500: user[0] = user[1] = '\0';
501: ## retrieve ( user = r.relowner ) where r.relid = "_atempv8"
502:
503: if ( (Ingcode[0] = user[0]) == '\0' )
504: syserr("can't find my own name");
505: Ingcode[1] = user[1];
506: Ingcode[2] = '\0';
507: ## exit
508: sync();
509: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.