disk - #ifndef _disk_ # #define _disk_ #include "disk.h"...

Info iconThis preview shows pages 1–4. 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;
Background image of page 1

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

View Full DocumentRight 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;
Background 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;
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/21/2011 for the course ECE 271 taught by Professor Eason,r during the Spring '08 term at University of Maine Orono .

Page1 / 16

disk - #ifndef _disk_ # #define _disk_ #include "disk.h"...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online