static ospfs_direntry_t * create_blank_direntry(ospfs_inode_t *dir_oi) { // Outline: // 1. Check the existing directory data for an empty entry. Return one // if you find it. // 2. If there's no empty entries, add a block to the directory. // Use ERR_PTR if this fails; otherwise, clear out all the directory // entries and return one of them. /* EXERCISE: Your code here. */ int f_pos = 0; int r; //Search for empty directory for(; f_pos < dir_oi->oi_size; f_pos+= OSPFS_DIRENTRY_SIZE){ ospfs_direntry_t *od = ospfs_inode_data(dir_oi, f_pos); if(od->od_ino == 0){ return od; } } //No empty directories found, so add a new block r = change_size(dir_oi, dir_oi->oi_size + OSPFS_BLKSIZE); //Check for error if(r < 0){ return ERR_PTR(r); } //Don't know if this is right, get the pos of the newly added block return ospfs_inode_data(dir_oi, f_pos); }
static int ospfs_unlink(struct inode *dirino, struct dentry *dentry) { ospfs_inode_t *oi = ospfs_inode(dentry->d_inode->i_ino); ospfs_inode_t *dir_oi = ospfs_inode(dentry->d_parent->d_inode->i_ino); int entry_off; ospfs_direntry_t *od; od = NULL; // silence compiler warning; entry_off indicates when !od for (entry_off = 0; entry_off < dir_oi->oi_size; entry_off += OSPFS_DIRENTRY_SIZE) { od = ospfs_inode_data(dir_oi, entry_off); if (od->od_ino > 0 && strlen(od->od_name) == dentry->d_name.len && memcmp(od->od_name, dentry->d_name.name, dentry->d_name.len) == 0) break; } if (entry_off == dir_oi->oi_size) { printk("<1>ospfs_unlink should not fail!\n"); return -ENOENT; } od->od_ino = 0; oi->oi_nlink--; //after unlinking, decrement number of links dir_oi->oi_nlink--; //if a file doesn't have any more links, we can delete it by giving it 0 size if (oi->oi_ftype != OSPFS_FTYPE_SYMLINK && oi->oi_nlink == 0) change_size(oi,0); return 0; }
static int ospfs_notify_change(struct dentry *dentry, struct iattr *attr) { struct inode *inode = dentry->d_inode; ospfs_inode_t *oi = ospfs_inode(inode->i_ino); int retval = 0; if (attr->ia_valid & ATTR_SIZE) { // We should not be able to change directory size if (oi->oi_ftype == OSPFS_FTYPE_DIR) return -EPERM; if ((retval = change_size(oi, attr->ia_size)) < 0) goto out; } if (attr->ia_valid & ATTR_MODE) // Set this inode's mode to the value 'attr->ia_mode'. oi->oi_mode = attr->ia_mode; if ((retval = inode_change_ok(inode, attr)) < 0 || (retval = inode_setattr(inode, attr)) < 0) goto out; out: return retval; }
static ospfs_direntry_t * create_blank_direntry(ospfs_inode_t *dir_oi) { // Outline: // 1. Check the existing directory data for an empty entry. Return one // if you find it. // 2. If there's no empty entries, add a block to the directory. // Use ERR_PTR if this fails; otherwise, clear out all the directory // entries and return one of them. /* EXERCISE: Your code here. */ //return ERR_PTR(-EINVAL); // Replace this line //Part 1: //Iterate through directory data and find empty entry uint32_t i = 0; ospfs_direntry_t *tmp; uint32_t num_entries = dir_oi->oi_size; for (i = 0; i < num_entries; i+= OSPFS_DIRENTRY_SIZE) { tmp = ospfs_inode_data(dir_oi, i); if (tmp->od_ino == 0) return tmp; } int blankdir = change_size(dir_oi, dir_oi->oi_size+OSPFS_DIRENTRY_SIZE); if (blankdir == 0) { tmp = ospfs_inode_data(dir_oi, num_entries); return tmp; } return ERR_PTR(blankdir); }
static ospfs_direntry_t * create_blank_direntry(ospfs_inode_t *dir_oi) { uint32_t blockno; uint32_t off = 1; int ret; uint32_t entry_off; // Outline: // 1. Check the existing directory data for an empty entry. Return one // if you find it. // 2. If there's no empty entries, add a block to the directory. // Use ERR_PTR if this fails; otherwise, clear out all the directory // entries and return one of them. /* EXERCISE: Your code here. */ // Search through the directory block for (entry_off = 0; entry_off < dir_oi->oi_size; entry_off += OSPFS_DIRENTRY_SIZE) { // Find the OSPFS inode for the entry ospfs_direntry_t *od = ospfs_inode_data(dir_oi, entry_off); // Set 'entry_inode' if we find the file we are looking for if (od->od_ino == 0) { return od; } } if ((ret = change_size(dir_oi, dir_oi->oi_size + OSPFS_DIRENTRY_SIZE))) { return NULL; } return create_blank_direntry(dir_oi); }
static int ospfs_unlink(struct inode *dirino, struct dentry *dentry) { ospfs_inode_t *oi = ospfs_inode(dentry->d_inode->i_ino); ospfs_inode_t *dir_oi = ospfs_inode(dentry->d_parent->d_inode->i_ino); int entry_off; ospfs_direntry_t *od; od = NULL; // silence compiler warning; entry_off indicates when !od for (entry_off = 0; entry_off < dir_oi->oi_size; entry_off += OSPFS_DIRENTRY_SIZE) { od = ospfs_inode_data(dir_oi, entry_off); if (od->od_ino > 0 && strlen(od->od_name) == dentry->d_name.len && memcmp(od->od_name, dentry->d_name.name, dentry->d_name.len) == 0) break; } if (entry_off == dir_oi->oi_size) { printk("<1>ospfs_unlink should not fail!\n"); return -ENOENT; } od->od_ino = 0; oi->oi_nlink--; // if not a symlink, delete file data when all links are gone if (oi->oi_ftype != OSPFS_FTYPE_SYMLINK && oi->oi_nlink == 0) return change_size(oi, 0); return 0; }
int enlarge(QSP_ARG_DECL Data_Obj *big_dp,Data_Obj *lil_dp) /* reduce into lil_dp */ { if( change_size(QSP_ARG big_dp,lil_dp) < 0 ) return(-1); SET_OBJ_FLAG_BITS(big_dp, DT_ASSIGNED); return(0); }
static ssize_t ospfs_write(struct file *filp, const char __user *buffer, size_t count, loff_t *f_pos) { ospfs_inode_t *oi = ospfs_inode(filp->f_dentry->d_inode->i_ino); int retval = 0; size_t amount = 0; // Support files opened with the O_APPEND flag. To detect O_APPEND, // use struct file's f_flags field and the O_APPEND bit. /* EXERCISE: Your code here */ int append = filp->f_flags & O_APPEND; if (append) *f_pos = oi->oi_size; // If the user is writing past the end of the file, change the file's // size to accomodate the request. (Use change_size().) /* EXERCISE: Your code here */ if (count > oi->oi_size - *f_pos) { change_size(oi, count + oi->oi_size); } // Copy data block by block while (amount < count && retval >= 0) { uint32_t blockno = ospfs_inode_blockno(oi, *f_pos); uint32_t n; char *data; if (blockno == 0) { retval = -EIO; goto done; } data = ospfs_block(blockno); // Figure out how much data is left in this block to write. // Copy data from user space. Return -EFAULT if unable to read // read user space. // Keep track of the number of bytes moved in 'n'. /* EXERCISE: Your code here */ n = count - amount; //left to write! if (n > OSPFS_BLKSIZE) n = OSPFS_BLKSIZE; if (copy_from_user(data + *f_pos, buffer, n) != 0) { return -EFAULT; } buffer += n; amount += n; *f_pos += n; } done: return (retval >= 0 ? amount : retval); }
int change_key(t_rules *rules, int key, int i) { if (key == 10 && i == 2) { change_size(rules); return (1); } else if (key == 10 && i == 1) { change_winscore(rules); return (1); } return (0); }
/** * Stops resizing a window, and fixes its position. */ void ClientModel::stop_resizing(Window client, Dimension2D size) { Desktop* old_desktop = m_desktops.get_category_of(client); if (!old_desktop->is_resizing_desktop()) return; if (m_was_stuck[client]) move_to_desktop(client, ALL_DESKTOPS, false); else move_to_desktop(client, m_current_desktop, false); change_size(client, DIM2D_WIDTH(size), DIM2D_HEIGHT(size)); focus(client); }
void win_textgrid_rearrange(window_t *win, XRectangle *box) { int wid, hgt; window_textgrid_t *cutwin = win->data; cutwin->bbox = *box; cutwin->cbox.x = box->x + prefs.textgrid.marginx; cutwin->cbox.width = box->width - 2 * prefs.textgrid.marginx; cutwin->cbox.y = box->y + prefs.textgrid.marginy; cutwin->cbox.height = box->height - 2 * prefs.textgrid.marginy; wid = (cutwin->cbox.width) / cutwin->font.gc[0].spacewidth; hgt = (cutwin->cbox.height) / cutwin->font.lineheight; if (wid < 0) wid = 0; if (hgt < 0) hgt = 0; change_size(cutwin, wid, hgt); }
static ssize_t ospfs_write(struct file *filp, const char __user *buffer, size_t count, loff_t *f_pos) { ospfs_inode_t *oi = ospfs_inode(filp->f_dentry->d_inode->i_ino); int retval = 0; size_t amount = 0; /* EXERCISE: Your code here */ //Detecting if appending to end of a file if(filp->f_flags & O_APPEND) *f_pos = oi->oi_size; /* EXERCISE: Your code here */ // If the user is writing past the end of the file, change the file's // size to accomodate the request. (Use change_size().) if(count > oi->oi_size - *f_pos) retval = change_size(oi, count + *f_pos); if(retval < 0){ //eprintk("Error changing file size.\n"); return retval; } // Copy data block by block while(amount < count && retval >= 0){ uint32_t blockno = ospfs_inode_blockno(oi, *f_pos); uint32_t n; char *data; if (blockno == 0){ retval = -EIO; goto done; } data = ospfs_block(blockno); // Figure out how much data is left in this block to write. // Copy data from user space. Return -EFAULT if unable to read // read user space. // Keep track of the number of bytes moved in 'n'. /* EXERCISE: Your code here */ uint32_t offset = *f_pos % OSPFS_BLKSIZE; n = count-amount; if(count-amount > OSPFS_BLKSIZE - offset){ n = OSPFS_BLKSIZE - offset; } if(copy_from_user(data + offset, buffer, n) != 0){ //eprintk("Unable to read from user space.\n"); retval = -EFAULT; goto done; } buffer += n; amount += n; *f_pos += n; } done: return (retval >= 0 ? amount : retval); }
int main(void) { ALLEGRO_TIMER *timer; ALLEGRO_EVENT_QUEUE *queue; ALLEGRO_MONITOR_INFO info; int w = 640, h = 480; bool done = false; bool need_redraw = true; bool background = false; example.show_help = true; if (!al_init()) { abort_example("Failed to init Allegro.\n"); return 1; } if (!al_init_image_addon()) { abort_example("Failed to init IIO addon.\n"); return 1; } al_init_font_addon(); al_get_num_video_adapters(); al_get_monitor_info(0, &info); #ifdef ALLEGRO_IPHONE al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); #endif al_set_new_display_option(ALLEGRO_SUPPORTED_ORIENTATIONS, ALLEGRO_DISPLAY_ORIENTATION_ALL, ALLEGRO_SUGGEST); example.display = al_create_display(w, h); w = al_get_display_width(example.display); h = al_get_display_height(example.display); if (!example.display) { abort_example("Error creating display.\n"); return 1; } if (!al_install_keyboard()) { abort_example("Error installing keyboard.\n"); return 1; } if (!al_install_mouse()) { abort_example("Error installing mouse.\n"); return 1; } example.font = al_load_font("data/fixed_font.tga", 0, 0); if (!example.font) { abort_example("Error loading data/fixed_font.tga\n"); return 1; } example.mysha = al_load_bitmap("data/mysha256x256.png"); if (!example.mysha) { abort_example("Error loading data/mysha256x256.png\n"); return 1; } example.white = al_map_rgb_f(1, 1, 1); example.half_white = al_map_rgba_f(1, 1, 1, 0.5); example.dark = al_map_rgb(15, 15, 15); example.red = al_map_rgb_f(1, 0.2, 0.1); change_size(256); add_sprite(); add_sprite(); timer = al_create_timer(1.0 / FPS); queue = al_create_event_queue(); al_register_event_source(queue, al_get_keyboard_event_source()); al_register_event_source(queue, al_get_mouse_event_source()); al_register_event_source(queue, al_get_timer_event_source(timer)); if (al_install_touch_input()) al_register_event_source(queue, al_get_touch_input_event_source()); al_register_event_source(queue, al_get_display_event_source(example.display)); al_start_timer(timer); while (!done) { float x, y; ALLEGRO_EVENT event; w = al_get_display_width(example.display); h = al_get_display_height(example.display); if (!background && need_redraw && al_is_event_queue_empty(queue)) { double t = -al_get_time(); add_time(); al_clear_to_color(al_map_rgb_f(0, 0, 0)); redraw(); t += al_get_time(); example.direct_speed_measure = t; al_flip_display(); need_redraw = false; } al_wait_for_event(queue, &event); switch (event.type) { case ALLEGRO_EVENT_KEY_CHAR: /* includes repeats */ if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) done = true; else if (event.keyboard.keycode == ALLEGRO_KEY_UP) { add_sprites(1); } else if (event.keyboard.keycode == ALLEGRO_KEY_DOWN) { remove_sprites(1); } else if (event.keyboard.keycode == ALLEGRO_KEY_LEFT) { change_size(example.bitmap_size - 1); } else if (event.keyboard.keycode == ALLEGRO_KEY_RIGHT) { change_size(example.bitmap_size + 1); } else if (event.keyboard.keycode == ALLEGRO_KEY_F1) { example.show_help ^= 1; } else if (event.keyboard.keycode == ALLEGRO_KEY_SPACE) { example.use_memory_bitmaps ^= 1; change_size(example.bitmap_size); } else if (event.keyboard.keycode == ALLEGRO_KEY_B) { example.blending++; if (example.blending == 4) example.blending = 0; } break; case ALLEGRO_EVENT_DISPLAY_CLOSE: done = true; break; case ALLEGRO_EVENT_DISPLAY_HALT_DRAWING: background = true; al_acknowledge_drawing_halt(event.display.source); break; case ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING: background = false; break; case ALLEGRO_EVENT_DISPLAY_RESIZE: al_acknowledge_resize(event.display.source); break; case ALLEGRO_EVENT_TIMER: update(); need_redraw = true; break; case ALLEGRO_EVENT_TOUCH_BEGIN: x = event.touch.x; y = event.touch.y; goto click; case ALLEGRO_EVENT_MOUSE_BUTTON_UP: x = event.mouse.x; y = event.mouse.y; goto click; click: { int fh = al_get_font_line_height(example.font); if (x < 80 && y >= h - fh * 10) { int button = (y - (h - fh * 10)) / (fh * 2); if (button == 0) { example.use_memory_bitmaps ^= 1; change_size(example.bitmap_size); } if (button == 1) { example.blending++; if (example.blending == 4) example.blending = 0; } if (button == 3) { if (x < 40) remove_sprites(example.sprite_count / 2); else add_sprites(example.sprite_count); } if (button == 2) { int s = example.bitmap_size * 2; if (x < 40) s = example.bitmap_size / 2; change_size(s); } if (button == 4) { example.show_help ^= 1; } } break; } } } al_destroy_bitmap(example.bitmap); return 0; }
void event_loop( Display* display, Window window ) { while (1) { while (XPending(display) > 0) { XEvent event; XNextEvent( display, &event ); switch (event.type) { case Expose: break; case ConfigureNotify: change_size(event.xconfigure.width, event.xconfigure.height); break; case KeyPress: { int code; code = XLookupKeysym( &event.xkey, 0); if ((code == XK_Escape)||(code == XK_q)) return; if (code == XK_Up) { eLit += lStep; if ( eLit > PI) eLit = PI; } if (code == XK_Down) { eLit -= lStep; if (eLit < 0.f) eLit = 0.f; } if (code == XK_Left) aLit -= lStep; if (code == XK_Right) aLit += lStep; if(code == XK_w) dCam = tStep; if(code == XK_s) dCam = -tStep; if(code == XK_d) lCam = tStep; if(code == XK_a) lCam = -tStep; if(code == XK_g) GLSLshader = !GLSLshader; if (code == XK_f) print_fps = !print_fps; if (code == XK_o) { scalePoly++; glPolygonOffset(scalePoly, biasPoly); } if (code == XK_i) { scalePoly--; glPolygonOffset(scalePoly, biasPoly); } if (code == XK_l) { biasPoly++; glPolygonOffset(scalePoly, biasPoly); } if (code == XK_k) { biasPoly--; glPolygonOffset(scalePoly, biasPoly); } if (code == XK_p) // toggle character 0 running/standing { md2_model[0]->anim_command = ANIMATION_CHANGE; md2_model[1]->anim_command = ANIMATION_CHANGE; if (md2_model[0]->current_animation == ANIMATION_RUN) { md2_model[0]->anim_state = ANIMATION_STANDING_IDLE; md2_model[1]->anim_state = ANIMATION_STANDING_IDLE; } else { md2_model[0]->anim_state = ANIMATION_RUN; md2_model[1]->anim_state = ANIMATION_RUN; } } if (code == XK_0) // increase character 1 animation { md2_model[2]->anim_command = ANIMATION_CHANGE; if ( md2_model[2]->anim_state++ == ANIMATION_CROUCH_DEATH ) md2_model[2]->anim_state = ANIMATION_STANDING_IDLE; } if (code == XK_9) // decrease character 1 animation { md2_model[2]->anim_command = ANIMATION_CHANGE; if ( md2_model[2]->anim_state-- == ANIMATION_STANDING_IDLE ) md2_model[2]->anim_state = ANIMATION_CROUCH_DEATH; } if (code == XK_h) // kill character 1 { md2_model[2]->anim_command = ANIMATION_CHANGE; md2_model[2]->anim_state = ANIMATION_DEATH_SLOW; } if (code == XK_r) { wireframe = !wireframe; if (wireframe) glPolygonMode(GL_FRONT, GL_LINE); else glPolygonMode(GL_FRONT, GL_FILL); } } case ButtonPress: { handle_mouse_button(event.xbutton.button, 0, event.xbutton.x, event.xbutton.y); break; } case ButtonRelease: { handle_mouse_button(event.xbutton.button, 1, event.xbutton.x, event.xbutton.y); break; } case MotionNotify: { if (event.xmotion.state & Button1Mask) { handle_mouse_motion(1, event.xmotion.x, event.xmotion.y); break; } if (event.xmotion.state & Button3Mask) handle_mouse_motion(3, event.xmotion.x, event.xmotion.y); break; } } } render(); glXSwapBuffers( display, window ); switch (signal_pending) { case SIGINT: case SIGHUP: case SIGTERM: return; /* return from event_loop */ default: break; } signal_pending = 0; if( (use_timer) && ( (etime - t2) > max_timer ) ) return; } }
void render(void) { static GLint iFrames = 0; static GLfloat fps = 0.0f, DeltaT; static char cBuffer[64]; struct timeval tv; GLuint model_id; // Update timer gettimeofday(&tv, NULL); etime = (double)tv.tv_sec + tv.tv_usec / 1000000.0f; dt = etime - t0; t0 = etime; /* * Make the shadow pass * */ glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, FBO ); glPushMatrix(); //Compute light position sinE = sinf(eLit); cosE = cosf(eLit); sinA = sinf(aLit); cosA = cosf(aLit); lightPos[0] = lightRadius * cosE * sinA; lightPos[1] = lightRadius * sinE; lightPos[2] = lightRadius * cosE * cosA; lightPos[3] = 1.0f; //Set light position glLightfv(GL_LIGHT0, GL_POSITION, lightPos); //Set up camera to light location glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective( 70.0f, 1.0f, 75.0f, 350.0f ); glGetDoublev(GL_PROJECTION_MATRIX, lightProjection ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt( lightPos[0], lightPos[1], lightPos[2], 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f ); glGetDoublev(GL_MODELVIEW_MATRIX, lightModelview ); glViewport( 0, 0, shadow_sz, shadow_sz ); glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_POLYGON_OFFSET_FILL); glShadeModel(GL_FLAT); //Rotate scene, if required glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); //Disable shaders glUseProgramObjectARB(0); glDisable(GL_VERTEX_PROGRAM_ARB); glDisable(GL_FRAGMENT_PROGRAM_ARB); // Draw dynamic objects for (model_id = 0; model_id < NUM_MODELS; model_id++ ) { //Update the kinematic's state UpdateMD2(md2_model[model_id], dt); //Animate the MD2 models AnimateMD2(md2_model[model_id], dt); //Draw the geometry glPushMatrix(); glTranslatef( md2_model[model_id]->position.x, md2_model[model_id]->position.y, md2_model[model_id]->position.z ); glRotatef( md2_model[model_id]->rotation, 0.0f, 1.0f, 0.0f ); DrawMD2(md2_model[model_id]); glPopMatrix(); } glPopMatrix(); glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); /* * And now the normal pass * */ //Back to normal settings glDisable(GL_POLYGON_OFFSET_FILL); glShadeModel(GL_SMOOTH); change_size( width, height ); // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); //Set up camera location and parameters setup_camera((float)dt); //Retrieve modelview matrix and invert it glGetDoublev(GL_MODELVIEW_MATRIX, cameraModelview ); FastInvert4( cameraModelview, cameraModelviewInverse ); //Set up depth texture glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, shadow_tx); //Set up texture matrix for shadow map projection glMatrixMode(GL_TEXTURE); glLoadIdentity(); glTranslatef(0.5f, 0.5f, 0.5f); glScalef(0.5f, 0.5f, 0.5f); glMultMatrixd(lightProjection); glMultMatrixd(lightModelview); glMultMatrixd(cameraModelviewInverse); glMatrixMode(GL_MODELVIEW); //Rotate scene glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); //Re-enable shaders glEnable(GL_VERTEX_PROGRAM_ARB); glEnable(GL_FRAGMENT_PROGRAM_ARB); if (GLSLshader) glUseProgramObjectARB(progObj); else glUseProgramObjectARB(0); //Floor //Color glColor3f(0.64f, 0.63f, 0.65f); //Set textures glActiveTexture(GL_TEXTURE0); //Diffuse map glBindTexture(GL_TEXTURE_2D, texture_id[NUM_TEXTURES-2]); glActiveTexture(GL_TEXTURE1); //Normal map glBindTexture(GL_TEXTURE_2D, texture_id[NUM_TEXTURES-1]); //Set Tangent vector glVertexAttrib3fv( tangent, floorT ); //Set Binormal vector glVertexAttrib3fv( binormal, floorB ); //Set Normal vector glNormal3fv( floorN ); //Call Display List to draw glCallList(FList); // Draw dynamic objects for (model_id = 0; model_id < NUM_MODELS; model_id++ ) { //Set color glColor3f( md2_model[model_id]->color.x, md2_model[model_id]->color.y, md2_model[model_id]->color.z ); //Set texture glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture_id[2*model_id]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture_id[2*model_id+1]); //Draw the geometry glPushMatrix(); glTranslatef( md2_model[model_id]->position.x, md2_model[model_id]->position.y, md2_model[model_id]->position.z ); glRotatef( md2_model[model_id]->rotation, 0.0f, 1.0f, 0.0f ); DrawMD2(md2_model[model_id]); glPopMatrix(); } glPopMatrix(); iFrames++; DeltaT = (GLfloat)(etime-t1); if( DeltaT >= Timed ) { fps = (GLfloat)(iFrames)/DeltaT; fps_count++; fps_mean = ((fps_count - 1.0f) * fps_mean + fps ) / fps_count; iFrames = 0; t1 = etime; sprintf(cBuffer,"FPS: %.1f Mean FPS: %.1f Poly Scale: %.1f Bias: %.1f", fps, fps_mean, scalePoly, biasPoly); } if (print_fps) { if (windowpos) { glColor3f(1.0f, 1.0f, 1.0f); glPushAttrib(GL_LIST_BIT); glListBase(fps_font - ' '); glWindowPos2i(0,2); glCallLists(strlen(cBuffer), GL_UNSIGNED_BYTE, cBuffer); glPopAttrib(); } if( iFrames == 0 ) printf("FPS: %.1f Mean FPS: %.1f\n", fps, fps_mean); } lCam = 0.0f; vCam = 0.0f; dCam = 0.0f; }
static ssize_t ospfs_write(struct file *filp, const char __user *buffer, size_t count, loff_t *f_pos) { ospfs_inode_t *oi = ospfs_inode(filp->f_dentry->d_inode->i_ino); int retval = 0; size_t amount = 0; //eprintk("writing ~~~~~~~~~~~~~~~~~~"); // Support files opened with the O_APPEND flag. To detect O_APPEND, // use struct file's f_flags field and the O_APPEND bit. /* EXERCISE: Your code here */ if (filp->f_flags & O_APPEND) //if has the flag { *f_pos = oi->oi_size; } // If the user is writing past the end of the file, change the file's // size to accomodate the request. (Use change_size().) /* EXERCISE: Your code here */ if ((*f_pos+count) > oi->oi_size) { //static int change_size(ospfs_inode_t *oi, uint32_t want_size); int change = change_size(oi, (*f_pos+count)); if (change < 0) goto done; } // Copy data block by block while (amount < count && retval >= 0) { uint32_t blockno = ospfs_inode_blockno(oi, *f_pos); uint32_t n; char *data; if (blockno == 0) { retval = -EIO; goto done; } data = ospfs_block(blockno); // Figure out how much data is left in this block to write. // Copy data from user space. Return -EFAULT if unable to read // read user space. // Keep track of the number of bytes moved in 'n'. /* EXERCISE: Your code here */ //retval = -EIO; // Replace these lines //goto done; uint32_t blk_left = OSPFS_BLKSIZE - (*f_pos) % OSPFS_BLKSIZE; data = data + (*f_pos) % OSPFS_BLKSIZE; if (blk_left > (count-amount)) { blk_left = count - amount; } //unsigned long copy_from_user (void * to,const void __user * from,unsigned long n); if (copy_from_user(data,buffer,blk_left)!=0) return -EFAULT; buffer += n; amount += n; *f_pos += n; } done: return (retval >= 0 ? amount : retval); }
static ssize_t ospfs_write(struct file *filp, const char __user *buffer, size_t count, loff_t *f_pos) { ospfs_inode_t *oi = ospfs_inode(filp->f_dentry->d_inode->i_ino); int retval = 0; size_t amount = 0; if (!count) return 0; if (count < 0 ) return -EIO; // Support files opened with the O_APPEND flag. To detect O_APPEND, // use struct file's f_flags field and the O_APPEND bit. /* DONE: Your code here */ if ((filp->f_flags & O_APPEND) == O_APPEND) { *f_pos = oi->oi_size; } // If the user is writing past the end of the file, change the file's // size to accomodate the request. (Use change_size().) /* DONE: Your code here */ if (count > oi->oi_size - *f_pos) { retval = change_size(oi, *f_pos + count); if (retval) return retval; } // Copy data block by block while (amount < count && retval >= 0) { uint32_t blockno = ospfs_inode_blockno(oi, *f_pos); uint32_t n; char *data; if (blockno == 0) { retval = -EIO; goto done; } data = ospfs_block(blockno); // Figure out how much data is left in this block to write. // Copy data from user space. Return -EFAULT if unable to // read user space. // Keep track of the number of bytes moved in 'n'. /* DONE: Your code here */ long block_pos = *f_pos % OSPFS_BLKSIZE; // if the amount to write is greater than the amount left in this block if (count - amount > OSPFS_BLKSIZE - block_pos) { n = OSPFS_BLKSIZE - block_pos; } // if amt to write is less than amt left else { n = count - amount; } retval = copy_from_user(data + block_pos, buffer, n); if (retval != 0) { return -EFAULT; } buffer += n; amount += n; *f_pos += n; } done: return (retval >= 0 ? amount : retval); }