Exemplo n.º 1
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);
}
Exemplo n.º 2
0
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);
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
void tdisk_init() {
	static char init_done = 0;
	int i;
	if (!init_done) {
		disk_open(&tdisks[0], floppyA);	
		disk_open(&tdisks[1], floppyB);	
		disk_open(&tdisks[2], floppyC);	
		disk_open(&tdisks[3], floppyD);	
		init_done = 1;
	}
	for (i = 0; i < 4; i++) {
		tdisks[i].ptr = NULL;
		tdisks[i].track =
		tdisks[i].motor =
		tdisks[i].inprogress = 0;
	}
	selected = -1;
}	// tdisk_init
Exemplo n.º 5
0
int disk_init() {
	static char init_done = 0;
	int i;
	if (!init_done) {
		disk_open(&disks[0], floppyA);	
		disk_open(&disks[1], floppyB);	
		disk_open(&disks[2], floppyC);	
		disk_open(&disks[3], floppyD);	
		init_done = 1;
	}
	for (i = 0; i < 4; i++) {
		disks[i].ptr = NULL;
		disks[i].track = disks[i].side =
		disks[i].motor = disks[i].inprogress = 0;
	}
	selected = -1;
	return OK;
}
Exemplo n.º 6
0
int
openrd(const char *name, const char **basename)
{
	const char *cp = name;

	while (*cp && *cp!='(')
		cp++;
	if (!*cp)
		cp = name;
	else {
		if (cp++ != name) {
			if (name[1] != 'd' ||
			    (name[0] != 'h' && name[0] != 'f' && name[0] != 's')) {
				printf("Unknown device\n");
				return 1;
			}
			dev = name[0];
		}
		if (*cp >= '0' && *cp <= '9')
			if ((unit = *cp++ - '0') > 1) {
				printf("Bad unit\n");
				return 1;
			}
		if (!*cp || (*cp == ',' && !*++cp))
			return 1;
		if (*cp >= 'a' && *cp <= 'p')
			part = *cp++ - 'a';
		while (*cp && *cp++!=')') ;
	}
	if (disk_open()) {
	  	printf("Can't open device.\n");
		return 1;
	}
	cnt = SBSIZE;
	bnum = SBLOCK + boff;
	if (disk_read(bnum, cnt, (vm_offset_t)fsbuf)) {
		printf("Cant read super block\n");
		return 1;
	}
	fs = (struct fs *)fsbuf;
	if (fs->fs_magic != FS_MAGIC) {
		printf("bad FS_MAGIC\n");
		return 1;
	}
	if (!*cp || *cp == ' ' || !find(cp))
		return 1;
	poff = 0;
	if (basename)
		*basename = cp;
	return 0;
}
Exemplo n.º 7
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;
	}
}
Exemplo n.º 8
0
static int
beri_cfi_disk_open(struct open_file *f, ...)
{
	va_list ap;
	struct disk_devdesc *dev;

	va_start(ap, f);
	dev = va_arg(ap, struct disk_devdesc *);
	va_end(ap);

	if (dev->d_unit != 0)
		return (EIO);
	return (disk_open(dev, cfi_get_mediasize(), cfi_get_sectorsize(), 0));
}
Exemplo n.º 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;
}
Exemplo n.º 10
0
int
devfs(void)
{
	if (disk_open()) {
	  	printf("Can't open device.\n");
		return 1;
	}
	cnt = SBSIZE;
	bnum = SBLOCK + boff;
	if (disk_read(bnum, cnt, (vm_offset_t)fsbuf)) {
		printf("Cant read super block\n");
		return 1;
	}
	fs = (struct fs *)fsbuf;
	return (fs->fs_magic != FS_MAGIC);
}
Exemplo n.º 11
0
Arquivo: part.c Projeto: andreiw/iQUIK
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;
}
Exemplo n.º 12
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);
	}
}
Exemplo n.º 13
0
static int
stor_opendev(struct disk_devdesc *dev)
{
	int err;

	if (dev->d_unit < 0 || dev->d_unit >= stor_info_no)
		return (EIO);

	if (SI(dev).opened == 0) {
		err = ub_dev_open(SI(dev).handle);
		if (err != 0) {
			stor_printf("device open failed with error=%d, "
			    "handle=%d\n", err, SI(dev).handle);
			return (ENXIO);
		}
		SI(dev).opened++;
	}
	return (disk_open(dev, SI(dev).blocks * SI(dev).bsize,
	    SI(dev).bsize, 0));
}
Exemplo n.º 14
0
static int
beri_sdcard_disk_open(struct open_file *f, ...)
{
	va_list ap;
	struct disk_devdesc *dev;

	va_start(ap, f);
	dev = va_arg(ap, struct disk_devdesc *);
	va_end(ap);

	if (!(altera_sdcard_get_present())) {
		printf("SD card not present or not supported\n");
		return (ENXIO);
	}

	if (dev->dd.d_unit != 0)
		return (EIO);
	return (disk_open(dev, altera_sdcard_get_mediasize(),
	    altera_sdcard_get_sectorsize()));
}
Exemplo n.º 15
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;
}
Exemplo n.º 16
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);

}
Exemplo n.º 17
0
Arquivo: main.c Projeto: Madx-com/BOSC
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;
}
Exemplo n.º 18
0
int main(int argc, char* argv[])
{
    
    FILE*           debugfile;
    disk_t*         disk;
    unt8*           buffer;
    unt8*           clusterbuffer;

    unsigned        i;
    unsigned        j;
    unsigned        k;
    void*           fat_bitmap;
    void*           trifs_bitmap;
    unsigned        diskbitmapsize;
    unt32*          cluster_buffer;

    printf("Trinary File System Tools : Convert FAT32 to TriFS\n\r"
           "Copryright (c) 2003, Rudy Koot (Trinary Technologies)\n\r"
           "\n\r"
           "This program is free software; you can redistribute it and/or modify\n\r"
           "it under the terms of the GNU General Public License as published by\n\r"
           "the Free Software Foundation; either version 2 of the License, or\n\r"
           "(at your option) any later version.\n\r");


	disk = disk_open(argv[1]);
    disk->blocksize = 512;

    fat_super = malloc(disk->blocksize);

    disk_read(disk, ((unt8*)(fat_super)), 0, 1);

    printf("\n\rBIOS Parameter Block:\n\r");
    printf("    File System Creator: %.8s\n\r", fat_super->system);
    printf("    Bytes per Sector   : %i\n\r", fat_super->bytespersector);
    printf("    Sectors per Cluster: %i\n\r", fat_super->sectorspercluster);
    printf("    Reserved Sectors   : %i\n\r", fat_super->reservedsectors);
    printf("    Number of FATs     : %i\n\r", fat_super->numberoffats);
    printf("    Root Entries       : %i\n\r", fat_super->rootentries);
    printf("    Legacy Sectors     : %i\n\r", fat_super->legacysectors);
    printf("    Media              : %X\n\r", fat_super->media);
    printf("    Legacy FAT Size    : %i\n\r", fat_super->legacyfatsize);
    printf("    Sectors Per Track  : %i\n\r", fat_super->sectorspertrack);
    printf("    Number of Tracks   : %i\n\r", fat_super->numberoftracks);
    printf("    Hidden Sectors     : %i\n\r", fat_super->hiddensectors);
    printf("    Total Sectros      : %i\n\r", fat_super->totalsectors);
    printf("    FAT Size           : %i\n\r", fat_super->fatsize);
    printf("    Extension Flags    : %i\n\r", fat_super->extensionflags);
    printf("    File System Version: %X\n\r", fat_super->filesystemversion);
    printf("    Root Cluster       : %i\n\r", fat_super->rootcluster);
    printf("    File System Info   : %i\n\r", fat_super->fsinfo);
    printf("    Boot Sector Backup : %i\n\r", fat_super->bootsectorbackup);
    printf("    Drive Number       : %X\n\r", fat_super->drivenumber);
    printf("    Boot Signature     : %X\n\r", fat_super->bootsignature);
    printf("    Volume ID          : %X\n\r", fat_super->volid);
    printf("    Label              : %.11s\n\r", fat_super->label);
    printf("    File System Type   : %.8s\n\r", fat_super->fstype);

    
    printf("\n\rFile System Layout:\n\r");
    printf("    %.10i - %.10i: Boot Sector\n\r", 0, fat_super->reservedsectors - 1);
    printf("    %.10i - %.10i: FAT 1\n\r", fat_super->reservedsectors, fat_super->fatsize + fat_super->reservedsectors - 1);
    printf("    %.10i - %.10i: FAT 2\n\r", fat_super->fatsize + fat_super->reservedsectors, 2 * fat_super->fatsize + fat_super->reservedsectors - 1);
    printf("    %.10i - %.10i: Data Area\n\r", 2 * fat_super->fatsize + fat_super->reservedsectors, fat_super->totalsectors - 1);

    /* Setup the Conversion Table.                                            */

    ct.blocksize = 4096;
    ct.bandsize = (256 * 1024 * 1024) / ct.blocksize;
    ct.trifsmetadata = 4;

    ct.sectorsize = fat_super->bytespersector;
    ct.clustersize = (fat_super->bytespersector * fat_super->sectorspercluster) / ct.blocksize;
    ct.fatmetadata = ((fat_super->reservedsectors + fat_super->fatsize * fat_super->numberoffats) * fat_super->bytespersector) / ct.blocksize;
    ct.disksize = (fat_super->totalsectors * fat_super->bytespersector) / ct.blocksize;

    if (((fat_super->reservedsectors + fat_super->fatsize * fat_super->numberoffats) * fat_super->bytespersector) % ct.blocksize != 0)
    {
        printf("Sorry the FAT alignment of this disk SUCKS!!!");
        exit(1);
    }

    if (ct.blocksize > (fat_super->bytespersector * fat_super->sectorspercluster))
    {
        printf("The new Block Size must be small or equal to the original Cluster Size.");
        exit(1);
    }

    printf("\n\rConversion Settings:\n\r");
    printf("    Block Size         : %i bytes\n\r", ct.blocksize);
    printf("    Band Size          : %i blocks\n\r", ct.bandsize);
    printf("    Sector Size        : %i bytes\n\r", ct.sectorsize);
    printf("    Cluster Size       : %i blocks\n\r", ct.clustersize);
    printf("    FAT Metadata Size  : %i blocks\n\r", ct.fatmetadata);
    printf("    TriFS Metadata Size: %i blocks\n\r", ct.trifsmetadata);
    printf("    Disk Size          : %i blocks\n\r", ct.disksize);

    printf("\n\rConverting File System:\n\r");

    printf("    Loading FAT\n\r");

    fat_buffer = malloc(fat_super->fatsize * fat_super->bytespersector);
    disk_read(disk, fat_buffer, fat_super->reservedsectors, fat_super->fatsize);
    
    /* Build the FAT Bitmap, by reserving the FAT Meta Data and the allocated *
     * freestore.                                                             */
    printf("    Building FAT Bitmap\n\r");

    diskbitmapsize = ((fat_super->totalsectors * fat_super->bytespersector) / ct.blocksize + 7) / 8;
    fat_bitmap = malloc(diskbitmapsize);
    memset(fat_bitmap, 0, diskbitmapsize);
    
    for (i = 0; i < ct.fatmetadata; i++)
    {
        bitset(fat_bitmap, i);
    }

    for (i = 0; i < (fat_super->fatsize * fat_super->bytespersector) / 4; i++)
    {
        if (fat_buffer[i] != 0)
        {
            for (j = 0; j < ct.clustersize; j++)
            {
                bitset(fat_bitmap, i * ct.clustersize + j);
            }
        }
    }

    /* Build the TriFS Bitmap, by reserving the TriFS Meta Data.              */
    printf("    Building TriFS Bitmap\n\r");

    trifs_bitmap = malloc(diskbitmapsize);
    memset(trifs_bitmap, 0, diskbitmapsize);

    for (i = 0; i < ct.disksize; i += ct.bandsize)
    {
        for (j = 0; j < ct.trifsmetadata; j++)
        {
            bitset(trifs_bitmap, i + j);
        }
    }

    printf("    Moving Conflicting Clusters\n\r");


    disk->blocksize = ct.blocksize;
    buffer = malloc(ct.clustersize * ct.blocksize);

    for (i = 0; i < ct.disksize; i++)
    {
        if (bitget(trifs_bitmap, i) && bitget(fat_bitmap, i) && block2cluster(i) != 0)
        {
            printf("        %i (%i) ", i, block2cluster(i));

            for (j = 0; j < (fat_super->fatsize * fat_super->bytespersector) / 4; j++)
            {
                if (fat_buffer[j] == 0)
                {
                    printf("=> %i (%i)\n\r", j, cluster2block(j));
                    
                    disk_read(disk, buffer, i, ct.clustersize);
                    disk_write(disk, buffer, cluster2block(j), ct.clustersize);

                    for (k = 0; k < (fat_super->fatsize * fat_super->bytespersector) / 4; k++)
                    {
                        if (fat_buffer[k] == block2cluster(i))
                        {
                            fat_buffer[k] = j;
                            break;
                        }
                    }

                    fat_buffer[j] = block2cluster(i);

                    break;
                }
            }
        }
    }

    printf("    Building Directory Structure\n\r");

    fat_builddirectory(disk, fat_super->rootcluster, ":", 0);

    printf("    Updating Metadata\n\r");

    debugfile = fopen("c:\\fat.bitmap.dump", "wb");
    fwrite(fat_bitmap, diskbitmapsize, 1, debugfile);
    fclose(debugfile);

    debugfile = fopen("c:\\trifs.bitmap.dump", "wb");
    fwrite(trifs_bitmap, diskbitmapsize, 1, debugfile);
    fclose(debugfile);
    
    
    return 0;
}
Exemplo n.º 19
0
static
void *
disk_init(int slot, int argc, char *argv[])
{
    struct disk_data *dd;
    const char *filename = NULL;
    off_t size;
    uint32_t totsectors=0;
    uint32_t rpm = 3600;
    int i, paranoid=0, usedoom = 1;

    for (i=1; i<argc; i++) {
        if (!strncmp(argv[i], "rpm=", 4)) {
            rpm = atoi(argv[i]+4);
        }
        else if (!strncmp(argv[i], "sectors=", 8)) {
            totsectors = atoi(argv[i]+8);
        }
        else if (!strncmp(argv[i], "size=", 5)) {
            size = getsize(argv[i]+5);
            if (size % SECTSIZE) {
                msg("disk: slot %d: Configured size is not a "
                    "unit number of sectors", slot);
                die();
            }
            totsectors = size / SECTSIZE;
        }
        else if (!strncmp(argv[i], "file=", 5)) {
            filename = argv[i]+5;
        }
        else if (!strcmp(argv[i], "paranoid")) {
            paranoid = 1;
        }
        else if (!strcmp(argv[i], "doom")) {
            usedoom = 1;
        }
        else if (!strcmp(argv[i], "nodoom")) {
            usedoom = 0;
        }
        else {
            msg("disk: slot %d: invalid option %s", slot, argv[i]);
            die();
        }
    }

    if (rpm < 60) {
        msg("disk: slot %d: RPM too low (%d)", slot, rpm);
        die();
    }
    if (rpm % 60) {
        msg("disk: slot %d: RPM %d not a multiple of 60", slot, rpm);
        die();
    }

    if (filename==NULL) {
        msg("disk: slot %d: No filename specified", slot);
        die();
    }

    /*
     * Set up the disk
     */

    dd = domalloc(sizeof(struct disk_data));

    dd->dd_slot = slot;

    dd->dd_fd = -1;
    dd->dd_paranoid = paranoid;

    dd->dd_sectors = NULL;
    dd->dd_tracks = 0;
    dd->dd_totsectors = 0;
    dd->dd_rpm = rpm;
    dd->dd_nsecs_per_rev = 1000000000 / (dd->dd_rpm / 60);

    dd->dd_usedoom = usedoom;

    dd->dd_current_track = 0;
    clock_time(&dd->dd_trackarrival_secs, &dd->dd_trackarrival_nsecs);
    dd->dd_iostatus = -1;
    dd->dd_timedop = 0;

    dd->dd_worktries = 0;

    dd->dd_stat = DISKSTAT_IDLE;
    dd->dd_sect = 0;

    dd->dd_buf = domalloc(SECTSIZE);

    disk_open(dd, filename, totsectors);
    if (dd->dd_totsectors != totsectors && totsectors > 0) {
        msg("disk: slot %d: %s: Wrong configured size %u (%uK)",
            slot, filename, totsectors,
            totsectors * 1024 / SECTSIZE);
        msg("disk: slot %d: %s: Using image size %u (%uK)",
            slot, filename, dd->dd_totsectors,
            dd->dd_totsectors * 1024 / SECTSIZE);
    }

    if (dd->dd_totsectors < 128) {
        msg("disk: slot %d: %s: Too small", slot, filename);
        die();
    }

    /* set dd_cylinders, dd_sectors, dd_heads */
    if (compute_sectors(dd)) {
        msg("disk: slot %d: %s: Geometry initialization failed "
            "(try another size)", slot, filename);
        die();
    }

    return dd;
}
Exemplo n.º 20
0
static bool format_setup(void)
{
  struct device **devices = 0;
  struct device **p = 0;
  int n = 0;
  int size = 128;
  int i = 0;
  int j = 0;

  if((devices = device_probe_all(true)) == 0)
    return false;

  targets = malloc0(size * sizeof(struct format *));

  for( p = devices ; *p != 0 ; ++p )
  {
    struct device *device = *p;
    struct disk *disk = disk_open(device);
    struct format *target = 0;
    char buf[PATH_MAX] = {0};
 
    if(disk == 0)
    {
      target = malloc0(sizeof(struct format));
    
      add_target(target,&n,&size);
    
      target->devicepath = strdup(device_get_path(device));
      
      size_to_string(buf,PATH_MAX,device_get_size(device),true);
    
      target->size = strdup(buf);
    
      probe_filesystem(target);
    }
    else
    {
      for( i = 0, j = disk_partition_get_count(disk) ; i < j ; ++i )
      {
        const char *purpose = disk_partition_get_purpose(disk,i);
      
        if(
          strcmp(purpose,"data") != 0 && 
          strcmp(purpose,"swap") != 0 && 
          strcmp(purpose,"efi")  != 0
        )
          continue;
        
        target = malloc0(sizeof(struct format));
      
        add_target(target,&n,&size);
      
        snprintf(buf,PATH_MAX,"%s%d",device_get_path(device),disk_partition_get_number(disk,i));
        
        target->devicepath = strdup(buf);
        
        size_to_string(buf,PATH_MAX,disk_partition_get_size(disk,i),true);
        
        target->size = strdup(buf);
        
        probe_filesystem(target);
      }
    }
    
    device_close(device);
  }

  free(devices);

  targets = realloc(targets,(n + 1) * sizeof(struct format *));

  return true;
}
Exemplo n.º 21
0
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;
}