Re: [PATCH] Speeding up FAT operations

Richard B. Johnson (root@chaos.analogic.com)
Thu, 24 Sep 1998 13:47:56 -0400 (EDT)


On 23 Sep 1998, H. Peter Anvin wrote:

> Followup to: <Pine.LNX.3.95.980923084335.832D-100000@chaos.analogic.com>
> By author: "Richard B. Johnson" <root@chaos.analogic.com>
> In newsgroup: linux.dev.kernel
> >
> > > This may not mean much, but two years ago when I first started learning a
> > > computer I was learning QBASIC. And I read a post somewhere of an error in
> > > QBASIC that would allow you to make a space in the name that no other program
> > > could read except another QBASIC program that opened it the same way. It was
> > > something like the following... (I haven't touched it for over a year and a
> > > half so it may not be completely accurate)
> > >
> > > open "blah hi" as binary #1 (or something like this)
> > > print #1, "jkfsdjlkfsdjkl"
> > > close #1
> > >
> > > Then you can open "blah hi" with the QBASIC program again.
> > >
> > > The system never reported it as an error or anything, and it would show up as
> > > a valid file when you did a DIR. In fact, when you got a directory listing,
> > > it would show it with the space.
> > >
> >
> > Yes. A DOS File-System emulator cannot assume that DOS file-names are
> > all in upper case. It also can't assume that it contains "valid"
> > characters. DOS File names are not supposed to contain '.', ' ', etc.,
> > but they can.
> >
>
> Hang on! That's a different thing -- you can't create those files
> with DOS system calls. Space *IS* a legal character in DOS filenames
> -- the system calls will happily accept it, although the shell won't
> (although it will match it against ?).
>
> -hpa

The systems calls will not accept a space even though a MS-DOS file-
name of "1" is really "1 " on the physical disk. Try it.....

pseg segment para public 'code'
assume cs:pseg, ds:pseg, es:pseg, ss:pseg
org 100h
main proc near
jmp short foo
;fname db ' ',0 ; Bad
;fname db 'z',0 ; Okay
;fname db '.',0 ; Bad
;fname db 0e5h,0e5h,0 ; Okay
;fname db 27,'[H',27,'[J',0 ; Bad
;fname db 1,2,3,4,5,0 ; Bad
;fname db 127,128,129,0 ; Good
fname db '55',248,'C',0 ; Good
badfile db 'Bad file name.',0dh,0ah,'$'
good db 'Good!',0dh,0ah,'$'
main endp
;
foo proc near
mov dx,offset fname ; Point to file name
xor cx,cx ; Normal file attributes
mov ax,3c00h ; MS-DOS Create function
int 21h
jc bad ; Was bad, can't create.
mov bx,ax ; Good, get handle
mov ax,3d00h ; MS-DOS Close function
int 21h
mov dx,offset good ; Point to 'Good' string.
jmp short prnt ; Print and exit

bad: mov dx,offset badfile ; Point to bad file name string
prnt: mov ax,0900h ; MS-DOS print-string
int 21h
quit: mov ax,4c00h ; MS-DOS exit normal
int 21h
foo endp
;
pseg ends
end main

What GWBASIC used to do was create a file using the FCB function call
0x16. Then, since it had the original File-Control-Block in its
address-space, it would put any characters it wanted, including
lower-case, in the FCB when it closed it. This is what got written
to the disk. This is also the way Peter Norton 'opened' a directory
as a file so that he could sort its contents.

The original post was a warning that one should not assume that there
are no "incorrect" characters in a MS-DOS file-name. I can easily
create a file called "*.*" and or "???????????", which can cause some
problems with 'rm', etc., although such file-names are usually
'created' during a disk error.

Cheers,
Dick Johnson
***** FILE SYSTEM WAS MODIFIED *****
Penguin : Linux version 2.1.118 on an i586 machine (66.15 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/