FILE*fp = NULL double L p ">

disk_emu.c -...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include "disk_emu.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <unistd.h> FILE *fp = NULL; double L, p; double r; int BLOCK_SIZE, MAX_BLOCK, MAX_RETRY, lru; /*----------------------------------------------------------*/ /*Close the disk file filled when you don't need it anymore. */ /*----------------------------------------------------------*/ int close_disk() { if (NULL != fp) { fclose(fp); } return 0; } /*---------------------------------------*/ /*Initializes a disk file filled with 0's*/ /*---------------------------------------*/ int init_fresh_disk(char *filename, int block_size, int num_blocks) { int i, j; /*Set up latency at 0.02 second*/ L = 00000.f; /*Set up failure at 10%*/ p = -1.f; /*Set up max retry attempts after failure to 3*/ MAX_RETRY = 3; BLOCK_SIZE = block_size; MAX_BLOCK = num_blocks; /*Initializes the random number generator*/ srand((unsigned int)(time(0))); /*Creates a new file*/ fp = fopen(filename, "w+b"); if (fp == NULL) { printf("Could not create new disk file %s\n\n", filename); return -1; } /*Fills the file with 0's to its given size*/ for (i = 0; i < MAX_BLOCK; i++) { for (j = 0; j < BLOCK_SIZE; j++) { fputc(0, fp); } } return 0; } /*----------------------------*/ /*Initializes an existing disk*/ /*----------------------------*/ int init_disk(char *filename, int block_size, int num_blocks) { /*Set up latency at 0.02 second*/ L = 00000.f; /*Set up failure at 10%*/ p = -1.f;
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern