freemyipod r50 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r49‎ | r50 | r51 >
Date:13:05, 7 August 2010
Author:theseven
Status:new
Tags:
Comment:
Fix panicf()/DEBUGF() calls in FAT code
Modified paths:
  • /embios/trunk/dir.c (modified) (history)
  • /embios/trunk/disk.c (modified) (history)
  • /embios/trunk/fat.c (modified) (history)
  • /embios/trunk/file.c (modified) (history)
  • /embios/trunk/panic.c (modified) (history)
  • /embios/trunk/panic.h (modified) (history)
  • /embios/trunk/thread.h (modified) (history)

Diff [purge]

Index: embios/trunk/panic.c
@@ -31,12 +31,26 @@
3232 #include "contextswitch.h"
3333
3434
 35+extern struct scheduler_thread* scheduler_threads;
 36+extern struct scheduler_thread* current_thread;
3537 void hang();
3638
3739
3840 void handle_panic(enum panic_severity severity)
3941 {
40 - thread_exit();
 42+ int i;
 43+ if (severity == PANIC_KILLTHREAD) thread_exit();
 44+ else
 45+ {
 46+ uint32_t mode = enter_critical_section();
 47+ for (i = 0; i < MAX_THREADS; i++)
 48+ if (scheduler_threads[i].type == USER_THREAD)
 49+ scheduler_threads[i].state = THREAD_SUSPENDED;
 50+ current_thread->state = THREAD_DEFUNCT_ACK;
 51+ current_thread->block_type = THREAD_DEFUNCT_PANIC;
 52+ leave_critical_section(mode);
 53+ context_switch();
 54+ }
4155 }
4256
4357 void panic(enum panic_severity severity, const char* string)
Index: embios/trunk/disk.c
@@ -84,7 +84,7 @@
8585 /* check that the boot sector is initialized */
8686 if ( (sector[510] != 0x55) ||
8787 (sector[511] != 0xaa)) {
88 - DEBUGF("Bad boot sector signature\n");
 88+ DEBUGF("Bad boot sector signature");
8989 return NULL;
9090 }
9191
@@ -95,7 +95,7 @@
9696 pinfo[i].start = BYTES2INT32(ptr, 8);
9797 pinfo[i].size = BYTES2INT32(ptr, 12);
9898
99 - DEBUGF("Part%d: Type %02x, start: %08lx size: %08lx\n",
 99+ DEBUGF("Part%d: Type %02x, start: %08lx size: %08lx",
100100 i,pinfo[i].type,pinfo[i].start,pinfo[i].size);
101101
102102 /* extended? */
@@ -196,7 +196,7 @@
197197
198198 if (mounted == 0 && volume != -1) /* none of the 4 entries worked? */
199199 { /* try "superfloppy" mode */
200 - DEBUGF("No partition found, trying to mount sector 0.\n");
 200+ DEBUGF("No partition found, trying to mount sector 0.");
201201 if (!fat_mount(IF_MV2(volume,) IF_MD2(drive,) 0))
202202 {
203203 mounted = 1;
Index: embios/trunk/panic.h
@@ -31,7 +31,7 @@
3232 enum panic_severity
3333 {
3434 PANIC_KILLTHREAD = 0,
35 - PANIC_KILLPROCESS = 1,
 35+ PANIC_KILLUSERTHREADS = 1,
3636 PANIC_FATAL = 2
3737 };
3838
Index: embios/trunk/fat.c
@@ -236,7 +236,7 @@
237237
238238 if (cluster > (long)(fat_bpb->dataclusters + 1))
239239 {
240 - DEBUGF( "cluster2sec() - Bad cluster number (%ld)\n", cluster);
 240+ DEBUGF( "cluster2sec() - Bad cluster number (%ld)", cluster);
241241 return -1;
242242 }
243243
@@ -309,7 +309,7 @@
310310 rc = storage_read_sectors(IF_MD2(drive,) startsector,1,buf);
311311 if(rc)
312312 {
313 - DEBUGF( "fat_mount() - Couldn't read BPB (error code %d)\n", rc);
 313+ DEBUGF( "fat_mount() - Couldn't read BPB (error code %d)", rc);
314314 return rc * 10 - 1;
315315 }
316316
@@ -379,11 +379,11 @@
380380 fat_bpb->is_fat16 = true;
381381 if (fat_bpb->dataclusters < 4085)
382382 { /* FAT12 */
383 - DEBUGF("This is FAT12. Go away!\n");
 383+ DEBUGF("This is FAT12. Go away!");
384384 return -2;
385385 }
386386 #else /* #ifdef HAVE_FAT16SUPPORT */
387 - DEBUGF("This is not FAT32. Go away!\n");
 387+ DEBUGF("This is not FAT32. Go away!");
388388 return -2;
389389 #endif /* #ifndef HAVE_FAT16SUPPORT */
390390 }
@@ -414,7 +414,7 @@
415415 rc = bpb_is_sane(IF_MV(fat_bpb));
416416 if (rc < 0)
417417 {
418 - DEBUGF( "fat_mount() - BPB is not sane\n");
 418+ DEBUGF( "fat_mount() - BPB is not sane");
419419 return rc * 10 - 3;
420420 }
421421
@@ -432,7 +432,7 @@
433433 startsector + fat_bpb->bpb_fsinfo, 1, buf);
434434 if (rc < 0)
435435 {
436 - DEBUGF( "fat_mount() - Couldn't read FSInfo (error code %d)\n", rc);
 436+ DEBUGF( "fat_mount() - Couldn't read FSInfo (error code %d)", rc);
437437 return rc * 10 - 4;
438438 }
439439 fat_bpb->fsinfo.freecount = BYTES2INT32(buf, FSINFO_FREECOUNT);
@@ -445,11 +445,11 @@
446446 fat_recalc_free(IF_MV(volume));
447447 }
448448
449 - DEBUGF("Freecount: %ld\n",fat_bpb->fsinfo.freecount);
450 - DEBUGF("Nextfree: 0x%lx\n",fat_bpb->fsinfo.nextfree);
451 - DEBUGF("Cluster count: 0x%lx\n",fat_bpb->dataclusters);
452 - DEBUGF("Sectors per cluster: %d\n",fat_bpb->bpb_secperclus);
453 - DEBUGF("FAT sectors: 0x%lx\n",fat_bpb->fatsize);
 449+ DEBUGF("Freecount: %ld",fat_bpb->fsinfo.freecount);
 450+ DEBUGF("Nextfree: 0x%lx",fat_bpb->fsinfo.nextfree);
 451+ DEBUGF("Cluster count: 0x%lx",fat_bpb->dataclusters);
 452+ DEBUGF("Sectors per cluster: %d",fat_bpb->bpb_secperclus);
 453+ DEBUGF("FAT sectors: 0x%lx",fat_bpb->fatsize);
