home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / msdos / programm / 8508 < prev    next >
Encoding:
Text File  |  1992-08-12  |  6.4 KB  |  186 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!mcsun!Germany.EU.net!nixpbe!news.sni.de!fam168!frank
  3. From: Frank Hoffmann <fh.pad@sni.de>
  4. Subject: Re: Volume label's
  5. Message-ID: <frank.713687987@fam168>
  6. Keywords: volume labels
  7. Sender: news@nixpbe.sni.de
  8. Organization: Siemens Nixdorf Info.Sys. AG, Paderborn, Germany
  9. References: <hvisage.713546489@rkw-risc>
  10. Date: Thu, 13 Aug 1992 06:39:47 GMT
  11. Lines: 173
  12.  
  13. hvisage@rkw-risc.cs.up.ac.za (Hendrik Visage) writes:
  14.  
  15. >Hi net,
  16. >    I need to change, create and delete volume labels in
  17. > TP6.0, TC++ or TASM. under MS-DOS 5.00. If possible please send EMail.
  18.  
  19. >Thanx.
  20. > -------------------------------------
  21. > H.Visage
  22. >  hvisage@rkw-risc.cs.up.ac.za
  23. >  9121110@rkw-lan.cs.up.ac.za
  24. > ------------------------------------- 
  25.  
  26. The following code (MSC 6.00) generates/deletes a volume label on the
  27. requested drive. It works although the error return is not sure.
  28.  
  29. (Yup! we may could have written the same thing in ASM)
  30.  
  31. ---cut-here---cut-here---cut-here---cut-here---cut-here---cut-here---cut-here-
  32. /*-------------------------------------------------------------------*/
  33. static char *xchngvol_id =
  34. "  @(#)  [xchngvol.c]       Ver.: 01/00           910618     fh      ";
  35. /*-------------------------------------------------------------------*/
  36. /*                                                                   */
  37. /*  History:                                                         */
  38. /*                                                                   */
  39. /*  Release     date      comment                                    */
  40. /*                                                                   */
  41. /*    01/00 fh  910618    Original release                           */
  42. /*                                                                   */
  43. /*-------------------------------------------------------------------*/
  44.  
  45.  
  46. #ifdef MSDOS
  47.  
  48.  
  49.  
  50. #include <fh.h>
  51. #include <dos.h>
  52. #include <errno.h>
  53. #include <string.h>
  54.  
  55.  
  56. /********************************************************************/
  57. xchngvol (drive, label)
  58. /********************************************************************/
  59.  
  60. char drive;                         /* a, b, c ... */
  61. char *label;                        /* ... */
  62.  
  63. {
  64.  
  65. struct fcb
  66. {
  67. /*------ start of 'extended' FCB ------*/        
  68.     char    ext_flag;               /* extended FCB, if FFh */
  69.     char    rsvd_1[5];              /* reserved */
  70.     char    ext_attrib;             /* attribute of extended FCB */
  71. /*------ start of 'normal' FCB ------*/        
  72.     char    drive;                  /* drive number. 0=default, 1=A ... */
  73.     char    name[8];                /* blank padded file name */
  74.     char    ext[3];                 /* blank padded extension */
  75.     int     curr_block;             /* current block number */
  76.     int     log_rec;                /* logical record size */
  77.     long    size;                   /* files size */
  78.     int     date;                   /* date of last write */
  79.     int     time;                   /* time of last write */
  80.     char    rsvd_2[8];              /* reserved */
  81.     char    rec_in_block;           /* record in current block */
  82.     long    rnd_acc_rec;            /* random access record number */
  83. };
  84.  
  85.  
  86. struct find_t file;                 /* find structure */
  87. struct fcb myfcb;                   /* our file control block */
  88.  
  89.  
  90. char find[7];                       /* string for find_first */
  91. char help[13];                      /* destination label help */
  92. char dlabel[16];                    /* destination label */
  93. int ddrive;                         /* destination drive */
  94. char *p1;
  95. int i;
  96. int create;                         /* creation flag */
  97.  
  98.  
  99. create = 0;                         /* default = just delete */
  100.  
  101. ddrive = toupper (drive);
  102.  
  103. sprintf (find, "%c:\\*.*", (char) ddrive);
  104.  
  105. for (i = 0; i < 13; i++) help[i] = 0x00;
  106.  
  107. if (label != (char *) 0)            /* copy user label */
  108. {
  109.     strncpy (help, label, 8);       /* first 8 chars */
  110.     if (strlen (label) > 8)         /* more ? ... */
  111.     {
  112.         help[8] = '.';              /* separated by dot, 'cause its a file */
  113.         label += 8;
  114.         strncpy (&help[9], label, 3);
  115.         help[12] = 0x00;
  116.     }
  117.     sprintf (dlabel, "%c:\\%s", (char) ddrive, help);
  118.     dlabel[15] = 0x00;
  119.     create = 1;
  120. }
  121.  
  122. ddrive -= 64;                           /* convert to 1, 2, 3 ... */
  123.  
  124. p1 = (char *) &myfcb;                   /* points to an extended FCB */
  125.   
  126.                                         /* search for existing volume name */
  127. if (_dos_findfirst (find, 0x28, &file) == 0)
  128. {
  129.     strcpy (myfcb.name, file.name);     /* copy old volume name */
  130.     for (i = strlen (myfcb.name); i < 8; i++)
  131.     {
  132.         myfcb.name[i] = 0x20;           /* blank out unused parts */
  133.     }
  134.     strcpy (myfcb.ext, "???");
  135.     myfcb.ext_flag = 0xff;              /* extended FCB */
  136.     myfcb.ext_attrib = 0x28;            /* attributes: VOLID+ARCHIVE */
  137.     myfcb.drive = ddrive;               /* drive ID */
  138.     _asm mov ax, byte ptr p1
  139.     _asm mov dx, ax                     /* address of FCB */
  140.     _asm mov ax, 1300h
  141.     _asm int 21h                        /* delete file. INT 21h, func: 13h */
  142.     _asm jnc ok1
  143.     return (-1);
  144.  
  145. ok1:
  146.     ;                                   /* label MUST contain a statement! */
  147. }
  148.  
  149. if (! create)
  150. {
  151.     return (0);                         /* our job is done */
  152. }
  153.  
  154. p1 = dlabel;                            /* ASM really is too dumb ! */
  155.  
  156. _asm mov ax, byte ptr p1
  157. _asm mov dx, ax                         /* file name          */
  158. _asm mov cx, 28h                        /* attributes         */
  159. _asm mov ax, 5b00h
  160. _asm int 21h                            /* create file. INT 21h, func: 5Bh */
  161. _asm jnc ok2
  162.  
  163. return (-1);
  164.  
  165. ok2:
  166. return (0);
  167.  
  168. } /* end of xchgngvol */
  169.  
  170.  
  171. #endif    /* MSDOS */
  172. ---cut-here---cut-here---cut-here---cut-here---cut-here---cut-here---cut-here-
  173.  
  174. Hope that helps a bit...
  175.  
  176. frank
  177. -------------------------------------------------------------------------------
  178.     __________                  Frank Hoffmann        Voice: [+49] 5251 812 209
  179.      /             /    Siemens-Nixdorf Info. Systems  Data: [+49] 5251 812 207
  180.     /__           /      Dept: AP 52 / SW-Production    Fax: [+49] 5251 811 599
  181.    /' _  _   __  //            Fuerstenallee 7          USA: fh.pad@sni-usa.com
  182. __/__/__(_(_/ /_/^\__    W-4790 Paderborn / Germany    !USA: fh.pad@sni.de
  183. -------------------------------------------------------------------------------
  184. ( * )  <--- The green dot.  This mail is reusable. Copy to /dev/null instantly.
  185. -------------------------------------------------------------------------------
  186.