[net.micro.pc] Write protecting a file in DOS?

keifer@uiucdcs.CS.UIUC.EDU (12/02/85)

Field 3 (byte offset 11) of the file directory entry, bit 0 controls
write protection.  Turn this bit on for write-protect (read-only).

directory entry:
 Field  Offset  Desc.    
   1      0      File name
   2      8      fielanem extension
   3      11     attribute
   etc.

Attribute Byte:
	76543210
	.......1 Read-only
	......1. Hidden
	.....1.. System
	....1... Volume label
	...1.... subdirectory
	..1..... archive
	.1...... unused
	1....... unused

This information is from Peter Norton's "Programmer's Guide to the IBM
PC" (a swell book).

	G. P. Seaburg
	c/o K. Keifer
	Univ. of Illinois

bill@hp-pcd.UUCP (bill) (12/02/85)

All you need to do is set the file's Read-Only attribute bit.
The easiest way to do this is to use one of the many available
programs that let you monkey with file attributes -- CHMODE (aka CHMOD)
is probably the most popular; TCHMOD is another I know of, as well as
one of the programs that comes with the Norton Utilities (I forget
its name, I think it's FA.COM or something like that).  With CHMODE,
you just say
		chmode +r filename

Kind of like the way you'd do it with Unix.

If you want to do it programmatically, there's a dos function called
Get/Set Attribute.  Unfortunately, I don't have its specifics in front
of me so I'll leave it to someone else to describe it to you, or you
can look it up in any handy-dandy MS-DOS Programmer's Reference Manual ...

bill frolik
hp-pcd!bill