-
Notifications
You must be signed in to change notification settings - Fork 20
/
fsck.cpm.c
632 lines (603 loc) · 19.1 KB
/
fsck.cpm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/* #includes */ /*{{{C}}}*//*{{{*/
#include "config.h"
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "getopt_.h"
#include "cpmdir.h"
#include "cpmfs.h"
#ifdef USE_DMALLOC
#include <dmalloc.h>
#endif
/*}}}*/
/* #defines */ /*{{{*/
/* your favourite password *:-) */
#define T0 'G'
#define T1 'E'
#define T2 'H'
#define T3 'E'
#define T4 'I'
#define T5 'M'
#define T6 ' '
#define T7 ' '
#define PB ((char)(T0+T1+T2+T3+T4+T5+T6+T7))
#define P0 ((char)(T7^PB))
#define P1 ((char)(T6^PB))
#define P2 ((char)(T5^PB))
#define P3 ((char)(T4^PB))
#define P4 ((char)(T3^PB))
#define P5 ((char)(T2^PB))
#define P6 ((char)(T1^PB))
#define P7 ((char)(T0^PB))
/*}}}*/
/* types */ /*{{{*/
enum Result { OK=0, MODIFIED=1, BROKEN=2 };
/*}}}*/
/* variables */ /*{{{*/
static int norepair=0;
/*}}}*/
/* bcdCheck -- check format and range of BCD digit */ /*{{{*/
static int bcdCheck(int n, int max, const char *msg, const char *unit, int extent1, int extent2)
{
if (((n>>4)&0xf)>10 || (n&0xf)>10 || (((n>>4)&0xf)*10+(n&0xf))>=max)
{
printf("Error: Bad %s %s (extent=%d/%d, %s=%02x)\n",msg,unit,extent1,extent2,unit,n&0xff);
return -1;
}
else return 0;
}
/*}}}*/
/* pwdCheck -- check password */ /*{{{*/
static int pwdCheck(int extent, const char *pwd, char decode)
{
char c;
int i;
for (i=0; i<8; ++i) if ((c=((char)(pwd[7-i]^decode)))<' ' || c&0x80)
{
printf("Error: non-printable character in password (extent=%d, password=",extent);
for (i=0; i<8; ++i)
{
c=pwd[7-i]^decode;
if (c<' ' || c&0x80)
{
putchar('\\'); putchar('0'+((c>>6)&0x01));
putchar('0'+((c>>3)&0x03));
putchar('0'+(c&0x03));
}
else putchar(c);
}
printf(")\n");
return -1;
}
return 0;
}
/*}}}*/
/* ask -- ask user and return answer */ /*{{{*/
static int ask(const char *msg)
{
while (1)
{
char buf[80];
if (norepair) return 0;
printf("%s [Y]? ",msg); fflush(stdout);
if (fgets(buf,sizeof(buf),stdin)==(char*)0) exit(1);
switch (toupper(buf[0]))
{
case '\n':
case 'Y': return 1;
case 'N': return 0;
}
}
}
/*}}}*/
/* prfile -- print file name */ /*{{{*/
static char *prfile(struct cpmSuperBlock *sb, int extent)
{
struct PhysDirectoryEntry *dir;
static char name[80];
char *s=name;
int i;
char c;
dir=sb->dir+extent;
for (i=0; i<8; ++i)
{
c=dir->name[i];
if ((c&0x7f)<' ')
{
*s++='\\'; *s++=('0'+((c>>6)&0x01));
*s++=('0'+((c>>3)&0x03));
*s++=('0'+(c&0x03));
}
else *s++=(c&0x7f);
}
*s++='.';
for (i=0; i<3; ++i)
{
c=dir->ext[i];
if ((c&0x7f)<' ')
{
*s++='\\'; *s++=('0'+((c>>6)&0x01));
*s++=('0'+((c>>3)&0x03));
*s++=('0'+(c&0x03));
}
else *s++=(c&0x7f);
}
*s='\0';
return name;
}
/*}}}*/
/* fsck -- file system check */ /*{{{*/
static int fsck(struct cpmInode *root, const char *image)
{
/* variables */ /*{{{*/
enum Result ret=OK;
int extent,extent2;
struct PhysDirectoryEntry *dir,*dir2;
struct cpmSuperBlock *sb=root->sb;
/*}}}*/
/* Phase 1: check extent fields */ /*{{{*/
printf("Phase 1: check extent fields\n");
for (extent=0; extent<sb->maxdir; ++extent)
{
char *status;
int usedBlocks=0;
dir=sb->dir+extent;
status=&dir->status;
if (*status>=0 && *status<=(sb->type==CPMFS_P2DOS ? 31 : 15)) /* directory entry */ /*{{{*/
{
/* check name and extension */ /*{{{*/
{
int i;
char *c;
for (i=0; i<8; ++i)
{
c=&(dir->name[i]);
if (!ISFILECHAR(i,*c&0x7f) || islower(*c&0x7f))
{
printf("Error: Bad name (extent=%d, name=\"%s\", position=%d)\n",extent,prfile(sb,extent),i);
if (ask("Remove file"))
{
*status=(char)0xE5;
ret|=MODIFIED;
break;
}
else ret|=BROKEN;
}
}
if (*status==(char)0xe5) continue;
for (i=0; i<3; ++i)
{
c=&(dir->ext[i]);
if (!ISFILECHAR(1,*c&0x7f) || islower(*c&0x7f))
{
printf("Error: Bad name (extent=%d, name=\"%s\", position=%d)\n",extent,prfile(sb,extent),i);
if (ask("Remove file"))
{
*status=(char)0xE5;
ret|=MODIFIED;
break;
}
else ret|=BROKEN;
}
}
if (*status==(char)0xe5) continue;
}
/*}}}*/
/* check extent number */ /*{{{*/
if ((dir->extnol&0xff)>0x1f)
{
printf("Error: Bad lower bits of extent number (extent=%d, name=\"%s\", low bits=%d)\n",extent,prfile(sb,extent),dir->extnol&0xff);
if (ask("Remove file"))
{
*status=(char)0xE5;
ret|=MODIFIED;
}
else ret|=BROKEN;
}
if (*status==(char)0xe5) continue;
if ((dir->extnoh&0xff)>0x3f)
{
printf("Error: Bad higher bits of extent number (extent=%d, name=\"%s\", high bits=%d)\n",extent,prfile(sb,extent),dir->extnoh&0xff);
if (ask("Remove file"))
{
*status=(char)0xE5;
ret|=MODIFIED;
}
else ret|=BROKEN;
}
if (*status==(char)0xe5) continue;
/*}}}*/
/* check last record byte count */ /*{{{*/
if ((dir->lrc&0xff)>128)
{
printf("Error: Bad last record byte count (extent=%d, name=\"%s\", lrc=%d)\n",extent,prfile(sb,extent),dir->lrc&0xff);
if (ask("Clear last record byte count"))
{
dir->lrc=(char)0;
ret|=MODIFIED;
}
else ret|=BROKEN;
}
if (*status==(char)0xe5) continue;
/*}}}*/
/* check block number range */ /*{{{*/
{
int block,min,max,i;
min=(sb->maxdir*32+sb->blksiz-1)/sb->blksiz;
max=sb->size;
for (i=0; i<16; ++i)
{
block=dir->pointers[i]&0xff;
if (sb->size>=256) block+=(dir->pointers[++i]&0xff)<<8;
if (block>0)
{
++usedBlocks;
if (block<min || block>=max)
{
printf("Error: Bad block number (extent=%d, name=\"%s\", block=%d)\n",extent,prfile(sb,extent),block);
if (ask("Remove file"))
{
*status=(char)0xE5;
ret|=MODIFIED;
break;
}
else ret|=BROKEN;
}
}
}
if (*status==(char)0xe5) continue;
}
/*}}}*/
/* check number of used blocks ? */ /*{{{*/
/*}}}*/
/* check record count */ /*{{{*/
{
int i,min,max,recordsInBlocks,used=0;
min=(dir->extnol%sb->extents)*16/sb->extents;
max=((dir->extnol%sb->extents)+1)*16/sb->extents;
assert(min<max);
for (i=min; i<max; ++i)
{
/* [JCE] Rewritten because the previous implementation didn't work
* properly with Visual C++ */
if (dir->pointers[i] || (sb->size>=256 && dir->pointers[i+1])) ++used;
if (sb->size >= 256) ++i;
}
recordsInBlocks=(((unsigned char)dir->blkcnt)*128+sb->blksiz-1)/sb->blksiz;
if (recordsInBlocks!=used)
{
printf("Error: Bad record count (extent=%d, name=\"%s\", record count=%d)\n",extent,prfile(sb,extent),dir->blkcnt&0xff);
if (ask("Remove file"))
{
*status=(char)0xE5;
ret|=MODIFIED;
}
else ret|=BROKEN;
}
if (*status==(char)0xe5) continue;
}
/*}}}*/
/* check for too large .com files */ /*{{{*/
if (((EXTENT(dir->extnol,dir->extnoh)==3 && dir->blkcnt>=126) || EXTENT(dir->extnol,dir->extnoh)>=4) && (dir->ext[0]&0x7f)=='C' && (dir->ext[1]&0x7f)=='O' && (dir->ext[2]&0x7f)=='M')
{
printf("Warning: Oversized .COM file (extent=%d, name=\"%s\")\n",extent,prfile(sb,extent));
}
/*}}}*/
}
/*}}}*/
else if ((sb->type==CPMFS_P2DOS || sb->type==CPMFS_DR3) && *status==33) /* check time stamps ? */ /*{{{*/
{
unsigned long created,modified;
char s;
if ((s=sb->dir[extent2=(extent&~3)].status)>=0 && s<=(sb->type==CPMFS_P2DOS ? 31 : 15)) /* time stamps for first of the three extents */ /*{{{*/
{
bcdCheck(dir->name[2],24,sb->cnotatime ? "creation date" : "access date","hour",extent,extent2);
bcdCheck(dir->name[3],60,sb->cnotatime ? "creation date" : "access date","minute",extent,extent2);
bcdCheck(dir->name[6],24,"modification date","hour",extent,extent2);
bcdCheck(dir->name[7],60,"modification date","minute",extent,extent2);
created=(dir->name[4]+(dir->name[1]<<8))*(0x60*0x60)+dir->name[2]*0x60+dir->name[3];
modified=(dir->name[0]+(dir->name[5]<<8))*(0x60*0x60)+dir->name[6]*0x60+dir->name[7];
if (sb->cnotatime && modified<created)
{
printf("Warning: Modification date earlier than creation date (extent=%d/%d)\n",extent,extent2);
}
}
/*}}}*/
if ((s=sb->dir[extent2=(extent&~3)+1].status)>=0 && s<=(sb->type==CPMFS_P2DOS ? 31 : 15)) /* time stamps for second */ /*{{{*/
{
bcdCheck(dir->lrc,24,sb->cnotatime ? "creation date" : "access date","hour",extent,extent2);
bcdCheck(dir->extnoh,60,sb->cnotatime ? "creation date" : "access date","minute",extent,extent2);
bcdCheck(dir->pointers[1],24,"modification date","hour",extent,extent2);
bcdCheck(dir->pointers[2],60,"modification date","minute",extent,extent2);
created=(dir->ext[2]+(dir->extnol<<8))*(0x60*0x60)+dir->lrc*0x60+dir->extnoh;
modified=(dir->blkcnt+(dir->pointers[0]<<8))*(0x60*0x60)+dir->pointers[1]*0x60+dir->pointers[2];
if (sb->cnotatime && modified<created)
{
printf("Warning: Modification date earlier than creation date (extent=%d/%d)\n",extent,extent2);
}
}
/*}}}*/
if ((s=sb->dir[extent2=(extent&~3)+2].status)>=0 && s<=(sb->type==CPMFS_P2DOS ? 31 : 15)) /* time stamps for third */ /*{{{*/
{
bcdCheck(dir->pointers[7],24,sb->cnotatime ? "creation date" : "access date","hour",extent,extent2);
bcdCheck(dir->pointers[8],60,sb->cnotatime ? "creation date" : "access date","minute",extent,extent2);
bcdCheck(dir->pointers[11],24,"modification date","hour",extent,extent2);
bcdCheck(dir->pointers[12],60,"modification date","minute",extent,extent2);
created=(dir->pointers[5]+(dir->pointers[6]<<8))*(0x60*0x60)+dir->pointers[7]*0x60+dir->pointers[8];
modified=(dir->pointers[9]+(dir->pointers[10]<<8))*(0x60*0x60)+dir->pointers[11]*0x60+dir->pointers[12];
if (sb->cnotatime && modified<created)
{
printf("Warning: Modification date earlier than creation date (extent=%d/%d)\n",extent,extent2);
}
}
/*}}}*/
}
/*}}}*/
else if (sb->type==CPMFS_DR3 && *status==32) /* disc label */ /*{{{*/
{
unsigned long created,modified;
bcdCheck(dir->pointers[10],24,sb->cnotatime ? "creation date" : "access date","hour",extent,extent);
bcdCheck(dir->pointers[11],60,sb->cnotatime ? "creation date" : "access date","minute",extent,extent);
bcdCheck(dir->pointers[14],24,"modification date","hour",extent,extent);
bcdCheck(dir->pointers[15],60,"modification date","minute",extent,extent);
created=(dir->pointers[8]+(dir->pointers[9]<<8))*(0x60*0x60)+dir->pointers[10]*0x60+dir->pointers[11];
modified=(dir->pointers[12]+(dir->pointers[13]<<8))*(0x60*0x60)+dir->pointers[14]*0x60+dir->pointers[15];
if (sb->cnotatime && modified<created)
{
printf("Warning: Label modification date earlier than creation date (extent=%d)\n",extent);
}
if (dir->extnol&0x40 && dir->extnol&0x10)
{
printf("Error: Bit 4 and 6 can only be exclusively be set (extent=%d, label byte=0x%02x)\n",extent,(unsigned char)dir->extnol);
if (ask("Time stamp on creation"))
{
dir->extnol&=~0x40;
ret|=MODIFIED;
}
else if (ask("Time stamp on access"))
{
dir->extnol&=~0x10;
ret|=MODIFIED;
}
else ret|=BROKEN;
}
if (dir->extnol&0x80 && pwdCheck(extent,dir->pointers,dir->lrc))
{
char msg[80];
sprintf(msg,"Set password to %c%c%c%c%c%c%c%c",T0,T1,T2,T3,T4,T5,T6,T7);
if (ask(msg))
{
dir->pointers[0]=P0;
dir->pointers[1]=P1;
dir->pointers[2]=P2;
dir->pointers[3]=P3;
dir->pointers[4]=P4;
dir->pointers[5]=P5;
dir->pointers[6]=P6;
dir->pointers[7]=P7;
dir->lrc=PB;
ret|=MODIFIED;
}
else ret|=BROKEN;
}
}
/*}}}*/
else if (sb->type==CPMFS_DR3 && *status>=16 && *status<=31) /* password */ /*{{{*/
{
/* check name and extension */ /*{{{*/
{
int i;
char *c;
for (i=0; i<8; ++i)
{
c=&(dir->name[i]);
if (!ISFILECHAR(i,*c&0x7f) || islower(*c&0x7f))
{
printf("Error: Bad name (extent=%d, name=\"%s\", position=%d)\n",extent,prfile(sb,extent),i);
if (ask("Clear password entry"))
{
*status=(char)0xE5;
ret|=MODIFIED;
break;
}
else ret|=BROKEN;
}
}
if (*status==(char)0xe5) continue;
for (i=0; i<3; ++i)
{
c=&(dir->ext[i]);
if (!ISFILECHAR(1,*c&0x7f) || islower(*c&0x7f))
{
printf("Error: Bad name (extent=%d, name=\"%s\", position=%d)\n",extent,prfile(sb,extent),i);
if (ask("Clear password entry"))
{
*status=(char)0xE5;
ret|=MODIFIED;
break;
}
else ret|=BROKEN;
}
}
if (*status==(char)0xe5) continue;
}
/*}}}*/
/* check password */ /*{{{*/
if (dir->extnol&(0x80|0x40|0x20) && pwdCheck(extent,dir->pointers,dir->lrc))
{
char msg[80];
sprintf(msg,"Set password to %c%c%c%c%c%c%c%c",T0,T1,T2,T3,T4,T5,T6,T7);
if (ask(msg))
{
dir->pointers[0]=P0;
dir->pointers[1]=P1;
dir->pointers[2]=P2;
dir->pointers[3]=P3;
dir->pointers[4]=P4;
dir->pointers[5]=P5;
dir->pointers[6]=P6;
dir->pointers[7]=P7;
dir->lrc=PB;
ret|=MODIFIED;
}
else ret|=BROKEN;
}
/*}}}*/
}
/*}}}*/
else if (*status!=(char)0xe5) /* bad status */ /*{{{*/
{
printf("Error: Bad status (extent=%d, name=\"%s\", status=0x%02x)\n",extent,prfile(sb,extent),*status&0xff);
if (ask("Clear entry"))
{
*status=(char)0xE5;
ret|=MODIFIED;
}
else ret|=BROKEN;
continue;
}
/*}}}*/
}
/*}}}*/
/* Phase 2: check extent connectivity */ /*{{{*/
printf("Phase 2: check extent connectivity\n");
/* check multiple allocated blocks */ /*{{{*/
for (extent=0; extent<sb->maxdir; ++extent) if ((dir=sb->dir+extent)->status>=0 && dir->status<=(sb->type==CPMFS_P2DOS ? 31 : 15))
{
int i,j,block,block2;
for (i=0; i<16; ++i)
{
block=dir->pointers[i]&0xff;
if (sb->size>=256) block+=(dir->pointers[++i]&0xff)<<8;
for (extent2=0; extent2<sb->maxdir; ++extent2) if ((dir2=sb->dir+extent2)->status>=0 && dir2->status<=(sb->type==CPMFS_P2DOS ? 31 : 15))
{
for (j=0; j<16; ++j)
{
block2=dir2->pointers[j]&0xff;
if (sb->size>=256) block2+=(dir2->pointers[++j]&0xff)<<8;
if (block!=0 && block2!=0 && block==block2 && !(extent==extent2 && i==j))
{
printf("Error: Multiple allocated block (extent=%d,%d, name=\"%s\"",extent,extent2,prfile(sb,extent));
printf(",\"%s\" block=%d)\n",prfile(sb,extent2),block);
ret|=BROKEN;
}
}
}
}
}
/*}}}*/
/* check multiple extents */ /*{{{*/
for (extent=0; extent<sb->maxdir; ++extent) if ((dir=sb->dir+extent)->status>=0 && dir->status<=(sb->type==CPMFS_P2DOS ? 31 : 15))
{
for (extent2=0; extent2<sb->maxdir; ++extent2) if ((dir2=sb->dir+extent2)->status>=0 && dir2->status<=(sb->type==CPMFS_P2DOS ? 31 : 15))
{
if (extent!=extent2 && EXTENT(dir->extnol,dir->extnoh)==EXTENT(dir2->extnol,dir2->extnoh) && dir->status==dir2->status)
{
int i;
for (i=0; i<8 && (dir->name[i]&0x7f)==(dir2->name[i]&0x7f); ++i);
if (i==8)
{
for (i=0; i<3 && (dir->ext[i]&0x7f)==(dir2->ext[i]&0x7f); ++i);
if (i==3)
{
printf("Error: Duplicate extent (extent=%d,%d)\n",extent,extent2);
ret|=BROKEN;
}
}
}
}
}
/*}}}*/
/*}}}*/
if (ret==0) /* print statistics */ /*{{{*/
{
struct cpmStatFS statfsbuf;
int fragmented=0,borders=0;
cpmStatFS(root,&statfsbuf);
for (extent=0; extent<sb->maxdir; ++extent) if ((dir=sb->dir+extent)->status>=0 && dir->status<=(sb->type==CPMFS_P2DOS ? 31 : 15))
{
int i,block,previous=-1;
for (i=0; i<16; ++i)
{
block=dir->pointers[i]&0xff;
if (sb->size>=256) block+=(dir->pointers[++i]&0xff)<<8;
if (previous!=-1)
{
if (block!=0 && block!=(previous+1)) ++fragmented;
++borders;
}
previous=block;
}
}
fragmented=(borders ? (1000*fragmented)/borders : 0);
printf("%s: %ld/%ld files (%d.%d%% non-contigous), %ld/%ld blocks\n",image,statfsbuf.f_files-statfsbuf.f_ffree,statfsbuf.f_files,fragmented/10,fragmented%10,statfsbuf.f_blocks-statfsbuf.f_bfree,statfsbuf.f_blocks);
}
/*}}}*/
return ret;
}
/*}}}*/
const char cmd[]="fsck.cpm";
/* main */ /*{{{*/
int main(int argc, char *argv[])
{
const char *err;
const char *image;
const char *format;
const char *devopts=NULL;
int c,usage=0;
struct cpmSuperBlock sb;
struct cpmInode root;
enum Result ret;
if (!(format=getenv("CPMTOOLSFMT"))) format=FORMAT;
while ((c=getopt(argc,argv,"T:f:nh?"))!=EOF) switch(c)
{
case 'f': format=optarg; break;
case 'T': devopts=optarg; break;
case 'n': norepair=1; break;
case 'h':
case '?': usage=1; break;
}
if (optind!=(argc-1)) usage=1;
else image=argv[optind++];
if (usage)
{
fprintf(stderr,"Usage: %s [-f format] [-n] image\n",cmd);
exit(1);
}
if ((err=Device_open(&sb.dev, image, (norepair ? O_RDONLY : O_RDWR), devopts)))
{
if ((err=Device_open(&sb.dev, image,O_RDONLY, devopts)))
{
fprintf(stderr,"%s: cannot open %s: %s\n",cmd,image,err);
exit(1);
}
else
{
fprintf(stderr,"%s: cannot open %s for writing, no repair possible\n",cmd,image);
}
}
if (cpmReadSuper(&sb,&root,format)==-1)
{
fprintf(stderr,"%s: cannot read superblock (%s)\n",cmd,boo);
exit(1);
}
ret=fsck(&root,image);
if (ret&MODIFIED)
{
if (cpmSync(&sb)==-1)
{
fprintf(stderr,"%s: write error on %s: %s\n",cmd,image,strerror(errno));
ret|=BROKEN;
}
fprintf(stderr,"%s: FILE SYSTEM ON %s MODIFIED",cmd,image);
if (ret&BROKEN) fprintf(stderr,", PLEASE CHECK AGAIN");
fprintf(stderr,"\n");
}
cpmUmount(&sb);
if (ret&BROKEN) return 2;
else return 0;
}
/*}}}*/