int main(int argc, char **argv) { int i,disk; struct DEVICEPARAMS dp; if (argc == 2) disk = atoi(argv[1]); else disk = get_drive(); printf("\nDrive %c:\n",disk+'A'); if ((i = disk_getparams(disk,&dp)) != DISK_OK) { lib_error("get",i); } else { #ifdef _WIN32 #if defined __WATCOMC__ && __WATCOMC__ >= 1100 if (dp.total_sectors > MAX_FAT16_SECS) printf("drive size %Lu\n",disk_size32(&dp)); /* Microsoft %? */ else #endif #endif printf("drive size %lu\n",disk_size(&dp)); display(&dp); } return 0; }
void device_unload_mess_cd(mess_image *image) { struct mess_cd *cd = get_drive(image); assert(cd->cdrom_handle); cdrom_close(cd->cdrom_handle); cd->cdrom_handle = NULL; }
static int internal_load_mess_cd(mess_image *image, const char *metadata) { chd_error err = 0; struct mess_cd *cd; chd_file *chd; int id = image_index_in_device(image); cd = get_drive(image); /* open the CHD file */ err = chdcd_open_ref(image, CHD_OPEN_READ, NULL, &chd); /* CDs are never writable */ if (err) goto error; /* open the CD-ROM file */ cd->cdrom_handle = cdrom_open(chd); if (!cd->cdrom_handle) goto error; drive_handles[id] = cd->cdrom_handle; return INIT_PASS; error: if (chd) chd_close(chd); if (err) image_seterror(image, IMAGE_ERROR_UNSPECIFIED, chd_get_error_string(err)); return INIT_FAIL; }
void device_unload_mess_hd(mess_image *image) { struct mess_hd *hd = get_drive(image); assert(hd->hard_disk_handle); hard_disk_close(hd->hard_disk_handle); hd->hard_disk_handle = NULL; drive_handles[image_index_in_device(image)] = NULL; }
static int internal_load_mess_hd(mess_image *image, const char *metadata) { int err = 0; struct mess_hd *hd; chd_file *chd; int is_writeable; int id = image_index_in_device(image); hd = get_drive(image); /* open the CHD file */ do { is_writeable = image_is_writable(image); chd = chd_open_ref(image, is_writeable, NULL); if (!chd) { err = chd_get_last_error(); /* special case; if we get CHDERR_FILE_NOT_WRITEABLE, make the * image read only and repeat */ if (err == CHDERR_FILE_NOT_WRITEABLE) image_make_readonly(image); } } while(!chd && is_writeable && (err == CHDERR_FILE_NOT_WRITEABLE)); if (!chd) goto error; /* if we created the image and hence, have metadata to set, set the metadata */ if (metadata) { err = chd_set_metadata(chd, HARD_DISK_STANDARD_METADATA, 0, metadata, strlen(metadata) + 1); if (err != CHDERR_NONE) goto error; } /* open the hard disk file */ hd->hard_disk_handle = hard_disk_open(chd); if (!hd->hard_disk_handle) goto error; drive_handles[id] = hd->hard_disk_handle; return INIT_PASS; error: if (chd) chd_close(chd); err = chd_get_last_error(); if (err) image_seterror(image, IMAGE_ERROR_UNSPECIFIED, chd_get_error_string(err)); return INIT_FAIL; }
int DirAccess::get_current_drive() { String path = get_current_dir().to_lower(); for(int i=0;i<get_drive_count();i++) { String d = get_drive(i).to_lower(); if (path.begins_with(d)) return i; } return 0; }
static int common_dos_loop(MainParam_t *mp, const char *pathname, lookupState_t *lookupState, int open_mode) { Stream_t *RootDir; char *cwd; char *drive; char *rest; int ret; mp->loop = _dos_loop; drive='\0'; cwd = ""; if((rest = skip_drive(pathname)) > pathname) { drive = get_drive(pathname, NULL); if (strncmp(pathname, mp->mcwd, rest - pathname) == 0) cwd = skip_drive(mp->mcwd); pathname = rest; } else { drive = get_drive(mp->mcwd, NULL); cwd = skip_drive(mp->mcwd); } if(*pathname=='/') /* absolute path name */ cwd = ""; RootDir = mp->File = open_root_dir(drive, open_mode); if(!mp->File) return ERROR_ONE; ret = recurs_dos_loop(mp, cwd, pathname, lookupState); if(ret & NO_CWD) { /* no CWD */ *mp->mcwd = '\0'; unlink_mcwd(); ret = recurs_dos_loop(mp, "", pathname, lookupState); } FREE(&RootDir); return ret; }
void mcat(int argc, char **argv, int type) { struct device *dev; struct device out_dev; char *drive, name[EXPAND_BUF]; char errmsg[200]; Stream_t *Stream; char buf[BUF_SIZE]; mt_off_t address = 0; char mode = O_RDONLY; int optindex = 1; size_t len; noPrivileges = 1; if (argc < 2) { usage(); } if (argv[1][0] == '-') { if (argv[1][1] != 'w') { usage(); } mode = O_WRONLY; optindex++; } if (argc - optindex < 1) usage(); if (skip_drive(argv[optindex]) == argv[optindex]) usage(); drive = get_drive(argv[optindex], NULL); /* check out a drive whose letter and parameters match */ sprintf(errmsg, "Drive '%s:' not supported", drive); Stream = NULL; for (dev=devices; dev->name; dev++) { FREE(&Stream); if (strcmp(dev->drive, drive) != 0) continue; out_dev = *dev; expand(dev->name,name); #ifdef USING_NEW_VOLD strcpy(name, getVoldName(dev, name)); #endif Stream = 0; #ifdef USE_XDF Stream = XdfOpen(&out_dev, name, mode, errmsg, 0); if(Stream) out_dev.use_2m = 0x7f; #endif #ifdef USE_FLOPPYD if(!Stream) Stream = FloppydOpen(&out_dev, dev, name, mode, errmsg, 0, 1); #endif if (!Stream) Stream = SimpleFileOpen(&out_dev, dev, name, mode, errmsg, 0, 1, 0); if( !Stream) continue; break; } /* print error msg if needed */ if ( dev->drive == 0 ) { FREE(&Stream); fprintf(stderr,"%s\n",errmsg); exit(1); } if (mode == O_WRONLY) { while ((len = fread(buf, 1, BUF_SIZE, stdin)) == BUF_SIZE) { WRITES(Stream, buf, address, BUF_SIZE); address += BUF_SIZE; } if (len) WRITES(Stream, buf, address, len); } else { while ((len = READS(Stream, buf, address, BUF_SIZE)) == BUF_SIZE) { fwrite(buf, 1, BUF_SIZE, stdout); address += BUF_SIZE; } if (len) fwrite(buf, 1, len, stdout); } FREE(&Stream); exit(0); }
hard_disk_file *mess_hd_get_hard_disk_file(mess_image *image) { struct mess_hd *hd = get_drive(image); return hd->hard_disk_handle; }
cdrom_file *mess_cd_get_cdrom_file(mess_image *image) { struct mess_cd *cd = get_drive(image); return cd->cdrom_handle; }
void minfo(int argc, char **argv, int type) { struct bootsector boot0; #define boot (&boot0) char name[EXPAND_BUF]; int media; int tot_sectors; struct device dev; char *drive; int verbose=0; int c; Stream_t *Stream; struct label_blk_t *labelBlock; while ((c = getopt(argc, argv, "v")) != EOF) { switch (c) { case 'v': verbose = 1; break; default: usage(); } } if(argc == optind) usage(); for(;optind < argc; optind++) { if(skip_drive(argv[optind]) == argv[optind]) usage(); drive = get_drive(argv[optind], NULL); if(! (Stream = find_device(drive, O_RDONLY, &dev, boot, name, &media, 0))) exit(1); tot_sectors = DWORD(bigsect); SET_INT(tot_sectors, WORD(psect)); printf("device information:\n"); printf("===================\n"); printf("filename=\"%s\"\n", name); printf("sectors per track: %d\n", dev.sectors); printf("heads: %d\n", dev.heads); printf("cylinders: %d\n\n", dev.tracks); printf("mformat command line: mformat -t %d -h %d -s %d ", dev.tracks, dev.heads, dev.sectors); if(DWORD(nhs)) printf("-H %d ", DWORD(nhs)); printf("%s:\n", drive); printf("\n"); printf("bootsector information\n"); printf("======================\n"); printf("banner:\"%8s\"\n", boot->banner); printf("sector size: %d bytes\n", WORD(secsiz)); printf("cluster size: %d sectors\n", boot->clsiz); printf("reserved (boot) sectors: %d\n", WORD(nrsvsect)); printf("fats: %d\n", boot->nfat); printf("max available root directory slots: %d\n", WORD(dirents)); printf("small size: %d sectors\n", WORD(psect)); printf("media descriptor byte: 0x%x\n", boot->descr); printf("sectors per fat: %d\n", WORD(fatlen)); printf("sectors per track: %d\n", WORD(nsect)); printf("heads: %d\n", WORD(nheads)); printf("hidden sectors: %d\n", DWORD(nhs)); printf("big size: %d sectors\n", DWORD(bigsect)); if(WORD(fatlen)) { labelBlock = &boot->ext.old.labelBlock; } else { labelBlock = &boot->ext.fat32.labelBlock; } printf("physical drive id: 0x%x\n", labelBlock->physdrive); printf("reserved=0x%x\n", labelBlock->reserved); printf("dos4=0x%x\n", labelBlock->dos4); printf("serial number: %08X\n", _DWORD(labelBlock->serial)); printf("disk label=\"%11.11s\"\n", labelBlock->label); printf("disk type=\"%8.8s\"\n", labelBlock->fat_type); if(!WORD(fatlen)){ printf("Big fatlen=%u\n", DWORD(ext.fat32.bigFat)); printf("Extended flags=0x%04x\n", WORD(ext.fat32.extFlags)); printf("FS version=0x%04x\n", WORD(ext.fat32.fsVersion)); printf("rootCluster=%u\n", DWORD(ext.fat32.rootCluster)); if(WORD(ext.fat32.infoSector) != MAX32) printf("infoSector location=%d\n", WORD(ext.fat32.infoSector)); if(WORD(ext.fat32.backupBoot) != MAX32) printf("backup boot sector=%d\n", WORD(ext.fat32.backupBoot)); displayInfosector(Stream,boot); } if(verbose) { int size; unsigned char *buf; printf("\n"); size = WORD(secsiz); buf = (unsigned char *) malloc(size); if(!buf) { fprintf(stderr, "Out of memory error\n"); exit(1); } size = READS(Stream, buf, (mt_off_t) 0, size); if(size < 0) { perror("read boot sector"); exit(1); } print_sector("Boot sector hexdump", buf, size); } } exit(0); }