void umain() { int a = 0; int id = 0; if ((id = fork()) == 0) { if ((id = fork()) == 0) { a += 3; for (;;) { writef("\t\tthis is child2 :a:%d\n", a); } } a += 2; for (;;) { writef("\tthis is child :a:%d\n", a); } } a++; for (;;) { writef("this is father: a:%d\n", a); } }
int write(int fdnum, const void *buf, u_int n) { int r; struct Dev *dev; struct Fd *fd; if ((r = fd_lookup(fdnum, &fd)) < 0 || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0) { return r; } if ((fd->fd_omode & O_ACCMODE) == O_RDONLY) { writef("[%08x] write %d -- bad mode\n", env->env_id, fdnum); return -E_INVAL; } if (debug) writef("write %d %p %d via dev %s\n", fdnum, buf, n, dev->dev_name); r = (*dev->dev_write)(fd, buf, n, fd->fd_offset); if (r > 0) { fd->fd_offset += r; } return r; }
void umain(int argc, char **argv) { int fd, r, n, n2; if ((fd = open("motd", O_RDONLY)) < 0) user_panic("open motd: %e", fd); seek(fd, 0); if ((n = readn(fd, buf, sizeof buf)) <= 0) user_panic("readn: %e", n); if ((r = fork()) < 0) user_panic("fork: %e", r); if (r == 0) { seek(fd, 0); writef("going to read in child (might page fault if your sharing is buggy)\n"); if ((n2 = readn(fd, buf2, sizeof buf2)) != n2) user_panic("read in parent got %d, read in child got %d", n, n2); if(memcmp(buf, buf2, n) != 0) user_panic("read in parent got different bytes from read in child"); writef("read in child succeeded\n"); seek(fd, 0); close(fd); exit(); } wait(r); //seek(fd, 0); if ((n2 = readn(fd, buf2, sizeof buf2)) != n) user_panic("read in parent got %d, then got %d", n, n2); writef("buf : %s\n",buf); writef("read in parent succeeded\n"); }
bool_t pack_write_dir(restable_t *rt) { size_t i; size_t offset; offset = ftell(rt->file); fseek(rt->file, 0, SEEK_SET); if (writef(rt->file, "c4l4l4", PACK_IDENT, offset, rt->number * PACK_ENTRY_SIZE) != OK) { fprintf(stderr, "pack_write_dir: Can't write header.\n"); return FALSE; } fseek(rt->file, offset, SEEK_SET); for(i = 0; i < rt->number; i++) { if (writef(rt->file, "s56l4l4", rt->entries[i].name, rt->entries[i].offset, rt->entries[i].size) != OK) { fprintf(stderr, "pack_write_dir: Can't write entry #%u.\n", i); return FALSE; } } return TRUE; }
void showcelltype(void) /* Prints the type of cell and what is in it */ { char colstr[3], *s; int color; formdisplay = !formdisplay; s = cellstring(curcol, currow, &color, NOFORMAT); colstring(curcol, colstr); if (curcell == NULL) writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1, MSGEMPTY); else switch(curcell->attrib) { case TEXT : writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1, MSGTEXT); break; case VALUE : writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1, MSGVALUE); break; case FORMULA : writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1, MSGFORMULA); break; } /* switch */ writef(1, 24, CELLCONTENTSCOLOR, 80, "%s", s); formdisplay = !formdisplay; } /* showcelltype */
bool_t grp_write_dir(restable_t *rt) { size_t i; size_t offset; offset = ftell(rt->file); fseek(rt->file, 0, SEEK_SET); if (writef(rt->file, "c12l4", GRP_IDENT, rt->number) != OK) { fprintf(stderr, "grp_read_dir: Can't write header.\n"); return FALSE; } for(i = 0; i < rt->number; i++) { if (writef(rt->file, "s12l4", rt->entries[i].name, rt->entries[i].size) != OK) { fprintf(stderr, "grp_write_dir: Can't write entry #%u.\n", i); return FALSE; } } fseek(rt->file, offset, SEEK_SET); return TRUE; }
bool_t gob_write_dir(restable_t *rt) { size_t i; size_t offset; offset = ftell(rt->file); fseek(rt->file, 0, SEEK_SET); if (writef(rt->file, "c4l4", GOB_IDENT, offset) != OK) { fprintf(stderr, "gob_write_dir: Can't write header.\n"); return FALSE; } fseek(rt->file, offset, SEEK_SET); if (writef(rt->file, "l4", rt->number) != OK) { fprintf(stderr, "gob_write_dir: Can't write number of entries.\n"); return FALSE; } for(i = 0; i < rt->number; i++) { if (writef(rt->file, "l4l4s13", rt->entries[i].offset, rt->entries[i].size, rt->entries[i].name) != OK) { fprintf(stderr, "gob_write_dir: Can't write entry #%u.\n", i); return FALSE; } } return TRUE; }
void ConsoleSession::onCommand(const std::vector<std::string>& args) { if(args.empty()) { printPrompt(); return; } const std::string& commandName = args[0]; std::vector<std::string> commandArgs(args.begin() + 1, args.end()); const ConsoleCommands::Command* command = consoleCommands->getCommand(commandName); if(!command) { writef("Unknown command : %s\r\n", commandName.c_str()); } else { ConsoleCommands::Command::CallStatus status = command->call(this, commandArgs); switch(status) { case ConsoleCommands::Command::CS_Success: break; case ConsoleCommands::Command::CS_NotEnoughArgs: write("Not enough arguments\r\n"); break; case ConsoleCommands::Command::CS_TooMuchArgs: write("Too many arguments\r\n"); break; }; if(status != ConsoleCommands::Command::CS_Success) { writef("Usage:\r\n%s\r\n", command->usageExample.c_str()); } } printPrompt(); }
ssize_t write(int fd, const void *buf, size_t sz) { struct openposixfile* of = ofposix_find(posix_files, fd_of, &fd); if(of == NULL) { return writef(fd, buf, sz); } TRACE(posix, "writing %zu bytes to %d", sz, fd); stream(transferlibs, of->name, buf, sz); /* It will cause us a lot of problems if a write ends up being short, and the * application then resubmits the next part of the partial write. So, * iterate and make sure we avoid any partial writes. */ { ssize_t written = 0; do { errno=0; ssize_t bytes = writef(fd, ((const char*)buf)+written, sz-written); if(bytes == -1 && errno == EINTR) { continue; } if(bytes == -1 && written == 0) { return -1; } if(bytes == -1) { return written; } written += bytes; } while((size_t)written < sz); return written; } }
int do_wri(u8 * file){ s8 ret,fd; u32 retlba ; u8 i=0; u32 ch; u8 buff[256] = {0}; if (!check_for_args(WRI,1))return 1; fd = openf(file,O_RW); if ( fd == -1){ retlba=NO_LBA; if (ERROR_NO == NO_DIR_FILE) retlba = creatf(file , 064); if (retlba == NO_LBA){ vd_puts ( "COULD NOT OPEN OR CREATE THE DESTINATION FILE\n" ); errormessage(geterror()); closef(fd); fl_clean(); return 0; } fd = openf(file,O_RW); } if(fd == -1){ vd_puts("CANNOT OPEN THE FILE\n"); errormessage(geterror()); fl_clean(); return 1; } while(1){ ch=getche(); if(ch == 1) break; if( ch == 13 || ch == 10){printf("\n"); ch = '\n';} if (i == 255){ i=0; ret = writef(fd,buff,256); if(ret == -1){ vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n"); errormessage(geterror()); unlinkf(file); fl_clean(); return 1; } } buff[i++] = ch; } ret = writef(fd,buff,i); if(ret == -1){ vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n"); errormessage(geterror()); unlinkf(file); fl_clean(); return 1; } closef(fd); vd_puts(" \n"); fl_clean(); return 0; }
void serve_open(u_int envid, struct Fsreq_open *rq) { writef("serve_open %08x %x 0x%x\n", envid, (int)rq->req_path, rq->req_omode); u_char path[MAXPATHLEN]; struct File *f; struct Filefd *ff; int fileid; int r; struct Open *o; // Copy in the path, making sure it's null-terminated user_bcopy(rq->req_path, path, MAXPATHLEN); path[MAXPATHLEN - 1] = 0; //writef("serve_open:enter open %s\n",rq->req_path); // Find a file id. if ((r = open_alloc(&o)) < 0) { writef("open_alloc failed: %d", r); goto out; } fileid = r; //writef("serve_open:ending find a file id o = %x\n",o); // Open the file. if ((r = file_open((char *)path, &f)) < 0) { writef("file_open failed: %e", r); goto out; } //writef("serve_open:ending open the file\n"); // Save the file pointer. o->o_file = f; // Fill out the Filefd structure ff = (struct Filefd *)o->o_ff; ff->f_file = *f; ff->f_fileid = o->o_fileid; o->o_mode = rq->req_omode; ff->f_fd.fd_omode = o->o_mode; ff->f_fd.fd_dev_id = devfile.dev_id; //writef("serve_open:will to ipc send\n"); if (debug) { writef("sending success, page %08x\n", (u_int)o->o_ff); } ipc_send(envid, 0, (u_int)o->o_ff, PTE_V | PTE_R | PTE_LIBRARY); //writef("serve_open:end of open %s\n",rq->req_path); return; out: user_panic("*********************path:%s", path); ipc_send(envid, r, 0, 0); }
void errormsg(char *s) /* Prints an error message at the bottom of the screen */ { printf("%c", 7); /* Beeps the speaker */ writef(1, 25, ERRORCOLOR, 79, "%s %s", s, MSGKEYPRESS); gotoxy(strlen(s) + strlen(MSGKEYPRESS) + 3, 25); getkey(); gotoxy(1, 25); writef(1, 25, WHITE, 79, ""); } /* errormsg */
void serve(void) { u_int req, whom, perm; for (;;) { perm = 0; req = ipc_recv(&whom, REQVA, &perm); // All requests must contain an argument page if (!(perm & PTE_V)) { writef("Invalid request from %08x: no argument page\n", whom); continue; // just leave it hanging... } switch (req) { case FSREQ_OPEN: serve_open(whom, (struct Fsreq_open *)REQVA); break; case FSREQ_MAP: serve_map(whom, (struct Fsreq_map *)REQVA); break; case FSREQ_SET_SIZE: serve_set_size(whom, (struct Fsreq_set_size *)REQVA); break; case FSREQ_CLOSE: serve_close(whom, (struct Fsreq_close *)REQVA); break; case FSREQ_DIRTY: serve_dirty(whom, (struct Fsreq_dirty *)REQVA); break; case FSREQ_REMOVE: serve_remove(whom, (struct Fsreq_remove *)REQVA); break; case FSREQ_SYNC: serve_sync(whom); break; default: writef("Invalid request code %d from %08x\n", whom, req); break; } syscall_mem_unmap(0, REQVA); } }
void redrawscreen(void) /* Displays the entire screen */ { setrightcol(); setbottomrow(); writef(1, 1, MSGMEMORYCOLOR, strlen(MSGMEMORY), MSGMEMORY); writef(29, 1, PROMPTCOLOR, strlen(MSGCOMMAND), MSGCOMMAND); changeautocalc(autocalc); changeformdisplay(formdisplay); printfreemem(); displayscreen(NOUPDATE); } /* redrawscreen */
/* ................................ OUTPUT ............................. */ void output (FILE *Fptr[], double T) { int i1; /* Evaluate output quantities */ k = 0.125*(m*pow(z[4],2)+4*i*pow(z[3],2))*pow(omega,2); p = -0.5*g*l*m*z[1]; longoutput = 2 + 2*theta + p + z[1] + omega + 0.125*(m*pow(z[4],2)+4*i*pow( z[3],2))*pow(omega,2); z[13] = z[8]*z[1]*z[4]/z[11]; z[14] = (m*pow(z[4],2)+4*i*pow(z[3],2))*omega; z[16] = z[15]*z[2]; z[17] = 1 + 0.25*(m*pow(z[4],2)+4*i*pow(z[3],2))*omega; /* Write output to screen and to output file(s) */ writef(stdout, " %- 14.6E", omega,theta,k,p,longoutput,_NAN); writef(Fptr[1]," %- 14.6E", omega,theta,k,p,longoutput,_NAN); A[0][0] = 0; A[0][1] = -0.5*z[13]; A[1][0] = 1; A[1][1] = 0; B[0][0] = z[3]/z[11]; B[0][1] = -0.5*z[4]/z[11]; B[1][0] = 0; B[1][1] = 0; C[0][0] = 1; C[0][1] = 0; C[1][0] = 0; C[1][1] = 1; C[2][0] = 0.25*z[14]; C[2][1] = 0; C[3][0] = 0; C[3][1] = 0.5*z[16]; C[4][0] = z[17]; C[4][1] = 2 + 0.5*z[16] - sin(theta); D[0][0] = 0; D[0][1] = 0; D[1][0] = 0; D[1][1] = 0; D[2][0] = 0; D[2][1] = 0; D[3][0] = 0; D[3][1] = 0; D[4][0] = 0; D[4][1] = 0; Encode[0] = 0.0; Encode[1] = 0.0; Encode[2] = 0.0; Encode[3] = 0.0; }
int do_app(u8 * file){ s8 ret,fd; u8 i=0; u32 ch; u8 buff[256]; struct fnode fn; u32 size; if (!check_for_args(APP,1)) return 1; fd = openf(file,O_RW); if(fd == -1){ vd_puts( "CANNOT OPEN THE FILE\n"); errormessage(geterror()); fl_clean(); return 1; } finfo(fd, & fn); size = fn.size; ret= seekf(fd, size,SEEK_BEG); while(1){ ch=getche(); if(ch == 1) break; if (ch == 13 || ch == 10 ){ printf("\n");ch='\n'; } if (i == 255){ i=0; ret = writef(fd,buff,256); if(ret == -1){ vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n"); errormessage(geterror()); unlinkf(file); fl_clean(); return 1; } } buff[i++] = (u8)ch; } ret = writef(fd,buff,i); if(ret == -1){ vd_puts("SORRY SORRY CANNOT WRITE TO FILE SO REMOVING IT\n"); errormessage(geterror()); unlinkf(file); fl_clean(); return 1; } puts(" "); closef(fd); fl_clean(); return 0; }
void umain(void) { char buf[100]; int i, pid, p[2]; if ((i=pipe(p)) < 0) user_panic("pipe: %e", i); if ((pid=fork()) < 0) user_panic("fork: %e", i); if (pid == 0) { writef("[%08x] pipereadeof close %d\n", env->env_id, p[1]); close(p[1]); writef("[%08x] pipereadeof readn %d\n", env->env_id, p[0]); i = readn(p[0], buf, sizeof buf-1); if (i < 0) user_panic("read: %e", i); buf[i] = 0; if (strcmp(buf, msg) == 0) writef("\npipe read closed properly\n"); else writef("\ngot %d bytes: %s\n", i, buf); exit(); } else { writef("[%08x] pipereadeof close %d\n", env->env_id, p[0]); close(p[0]); writef("[%08x] pipereadeof write %d\n", env->env_id, p[1]); if ((i=write(p[1], msg, strlen(msg))) != strlen(msg)) user_panic("write: %e", i); close(p[1]); } wait(pid); if ((i=pipe(p)) < 0) user_panic("pipe: %e", i); if ((pid=fork()) < 0) user_panic("fork: %e", i); if (pid == 0) { close(p[0]); for(;;){ writef("."); if(write(p[1], "x", 1) != 1) break; } writef("\npipe write closed properly\n"); } close(p[0]); close(p[1]); wait(pid); writef("pipe tests passed\n"); }
void _user_panic(const char *file, int line, const char *fmt,...) { va_list ap; va_start(ap, fmt); writef("panic at %s:%d: ", file, line); user_lp_Print(user_myoutput, 0, (char *)fmt, ap); writef("\n"); va_end(ap); for(;;); }
void umain(void) { user_assert(sizeof(struct File) == 256); writef("FS is running\n"); // Check that we are able to do I/O //outw(0x8A00, 0x8A00); writef("FS can do I/O\n"); serve_init(); fs_init(); fs_test(); serve(); }
void serve_dirty(u_int envid, struct Fsreq_dirty *rq) { if (debug) { writef("serve_dirty %08x %08x %08x\n", envid, rq->req_fileid, rq->req_offset); } // Your code here struct Open *pOpen; int r; if ((r = open_lookup(envid, rq->req_fileid, &pOpen)) < 0) { ipc_send(envid, r, 0, 0); return; } if ((r = file_dirty(pOpen->o_file, rq->req_offset)) < 0) { ipc_send(envid, r, 0, 0); return; } ipc_send(envid, 0, 0, 0); return; // user_panic("serve_dirty not implemented"); }
void serve_set_size(u_int envid, struct Fsreq_set_size *rq) { if (debug) { writef("serve_set_size %08x %08x %08x\n", envid, rq->req_fileid, rq->req_size); } struct Open *pOpen; int r; // Your code here if ((r = open_lookup(envid, rq->req_fileid, &pOpen)) < 0) { ipc_send(envid, r, 0, 0); return; } if ((r = file_set_size(pOpen->o_file, rq->req_size)) < 0) { ipc_send(envid, r, 0, 0); return; } ipc_send(envid, 0, 0, 0);//PTE_V); return; // user_panic("serve_set_size not implemented"); }
void serve_map(u_int envid, struct Fsreq_map *rq) { if (debug) { writef("serve_map %08x %08x %08x\n", envid, rq->req_fileid, rq->req_offset); } struct Open *pOpen; u_int filebno; void *blk; int r; // Your code here if ((r = open_lookup(envid, rq->req_fileid, &pOpen)) < 0) { ipc_send(envid, r, 0, 0); return; } filebno = rq->req_offset / BY2BLK; if ((r = file_get_block(pOpen->o_file, filebno, &blk)) < 0) { ipc_send(envid, r, 0, 0); return; } ipc_send(envid, 0, (u_int)blk, PTE_V | PTE_R | PTE_LIBRARY); return; // user_panic("serve_map not implemented"); }
LINEDESC *sp_inject (char lin[], int len, LINEDESC *line) { LINEDESC *ret; LINEDESC *ptr; ret = alloc (&ptr); if (ptr == SE_NOMORE) { Errcode = ECANTINJECT; return (ret); } ptr->Seekaddr = Scrend; ptr->Lineleng = len + 1; ptr->Globmark = SE_NO; ptr->Markname = DEFAULTNAME; seekf ((long) Scrend * 8, Scr); writef (lin, len + 1, Scr); Scrend += ((len + 1) + 7) / 8; /* fudge for larger buffer */ Lastln++; Buffer_changed = SE_YES; /* * this part dependant on the fact that we set * Curln = line in the routine do_read. */ blkmove (ptr - Buf, ptr - Buf, Curln); /* need line no's */ Curln++; return (ret); }
void Node::write2Blk(Block &blk, int typeId, int strLen, BufferManager* bufferManager) { char* mem = blk.data; mem[0] = isleaf; mem[1] = isroot; mem += 2*sizeof(char); writei(getPSize(), mem), writei(getKSize(), mem), writei(typeId, mem), writei(strLen, mem); std::cout << "getPSize()" << getPSize() <<std::endl; std::cout << "getKSize()" << getKSize() <<std::endl; for( int i = 0; i < getPSize(); i++ ) { std::cout << "P[i]" << P[i] << std::endl; writei(P[i], mem); } for( int i = 0; i < getKSize(); i++ ) { std::cout << "K[i]" << K[i].datai << std::endl; if( typeId == 0 ) { writei(K[i].datai, mem); } else if( typeId == 1 ) { writef(K[i].dataf, mem); } else if( typeId == 2 ) { writes(K[i].datas, strLen, mem); } } std::cout << "Node::write2Blk " << blk.pos/BLOCK_SIZE << std::endl; //BufferManager bufferManager; bufferManager->writeBlock(blk); }
/* * Shows random names simialiar to the do_randomnames command but formatted for * the login screen. */ void show_random_names(DESCRIPTOR_DATA *d) { int row = 0; int col = 0; show_menu_top(d); show_menu_header("Random Names", d); write_to_descriptor(d->descriptor, BLANK_MENU_LINE, d); for (row = 0; row < 8; row++) { write_to_descriptor(d->descriptor, "{w | {g", d); // Since the random function returns a static char we have to use it in // separate calls. for (col = 0; col < 4; col++) { writef(d, "%-16s", generate_random_name()); } write_to_descriptor(d->descriptor, "{w |\r\n", d); } show_menu_bottom(d); return; }
int read(int fdnum, void *buf, u_int n) { int r; struct Dev *dev; struct Fd *fd; if ((r = fd_lookup(fdnum, &fd)) < 0 || (r = dev_lookup(fd->fd_dev_id, &dev)) < 0) { return r; } if ((fd->fd_omode & O_ACCMODE) == O_WRONLY) { writef("[%08x] read %d -- bad mode\n", env->env_id, fdnum); return -E_INVAL; } r = (*dev->dev_read)(fd, buf, n, fd->fd_offset); if (r >= 0) { fd->fd_offset += r; } return r; }
EventChain<SocketSession> ConsoleSession::onConnected() { writef("%s - Administration console - Type \"help\" for a list of available commands\r\n", GlobalCoreConfig::get()->app.appName.get().c_str()); printPrompt(); return TelnetSession::onConnected(); }
void new_highscore_loop() { uint64_t ascii = readKeyCode(); screen_t scr_score; screen_init(&scr_score, 20, 10, 45, 2); // screen_clear(&scr_score, 0x00); if(ascii) { switch(ascii) { case KEY_CODE_AU: ++*new_highscore.name_p; break; case KEY_CODE_AD: --*new_highscore.name_p; break; case KEY_CODE_ENT: ++new_highscore.name_p; // Name entered if(!*new_highscore.name_p) { highscore_init(); return; } break; } } writef(&scr_score, "Your score: %c%u%c%n" "Your name: %c%s", 0x2F, new_highscore.score->score, 0x07, 0xC7, new_highscore.score->name ); }
void CProtocolUtil::vwritef(synergy::IStream* stream, const char* fmt, UInt32 size, va_list args) { assert(stream != NULL); assert(fmt != NULL); // done if nothing to write if (size == 0) { return; } // fill buffer UInt8* buffer = new UInt8[size]; writef(buffer, fmt, args); try { // write buffer stream->write(buffer, size); LOG((CLOG_DEBUG2 "wrote %d bytes", size)); delete[] buffer; } catch (XBase&) { delete[] buffer; throw; } }
bool w_cmd(File *f, Cmd *cp) { if(getname(f, cp->ctext, false)==0) error(Enoname); writef(f); return true; }