home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / atari / st / tech / 6464 < prev    next >
Encoding:
Text File  |  1993-01-04  |  3.6 KB  |  109 lines

  1. Newsgroups: comp.sys.atari.st.tech
  2. Path: sparky!uunet!munnari.oz.au!spool.mu.edu!agate!doc.ic.ac.uk!warwick!dcs.warwick.ac.uk!leo
  3. From: leo@dcs.warwick.ac.uk (Leo Hendry)
  4. Subject: Re: How do you set a disk's volume label?
  5. Message-ID: <1993Jan4.203023.5854@dcs.warwick.ac.uk>
  6. Sender: news@dcs.warwick.ac.uk (Network News)
  7. Nntp-Posting-Host: granite
  8. Organization: Department of Computer Science, Warwick University, England
  9. References: <H.ea.kYwLB_Rm3xg@kynes.bison.mb.ca>
  10. Date: Mon, 4 Jan 1993 20:30:23 GMT
  11. Lines: 96
  12.  
  13. In article <H.ea.kYwLB_Rm3xg@kynes.bison.mb.ca> rdo@kynes.bison.mb.ca writes:
  14. >Using the following code, I can find the volume label on a disk:
  15. >
  16. >#include <stdio.h>
  17. >#include <string.h>
  18. >#include <osbind.h>
  19. >#include <ostruct.h>
  20. >
  21. >/* Get disk vol for specified drive */
  22. >char *
  23. >getvol(char drive)
  24. >{
  25. >    _DTA    *dta;
  26. >    char    path[8];
  27. >    char    *vol = NULL;
  28. >
  29. >    path[0] = '/';
  30. >    path[1] = drive;
  31. >    path[2] = '\0';
  32. >    chdir(path);
  33. >    Fsfirst("*.*", FA_LABEL);
  34. >    do {
  35. >        dta = (_DTA *)Fgetdta();
  36. >        printf("name: %s\n", dta->dta_name);
  37. >        if (dta->dta_attribute == FA_LABEL) {
  38. >            vol = strdup(dta->dta_name);
  39. >            break;
  40. >        }
  41. >    } while (Fsnext() == 0);
  42. >
  43. >    if (vol != NULL)
  44. >        return vol;
  45. >    else
  46. >        return NULL;
  47. >}
  48.  
  49. I doubt it - there are several problems with this.  Firstly, you set aside
  50. 8 bytes for "path", then only use 3 of them.  Then (more importantly) you set
  51. path to the string "/D", where D is the drive (Note the slash is the wrong
  52. way round).  Note that anyway chdir("a:\") will simply change the current
  53. directory on drive A: to the root, not change to drive A:.
  54.   Next you call Fsfirst without first setting the DTA - by default this is
  55. over the area where the command line is stored.  Then you assume that
  56. Fsfirst has found something when it might not have done.  Next you call
  57. Fgetdta inside a loop where the DTA address never changes and check that the
  58. attribute really is FA_LABEL, which it always will be (this is not a bug -
  59. just a waste of time). You then call Fsnext to find the next file with the
  60. FA_LABEL - even if for some reason there were two labels on the disk the
  61. "break" would mean the second one would be ignored.  Finally "if (vol!=NULL)
  62. return vol; else return NULL;" can be reduced to "return vol".
  63.   Sorry to be so negative, but here's how I'd do it:
  64.  
  65. char *getvol(char drive)
  66.  {
  67.  _DTA dta;
  68.  static char search[]="X:\\*.*";
  69.  
  70.  *search=drive;
  71.  Fsetdta(&dta);
  72.  if (!Fsfirst(search, FA_LABEL))
  73.   return strdup(dta.dta_name);
  74.  return NULL;
  75.  }
  76.  
  77. Two backslashes are required in "search" because backslash is used as an
  78. escape character in C - "X:\*.*" will be interpreted as "X:*.*" or maybe
  79. "X:.*", I can't remember which.  Note that the above this changes the DTA's
  80. address - it might be a good idea to save it at the beginning and restore it
  81. afterwards.
  82.  
  83. >Now, what I'd like to do is be able to change an existing label.  Or, if one
  84. >doesn't exist, I'd like to create it.
  85.  
  86. Simple - as you know, the volume label is simply a file with the attribute
  87. FA_LABEL, so to change it you simply delete this file and create a new one
  88. with the name you require.  The following sets the label of the specified
  89. drive to "new_vol" (or insures there is no volume label if new_vol is NULL
  90. and returns the old label (or NULL if there was previously none).
  91.  
  92. char *setvol(char drive, char *new_vol)
  93.  {
  94.  char *old_vol;
  95.  
  96.  if (old_vol=getvol(drive))
  97.   Dremove(old_vol);
  98.  if (new_vol)
  99.   Dclose(Dcreat(FA_LABEL, new_vol));
  100.  return old_vol;
  101.  }
  102.  
  103. It is more than possible that I have made a mistake somewhere (eg. Dremove may
  104. be called something else, and Dcreat may take it's arguments in the opposite
  105. order) as I have not tested either of the above.  However, this should at
  106. least give you the general idea.
  107.  
  108. - Leo
  109.