454454
455455 #ifdef HAVE_MULTIVOLUME
456456 fat_bpb->mounted = true;
@@ -556,7 +556,7 @@
557557 #endif
558558 if(fat_bpb->bpb_bytspersec % SECTOR_SIZE)
559559 {
560 - DEBUGF( "bpb_is_sane() - Error: sector size is not sane (%d)\n",
 560+ DEBUGF( "bpb_is_sane() - Error: sector size is not sane (%d)",
561561 fat_bpb->bpb_bytspersec);
562562 return -1;
563563 }
@@ -564,7 +564,7 @@
565565 > 128L*1024L)
566566 {
567567 DEBUGF( "bpb_is_sane() - Error: cluster size is larger than 128K "
568 - "(%d * %d = %d)\n",
 568+ "(%d * %d = %d)",
569569 fat_bpb->bpb_bytspersec, fat_bpb->bpb_secperclus,
570570 fat_bpb->bpb_bytspersec * fat_bpb->bpb_secperclus);
571571 return -2;
@@ -571,19 +571,19 @@
572572 }
573573 if(fat_bpb->bpb_numfats != 2)
574574 {
575 - DEBUGF( "bpb_is_sane() - Warning: NumFATS is not 2 (%d)\n",
 575+ DEBUGF( "bpb_is_sane() - Warning: NumFATS is not 2 (%d)",
576576 fat_bpb->bpb_numfats);
577577 }
578578 if(fat_bpb->bpb_media != 0xf0 && fat_bpb->bpb_media < 0xf8)
579579 {
580580 DEBUGF( "bpb_is_sane() - Warning: Non-standard "
581 - "media type (0x%02x)\n",
 581+ "media type (0x%02x)",
582582 fat_bpb->bpb_media);
583583 }
584584 if(fat_bpb->last_word != 0xaa55)
585585 {
586586 DEBUGF( "bpb_is_sane() - Error: Last word is not "
587 - "0xaa55 (0x%04x)\n", fat_bpb->last_word);
 587+ "0xaa55 (0x%04x)", fat_bpb->last_word);
588588 return -3;
589589 }
590590
@@ -592,7 +592,7 @@
593593 fat_bpb->bpb_secperclus)
594594 {
595595 DEBUGF( "bpb_is_sane() - Error: FSInfo.Freecount > disk size "
596 - "(0x%04lx)\n", fat_bpb->fsinfo.freecount);
 596+ "(0x%04lx)", fat_bpb->fsinfo.freecount);
597597 return -4;
598598 }
599599
@@ -618,8 +618,8 @@
619619 sectorbuf);
620620 if(rc < 0)
621621 {
622 - panicf("flush_fat_sector() - Could not write sector %ld"
623 - " (error %d)\n",
 622+ panicf(PANIC_KILLUSERTHREADS, "flush_fat_sector() - Could not write sector %ld"
 623+ " (error %d)",
624624 secnum, rc);
625625 }
626626 #ifdef HAVE_MULTIVOLUME
@@ -638,8 +638,8 @@
639639 secnum, 1, sectorbuf);
640640 if(rc < 0)
641641 {
642 - panicf("flush_fat_sector() - Could not write sector %ld"
643 - " (error %d)\n",
 642+ panicf(PANIC_KILLUSERTHREADS, "flush_fat_sector() - Could not write sector %ld"
 643+ " (error %d)",
644644 secnum, rc);
645645 }
646646 }
@@ -686,7 +686,7 @@
687687 if(rc < 0)
688688 {
689689 DEBUGF( "cache_fat_sector() - Could not read sector %ld"
690 - " (error %d)\n", secnum, rc);
 690+ " (error %d)", secnum, rc);
691691 mutex_unlock(&cache_mutex);
692692 return NULL;
693693 }
@@ -732,7 +732,7 @@
733733 cluster numbers out of bounds */
734734 if ( c < 2 || c > fat_bpb->dataclusters+1 )
735735 continue;
736 - DEBUGF("find_free_cluster(%x) == %x\n",startcluster,c);
 736+ DEBUGF("find_free_cluster(%x) == %x",startcluster,c);
737737 fat_bpb->fsinfo.nextfree = c;
738738 return c;
739739 }
@@ -760,7 +760,7 @@
761761 cluster numbers out of bounds */
762762 if ( c < 2 || c > fat_bpb->dataclusters+1 )
763763 continue;
764 - DEBUGF("find_free_cluster(%lx) == %lx\n",startcluster,c);
 764+ DEBUGF("find_free_cluster(%lx) == %lx",startcluster,c);
765765 fat_bpb->fsinfo.nextfree = c;
766766 return c;
767767 }
@@ -769,7 +769,7 @@
770770 }
771771 }
772772
773 - DEBUGF("find_free_cluster(%lx) == 0\n",startcluster);
 773+ DEBUGF("find_free_cluster(%lx) == 0",startcluster);
774774 return 0; /* 0 is an illegal cluster number */
775775 }
776776
@@ -788,18 +788,18 @@
789789
790790 val &= 0xFFFF;
791791
792 - DEBUGF("update_fat_entry(%x,%x)\n",entry,val);
 792+ DEBUGF("update_fat_entry(%x,%x)",entry,val);
793793
794794 if (entry==val)
795 - panicf("Creating FAT loop: %lx,%lx\n",entry,val);
 795+ panicf(PANIC_KILLUSERTHREADS, "Creating FAT loop: %lx,%lx",entry,val);
796796
797797 if ( entry < 2 )
798 - panicf("Updating reserved FAT entry %ld.\n",entry);
 798+ panicf(PANIC_KILLUSERTHREADS, "Updating reserved FAT entry %ld.",entry);
799799
800800 sec = cache_fat_sector(IF_MV2(fat_bpb,) sector, true);
801801 if (!sec)
802802 {
803 - DEBUGF( "update_fat_entry() - Could not cache sector %d\n", sector);
 803+ DEBUGF( "update_fat_entry() - Could not cache sector %d", sector);
804804 return -1;
805805 }
806806
@@ -812,7 +812,7 @@
813813 fat_bpb->fsinfo.freecount++;
814814 }
815815
816 - DEBUGF("update_fat_entry: %d free clusters\n",
 816+ DEBUGF("update_fat_entry: %d free clusters",
817817 fat_bpb->fsinfo.freecount);
818818
819819 sec[offset] = htole16(val);
@@ -824,18 +824,18 @@
825825 int offset = entry % CLUSTERS_PER_FAT_SECTOR;
826826 unsigned long* sec;
827827
828 - DEBUGF("update_fat_entry(%lx,%lx)\n",entry,val);
 828+ DEBUGF("update_fat_entry(%lx,%lx)",entry,val);
829829
830830 if (entry==val)
831 - panicf("Creating FAT loop: %lx,%lx\n",entry,val);
 831+ panicf(PANIC_KILLUSERTHREADS, "Creating FAT loop: %lx,%lx",entry,val);
832832
833833 if ( entry < 2 )
834 - panicf("Updating reserved FAT entry %ld.\n",entry);
 834+ panicf(PANIC_KILLUSERTHREADS, "Updating reserved FAT entry %ld.",entry);
835835
836836 sec = cache_fat_sector(IF_MV2(fat_bpb,) sector, true);
837837 if (!sec)
838838 {
839 - DEBUGF("update_fat_entry() - Could not cache sector %ld\n", sector);
 839+ DEBUGF("update_fat_entry() - Could not cache sector %ld", sector);
840840 return -1;
841841 }
842842
@@ -849,7 +849,7 @@
850850 fat_bpb->fsinfo.freecount++;
851851 }
852852
853 - DEBUGF("update_fat_entry: %ld free clusters\n",
 853+ DEBUGF("update_fat_entry: %ld free clusters",
854854 fat_bpb->fsinfo.freecount);
855855
856856 /* don't change top 4 bits */
@@ -875,7 +875,7 @@
876876 sec = cache_fat_sector(IF_MV2(fat_bpb,) sector, false);
877877 if (!sec)
878878 {
879 - DEBUGF( "read_fat_entry() - Could not cache sector %d\n", sector);
 879+ DEBUGF( "read_fat_entry() - Could not cache sector %d", sector);
880880 return -1;
881881 }
882882
@@ -891,7 +891,7 @@
892892 sec = cache_fat_sector(IF_MV2(fat_bpb,) sector, false);
893893 if (!sec)
894894 {
895 - DEBUGF( "read_fat_entry() - Could not cache sector %ld\n", sector);
 895+ DEBUGF( "read_fat_entry() - Could not cache sector %ld", sector);
896896 return -1;
897897 }
898898
@@ -943,7 +943,7 @@
944944 fat_bpb->startsector + fat_bpb->bpb_fsinfo, 1,fsinfo);
945945 if (rc < 0)
946946 {
947 - DEBUGF( "flush_fat() - Couldn't read FSInfo (error code %d)\n", rc);
 947+ DEBUGF( "flush_fat() - Couldn't read FSInfo (error code %d)", rc);
948948 return rc * 10 - 1;
949949 }
950950 intptr = (long*)&(fsinfo[FSINFO_FREECOUNT]);
@@ -956,7 +956,7 @@
957957 fat_bpb->startsector + fat_bpb->bpb_fsinfo,1,fsinfo);
958958 if (rc < 0)
959959 {
960 - DEBUGF( "flush_fat() - Couldn't write FSInfo (error code %d)\n", rc);
 960+ DEBUGF( "flush_fat() - Couldn't write FSInfo (error code %d)", rc);
961961 return rc * 10 - 2;
962962 }
963963
@@ -968,7 +968,7 @@
969969 int i;
970970 int rc;
971971 unsigned char *sec;
972 - DEBUGF("flush_fat()\n");
 972+ DEBUGF("flush_fat()");
