




已阅读5页,还剩54页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Chapter 14 Disks Fundamentals,Every operating system has some type of disk management system. At the lowest level, it manages partitions. At the nest-highest level, it manages files and directories. A file system must keep track of the location, sizes, and attributes of each disk file. A cluster is the smallest unit space used by a file; it consists of one or more adjacent disk sectors. A file system stores each file as a linked sequence of clusters. Actually, a cluster size of 4,096 (4 KB) is considered an efficient way to store small files. A chain of clusters is referenced by a file allocation table (FAT) that keep track of all clusters used by a file. A pointer to the first cluster entry in the FAT is stored in each files directory entry.,2. MS-DOS directory StructureEach MS-DOS directory entry is 32 bytes long and contains the fields.,AttributeThe attribute field identifies the type of field. The field is bit-mapped and usually contains a combination of one of the values. The two reserved bits should always be 0. The archive bit is set when a file is modified. The subdirectory bit is set if the entry contains the name of a subdirectory. The volume label identifies the entry as the name of a disk volume. The system file bit indicates that file is part of the operating system. The hidden file bits makes the file hidden; its name does not appear in d display of the directory. The read-only bit prevents the file from being deleted or modified in any way. Finally, an attribute value of 0Fh indicates the current directory is for an extended filename.,File Attribute Byte Fields,Function Call of File Management,File/Device HandlesBoth MS-DOS and MS-Windows use 16-bit integers called handles to identify files and I/O devices There are five predefined device.0=Keyboard (standard input)1=Console (standard output)2=Error output3=Auxiliary device (asynchronous)4=Printer,Each I/O function has a common characteristic: if it fails, the Carry flag is set and an error code is returned in AX.,Example Modifying the Attribute of the File (43H)MOV AH, 43H ;check or change attributeMOV AL,01 ;set file attributeMOV CX,01 ;read onlyMOV DX, SEG FNAME ;addr of ASCIZ stringMOV DS, DXMOV DX,OFFSET FNAMEINT 21H ; call DOS,Example Write disk filePATHNM1 DB E:ACCOUNTS.FIL, 00HHANDLE1 DW ? ;file handle MOV AH, 3CH ; request creat MOV CX, 00 ; normal file LEA DX, PATHNM1 ; ASCIZ string INT 21H ; call DOS JC ERROR ; exit if error MOV HANDLE1, AX ; save handle in DW,HANDLE1 DW ?OUTREC DB 265 DUP(?) MOV AH, 40H ; request write MOV BX, HANDLE1 ; handle MOV CX, 265 ; number of bytes LEA DX, OUTREC ; address of output area INT 21H ; call interrupt service JC ERROR2 ; special action if error CMP AX, 265 ; all bytes written? JNE ERROR3 ; if not, error,MOV AH, 3EH ;request closeMOV BX, HANDLE1 ;file handleINT 21H ;call DOS,LEA DX, OUTREC ; addr of output area INT 21H ; call interrupt service JC ERROR2 ; special action if error CMP AX, 265 ; all bytes written? JNE ERROR3 ; if not, error,ExampleCreating a File,.model small .stack 64 .datanamepar label bytemaxlen db 30namelen db ?namerec db 30 dup( ), odh, oahclrf db 13, 10, $,errcde db 0handle dw ?pathname db D:NAME.DAT,0prompt db name ?Row db 01opnmsg db * open error *,0dh,0ah,$wrtmsg db * write error *,oah,odh,$ .codebegin proc far move ax,data,mov ds, ax mov es, ax mov ax, 0600h call scren ; clear screen call curs ; set cursor call creath ; create file cmp errcde, 0 ; create error? jz contin ; yes, continuecontin: call proach cmp namelen, 0 ;end of inpout,jne contin ; no, continue call clseh ; yes, closeback: mov ax, 4c00h ; return to DOS int 21hbegin endp;-; create disk filecreath proc near mov ah, 3ch ; request create mov cx, 0 ; normal attribute lea dx, pathname,int 21h jc al ; error? mov handle, ax ; no, save handle retal: lea dx, opnmsg call errm retcreath endp;-; accept inputproch proc near,mov ah, 40h ; request display mov bx, 01 ; 01=output display mov cx, 06 ; length of promt lea dx, prompt ; display prompt int 21h mov ah, 0ah ; request input lea dx, namepar ; accept name int 21h cmp namelen, 0 jne b1; ;yes,ret ; no, exitb1: mov al, 20h ; blank for storing sub ch, ch mov cl, namelen ; length lea di, namerce add di, cx ; calculate+length neg cx ; calculate remaining add cx, 30 ; length cld rep stosb ; set to blank,call writh ; write disk record call scrl ; check for scroll retproch endp;-; check for scrollscrl proc near cmp row, 18h ; bottom of screen? jae cl ; yes, bypass mov ah, 09 ; no, to next row lea dx, clrf,mov ah, 09 ; no, to next row lea dx, clrf int 21h inc row ; no, add to row retc1: mov ax, 0601h ;scroll one row call scren call curs ; reset cursor retscrl endp,; write disk recordwrith proc near mov ah, 40h ; request write mov bx, handle mov cx, 32 ; for name and CR/LF lea dx, namerec int 21h jnc dl ; valid writ? lea dx, writmsg ; no call errm ; call error rotine,mov namelen, 0d1: retwrith endp;-; close disk fileclseh proc near mov namerec, 1ah ;set EOF mark call writh mov ah, 3eh ; request close mov bx, handle int 21h,clseh endp;-; scroll screenscreen proc near ; AX set on entry mov bh, 1eh ; set yellow on blue mov cx, 0 mov dx, 184fh int 10h ; scroll retscreen endp,; set cursorcurs proc near mov ah, 02 mov bh,0 mov dh, row ; set cursor int 10h retcurs endp;-; disk error routine,errm proc near ;DX contains address mov ah, 40h ; of message mov bx, 01 ; handle mov cx, 21 ; length int 21h mov errcde, 01 ; set error code reterrm endp;- end begin,Example Read disk file ; Read disk record created by hancreat .model small .stack 64 .dataendcde db 0handle dw ?ioarea db 32 dup( )pathnam db D:name.dat,0openms db * open error *,0dh,0ahreadmsg db * read error *, 0dh, 0ah,row db 0dseg ends;- .codebegin proc far mov ax, data mov ds, ax mov es, ax mov ax, 0600h call scren call curs,call openth cmp endcde, 0 jnzcontin: call readh cmp endcde, 0 jnz al call disp jmp continal: mov ax, 4c00h int 21hbeging endp,;-;open fileopenh proc near mov ah, 3dh ;request open mov al, 0 ; normal file lea dx, pathnma int 21h jc bl ; error mov handle, ax ; no, save handle ret,b1: mov endcde, 01 ;yes lea dx, openmsg ;display call errm ;error message retopenh endp;-; read disk recordreadh proc near,mov ah, 3fh ;request read mov bx, handle mov cx, 32 ;for name and CR/LF lea dx, ioarea int 21h jc c1 ;error on read? cmp ax, 0 ;end of file? je c2 cmp ioarea, 1ah ;EOF marker? je c2 ;yes, exit ret,c1: lea dx, readmsg ;no, invalid read call errmc2 mov endcde, 01 ;force end retreadh endp;-; display namedisph proc near mov ah, 40h ;request display mov bx, 01 ;set handle lea dx, ioarea,int 21h cmp row, 24 ;bottom of screen jae d1 inc row retd1: mov ax, 0601h call scren ;scroll call curs ; set cursor retdisph endp,;-;scroll screenscren proc near ; AX set on entry mov bh, 1eh ;set color mov cx, 0 mov dx, 184fh ;request scroll int 10h retscren endp,; set cursorcurs proc near mov ah, 2 ;request set cursor mov bh, 2 mov dh, row ;row mov dl,0 ;column int 10h retcurs endp;-;disk error routine,errm proc near mov ah, 40h ;DX contains address mov bx, 01 ; handle mov cx, 20 ;length of message int 21h reterrm endp;-end begin,Example Shift pointer of fileAL=00 absolute shift mode MOV AH, 42H ;request move pointer MOV AL, 00 ;to start of file MOV BX, HANDLE1 ;set file handle MOV CX, 00 ;high_order word of offset MOV DX, 1024 ;low_order word of offset INT 21H ;call DOS JC ERROR ;check error,AL=01 relative shift mode MOV BX, HANDLE ;file handle MOV CX, 0 ;high_order word MOV DX, N ;low_order word CMP DX, 0 ;if N0,JGE POINT ;yes NOT CX ;extending the signPOINT: MOV AL, 1 ;method1 MOV AH, 42H ;request move pointer INT 21H JC ERROR,3. AL=2 absolute inverse shift mode MOV AH, 42H ;request move pointer MOV AL, 2 ;method 2 MOV BX, HANDLE ;handle MOV CX, 0 ;offset MOV DX, 0 INT 21H ;call DOS JC ERROR ;check error,Example Random read fileTITLE READR.EXE-Read disk records randomly .model small .stack 64 .datahandle dw ? ;file handlerecindx dw ? ;record indexerrcde db 00 ;read error indicator,prompt db RECORD NUMBER?ioarea db 32 dup( ) ;disk record areapathnam db D:NAME.DAT,0openmsg db * open error *, 0dh, 0ahreadmsg db * read error *, 0dh, 0ahrow db 00col db 00recdpar label byte ;input parameter lists:maxlen db 3 ;maximum lengthactlen db ? ;actual lengthrecdno db 3 dup ( ) ;record number,.code .386main proc far mov ax, data ;intialize mov ds, ax ;sehment mov es, ax ;registers mov ax, 0600h call scrn ;clear screen call curs ;set cursor call openran ;open file call errcde ;valid open,cmp errcde, 0 ;valid open? jnz exit ;not, exitcallsub: call recnum ;request record # cmp actlen, 0 ;any more request? je exit ;no, exit call readran ;read disk record cmp errcde, 0 ;normal read? jnz next ;no, bypass call disp ;yes, display namenext: jmp callsub ;continueexit mov ax, 4c00h ;end processing int 21h,main endp;-;open fileopenran proc near mov ah, 3dh ;request open mov al, 0 ;normal file lea dx, pathnam int 21h jc errm1 ;error?,mov handle, ax ;no, save handl
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 知识付费培训合作方案课件
- 铁岭市应急知识培训课件
- 铁东区燃气安全知识培训课件
- 钳工工艺基础知识培训课件
- 知识产权挖掘培训证书课件
- 钳工基础知识培训课件下载
- 钧瓷鉴定课件
- 知识产权培训领导致辞课件
- 2025年在线教育平台教学质量评估与学习效果反馈机制研究
- 2025年安全员考试题库及答案
- 驿站快递合同协议书
- 《新型主动脉夹层护理策略》课件
- 2025年人教版小学五年级下册奥林匹克数学竞赛试卷(附参考答案)
- 食品企业的自查自纠工作应如何开展 试题及答案
- 《箱式快装建筑设计、施工、验收规程》
- 固态电池成本控制-全面剖析
- 气道异物梗阻的急救
- 贵州省黔东南州2025年六年级下学期小升初招生数学试卷含解析
- 《企业财务舞弊探究的国内外文献综述》9000字
- 医院感染的疾病监测和报告制度
- 《食源性疾病与营养健康》课件
评论
0/150
提交评论