int kpipe(int pd[2]) { OFT *read, *write; PIPE *pipe; u16 i = 0, j=0; pipe = getPipe(); if( pipe == 0) { return 0; } if ( getOFT(&read, &write) < 0 ) { printf("No open file descripters\n"); return -1; } for(i=0;i < NFD;++i) { if (running->fd[i] == 0) { printf("Putting [%d] into address %x\n", i, pd); put_word(i, running->uss, pd); pd++; if( j == 0 ) { running->fd[i] = read; }else { running->fd[i] = write; } ++j; } if (j == 2) { break; } } read->pipe_ptr = write->pipe_ptr = pipe; read->mode = READ_PIPE; read->refCount = 1; printf("READ mode[%d] count[%d]\n", read->mode, read->refCount); write->mode = WRITE_PIPE; write->refCount = 1; printf("Write mode[%d] count[%d]\n", write->mode, write->refCount); for(i=0;i< PSIZE ; ++i) { pipe->buf[i] = 0; } pipe->head = pipe->tail = pipe->data = 0; pipe->nreader = pipe->nwriter = pipe->busy = 1; pipe->room = PSIZE; }
int kpipe(int pd) { // create a pipe; fill pd[0] pd[1] (in USER mode!!!) with descriptors OFTE * read, * write; PIPE *newpipe; u16 i = 0; newpipe = getPipe(); if(newpipe == 0){ return 0; } if(!getOFT(&read, &write)){ printf("getOFT success"); } printf("ref: %d\n", read->refCount); printf("About to pipe running PROC %d\n", running->pid); // Get the next open FD spot and fill it with the reader OFTE while(running->fd[i] != 0){ i++; } running->fd[i] = read; printf("Putting word (%d) into address %x\n", i, pd); put_word(i, running->uss, pd); // Continue to the next open spot and fill it with the writer OFTE pd+=2; while(running->fd[i] != 0){ i++; } running->fd[i] = write; printf("Putting word (%d) into address %x\n", i, pd); put_word(i, running->uss, pd); // Set both the reader and writer to the pipe read->pipe_ptr = write->pipe_ptr = pipe; // Init the OFTE structs read->mode = READ_PIPE; write->mode = WRITE_PIPE; printf("mode: %d\n", read->mode); printf("OFT = %x\n", read); printf("OFT = %x\n", write); read->refCount = 1; write->refCount = 1; // Init our pipe for(i=0;i<PIPE_SIZE;i++){ pipe->buf[i] = 0; } pipe->head = 0; pipe->tail = 0; pipe->room = PIPE_SIZE; pipe->data = 0; pipe->nreader = 1; pipe->nwriter = 1; pipe->busy = 1; }