{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

disk -...

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
#ifndef _disk_ #define _disk_ # #include "disk.h" #include "inout.cpp" #include "shell.cpp" #include "fs.cpp" #define RW 33 #define RO 32 # #define File_Not_Found 1 #define Folder_Not_Found 2 #define Destination_File_Exist 3 #define Destination_Folder_Exist 4 #define Access_Violation 5 # char Error_Code; char curr_dir_cnum; extern Directory curr_dir; extern char *path; extern char floppy_hardd_tog; char Drive_No=0x80; c // Initialise Routine // Disk disk; Drive d[4]; D //To check whether the entered drive is valid or not struct Entry_details Disk::validate_drive(char* str) { int dr_num; struct Entry_details file_details; dr_num = path[0]-'A'; if((dr_num==2)||(dr_num==3)) { file_details.lba = curr_dir.dir_lba; file_details = d[dr_num-2].validate_entry(str,file_details,dr_num); return file_details; } } //Convertion of chs to lba addressing long Disk::chs_to_lba(int track,int head,int sector) { long lba; lba = (track*255*63) + head*63 + sector; return(lba); } //Convertion of chs to lba addressing long Disk::chs_to_lba(char track,char head,char sector) { int h,t,s,temp; long lba; h=head; s=(sector & 0x3f); temp = (sector & 0xc0)<<2;
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
t=track+temp; lba =(255*63*(long)t); lba+= s+ (63*h); return(lba); } //Constructor for Disk class Disk::Disk() { char head,track,sector,buf[512]; int i,j,read_flag,inc=446; long lba; num_of_drives=2;//Number of drives assumed to be 2 read_flag = get_sector(lba = 1,0x01,buf);//MBR is on t=0,h=0,s=1; for(i=0;i<4;i++) for(j=0;j<16;j++) partition[i][j] = buf[inc++]; head=partition[1][1]; sector=partition[1][2]; track=partition[1][3]; lba = chs_to_lba(track,head,sector); read_flag = get_sector(lba,0x01,buf); inc=446; for(i=1;i<4;i++) for(j=0;j<16;j++) partition[i][j] = buf[inc++]; } //Read sectors with a given lba int Disk::get_sector(long lba,char num_sectors,char *buf) { char num; int h,t,s,temp; char head,sector,track; if((lba==50)&&(priority!=1)) {Error_Code=Access_Violation;return 0;} t = lba/(255*63); h = (lba%(255*63))/63; s = lba%63; head = h; sector = (t & 0x300)>>2; sector+=s; track = t; asm mov cx,0x3; lp: asm push cx; asm mov ah,0x02 asm mov al,num_sectors asm mov ch,track asm mov cl,sector asm mov dh,head asm mov dl,Drive_No asm mov bx,buf asm push ds asm int 0x13 asm pop es asm jnc nerror; num=0; asm pop cx;
Image of page 2
asm dec cx; asm jnz lp; asm mov num,ah return num; nerror: asm mov num,ah return num; } //Write sectors with a given lba int Disk::put_sector(long lba,char num_sectors,char *buf) { char num; int h,t,s,temp; char head,sector,track; if((lba==50)&&(priority!=1)) {Error_Code=Access_Violation;return 0;} t = lba/(255*63); h = (lba%(255*63))/63; s = lba%63; head = h; sector = (t & 0x300)>>2; sector+=s; track = t; asm mov cx,0x3; lp: asm push cx; asm mov ah,0x03 asm mov al,num_sectors asm mov ch,track asm mov cl,sector asm mov dh,head asm mov dl,Drive_No asm mov bx,buf asm push ds asm int 0x13 asm pop es asm jnc nerror; num=0; asm pop cx; asm dec cx; asm jnz lp; asm mov num,ah return num; nerror: asm mov num,ah return num; } //Validate a given relative path struct Entry_details Drive::validate_entry(char* str,struct Entry_details file_details,int dr_num) { Directory dir; file_details = dir.get_lba(str,file_details,dr_num); return file_details; }
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
} //Validate a given absolute path struct Entry_details Disk::validate_drive_abs(char* path) { int dr_num; struct Entry_details file_details; dr_num = *path - 'A'; if((dr_num==2)||(dr_num==3)) { file_details.lba = d[dr_num-2].rootdir_lba;
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern