home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / next / sysadmin / 6661 < prev    next >
Encoding:
Text File  |  1992-11-22  |  5.3 KB  |  173 lines

  1. Newsgroups: comp.sys.next.sysadmin
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!destroyer!cs.ubc.ca!unixg.ubc.ca!kakwa.ucs.ualberta.ca!vega!ntomczak
  3. From: ntomczak@vega.math.ualberta.ca (N Tomczak-Jaegermann)
  4. Subject: MS-DOS disks labels under NeXTSTEP_3.0 - how to
  5. Message-ID: <ntomczak.722502506@vega>
  6. Summary: make them colourful
  7. Sender: news@kakwa.ucs.ualberta.ca
  8. Nntp-Posting-Host: vega.math.ualberta.ca
  9. Organization: University Of Alberta, Edmonton Canada
  10. Date: Mon, 23 Nov 1992 07:08:26 GMT
  11. Lines: 160
  12.  
  13.  
  14. If you who have problems with MS-DOS diskettes rejected because of
  15. garbled labels or you are bored with MS-DOS disks mounting as /no_name
  16. or /unknown here is a small program, relabel_dos, which may help to
  17. alleviate your worries.  It works for me and it may work for you, but
  18. there are no guarantees of any kind and there is a distinct potential
  19. of loosing your data.  So be careful and check first how it operates
  20. on spare copies of diskettes of the kind you are using.  Check also
  21. if modified disks will not spook out your MS-DOS computer with
  22. which you would like to exchange disks.  Maybe they might.
  23. !!Read carefully all instructions!!
  24.  
  25.   Have fun,
  26.   Michal
  27.  
  28. /******************* relabel_dos.c ************************
  29. *
  30. * Utility to modify labels on MS-DOS diskettes used on NeXT.
  31. *
  32. * Instructions:
  33. *   To run this program you have to be 'root' (or, if you feel
  34. *   bold and reckless today, you may make it 'suid root').
  35. *   Start this program from a Terminal window and give it as an
  36. *   argument a label you want to use.  DO NOT insert a diskette
  37. *   until asked by an alert box to do so.  After succesful
  38. *   program completion your diskette will be ejected.  Insert
  39. *   it back and NeXT hopefuly will mount the diskette under its
  40. *   brand new label.
  41. *
  42. *   If you will try this operation on a diskette which was
  43. *   already mounted re-insertion of an ejected disk will NOT
  44. *   change a displayed label.  Eject that disk properly
  45. *   from Workspace and re-insert once again.
  46. *
  47. * DIRE WARNINGS!!!
  48. *   Main use of this program is make acceptable to NeXT
  49. *   MS-DOS diskettes which are rejected because of garbage
  50. *   labels.  Therefore this program reads and writes raw,
  51. *   not-mounted, floppies an does not attempt to check if
  52. *   they are really MS-DOS.  Executing it on a disk with
  53. *   Unix or Mac file system will likely cause a damage not
  54. *   easy recoverable on this side of formatting.
  55. *      There is also no check if label characters are valid
  56. *   from MS-DOS point of view - mostly because I do not know
  57. *   if there are any limitations. Letters are converted to
  58. *   an upper case just because NeXT is doing this.  It does
  59. *   not seem that this really matters.  Spaces are ok in
  60. *   labels, but an argument has to be quoted in such cases.
  61. *   NeXT will convert on a display label blanks into underscores.
  62. *      Lastly - ONE(!) MS-DOS computer did not mind diskettes
  63. *   with modified labels.  I have no idea if this applies
  64. *   to your machine.  Check it out on spare disks!!!
  65. *
  66. * Compilation:
  67. *    compile with 'cc -O2 -s -object -o relabel_dos relabel_doc.c'
  68. *
  69. * Disclaimers:
  70. * This program is provided on 'as is' basis and using it you accept
  71. * full responsibility for its results.  In no event I shall be liable
  72. * for any incidental, consequential, special or indirect damages of
  73. * any kind, including, without limitation, lost profits or
  74. * revenues, arising out of the use, installation, or operation of
  75. * this program.
  76. *  Michal Jaegermann
  77. *  ntomczak@vega.math.ualberta.ca
  78. *  ntomczak@vm.ucs.ualberta.ca
  79. *
  80. *  22 November 1992
  81. **********************************************************/
  82.  
  83. #define FLOPPY        "/dev/rfd0b"
  84. #define SECT_SIZE    512
  85. #define LABEL_START    43
  86. #define LABEL_WIDTH    11
  87.  
  88. #include <stdio.h>
  89. #include <string.h>
  90. #include <ctype.h>
  91. #include <libc.h>
  92. #include <dev/disk.h>
  93. #include <sys/file.h>
  94.  
  95. void
  96. eject_and_exit(int fd)
  97. {
  98.     ioctl(fd, DKIOCEJECT, 0);
  99.     close (fd);
  100.     exit (1);
  101. }
  102.  
  103. int
  104. main(int argc, char **argv)
  105. {
  106.     unsigned char sect_buf[SECT_SIZE];
  107.     unsigned char *label_end = §_buf[LABEL_START + LABEL_WIDTH];
  108.     unsigned char *apos, *lpos;
  109.     int fd;
  110.     int c;
  111.  
  112.     if(argc < 2) {
  113.     fprintf(stderr, "usage: %s new_label\n", argv[0]);
  114.     exit (1);
  115.     }
  116.     
  117.     /* get sector 0 from floppy */
  118.  
  119.     if (0 > (fd = open (FLOPPY, O_RDONLY, 0))) {
  120.     fprintf(stderr, "cannot open " FLOPPY " for reading\n");
  121.     exit(1);
  122.     }
  123.  
  124.     if (SECT_SIZE != read(fd, sect_buf, SECT_SIZE)) {
  125.     fprintf(stderr, "error reading boot sector\n");
  126.     eject_and_exit (fd);
  127.     }
  128.     close(fd);
  129.     
  130.     /* modify label on a sector image  - leftover filled with blanks*/
  131.  
  132.     apos = argv[1];
  133.     lpos = §_buf[LABEL_START];
  134.  
  135.     c = 1;
  136.     do {
  137.     if ('\0' != c) {
  138.         if ('\0' == (c = *apos++))
  139.         continue;
  140.         /*
  141.          * NeXT does not seem to care about case
  142.          * but maybe MS-DOS does - convert to upper case
  143.          */
  144.         if (islower(c))
  145.         c = toupper(c);
  146.         *lpos++ = c;
  147.     }
  148.     else {
  149.         *lpos++ = ' ';
  150.     }
  151.     } while (lpos < label_end);
  152.  
  153.     /* write sector 0 back to floppy */
  154.  
  155.     if (0 > (fd = open (FLOPPY, O_WRONLY, 0))) {
  156.     fprintf(stderr, "cannot open " FLOPPY " for writing\n");
  157.     exit (1);
  158.     }
  159.  
  160.     if (SECT_SIZE != write(fd, sect_buf, SECT_SIZE)) {
  161.     fprintf(stderr, "error writing boot sector\n");
  162.     eject_and_exit (fd);
  163.     }
  164.     
  165.     /* eject modified disk and get out */
  166.  
  167.     ioctl(fd, DKIOCEJECT, 0);
  168.     close(fd);
  169.  
  170.     return 0;
  171. }
  172.