Читать диплом по информатике, вычислительной технике, телекоммуникациям: "Програма для роботи з файловою системою" Страница 8
exit(2);
} fseek(fd,0,SEEK_SET);
fread(buffer,2,1,fd);
if(buffer[0]!=0xcd)
if(buffer[1]!=0x20) {
fclose(fd);
printf("\n%s is NOT protected....\n\n",fname);
exit(2);
} fseek(fd,-2,SEEK_END);
fread(buffer,2,1,fd);
fseek(fd,0,SEEK_SET);
fwrite(buffer,2,1,fd);
fclose(fd);
handle=open(fname,O_RDWR);
chsize(handle,(filelength(handle))-2);
close(handle);
} Модуль, який пише та читає інформацію напряму в ділянку диску без звертання до FAT системи include common.mac text segment use16
assume CS:text, DS:text
org 256 myproc proc
mov AH,09h;printing function printf g ;print g
printf g1 ;print g1 ;parse the command line...
getf guff ;guff will have the command line ;is the command line empty?
cmp guff[0], 0
je expl ;is the command line starting with ?
cmp guff[0], '?'
je expl ;we are reading the disk
cmp guff[0], '^'
je readdisk ;nothing else but to write...
jmp writedisk
writedisk:
printf g2
waitenter
mov AH, 09h ;writing out
printf g3 ;what are we doing
printf guff ;file name
call disk_write ;write to disk
jmp rc
readdisk:
printf g2
waitenter
call disk_read ;write from disk
jmp rc
expl:
printf gline
jmp rc
rc: ;return
mov AX, 4C00h
int 21h
myproc endp ;====================================================================
;====================================================================
;==================== Procedure: disk_read =======================
;====================================================================
;==================================================================== disk_read proc
mov AH, 02h ;read raw input
mov AL, 1 ;number of sectors
mov CH, 0 ;cylinder
mov CL, 1 ;sector
mov DH, 1 ;head
mov DL, 0 ;disk drive - floppy
lea BX, guff
int 13h ;call BIOS
jnae ocr ;now guff stores file name
mov AH, 02h
mov AL, 1
mov CH, 1
mov CL, 1
mov DH, 0
mov DL, 0
lea BX, file
int 13h ;call BIOS
jnae ocr ;decrypt data
call chiper ;write output to the file saved
mov AH, 3Ch;create file
mov CX, 0;no attributes
lea DX, guff ;name
int 21h;call DOS
mov handle, AX ;get file handle mov AH, 40h;write to file
mov BX, handle ;handle ;get len
mov CX, 0 ;dump CX and SI
mov SI, 0
clen:
cmp file[SI], 0 ;is it zero yet?
je clenf ;this is the len inc SI ;increase counting
inc CX ;increase counting
jmp clen ;jump back
clenf: lea DX, file ;file data
int 21h;call DOS mov AH, 3Eh;close file
mov BX, handle ;handle
int 21h;call DOS ;open file for writing....
mov AH, 09h
printf success
jmp finr
ocr:
mov AH, 09h
printf error
finr: ret
disk_read endp ;====================================================================
;====================================================================
;====================================================================
;====================================================================
;==================== Procedure: disk_write ======================
;====================================================================
;====================================================================
disk_write proc
;write file name
mov AH, 03h;write raw output
mov AL, 1;write 1 sector
mov CH, 0;cylinder zero
mov CL, 1;sector no 1
mov DH, 1;head 1
mov DL, 0;disk drive A:
lea BX, guff ;set buffer
int 13h ;call BIOS ;read file...
mov AH, 3Dh;open file
mov AL, 2;read-write
lea DX, guff ;file name
int 21h;call DOS
mov handle, AX ;get handle mov AH, 3Fh;reading file
mov BX, handle ;set handle
mov CX, 1024;reading
lea DX, file ;buffer
int 21h;call DOS ;encrypt data
call chiper ;looping through each
mov AH, 03h
mov AL, 1
mov CH, 1
mov CL, 1
mov DH, 0
mov DL, 0
lea BX, file
int 13h ;show message
jnb okw
occ:
mov AH, 09h
printf error
jmp fin
okw:
mov AH, 09h
printf success
fin: ret ;return backwards
disk_write endp
;====================================================================
;====================================================================
;====================================================================
;====================================================================
;==================== Procedure: chiper ==========================
;====================================================================
;====================================================================
chiper proc
mov SI, 0
;xor values
chipe:
cmp file[SI], 0
je chipf ;jump if zero...
xor file[SI], 3
inc SI ;increase counter
jmp chipe
chipf:
ret ;return
chiper endp
;====================================================================
;==================================================================== g db 'Welcome
Похожие работы
Интересная статья: Основы написания курсовой работы

(Назад)
(Cкачать работу)