static int
beri_sdcard_disk_print(int verbose)
{
	struct disk_devdesc dev;
	char line[80];
	int ret;

	printf("%s devices:", beri_sdcard_disk.dv_name);
	if ((ret = pager_output("\n")) != 0)
		return (ret);
	
	snprintf(line, sizeof(line), "    sdcard%d   Altera SD card drive\n", 0);
	ret = pager_output(line);
	if (ret != 0)
	    return (ret);
	dev.dd.d_dev = &beri_sdcard_disk;
	dev.dd.d_unit = 0;
	dev.d_slice = D_SLICENONE;
	dev.d_partition = D_PARTNONE;
	if (disk_open(&dev, altera_sdcard_get_mediasize(),
	    altera_sdcard_get_sectorsize()) == 0) {
		snprintf(line, sizeof(line), "    sdcard%d", 0);
		ret = disk_print(&dev, line, verbose);
		disk_close(&dev);
	}
	return (ret);
}
Exemple #2
0
static int
beri_cfi_disk_print(int verbose)
{
	struct disk_devdesc dev;
	char line[80];
	int ret;

	printf("%s devices:", beri_cfi_disk.dv_name);
	if ((ret = pager_output("\n")) != 0)
		return (ret);

	snprintf(line, sizeof(line), "    cfi%d   CFI flash device\n", 0);
	ret = pager_output(line);
	if (ret != 0)
		return (ret);
	dev.d_dev = &beri_cfi_disk;
	dev.d_unit = 0;
	dev.d_slice = -1;
	dev.d_partition = -1;
	if (disk_open(&dev, cfi_get_mediasize(),
	    cfi_get_sectorsize(), 0) == 0) {
		snprintf(line, sizeof(line), "    cfi%d", 0);
		ret = disk_print(&dev, line, verbose);
		disk_close(&dev);
	}

	return (ret);
}
Exemple #3
0
static int
stor_print(int verbose)
{
	struct disk_devdesc dev;
	static char line[80];
	int i, ret = 0;

	if (stor_info_no == 0)
		return (ret);

	printf("%s devices:", uboot_storage.dv_name);
	if ((ret = pager_output("\n")) != 0)
		return (ret);

	for (i = 0; i < stor_info_no; i++) {
		dev.d_dev = &uboot_storage;
		dev.d_unit = i;
		dev.d_slice = -1;
		dev.d_partition = -1;
		snprintf(line, sizeof(line), "\tdisk%d (%s)\n", i,
		    ub_stor_type(SI(&dev).type));
		if ((ret = pager_output(line)) != 0)
			break;
		if (stor_opendev(&dev) == 0) {
			sprintf(line, "\tdisk%d", i);
			ret = disk_print(&dev, line, verbose);
			disk_close(&dev);
			if (ret != 0)
				break;
		}
	}
	return (ret);
}
static int
beri_sdcard_disk_close(struct open_file *f)
{
	struct disk_devdesc *dev;

	dev = (struct disk_devdesc *)f->f_devdata;
	return (disk_close(dev));
}
Exemple #5
0
static int
stor_close(struct open_file *f)
{
	struct disk_devdesc *dev;

	dev = (struct disk_devdesc *)(f->f_devdata);
	return (disk_close(dev));
}
Exemple #6
0
void *sfs_init(struct fuse_conn_info *conn)
{
    
    log_msg("Testing- log started- sfs_init()\n");
    log_msg("\nsfs_init()\n");
    
    log_conn(conn);
    log_fuse_context(fuse_get_context());
    
    disk_open(SFS_DATA->diskfile);
    char *readbuf;
    char *writebuf;
    int status=block_read(0,&readbuf);
    

    struct super_block* sb;
    //writebuf=&sb;
    
    if(status==0){//first time in sfs_init
        sb = (struct super_block*)malloc(sizeof(struct super_block));

        log_msg("Testing- first time in sfs_init\n");
        sb->size=131072;
        sb->nblocks=256;
        sb->ninode=0;
        //log_msg("%d\n",sb.nblocks);
        writebuf=sb;
        int write_status=block_write(0,&writebuf);
        
        //log_msg("%d", write_status);
        if(write_status>0){
            log_msg("Testing- write successful %d\n",write_status);
            struct super_block* testbuf;
            
            int x=block_read(0,&testbuf);
            log_msg("Read status %d\n",x);
            log_msg("Block read %d\n",testbuf->size);
            log_msg("Block read %d\n",testbuf->nblocks);
            log_msg("Block read %d\n",testbuf->ninode);
        }
        

    }
    disk_close();
    
    //log_msg(hello_path);
    
    //char *test="abcd";
   // char *test2;
    
    //int output=block_write(0,&test);
     //output = block_read(0, &test2);
   // log_msg("Block read :%s", test2);
    //log_msg(output);
    //disk_close();
    log_msg("Testing- exiting sfs_init()\n");
    return SFS_DATA;
}
Exemple #7
0
static
void
disk_cleanup(void *data)
{
    struct disk_data *dd = data;
    disk_close(dd);
    free(dd->dd_buf);
    free(dd);
}
Exemple #8
0
int
main(int argc, char *argv[])
{
	int parsed;
	int success = 1;

	parsed = parse_options(argc, argv);
	argc -= parsed;
	argv += parsed;

	if (opts.size_override)
	{
		uint64_t size = parse_disk_size(opts.size_override);
		blkio_set_size_override(size);
	}

	if (opts.sparse_clone)
		blkio_open_sparse_clone(opts.sparse_clone);

	if (opts.command_fn)
	{
		if ((disk = disk_open(opts.device_path)) == 0)
		        success = 0;
		if (success && (fs = fs_open_disk(disk)) == 0)
		        success = 0;
		if (success)
			success = opts.command_fn(argc, argv);
		if (fs)
			fs_close(fs);
		if (disk)
			disk_close(disk);
	}
	else
	{
		usage();
	}

	if (opts.sparse_clone)
		blkio_close_sparse_clone();

	if (success)
	{
		return 0;
	}
	else
	{
		fprintf(stderr, "%s\n", get_error());
		return 1;
	}
}
Exemple #9
0
int *run(int npages, int nframes, page_fault_handler_t handler, void (*program)(char *, int)) {
    int i;
    page_algo_handler = handler;

    disk = disk_open("myvirtualdisk",npages);
    if(!disk) {
        fprintf(stderr,"couldn't create virtual disk: %s\n",strerror(errno));
        exit(EXIT_FAILURE);
    }

    struct page_table *pt = page_table_create( npages, nframes, page_fault_handler );
    if(!pt) {
        fprintf(stderr,"couldn't create page table: %s\n",strerror(errno));
        exit(EXIT_FAILURE);
    }

    fi = 0;
    disk_reads = 0;
    disk_writes = 0;
    page_faults = 0;

    // Init frame table
    ft = malloc(nframes * sizeof(int));
    for (i = 0; i < nframes; ++i)
    {
        ft[i] = -1;
    }

    char *virtmem = page_table_get_virtmem(pt);
    physmem = page_table_get_physmem(pt);

    program(virtmem,npages*PAGE_SIZE);

    printf("Disk writes: %d\n", disk_writes);
    printf("Disk reads:  %d\n", disk_reads);
    printf("Page faults: %d\n", page_faults);

    free(ft);
    page_table_delete(pt);
    disk_close(disk);

    int *stats = malloc(sizeof(int) * 3);
    stats[0] = disk_reads;
    stats[1] = disk_writes;
    stats[2] = page_faults;

    return stats;
}
Exemple #10
0
quik_err_t
part_open(char *device,
          int partno,
          part_t *part)
{
   ihandle dev;
   quik_err_t err;
   quik_err_t err2;

   if (part->flags & PART_VALID) {
      if (part->partno == partno &&
          !strcmp(device, part->devname)) {
         return ERR_NONE;
      }

      part_close(part);
   }

   err = disk_open(device, &dev);
   if (err != ERR_NONE) {
      return err;
   }

   err = read_mac_partition(dev, partno, part);
   if (err == ERR_PART_NOT_MAC) {
      err2 = read_dos_partition(dev, partno, part);

      if (err2 == ERR_PART_NOT_DOS) {
         err = ERR_PART_NOT_PARTITIONED;
      } else {
         err = err2;
      }
   }

   if (err != ERR_NONE) {
      disk_close(dev);
      return err;
   }

   part->partno = partno;
   strncpy(part->devname, device, sizeof(part->devname));
   part->flags |= PART_VALID;

   return ERR_NONE;
}
Exemple #11
0
static void
beri_sdcard_disk_print(int verbose)
{
	struct disk_devdesc dev;
	char line[80];

	sprintf(line, "    sdcard%d   Altera SD card drive\n", 0);
	pager_output(line);
	dev.d_dev = &beri_sdcard_disk;
	dev.d_unit = 0;
	dev.d_slice = -1;
	dev.d_partition = -1;
	if (disk_open(&dev, altera_sdcard_get_mediasize(),
	    altera_sdcard_get_sectorsize(), 0) == 0) {
		sprintf(line, "    sdcard%d", 0);
		disk_print(&dev, line, verbose);
		disk_close(&dev);
	}
}
Exemple #12
0
static void
stor_print(int verbose)
{
	struct disk_devdesc dev;
	static char line[80];
	int i;

	for (i = 0; i < stor_info_no; i++) {
		dev.d_dev = &uboot_storage;
		dev.d_unit = i;
		dev.d_slice = -1;
		dev.d_partition = -1;
		sprintf(line, "\tdisk%d (%s)\n", i,
		    ub_stor_type(SI(&dev).type));
		pager_output(line);
		if (stor_opendev(&dev) == 0) {
			sprintf(line, "\tdisk%d", i);
			disk_print(&dev, line, verbose);
			disk_close(&dev);
		}
	}
}
Exemple #13
0
int diskscan_cli(int argc, char **argv)
{
	int ret;
	options_t opts;
	memset(&opts, 0, sizeof(opts));
	opts.mode = SCAN_MODE_SEQ;

	if (parse_args(argc, argv, &opts))
		return 1;
	verbose = opts.verbose;

	print_header();

	setup_signals();

	if (disk_open(&disk, opts.disk_path, opts.fix, 70))
		return 1;

	/*
	if (print_disk_info(&disk))
		return 1;
	*/

	if (opts.data_log_raw_name)
		data_log_raw_start(&disk.data_raw, opts.data_log_raw_name, &disk);
	if (opts.data_log_name)
		data_log_start(&disk.data_log, opts.data_log_name, &disk);
	ret = 0;
	if (disk_scan(&disk, opts.mode, opts.scan_size))
		ret = 1;
	if (opts.data_log_raw_name)
		data_log_raw_end(&disk.data_raw);
	if (opts.data_log_name)
		data_log_end(&disk.data_log, &disk);

	disk_close(&disk);
	return ret;
}
Exemple #14
0
UIDiskChooser::UIDiskChooser(const char* title):Fl_Double_Window(400, 200, title){
	uint32 i = 0;
	uint32 dcount = disk_count();
	disk_info_t info;
	handle_t h;
	char *fmt_name = "\\\\.\\PhysicalDrive%d";
	char *name;
	char *size;

	_list = new UIDiskList(0, 0, 400, 160);
	_list->begin();
	for (i = 0; i < dcount; i ++){
		h = disk_open(i);
		if (h != null){
			name = (char*)calloc(64, sizeof(char));
			size = (char*)calloc(32, sizeof(char));
			
			disk_info(h, &info);
			format_size(size, info.size);
			sprintf(name, fmt_name, i);
			
			_list->add_disk(i, name, size, info.mbr.gpt_protect ? info.gpt.part_count : info.mbr.part_count);
		}
		disk_close(h);
	}
	_list->end();
	add(_list);
	
	_ok = new Fl_Button(260, 170, 60, 24, "OK");
	_ok->callback(ok_cb, this);
	add(_ok);
	_cancel = new Fl_Button(330, 170, 60, 24, "Cancel");
	_cancel->callback(cancel_cb, this);
	add(_cancel);

}
int main( int argc, char *argv[] )
{
    // handle input
    if(argc!=5) {
		printf("use: virtmem <npages> <nframes> <rand|fifo|custom> <sort|scan|focus>\n");
		return 1;
	}

	int npages = atoi(argv[1]);
	int nframes = atoi(argv[2]);
	char *page_replacement = argv[3];
    const char *program = argv[4];
    if (!strcmp(page_replacement,"rand")){
        page_rep_choice = 0;
    }
    else if(!strcmp(page_replacement,"fifo")){
        page_rep_choice = 1;
    }
    else if(!strcmp(page_replacement,"custom")){
        page_rep_choice = 2;
    }
    else{
        printf("Choose rand, fifo, or custum\n");
        return 1;
    }

    // create new virtual disk with pointer to the disk object
	struct disk *disk = disk_open("myvirtualdisk",npages);
	if(!disk) {
		fprintf(stderr,"couldn't create virtual disk: %s\n",strerror(errno));
		return 1;
	}

    // create page table with pointer to page table
    // includes virtual memory and physical memory
	struct page_table *pt = page_table_create( npages, nframes, page_fault_handler );
	if(!pt) {
		fprintf(stderr,"couldn't create page table: %s\n",strerror(errno));
		return 1;
	}

    // return pointer to start of virtual memory
	char *virtmem = page_table_get_virtmem(pt);
    // return pointer to start of physical memory
	char *physmem = page_table_get_physmem(pt);

	// calls page_fault_handler
	// call one of the algorithms
	if(!strcmp(program,"sort")) {
		sort_program(virtmem,npages*PAGE_SIZE);

	} else if(!strcmp(program,"scan")) {
		scan_program(virtmem,npages*PAGE_SIZE);

	} else if(!strcmp(program,"focus")) {
		focus_program(virtmem,npages*PAGE_SIZE);

	} else {
		fprintf(stderr,"unknown program: %s\n",argv[3]);

	}

    page_table_print(pt);
    // clean up
	page_table_delete(pt);
	disk_close(disk);

	return 0;
}
Exemple #16
0
void
part_close(part_t *part)
{
   disk_close(part->dev);
   memset(part, 0, sizeof(*part));
}
Exemple #17
0
int main( int argc, char *argv[] )
{
	char line[1024];
	char cmd[1024];
	char arg1[1024];
	char arg2[1024];
	int inumber, result, args;

	if(argc!=3) {
		printf("use: %s <diskfile> <nblocks>\n",argv[0]);
		return 1;
	}

	if(!disk_init(argv[1],atoi(argv[2]))) {
		printf("couldn't initialize %s: %s\n",argv[1],strerror(errno));
		return 1;
	}

	printf("opened emulated disk image %s with %d blocks\n",argv[1],disk_size());

	while(1) {
		printf(" prompt> ");
		fflush(stdout);

		if(!fgets(line,sizeof(line),stdin)) break;

		if(line[0]=='\n') continue;
		line[strlen(line)-1] = 0;

		args = sscanf(line,"%s %s %s",cmd,arg1,arg2);
		if(args==0) continue;

		if(!strcmp(cmd,"format")) {
			if(args==1) {
				if(fs_format()) {
					printf("disk formatted.\n");
				} else {
					printf("format failed!\n");
				}
			} else {
				printf("use: format\n");
			}
		} else if(!strcmp(cmd,"mount")) {
			if(args==1) {
				if(fs_mount()) {
					printf("disk mounted.\n");
				} else {
					printf("mount failed!\n");
				}
			} else {
				printf("use: mount\n");
			}
		} else if(!strcmp(cmd,"umount")) {
			if(args==1) {
				if(fs_umount()) {
					printf("disk umounted.\n");
				} else {
					printf("umount failed!\n");
				}
			} else {
				printf("use: mount\n");
			}
		} else if(!strcmp(cmd,"debug")) {
			if(args==1) {
				fs_debug();
			} else {
				printf("use: debug\n");
			}
		} else if(!strcmp(cmd,"getsize")) {
			if(args==2) {
				inumber = atoi(arg1);
				result = fs_getsize(inumber);
				if(result>=0) {
					printf("inode %d has size %d\n",inumber,result);
				} else {
					printf("getsize failed!\n");
				}
			} else {
				printf("use: getsize <inumber>\n");
			}
			
		} else if(!strcmp(cmd,"create")) {
			if(args==1) {
				inumber = fs_create();
				if(inumber>=0) {
					printf("created inode %d\n",inumber);
				} else {
					printf("create failed!\n");
				}
			} else {
				printf("use: create\n");
			}
		} else if(!strcmp(cmd,"delete")) {
			if(args==2) {
				inumber = atoi(arg1);
				if(fs_delete(inumber)) {
					printf("inode %d deleted.\n",inumber);
				} else {
					printf("delete failed!\n");	
				}
			} else {
				printf("use: delete <inumber>\n");
			}
		} else if(!strcmp(cmd,"cat")) {
			if(args==2) {
				inumber = atoi(arg1);
				if(!do_copyout(inumber,"/dev/stdout")) {
					printf("cat failed!\n");
				}
			} else {
				printf("use: cat <inumber>\n");
			}

		} else if(!strcmp(cmd,"copyin")) {
			if(args==3) {
				inumber = atoi(arg2);
				if(do_copyin(arg1,inumber)) {
					printf("copied file %s to inode %d\n",arg1,inumber);
				} else {
					printf("copy failed!\n");
				}
			} else {
				printf("use: copyin <filename> <inumber>\n");
			}

		} else if(!strcmp(cmd,"copyout")) {
			if(args==3) {
				inumber = atoi(arg1);
				if(do_copyout(inumber,arg2)) {
					printf("copied inode %d to file %s\n",inumber,arg2);
				} else {
					printf("copy failed!\n");
				}
			} else {
				printf("use: copyout <inumber> <filename>\n");
			}

		} else if(!strcmp(cmd,"help")) {
			printf("Commands are:\n");
			printf("    format\n");
			printf("    mount\n");
			printf("    umount\n");
			printf("    debug\n");
			printf("    create\n");
			printf("    delete  <inode>\n");
			printf("    getsize  <inode>\n");
			printf("    cat     <inode>\n");
			printf("    copyin  <file> <inode>\n");
			printf("    copyout <inode> <file>\n");
			printf("    help\n");
			printf("    quit\n");
			printf("    exit\n");
		} else if(!strcmp(cmd,"quit")) {
			break;
		} else if(!strcmp(cmd,"exit")) {
			break;
		} else {
			printf("unknown command: %s\n",cmd);
			printf("type 'help' for a list of commands.\n");
			result = 1;
		}
	}

	printf("closing emulated disk.\n");
	disk_close();

	return 0;
}
Exemple #18
0
int main( int argc, char *argv[] )
{
	char line[1024];
	char cmd[1024];
	char arg1[1024];
	char arg2[1024];
	int result, args;

	if(argc!=3) {
		printf("use: %s <diskfile> <nblocks>\n",argv[0]);
		return 1;
	}

	if(!disk_init(argv[1],atoi(argv[2]))) {
		printf("couldn't initialize %s: %s\n",argv[1],strerror(errno));
		return 1;
	}

	printf("opened emulated disk image %s with %d blocks\n",argv[1],disk_size());

	while(1) {
		printf(" prompt> ");
		fflush(stdout);

		if(!fgets(line,sizeof(line),stdin)) break;

		if(line[0]=='\n') continue;
		line[strlen(line)-1] = 0;

		args = sscanf(line,"%s %s %s",cmd,arg1,arg2);
		if(args==0) continue;

		if(!strcmp(cmd,"format")) {
			if(args==1) {
				if(!fs_format()) {
					printf("disk formatted.\n");
				} else {
					printf("format failed!\n");
				}
			} else {
				printf("use: format\n");
			}
		} else if(!strcmp(cmd,"mount")) {
			if(args==1) {
				if(!fs_mount()) {
					printf("disk mounted.\n");
				} else {
					printf("mount failed!\n");
				}
			} else {
				printf("use: mount\n");
			}
		} else if(!strcmp(cmd,"debug")) {
			if(args==1) {
				fs_debug();
			} else {
				printf("use: debug\n");
			}
		} else if(!strcmp(cmd,"getsize")) {
			if(args==2) {
				result = fs_getsize(arg1);
				if(result>=0) {
					printf("file %s has size %d\n",arg1,result);
				} else {
					printf("getsize failed!\n");
				}
			} else {
				printf("use: getsize <filename>\n");
			}
			
		} else if(!strcmp(cmd,"create")) {
			if(args==2) {
				result = fs_create(arg1);
				if(result==0) {
					printf("created file %s\n",arg1);
				} else {
					printf("create failed!\n");
				}
			} else {
				printf("use: create <filename>\n");
			}
		} else if(!strcmp(cmd,"delete")) {
			if(args==2) {
				if(!fs_delete(arg1)) {
					printf("file %s deleted.\n",arg1);
				} else {
					printf("delete failed!\n");	
				}
			} else {
				printf("use: delete <filename>\n");
			}
		} else if(!strcmp(cmd,"cat")) {
			if(args==2) {
				if(!do_copyout(arg1,"/dev/stdout")) {
					printf("cat failed!\n");
				}
			} else {
				printf("use: cat <name>\n");
			}

		} else if(!strcmp(cmd,"copyin")) {
			if(args==3) {
				if(do_copyin(arg1,arg2)) {
					printf("copied file %s to  %s\n",arg1,arg2);
				} else {
					printf("copy failed!\n");
				}
			} else {
				printf("use: copyin <filename in host system> <filename in fs-miei-02>\n");
			}

		} else if(!strcmp(cmd,"copyout")) {
			if(args==3) {
				if(do_copyout(arg1,arg2)) {
					printf("copied myfs_file %s to file %s\n", arg1,arg2);
				} else {
					printf("copy failed!\n");
				}
			} else {
				printf("use: copyout <inumber> <filename>\n");
			}

		} else if(!strcmp(cmd,"help")) {
			printf("Commands are:\n");
			printf("    format\n");
			printf("    mount\n");
			printf("    debug\n");
			printf("    create\n");
			printf("    delete  <filename>\n");
			printf("    cat     <filename>\n");
			printf("    getsize <filename>\n");
			printf("    copyin  <file name in host system> <miei02-filename>\n");
			printf("    copyout <miei02-filename> <file name in host system>\n");
			printf("	dump <number_of_block_with_text_contents>\n");
			printf("    help\n");
			printf("    quit\n");
			printf("    exit\n");
		} else if(!strcmp(cmd,"quit")) {
			break;
		} else if(!strcmp(cmd,"exit")) {
			break;
		} else if (!strcmp(cmd, "dump")){
			if(args==2) {
				int blNo = atoi(arg1);
				printf("Dumping disk block %d\n", blNo);
				char b[4096];
				disk_read( blNo, b);
				printf("------------------------------\n");
				printf("%s", b);
				printf("\n------------------------------\n");
			}
			else {
				printf("use: dump <block_number>\n");
			}
		} else {
			printf("unknown command: %s\n",cmd);
			printf("type 'help' for a list of commands.\n");
			result = 1;
		}
	}

	printf("closing emulated disk.\n");
	disk_close();

	return 0;
}
Exemple #19
0
int disk_open(disk_t *disk, const char *path, int fix, unsigned latency_graph_len)
{
	memset(disk, 0, sizeof(*disk));
	disk->fix = fix;

	INFO("Validating path %s", path);
	if (access(path, F_OK)) {
		ERROR("Disk path %s does not exist, errno=%d: %s", path, errno, strerror(errno));
		return 1;
	}

	const int access_mode_flag = fix ? R_OK|W_OK : R_OK;
	if (access(path, access_mode_flag)) {
		ERROR("Disk path %s is inaccessible, errno=%d: %s", path, errno, strerror(errno));
		return 1;
	}

	if (!disk_dev_open(&disk->dev, path)) {
		ERROR("Failed to open path %s, errno=%d: %s", path, errno, strerror(errno));
		return 1;
	}

	if (disk_dev_read_cap(&disk->dev, &disk->num_bytes, &disk->sector_size) < 0) {
		ERROR("Can't get block device size information for path %s, errno=%d: %s", path, errno, strerror(errno));
		goto Error;
	}

	if (disk->num_bytes == 0) {
		ERROR("Invalid number of sectors");
		goto Error;
	}

	if (disk->sector_size == 0 || disk->sector_size % 512 != 0) {
		ERROR("Invalid sector size %" PRIu64, disk->sector_size);
		goto Error;
	}

#if 0
	const uint64_t new_bytes_raw = disk->num_bytes / 10;
	const uint64_t new_bytes_leftover = new_bytes_raw % 512;
	const uint64_t new_bytes = new_bytes_raw - new_bytes_leftover;
	disk->num_bytes = new_bytes;
#endif

	if (disk_dev_identify(&disk->dev, disk->vendor, disk->model, disk->fw_rev, disk->serial, &disk->is_ata, disk->ata_buf, &disk->ata_buf_len) < 0) {
		ERROR("Can't identify disk for path %s, errno=%d: %s", path, errno, strerror(errno));
		goto Error;
	}

	strncpy(disk->path, path, sizeof(disk->path));
	disk->path[sizeof(disk->path)-1] = 0;

	hdr_init(1, 60*1000*1000, 3, &disk->histogram);

	disk->latency_graph_len = latency_graph_len;
	disk->latency_graph = calloc(latency_graph_len, sizeof(latency_t));
	if (disk->latency_graph == NULL) {
		ERROR("Failed to allocate memory for latency graph data");
		goto Error;
	}

	if (disk->is_ata)
		disk_ata_monitor_start(disk);
	else
		disk_scsi_monitor_start(disk);

	INFO("Opened disk %s sector size %"PRIu64" num bytes %"PRIu64, path, disk->sector_size, disk->num_bytes);
	return 0;

Error:
	disk_close(disk);
	return 1;
}
Exemple #20
0
int main( int argc, char *argv[] )
{
	if(argc!=5) 
	{
		printf("use: virtmem <npages> <nframes> <rand|fifo|custom> <sort|scan|focus>\n");
		return 1;
	}

	npages = atoi(argv[1]);
	nframes = atoi(argv[2]);
	const char *algorithm = argv[3];
	const char *program = argv[4];

	loaded_pages = malloc(sizeof(int) * nframes);
	int i;
	for(i = 0; i < nframes; i++)
	{
		/* indicate that there is no pages loaded yet */
		loaded_pages[i] = -1;
	}

	disk = disk_open("myvirtualdisk",npages);
	if(!disk) 
	{
		fprintf(stderr,"couldn't create virtual disk: %s\n",strerror(errno));
		return 1;
	}

	struct page_table *pt = page_table_create( npages, nframes, page_fault_handler );
	if(!pt) 
	{
		fprintf(stderr,"couldn't create page table: %s\n",strerror(errno));
		return 1;
	}
	
	char *virtmem = page_table_get_virtmem(pt);

	physmem = page_table_get_physmem(pt);

	if(!strcmp(algorithm, "rand")) 
	{
		pageswap = 0;
	}
	else if(!strcmp(algorithm, "fifo"))
	{
		pageswap = 1;
		fifo_counter = 0;
	}
	else if(!strcmp(algorithm, "custom"))
	{
		pageswap = 2;
		fifo_counter = 0;
		clock = malloc(sizeof(int) * nframes);
		for(i = 0; i < nframes; i++)
		{
			clock[i] = 0;
		}
	}
	else if(!strcmp(algorithm, "custom2"))
	{
		pageswap = 3;
		clock = malloc(sizeof(int) * nframes);
		for(i = 0; i < nframes; i++)
		{
			clock[i] = 0;
		}
	}
	else
	{
		fprintf(stderr,"unknown algorithm: %s\n",argv[2]);
	}

	if(!strcmp(program,"sort")) 
	{
		sort_program(virtmem,npages*PAGE_SIZE);

	} 
	else if(!strcmp(program,"scan")) 
	{
		scan_program(virtmem,npages*PAGE_SIZE);

	} 
	else if(!strcmp(program,"focus")) 
	{
		focus_program(virtmem,npages*PAGE_SIZE);

	} 
	else 
	{
		fprintf(stderr,"unknown program: %s\n",argv[3]);
	}
	printf("Faults: %d Reads: %d Writes: %d\n", fault_counter, read_count, write_count);
	page_table_delete(pt);
	disk_close(disk);

	return 0;
}