973973
974974 mutex_lock(&cache_mutex);
975975 for(i = 0;i < FAT_CACHE_SIZE;i++)
@@ -1108,7 +1108,7 @@
11091109 int rc;
11101110 unsigned short name_utf16[namelen + 1];
11111111
1112 - DEBUGF("write_long_name(file:%lx, first:%d, num:%d, name:%s)\n",
 1112+ DEBUGF("write_long_name(file:%lx, first:%d, num:%d, name:%s)",
11131113 file->firstcluster, firstentry, numentries, name);
11141114
11151115 rc = fat_seek(file, sector);
@@ -1149,7 +1149,7 @@
11501150 /* read next sector */
11511151 rc = fat_readwrite(file, 1, buf, false);
11521152 if (rc<0) {
1153 - DEBUGF("Failed writing new sector: %d\n",rc);
 1153+ DEBUGF("Failed writing new sector: %d",rc);
11541154 return rc * 10 - 5;
11551155 }
11561156 if (rc==0)
@@ -1164,7 +1164,7 @@
11651165
11661166 /* verify this entry is free */
11671167 if (entry[0] && entry[0] != 0xe5 )
1168 - panicf("Dir entry %d in sector %x is not free! "
 1168+ panicf(PANIC_KILLUSERTHREADS, "Dir entry %d in sector %x is not free! "
11691169 "%02x %02x %02x %02x",
11701170 idx, sector,
11711171 entry[0], entry[1], entry[2], entry[3]);
@@ -1202,12 +1202,12 @@
12031203 entry[FATDIR_FSTCLUSLO] = 0;
12041204 entry[FATLONG_TYPE] = 0;
12051205 entry[FATLONG_CHKSUM] = chksum;
1206 - DEBUGF("Longname entry %d: %s\n", idx, name+nameidx);
 1206+ DEBUGF("Longname entry %d: %s", idx, name+nameidx);
12071207 }
12081208 else {
12091209 /* shortname entry */
12101210 unsigned short date=0, time=0, tenth=0;
1211 - DEBUGF("Shortname entry: %s\n", shortname);
 1211+ DEBUGF("Shortname entry: %s", shortname);
12121212 memcpy(entry + FATDIR_NAME, shortname, 11);
12131213 entry[FATDIR_ATTR] = is_directory?FAT_ATTR_DIRECTORY:0;
12141214 entry[FATDIR_NTRES] = 0;
@@ -1277,7 +1277,7 @@
12781278 int entries_needed, entries_found = 0;
12791279 int firstentry;
12801280
1281 - DEBUGF( "add_dir_entry(%s,%lx)\n",
 1281+ DEBUGF( "add_dir_entry(%s,%lx)",
12821282 name, file->firstcluster);
12831283
12841284 /* Don't check dotdirs name for validity */
@@ -1325,12 +1325,12 @@
13261326 rc = fat_readwrite(&dir->file, 1, buf, false);
13271327 if (rc < 0) {
13281328 DEBUGF( "add_dir_entry() - Couldn't read dir"
1329 - " (error code %d)\n", rc);
 1329+ " (error code %d)", rc);
13301330 return rc * 10 - 3;
13311331 }
13321332
13331333 if (rc == 0) { /* current end of dir reached */
1334 - DEBUGF("End of dir on cluster boundary\n");
 1334+ DEBUGF("End of dir on cluster boundary");
13351335 break;
13361336 }
13371337
@@ -1340,7 +1340,7 @@
13411341 switch (buf[i * DIR_ENTRY_SIZE]) {
13421342 case 0:
13431343 entries_found += DIR_ENTRIES_PER_SECTOR - i;
1344 - DEBUGF("Found end of dir %d\n",
 1344+ DEBUGF("Found end of dir %d",
13451345 sector * DIR_ENTRIES_PER_SECTOR + i);
13461346 i = DIR_ENTRIES_PER_SECTOR - 1;
13471347 done = true;
@@ -1348,7 +1348,7 @@
13491349
13501350 case 0xe5:
13511351 entries_found++;
1352 - DEBUGF("Found free entry %d (%d/%d)\n",
 1352+ DEBUGF("Found free entry %d (%d/%d)",
13531353 sector * DIR_ENTRIES_PER_SECTOR + i,
13541354 entries_found, entries_needed);
13551355 break;
@@ -1360,7 +1360,7 @@
13611361 if (!strncmp(shortname, buf + i * DIR_ENTRY_SIZE, 11)) {
13621362 /* shortname exists already, make a new one */
13631363 randomize_dos_name(shortname);
1364 - DEBUGF("Duplicate shortname, changing to %s\n",
 1364+ DEBUGF("Duplicate shortname, changing to %s",
13651365 shortname);
13661366
13671367 /* name has changed, we need to restart search */
@@ -1377,7 +1377,7 @@
13781378 /* step 2: extend the dir if necessary */
13791379 if (firstentry < 0)
13801380 {
1381 - DEBUGF("Adding new sector(s) to dir\n");
 1381+ DEBUGF("Adding new sector(s) to dir");
13821382 rc = fat_seek(&dir->file, sector);
13831383 if (rc < 0)
13841384 return rc * 10 - 4;
@@ -1402,7 +1402,7 @@
14031403
14041404 /* step 3: add entry */
14051405 sector = firstentry / DIR_ENTRIES_PER_SECTOR;
1406 - DEBUGF("Adding longname to entry %d in sector %d\n",
 1406+ DEBUGF("Adding longname to entry %d in sector %d",
14071407 firstentry, sector);
14081408
14091409 rc = write_long_name(&dir->file, firstentry,
@@ -1414,7 +1414,7 @@
14151415 file->direntry = firstentry + entries_needed - 1;
14161416 file->direntries = entries_needed;
14171417 file->dircluster = dir->file.firstcluster;
1418 - DEBUGF("Added new dir entry %d, using %d slots.\n",
 1418+ DEBUGF("Added new dir entry %d, using %d slots.",
14191419 file->direntry, file->direntries);
14201420
14211421 return 0;
@@ -1535,7 +1535,7 @@
15361536 struct fat_file dir;
15371537 int rc;
15381538
1539 - DEBUGF("update_file_size(cluster:%lx entry:%d size:%ld)\n",
 1539+ DEBUGF("update_file_size(cluster:%lx entry:%d size:%ld)",
15401540 file->firstcluster, file->direntry, size);
15411541
15421542 /* create a temporary file handle for the dir holding this file */
@@ -1552,7 +1552,7 @@
15531553 return rc * 10 - 3;
15541554
15551555 if (!entry[0] || entry[0] == 0xe5)
1556 - panicf("Updating size on empty dir entry %d\n", file->direntry);
 1556+ panicf(PANIC_KILLUSERTHREADS, "Updating size on empty dir entry %d", file->direntry);
15571557
15581558 entry[FATDIR_ATTR] = attr & 0xFF;
15591559
@@ -1656,12 +1656,12 @@
16571657 /* fixme: remove error check when done */
16581658 if (volume >= NUM_VOLUMES || !fat_bpbs[volume].mounted)
16591659 {
1660 - DEBUGF("fat_open() illegal volume %d\n", volume);
 1660+ DEBUGF("fat_open() illegal volume %d", volume);
16611661 return -1;
16621662 }
16631663 #endif
16641664
1665 - DEBUGF("fat_open(%lx), entry %d\n",startcluster,file->direntry);
 1665+ DEBUGF("fat_open(%lx), entry %d",startcluster,file->direntry);
16661666 return 0;
16671667 }
16681668
@@ -1671,7 +1671,7 @@
16721672 {
16731673 int rc;
16741674
1675 - DEBUGF("fat_create_file(\"%s\",%lx,%lx)\n",name,(long)file,(long)dir);
 1675+ DEBUGF("fat_create_file(\"%s\",%lx,%lx)",name,(long)file,(long)dir);
16761676 rc = add_dir_entry(dir, file, name, false, false);
16771677 if (!rc) {
16781678 file->firstcluster = 0;
@@ -1700,7 +1700,7 @@
17011701 int rc;
17021702 struct fat_file dummyfile;
17031703
1704 - DEBUGF("fat_create_dir(\"%s\",%lx,%lx)\n",name,(long)newdir,(long)dir);
 1704+ DEBUGF("fat_create_dir(\"%s\",%lx,%lx)",name,(long)newdir,(long)dir);
17051705
17061706 memset(newdir, 0, sizeof(struct fat_dir));
17071707 memset(&dummyfile, 0, sizeof(struct fat_file));
@@ -1765,7 +1765,7 @@
17661766 struct bpb* fat_bpb = &fat_bpbs[file->volume];
17671767 #endif
17681768
1769 - DEBUGF("fat_truncate(%lx, %lx)\n", file->firstcluster, last);
 1769+ DEBUGF("fat_truncate(%lx, %lx)", file->firstcluster, last);
17701770
17711771 for ( last = get_next_cluster(IF_MV2(fat_bpb,) last); last; last = next ) {
17721772 next = get_next_cluster(IF_MV2(fat_bpb,) last);
@@ -1783,7 +1783,7 @@
17841784 #ifdef HAVE_MULTIVOLUME
17851785 struct bpb* fat_bpb = &fat_bpbs[file->volume];
17861786 #endif
1787 - DEBUGF("fat_closewrite(size=%ld)\n",size);
 1787+ DEBUGF("fat_closewrite(size=%ld)",size);
17881788
17891789 if (!size) {
17901790 /* empty file */
@@ -1814,16 +1814,16 @@
18151815 long next;
18161816 for ( next = file->firstcluster; next;
18171817 next = get_next_cluster(IF_MV2(fat_bpb,) next) ) {
1818 - DEBUGF("cluster %ld: %lx\n", count, next);
 1818+ DEBUGF("cluster %ld: %lx", count, next);
18191819 count++;
18201820 }
18211821 len = count * fat_bpb->bpb_secperclus * SECTOR_SIZE;
1822 - DEBUGF("File is %ld clusters (chainlen=%ld, size=%ld)\n",
 1822+ DEBUGF("File is %ld clusters (chainlen=%ld, size=%ld)",
18231823 count, len, size );
18241824 if ( len > size + fat_bpb->bpb_secperclus * SECTOR_SIZE)
1825 - panicf("Cluster chain is too long\n");
 1825+ panicf(PANIC_KILLUSERTHREADS, "Cluster chain is too long");
18261826 if ( len < size )
1827 - panicf("Cluster chain is too short\n");
 1827+ panicf(PANIC_KILLUSERTHREADS, "Cluster chain is too short");
18281828 }
18291829 #endif
18301830
@@ -1854,7 +1854,7 @@
18551855 return rc * 10 - 3;
18561856
18571857 for (i=0; i < numentries; i++) {
1858 - DEBUGF("Clearing dir entry %d (%d/%d)\n",
 1858+ DEBUGF("Clearing dir entry %d (%d/%d)",
18591859 entry, i+1, numentries);
18601860 buf[(entry % DIR_ENTRIES_PER_SECTOR) * DIR_ENTRY_SIZE] = 0xe5;
18611861 entry++;
@@ -1901,7 +1901,7 @@
19021902 struct bpb* fat_bpb = &fat_bpbs[file->volume];
19031903 #endif
19041904
1905 - DEBUGF("fat_remove(%lx)\n",last);
 1905+ DEBUGF("fat_remove(%lx)",last);
19061906
19071907 while ( last ) {
19081908 next = get_next_cluster(IF_MV2(fat_bpb,) last);
@@ -1942,7 +1942,7 @@
19431943 struct bpb* fat_bpb = &fat_bpbs[file->volume];
19441944
19451945 if (file->volume != dir->file.volume) {
1946 - DEBUGF("No rename across volumes!\n");
 1946+ DEBUGF("No rename across volumes!");
19471947 return -1;
19481948 }
19491949 #else
@@ -1950,7 +1950,7 @@
19511951 #endif
19521952
19531953 if ( !file->dircluster ) {
1954 - DEBUGF("File has no dir cluster!\n");
 1954+ DEBUGF("File has no dir cluster!");
19551955 return -2;
19561956 }
19571957
@@ -2006,7 +2006,7 @@
20072007 if(strncmp(".. ", entry, 11))
20082008 {
20092009 /* .. entry must be second entry according to FAT spec (p.29) */
2010 - DEBUGF("Second dir entry is not double-dot!\n");
 2010+ DEBUGF("Second dir entry is not double-dot!");
20112011 return rc * 10 - 9;
20122012 }
20132013 clusptr = (short*)(entry + FATDIR_FSTCLUSHI);
@@ -2040,7 +2040,7 @@
20412041 long cluster = 0;
20422042 long sector;
20432043
2044 - DEBUGF("next_write_cluster(%lx,%lx)\n",file->firstcluster, oldcluster);
 2044+ DEBUGF("next_write_cluster(%lx,%lx)",file->firstcluster, oldcluster);
20452045
20462046 if (oldcluster)
20472047 cluster = get_next_cluster(IF_MV2(fat_bpb,) oldcluster);
@@ -2066,10 +2066,10 @@
20672067 else {
20682068 #ifdef TEST_FAT
20692069 if (fat_bpb->fsinfo.freecount>0)
2070 - panicf("There is free space, but find_free_cluster() "
2071 - "didn't find it!\n");
 2070+ panicf(PANIC_KILLUSERTHREADS, "There is free space, but find_free_cluster() "
 2071+ "didn't find it!");
20722072 #endif
2073 - DEBUGF("next_write_cluster(): Disk full!\n");
 2073+ DEBUGF("next_write_cluster(): Disk full!");
20742074 return 0;
20752075 }
20762076 }
@@ -2089,7 +2089,7 @@
20902090 #endif
20912091 int rc;
20922092
2093 - DEBUGF("transfer(s=%lx, c=%lx, %s)\n",
 2093+ DEBUGF("transfer(s=%lx, c=%lx, %s)",
20942094 start+ fat_bpb->startsector, count, write?"write":"read");
20952095 if (write) {
20962096 unsigned long firstallowed;
@@ -2101,9 +2101,9 @@
21022102 firstallowed = fat_bpb->firstdatasector;
21032103
21042104 if (start < firstallowed)
2105 - panicf("Write %ld before data\n", firstallowed - start);
 2105+ panicf(PANIC_KILLUSERTHREADS, "Write %ld before data", firstallowed - start);
21062106 if (start + count > fat_bpb->totalsectors)
2107 - panicf("Write %ld after data\n",
 2107+ panicf(PANIC_KILLUSERTHREADS, "Write %ld after data",
21082108 start + count - fat_bpb->totalsectors);
21092109 rc = storage_write_sectors(IF_MD2(fat_bpb->drive,)
21102110 start + fat_bpb->startsector, count, buf);
@@ -2113,7 +2113,7 @@
21142114 start + fat_bpb->startsector, count, buf);
21152115 if (rc < 0) {
21162116 DEBUGF( "transfer() - Couldn't %s sector %lx"
2117 - " (error code %d)\n",
 2117+ " (error code %d)",
21182118 write ? "write":"read", start, rc);
21192119 return rc;
21202120 }
@@ -2138,9 +2138,9 @@
21392139 long i;
21402140 int rc;
21412141
2142 - DEBUGF( "fat_readwrite(file:%lx,count:0x%lx,buf:%lx,%s)\n",
 2142+ DEBUGF( "fat_readwrite(file:%lx,count:0x%lx,buf:%lx,%s)",
21432143 file->firstcluster,sectorcount,(long)buf,write?"write":"read");
2144 - DEBUGF( "fat_readwrite: sec=%lx numsec=%ld eof=%d\n",
 2144+ DEBUGF( "fat_readwrite: sec=%lx numsec=%ld eof=%d",
21452145 sector,numsec, eof?1:0);
21462146
21472147 if ( eof && !write)
@@ -2232,7 +2232,7 @@
22332233 if (eof)
22342234 i--;
22352235
2236 - DEBUGF("Sectors written: %ld\n", i);
 2236+ DEBUGF("Sectors written: %ld", i);
22372237 return i;
22382238 }
22392239
@@ -2270,7 +2270,7 @@
22712271 cluster = get_next_cluster(IF_MV2(fat_bpb,) cluster);
22722272 if (!cluster) {
22732273 DEBUGF("Seeking beyond the end of the file! "
2274 - "(sector %ld, cluster %ld)\n", seeksector, i);
 2274+ "(sector %ld, cluster %ld)", seeksector, i);
22752275 return -1;
22762276 }
22772277 }
@@ -2281,7 +2281,7 @@
22822282 sectornum = -1;
22832283 }
22842284
2285 - DEBUGF("fat_seek(%lx, %lx) == %lx, %lx, %lx\n",
 2285+ DEBUGF("fat_seek(%lx, %lx) == %lx, %lx, %lx",
22862286 file->firstcluster, seeksector, cluster, sector, sectornum);
22872287
22882288 file->lastcluster = cluster;
@@ -2300,7 +2300,7 @@
23012301 /* fixme: remove error check when done */
23022302 if (volume >= NUM_VOLUMES || !fat_bpbs[volume].mounted)
23032303 {
2304 - DEBUGF("fat_open() illegal volume %d\n", volume);
 2304+ DEBUGF("fat_open() illegal volume %d", volume);
23052305 return -1;
23062306 }
23072307 #else
@@ -2315,7 +2315,7 @@
23162316 if(rc)
23172317 {
23182318 DEBUGF( "fat_opendir() - Couldn't open dir"
2319 - " (error code %d)\n", rc);
 2319+ " (error code %d)", rc);
23202320 return rc * 10 - 1;
23212321 }
23222322
@@ -2356,7 +2356,7 @@
23572357 }
23582358 if (rc < 0) {
23592359 DEBUGF( "fat_getnext() - Couldn't read dir"
2360 - " (error code %d)\n", rc);
 2360+ " (error code %d)", rc);
23612361 return rc * 10 - 1;
23622362 }
23632363 dir->sector = dir->file.lastsector;
Index: embios/trunk/thread.h
@@ -58,7 +58,8 @@
5959 THREAD_BLOCK_SLEEP,
6060 THREAD_BLOCK_MUTEX,
6161 THREAD_BLOCK_WAKEUP,
62 - THREAD_DEFUNCT_STKOV
 62+ THREAD_DEFUNCT_STKOV,
 63+ THREAD_DEFUNCT_PANIC
6364 };
6465
6566 enum thread_type
Index: embios/trunk/dir.c
@@ -72,7 +72,7 @@
7373 #endif
7474
7575 if ( name[0] != '/' ) {
76 - DEBUGF("Only absolute paths supported right now\n");
 76+ DEBUGF("Only absolute paths supported right now");
7777 return NULL;
7878 }
7979
@@ -82,7 +82,7 @@
8383 break;
8484
8585 if ( dd == MAX_OPEN_DIRS ) {
86 - DEBUGF("Too many dirs open\n");
 86+ DEBUGF("Too many dirs open");
8787 errno = EMFILE;
8888 return NULL;
8989 }
@@ -98,7 +98,7 @@
9999 #endif
100100
101101 if ( fat_opendir(IF_MV2(volume,) &pdir->fatdir, 0, NULL) < 0 ) {
102 - DEBUGF("Failed opening root dir\n");
 102+ DEBUGF("Failed opening root dir");
103103 pdir->busy = false;
104104 return NULL;
105105 }
@@ -128,7 +128,7 @@
129129 &pdir->fatdir,
130130 entry.firstcluster,
131131 &pdir->fatdir) < 0 ) {
132 - DEBUGF("Failed opening dir '%s' (%ld)\n",
 132+ DEBUGF("Failed opening dir '%s' (%ld)",
133133 part, entry.firstcluster);
134134 pdir->busy = false;
135135 return NULL;
@@ -208,7 +208,7 @@
209209 int rc;
210210
211211 if ( name[0] != '/' ) {
212 - DEBUGF("mkdir: Only absolute paths supported right now\n");
 212+ DEBUGF("mkdir: Only absolute paths supported right now");
213213 return -1;
214214 }
215215
@@ -224,17 +224,17 @@
225225 else
226226 parent = namecopy;
227227
228 - DEBUGF("mkdir: parent: %s, name: %s\n", parent, basename);
 228+ DEBUGF("mkdir: parent: %s, name: %s", parent, basename);
229229
230230 dir = opendir(parent);
231231
232232 if(!dir) {
233 - DEBUGF("mkdir: can't open parent dir\n");
 233+ DEBUGF("mkdir: can't open parent dir");
234234 return -2;
235235 }
236236
237237 if(basename[0] == 0) {
238 - DEBUGF("mkdir: Empty dir name\n");
 238+ DEBUGF("mkdir: Empty dir name");
239239 errno = EINVAL;
240240 return -3;
241241 }
@@ -242,7 +242,7 @@
243243 /* Now check if the name already exists */
244244 while ((entry = readdir(dir))) {
245245 if ( !strcasecmp(basename, entry->d_name) ) {
246 - DEBUGF("mkdir error: file exists\n");
 246+ DEBUGF("mkdir error: file exists");
247247 errno = EEXIST;
248248 closedir(dir);
249249 return - 4;
@@ -276,7 +276,7 @@
277277 if (strcmp(entry->d_name, ".") &&
278278 strcmp(entry->d_name, ".."))
279279 {
280 - DEBUGF("rmdir error: not empty\n");
 280+ DEBUGF("rmdir error: not empty");
281281 errno = ENOTEMPTY;
282282 closedir(dir);
283283 return -2;
@@ -285,7 +285,7 @@
286286
287287 rc = fat_remove(&(dir->fatdir.file));
288288 if ( rc < 0 ) {
289 - DEBUGF("Failed removing dir: %d\n", rc);
 289+ DEBUGF("Failed removing dir: %d", rc);
290290 errno = EIO;
291291 rc = rc * 10 - 3;
292292 }
Index: embios/trunk/file.c
@@ -73,11 +73,11 @@
7474 (void)use_cache;
7575 #endif
7676
77 - DEBUGF("open(\"%s\",%d)\n",pathname,flags);
 77+ DEBUGF("open(\"%s\",%d)",pathname,flags);
7878
7979 if ( pathname[0] != '/' ) {
80 - DEBUGF("'%s' is not an absolute path.\n",pathname);
81 - DEBUGF("Only absolute pathnames supported at the moment\n");
 80+ DEBUGF("'%s' is not an absolute path.",pathname);
 81+ DEBUGF("Only absolute pathnames supported at the moment");
8282 errno = EINVAL;
8383 return -1;
8484 }
@@ -88,7 +88,7 @@
8989 break;
9090
9191 if ( fd == MAX_OPEN_FILES ) {
92 - DEBUGF("Too many files open\n");
 92+ DEBUGF("Too many files open");
9393 errno = EMFILE;
9494 return -2;
9595 }
@@ -148,7 +148,7 @@
149149 name = pathnamecopy+1;
150150 }
151151 if (!dir) {
152 - DEBUGF("Failed opening dir\n");
 152+ DEBUGF("Failed opening dir");
153153 errno = EIO;
154154 file->busy = false;
155155 return -4;
@@ -155,7 +155,7 @@
156156 }
157157
158158 if(name[0] == 0) {
159 - DEBUGF("Empty file name\n");
 159+ DEBUGF("Empty file name");
160160 errno = EINVAL;
161161 file->busy = false;
162162 closedir(dir);
@@ -176,13 +176,13 @@
177177 }
178178
179179 if ( !entry ) {
180 - DEBUGF("Didn't find file %s\n",name);
 180+ DEBUGF("Didn't find file %s",name);
181181 if ( file->write && (flags & O_CREAT) ) {
182182 rc = fat_create_file(name,
183183 &(file->fatfile),
184184 &(dir->fatdir));
185185 if (rc < 0) {
186 - DEBUGF("Couldn't create %s in %s\n",name,pathnamecopy);
 186+ DEBUGF("Couldn't create %s in %s",name,pathnamecopy);
187187 errno = EIO;
188188 file->busy = false;
189189 closedir(dir);
@@ -195,7 +195,7 @@
196196 file->attr = 0;
197197 }
198198 else {
199 - DEBUGF("Couldn't find %s in %s\n",name,pathnamecopy);
 199+ DEBUGF("Couldn't find %s in %s",name,pathnamecopy);
200200 errno = ENOENT;
201201 file->busy = false;
202202 closedir(dir);
@@ -239,7 +239,7 @@
240240 struct filedesc* file = &openfiles[fd];
241241 int rc = 0;
242242
243 - DEBUGF("close(%d)\n", fd);
 243+ DEBUGF("close(%d)", fd);
244244
245245 if (fd < 0 || fd > MAX_OPEN_FILES-1) {
246246 errno = EINVAL;
@@ -268,7 +268,7 @@
269269 struct filedesc* file = &openfiles[fd];
270270 int rc = 0;
271271
272 - DEBUGF("fsync(%d)\n", fd);
 272+ DEBUGF("fsync(%d)", fd);
273273
274274 if (fd < 0 || fd > MAX_OPEN_FILES-1) {
275275 errno = EINVAL;
@@ -324,7 +324,7 @@
325325 #endif
326326 rc = fat_remove(&(file->fatfile));
327327 if ( rc < 0 ) {
328 - DEBUGF("Failed removing file: %d\n", rc);
 328+ DEBUGF("Failed removing file: %d", rc);
329329 errno = EIO;
330330 return rc * 10 - 3;
331331 }
@@ -403,7 +403,7 @@
404404 if ( rc == -1) {
405405 close(fd);
406406 closedir(dir);
407 - DEBUGF("Failed renaming file across volumnes: %d\n", rc);
 407+ DEBUGF("Failed renaming file across volumnes: %d", rc);
408408 errno = EXDEV;
409409 return -6;
410410 }
@@ -411,7 +411,7 @@
412412 if ( rc < 0 ) {
413413 close(fd);
414414 closedir(dir);
415 - DEBUGF("Failed renaming file: %d\n", rc);
 415+ DEBUGF("Failed renaming file: %d", rc);
416416 errno = EIO;
417417 return rc * 10 - 7;
418418 }
@@ -471,7 +471,7 @@
472472 struct filedesc* file = &openfiles[fd];
473473 long sector = file->fileoffset / SECTOR_SIZE;
474474
475 - DEBUGF("Flushing dirty sector cache\n");
 475+ DEBUGF("Flushing dirty sector cache");
476476
477477 /* make sure we are on correct sector */
478478 rc = fat_seek(&(file->fatfile), sector);
@@ -516,7 +516,7 @@
517517 return -1;
518518 }
519519
520 - DEBUGF( "readwrite(%d,%lx,%ld,%s)\n",
 520+ DEBUGF( "readwrite(%d,%lx,%ld,%s)",
521521 fd,(long)buf,count,write?"write":"read");
522522
523523 /* attempt to read past EOF? */
@@ -564,10 +564,10 @@
565565 rc = fat_readwrite(&(file->fatfile), sectors,
566566 (unsigned char*)buf+nread, write );
567567 if ( rc < 0 ) {
568 - DEBUGF("Failed read/writing %ld sectors\n",sectors);
 568+ DEBUGF("Failed read/writing %ld sectors",sectors);
569569 errno = EIO;
570570 if(write && file->fatfile.eof) {
571 - DEBUGF("No space left on device\n");
 571+ DEBUGF("No space left on device");
572572 errno = ENOSPC;
573573 } else {
574574 file->fileoffset += nread;
@@ -606,10 +606,10 @@
607607 if (write) {
608608 if ( file->fileoffset + nread < file->size ) {
609609 /* sector is only partially filled. copy-back from disk */
610 - DEBUGF("Copy-back tail cache\n");
 610+ DEBUGF("Copy-back tail cache");
611611 rc = fat_readwrite(&(file->fatfile), 1, file->cache, false );
612612 if ( rc < 0 ) {
613 - DEBUGF("Failed writing\n");
 613+ DEBUGF("Failed writing");
614614 errno = EIO;
615615 file->fileoffset += nread;
616616 file->cacheoffset = -1;
@@ -628,7 +628,7 @@
629629 (file->fileoffset + nread) /
630630 SECTOR_SIZE);
631631 if ( rc < 0 ) {
632 - DEBUGF("fat_seek() failed\n");
 632+ DEBUGF("fat_seek() failed");
633633 errno = EIO;
634634 file->fileoffset += nread;
635635 file->cacheoffset = -1;
@@ -649,7 +649,7 @@
650650 else {
651651 rc = fat_readwrite(&(file->fatfile), 1, file->cache,false);
652652 if (rc < 1 ) {
653 - DEBUGF("Failed caching sector\n");
 653+ DEBUGF("Failed caching sector");
654654 errno = EIO;
655655 file->fileoffset += nread;
656656 file->cacheoffset = -1;
@@ -663,7 +663,7 @@
664664 }
665665
666666 file->fileoffset += nread;
667 - DEBUGF("fileoffset: %ld\n", file->fileoffset);
 667+ DEBUGF("fileoffset: %ld", file->fileoffset);
668668
669669 /* adjust file size to length written */
670670 if ( write && file->fileoffset > file->size )
@@ -701,7 +701,7 @@
702702 int rc;
703703 struct filedesc* file = &openfiles[fd];
704704
705 - DEBUGF("lseek(%d,%ld,%d)\n",fd,offset,whence);
 705+ DEBUGF("lseek(%d,%ld,%d)",fd,offset,whence);
706706
707707 if (fd < 0 || fd > MAX_OPEN_FILES-1) {
708708 errno = EINVAL;