News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Stand Test of time ?

Started by Magnum, January 23, 2013, 12:54:58 AM

Previous topic - Next topic

Tedd

Clusters are just groupings of sectors, to make keeping track of them require less space.
So the 'unused' part consists of the sectors allocated to this cluster, and they will contain whatever was left in them from any previous files that occupied those sectors in that cluster.
If you're hoping to erase and leave as little information as possible (while not being destructive to anything else) then you should round up and erase full clusters (even if the file takes one whole byte of a cluster.)
Potato2

dedndave

different operating systems behave a little differently, of course
completely unwritten sectors are likely to have whatever the last file had that used that sector
partially unwritten sectors may be written with remnants from file buffers

thing to do is to find the cluster size for the drive you are writing to
make the file an even number of clusters in size (as Tedd suggested)
write it
then, change it's size

i think sector size is generally 512 bytes
(on older machines, it was the max - not sure that's still true - but 512 is used for backward compatibility)
the cluster size will depend mainly on the size of the partition
many of the partitions i have use 8 kb clusters (16 sectors per cluster)

Magnum

My NTFS is using 4 Kb clusters.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

GetDiskFreeSpace will get it for you
on the old forum, Hutch had a nice little routine for that

Magnum

I don't think that'll work for my 16 bit program, but you never know.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave


FORTRANS

Hi,

   DOS has Function 36H Get Disk Free Space.


INT 21,36   Get Disk Free Space

   Returns the free clusters on the spcified drive.  It also
gets information to calculate the equivalent number of bytes.

INPUT  AH = 36H
       DL = Drive Number

OUTPUT AX = Sectors per Cluster (0FFFFH if error)
       BX = Clusters Available
       CX = Bytes per Sector
       DX = Total Clusters on Disk
]

Regards,

SteveI

Magnum

I think we've strayed from what was suggested.

;; Assuming ES == DS, and CLD has been done

   mov di,offset [random]
   mov cx,64000 / 2
   mov ax,0
   rep stosw

When you overwrite a file, you should probably round up the length to
the next full allocation cluster size (often 4KB, but check!), so that
you get rid of any data remaining in that tail.

If I understand it, I would like to write over the ( file +  the remaining bytes in the partially used cluster)

So if cluster size is 4 Kb x 1024 = 4096 bytes

So if the file is 8000 bytes in size, then are there  192 bytes left to be overwritten too ?

2 clusters x 4096 =  8192 bytes allocated for the file  -  8000 = 192


open_it:

mov ax,716Ch ; create file
xor cx,cx ; file attributes

; file access modes (bits) BX register
; 000 read-only
; 001 write-only
; 010 read-write
; 100 read-only, do not modify file's last-access time

; Bitfields for Windows95 long-name open action: DX Register
; Bit(s) Description (Table 01781)
; 0 open file (fail if file does not exist)
; 1 truncate file if it already exists (fail if file does not exist)
; 4 create new file if file does not already exist (fail if exists)
; Note: the only valid combinations of multiple flags are bits 4&0 and 4&1


mov bx,00000001b ; access mode - write only
mov dx,00000001b ; open file
lea si,file_name + 2 ; sets the file name
int 21h
mov [handle],ax ; Save file handle
jnc short get_size ; No errors, go on

no_file:

mov dx,offset not_there; Get error message
jmp error ; and go display/exit
get_size:
mov ax,4202h ; Set file pointer
mov bx,[handle] ; for this file
xor cx,cx ; relative to end of file
xor dx,dx ; offset 0 bytes
int 21h
jnc save_size

err2:
mov dx,offset emsg2 ; Get error message
jmp error ; and go display/exit

save_size:

mov word ptr [file_size],ax ; Save low word of file size
mov word ptr [file_size + 2],dx ; Save high word

mov ax,4200h ; Move file pointer
mov bx,[handle] ; for this file
xor cx,cx ; relative to beginning of file
xor dx,dx ; offset 0 bytes
int 21h
jc err2 ; Errors: go handle

next_bunch:

mov cx,64000 ; Assume 64,000 bytes or more
; left to do

sub word ptr [file_size],cx ; Is there ? - subtract it
sbb word ptr [file_size + 2],0 ; from saved file size

jae wipe ; There were 64,000 bytes or
; more left

mov cx,word ptr [file_size] ; Get number of bytes left
add cx,64000 ; back CX (undo subtraction)

wipe:

mov ah,40h ; Write file
mov bx,[handle] ; Handle
lea dx,random ; Write the random bytes
int 21h
jnc check_size ; No errors, go on

err3:

mov dx,offset emsg3 ; Get appropriate error message
jmp error ; and go display/exit

check_size:

cmp ax,cx
jnz err3
cmp ax,64000 ; Full 64,000 bytes written,
je next_bunch ; yes, go check for more

jmp SHORT $+2 ; short delay cuz sometimes
; file isn't renamed in a cmd.exe or command.com environment
;

mov bx,[handle] ; close file
mov ah,3eh
int 21h

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

cluster sizes are always powers of 2 - that simplifies the calculation a little bit
    mov     eax,SizeOfMyFile
    add     eax,(ClusterSize-1)
    and     ax,(-ClusterSize)    ;EAX = total bytes to write

or
    mov     edx,ClusterSize
    mov     eax,SizeOfMyFile
    dec     edx
    add     eax,edx
    not     edx
    and     eax,edx              ;EAX = total bytes to write