home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 183_01 / getvol.c < prev    next >
Text File  |  1985-09-26  |  3KB  |  112 lines

  1. /****************************************************************/
  2. /*                                                              */
  3. /* Title:       Getvol                                          */
  4. /*                                                              */
  5. /* Abstract:    This routine will return the volume name for    */
  6. /*              the specified disk drive (0..n). If the drive   */
  7. /*              does not have a volume label, a null string is  */
  8. /*              returned.                                       */
  9. /*                                                              */
  10. /* Call:        int getvol (drive, name);                       */
  11. /*              int drive;                                      */
  12. /*              char *name;                                     */
  13. /*                                                              */
  14. /* Arguments:   drive:  Drive number to obtain the volume       */
  15. /*                      label. 1 == A, 2 == B, etc.             */
  16. /*                      drive 0 is the current drive.           */
  17. /*              name:   Array of characters [0..11] to receive  */
  18. /*                      the volume label.                       */
  19. /*                                                              */
  20. /* Returns:     0 : no error in the operation.                  */
  21. /*              1 : Invalid drive                               */
  22. /*              2 : Invalid DOS revison (1.x)                   */
  23. /*              3 : Volume label is not defined                 */
  24. /*                                                              */
  25. /****************************************************************/
  26.  
  27. #include "STDIO.H"
  28. #include "DOS.H"
  29.  
  30. extern int _dos;                /* Flag for DOS revision level  */
  31.  
  32. int getvol(drive, name)
  33. int  drive;                     /* Drive number */
  34. int *name;                      /* Volume name  */
  35.  
  36. {
  37.  
  38. union REGS inregs;
  39. union REGS outregs;
  40.  
  41. char    dta_buffer[128];        /* Disk buffer area     */
  42. struct
  43.     {
  44.     char dr_flag;               /* Flag to indicate extended FCB */
  45.     char filler1[5];            /* reserved (should be 0)        */
  46.     char attr;                  /* Volume attribute byte         */
  47.     char drive_code;            /* Drive code                    */
  48.     char filler2[11];           /* Filler for the file name      */
  49.     char filler3[25];           /* Remainder of the FCB          */
  50.     } fcbs;
  51.  
  52. int indx;
  53.  
  54. /*
  55. *     Ensure that the drive number is valid
  56. */
  57.  
  58. if ((drive < 0) || (drive > 16))
  59.     {
  60.     return (1);
  61.     }
  62.  
  63. /*
  64. *     Reject the request for Dos 1.x
  65. */
  66.  
  67. if (!(_dos))
  68.     {
  69.     return (2);
  70.     }
  71.  
  72. /*
  73. *     Build the File Control Block area
  74. */
  75.  
  76. repmem (&fcbs, "\000", 1, 44);
  77. fcbs.dr_flag    = 0xff;
  78. fcbs.attr       = 8;
  79. fcbs.drive_code = (char) drive;
  80. repmem (&fcbs.filler2, "?", 1, 11);
  81.  
  82. /*
  83. *     Define the disk transfer area
  84. */
  85.  
  86. inregs.h.ah = 26;
  87. inregs.x.dx = (int) &dta_buffer;
  88. int86 (0x21, &inregs, &outregs);
  89.  
  90. /*
  91. *     Search for the volume label only
  92. */
  93.  
  94. inregs.h.ah = 17;
  95. inregs.x.dx = (int) &fcbs;
  96. int86 (0x21, &inregs, &outregs);
  97.  
  98. /*
  99. *     Return the volume label if no error occured
  100. */
  101.  
  102. if (outregs.h.al != 0xff)
  103.     {
  104.     stccpy (name, &dta_buffer[8], 12);
  105.     return (0);
  106.     }
  107. else
  108.     {
  109.     return (3);
  110.     }
  111. }
  112.