Disk Utilities-System Programming-Lecture Notes, Study notes of System Programming

This lecture handout is for System Programming course. It was provided by Prof. Indubhushan Vijayabhas at Ambedkar University, Delhi. It includes: Disk, Utility, Include, Signed, Char, Int, Quick, Format, Partition

Typology: Study notes

2011/2012

Uploaded on 08/07/2012

anishay
anishay 🇮🇳

4.2

(25)

118 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture # 41
#include <stdio.h>
#include <dos.h>
#include <bios.h>
#include <alloc.h>
typedef struct tagfcb
{ unsigned cha r filename [8];
unsigned cha r ext[3];
unsigned cha r attrib;
unsigned cha r reserved [10];
unsigned i nt time, date;
unsigned i nt firstcluster;
unsigned l ong int size;
}FCB;
typedef struct tagBPB
{ unsigned i nt bytesper sec;
unsigned cha r secperclu st;
unsigned i nt reserved secs;
unsigned cha r fats;
unsigned i nt rootdirents;
unsigned i nt smallsecs;
unsigned cha r media;
unsigned i nt fatsecs;
unsigned i nt secspertrack ;
unsigned i nt heads;
unsigned l ong int hiddensecs;
unsigned l ong int hugesecs;
unsigned cha r driveno;
unsigned cha r reserved;
unsigned cha r bootsignature;
unsigned l ong int volumeid;
unsigned cha r volumelabel[11];
unsigned cha r filesystem[8];
}BPB;
struct bootblock
{unsigned cha r jumpinst[3];
unsigned cha r osname[8];
BPB bpb;
unsigned cha r code[448];
};
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Disk Utilities-System Programming-Lecture Notes and more Study notes System Programming in PDF only on Docsity!

Lecture # 41

#include <stdio.h> #include <dos.h> #include <bios.h> #include <alloc.h> typedef struct tagfcb { unsigned char filename [8]; unsigned char ext[3]; unsigned char attrib; unsigned char reserved [10]; unsigned int time,date; unsigned int firstcluster; unsigned long int size; }FCB; typedef struct tagBPB { unsigned int byte spersec; unsigned char secperclust; unsigned int reservedsecs; unsigned char fats; unsigned int rootdirents; unsigned int smallsecs; unsigned char media;

unsigned int fatsecs; unsigned int secspertrack; unsigned int heads; unsigned long int hiddensecs; unsigned long int hugesecs; unsigned char driveno; unsigned char reserved; unsigned char bootsignature; unsigned long int volumeid; unsigned char volumelabel[11]; unsigned char filesystem[8]; }BPB;

struct bootblock { unsigned char jumpinst[3]; unsigned char osname[8]; BPB bpb; unsigned char code[448]; };

DPB far * getdpb(int drive) { DPB far *dpb=(DPB far *)0; _asm push ds; _asm mov ah,0x _asm mov dl,byte ptr drive; _asm mov dx,ds; _asm int 0x21; _asm pop ds _asm cmp al,0xff _asm je finish _asm mov word ptr dpb+2,dx _asm mov word ptr dpb,bx return dpb; finish: return ((DPB far *)(0)); }

void main (void) { unsigned char filename[9]; struct bootblock bb; unsigned char ext[4]; FCB * dirbuffer; unsigned int * FAT; DPB d; DPB far * dpbptr; int i,flag; unsigned int cluster; puts("Enter filename:"); gets (filename); puts("Enter Extension"); gets(ext); if ((absread(0x05,1,0, &bb))==0) puts ("Success"); else{ puts("Failure"); exit(0); }

• Quick Format

-- initializes the data structures for file

management.

-- initializes and sets the size of FAT, root

directory etc, according to the drive size.

-- initializes the data in boot block and

places appropriate boot strap code for

the boot block.

Disk Partitioning Software

• Write the code part of partition table to

appropriately load the Boot Block of active

partition in primary partition table.

• Places data in the partition table regarding

primary and extended partitions.

• As per specification of the user assigns a

appropriate size to primary and extended

partition by modifying their data part.

Scan Disk

Surface Scan for Bad Sectors

• It attempts to write a block.

• After write it reads back the block contents.

• Performs the CRC test on data read back.

• If there is an error then the data on that block

is not stable the cluster of that block should be

marked bad.

• The cluster is marked bad by placing the

appropriate code for bad cluster so that they

may not be allocated to any file.

Lost Chains

• The disk scanning software may also look

for lost chains.

• Lost chains are chains in FAT which

apparently don’t belong to any file.

• They may occur due to some error in the

system like power failure during deletion

process.

Defragmenter

  • Disk fragmentation is unwanted.
  • Fragmentation means that clusters of a same file are not

contiguously placed, rather they are far apart, increasing seek

time hence access time.

  • So its desirable that files clusters may be placed contiguously,

this can be done by compaction or defragme ntation.

  • Defragmentation Software reserves space for each file in

contiguous block by moving the data in clusters and

readjusting.

  • As a result of defragmentation the FAT entries will change

and data will move from one cluster to other localized cluster to

reduce seek time.

  • Defragmentation has high computation cost and thus cannot

be performe d frequently.

File Restoration

  • FAT structure provides the possibility of recovering a file

after deletion, if its clusters were contiguous and have not been

over-written.

  • DOS perform file deletion by placing 0xE5 at the first byte of

it FCB entry and placing 0’s (meaning available) in the entries

for the file clusters in the FAT.

  • Two task should be performed successfully to undelete a file

-- Replacing the 0xE5 entry in FCB by a valid file name

character.

-- placing the appropriate values in FAT for

representation of file cluster chain.

  • If any one of the above cannot be done then the file cannot be

fully recovered.