Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

Serial-Number of a Disk

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Serial-Number of a Disk

    Hi everybody,

    how can I get the serial number of a disk, without using
    shell and dir ... in PB 3.5 ???

    Thanks for help.

    Matthias Kuhn



    ------------------

  • #2
    As far as I know, disks don't have serial numbers, per-sey, but
    they do have (optional) volume labels. VL's could be used as
    serial numbers if needed. There are no published functions that
    I know of to extract a disks VL. To get it, you have to use
    DIR$ and it is always located in the root directory. Bit 3 of
    the ATTR byte, if set, indicates a VL and only one is allowed.

    The easiest way is to use: >>> VL$ = dir$("c:\*.*",8) <<<

    There is another,indirect way, by using int21 to get a files
    DTA segment and offset information. Won't publish here since
    the dir$ above should do the trick.

    Hope this helps


    ------------------
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

    Comment


    • #3
      Code:
      Matthias--
         
      I've dusted off the following, which does what you're looking for.
             
      $IF 0
      +--------------------------------------------------------------------------+
      | WESTFORD CUSTOM PC/FX         -*-   DISK_ID.BAS   -*-            4/11/94 |
      | CIS: 76470,2417 |--------------------------------------------------------+
      | 978-692-8163 |--+                                                rev 2/01
      +--------------+
         
      NOTE: The routines contained in this file are intended for use with 
      PB/DOS only.
         
      This file contains the routine DiskID(Drive%, MIDType AS MediaIDType),
      which returns the volume name (if any), serial number, and disk FAT type 
      (12-bit or 16-bit entries) of the specified logical drive.  The DOS call 
      which is used (21h/6900h) is available only with DOS 4.0+, so before 
      calling DiskID, verify the existence of DOS 4.0+ by using the function 
      DOSversion% (also enclosed in this file).
      $ENDIF
         
      $OPTIMIZE SPEED
      $LIB ALL OFF
      '============
      DEFINT A-Z
         
      TYPE MediaIDType
         InfoLevel AS INTEGER
         SerialNum AS DWORD
         VolLabel AS STRING * 11
         FileSysType AS STRING * 8
         ErrorCode AS INTEGER
      END TYPE
      DIM MIDType AS MediaIDType
         
      OSver% = DOSversion%
      major$ = trim$(str$(OSver% AND 255)) : minor$ = trim$(str$(OSver% \ 256))
         
      print
      print "DOS version: "; major$; "."; minor$
      if (OSver% AND 255) < 4 then
         print "Volume and serial number ID requires DOS 4.0+"
         end
      end if
         
      drive% = 0                 '0=default drive, 1=A:, 2=B:, 3=C:, etc.
      call DiskID(drive%, MIDType)
      if istrue(MIDType.ErrorCode) then
         print "DiskID error: DOS error code"; MIDType.ErrorCode
         end
      end if
         
      if isfalse(drive%) then
         d$ = "default"
      else
         d$ = chr$(drive%+64)
      end if
      print "drive: "; d$
         
      highword?? = MidType.SerialNum \ 65536
      lowword?? =  MidType.SerialNum AND 65535
      print "serial number: "; hexword$(highword??);":"; hexword$(lowword??)
      print "volume: "; MIDType.VolLabel
      print MIDType.FileSysType
         
      END
         
      '======================
      SUB DiskID(BYVAL Drive%, MIDType AS MediaIDType)
      LOCAL pMIDType???, ecode%
         
      MIDType.InfoLevel = 0         'DOS requires 0
      pMIDType??? = varptr32(MidType)
      !  push  ds
      !  mov   bx, Drive%           ;drive to check
      !  mov   ch, &h08
      !  mov   cl, &h66             ;get media info
      !  lds   dx, pMIDType???
      '-- ! mov   ax, &h440D        ;requires DOS 3.2+ but can trip critical error
      !  mov   ax, &h6900           ;requires DOS 4.0+
      !  int   &h21
      !  pop   ds
      !  jnc   DiskIDdone
      !  mov   ecode%, ax           ;if error, save error code to MIDtype
      DiskIDdone:
      MIDType.ErrorCode = ecode%
      END SUB
         
      '======================
      FUNCTION DOSversion% PUBLIC
      '-- Returns minor/major DOS version in high/low bytes of DOSversion%
      '-- Tries 21h/3306h (DOS 5+) to retrieve the true DOS version;
      '-- if not available, uses 21h/3001h, although this function can
      '-- be fooled by SETVER
      '-- NOTE: WIN NT and 2000 return DOS ver 5.5
      '-- DOS 4.01 returns DOS 4.00
      !  mov   ax, &h3306
      !  xor   bx, bx            ;zero bx before call
      !  int   &h21
      !  or    bx, bx            ;is bx changed?
      !  jz    Try213001         ;if no, then DOS < 5.0, so try old call
      !  mov   ax, bx            ;if call was good (DOS >= 5.0), take & go
      !  jmp   GotVersion
      Try213001:
      !  mov   ax, &h3001
      !  int   &h21
      GotVersion:
      !  mov   function, ax
      END FUNCTION
         
         
      '======================
      FUNCTION HexWord$(BYVAL WordVar??)
      LOCAL h$
      h$ = hex$(WordVar??)
      do until len(h$) = 4
         h$ = "0" + h$
      loop
      function = h$
      END FUNCTION

      [This message has been edited by Greg Turgeon (edited March 11, 2001).]

      Comment


      • #4
        Hi all,

        Mel: There is a serialnumber on every disk e.g. 1234-5678 and
        dir$... will not do the job.

        Greg: Your program looks good - but I use the winDos 7.10
        and I get the error massage: "DOSerror code 26". So I
        can´t use it.

        Thanks for help.

        Regards

        Matthias Kuhn


        ------------------

        Comment


        • #5
          Code:
          Matthias--
             
          This is interesting.  I've tried the code on a straight DOS 
          7.1 setup, and it works properly, including with FAT32 
          drives.  Error 26 reports an unknown media type (a non-DOS 
          disk).   What are the details of the setup you're working 
          with?
          [This message has been edited by Greg Turgeon (edited March 12, 2001).]

          Comment


          • #6
            Hi Greg,

            my system is exactly: Win95 Version 4.00.1111.

            The Media Type was the floppy disk 1.44 MB DS HD Dos formatted.

            I need this number for bank accounts.

            Regards

            Matthias Kuhn

            ------------------

            Comment


            • #7
              Code:
              Matthias--
                 
              This one remains a mystery.  I've tried the code on a Win 
              95a system, and it's returned the correct data from every 
              floppy disk I've tried reading, including 1.4M and 720K 
              3.5" disks, old 5.25" disks, and disks formatted under two 
              older versions of DOS. 
                 
              However, you now say, "my system is exactly: Win95 Version 
              4.00.1111."  This is Win 95b--the OSR2 version.  That might 
              have some relevance, but what version of DOS is reported by 
              the PB code?  The DOS version reported by Win 95a is 7.0, 
              yet you said earlier, "I use the winDos 7.10."

              [This message has been edited by Greg Turgeon (edited March 12, 2001).]

              Comment


              • #8
                Hi Greg,

                Your program reported Dos 7.1. really.

                If I say "drive%=1" then it reported: Disk ID error:
                Dos Errorcode 26.

                If I say "drive%=0" then it works correct with drive: C:
                Harddisk Fat 32.

                Result: The disk had no Serialnumber at all. I´ve tested it
                with the dir$ command.

                This are yellow Disks from Fujifilm.

                With other disk´s it work´s good.

                Thanks for Your persistence.

                Any idea´s to do ??? with those disk´s ??? :?

                Regards

                Matthias Kuhn



                ------------------

                Comment


                • #9
                  A serial number is only present on a disk if the format program put one there.
                  Disks created before MS-DOS 4.0 or so won't have them. Disks formatted by custom
                  format utilities may well not have them either.


                  ------------------
                  Tom Hanlin
                  PowerBASIC Staff

                  Comment


                  • #10
                    If all fails and your DOS can use Int13 or Int25, do an absolute
                    disk sector read of the boot sector. The serial number (formerly
                    known as volume label) starts at offset 40d. On my system, the
                    serial number is stored on disk in reverse order of what's shown
                    on the screen.


                    ------------------
                    There are no atheists in a fox hole or the morning of a math test.
                    If my flag offends you, I'll help you pack.

                    Comment


                    • #11
                      If there was no serial number created during the format operation, what would be the point?

                      ------------------
                      Lance
                      PowerBASIC Support
                      mailto:[email protected][email protected]</A>
                      Lance
                      mailto:[email protected]

                      Comment


                      • #12
                        Code:
                        Matthias--
                           
                        "Any idea´s to do ??? with those disk´s ???"
                           
                        Can you reformat them?  I don't know the exact 
                        circumstances that you're dealing with. 
                           
                        This is probably just a coincidence, but I've had trouble 
                        with bad sectors on new floppy disks right out of the box 
                        only once.  Same brand: Fuji.  This was quite a few years 
                        ago. 
                           
                           . . .
                           
                        "The serial number (formerly known as volume label)..."
                           
                        Formerly?  Serial numbers and volume labels have been 
                        distinct since at least DOS 3.2.  Before that? 
                           
                           . . .
                           
                        "A serial number is only present on a disk if the format 
                        program put one there. Disks created before MS-DOS 4.0 or 
                        so won't have them. Disks formatted by custom format 
                        utilities may well not have them either."
                           
                        In this particular case, the PB code returns a post-4.0 
                        version of DOS, but the second point--about custom format 
                        utilities--offers a rich set of possibilities for 
                        world-class screwiness.

                        ------------------
                        -- Greg
                        [email protected]

                        Comment


                        • #13
                          Fuji bulk formats their disks. You will not get a serial number unless you format them again.


                          ------------------
                          Amos

                          Comment

                          Working...
                          X