1: /*
2: * Change MSDOS file attribute flags
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 "msdos.h"
13: #include "patchlevel.h"
14:
15: int fd = -1; /* the file descriptor for the device */
16: int dir_start; /* starting sector for directory */
17: int dir_len; /* length of directory (in sectors) */
18: int dir_entries; /* number of directory entries */
19: int clus_size; /* cluster size (in sectors) */
20: char *mcwd; /* the Current Working Directory */
21: int fat_error; /* FAT error detected? */
22:
23: #define ADD 1
24: #define REMOVE (-1)
25: #define LEAVE 0
26:
27: main(argc, argv)
28: int argc;
29: char *argv[];
30: {
31: int entry, ismatch, oops, fargn, read_only, hidden, sys, archive;
32: int i, action;
33: char *filename, *newfile, *unix_name(), drive, get_drive();
34: char *get_path(), *pathname, *get_name(), *fix_mcwd(), last_drive;
35: void exit(), dir_write(), dir_flush(), disk_flush();
36: struct directory *dir, *dir_read();
37:
38: oops = 0;
39: fargn = -1;
40: archive = LEAVE;
41: hidden = LEAVE;
42: read_only = LEAVE;
43: sys = LEAVE;
44: /* can't use getopt(3)... */
45: for (i = 1; i < argc; i++) {
46: switch (argv[i][0]) {
47: case '-':
48: action = REMOVE;
49: break;
50: case '+':
51: action = ADD;
52: break;
53: default:
54: fargn = i;
55: break;
56: }
57: if (fargn != -1)
58: break;
59:
60: switch (argv[i][1]) {
61: case 'a':
62: case 'A':
63: archive = action;
64: break;
65: case 'h':
66: case 'H':
67: hidden = action;
68: break;
69: case 'r':
70: case 'R':
71: read_only = action;
72: break;
73: case 's':
74: case 'S':
75: sys = action;
76: break;
77: default:
78: oops++;
79: break;
80: }
81: if (oops)
82: break;
83: }
84: if (argc < 3 || argv[fargn][0] == '\0' || oops) {
85: fprintf(stderr, "Mtools version %s, dated %s\n", VERSION, DATE);
86: fprintf(stderr, "Usage: %s [-a|+a] [-h|+h] [-r|+r] [-s|+s] msdosfile [msdosfiles...]\n", argv[0]);
87: exit(1);
88: }
89: last_drive = 'x';
90: mcwd = fix_mcwd();
91:
92: for (i = fargn; i < argc; i++) {
93: drive = get_drive(argv[i]);
94: if (last_drive != drive) {
95: if (init(drive, 2)) {
96: fprintf(stderr, "%s: Cannot initialize '%c:'\n", argv[0], drive);
97: continue;
98: }
99: last_drive = drive;
100: }
101: filename = get_name(argv[i]);
102: pathname = get_path(argv[i]);
103: if (subdir(drive, pathname))
104: continue;
105:
106: /* see if exists and do it */
107: ismatch = 0;
108: for (entry = 0; entry < dir_entries; entry++) {
109: dir = dir_read(entry);
110: /* if empty */
111: if (dir->name[0] == 0x0)
112: break;
113: /* if erased */
114: if (dir->name[0] == 0xe5)
115: continue;
116: /* if dir or volume label */
117: if ((dir->attr & 0x10) || (dir->attr & 0x08))
118: continue;
119:
120: newfile = unix_name(dir->name, dir->ext);
121:
122: /* do it... */
123: if (match(newfile, filename)) {
124: if (archive == ADD)
125: dir->attr |= 0x20;
126: if (archive == REMOVE)
127: dir->attr &= ~0x20;
128: if (hidden == ADD)
129: dir->attr |= 0x02;
130: if (hidden == REMOVE)
131: dir->attr &= ~0x02;
132: if (read_only == ADD)
133: dir->attr |= 0x01;
134: if (read_only == REMOVE)
135: dir->attr &= ~0x01;
136: if (sys == ADD)
137: dir->attr |= 0x04;
138: if (sys == REMOVE)
139: dir->attr &= ~0x04;
140: dir_write(entry, dir);
141: ismatch++;
142: }
143: }
144: if (!ismatch)
145: fprintf(stderr, "%s: File \"%s\" not found\n", argv[0], filename);
146: }
147: dir_flush();
148: disk_flush();
149: close(fd);
150: exit(0);
151: }
Defined functions
main
defined in line
27;
never used
Defined variables
fd
defined in line
15; used 1 times
mcwd
defined in line
20; used 1 times
Defined macros
ADD
defined in line
23; used 5 times
LEAVE
defined in line
25; used 4 times