Exemple #1
0
bool File::openw(const char* filename,uint32_t dir_cluster) {
  if(!openr(filename,dir_cluster)) {
    errnum=0; //Not opening the file is not necessarily an error
    if(!create(filename,dir_cluster)) FAIL(errnum*100+2);
  }
  de.size=0;
  if(!wipeChain()) FAIL(errnum*100+3);
  cluster=de.cluster();
  return true;
}
/* 
** DISP -- display integrity, permit, or define query on a relation
**
**	Finds a relation owned by the user or the DBA and passes
**	the name and owner to the appropritae routine depending on
**	mode.
**
**	Parameters:
**		relation -- relation on which query is to be printed
**		mode -- the print mode:
**			4 -- view
**			5 -- permit
**			6 -- integrity
**
**	Returns:
**		0 -- success
**		1 -- no such relation, or none seeable by the user.
**		3 -- VIEW mode and relation not a view
**		4 -- PERMIT and no permissions on relation
**		5 -- INTEGRITY mode and no integrity constraints
**
**	Trace Flags:
**		33, 8
*/
int
disp(char *relation, int mode)
{
	desc_t		d;
	register int	i;
	extern char	*Resrel;

#ifdef xZTR1
	if (tTf(50, 8))
		printf("disp: relation %s\n", relation);
#endif

	Resrel = relation;
	i = openr(&d, OR_RELTID, relation);
	if (i > 0)
		return (1);
	else if (i < 0)
		syserr("disp: openr(%s) ret %d", relation, i);
	switch (mode) {
	  case 4:		/* View query */
		if (d.d_r.r_status & S_VIEW)
			pr_def(relation, d.d_r.r_owner);
		else 
			return (3);
		break;

	  case 5:
		if (pr_prot(relation, (relation_t *) &d))
			return (4);
		break;

	  case 6:
		if (d.d_r.r_status & S_INTEG)
			pr_integrity(relation, d.d_r.r_owner);
		else
			return (5);
		break;

	  default:
		syserr("disp: mode == %d", mode);
	}
	return (0);
}
int
copy(int pc, paramv_t *pv)
{
	extern char	*Usercode;
	extern int	Noupdt;
	register int	i, pid;
	register char	*cp;
	int		stat;
	int		op;

#ifdef xZTR1
	if (tTf(30,1)) {
		printf("entered copy\n");
		prvect(pc, pv);
	}
#endif
	Duptuple = 0;
	Truncount = 0;
	Tupcount = 0;
	Baddoms = 0;
	Relname = pv[0].pv_val.pv_str;
	Into = (pv[pc-2].pv_val.pv_str[0] == 'i');
	Filename = pv[pc-1].pv_val.pv_str;

	/* relation must exist and not be a system relation */
	/* in addition a copy "from" can't be done if the user */
	/* doesn't own the relation */
	/* and furthermore it can't have an index */
	i = 0;	/* assume all is well */
	if ((op = openr(&Des, OR_WRITE, Relname)) != 0) {
		if (op == AMOPNVIEW_ERR)
			i = NOCPVIEW;
		else {
			if (op < 0)
				syserr("COPY: openr 1 (%.14s) %d", Relname, op);
			else
				/* non-existant relation */
				i = NOEXIST;
		}
	} else {
		if (Into) {
			if ((Des.d_r.r_status & S_PROTALL)
				&& (Des.d_r.r_status & S_PROTRET)
				&& !bequal(Usercode, Des.d_r.r_owner, USERCODE_SIZE))
				i = RELPROTECT;
		} else {
			/* extra checking if this is a copy "from" */

			/* must be owned by the user */
			if (!bequal(Usercode, Des.d_r.r_owner, USERCODE_SIZE))
				i = NOTOWNER;
			else
				/* must be updateable */
				if ((Des.d_r.r_status & S_NOUPDT) && Noupdt)
					i = NOUPDT;
				else
					/* must not be indexed */
					if (Des.d_r.r_indexed > 0)
						i = DESTINDEX;
		}
	}
	if (i) {
		closer(&Des);
		return (error(i, Relname, 0));	/* relation doesn't exist for this user */
	}

	/* check that file name begins with a "/" */
	cp = Filename;
	while (*cp == ' ')
		cp++;
	if (*cp != '/') {
		closer(&Des);
		return (error(FULLPATH, Filename, 0));
	}

	/* fill map structures with transfer information */
	if ((i = mapfill(&pv[1])) != 0) {
		closer(&Des);
		return (i);	/* error in user semantics */
	}

	/* fork a child process which will run as the real user */
	/* that child will complete the copy and exit */
	if (pipe(Piped))
		syserr("copy:can't make pipe");
	if ((pid = fork()) < 0)
		syserr("copy:can't fork");
	if (pid) {
		/* the ingres parent */
		close(Piped[1]);
		ruboff(0);	/* interrupts off */
		stat = fullwait(pid, "copy");
		if (read(Piped[0], &Des.d_addc, 4) != 4)
			syserr("copy:can't read pipe");
		close(Piped[0]);
		closer(&Des);	/* close the rel */
		rubon();
		/* if stat is != 0 then add on 5800 for error */
		if (stat)
			stat += 5800;
		return (stat);	/* done */
	}

	/* the child. change to run as the real user */
	if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
		signal(SIGINT, copydone);	/* clean up on rubout */
	}
	setuid(getuid());
	setgid(getgid());
	if (Into) {
		/* from relation into file */
		if ((File_iop = fopen(Filename, "w")) == NULL) /* create file for user */
			i = nferror(NOFILECRT, Filename, 0);	/* cant create file */
		else {
			if (Lockrel)	/* set a shared lock on relation*/
				setrll(A_SLP, &Des.d_tid, M_SHARE);
			i = rel_file();
		}
	} else {
		/* from UNIX file into relation */
		if ((File_iop = fopen(Filename, "r")) == NULL)
			i = nferror(NOFILEOPN, Filename, 0);	/* cant open user file */
		else {
			if (Lockrel)	/* set an exclusive lock on relat*/
				setrll(A_SLP, &Des.d_tid, M_EXCL);
			i = file_rel();
			if (Duptuple)
				nferror(DUPTUPS, locv(Duptuple), 0);	/* warning only */
			if (Baddoms)
				nferror(BADDOMS, locv(Baddoms), 0);	/* warning only */
		}
	}
	copydone(i);
	return(0);
}
Exemple #4
0
update()
{
	register int		i, mode;
	struct descriptor	rel;
	long			oldtid, tupcnt;
	char			oldtup[MAXTUP], newtup[MAXTUP];
	char			*batchname();
	extern int		Dburetflag;
	extern struct retcode	Dburetcode;

#	ifdef xZTR1
	if (tTf(15, -1))
		printf("Update on %s\n", batchname());
#	endif
	/* set up to read batchhd */
	Batch_cnt = BATCHSIZE;	/* force a read on next getbatch */
	Batch_dirty = FALSE;
	if ((Batch_fp = open(batchname(), 2)) < 0)
		syserr("prim:can't open %s", batchname());
	getbatch(&Batchhd, sizeof Batchhd);

	tupcnt = Batchhd.num_updts;
#	ifdef xZTR1
	if (tTf(15, 0))
		printf("rel=%s tups=%s\n", Batchhd.rel_name, locv(tupcnt));
#	endif
	Dburetflag = TRUE;
	Dburetcode.rc_tupcount = 0;
	if (!tupcnt)
	{
		rmbatch();
		return (1);
	}

	/* update the primary relation */
	if (i = openr(&rel, 2, Batchhd.rel_name))
		syserr("prim:can't openr %s %d", Batchhd.rel_name, i);
	mode = Batchhd.mode_up;

	while (tupcnt--)
	{
		getbatch(&oldtid, Batchhd.tido_size);	/* read old tid */
		getbatch(oldtup, Batchhd.tupo_size);	/* and portions of old tuple */
		getbatch(newtup, Batchhd.tupn_size);	/* and the newtup */

		switch (mode)
		{

		  case mdDEL:
			if ((i = delete(&rel, &oldtid)) < 0)
				syserr("prim:bad del %d %s", i, Batchhd.rel_name);
			break;

		  case mdREPL:
			if (i = replace(&rel, &oldtid, newtup, TRUE))
			{
				/* if newtuple is a duplicate, then ok */
				if (i == 1)
					break;
				/* if this is recovery and oldtup not there, try to insert newtup */
				if (Batch_recovery && i == 2)
					goto upinsert;
				syserr("prim:Non-functional replace on %s (%d)", i, Batchhd.rel_name);
			}
			Dburetcode.rc_tupcount++;
			break;

		  case mdAPP:
		  upinsert:
			if ((i = insert(&rel, &oldtid, newtup, TRUE)) < 0)
				syserr("prim:bad insert %d %s", i, Batchhd.rel_name);
			break;

		  default:
			syserr("prim:impossible mode %d", mode);
		}
		putbatch(&oldtid, Batchhd.tidn_size);	/* write new tid if necessary */
	}
	/* fix the tupchanged count if delete or append */
	if (mode != mdREPL)
		Dburetcode.rc_tupcount = rel.reladds >= 0 ? rel.reladds : -rel.reladds;
	/* close the relation but secupdate will still use the decriptor */
	if (i = closer(&rel))
		syserr("prim:close err %d %s", i, Batchhd.rel_name);
	batchflush();

	/* if this relation is indexed, update the indexes */
	if (rel.relindxd > 0)
		secupdate(&rel);
	rmbatch();

#	ifdef xZTR1
	if (tTf(15, 2))
		printf("%s tups changed\n", locv(Dburetcode.rc_tupcount));
#	endif
	return (0);
}
Exemple #5
0
int main( int argc, char **argv )
{
    int     i;
    FILE    *skeleton, *temp, *tokout, *actout;
    int     ch;
    char    tempfname[10];
    char    *fileprefix = "y";
    size_t  size;

    param_requested = 0;
    for( i = 1; i < argc; ++i ) {
        ch = argv[i][0];
        switch( param_requested ) {
        case 'b':
            if( ch != '-' ) {
                if( ch != '\0' )
                    fileprefix = argv[i];
                ++i;
            }
            break;
        case 'p':
            if( ch != '-' ) {
                if( ch != '\0' )
                    symprefix = argv[i];
                ++i;
            }
            break;
        default:
            break;
        }
        param_requested = 0;
        if( argv[i][0] != '-' )
            break;
        setoptions( &argv[i][1] );
    }
    if( i != argc - 1 && i != argc - 2 ) {
        puts( "usage: yacc [-dlv] [-d[bcdfhpstuw]] [-b <file_prefix>] [-p <sym_prefix>]" );
        puts( "                  <grammar> [<driver>]" );
        puts( "options:" );
        puts( "    -b <file_prefix> file prefix used in place of default 'y' prefix" );
        puts( "    -d    output header file" );
        puts( "    -db   output bigger (less optimal) tables" );
        puts( "    -dc   output compact tables (slower to execute)" );
        puts( "    -dd   use dense tokens (no '+' style tokens allowed)" );
        puts( "    -de   dump all symbols to header file as enum items, no macros" );
        puts( "    -df   output fast tables (larger size)" );
        puts( "    -dh   use 'default shift' optimization" );
        puts( "    -dp   dump all productions" );
        puts( "    -ds   dump full state tables" );
        puts( "    -dt   translate 'keyword' to Y_KEYWORD, '++' to Y_PLUS_PLUS, etc." );
        puts( "    -du   eliminate useless unit production reduction" );
        puts( "    -dw   disable default action type checking" );
        puts( "    -l    output #line directives" );
        puts( "    -p <sym_prefix> symbol prefix used in place of default 'yy' prefix" );
        puts( "    -v    write description and report into file" );
        exit( 1 );
    }
    skeleton = NULL;
    if( i == argc - 2 ) {
        skeleton = openr( argv[argc - 1] );
        if( skeleton == NULL ) {
            msg( "could not open driver source code '%s'\n", argv[argc - 1] );
        }
    }
    loadpath = argv[0];
    *getname( loadpath ) = '\0';
    srcname = argv[i];
    if( !strrchr( srcname, '.' ) ) {
        srcname = alloca( strlen( argv[i] )+3 );
        srcname = strcat( strcpy( srcname, argv[i] ), ".y" );
    }
    yaccin = openr( srcname );

    size = strlen( fileprefix);
    codefilename   = MALLOC( size + 6, char );
    strcat( strcpy( codefilename, fileprefix), "tab.c" );
    headerfilename = MALLOC( size + 6, char );
    strcat( strcpy( headerfilename, fileprefix), "tab.h" );
    descfilename   = MALLOC( size + 5, char );
    strcat( strcpy( descfilename, fileprefix), ".out" );
    actout = openw( codefilename );
    defs( actout );
    tokout = openw( headerfilename );
    dump_header( tokout );
    temp = NULL;
    for( i = 0; i < 1000 && temp == NULL; ++i ) {
        sprintf( tempfname, "ytab.%3d", i );
        temp = fopen( tempfname, "w+" );
    }
    if( temp == NULL ) {
        msg( "Cannot create temporary file\n" );
    }
    rules( temp );
    buildpro();
    CalcMinSentence();
    if( proflag || showflag ) {
        showpro();
    }
    lr0();
    lalr1();
    SetupStateTable();
    /* apply state filters */
    FindUnused();
    if( eliminateunitflag ) {
        EliminateUnitReductions();
    }
    if( default_shiftflag ) {
        if( keyword_id_low == 0 ) {
            msg( "No %%keyword_id <low> <high> specified." );
        } else {
            MarkDefaultShifts();
        }
    }
    MarkNoUnitRuleOptimizationStates();
    RemoveDeadStates();
    MarkDefaultReductions();
    if( showflag ) {
        showstates();
    }
    if( warnings ) {
        if( warnings == 1 ) {
            printf( "%s: 1 warning\n", srcname );
        } else {
            printf( "%s: %d warnings\n", srcname, warnings );
        }
        exit( 1 );
    }
    parsestats();
    dumpstatistic( "parser states", nstate );
    dumpstatistic( "# states (1 reduce only)", nstate_1_reduce );
    dumpstatistic( "reduce/reduce conflicts", RR_conflicts );
    dumpstatistic( "shift/reduce conflicts", SR_conflicts );
    show_unused();
    if( skeleton == NULL ) {
        skeleton = fpopen( loadpath, "yydriver.c" );
        if( skeleton == NULL ) {
            warn( "Can't find yacc skeleton yydriver.c\n" );
        }
    }
    /* copy first part of skeleton */
    if( skeleton != NULL )
        copy_part( skeleton, actout );
    rewind( tokout );
    /* copy tokens */
    copy_rest( tokout, actout );
    close_header( tokout );
    genobj( actout );
    /* copy middle part of skeleton */
    if( skeleton != NULL )
        copy_part( skeleton, actout );
    rewind( temp );
    copy_rest( temp, actout );
    fclose( temp );
    remove( tempfname );
    /* copy last part of skeleton */
    if( skeleton != NULL ) {
        copy_rest( skeleton, actout );
        fclose( skeleton );
    }
    tail( actout );
    fclose( actout );
    FREE( codefilename );
    FREE( headerfilename );
    FREE( descfilename );
    return( 0 );
}
int
indexx(int pc, paramv_t *pv)
{
	register int		i;
	int			j;
	register struct dom	*dom;
	register paramv_t	*p;
	char			*primary, *indx;
	int			ndoms, newpc;
	struct tup_id		tid, hitid;
	struct tup_id		xtid;
	paramv_t		newpv[MAX_2ND_KEYS * 2 + 4];
	char			primtup[MAX_TUP_SIZE], systup[MAX_TUP_SIZE];
	desc_t			desc, pridesc;
	extern desc_t		Reldes;
	extern desc_t		Attdes;
	extern desc_t		Inddes;
	relation_t		relkey, reltup;
	attr_t			attkey, atttup;
	index_t			indtup;
	struct dom		domain[MAX_2ND_KEYS];

	primary = pv[0].pv_val.pv_str;
	indx = pv[1].pv_val.pv_str;
#ifdef xZTR1
	if (tTf(33, -1))
		printf("index: (pri %s ind %s)\n", primary, indx);
#endif
	i = openr(&pridesc, OR_READ, primary);
	if (i == AMOPNVIEW_ERR)
		return (error(NOINDVIEW, primary, 0));
	if (i > 0)
		return (error(NOPRIMREL, primary, 0));
	if (i < 0)
		syserr("INDEX : openr (%.14s) %d", primary, i);

	if (!bequal(pridesc.d_r.r_owner, Usercode, USERCODE_SIZE)) {
		i = NOTOWNED;
	} else if (pridesc.d_r.r_status & S_CATALOG) {
		i = NOINDXSYSREL;
	} else if (pridesc.d_r.r_indexed == SECINDEX) {
		i = ALREADYINDX;
	}

	if (i) {
		closer(&pridesc);
		return (error(i, primary, 0));
	}
	/*
	**  GATHER INFO. ON DOMAINS
	*/
	opencatalog("attribute", OR_WRITE);
	ingres_setkey(&Attdes, &attkey, primary, ATTRELID);
	ingres_setkey(&Attdes, &attkey, pridesc.d_r.r_owner, ATTOWNER);
	pc -= 2;
	p = &pv[2];
	dom = domain;
	for (i = 0; i < pc; i++) {
		if (i >= MAX_2ND_KEYS) {
			closer(&pridesc);
			return (error(TOOMUCHDOMS, (p->pv_val).pv_str, primary, 0));	/* too many keys */
		}
		ingres_setkey(&Attdes, &attkey, (p->pv_val).pv_str, ATTNAME);
		j = getequal(&Attdes, &attkey, &atttup, &tid);
		if (j < 0)
			syserr("INDEX: geteq att %d", j);
		if (j) {
			closer(&pridesc);
			return (error(NODOM, (p->pv_val).pv_str, 0));	/* key not in relation */
		}
		if (pridesc.d_r.r_dim > 0 && atttup.a_id == pridesc.d_r.r_attrc) {
			/* attempting to use lid field as part of index */
			closer(&pridesc);
			return(error(NOINDXLID, primary, (p->pv_val).pv_str, 0));
		}
		dom->id = atttup.a_id;
		dom->off = atttup.a_off;
		dom->frml = atttup.a_len & I1MASK;
		dom->frm[0] = atttup.a_fmt;
		p++;
		dom++;
	}
	ndoms = i;
	noclose(&Attdes);

	/*
	** The "order" of the steps have been altered to improve
	** recovery possibilities
	*/
	/*
	**  STEP 1 & 2: CREATE INDEX RELATION.
	*/
	newpv[0].pv_val.pv_str = "0202";
	newpv[1].pv_val.pv_str = indx;
	newpc = 2;
	p = &pv[2];
	dom = domain;
	for (i = 0; i < pc; i++) {
		newpv[newpc++].pv_val.pv_str = (p->pv_val).pv_str;
		itoa(dom->frml, &dom->frm[1]);
		newpv[newpc++].pv_val.pv_str = dom->frm;
		dom++;
		p++;
	}
	newpv[newpc++].pv_val.pv_str = "tidp";
	newpv[newpc++].pv_val.pv_str = "i4";
	newpv[newpc].pv_type = PV_EOF;

	if (create(newpc, newpv)) {
		closer(&pridesc);
		return (-1);
	}

	/* This is done for concurrency reasons */
	if (noclose(&Reldes))
		syserr("index: noclose");

	/*
	**  STEP 5: FILL UP THE SECONDARY INDEX FILE ITSELF
	*/
	if (Lockrel) {
		/* set a shared relation lock */
		setrll(A_SLP, &pridesc.d_tid, M_SHARE);
	}
	if ((i = openr(&desc, OR_WRITE, indx)) != 0)
		syserr("INDEX: openr %.14s %d", indx, i);
	find(&pridesc, NOKEY, &tid, &hitid, (void *) NULL);
	while ((i = get(&pridesc, &tid, &hitid, primtup, TRUE)) == 0) {
		dom = domain;
		for (i = j = 0; j < ndoms; j++) {
#ifdef BIG_ENDIAN
			if (dom->frm[0] != 'c')
				i = ((i-1)|(dom->frml-1))+1;
#endif
			bmove(&primtup[dom->off], &systup[i], dom->frml);
			i += dom->frml;
			dom++;
		}
#ifdef BIG_ENDIAN
		i = ((i-1)|3)+1;
#endif
		/* move in pointer */
		bmove(&tid, &systup[i], sizeof(tid));
		if ((j = insert(&desc, &xtid, systup, TRUE)) < 0) {
			syserr("INDEX: insert %.14s %d", indx, j);
		}
	}
	if (i < 0) {
		syserr("INDEX: get %.14s %d", primary, i);
	}
	closer(&pridesc);
	closer(&desc);


	/*
	**  STEP 3: ENTRIES TO INDEX-REL
	*/
	/* mv in primary name  */
	pmove(primary, indtup.i_relname, MAX_NAME_SIZE, ' ');
	/* primary owner */
	bmove(pridesc.d_r.r_owner, indtup.i_owner, sizeof(pridesc.d_r.r_owner));
	/* index name */
	pmove(indx, indtup.i_index, MAX_NAME_SIZE, ' ');
	indtup.i_indrelspec = M_HEAP;
	for (i = 0; i < MAX_2ND_KEYS; i++) {
		indtup.i_dom[i] = (i < ndoms) ? domain[i].id : 0;
	}
	opencatalog("indices", OR_WRITE);
	if ((i = insert(&Inddes, &tid, (char *) &indtup, TRUE)) < 0)
		syserr("INDEX: insert ix %d", i);

	/*
	**  STEP 4: TURN BIT ON IN PRIMARY RELATION TO SHOW IT IS BEING INDEXED
	*/
	opencatalog("relation", OR_WRITE);
	ingres_setkey(&Reldes, &relkey, primary, RELID);
	ingres_setkey(&Reldes, &relkey, pridesc.d_r.r_owner, RELOWNER);
	if ((i = getequal(&Reldes, &relkey, &reltup, &tid)) != 0)
		syserr("INDEX: geteq rel %d", i);
	reltup.r_indexed = SECBASE;
	if ((i = replace(&Reldes, &tid, &reltup, TRUE)) < 0)
		syserr("INDEX: replace rel %d", i);

	if (Lockrel)
		unlrl(&pridesc.d_tid);	/* release relation lock */

	return (0);
}