[comp.sys.ibm.pc] Writing to Directories

dalegass@dalcs.UUCP (01/26/87)

I am working on a utility where I need to be able to write to a directory
entry.  I am able to *read* from a directory file using FINDFIRST and
FINDNEXT ms-dos calls, but I can't find any way to write back to the
directory.  MS-DOS won't allow treating the directory like a file, so
it can not be opened for normal file operations.  (The CHMOD function
call won't allow changing the directory bit, which would have allowed
turning the directory entry into a file entry temporarily.)

I realize this can be done through writing directly to the disk sector
containing the directory entry, but the root directory lies at different spots
on floppies, and different hard disks, so this poses a compatability problem.

If anyone has any suggestions, I would be very thankful.


***************************************************************************
Dale Gass, Dalhousie U., Halifax, N.S., Canada

UUCP:   {seismo|watmath|utai|garfield}!dalcs!dalegass.UUCP
     				       or dalegass@dalcs.UUCP
        ...!dalcs!dalcsug!dalegass.UUCP  or dalegass@dalcsug.UUCP
CDN:    dalegass@cs.dal.cdn
CSNET:  dalegass%cs.dal.cdn@ubc.csnet
ARPA:   dalegass%cs.dal.cdn%ubc.csnet@CSNET-RELAY.ARPA

bill@hpcvlo.UUCP (02/09/87)

You can always find the root directory on a DOS disk by looking at the
Bios Parameter Block in the disk's boot sector:

	Read boot sector (track 0, head 0, sector 1).
	You should see something like the following:

	0000	jmp	somewhere	;3-byte jump instruction

	0003	db	"IBM  3.2"	;8-byte revision string

	000B	dw	512		;(word) Bytes per sector
	000D	db	4		;(byte) Sectors per cluster
	000E	dw	1		;(word) Number of reserved sectors
	0010	db	2		;(byte) Number of FATs
	0011	dw	512		;(word) Number of root dir entires
	0013	dw	41735		;(word) Total sectors on the media
	0015	db	0F8h		;(byte) Media descriptor
	0016	dw	25		;(word) Sectors per FAT
	0018	dw	17		;(word) Sectors per track
	001A	dw	4		;(word) Number of heads
	001C	dw	17		;(word) Number of hidden sectors
	...


	You find the start of the root directory by adding up the following:

		  (Number of FATs)*(Sectors per FAT)
			+   Number of hidden sectors
			+ Number of reserved sectors
		------------------------------------
		=     First sector of root directory

	You can now use the DOS absolute sector read service (Int 25h)
	to read the directory, which will occupy contiguous sectors
	starting with the one you've calculated.


bill frolik
hp-pcd!bill
Hewlett-Packard Portable Computer Division
Corvallis, Oregon