home *** CD-ROM | disk | FTP | other *** search
- 'This is to test volume label setting and reading (28/11/90).Much of this
- 'work is based on Dave Skalick's DOS-FUNC.PF3 - however I was having problems
- 'with volume names. In particular, I wanted to read a volume name, and if possible
- 'set it or change it.
-
- '*****************************************************************
- 'I have had some problems getting these to work. Any thought or input on
- 'this subject would be of interest to many of us.
- 'Please leave messages addressed to DAVID TOPPS on Artist BBS.
- '*****************************************************************
-
- 'Firstly I have been unable to get attrib() to read a volume name. It is included
- 'here in a slightly trimmed form but the original version does not work either ( for me).
- 'Now it's probably because I'm not using the correct syntax. Some pointers on
- 'how to do this would be helpful.
-
- 'Using filestat() as a starting point, I adapted a routine from Ray Duncan's
- 'book "Advanced MSDOS",Ed 1,p158, to write a function which will read the
- 'volume name. This seems to work ok. It uses File handles.
-
- 'Now on p158 of the same book, he gives an example of doing much the same
- 'thing but using FCB's. Now this is important, since one must use extended
- 'FCB's to modify a volume name. I tried to adapt read_vol_hndl(), using the
- 'example on p158 (Hope you have that book so you can see what I'm referring
- 'to) but I can't get it to work. it is below as : read_vol_fcb()
- 'I think that one of the problems may be getting the function to search the
- 'root directory rather than the current directory. However, it doesn't seem
- 'to work even when run from the root directory.
-
- 'write_vol() was to have been based on the comments in the book, seen on
- 'p158-9. However, if I can't get past the point of finding the volume name
- 'using FCB's then there is not much point in continuing.
-
- 'Anyone any ideas on how to do this?
- '*****************************************************************
-
- PUBLIC attrib(2) write_vol() read_vol_fcb() read_vol_hndl()
-
- FUNCTION attrib(f_name,new_att)
- '============================================================================
- 'Written by Dave Skalick
- '----------------------------------------------------------------------------
- 'This function will read or set the attributes for any file.
- '
- ' f_name -- is the file to read/set the attributes on
- ' new_att -- New attributes to set the file to ("" just reads attribute)
- ' "a" -- archive
- ' "d" -- directory
- ' "h" -- hidden
- ' "n" -- none
- ' "r" -- read-only
- ' "s" -- system
- ' "v" -- volume label
- '*****************************************************************
- 'NOTE:You cannot set "d" or "v" using this function. For further information
- 'on this see Ray Duncan's "Advanced MSDOS", p158 and also the section on function 0x43.
- '============================================================================
- LOCAL ax_reg,cx_reg,f_mem,ret_val,seg,offset,flags_reg,r_w
-
- cx_reg=0
-
- IF new_att=""
- r_w=0
- ELSE
- r_w=1
- END IF
-
- new_att=LOWER(new_att)
- IF r_w AND (new_att!"a" OR new_att!"s" OR new_att!"h" OR new_att!"r" OR new_att="")
- IF LOWER(new_att)!"a"
- cx_reg=cx_reg+32
- END IF
- IF LOWER(new_att)!"s"
- cx_reg=cx_reg+4
- END IF
- IF LOWER(new_att)!"h"
- cx_reg=cx_reg+2
- END IF
- IF LOWER(new_att)!"r"
- cx_reg=cx_reg+1
- END IF
- IF LOWER(new_att)!"n"
- cx_reg=cx_reg+0
- END IF
- END IF
-
- '--- setup and pack file name in memory location ---
- MEMALLOC f_mem SIZEOF "35s"
- MEMPACK f_mem "35s" f_name
-
- '--- determine current segment and offset of filename memory location ---
- seg=f_mem/65536
- offset=MOD(f_mem,65536)
-
- '--- set segment and offset in registers for filename ---
- SETREG(DS,seg)
- SETREG(DX,offset)
-
- '--- free filename memory ---
- MEMFREE f_mem
-
- '--- set ah with service number (hex:0x43 -- dec:17152) --- get/set atributes
- ax_reg=17152
-
- '--- r_w=0 then read attributes -- r_w=1 then set cx reg with new attr ---
- IF r_w=1
- ax_reg=ax_reg+1
- SETREG(CX,cx_reg)
- END IF
-
- '--- set ax register for attribute and call interrupt 21 ---
- SETREG(AX,ax_reg)
- INTERRUPT 0x21
-
- '--- check for error ---
- flags_reg=GETREG(FLAGS)
- IF BITAND(flags_reg,1)=1
- RETURN(0)
- END IF
-
- IF r_w=1
- '--- if no error on write then return true ---
- RETURN(1)
- ELSE
- '--- if request for attribute then get current attribute setting ---
- cx_reg=GETREG(CX)
-
- ret_val=""
-
- '--- archive ---
- IF BITAND(cx_reg,32)=32
- ret_val=ret_val|"A"
- END IF
-
- '--- directory ---
- IF BITAND(cx_reg,16)=16
- ret_val=ret_val|"D"
- END IF
-
- '--- volume ---
- IF BITAND(cx_reg,8)=8
- ret_val=ret_val|"V"
- END IF
-
- '--- system ---
- IF BITAND(cx_reg,4)=4
- ret_val=ret_val|"S"
- END IF
-
- '--- hidden ---
- IF BITAND(cx_reg,2)=2
- ret_val=ret_val|"H"
- END IF
-
- '--- read-only ---
- IF BITAND(cx_reg,1)=1
- ret_val=ret_val|"R"
- ELSE
- IF LEN(ret_val)=0
- ret_val="N"
- END IF
- END IF
-
- RETURN(ret_val)
-
- END IF
- END FUNCTION
-
- FUNCTION write_vol()
- '*****************************************************************
-
- 'This is to write volume labels using extended FCB's.Not yet started.
- '*****************************************************************
- 'LOCAL
-
- END FUNCTION
-
- FUNCTION read_vol_hndl( drive)
- 'This is to read a volume with File handle functions. Uses filestat()
- 'from dos_func.pf3 as a starting point.Also uses framework from p158 of
- 'Ray Duncan. Yes this works well.Can set a drive.
-
- local ax_reg,dx_reg,es_reg,flag_reg
- local old_es,old_bx
- local f_mem,dta_mem
- local seg,offset
- local _a,_t,_d,_s,_at,_f
-
- IF NOT( ISSTRING( drive))
- MESSAGE "read_vol_hndl() needs a letter for the argument.Aborted"
- RETURN(-1)
- END IF
- IF LEN( drive)>1
- MESSAGE "read_vol_hndl() needs a single letter for the argument.Aborted"
- RETURN(-1)
- END IF
-
- '--- setup and pack file name in memory location ---
- memalloc f_mem sizeof "10s"
- mempack f_mem "10s" drive|":\*.*"
- 'mempack f_mem "10s" f_name
-
- '--- setup new memory location for dta ---
- memalloc dta_mem size 128
-
- '--- call for current dta location ---
- setreg(ax,0x2F00)
- interrupt 0x21
-
- '--- store current dta location ---
- old_es=getreg(es)
- old_bx=getreg(bx)
-
- '--- determine current segment and offset of dta memory location ---
- seg=dta_mem/65536
- offset=mod(dta_mem,65536)
-
- '--- set segement and offset in registers for new dta ---
- setreg(ds,seg)
- setreg(dx,offset)
-
- '--- set service number for new dta location and call interupt 21 ---
- setreg(ax,0x1A00)
- interrupt 0x21
-
- '--- determine current segment and offset of filename memory location ---
- seg=f_mem/65536
- offset=mod(f_mem,65536)
-
- '--- set segement and offset in registers for filename ---
- setreg(ds,seg)
- setreg(dx,offset)
-
- '--- set cx for matching vol attributes ---
- setreg(cx,0x0008)
-
- '--- set service number to find file and store information in dta location ---
- setreg(ax,0x4E00)
- interrupt 0x21
-
- '--- get the result code from 4E call ---
- flag_reg=getreg(flags)
-
- '--- set segment and offset in registers of original dta ---
- setreg(ds,old_es)
- setreg(dx,old_bx)
-
- '--- set service number for original dta location and call interupt 21 ---
- setreg(ax,0x1A00)
- interrupt 0x21
-
- '--- free filename memory ---
- memfree f_mem
-
- '--- if error from "find first file" function then exit with error message ---
- if bitand(flag_reg,1)=1
- errormessage 7 "File not found"
- return(0)
- end if
-
- '--- unpack dta for attribute, time, date,size & volume name then clear memory---
- memunpack dta_mem "21xbwwl13s" _a _t _d _s _f
- memfree dta_mem
-
- '--- file name and extention ---
- return(_f)
-
- END FUNCTION
-
- FUNCTION read_vol_fcb( drive)
- 'This is to read volume labels using extended FCB's.Uses filestat()
- 'from dos_func.pf3 as a starting point.Also uses framework from p157 of
- 'Ray Duncan. This does not work. It fails during the find first match.
- 'I suspect that this is because you are not in the root directory.Try it there.
- 'No it does not work in the \ either. There does not seem to be a way of
- 'specifying a directory when using FCB's. On p159 in Ray Duncan's book, it
- 'suggests that the volume label will always be added to the root dir, no
- 'matter what the current directory is. However, this will not help if you can't
- 'get beyond the function 0x11 find-first without failing. Is my syntax wrong?
-
- local ax_reg,dx_reg,es_reg,flag_reg
- local old_es,old_bx
- local f_mem,dta_mem
- local seg,offset
- local _a _t _d _s _at _f drive_code wildcard
-
- IF NOT( ISSTRING( drive))
- MESSAGE "read_vol_hndl() needs a letter for the argument.Aborted"
- RETURN(-1)
- END IF
- IF LEN( drive)>1
- MESSAGE "read_vol_hndl() needs a single letter for the argument.Aborted"
- RETURN(-1)
- END IF
-
- drive_code = CHR( ASC( UPPER(drive))-64)
- wildcard = REPEAT("?",11)
- 'wildcard = "\*.*" --does not help
-
- '--- setup and pack file name in memory location ---
- memalloc f_mem sizeof "64s"
- mempack f_mem "B5ZBB11S25Z" CHR(0xFF) CHR(8) drive_code wildcard
-
- '--- setup new memory location for dta ---
- memalloc dta_mem size 128
-
- '--- call for current dta location ---
- setreg(ax,0x2F00)
- interrupt 0x21
-
- '--- store current dta location ---
- old_es=getreg(es)
- old_bx=getreg(bx)
-
- '--- determine current segment and offset of dta memory location ---
- seg=dta_mem/65536
- offset=mod(dta_mem,65536)
-
- '--- set segement and offset in registers for new dta ---
- setreg(ds,seg)
- setreg(dx,offset)
-
- '--- set service number for new dta location and call interupt 21 ---
- setreg(ax,0x1A00)
- interrupt 0x21
-
- '--- determine current segment and offset of filename memory location ---
- seg=f_mem/65536
- offset=mod(f_mem,65536)
-
- '--- set segment and offset in registers for filename ---
- setreg(ds,seg)
- setreg(dx,offset)
-
- '--- set service number to find first and store information in dta location ---
- setreg(ax,0x1100)
- interrupt 0x21
-
- '--- get the result code from 11 call ---
- ax_reg = GETREG(AX)
-
- '--- set segment and offset in registers of original dta ---
- setreg(ds,old_es)
- setreg(dx,old_bx)
-
- '--- set service number for original dta location and call interupt 21 ---
- setreg(ax,0x1A00)
- interrupt 0x21
-
- '--- free filename memory ---
- memfree f_mem
-
- '--- if error from "find first file" function then exit with error message ---
- IF BITAND( ax_reg,0xFF) <> 0
- 'IF ah = 255
- MESSAGE "No match found. ax_reg is" & STR( ax_reg) & STR( BITAND( ax_reg,0xFF))
- RETURN(-1)
- ELSE
- 'continue
- END IF
-
- '--- unpack dta for attribute, time, date,size & volume name then clear memory---
- memunpack dta_mem "6xbb11s" _a _d _f '_a is attribute byte,_d is drive byte
- memfree dta_mem
-
- '--- file name and extention ---
- return(_f)
-
- END FUNCTION
-
-