Re: determine volume serial number
- Posted by Craig Gilbert <cgilbert at CENNET.MC.PEACHNET.EDU> Jan 02, 1998
- 874 views
Here is a translation of the Power Basic file David Cuny contributed. It seems to work okay on my computer. ------------------cut here---------- include machine.e include wildcard.e ------------------------------------------------------------------------------ global function GetDiskID(sequence Drive) -- return volume label, serial number, and filesystem in sequence -- translated from PowerBasic code supplied by David Cuny atom ParaBlock, serNo sequence reg, Serial, Volume, FileSy object retVal -- here's the parameter block layout; -- note that you can't really index ParaBlock this way . . . -- TYPE ParaBlock -- Info AS INTEGER ParaBlock[1..2] -- SerNo AS LONG ParaBlock[3..6] -- Label AS STRING * 11 ParaBlock[7..17] -- FileSys AS STRING * 8 ParaBlock[18..25] -- END TYPE ParaBlock = allocate_low(25) -- Buffer for drive parameter block lock_memory(ParaBlock,25) -- can't remember if this is necessary -- with low memory but it doesn't seem -- to hurt poke(ParaBlock,repeat(0,25)) -- Information level always zero, -- plus clear rest of block reg = repeat(0,10) reg[REG_AX] = #440D -- Generic IOCTL device request if length(Drive) != 1 then -- If no drive specified reg[REG_BX] = 0 -- then use default else -- Otherwise convert reg[REG_BX] = upper(Drive[1]) - '@'-- drive letter to number end if -- A: = 1, B: = 2 etc reg[REG_CX] = #866 -- Subfunction: get drive ID reg[REG_DS] = floor(ParaBlock/16) -- Segment of buffer reg[REG_DX] = remainder(ParaBlock,16) -- Offset of buffer reg = dos_interrupt(#21,reg) -- Invoke DOS if and_bits(1, reg[REG_FLAGS]) != 1 then -- everything OK serNo = bytes_to_int(peek({ParaBlock+2,4})) Serial = sprintf("%x",{serNo}) -- Get serial number Volume = peek({ParaBlock+6,11}) -- Get volume label FileSy = peek({ParaBlock+17,8}) -- Get file system type retVal = {Serial, Volume, FileSy} else retVal = reg[REG_AX] -- DOS error code end if free_low(ParaBlock) return retVal end function ------------------------------------------------------------------------------ procedure test() object ret ret = GetDiskID("c") if atom(ret) then printf(1,"Sorry, an error occurred:Dos Error Code = %d\n",{ret}) abort(1) else puts(1,"Disk information for drive C\n") puts(1,"----------------------------\n") printf(1,"Volume label : %s\n",{ret[2]}) printf(1,"Serial number : %s\n",{ret[1]}) printf(1,"File system : %s\n",{ret[3]}) end if end procedure ------------------------################## test() =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- J. Craig Gilbert cgilbert at mc.peachnet.edu "Positing infinity, the rest is easy." Roger Zelazny, in 'Creatures of Light and Darkness' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-