home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / os / msdos / programm / 10361 < prev    next >
Encoding:
Text File  |  1992-11-05  |  8.0 KB  |  219 lines

  1. Path: sparky!uunet!pipex!warwick!uknet!mcsun!Germany.EU.net!nixpbe!news.sni.de!fam168!frank
  2. From: fh.pad@sni.de (Frank Hoffmann)
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: Re: Obtaining the volume label
  5. Message-ID: <frank.720964912@fam168>
  6. Date: 5 Nov 92 12:01:52 GMT
  7. References: <114@complex.complex.is>
  8. Organization: Siemens Nixdorf Informationssysteme AG, Paderborn, Germany
  9. Lines: 207
  10. NNTP-Posting-Host: fam168.ap.pdb.sni.de
  11.  
  12. Actually this is a crosspost from alt.msdos.programmer, so if you already
  13. know it -- forgive me :-)
  14.  
  15.  
  16. Path: news.sni.de!fam168!frank
  17. From: Frank Hoffmann <fh.pad@sni.de>
  18. Newsgroups: alt.msdos.programmer
  19. Subject: Re: Setting volume labels..
  20. Date: 2 Nov 92 09:03:45 GMT
  21. Organization: Siemens Nixdorf Informationssysteme AG, Paderborn, Germany
  22. Lines: 180
  23. Message-ID: <frank.720695025@fam168>
  24. References: <92299.041830MBT3@psuvm.psu.edu>
  25. NNTP-Posting-Host: fam168.ap.pdb.sni.de
  26.  
  27. Mike Tierney <MBT3@psuvm.psu.edu> writes:
  28.  
  29. >Hi all!
  30. >     Does anyone out there have any sample source code demonstrating how
  31. >to set/remove disk volume labels?  I've tried to come up with a method on
  32. >my own, however, I can't seem to find a way to remove a volume label that
  33. >has no other file attribute set (e.g. if a volume label also has the
  34. >Archive attribute set, I can work with it, otherwise not).  The source can
  35. >be in any language (C, Pascal, Asm).  Thanks for any help you can give,
  36. >                                        -Mike
  37.  
  38. >------------------------------------------------------------------------
  39. >Mike Tierney    "..what would be 'beautiful' if the contradiction had
  40. >mbt3@vm.psu.edu  not first become conscious of itself, if the ugly had
  41. >mbt@ecl.psu.edu  not first said to itself, 'I am ugly'?"
  42. >mbt@eclu.psu.edu                            - Nietzsche
  43.  
  44. All right ... here we go.
  45.  
  46. Once i was pretty upset with *MS* handling of the "label" command. I wanted to
  47. delete or change volume labels without any online input by the user. So i
  48. wrote the following 'C' code. Anyway, it doesn't ever work. (Dunno why)
  49. So without any warranty and using the standard disclaimer :
  50.  
  51. regards
  52. frank
  53.  
  54. [cut here]
  55.  
  56. /*-------------------------------------------------------------------*/
  57. static char *xchngvol_id =
  58. "  @(#)  [xchngvol.c]       Ver.: 01/00           910618     fh      ";
  59. /*-------------------------------------------------------------------*/
  60. /*                                                                   */
  61. /*  History:                                                         */
  62. /*                                                                   */
  63. /*  Release     date      comment                                    */
  64. /*                                                                   */
  65. /*    01/00 fh  910618    Original release                           */
  66. /*                                                                   */
  67. /*-------------------------------------------------------------------*/
  68.  
  69.  
  70. #ifdef MSDOS
  71.  
  72.  
  73.  
  74. #include <dos.h>
  75. #include <errno.h>
  76. #include <string.h>
  77.  
  78.  
  79. /********************************************************************/
  80. xchngvol (drive, label)
  81. /********************************************************************/
  82.  
  83. char drive;                         /* a, b, c ... */
  84. char *label;                        /* ... */
  85.  
  86. {
  87.  
  88. struct fcb
  89. {
  90. /*------ start of 'extended' FCB ------*/        
  91.     char    ext_flag;               /* extended FCB, if FFh */
  92.     char    rsvd_1[5];              /* reserved */
  93.     char    ext_attrib;             /* attribute of extended FCB */
  94. /*------ start of 'normal' FCB ------*/        
  95.     char    drive;                  /* drive number. 0=default, 1=A ... */
  96.     char    name[8];                /* blank padded file name */
  97.     char    ext[3];                 /* blank padded extension */
  98.     int     curr_block;             /* current block number */
  99.     int     log_rec;                /* logical record size */
  100.     long    size;                   /* files size */
  101.     int     date;                   /* date of last write */
  102.     int     time;                   /* time of last write */
  103.     char    rsvd_2[8];              /* reserved */
  104.     char    rec_in_block;           /* record in current block */
  105.     long    rnd_acc_rec;            /* random access record number */
  106. };
  107.  
  108. struct find_t file;                 /* find structure */
  109. struct fcb myfcb;                   /* our file control block */
  110.  
  111.  
  112. char find[7];                       /* string for find_first */
  113. char help[13];                      /* destination label help */
  114. char dlabel[16];                    /* destination label */
  115. int ddrive;                         /* destination drive */
  116. char *p1;
  117. int i;
  118. int create;                         /* creation flag */
  119.  
  120.  
  121. create = 0;                         /* default = just delete */
  122.  
  123. ddrive = toupper (drive);
  124.  
  125. sprintf (find, "%c:\\*.*", (char) ddrive);
  126.  
  127. for (i = 0; i < 13; i++) help[i] = 0x00;
  128.  
  129. if (label != (char *) 0)            /* copy user label */
  130. {
  131.     strncpy (help, label, 8);       /* first 8 chars */
  132.     if (strlen (label) > 8)         /* more ? ... */
  133.     {
  134.         help[8] = '.';              /* separated by dot, 'cause its a file */
  135.         label += 8;
  136.         strncpy (&help[9], label, 3);
  137.         help[12] = 0x00;
  138.     }
  139.     sprintf (dlabel, "%c:\\%s", (char) ddrive, help);
  140.     dlabel[15] = 0x00;
  141.     create = 1;
  142. }
  143.  
  144. ddrive -= 64;                           /* convert to 1, 2, 3 ... */
  145.  
  146. p1 = (char *) &myfcb;                   /* points to an extended FCB */
  147.   
  148.                                         /* search for existing volume name */
  149. if (_dos_findfirst (find, 0x28, &file) == 0)
  150. {
  151.     strcpy (myfcb.name, file.name);     /* copy old volume name */
  152.     for (i = strlen (myfcb.name); i < 8; i++)
  153.     {
  154.         myfcb.name[i] = 0x20;           /* blank out unused parts */
  155.     }
  156.     strcpy (myfcb.ext, "???");
  157.     myfcb.ext_flag = 0xff;              /* extended FCB */
  158.     myfcb.ext_attrib = 0x28;            /* attributes: VOLID+ARCHIVE */
  159.     myfcb.drive = ddrive;               /* drive ID */
  160.     _asm mov ax, byte ptr p1
  161.     _asm mov dx, ax                     /* address of FCB */
  162.     _asm mov ax, 1300h
  163.     _asm int 21h                        /* delete file. INT 21h, func: 13h */
  164.     _asm jnc ok1
  165.     return (-1);
  166.  
  167. ok1:
  168.     ;                                   /* label MUST contain a statement! */
  169. }
  170.  
  171. if (! create)
  172. {
  173.     return (0);                         /* our job is done */
  174. }
  175.  
  176. p1 = dlabel;                            /* ASM is really too dumb ! */
  177.  
  178. _asm mov ax, byte ptr p1
  179. _asm mov dx, ax                         /* file name          */
  180. _asm mov cx, 28h                        /* attributes         */
  181. _asm mov ax, 5b00h
  182. _asm int 21h                            /* create file. INT 21h, func: 5Bh */
  183. _asm jnc ok2
  184.  
  185. return (-1);
  186.  
  187. ok2:
  188. return (0);
  189.  
  190. } /* end of xchgngvol */
  191.  
  192.  
  193. #endif    /* MSDOS */
  194.  
  195. [cut here]
  196. <EOT>
  197.  
  198. -------------------------------------------------------------------------------
  199.     __________                  Frank Hoffmann
  200.      /             /    Siemens-Nixdorf Info. Systems Voice: [49] 5 251 812 209
  201.     /__           /      Dept: AP 52 / SW-Production    Fax: [49] 5 251 811 599
  202.    /' _  _   __  //            Fuerstenallee 7          USA: fh.pad@sni-usa.com
  203. __/__/__(_(_/ /_/^\__    W-4790 Paderborn / Germany    !USA: fh.pad@sni.de
  204. -------------------------------------------------------------------------------
  205.        My opinion ??  waaaaaaaaaaaaaaaaaaaaahahahahahahahahahahahahahahah
  206. -------------------------------------------------------------------------------
  207.  
  208.  
  209.  
  210. -------------------------------------------------------------------------------
  211.     __________                  Frank Hoffmann
  212.      /             /    Siemens-Nixdorf Info. Systems Voice: [49] 5 251 812 209
  213.     /__           /      Dept: AP 52 / SW-Production    Fax: [49] 5 251 811 599
  214.    /' _  _   __  //            Fuerstenallee 7          USA: fh.pad@sni-usa.com
  215. __/__/__(_(_/ /_/^\__    W-4790 Paderborn / Germany    !USA: fh.pad@sni.de
  216. -------------------------------------------------------------------------------
  217.        My opinion ??  waaaaaaaaaaaaaaaaaaaaahahahahahahahahahahahahahahah
  218. -------------------------------------------------------------------------------
  219.