1: /*
   2:  * Make an MSDOS volume label
   3:  *
   4:  * Emmet P. Gray			US Army, HQ III Corps & Fort Hood
   5:  * ...!uunet!uiucuxc!fthood!egray	Attn: AFZF-DE-ENV
   6:  * fthood!egray@uxc.cso.uiuc.edu	Directorate of Engineering & Housing
   7:  * 					Environmental Management Office
   8:  * 					Fort Hood, TX 76544-5057
   9:  */
  10: 
  11: #include <stdio.h>
  12: #include <ctype.h>
  13: #include "msdos.h"
  14: #include "patchlevel.h"
  15: 
  16: int fd = -1;                /* the file descriptor for the device */
  17: int dir_start;              /* starting sector for directory */
  18: int dir_len;                /* length of directory (in sectors) */
  19: int dir_entries;            /* number of directory entries */
  20: int clus_size;              /* cluster size (in sectors) */
  21: char *mcwd;             /* the Current Working Directory */
  22: int fat_error;              /* FAT error detected? */
  23: 
  24: main(argc, argv)
  25: int argc;
  26: char *argv[];
  27: {
  28:     int entry, slot, fargn, verbose, oops;
  29:     char filename[30], *strncpy(), drive, ans[10], *strncat();
  30:     char *strcpy(), *fix_mcwd();
  31:     unsigned char fixed[12], vol[12];
  32:     void exit(), dir_write(), dir_flush(), disk_flush();
  33:     struct directory *dir, *dir_read(), *mk_entry();
  34:     long time(), now;
  35: 
  36:     fargn = 1;
  37:     verbose = 0;
  38:     oops = 0;
  39:     if (argc > 1) {
  40:         if (!strcmp(argv[1], "-v")) {
  41:             fargn = 2;
  42:             verbose = 1;
  43:         }
  44:         if (argv[1][0] == '-' && !verbose)
  45:             oops++;
  46:     }
  47:     if (argc < 2 || argv[fargn][1] != ':' || oops) {
  48:         fprintf(stderr, "Mtools version %s, dated %s\n", VERSION, DATE);
  49:         fprintf(stderr, "Usage: %s [-v] drive:\n", argv[0]);
  50:         exit(1);
  51:     }
  52:     mcwd = fix_mcwd();
  53: 
  54:     drive = argv[fargn][0];
  55:     if (islower(drive))
  56:         drive = toupper(drive);
  57: 
  58:     if (init(drive, 2)) {
  59:         fprintf(stderr, "%s: Cannot initialize '%c:'\n", argv[0], drive);
  60:         exit(1);
  61:     }
  62:                     /* see if a label exists and get slot */
  63:     slot = -1;
  64:     vol[0] = '\0';
  65:     for (entry = 0; entry < dir_entries; entry++) {
  66:         dir = dir_read(entry);
  67:                     /* if empty */
  68:         if (dir->name[0] == 0x0) {
  69:             if (slot < 0)
  70:                 slot = entry;
  71:             break;
  72:         }
  73:                     /* if erased */
  74:         if (dir->name[0] == 0xe5) {
  75:             if (slot < 0)
  76:                 slot = entry;
  77:             continue;
  78:         }
  79:                     /* if not a volume label */
  80:         if (!(dir->attr & 0x08))
  81:             continue;
  82: 
  83:         slot = entry;
  84:         strncpy((char *) vol, (char *) dir->name, 8);
  85:         vol[8] = '\0';
  86:         strncat((char *) vol, (char *) dir->ext, 3);
  87:         vol[11] = '\0';
  88: 
  89:         printf("Volume in drive %c is \"%s\"\n", drive, vol);
  90:         break;
  91:     }
  92:     if (slot < 0) {
  93:         fprintf(stderr, "%s: No directory slots\n", argv[0]);
  94:         exit(1);
  95:     }
  96:     if (vol[0] == '\0')
  97:         printf("Volume in drive %c is unlabeled\n", drive);
  98: 
  99:                     /* ask for new label */
 100:     printf("Enter the new volume label (11 characters): ");
 101:     gets(filename);
 102:     if (filename[0] != '\0') {
 103:         sprintf((char *) fixed, "%-11.11s", filename);
 104:         if (strlen(filename) > 11 && verbose)
 105:             printf("New label is \"%s\"\n", fixed);
 106:     }
 107:     else {
 108:         if (vol[0] == '\0')
 109:             exit(0);
 110: 
 111:         printf("Delete volume label (y/n): ");
 112:         gets(ans);
 113:         if (ans[0] == 'y' || ans[0] == 'Y') {
 114:             strcpy((char *) fixed, (char *) vol);
 115:             fixed[0] = 0xe5;
 116:         }
 117:         else
 118:             exit(0);
 119:     }
 120:                     /* make directory entry */
 121:     time(&now);
 122:     dir = mk_entry(fixed, 0x08, 0, 0L, now);
 123:     dir_write(slot, dir);
 124: 
 125:     dir_flush();
 126:     disk_flush();
 127:     close(fd);
 128:     exit(0);
 129: }

Defined functions

main defined in line 24; never used

Defined variables

clus_size defined in line 20; never used
dir_entries defined in line 19; used 1 times
  • in line 65
dir_len defined in line 18; never used
dir_start defined in line 17; never used
fat_error defined in line 22; never used
fd defined in line 16; used 1 times
mcwd defined in line 21; used 1 times
  • in line 52
Last modified: 1992-06-24
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2615
Valid CSS Valid XHTML 1.0 Strict