i/o scan disk scheduling using c, c++ or java -
learning system's programming,how can implement scan disk scheduling algorithm using c, c++ or java. requirements piece of code access disk handles. below example of code have been working on, problem merely simulation of taking place when scan disk algorithm running. header position , input data values user inserting program. want able read current header position, , en queue requests , implement scan disk scheduling or other scheduling algorithm
#include<stdio.h> #include<conio.h> #include<math.h> #define max 15 #define cymax 249 int i,j,req,ttl_tracks=0,cp,np,cposn,nposn; int cyposn[max],temp; void input() { { clreol(); printf("\n enter current header position : "); scanf("%d",&cposn); /*cposn current cylinder position in case same current header position*/ }while(cposn>cymax || cposn <=0); printf("\n enter %d i/o requests : ",req); cyposn[0] = cposn; for(i=1;i<=req;i++) /*this loop helps store different requests inputs in array of cylinder positions cyposn: note initial array cyposn stores value of initial header postion , why loop begins 1 */ scanf("%d",&cyposn[i]); } void scan() /*function scanning schedule*/ { int tmp = cp; /*the tmp integer used swapping values, current cylinder position next*/ int ind = 0; for(i=0;i<=req;i++)/*this outer loops counts number of requests*/ { for(j=0;j<req-i;j++) /*this inner loop walks through different values in cylinder array later become sorted */ { if(cyposn[j] > cyposn[j+1])/*compares 2 values previous position , next position, if previous greater next position, positions swapped, taking next position tobecome current position situation ensure current position become small possible: hence handle move left */ { temp = cyposn[j]; cyposn[j] = cyposn[j+1]; cyposn[j+1] = temp; } } } cp=0; /*when loop finishes untill finds minimal value: handle assigned position '0' making current position zero*/ { if(cyposn[cp] == cposn) break; /*if reaches possible maximum cylinder value breaks else increments values*/ cp++; }while(cp!=req); printf("\ns.no. current position next position displacement \n"); printf("---------------------------------------------------------- \n\n"); i=0; cposn = cyposn[cp]; { if(ind == 0) { if(cp == 0) { nposn = 0; ind = 1; } else nposn = cyposn[--cp]; } else { if(cp == 0) cp = tmp; nposn = cyposn[++cp]; } printf(" %d\t\t%d\t\t%d\t\t%d\n",++i,cposn,nposn,abs(cposn-nposn)); ttl_tracks += (abs(cposn-nposn)); cposn = nposn; }while(nposn!=cyposn[req]); printf("---------------------------------------------------------- \n\n"); printf(" total tracks displaced : %d",ttl_tracks); } void main() { { clrscr(); printf("\n enter number of requests : "); scanf("%d",&req); }while(req>max || req <=0); input(); scan(); getch(); }
you can send commands hard drive. protocol depends on hard drive.
check these out:
http://www.ata-atapi.com/pata.html
http://www.t13.org/documents/uploadeddocuments/docs2006/d1699r3f-ata8-acs.pdf
i suggest research sata, pata , atapi protocols. search "petzold writing device drivers".
Comments
Post a Comment