home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DOS_HELP / VOL_READ.ZIP / VOLUME2.PF3
Encoding:
Text File  |  1990-11-29  |  10.6 KB  |  371 lines

  1. 'This is to test volume label setting and reading (28/11/90).Much of this
  2. 'work is based on Dave Skalick's DOS-FUNC.PF3 - however I was having problems
  3. 'with volume names. In particular, I wanted to read a volume name, and if possible
  4. 'set it or change it.
  5.  
  6. '*****************************************************************
  7. 'I have had some problems getting these to work. Any thought or input on
  8. 'this subject would be of interest to many of us.
  9. 'Please leave messages addressed to DAVID TOPPS on Artist BBS.
  10. '*****************************************************************
  11.  
  12. 'Firstly I have been unable to get attrib() to read a volume name. It is included
  13. 'here in a slightly trimmed form but the original version does not work either ( for me).
  14. 'Now it's probably because I'm not using the correct syntax. Some pointers on
  15. 'how to do this would be helpful.
  16.  
  17. 'Using filestat() as a starting point, I adapted a routine from Ray Duncan's
  18. 'book "Advanced MSDOS",Ed 1,p158, to write a function which will read the
  19. 'volume name. This seems to work ok. It uses File handles.
  20.  
  21. 'Now on p158 of the same book, he gives an example of doing much the same
  22. 'thing but using FCB's. Now this is important, since one must use extended
  23. 'FCB's to modify a volume name. I tried to adapt read_vol_hndl(), using the 
  24. 'example on p158 (Hope you have that book so you can see what I'm referring
  25. 'to) but I can't get it to work. it is below as : read_vol_fcb()
  26. 'I think that one of the problems may be getting the function to search the
  27. 'root directory rather than the current directory. However, it doesn't seem
  28. 'to work even when run from the root directory.
  29.  
  30. 'write_vol() was to have been based on the comments in the book, seen on
  31. 'p158-9. However, if I can't get past the point of finding the volume name
  32. 'using FCB's then there is not much point in continuing.
  33.  
  34. 'Anyone any ideas on how to do this?
  35. '*****************************************************************
  36.  
  37. PUBLIC attrib(2) write_vol() read_vol_fcb() read_vol_hndl() 
  38.  
  39. FUNCTION attrib(f_name,new_att)
  40. '============================================================================
  41. 'Written by Dave Skalick
  42. '----------------------------------------------------------------------------
  43. 'This function will read or set the attributes for any file.
  44. '
  45. '    f_name -- is the file to read/set the attributes on
  46. '   new_att -- New attributes to set the file to ("" just reads attribute)
  47. '              "a" -- archive
  48. '              "d" -- directory
  49. '              "h" -- hidden
  50. '              "n" -- none
  51. '              "r" -- read-only
  52. '              "s" -- system
  53. '              "v" -- volume label
  54. '*****************************************************************
  55. 'NOTE:You cannot set "d" or "v" using this function. For further information
  56. 'on this see Ray Duncan's "Advanced MSDOS", p158 and also the section on function 0x43.
  57. '============================================================================
  58. LOCAL ax_reg,cx_reg,f_mem,ret_val,seg,offset,flags_reg,r_w
  59.  
  60. cx_reg=0
  61.  
  62. IF new_att=""
  63.    r_w=0
  64. ELSE
  65.    r_w=1
  66. END IF
  67.  
  68. new_att=LOWER(new_att)
  69. IF r_w AND (new_att!"a" OR new_att!"s" OR new_att!"h" OR new_att!"r" OR new_att="")
  70.    IF LOWER(new_att)!"a"
  71.       cx_reg=cx_reg+32
  72.    END IF
  73.    IF LOWER(new_att)!"s"
  74.       cx_reg=cx_reg+4
  75.    END IF
  76.    IF LOWER(new_att)!"h"
  77.       cx_reg=cx_reg+2
  78.    END IF
  79.    IF LOWER(new_att)!"r"
  80.       cx_reg=cx_reg+1
  81.    END IF
  82.    IF LOWER(new_att)!"n"
  83.       cx_reg=cx_reg+0
  84.    END IF
  85. END IF
  86.  
  87. '--- setup and pack file name in memory location ---
  88. MEMALLOC f_mem SIZEOF "35s"
  89. MEMPACK f_mem "35s" f_name
  90.  
  91. '--- determine current segment and offset of filename memory location ---
  92. seg=f_mem/65536
  93. offset=MOD(f_mem,65536)
  94.  
  95. '--- set segment and offset in registers for filename ---
  96. SETREG(DS,seg)
  97. SETREG(DX,offset)
  98.  
  99. '--- free filename memory ---
  100. MEMFREE f_mem
  101.  
  102. '--- set ah with service number (hex:0x43 -- dec:17152) --- get/set atributes
  103. ax_reg=17152
  104.  
  105. '--- r_w=0 then read attributes -- r_w=1 then set cx reg with new attr ---
  106. IF r_w=1
  107.    ax_reg=ax_reg+1
  108.    SETREG(CX,cx_reg)
  109. END IF
  110.  
  111. '--- set ax register for attribute and call interrupt 21 ---
  112. SETREG(AX,ax_reg)
  113. INTERRUPT 0x21
  114.  
  115. '--- check for error ---
  116. flags_reg=GETREG(FLAGS)
  117. IF BITAND(flags_reg,1)=1
  118.    RETURN(0)
  119. END IF
  120.  
  121. IF r_w=1
  122.    '--- if no error on write then return true ---
  123.    RETURN(1)
  124. ELSE
  125.    '--- if request for attribute then get current attribute setting ---
  126.    cx_reg=GETREG(CX)
  127.  
  128.    ret_val=""
  129.  
  130.    '--- archive ---
  131.    IF BITAND(cx_reg,32)=32
  132.       ret_val=ret_val|"A"
  133.    END IF
  134.  
  135.    '--- directory ---
  136.    IF BITAND(cx_reg,16)=16
  137.       ret_val=ret_val|"D"
  138.    END IF
  139.  
  140.    '--- volume ---
  141.    IF BITAND(cx_reg,8)=8
  142.       ret_val=ret_val|"V"
  143.    END IF
  144.  
  145.    '--- system ---
  146.    IF BITAND(cx_reg,4)=4
  147.       ret_val=ret_val|"S"
  148.    END IF
  149.  
  150.    '--- hidden ---
  151.    IF BITAND(cx_reg,2)=2
  152.       ret_val=ret_val|"H"
  153.    END IF
  154.  
  155.    '--- read-only ---
  156.    IF BITAND(cx_reg,1)=1
  157.       ret_val=ret_val|"R"
  158.    ELSE
  159.       IF LEN(ret_val)=0
  160.          ret_val="N"
  161.       END IF
  162.    END IF
  163.  
  164.    RETURN(ret_val)
  165.  
  166. END IF
  167. END FUNCTION
  168.  
  169. FUNCTION write_vol()
  170. '*****************************************************************
  171.  
  172. 'This is to write volume labels using extended FCB's.Not yet started.
  173. '*****************************************************************
  174. 'LOCAL 
  175.  
  176. END FUNCTION
  177.  
  178. FUNCTION read_vol_hndl( drive)
  179. 'This is to read a volume with File handle functions. Uses filestat()
  180. 'from dos_func.pf3 as a starting point.Also uses framework from p158 of
  181. 'Ray Duncan. Yes this works well.Can set a drive.
  182.  
  183. local ax_reg,dx_reg,es_reg,flag_reg
  184. local old_es,old_bx
  185. local f_mem,dta_mem
  186. local seg,offset
  187. local _a,_t,_d,_s,_at,_f
  188.  
  189. IF NOT( ISSTRING( drive))
  190.     MESSAGE "read_vol_hndl() needs a letter for the argument.Aborted" 
  191.     RETURN(-1)
  192. END IF
  193. IF LEN( drive)>1 
  194.     MESSAGE "read_vol_hndl() needs a single letter for the argument.Aborted"
  195.     RETURN(-1)
  196. END IF
  197.  
  198. '--- setup and pack file name in memory location ---
  199. memalloc f_mem sizeof "10s"
  200. mempack f_mem "10s" drive|":\*.*"
  201. 'mempack f_mem "10s" f_name
  202.  
  203. '--- setup new memory location for dta ---
  204. memalloc dta_mem size 128
  205.  
  206. '--- call for current dta location ---
  207. setreg(ax,0x2F00)
  208. interrupt 0x21
  209.  
  210. '--- store current dta location ---
  211. old_es=getreg(es)
  212. old_bx=getreg(bx)
  213.  
  214. '--- determine current segment and offset of dta memory location ---
  215. seg=dta_mem/65536
  216. offset=mod(dta_mem,65536)
  217.  
  218. '--- set segement and offset in registers for new dta ---
  219. setreg(ds,seg)
  220. setreg(dx,offset)
  221.  
  222. '--- set service number for new dta location and call interupt 21 ---
  223. setreg(ax,0x1A00)
  224. interrupt 0x21
  225.  
  226. '--- determine current segment and offset of filename memory location ---
  227. seg=f_mem/65536
  228. offset=mod(f_mem,65536)
  229.  
  230. '--- set segement and offset in registers for filename ---
  231. setreg(ds,seg)
  232. setreg(dx,offset)
  233.  
  234. '--- set cx for matching vol attributes ---
  235. setreg(cx,0x0008)
  236.  
  237. '--- set service number to find file and store information in dta location ---
  238. setreg(ax,0x4E00)
  239. interrupt 0x21
  240.  
  241. '--- get the result code from 4E call ---
  242. flag_reg=getreg(flags)
  243.  
  244. '--- set segment and offset in registers of original dta ---
  245. setreg(ds,old_es)
  246. setreg(dx,old_bx)
  247.  
  248. '--- set service number for original dta location and call interupt 21 ---
  249. setreg(ax,0x1A00)
  250. interrupt 0x21
  251.  
  252. '--- free filename memory ---
  253. memfree f_mem
  254.  
  255. '--- if error from "find first file" function then exit with error message ---
  256. if bitand(flag_reg,1)=1
  257.    errormessage 7 "File not found"
  258.    return(0)
  259. end if
  260.  
  261. '--- unpack dta for attribute, time, date,size & volume name then clear memory---
  262. memunpack dta_mem "21xbwwl13s" _a _t _d _s _f
  263. memfree dta_mem
  264.  
  265. '--- file name and extention ---
  266. return(_f)
  267.  
  268. END FUNCTION
  269.  
  270. FUNCTION read_vol_fcb( drive)
  271. 'This is to read volume labels using extended FCB's.Uses filestat()
  272. 'from dos_func.pf3 as a starting point.Also uses framework from p157 of
  273. 'Ray Duncan. This does not work. It fails during the find first match.
  274. 'I suspect that this is because you are not in the root directory.Try it there.
  275. 'No it does not work in the \ either. There does not seem to be a way of 
  276. 'specifying a directory when using FCB's. On p159 in Ray Duncan's book, it
  277. 'suggests that the volume label will always be added to the root dir, no
  278. 'matter what the current directory is. However, this will not help if you can't
  279. 'get beyond the function 0x11 find-first without failing. Is my syntax wrong?
  280.  
  281. local ax_reg,dx_reg,es_reg,flag_reg
  282. local old_es,old_bx
  283. local f_mem,dta_mem
  284. local seg,offset
  285. local _a _t _d _s _at _f drive_code wildcard 
  286.  
  287. IF NOT( ISSTRING( drive))
  288.     MESSAGE "read_vol_hndl() needs a letter for the argument.Aborted" 
  289.     RETURN(-1)
  290. END IF
  291. IF LEN( drive)>1 
  292.     MESSAGE "read_vol_hndl() needs a single letter for the argument.Aborted"
  293.     RETURN(-1)
  294. END IF
  295.  
  296. drive_code = CHR( ASC( UPPER(drive))-64)
  297. wildcard = REPEAT("?",11)
  298. 'wildcard = "\*.*"    --does not help
  299.  
  300. '--- setup and pack file name in memory location ---
  301. memalloc f_mem sizeof "64s"
  302. mempack f_mem "B5ZBB11S25Z" CHR(0xFF) CHR(8) drive_code wildcard
  303.  
  304. '--- setup new memory location for dta ---
  305. memalloc dta_mem size 128
  306.  
  307. '--- call for current dta location ---
  308. setreg(ax,0x2F00)
  309. interrupt 0x21
  310.  
  311. '--- store current dta location ---
  312. old_es=getreg(es)
  313. old_bx=getreg(bx)
  314.  
  315. '--- determine current segment and offset of dta memory location ---
  316. seg=dta_mem/65536
  317. offset=mod(dta_mem,65536)
  318.  
  319. '--- set segement and offset in registers for new dta ---
  320. setreg(ds,seg)
  321. setreg(dx,offset)
  322.  
  323. '--- set service number for new dta location and call interupt 21 ---
  324. setreg(ax,0x1A00)
  325. interrupt 0x21
  326.  
  327. '--- determine current segment and offset of filename memory location ---
  328. seg=f_mem/65536
  329. offset=mod(f_mem,65536)
  330.  
  331. '--- set segment and offset in registers for filename ---
  332. setreg(ds,seg)
  333. setreg(dx,offset)
  334.  
  335. '--- set service number to find first and store information in dta location ---
  336. setreg(ax,0x1100)
  337. interrupt 0x21
  338.  
  339. '--- get the result code from 11 call ---
  340. ax_reg = GETREG(AX)
  341.  
  342. '--- set segment and offset in registers of original dta ---
  343. setreg(ds,old_es)
  344. setreg(dx,old_bx)
  345.  
  346. '--- set service number for original dta location and call interupt 21 ---
  347. setreg(ax,0x1A00)
  348. interrupt 0x21
  349.  
  350. '--- free filename memory ---
  351. memfree f_mem
  352.  
  353. '--- if error from "find first file" function then exit with error message ---
  354. IF BITAND( ax_reg,0xFF) <> 0
  355. 'IF ah = 255
  356.     MESSAGE "No match found. ax_reg is" & STR( ax_reg) & STR( BITAND( ax_reg,0xFF))
  357.     RETURN(-1)
  358. ELSE 
  359.     'continue
  360. END IF
  361.  
  362. '--- unpack dta for attribute, time, date,size & volume name then clear memory---
  363. memunpack dta_mem "6xbb11s" _a _d _f    '_a is attribute byte,_d is drive byte
  364. memfree dta_mem
  365.  
  366. '--- file name and extention ---
  367. return(_f)
  368.  
  369. END FUNCTION
  370.  
  371.