int __weak usleep(useconds_t useconds) { clock_t t0 = _clock(); clock_t dt = useconds / (1000000/CLOCKS_PER_SEC); while (_clock() - t0 < dt); return 0; }
unsigned __weak sleep(unsigned seconds) { clock_t t0 = _clock(); clock_t dt = seconds * CLOCKS_PER_SEC; while (_clock() - t0 < dt); return 0; }
/* use long instead of int so vfork works OK with -mshort */ long tfork(int (*func)(long), long arg) { register BASEPAGE *b; register long pid; register long savpending, savmask; register BASEPAGE *savbase; sighandler_t savhandler[NSIG]; long now; int i; b = (BASEPAGE *)Pexec(PE_CBASEPAGE, 0L, "", 0L); (void)Mshrink(b, SIZE+256); b->p_tbase = (char *)startup; b->p_dbase = (char *)func; b->p_dlen = arg; b->p_hitpa = ((char *)b) + SIZE + 256; pid = Pexec(104, 0L, b, 0L); if (pid == -ENOSYS) { /* save the signal masks and signal handlers, * the child may change them */ savpending = _sigpending; _sigpending = 0; savmask = _sigmask; _sigmask = 0; for (i = 0; i < NSIG; i++) savhandler[i] = _sig_handler[i]; savbase = _base; _base = b; now = _clock(); pid = Pexec(4, 0L, b, 0L); _base = savbase; /* restore signal stuff */ for (i = 0; i < NSIG; i++) _sig_handler[i] = savhandler[i]; _sigmask = savmask; _sigpending = savpending; if (pid >= 0) { long retval = pid; /* see the TOS algorithm for getpid() */ pid = ((long)b) >> 8; __waitval = (pid << 16) | retval; raise(SIGCHLD); __waittime = _clock() - now; _childtime += __waittime; }
/* * Sleep for usec microSeconds * the actual suspension time can be arbitrarily longer * */ int usleep (__useconds_t __useconds) { long stop; int r = -ENOSYS; if (__useconds >= 1000) r = Fselect((unsigned)(__useconds/1000), 0L, 0L, 0L); if (r == -ENOSYS) { stop = _clock() + USEC_TO_CLOCK_TICKS(__useconds); while (_clock() < stop) ; r = 0; } if (r < 0) { __set_errno (-r); return -1; } return 0; }
static int getFreeInode(char * name, int prev, int flag, int parent) { int i = 0; for ( i = 0 ; i < 2043 ; i++ ) { if ( freeInodes[i] ) { break; } } if ( i == 2043 ) { return -1; } INODE * inode = kmalloc(sizeof(INODE)); strcpy(inode->attributes.name, name); int seconds = _clock(0); inode->attributes.creation_time.seconds = ((seconds&0xF0) >> 4) * 10 + (seconds&0x0F); int minutes = _clock(2); inode->attributes.creation_time.minutes = ((minutes&0xF0) >> 4) * 10 + (minutes&0x0F); int hours = _clock(4); inode->attributes.creation_time.hours = ((hours&0xF0) >> 4) * 10 + (hours&0x0F); int day = _clock(7); inode->attributes.creation_time.day = ((day&0xF0) >> 4) * 10 + (day&0x0F); int month = _clock(8); inode->attributes.creation_time.month = ((month&0xF0) >> 4) * 10 + (month&0x0F); int year = _clock(9); inode->attributes.creation_time.year = ((year&0xF0) >> 4) * 10 + (year&0x0F); inode->attributes.prev_version = prev; inode->attributes.size = 0; inode->attributes.alive = 1; inode->attributes.free = 0; inode->attributes.parentDir = parent; int j = 0; if ( flag ) { inode->blocks[0] = getFreeBlock(); j++; } inode->blocks[j] = -1; setInode(inode, i); free(inode); freeInodes[i] = 0; return i; }
void init_fs() { char block[512] = {0}; useSector(0, block, READ,1); if ( *((int*)block) == 0x12345678 ) { //printSomewhere(300, "POR ACA"); root = kmalloc(sizeof(ENTRY)); strcpy(root->name, "/"); root->inodeNumber = 0; root->link = 0; int i; for ( i = 5 ; i < 2048 ; i++ ) { INODE * inodeAux = getInode(i-5); freeInodes[i-5] = inodeAux->attributes.free; free(inodeAux); } return; } *((int*)block) = 0x12345678; ENTRY rootEntry; strcpy(rootEntry.name , "/"); rootEntry.inodeNumber = 0; rootEntry.link = 0; memcpy( block + sizeof(int), (char*)&rootEntry, sizeof(ENTRY)); useSector(0, block, WRITE, 1); /*sete mapa d bits*/ int i; char mapBlock[4*512]; for ( i = 1 ; i < 4*512 ; i++ ) { mapBlock[i] = 0xFF; } mapBlock[0] = 0x7F; setBitMap(mapBlock); INODE inode; inode.attributes.free = 1; inode.blocks[0] = -1; for ( i = 5 ; i < 2048 ; i++ ) { if ( i == 5 ) { INODE rootInode; rootInode.blocks[0] = 0; rootInode.blocks[1] = -1; rootInode.attributes.prev_version = -1; rootInode.attributes.parentDir = 0; int seconds = _clock(0); rootInode.attributes.creation_time.seconds = ((seconds&0xF0) >> 4) * 10 + (seconds&0x0F); int minutes = _clock(2); rootInode.attributes.creation_time.minutes = ((minutes&0xF0) >> 4) * 10 + (minutes&0x0F); int hours = _clock(4); rootInode.attributes.creation_time.hours = ((hours&0xF0) >> 4) * 10 + (hours&0x0F); int day = _clock(7); rootInode.attributes.creation_time.day = ((day&0xF0) >> 4) * 10 + (day&0x0F); int month = _clock(8); rootInode.attributes.creation_time.month = ((month&0xF0) >> 4) * 10 + (month&0x0F); int year = _clock(9); rootInode.attributes.creation_time.year = ((year&0xF0) >> 4) * 10 + (year&0x0F); strcpy(rootInode.attributes.name , "/"); rootInode.attributes.size = 3 * sizeof(ENTRY); rootInode.attributes.free = 0; rootInode.attributes.alive = 1; char buffer[512] = {0}; memcpy(buffer, (char*)&rootInode, 512); useSector(5, buffer, WRITE, 1); } else {
clock (void) { return _clock (); }