void updatexfers(int numdevs, int *devs) { register int i, j, t; struct statinfo stats; int num_devices = 0; u_int64_t total_transfers; if ((num_devices = getnumdevs()) < 0) { syslog(LOG_ERR, "rstatd: can't get number of devices: %s", devstat_errbuf); exit(1); } if (checkversion() < 0) { syslog(LOG_ERR, "rstatd: %s", devstat_errbuf); exit(1); } stats.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo)); bzero(stats.dinfo, sizeof(struct devinfo)); if (getdevs(&stats) == -1) { syslog(LOG_ERR, "rstatd: can't get device list: %s", devstat_errbuf); exit(1); } for (i = 0, j = 0; i < stats.dinfo->numdevs && j < numdevs; i++) { if (((stats.dinfo->devices[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_DIRECT) && ((stats.dinfo->devices[i].device_type & DEVSTAT_TYPE_PASS) == 0)) { total_transfers = stats.dinfo->devices[i].num_reads + stats.dinfo->devices[i].num_writes + stats.dinfo->devices[i].num_other; /* * XXX KDM If the total transfers for this device * are greater than the amount we can fit in a * signed integer, just set them to the maximum * amount we can fit in a signed integer. I have a * feeling that the rstat protocol assumes 32-bit * integers, so this could well break on a 64-bit * architecture like the Alpha. */ if (total_transfers > INT_MAX) t = INT_MAX; else t = total_transfers; devs[j] = t; j++; } } if (stats.dinfo->mem_ptr) free(stats.dinfo->mem_ptr); free(stats.dinfo); }
/* * returns true if have a disk */ int haveadisk(void) { register int i; struct statinfo stats; int num_devices, retval = 0; if ((num_devices = getnumdevs()) < 0) { syslog(LOG_ERR, "rstatd: can't get number of devices: %s", devstat_errbuf); exit(1); } if (checkversion() < 0) { syslog(LOG_ERR, "rstatd: %s", devstat_errbuf); exit(1); } stats.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo)); bzero(stats.dinfo, sizeof(struct devinfo)); if (getdevs(&stats) == -1) { syslog(LOG_ERR, "rstatd: can't get device list: %s", devstat_errbuf); exit(1); } for (i = 0; i < stats.dinfo->numdevs; i++) { if (((stats.dinfo->devices[i].device_type & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_DIRECT) && ((stats.dinfo->devices[i].device_type & DEVSTAT_TYPE_PASS) == 0)) { retval = 1; break; } } if (stats.dinfo->mem_ptr) free(stats.dinfo->mem_ptr); free(stats.dinfo); return(retval); }
int main(int argc, char **argv) { int c, todo; u_int interval; /* milliseconds */ int reps; char *memf, *nlistf; char errbuf[_POSIX2_LINE_MAX]; memf = nlistf = NULL; interval = reps = todo = 0; maxshowdevs = 2; while ((c = getopt(argc, argv, "c:fiM:mN:n:p:stvw:z")) != -1) { switch (c) { case 'c': reps = atoi(optarg); break; case 'f': #ifdef notyet todo |= FORKSTAT; #else errx(EX_USAGE, "sorry, -f is not (re)implemented yet"); #endif break; case 'i': todo |= INTRSTAT; break; case 'M': memf = optarg; break; case 'm': todo |= MEMSTAT; break; case 'N': nlistf = optarg; break; case 'n': nflag = 1; maxshowdevs = atoi(optarg); if (maxshowdevs < 0) errx(1, "number of devices %d is < 0", maxshowdevs); break; case 'p': if (buildmatch(optarg, &matches, &num_matches) != 0) errx(1, "%s", devstat_errbuf); break; case 's': todo |= SUMSTAT; break; case 't': #ifdef notyet todo |= TIMESTAT; #else errx(EX_USAGE, "sorry, -t is not (re)implemented yet"); #endif break; case 'v': ++verbose; break; case 'w': interval = (u_int)(strtod(optarg, NULL) * 1000.0); break; case 'z': todo |= ZMEMSTAT; break; default: usage(); } } argc -= optind; argv += optind; if (todo == 0) todo = VMSTAT; /* * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. */ if (nlistf != NULL || memf != NULL) setgid(getgid()); kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf); if (kd == NULL) errx(1, "kvm_openfiles: %s", errbuf); if ((c = kvm_nlist(kd, namelist)) != 0) { if (c > 0) { warnx("undefined symbols:"); for (c = 0; c < (int)__arysize(namelist); c++) if (namelist[c].n_type == 0) fprintf(stderr, " %s", namelist[c].n_name); fputc('\n', stderr); } else warnx("kvm_nlist: %s", kvm_geterr(kd)); exit(1); } if (todo & VMSTAT) { struct winsize winsize; /* * Make sure that the userland devstat version matches the * kernel devstat version. If not, exit and print a * message informing the user of his mistake. */ if (checkversion() < 0) errx(1, "%s", devstat_errbuf); argv = getdrivedata(argv); winsize.ws_row = 0; ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&winsize); if (winsize.ws_row > 0) winlines = winsize.ws_row; } #define BACKWARD_COMPATIBILITY #ifdef BACKWARD_COMPATIBILITY if (*argv) { interval = (u_int)(strtod(*argv, NULL) * 1000.0); if (*++argv) reps = atoi(*argv); } #endif if (interval) { if (!reps) reps = -1; } else if (reps) { interval = 1000; } #ifdef notyet if (todo & FORKSTAT) doforkst(); #endif if (todo & MEMSTAT) domem(); if (todo & ZMEMSTAT) dozmem(); if (todo & SUMSTAT) dosum(); #ifdef notyet if (todo & TIMESTAT) dotimes(); #endif if (todo & INTRSTAT) dointr(); if (todo & VMSTAT) dovmstat(interval, reps); exit(0); }
/* Overly complex function that builds a .deb file */ void do_build(const char *const *argv) { static const char *const maintainerscripts[]= { PREINSTFILE, POSTINSTFILE, PRERMFILE, POSTRMFILE, NULL }; char *m; const char *debar, *directory, *const *mscriptp, *versionstring, *arch; char *controlfile, *tfbuf; const char *envbuf; struct pkginfo *checkedinfo; struct arbitraryfield *field; FILE *ar, *cf; int p1[2],p2[2],p3[2], warns, errs, n, c, subdir, gzfd; pid_t c1,c2,c3; struct stat controlstab, datastab, mscriptstab, debarstab; char conffilename[MAXCONFFILENAME+1]; time_t thetime= 0; struct file_info *fi; struct file_info *symlist = NULL; struct file_info *symlist_end = NULL; /* Decode our arguments */ directory = *argv++; if (!directory) badusage(_("--%s needs a <directory> argument"), cipaction->olong); /* template for our tempfiles */ if ((envbuf= getenv("TMPDIR")) == NULL) envbuf= P_tmpdir; tfbuf = m_malloc(strlen(envbuf) + 13); strcpy(tfbuf,envbuf); strcat(tfbuf,"/dpkg.XXXXXX"); subdir= 0; debar = *argv++; if (debar != NULL) { if (*argv) badusage(_("--build takes at most two arguments")); if (debar) { if (stat(debar,&debarstab)) { if (errno != ENOENT) ohshite(_("unable to check for existence of archive `%.250s'"),debar); } else if (S_ISDIR(debarstab.st_mode)) { subdir= 1; } } } else { m= m_malloc(strlen(directory) + sizeof(DEBEXT)); strcpy(m, directory); path_rtrim_slash_slashdot(m); strcat(m, DEBEXT); debar= m; } /* Perform some sanity checks on the to-be-build package. */ if (nocheckflag) { if (subdir) ohshit(_("target is directory - cannot skip control file check")); warning(_("not checking contents of control area.")); printf(_("dpkg-deb: building an unknown package in '%s'.\n"), debar); } else { controlfile= m_malloc(strlen(directory) + sizeof(BUILDCONTROLDIR) + sizeof(CONTROLFILE) + sizeof(CONFFILESFILE) + sizeof(POSTINSTFILE) + sizeof(PREINSTFILE) + sizeof(POSTRMFILE) + sizeof(PRERMFILE) + MAXCONFFILENAME + 5); /* Lets start by reading in the control-file so we can check its contents */ strcpy(controlfile, directory); strcat(controlfile, "/" BUILDCONTROLDIR "/" CONTROLFILE); warns= 0; errs= 0; parsedb(controlfile, pdb_recordavailable|pdb_rejectstatus, &checkedinfo, stderr, &warns); assert(checkedinfo->available.valid); if (strspn(checkedinfo->name, "abcdefghijklmnopqrstuvwxyz0123456789+-.") != strlen(checkedinfo->name)) ohshit(_("package name has characters that aren't lowercase alphanums or `-+.'")); if (checkedinfo->priority == pri_other) { warning(_("'%s' contains user-defined Priority value '%s'"), controlfile, checkedinfo->otherpriority); warns++; } for (field= checkedinfo->available.arbs; field; field= field->next) { if (known_arbitrary_field(field)) continue; warning(_("'%s' contains user-defined field '%s'"), controlfile, field->name); warns++; } checkversion(checkedinfo->available.version.version, _("(upstream) version"), &errs); checkversion(checkedinfo->available.version.revision, _("Debian revision"), &errs); if (errs) ohshit(_("%d errors in control file"),errs); if (subdir) { versionstring= versiondescribe(&checkedinfo->available.version,vdew_never); arch= checkedinfo->available.architecture; if (!arch) arch= ""; m= m_malloc(sizeof(DEBEXT)+1+strlen(debar)+1+strlen(checkedinfo->name)+ strlen(versionstring)+1+strlen(arch)); sprintf(m,"%s/%s_%s%s%s" DEBEXT,debar,checkedinfo->name,versionstring, arch[0] ? "_" : "", arch); debar= m; } printf(_("dpkg-deb: building package `%s' in `%s'.\n"), checkedinfo->name, debar); /* Check file permissions */ strcpy(controlfile, directory); strcat(controlfile, "/" BUILDCONTROLDIR "/"); if (lstat(controlfile, &mscriptstab)) ohshite(_("unable to stat control directory")); if (!S_ISDIR(mscriptstab.st_mode)) ohshit(_("control directory is not a directory")); if ((mscriptstab.st_mode & 07757) != 0755) ohshit(_("control directory has bad permissions %03lo (must be >=0755 " "and <=0775)"), (unsigned long)(mscriptstab.st_mode & 07777)); for (mscriptp= maintainerscripts; *mscriptp; mscriptp++) { strcpy(controlfile, directory); strcat(controlfile, "/" BUILDCONTROLDIR "/"); strcat(controlfile, *mscriptp); if (!lstat(controlfile,&mscriptstab)) { if (S_ISLNK(mscriptstab.st_mode)) continue; if (!S_ISREG(mscriptstab.st_mode)) ohshit(_("maintainer script `%.50s' is not a plain file or symlink"),*mscriptp); if ((mscriptstab.st_mode & 07557) != 0555) ohshit(_("maintainer script `%.50s' has bad permissions %03lo " "(must be >=0555 and <=0775)"), *mscriptp, (unsigned long)(mscriptstab.st_mode & 07777)); } else if (errno != ENOENT) { ohshite(_("maintainer script `%.50s' is not stattable"),*mscriptp); } } /* Check if conffiles contains sane information */ strcpy(controlfile, directory); strcat(controlfile, "/" BUILDCONTROLDIR "/" CONFFILESFILE); if ((cf= fopen(controlfile,"r"))) { struct file_info *conffiles_head = NULL; struct file_info *conffiles_tail = NULL; while (fgets(conffilename,MAXCONFFILENAME+1,cf)) { n= strlen(conffilename); if (!n) ohshite(_("empty string from fgets reading conffiles")); if (conffilename[n-1] != '\n') { warning(_("conffile name '%.50s...' is too long, or missing final newline"), conffilename); warns++; while ((c= getc(cf)) != EOF && c != '\n'); continue; } conffilename[n - 1] = '\0'; strcpy(controlfile, directory); strcat(controlfile, "/"); strcat(controlfile, conffilename); if (lstat(controlfile,&controlstab)) { if (errno == ENOENT) { if((n > 1) && isspace(conffilename[n-2])) warning(_("conffile filename '%s' contains trailing white spaces"), conffilename); ohshit(_("conffile `%.250s' does not appear in package"), conffilename); } else ohshite(_("conffile `%.250s' is not stattable"), conffilename); } else if (!S_ISREG(controlstab.st_mode)) { warning(_("conffile '%s' is not a plain file"), conffilename); warns++; } if (file_info_find_name(conffiles_head, conffilename)) warning(_("conffile name '%s' is duplicated"), conffilename); else { struct file_info *conffile; conffile = file_info_new(conffilename); add_to_filist(&conffiles_head, &conffiles_tail, conffile); } } free_filist(conffiles_head); if (ferror(cf)) ohshite(_("error reading conffiles file")); fclose(cf); } else if (errno != ENOENT) { ohshite(_("error opening conffiles file")); } if (warns) warning(_("ignoring %d warnings about the control file(s)\n"), warns); } m_output(stdout, _("<standard output>")); /* Now that we have verified everything its time to actually * build something. Lets start by making the ar-wrapper. */ if (!(ar=fopen(debar,"wb"))) ohshite(_("unable to create `%.255s'"),debar); if (setvbuf(ar, NULL, _IONBF, 0)) ohshite(_("unable to unbuffer `%.255s'"), debar); /* Fork a tar to package the control-section of the package */ unsetenv("TAR_OPTIONS"); m_pipe(p1); if (!(c1= m_fork())) { m_dup2(p1[1],1); close(p1[0]); close(p1[1]); if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory); if (chdir(BUILDCONTROLDIR)) ohshite(_("failed to chdir to .../DEBIAN")); execlp(TAR, "tar", "-cf", "-", "--format=gnu", ".", NULL); ohshite(_("failed to exec tar -cf")); } close(p1[1]); /* Create a temporary file to store the control data in. Immediately unlink * our temporary file so others can't mess with it. */ if ((gzfd= mkstemp(tfbuf)) == -1) ohshite(_("failed to make tmpfile (control)")); /* make sure it's gone, the fd will remain until we close it */ if (unlink(tfbuf)) ohshit(_("failed to unlink tmpfile (control), %s"), tfbuf); /* reset this, so we can use it elsewhere */ strcpy(tfbuf,envbuf); strcat(tfbuf,"/dpkg.XXXXXX"); /* And run gzip to compress our control archive */ if (!(c2= m_fork())) { m_dup2(p1[0],0); m_dup2(gzfd,1); close(p1[0]); close(gzfd); compress_cat(compress_type_gzip, 0, 1, "9", _("control")); } close(p1[0]); waitsubproc(c2,"gzip -9c",0); waitsubproc(c1,"tar -cf",0); if (fstat(gzfd,&controlstab)) ohshite(_("failed to fstat tmpfile (control)")); /* We have our first file for the ar-archive. Write a header for it to the * package and insert it. */ if (oldformatflag) { if (fprintf(ar, "%-8s\n%ld\n", OLDARCHIVEVERSION, (long)controlstab.st_size) == EOF) werr(debar); } else { thetime = time(NULL); if (fprintf(ar, "!<arch>\n" "debian-binary %-12lu0 0 100644 %-10ld`\n" ARCHIVEVERSION "\n" "%s" ADMINMEMBER "%-12lu0 0 100644 %-10ld`\n", thetime, (long)sizeof(ARCHIVEVERSION), (sizeof(ARCHIVEVERSION)&1) ? "\n" : "", (unsigned long)thetime, (long)controlstab.st_size) == EOF) werr(debar); } if (lseek(gzfd,0,SEEK_SET)) ohshite(_("failed to rewind tmpfile (control)")); fd_fd_copy(gzfd, fileno(ar), -1, _("control")); /* Control is done, now we need to archive the data. Start by creating * a new temporary file. Immediately unlink the temporary file so others * can't mess with it. */ if (!oldformatflag) { close(gzfd); if ((gzfd= mkstemp(tfbuf)) == -1) ohshite(_("failed to make tmpfile (data)")); /* make sure it's gone, the fd will remain until we close it */ if (unlink(tfbuf)) ohshit(_("failed to unlink tmpfile (data), %s"), tfbuf); /* reset these, in case we want to use the later */ strcpy(tfbuf,envbuf); strcat(tfbuf,"/dpkg.XXXXXX"); } /* Fork off a tar. We will feed it a list of filenames on stdin later. */ m_pipe(p1); m_pipe(p2); if (!(c1= m_fork())) { m_dup2(p1[0],0); close(p1[0]); close(p1[1]); m_dup2(p2[1],1); close(p2[0]); close(p2[1]); if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory); execlp(TAR, "tar", "-cf", "-", "--format=gnu", "--null", "-T", "-", "--no-recursion", NULL); ohshite(_("failed to exec tar -cf")); } close(p1[0]); close(p2[1]); /* Of course we should not forget to compress the archive as well.. */ if (!(c2= m_fork())) { close(p1[1]); m_dup2(p2[0],0); close(p2[0]); m_dup2(oldformatflag ? fileno(ar) : gzfd,1); compress_cat(compress_type, 0, 1, compression, _("data")); } close(p2[0]); /* All the pipes are set, now lets run find, and start feeding * filenames to tar. */ m_pipe(p3); if (!(c3= m_fork())) { m_dup2(p3[1],1); close(p3[0]); close(p3[1]); if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory); execlp(FIND, "find", ".", "-path", "./" BUILDCONTROLDIR, "-prune", "-o", "-print0", NULL); ohshite(_("failed to exec find")); } close(p3[1]); /* We need to reorder the files so we can make sure that symlinks * will not appear before their target. */ while ((fi=getfi(directory, p3[0]))!=NULL) if (S_ISLNK(fi->st.st_mode)) add_to_filist(&symlist, &symlist_end, fi); else { if (write(p1[1], fi->fn, strlen(fi->fn)+1) ==- 1) ohshite(_("failed to write filename to tar pipe (data)")); } close(p3[0]); waitsubproc(c3,"find",0); for (fi= symlist;fi;fi= fi->next) if (write(p1[1], fi->fn, strlen(fi->fn)+1) == -1) ohshite(_("failed to write filename to tar pipe (data)")); /* All done, clean up wait for tar and gzip to finish their job */ close(p1[1]); free_filist(symlist); waitsubproc(c2, _("<compress> from tar -cf"), 0); waitsubproc(c1,"tar -cf",0); /* Okay, we have data.tar.gz as well now, add it to the ar wrapper */ if (!oldformatflag) { const char *datamember; switch (compress_type) { case compress_type_gzip: datamember = DATAMEMBER_GZ; break; case compress_type_bzip2: datamember = DATAMEMBER_BZ2; break; case compress_type_lzma: datamember = DATAMEMBER_LZMA; break; case compress_type_cat: datamember = DATAMEMBER_CAT; break; default: internerr("unkown compress_type '%i'", compress_type); } if (fstat(gzfd, &datastab)) ohshite(_("failed to fstat tmpfile (data)")); if (fprintf(ar, "%s" "%s" "%-12lu0 0 100644 %-10ld`\n", (controlstab.st_size & 1) ? "\n" : "", datamember, (unsigned long)thetime, (long)datastab.st_size) == EOF) werr(debar); if (lseek(gzfd,0,SEEK_SET)) ohshite(_("failed to rewind tmpfile (data)")); fd_fd_copy(gzfd, fileno(ar), -1, _("cat (data)")); if (datastab.st_size & 1) if (putc('\n',ar) == EOF) werr(debar); } if (fclose(ar)) werr(debar); exit(0); }
DWORD WINAPI DumpThreadProc( LPVOID lpParameter) { unsigned int i,j,k,m,n,ret; int l; FD_SCAN_PARAMS sp; FD_SCAN_RESULT *sr; FD_READ_WRITE_PARAMS rwp; FD_CMD_RESULT cmdr; SECTORCONFIG* sectorconfig; floppydumperparams * params; unsigned char * tempstr; unsigned char * trackbuffer; unsigned char b; int tracksize,retry,gap3len,trackformat; unsigned long rotationtime,rpm,bitrate,tracklen; unsigned long total_size,numberofsector_read,number_of_bad_sector; CYLINDER* currentcylinder; SIDE* currentside; params=(floppydumperparams*)lpParameter; params->flopemu->hxc_printf(MSG_DEBUG,"Starting Floppy dump..."); tempstr=(char*)malloc(1024); trackbuffer=0; tracksize=0; if(checkversion()) { if(opendevice(params->drive)) { total_size=0; numberofsector_read=0; number_of_bad_sector=0; sr=malloc(sizeof(FD_ID_HEADER)*256 + 1); params->floppydisk->floppyBitRate=VARIABLEBITRATE; params->floppydisk->floppyNumberOfSide=params->number_of_side; params->floppydisk->floppyNumberOfTrack=params->number_of_track; params->floppydisk->floppySectorPerTrack=-1; seek(0, 0); sprintf(tempstr,"Checking drive RPM..."); SetDlgItemText(params->windowshwd,IDC_EDIT1,tempstr); rotationtime=200000; if (!DeviceIoControl(h, IOCTL_FD_GET_TRACK_TIME, 0, 0, &rotationtime, sizeof(rotationtime), &ret, NULL)) { sprintf(tempstr,"Error during RPM checking :%d ",GetLastError()); SetDlgItemText(params->windowshwd,IDC_EDIT1,tempstr); params->flopemu->hxc_printf(MSG_DEBUG,"Leaving Floppy dump: IOCTL_FD_GET_TRACK_TIME error %d...",GetLastError()); closedevice(); free(tempstr); params->status=0; return 0; } params->floppydisk->tracks=(CYLINDER**)malloc(sizeof(CYLINDER*)*params->floppydisk->floppyNumberOfTrack); rpm=60000/(rotationtime/1000); params->flopemu->hxc_printf(MSG_DEBUG,"Drive RPM: %d",rpm); sprintf(tempstr,"Drive RPM: %d",rpm); SetDlgItemText(params->windowshwd,IDC_EDIT1,tempstr); if(rpm>280 && rpm<320) rpm=300; if(rpm>340 && rpm<380) rpm=360; bitrate=500000; sprintf(tempstr,"Starting reading disk..."); SetDlgItemText(params->windowshwd,IDC_EDIT1,tempstr); for(i=0;i<params->floppydisk->floppyNumberOfTrack;i++) { params->floppydisk->tracks[i]=(CYLINDER*)malloc(sizeof(CYLINDER)); currentcylinder=params->floppydisk->tracks[i]; currentcylinder->number_of_side=params->floppydisk->floppyNumberOfSide; currentcylinder->sides=(SIDE**)malloc(sizeof(SIDE*)*currentcylinder->number_of_side); memset(currentcylinder->sides,0,sizeof(SIDE*)*currentcylinder->number_of_side); for(j=0;j<params->floppydisk->floppyNumberOfSide;j++) { currentcylinder->floppyRPM=rpm; currentcylinder->sides[j]=malloc(sizeof(SIDE)); memset(currentcylinder->sides[j],0,sizeof(SIDE)); currentside=currentcylinder->sides[j]; seek(i*params->double_step, j); l=0; do { m=0; while(tm[m].index!=l) { m++; } memset(sr,0,sizeof(FD_ID_HEADER)*256 + 1); if(tm[m].encoding_mode) { sp.flags=FD_OPTION_MFM; trackformat=ISOFORMAT_DD; } else { sp.flags=0x00; trackformat=ISOFORMAT_SD; } sp.head=j; bitrate=tm[m].bitrate; b = tm[m].bitrate_code; if (!DeviceIoControl(h, IOCTL_FD_SET_DATA_RATE, &b, sizeof b, NULL, 0, &ret, NULL)) { printf("IOCTL_FD_SET_DATA_RATE=%d failed err=%d\n", b, GetLastError()); closedevice(); params->status=0; return 0; } if (!DeviceIoControl(h, IOCTL_FD_SCAN_TRACK, &sp, sizeof sp, sr, sizeof(FD_ID_HEADER)*256 + 1, &ret, NULL)) { params->flopemu->hxc_printf(MSG_DEBUG,"IOCTL_FD_SCAN_TRACK error %d ...",GetLastError()); } if(sr->count) { n=0; while(tm[n].index) { n++; } k=tm[n].index; tm[n].index=tm[m].index; tm[m].index=k; } else { DeviceIoControl(h, IOCTL_FD_RESET, NULL, 0, NULL, 0, &ret, NULL); } l++; }while(l<8 && !sr->count); sectorconfig=(SECTORCONFIG*)malloc(sizeof(SECTORCONFIG)*sr->count); memset(sectorconfig,0,sizeof(SECTORCONFIG)*sr->count); params->flopemu->hxc_printf(MSG_DEBUG,"Track %d side %d: %d sectors found : ",i,j,sr->count); seek(i*params->double_step, j); if( sr->Header[0].cyl==sr->Header[sr->count-1].cyl && sr->Header[0].head==sr->Header[sr->count-1].head && sr->Header[0].sector==sr->Header[sr->count-1].sector && sr->Header[0].size==sr->Header[sr->count-1].size ) { sr->count--; } for(k=0;k<sr->count;k++) { params->flopemu->hxc_printf(MSG_DEBUG,"Sector %.2d, Track ID: %.3d, Head ID:%d, Size: %d bytes, Bitrate:%dkbits/s, %s",sr->Header[k].sector,sr->Header[k].cyl,sr->Header[k].head,128<<sr->Header[k].size,bitrate/1000,trackformat==ISOFORMAT_SD?"FM":"MFM"); if(tm[m].encoding_mode) { rwp.flags=FD_OPTION_MFM; } else { rwp.flags=0x00; } rwp.cyl=sr->Header[k].cyl; rwp.phead=j; rwp.head=sr->Header[k].head; rwp.sector=sr->Header[k].sector; rwp.size=sr->Header[k].size; rwp.eot=sr->Header[k].sector+1; rwp.gap=10; if((128<<sr->Header[k].size)>128) { rwp.datalen=255; } else { rwp.datalen=128; } retry=5; trackbuffer=realloc(trackbuffer,tracksize+(128<<sr->Header[k].size)); do { retry--; }while(!DeviceIoControl(h, IOCTL_FDCMD_READ_DATA, &rwp, sizeof rwp, &trackbuffer[tracksize], 128<<sr->Header[k].size, &ret, NULL) && retry); if(!retry) { DeviceIoControl(h, IOCTL_FD_GET_RESULT,0, 0, &cmdr, sizeof(FD_CMD_RESULT), &ret, NULL); params->flopemu->hxc_printf(MSG_DEBUG,"Read Error ! ST0: %.2x, ST1: %.2x, ST2: %.2x",cmdr.st0,cmdr.st1,cmdr.st2); number_of_bad_sector++; } total_size=total_size+(128<<sr->Header[k].size); numberofsector_read++; sectorconfig[k].cylinder=sr->Header[k].cyl; sectorconfig[k].head=sr->Header[k].head; sectorconfig[k].sector=sr->Header[k].sector; sectorconfig[k].sectorsize=(128<<sr->Header[k].size); tracksize=tracksize+(128<<sr->Header[k].size); sprintf(tempstr,"%d Sector(s) Read, %d bytes, %d Bad sector(s)",numberofsector_read,total_size,number_of_bad_sector); SetDlgItemText(params->windowshwd,IDC_EDIT2,tempstr); } currentside->number_of_sector=sr->count; currentside->bitrate=bitrate; tracklen=(bitrate/(rpm/60))/4; currentside->tracklen=tracklen; currentside->databuffer=malloc(currentside->tracklen); memset(currentside->databuffer,0,currentside->tracklen); currentside->flakybitsbuffer=0; currentside->timingbuffer=0; currentside->indexbuffer=malloc(currentside->tracklen); memset(currentside->indexbuffer,0,currentside->tracklen); fillindex(currentside->tracklen-1,currentside,2500,TRUE,1); gap3len=20; BuildISOTrack(params->flopemu,trackformat,currentside->number_of_sector,1,512,j,i,gap3len,trackbuffer,currentside->databuffer,¤tside->tracklen,0,0,sectorconfig); sprintf(tempstr,"Track %d side %d: %d sectors, %dkbits/s, %s",i,j,sr->count,bitrate/1000,trackformat==ISOFORMAT_SD?"FM":"MFM"); SetDlgItemText(params->windowshwd,IDC_EDIT1,tempstr); free(sectorconfig); free(trackbuffer); trackbuffer=0; tracksize=0; } } closedevice(); sprintf(tempstr,"Done !"); SetDlgItemText(params->windowshwd,IDC_EDIT1,tempstr); sprintf(tempstr,"%d Sector(s) Read, %d bytes, %d Bad sector(s)",numberofsector_read,total_size,number_of_bad_sector); SetDlgItemText(params->windowshwd,IDC_EDIT2,tempstr); params->flopemu->hxc_printf(MSG_DEBUG,"Done ! %d sectors read, %d bad sector(s), %d bytes read",numberofsector_read,number_of_bad_sector,total_size); loadfloppy("Floppy Dump",params->floppydisk,0); free(tempstr); params->flopemu->hxc_printf(MSG_DEBUG,"Leaving Floppy dump..."); params->status=0; return 0; } } sprintf(tempstr,"Error while opening fdrawcmd, see: http://simonowen.com/fdrawcmd"); SetDlgItemText(params->windowshwd,IDC_EDIT1,tempstr); free(tempstr); params->flopemu->hxc_printf(MSG_DEBUG,"Leaving Floppy dump..."); params->status=0; return 0; }