home *** CD-ROM | disk | FTP | other *** search
- ;-------------------------------------------------------------------;
- ; FileFitr.asm v0.13 11/17/91 ;
- ;-------------------------------------------------------------------;
- ; Utility to return an errorlevel based upon a comparison of the ;
- ; size of a file specified on the command line as compared to free ;
- ; diskspace on the specified disk drive. ;
- ; ;
- ; Program handles drive_not_ready errors, file_not_found errors, ;
- ; and non-existent_drive_errors. Also, program is smart enough to ;
- ; view filesizes in terms of cluster size of target drive. This ;
- ; ensures that the returned errorlevel is accurate. ;
- ; ;
- ; Syntax: FileFitr [d:][\path][filename] <drive> ;
- ; ;
- ; [filename] may contain a drive and/or path specification and ;
- ; refers to a single file, or a fileset when wildcards ;
- ; are used. ;
- ; ;
- ; [drive] the disk drive to inspect for freespace and then compare ;
- ; the file's size against. If not specified, defaults to ;
- ; current default drive. ;
- ; ;
- ; Errorlevels returned: ;
- ; ;
- ; errorlevel = 0 0 file copies will fit on disk. ;
- ; errorlevel = 1 1 file copies will fit on disk. ;
- ; errorlevel = 2 2 file copies will fit on disk. ;
- ; errorlevel = 3 3 file copies will fit on disk. ;
- ; ... ;
- ; errorlevel = 10 10 file copies will fit on disk. ;
- ; ... ;
- ; errorlevel = 163 163 file copies will fit on disk. ;
- ; ... ;
- ; errorlevel = 249 249 (or more) file copies will fit on disk. ;
- ; ... ;
- ; errorlevel = 250 reserved for future error ;
- ; errorlevel = 251 reserved for future error ;
- ; ;
- ; errorlevel = 252 source file not found ;
- ; errorlevel = 253 source drive not ready ;
- ; errorlevel = 254 target drive not ready ;
- ; errorlevel = 255 user error / help request ;
- ; ;
- ; Notes: ;
- ; As coded, this program can deal with disks with up to 65,535 ;
- ; free clusters (which might reasonably represent 32mb for 512 ;
- ; byte clusters, up through about 524mb for 8kb clusters. This ;
- ; should suit the needs of most people. :-) ;
- ; ;
- ; Also, by the same token, this program can only process batches ;
- ; of files which total less than 65535 clusters. Once again, not ;
- ; a problem. ;
- ; ;
- ;-------------------------------------------------------------------;
- ; v0.10 10/16/91 initial coding (modification of compsize.asm) ;
- ; v0.11 10/17/91 added full wildcard totalling ability. ;
- ; v0.12 10/18/91 added discrete file/disk error code returns. ;
- ; fixed minor bug in chekflop routine. ;
- ; v0.13 11/17/91 added drive reset to chekflop routine (thanks to ;
- ; Mark Tutt of FidoNet 1:363/88) ;
- ; ;
- ;-------------------------------------------------------------------;
- ; <Legal Status> ;
- ; In the spirit of cooperation and education within the computing ;
- ; community, and in the hope that someone may benefit: ;
- ; ;
- ; This program is released into the Public Domain. ;
- ; ;
- ; Please don't abuse this concept of sharing of information. ;
- ; ;
- ;-------------------------------------------------------------------;
- ; <General Disclaimer> ;
- ; Please note that this program was written for my personal use ;
- ; and that I am not a professional programmer. Thus, although I ;
- ; have made every effort to ensure that the code is bug free and ;
- ; performs as advertised, I can make no guarantees of suitability ;
- ; or performance - use at your own risk! ;
- ; ;
- ; In any case, this source code is provided for your inspection, ;
- ; enlightenment, and/or general amusement. ;
- ; ;
- ; I welcome any and all comments, criticisms, suggestions, or bug ;
- ; reports at the address below. ;
- ; ;
- ;-------------------------------------------------------------------;
- ; Written for and assembled under Microsoft QuickC ver 2.01 ;
- ; (Should also assemble under Masm with no problems) ;
- ;-------------------------------------------------------------------;
- ; Bruce Desmond Sacramento, Ca. Fidonet (1:203/39.9) ;
- ;-------------------------------------------------------------------;
-
- ; Directives
-
- _TEXT segment word public 'CODE'
- assume cs:_TEXT, ds:_TEXT
- org 100h
-
- ;-------------------------------------------------------------------;
- ; Extract [filespec] and [size] from PSP
- ;-------------------------------------------------------------------;
-
- first: mov di,offset fspb ;initialize dynamic filespec buff
- mov al,0
- mov cx,128 ;want 128 bytes of nuls
- rep stosb
-
- ;-------------------------------------------------------------------;
- ; Strip off leading spaces and check parms s'more
- ;-------------------------------------------------------------------;
-
- ffsp: mov si,80h ;if no filespec then show help
- cld
- lodsb ;and bail out
- cmp al,0
- jna died
-
- llup: mov dl,[si] ;get a char
- cmp dl,13 ;is it a CR? (uhoh!)
- je died
-
- cmp dl,32 ;leading space? (trash it)
- jne gfil
- inc si
- jmp llup ;keep looping until valid char
-
- ;-------------------------------------------------------------------;
- ; Extract any passed [filespec] from PSP
- ;-------------------------------------------------------------------;
-
- gfil: mov di,0 ;initialize write counter to 0
- mov bx,offset fspb ;start of filespec buffer
- flup: mov dl,[si] ;get a char
- inc si
- cmp dl,13 ;is it a CR?
- je chkdrv
- cmp dl,32 ;trailing space? (end of spec)
- je gots
-
- ;wildcard rejection code is right here. uncomment next 4 lines
- ;to not permit use of wildcards in filespec.
-
- ; cmp dl,'*' ;is it a wildcard?
- ; je died ;(Wildcards are verboten)
- ; cmp dl,'?' ;is it a wildcard?
- ; je died
-
- mov [bx+di],dl ;write char to data buffer
- inc di
- jmp flup
-
- gots: cmp di,0 ;check again for passed filespec
- ja zlup
-
- ;-------------------------------------------------------------------;
- died: mov ah,9 ;crashed, burned, mangled beyond
- mov dx,offset help ;recognition. Say "bye-bye"...
- int 21h
- jmp done
-
- ;-------------------------------------------------------------------;
- ; Extract any passed [drive] from PSP
- ;-------------------------------------------------------------------;
-
- zlup: mov cl,[si] ;get a char
- inc si
-
- cmp cl,13 ;is it a CR? (done!)
- je chkdrv
-
- cmp cl,32 ;leading or trailing space? (skip)
- je zlup
-
- or cl,32 ;lowercase it
-
- cmp cl,97 ;at least an 'a' ?
- jb died
-
- cmp cl,122 ;no more than a 'z' ?
- ja died
-
- mov nulbuf,cl ;prepend drive letter to buffer
-
- sub cl,96 ;resolve to digit (A=1, B=2, etc)
-
- mov driv,cl ;store drive letter
-
- ;-------------------------------------------------------------------;
- ; check if [drive] is drive A or B (a floppy). check drive ready
- ;-------------------------------------------------------------------;
-
- chkdrv: mov di,offset nulbuf ;check [disk_drive]
- call chekflop
- jnc chkfil
- mov byte ptr [ecode],254 ;load target drive error code
- jmp done
-
- ;-------------------------------------------------------------------;
- ; check if [filename] has a drive A or B (a floppy). check drive ready
- ;-------------------------------------------------------------------;
-
- chkfil: mov di,offset fspb ;check [filename]
- call chekflop
- jnc getfsp
- mov byte ptr [ecode],253 ;load source drive error code
- jmp short done
-
- ;-------------------------------------------------------------------;
- ; Get freespace of specified drive
- ;-------------------------------------------------------------------;
- getfsp: mov ah,36h ;get disk free space
- mov dl,driv ;retrieve drive desired
- int 21h
-
- cmp ax,0ffffh ;did error occur?
- jne clusmat
- mov byte ptr [ecode],254 ;load target drive error code
- jmp short done ;bad juju!
-
- clusmat: xor dx,dx ;byte/clust = sect/clust * byte/sect
- mul cx ;sector/cluster * byte/sector
-
- mov clsize,ax ;store cluster size
- mov freecl,bx ;store free clusters
-
- ;-------------------------------------------------------------------;
- ; Search for first file match (trick to check exist and get size)
- ;-------------------------------------------------------------------;
-
- fndfil: mov dx,offset fspb ;location of filespec
- mov cx,00000110b ;any combination of H,S,A,R attribs
- mov ah,4eh ;find first match
- int 21h
- jnc addtot
- mov byte ptr [ecode],252 ;load file not found error code
- jmp short done ;if bad filespec or no files exit
-
- addtot: call getsize ;retrieve filesize
- add sitot,ax ;lump in returned filesize
-
- ;-------------------------------------------------------------------;
- ; Search for next file match (trick to check exist and get size)
- ;-------------------------------------------------------------------;
-
- fndnxt: mov ah,4fh ;find next match
- int 21h
- jc cmpsize ;if no more files then finish up
-
- call getsize ;retrieve filesize
- add sitot,ax ;lump in returned filesize
-
- jmp short fndnxt
-
- ;-------------------------------------------------------------------;
- ; Compare filesize total (in sitot) to freespace (in freecl)
- ;-------------------------------------------------------------------;
-
- cmpsize: mov bx,sitot ;retreive clust/file total
-
- cmp bx,0 ;is filesize zero?
- ja cmpclu
-
- mov al,249 ;load return code
- jmp short prebail
-
- cmpclu: mov ax,freecl ;retrieve free clusters
- xor dx,dx
- div bx ;files_per_disk = freeclust/clus_per_file
-
- cmp ax,249 ;change any number over 249 to 249
- jna prebail
- mov al,249
-
- prebail: mov ecode,al
-
- ;-------------------------------------------------------------------;
- ; Bail out with errorlevel
- ;-------------------------------------------------------------------;
-
- done: mov al,ecode ;retreive errorlevel
- mov ah,04ch ;exit with errorlevel
- int 21h
-
- ;-------------------------------------------------------------------;
- ; function getsize Retrieve found filesize (from DTA).
- ; Filesize returned in AX
- ;-------------------------------------------------------------------;
-
- getsize proc near
-
- mov bx,09ah ;offset in DTA of 4byte filesize
-
- mov dx,word ptr[bx+2] ;get high word
- mov ax,word ptr[bx] ;get low word
-
- div clsize ;clust/file = filesize/clustersize
- ;remember that integral clusters are
- ;allocated for file storage
-
- cmp dx,0 ;any leftovers?
- je norndup
- inc ax ;bump to next even cluster
-
- norndup: ret
-
- getsize endp
-
-
- ;-------------------------------------------------------------------;
- ; function chekflop check drive in passed string pointed at by di
- ; returns: CF set if error
- ;-------------------------------------------------------------------;
- chekflop proc near
-
- mov dx,[di] ;grab first 2 bytes
-
- cmp dh,':' ;drive designator?
- jne nodrive
-
- and dl,0dfh ;uppercase
- sub dl,65 ;drive digit (0-25d)
-
- cmp dl,1 ;ignore hard disks
- ja nodrive
-
- mov cl,1 ;sector 1
- mov ch,0 ;track 0
- mov dh,0 ;side 0
-
- mov ah,4
- int 13h ;verify sector
-
- jnc nodrive ;drive was ok
-
- mov ah,0 ;reset drive
- int 13h
-
- stc
- ret
-
- nodrive: clc
- ret
-
- chekflop endp
-
- ;-------------------------------------------------------------------;
- ; Equates
- ;-------------------------------------------------------------------;
-
- ;-------------------------------------------------------------------;
- ; Data buffer(s)
- ;-------------------------------------------------------------------;
- nulbuf db 0,':\nul' ;target drive check buffer
-
- freecl dw 0 ;free clusters
- clsize dw 0 ;cluster size
- sitot dw 0 ;clusters/file total
-
- ecode db 255 ;errorlevel to return
-
- driv db 0 ;default drive number
-
- help db 13,10,13,10
- db 'FileFitr.com v0.13 11/17/91 '
- db 'errorlevel for compare of filesize(s) to freespace',13,10
- db ' Released to the PUBLIC DOMAIN by Bruce Desmond (1:203/39.9)',13,10,13,10
- db 'Syntax: FileFitr [d:][\path][filename] <drive>',13,10,13,10
- db '[filename] - compare size of file(s) to freespace. If wildcards'
- db 13,10
- db ' (* and/or ?) used, all matches totaled and compared.'
- db 13,10,13,10
- db '<drive> - inspect this drive and compare size[filename] to freespace.'
- db 13,10
- db ' If not specified, current default disk is used.'
- db 13,10,13,10
- db 'Errorlevels:',13,10,13,10
- db ' 0 = 0 file copies will fit on disk',13,10
- db ' ...',13,10
- db ' 137 = 137 file copies will fit on disk',13,10
- db ' ...',13,10
- db ' 249 = 249 (or more) file copies will fit on disk',13,10
- db ' ...',13,10
- db ' 250 = reserved 251 = reserved',13,10
- db ' 252 = source file not found 253 = source drive not ready',13,10
- db ' 254 = target drive not ready 255 = syntax error or help request'
- db 13,10,'$'
-
- fspb db 0 ;Dynamic Filespec data buffer
-
- ;-------------------------------------------------------------------;
-
- _TEXT ends
- end first
- ;-----------------------------end-of-code---------------------------;