Fungsi ini merupakan pengembangan dari pemahaman yang didapatkan dari tutorial 22. Namun, dikarenakan tutorial 22 belum sempurna dikembangkan, akhirnya fungsi modifikasi file dan melihat
informasi file tidak dapat dikembangkan. Usaha yang dilakukan adalah dengan mencoba berkoordinasi dengan kelompok lain dan menanyakan pada mahasiswa informatika yang ahli dalam sistem operasi. Hasilnya tetap, fungsi ini tidak dapat dikembangkan. Salah satu penyebabnya yang kami dapatkan adalah belum stabilnya OS yang dikembangkan oleh Mike (Brokenthorn).
Referensi
Tipe Nama Tautan
Program MKBT http://www.nu2.nu/mkbt
Program NASM http://superuser.com/questions/183335/how-to-create-a-virtual-floppy-drive
Program Bochs http://sourceforge.net/projects/bochs/ Program VFD http://sourceforge.net/projects/vfd/
Program PartCopy http://stahlworks.com/dev/index.php?tool=partcopy
Program VS Community http://www.visualstudio.com/en-us/products/free-developer-offers-vs Teori Pengembangan
OS
http://www.brokenthorn.com/Resources/OSDevIndex.html
Teori C++ (Include) http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx
Lampiran
Bagian ini merupakan lampiran atas kode yang paling berpengaruh dalam pengembangan OS dan yang mengalami perubahan.
1. Boot1.asm
;********************************************* ; Boot1.asm
; - A Simple Bootloader
;
; Operating Systems Development Tutorial ;*********************************************
bits 16 ; we are in 16 bit real
mode
org 0 ; we will set regisers
later
start: jmp main ; jump to start of
bootloader
;********************************************* ; BIOS Parameter Block
;*********************************************
; BPB Begins 3 bytes from start. We do a far jump, which is 3 bytes in size.
; If you use a short jump, add a "nop" after it to offset the 3rd byte. bpbOEM db "My OS " bpbBytesPerSector: DW 512 bpbSectorsPerCluster: DB 1 bpbReservedSectors: DW 1 bpbNumberOfFATs: DB 2 bpbRootEntries: DW 224 bpbTotalSectors: DW 2880 bpbMedia: DB 0xf0 ;; 0xF1 bpbSectorsPerFAT: DW 9 bpbSectorsPerTrack: DW 18 bpbHeadsPerCylinder: DW 2 bpbHiddenSectors: DD 0 bpbTotalSectorsBig: DD 0 bsDriveNumber: DB 0 bsUnused: DB 0 bsExtBootSignature: DB 0x29 bsSerialNumber: DD 0xa0a1a2a3 bsVolumeLabel: DB "MOS FLOPPY " bsFileSystem: DB "FAT12 "
;************************************************; ; Prints a string
; DS=>SI: 0 terminated string
;************************************************; Print:
lodsb ; load next byte from string
from SI to AL
or al, al ; Does AL=0?
jz PrintDone ; Yep, null terminator
found-bail out
mov ah, 0eh ; Nope-Print the
character int 10h
jmp Print ; Repeat until null terminator
found PrintDone:
ret ; we are done, so return
absoluteSector db 0x00 absoluteHead db 0x00 absoluteTrack db 0x00
;************************************************; ; Convert CHS to LBA
; LBA = (cluster - 2) * sectors per cluster
ClusterLBA:
sub ax, 0x0002 ; zero base cluster number
xor cx, cx
mov cl, BYTE [bpbSectorsPerCluster] ; convert byte to word
mul cx
add ax, WORD [datasector] ; base data sector ret
;************************************************; ; Convert LBA to CHS
; AX=>LBA Address to convert ;
; absolute sector = (logical sector / sectors per track) + 1 ; absolute head = (logical sector / sectors per track) MOD number of heads
; absolute track = logical sector / (sectors per track * number of heads)
;
;************************************************; LBACHS:
xor dx, dx ; prepare dx:ax for operation
div WORD [bpbSectorsPerTrack] ; calculate inc dl ; adjust for sector 0
mov BYTE [absoluteSector], dl
xor dx, dx ; prepare dx:ax for operation
div WORD [bpbHeadsPerCylinder] ; calculate mov BYTE [absoluteHead], dl
mov BYTE [absoluteTrack], al ret
;************************************************; ; Reads a series of sectors
; CX=>Number of sectors to read ; AX=>Starting sector
; ES:BX=>Buffer to read to
;************************************************; ReadSectors:
.MAIN
mov di, 0x0005 ; five retries for error
.SECTORLOOP push ax push bx push cx
call LBACHS ; convert starting sector to CHS
mov al, 0x01 ; read one sector mov ch, BYTE [absoluteTrack] ; track
mov cl, BYTE [absoluteSector] ; sector mov dh, BYTE [absoluteHead] ; head mov dl, BYTE [bsDriveNumber] ; drive
int 0x13 ; invoke BIOS jnc .SUCCESS ; test for read error
xor ax, ax ; BIOS reset disk int 0x13 ; invoke BIOS dec di ; decrement error counter
pop cx pop bx pop ax
jnz .SECTORLOOP ; attempt to read again
int 0x18 .SUCCESS
mov si, msgProgress call Print
pop cx pop bx pop ax
add bx, WORD [bpbBytesPerSector] ; queue next buffer
inc ax ; queue next sector
loop .MAIN ; read next sector ret
;********************************************* ; Bootloader Entry Point
;********************************************* main:
;--- ; code located at 0000:7C00, adjust segment registers ;---
cli ; disable interrupts
mov ax, 0x07C0 ; setup registers to
point to our segment mov ds, ax mov es, ax mov fs, ax mov gs, ax ;--- ; create stack ;---
mov ss, ax mov sp, 0xFFFF
sti ; restore interrupts
mov [bootdevice], dl
;--- ; Load root directory table
;--- LOAD_ROOT:
; compute size of root directory and store in "cx" xor cx, cx
xor dx, dx
mov ax, 0x0020 ; 32 byte directory entry
mul WORD [bpbRootEntries] ; total size of directory
div WORD [bpbBytesPerSector] ; sectors used by directory
xchg ax, cx
; compute location of root directory and store in "ax"
mov al, BYTE [bpbNumberOfFATs] ; number of FATs mul WORD [bpbSectorsPerFAT] ; sectors used by FATs
add ax, WORD [bpbReservedSectors] ; adjust for bootsector
mov WORD [datasector], ax ; base of root directory
add WORD [datasector], cx
; read root directory into memory (7C00:0200)
mov bx, 0x0200 ; copy root dir above bootcode
call ReadSectors
;--- ; Find stage 2
;--- ; browse root directory for binary image
mov cx, WORD [bpbRootEntries] ; load loop counter
mov di, 0x0200 ; locate first root entry
.LOOP: push cx
mov cx, 0x000B ; eleven character name
find
push di
rep cmpsb ; test for entry match
pop di
je LOAD_FAT pop cx
add di, 0x0020 ; queue next directory entry loop .LOOP jmp FAILURE ;--- ; Load FAT ;--- LOAD_FAT:
; save starting cluster of boot image mov dx, WORD [di + 0x001A]
mov WORD [cluster], dx ; file's first cluster
; compute size of FAT and store in "cx" xor ax, ax
mov al, BYTE [bpbNumberOfFATs] ; number of FATs mul WORD [bpbSectorsPerFAT] ; sectors used by FATs
mov cx, ax
; compute location of FAT and store in "ax"
mov ax, WORD [bpbReservedSectors] ; adjust for bootsector
; read FAT into memory (7C00:0200)
mov bx, 0x0200 ; copy FAT above bootcode
call ReadSectors
; read image file into memory (0050:0000) mov ax, 0x0050
mov es, ax ; destination for image
mov bx, 0x0000 ; destination for image
push bx
;--- ; Load Stage 2
LOAD_IMAGE:
mov ax, WORD [cluster] ; cluster to read pop bx ; buffer to read into
call ClusterLBA ; convert cluster to LBA
xor cx, cx
mov cl, BYTE [bpbSectorsPerCluster] ; sectors to read call ReadSectors
push bx
; compute next cluster
mov ax, WORD [cluster] ; identify current cluster
mov cx, ax ; copy current cluster
mov dx, ax ; copy current cluster
shr dx, 0x0001 ; divide by two add cx, dx ; sum for (3/2) mov bx, 0x0200 ; location of FAT in memory
add bx, cx ; index into FAT mov dx, WORD [bx] ; read two bytes from FAT
test ax, 0x0001 jnz .ODD_CLUSTER .EVEN_CLUSTER:
and dx, 0000111111111111b ; take low twelve bits
jmp .DONE .ODD_CLUSTER:
shr dx, 0x0004 ; take high twelve bits
.DONE:
mov WORD [cluster], dx ; store new cluster
cmp dx, 0x0FF0 ; test for end of file jb LOAD_IMAGE DONE: mov si, msgCRLF call Print mov dl, [bootdevice]
push WORD 0x0050 push WORD 0x0000 retf
FAILURE:
mov si, msgFailure call Print
mov ah, 0x00
int 0x16 ; await keypress int 0x19 ; warm boot computer bootdevice db 0 datasector dw 0x0000 cluster dw 0x0000 ImageName db "KRNLDR SYS" msgCRLF db 0x0D, 0x0A, 0x00 msgProgress db ".", 0x00
msgFailure db 0x0D, 0x0A, "MISSING OR CURRUPT KRNLDR. Press Any Key to Reboot", 0x0D, 0x0A, 0x00
TIMES 510-($-$$) DB 0 DW 0xAA55 2. Stage2.asm ;******************************************************* ; ; Stage2.asm ; Stage2 Bootloader ; ; OS Development Series ;******************************************************* bits 16 org 0x500 jmp main ; go to start ;******************************************************* ; Preprocessor directives ;******************************************************* %include "stdio.inc" ; basic i/o routines %include "Gdt.inc" ; Gdt routines
%include "A20.inc" ; A20 enabling
%include "Fat12.inc" ; FAT12 driver. Kinda :) %include "Common.inc"
%include "bootinfo.inc" %include "memory.inc"
;******************************************************* ; Data Section
;*******************************************************
LoadingMsg db 0x0D, 0x0A, "Searching for Operating System...", 0x00
msgFailure db 0x0D, 0x0A, "*** FATAL: Missing or corrupt KRNL32.EXE. Press Any Key to Reboot.", 0x0D, 0x0A, 0x0A, 0x00 boot_info: istruc multiboot_info at multiboot_info.flags, dd 0 at multiboot_info.memoryLo, dd 0 at multiboot_info.memoryHi, dd 0 at multiboot_info.bootDevice, dd 0 at multiboot_info.cmdLine, dd 0 at multiboot_info.mods_count, dd 0 at multiboot_info.mods_addr, dd 0 at multiboot_info.syms0, dd 0 at multiboot_info.syms1, dd 0 at multiboot_info.syms2, dd 0 at multiboot_info.mmap_length, dd 0 at multiboot_info.mmap_addr, dd 0 at multiboot_info.drives_length, dd 0 at multiboot_info.drives_addr, dd 0 at multiboot_info.config_table, dd 0 at multiboot_info.bootloader_name, dd 0 at multiboot_info.apm_table, dd 0 at multiboot_info.vbe_control_info, dd 0 at multiboot_info.vbe_mode_info, dw 0 at multiboot_info.vbe_interface_seg, dw 0 at multiboot_info.vbe_interface_off, dw 0 at multiboot_info.vbe_interface_len, dw 0 iend main: ;---; ; Setup segments and stack ; ;---;
cli ; clear interrupts xor ax, ax ; null segments
mov ds, ax
mov es, ax
mov ax, 0x0000 ; stack begins at 0x9000-0xffff
mov ss, ax
mov sp, 0xFFFF
sti ; enable interrupts
mov [boot_info+multiboot_info.bootDevice], dl call _EnableA20
sti
xor eax, eax xor ebx, ebx
call BiosGetMemorySize64MB push eax
mov eax, 64
mul ebx
mov ecx, eax
pop eax
add eax, ecx
add eax, 1024 ; the routine doesnt add the KB between 0-1MB; add it
mov dword [boot_info+multiboot_info.memoryHi], 0 mov dword [boot_info+multiboot_info.memoryLo], eax mov eax, 0x0 mov ds, ax mov di, 0x1000 call BiosGetMemoryMap call LoadRoot mov ebx, 0
mov ebp, IMAGE_RMODE_BASE mov esi, ImageName
call LoadFile ; load our file
mov dword [ImageSize], ecx
cmp ax, 0
je EnterStage3
mov si, msgFailure
call Puts16
mov ah, 0
; int 0x16 ; await keypress ; int 0x19 ; warm boot computer
;---; ; Go into pmode ; ;---; EnterStage3:
cli ; clear interrupts
mov eax, cr0 ; set bit 0 in cr0--enter pmode
or eax, 1 mov cr0, eax
jmp CODE_DESC:Stage3 ; far jump to fix CS. Remember that the code selector is 0x8!
; Note: Do NOT re-enable interrupts! Doing so will triple fault!
;****************************************************** ; ENTRY POINT FOR STAGE 3
;****************************************************** bits 32
%include "Paging.inc"
BadImage db "*** FATAL: Invalid or corrupt kernel image. Halting system.", 0
Stage3:
;---;
; Set registers ;
;---;
mov ax, DATA_DESC ; set data segments to data selector (0x10)
mov ds, ax mov ss, ax mov es, ax
mov esp, 9000h ; stack begins from 90000h call ClrScr32
call EnablePaging CopyImage:
mov eax, dword [ImageSize]
movzx ebx, word [bpbBytesPerSector] mul ebx
mov ebx, 4 div ebx cld
mov esi, IMAGE_RMODE_BASE mov edi, IMAGE_PMODE_BASE mov ecx, eax
rep movsd ; copy image to its protected mode address
TestImage:
mov ebx, [IMAGE_PMODE_BASE+60]
add ebx, IMAGE_PMODE_BASE ; ebx now points to file sig (PE00)
mov esi, ebx mov edi, ImageSig cmpsw
je EXECUTE mov ebx, BadImage call Puts32 cli
ImageSig db 'PE' EXECUTE:
;---; ; Execute Kernel
;---;
; parse the programs header info structures to get its entry point
add ebx, 24
mov eax, [ebx] ; _IMAGE_FILE_HEADER is
20 bytes + size of sig (4 bytes)
add ebx, 20-4 ; address of entry point
mov ebp, dword [ebx] ; get entry point offset in code section
add ebx, 12 ; image base is
offset 8 bytes from entry point
mov eax, dword [ebx] ; add image base add ebp, eax
cli
mov eax, 0x2badb002 ; multiboot specs
say eax should be this
mov ebx, 0
mov edx, [ImageSize] push dword boot_info
call ebp ; Execute Kernel
add esp, 4
cli hlt
;-- header information format for PE files --- ;typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header
; USHORT e_magic; // Magic number (Should be MZ ; USHORT e_cblp; // Bytes on last page of file ; USHORT e_cp; // Pages in file
; USHORT e_crlc; // Relocations
; USHORT e_cparhdr; // Size of header in paragraphs ; USHORT e_minalloc; // Minimum extra paragraphs needed
; USHORT e_maxalloc; // Maximum extra paragraphs needed
; USHORT e_ss; // Initial (relative) SS value ; USHORT e_sp; // Initial SP value
; USHORT e_csum; // Checksum
; USHORT e_ip; // Initial IP value
; USHORT e_cs; // Initial (relative) CS value ; USHORT e_lfarlc; // File address of relocation table
; USHORT e_res[4]; // Reserved words
; USHORT e_oemid; // OEM identifier (for e_oeminfo) ; USHORT e_oeminfo; // OEM information; e_oemid
specific
; USHORT e_res2[10]; // Reserved words
; LONG e_lfanew; // File address of new exe header ; } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
;<<--- Real mode stub program --->>
;<< Here is the file signiture, such as PE00 for NT --->>
;typedef struct _IMAGE_FILE_HEADER { ; USHORT Machine; ; USHORT NumberOfSections; ; ULONG TimeDateStamp; ; ULONG PointerToSymbolTable; ; ULONG NumberOfSymbols; ; USHORT SizeOfOptionalHeader; ; USHORT Characteristics; ;} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER; ;struct _IMAGE_OPTIONAL_HEADER { ; // ; // Standard fields. ; // ; USHORT Magic; ; UCHAR MajorLinkerVersion; ; UCHAR MinorLinkerVersion; ; ULONG SizeOfCode; ; ULONG SizeOfInitializedData; ; ULONG SizeOfUninitializedData;
; ULONG AddressOfEntryPoint; << IMPORTANT! ; ULONG BaseOfCode; ; ULONG BaseOfData; ; // ; // NT additional fields. ; // ; ULONG ImageBase; ; ULONG SectionAlignment; ; ULONG FileAlignment; ; USHORT MajorOperatingSystemVersion; ; USHORT MinorOperatingSystemVersion; ; USHORT MajorImageVersion; ; USHORT MinorImageVersion; ; USHORT MajorSubsystemVersion; ; USHORT MinorSubsystemVersion; ; ULONG Reserved1; ; ULONG SizeOfImage; ; ULONG SizeOfHeaders; ; ULONG CheckSum; ; USHORT Subsystem; ; USHORT DllCharacteristics; ; ULONG SizeOfStackReserve;
; ULONG SizeOfStackCommit; ; ULONG SizeOfHeapReserve; ; ULONG SizeOfHeapCommit; ; ULONG LoaderFlags; ; ULONG NumberOfRvaAndSizes; ; IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; ;} IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
3. Fungsi tambahan pada untuk fungsi aritmatika pada main.cpp
void get_opr_cmd (char* buf, int n,char* opr,int* n1,int* n2) {
KEYCODE key = KEY_UNKNOWN;
bool BufChar;
bool parse = false;
char arr[40];
//DebugPrintf("%d", opr); //! get command string
int i=0;
while ( i < n ) {
//! buffer the next char
BufChar = true;
//! grab next char
key = getch ();
//! end of command if enter is pressed
if (key==KEY_RETURN)
break;
//! backspace
if (key==KEY_BACKSPACE) {
//! dont buffer this char
BufChar = false;
if (i > 0) {
//! go back one char
unsigned y, x;
DebugGetXY (&x, &y);
if (x>0)
DebugGotoXY (--x, y);
else {
//! x is already 0, so go back one line
y--;
x = DebugGetHorz (); }
//! erase the character from display
DebugPutc (' '); DebugGotoXY (x, y); if (strcmp(opr,"\0")!=0){ if (buf[i-1]==','){ parse = false; } else { if (!parse){
n1[0] = (n1[0]/10); } else { n2[0] = (n2[0]/10); } } }
//! go back one char in cmd buf
i--; }
}
//! only add the char if it is to be buffered
if (BufChar) {
int digit1=0;
int digit2=0;
//! convert key to an ascii char and put it in buffer
char c = kkybrd_key_to_ascii (key);
if (c != 0) { //insure its an ascii char
DebugPutc (c); if (strcmp(opr,"\0")!=0){ if (key==KEY_COMMA){ parse = true; } else { if (!parse){ int num = kkybrd_key_to_ascii(key); n1[0] = (num-48)+(n1[0]*10); } else { int num = kkybrd_key_to_ascii(key); n2[0] = (num-48)+(n2[0]*10); } } } if (key==KEY_SPACE){ //DebugPrintf ("\n\r %s ",opr);
strcpy(opr,buf);
//DebugPrintf ("\n\r %s ",opr);
}
buf [i++] = c; }
}
//! wait for next key. You may need to adjust this to suite your needs
sleep (5); }
//! null terminate the string
buf [i] = '\0'; }
4. Fat12.cpp pada Windows 8.1 64-bit
/******************************************************************** ********** fat12.cpp -FAT12 Minidriver arthor\ Mike ********************************************************************* *********/
#include "DebugDisplay.h" #include "fat12.h" #include "string.h" #include "flpydsk.h" #include "bpb.h" #include "ctype.h"
//! bytes per sector
#define SECTOR_SIZE 512
//! FAT FileSystem
FILESYSTEM _FSysFat;
//! Mount info
MOUNT_INFO _MountInfo;
//! File Allocation Table (FAT)
uint8_t FAT [SECTOR_SIZE*2];
/**
Helper function. Converts filename to DOS 8.3 file format
*/
void ToDosFileName (const char* filename,
char* fname,
unsigned int FNameLength) {
unsigned int i=0;
if (FNameLength > 11)
return;
if (!fname || !filename)
return;
//! set all characters in output name to spaces
memset (fname, ' ', FNameLength);
//! 8.3 filename
for (i=0; i < strlen(filename)-1 && i < FNameLength; i++) {
if (filename[i] == '.' || i==8 )
break;
//! capitalize character and copy it over (we dont handle LFN format)
fname[i] = toupper (filename[i] ); }
//! add extension if needed
if (filename[i]=='.') {
//! note: cant just copy over-extension might not be 3 chars
for (int k=0; k<3; k++) { ++i; if ( filename[i] ) fname[8+k] = filename[i]; } }
//! extension must be uppercase (we dont handle LFNs)
for (i = 0; i < 3; i++)
fname[8+i] = toupper (fname[8+i]); }
/**
Locates file or directory in root directory */
FILE fsysFatDirectory (const char* DirectoryName) { FILE file;
unsigned char* buf; PDIRECTORY directory;
//! get 8.3 directory name
char DosFileName[11];
ToDosFileName (DirectoryName, DosFileName, 11); DosFileName[11]=0;
//! 14 sectors per directory
for (int sector=0; sector<14; sector++) {
//! read in sector of root directory
buf = (unsigned char*) flpydsk_read_sector (_MountInfo.rootOffset + sector );
//! get directory info
directory = (PDIRECTORY) buf;
//! 16 entries per sector
for (int i=0; i<16; i++) {
//! get current filename
char name[11];
memcpy (name, directory->Filename, 11); name[11]=0;
//! find a match?
if (strcmp (DosFileName, name) == 0) {
//! found it, set up file info
strcpy (file.name, DirectoryName); file.id = 0;
file.currentCluster = directory->FirstCluster; file.fileLength = directory->FileSize; file.eof = 0;
file.fileLength = directory->FileSize;
//! set file type
if (directory->Attrib == 0x10) file.flags = FS_DIRECTORY; else file.flags = FS_FILE; //! return file return file; } //! go to next directory directory++; } }
//! unable to find file
file.flags = FS_INVALID;
return file; }
/**
Reads from a file */
void fsysFatRead(PFILE file, unsigned char* Buffer, unsigned int
Length) {
if (file) {
//! starting physical sector
unsigned int physSector = 32 + (file->currentCluster - 1);
//! read in sector
unsigned char* sector = (unsigned char*) flpydsk_read_sector ( physSector );
//! copy block of memory
memcpy (Buffer, sector, 512);
//! locate FAT sector
unsigned int FAT_Offset = file->currentCluster + (file->currentCluster / 2); //multiply by 1.5
unsigned int FAT_Sector = 1 + (FAT_Offset / SECTOR_SIZE);
unsigned int entryOffset = FAT_Offset % SECTOR_SIZE;
//! read 1st FAT sector
sector = (unsigned char*) flpydsk_read_sector ( FAT_Sector ); memcpy (FAT, sector, 512);
//! read 2nd FAT sector
sector = (unsigned char*) flpydsk_read_sector ( FAT_Sector + 1 ); memcpy (FAT + SECTOR_SIZE, sector, 512);
//! read entry for next cluster
uint16_t nextCluster = *( uint16_t*) &FAT [entryOffset];
//! test if entry is odd or even
if( file->currentCluster & 0x0001 )
nextCluster >>= 4; //grab high 12 bits
else
nextCluster &= 0x0FFF; //grab low 12 bits //! test for end of file
if ( nextCluster >= 0xff8) { file->eof = 1;
return; }
//! test for file corruption
if ( nextCluster == 0 ) { file->eof = 1;
return; }
//! set next cluster
file->currentCluster = nextCluster; } } /** Closes file */
if (file)
file->flags = FS_INVALID; }
/**
Locates a file or folder in subdirectory */
FILE fsysFatOpenSubDir (FILE kFile,
const char* filename) { FILE file;
//! get 8.3 directory name
char DosFileName[11];
ToDosFileName (filename, DosFileName, 11); DosFileName[11]=0;
//! read directory
while (! kFile.eof ) {
//! read directory
unsigned char buf[512];
fsysFatRead (&file, buf, 512);
//! set directort
PDIRECTORY pkDir = (PDIRECTORY) buf;
//! 16 entries in buffer
for (unsigned int i = 0; i < 16; i++) {
//! get current filename
char name[11];
memcpy (name, pkDir->Filename, 11); name[11]=0;
//! match?
if (strcmp (name, DosFileName) == 0) {
//! found it, set up file info
strcpy (file.name, filename); file.id = 0;
file.currentCluster = pkDir->FirstCluster; file.fileLength = pkDir->FileSize; file.eof = 0;
file.fileLength = pkDir->FileSize;
//! set file type
if (pkDir->Attrib == 0x10) file.flags = FS_DIRECTORY; else file.flags = FS_FILE; //! return file return file; } //! go to next entry pkDir++; } }
//! unable to find file
return file; }
/**
Opens a file */
FILE fsysFatOpen (const char* FileName) { FILE curDirectory;
char* p = 0;
bool rootDir=true;
char* path = (char*) FileName;
//! any '\'s in path?
p = strchr (path, '\\');
if (!p) {
//! nope, must be in root directory, search it
curDirectory = fsysFatDirectory (path);
//! found file? if (curDirectory.flags == FS_FILE) return curDirectory; //! unable to find FILE ret; ret.flags = FS_INVALID; return ret; }
//! go to next character after first '\'
p++;
while ( p ) {
//! get pathname
char pathname[16];
int i=0;
for (i=0; i<16; i++) {
//! if another '\' or end of line is reached, we are done
if (p[i]=='\\' || p[i]=='\0')
break;
//! copy character
pathname[i]=p[i]; }
pathname[i]=0; //null terminate //! open subdirectory or file
if (rootDir) {
//! search root directory - open pathname
curDirectory = fsysFatDirectory (pathname); rootDir=false;
}
else {
//! search a subdirectory instead for pathname
curDirectory = fsysFatOpenSubDir (curDirectory, pathname); }
//! found directory or file?
break; //! found file? if (curDirectory.flags == FS_FILE) return curDirectory; //! find next '\' p=strchr (p+1, '\\'); if (p) p++; } //! unable to find FILE ret; ret.flags = FS_INVALID; return ret; } /**
Mounts the filesystem */
void fsysFatMount () {
//! Boot sector info
PBOOTSECTOR bootsector;
//! read boot sector
bootsector = (PBOOTSECTOR) flpydsk_read_sector (0);
//! store mount info
_MountInfo.numSectors = bootsector->Bpb.NumSectors; _MountInfo.fatOffset = 1; _MountInfo.fatSize = bootsector->Bpb.SectorsPerFat; _MountInfo.fatEntrySize = 8; _MountInfo.numRootEntries = bootsector->Bpb.NumDirEntries; _MountInfo.rootOffset = (bootsector->Bpb.NumberOfFats * bootsector->Bpb.SectorsPerFat) + 1; _MountInfo.rootSize = ( bootsector->Bpb.NumDirEntries * 32 ) / bootsector->Bpb.BytesPerSector; } /** Initialize filesystem */ void fsysFatInitialize () {
//! initialize filesystem struct
strcpy (_FSysFat.Name, "FAT12");
_FSysFat.Directory = fsysFatDirectory; _FSysFat.Mount = fsysFatMount; _FSysFat.Open = fsysFatOpen; _FSysFat.Read = fsysFatRead; _FSysFat.Close = fsysFatClose;
//! register ourself to volume manager
volRegisterFileSystem ( &_FSysFat, 0 );
//! mounr filesystem
fsysFatMount (); }
Kesimpulan
Tutorial yang diberikan Brokenthorn masih memiliki banyak bug dan memiliki keterbatasan lingkungan pengembangan. Pada situs Brokenthorn dikembangkan pada Windows 32-bit dengan tools Microsoft Visual Studio 2005 dan tidak mudah untuk beradaptasi dengan lingkungan pengembangan lainnya, seperti Windows 64-bit dan Microsoft Visual Studio versi lain.
Fungsi aritmatika dapat dikembangkan secara langsung pada Kernel tanpa memerlukan interface lain. Pengembangan fungsi ini akan lebih mudah dengan cara membuat fungsi baru sehingga tidak perlu memodifikasi fungsi yang sudah ada.
File System tidak dapat dikembangkan karena belum stabilnya OS yang dibuat.
Saran
Selain saran yang disampaikan pada tugas sebelumnya, saran yang muncul dari pengerjaan tugas ini adalah akan lebih baik apabila pemberi tugas telah berhasil mengerjakan tugas yang diberikan terlebih dahulu. Hal ini akan berpengaruh pada efisiensi waktu pengerjaan dan akan ada tempat bertanya yang pasti.