static void dump_integer(long value) { if (SCHAR_MIN <= value && value <= SCHAR_MAX) { dump_op(fop_SIGNED_BYTE); dump_byte(value); } else if (SHRT_MIN <= value && value <= SHRT_MAX) { dump_op(fop_SIGNED_SHORT); dump_short((short)value); } else if (INT_MIN <= value && value <= INT_MAX) { dump_op(fop_SIGNED_INT); dump_int(value); } else { dump_op(fop_SIGNED_LONG); dump_long(value); } }
static void show(long * l, int h, int w){ int i, j; int counter = 0; int n_bytes; n_bytes = NBYTES(w); printf(" "); for(i = 0 ; i < w ; i++){ printf("%d", i % 10); } printf("\n"); for(i = 0 ; i < h ; i++){ printf("%3d ", i); for(j = 0 ; j < n_bytes ; j++){ dump_long(l[counter], (j == n_bytes - 1) ? ((w - 1) % ARCH + 1) : ARCH); counter++; } printf("\n"); } }
int fatfindfile(char *fname) { int rc, i, j; putstr("--MBR--\n"); rc = readblock(DOSBBSECTOR, buf); if (dos_partition(0)->dp_typ != 6) { putstr("bad partition type\n"); return -1; }; start = getulong(dos_partition(0)->dp_start); dump_long("start ", start); putstr("--BOOT--\n"); rc = readblock(start, buf); if (getushort(bootsector->bpbBytesPerSec) != 512) { putstr("bad sector size\n"); return -1; }; cluster_size = bootsector->bpbSecPerClust; dump_long("cluster_size ", cluster_size); start_fat = start + getushort(bootsector->bpbResSectors); dump_long("start_fat ", start_fat); root_size = getushort(bootsector->bpbRootDirEnts); root_size = (root_size * 32+511)/512; dump_long("root_size ", root_size); dump_long("FATsecs ", getushort(bootsector->bpbFATsecs)); dump_long("FATs ", bootsector->bpbFATs); start_root = start_fat + bootsector->bpbFATs * getushort(bootsector->bpbFATsecs); start = start_root + root_size - 2 * cluster_size; /* first data sector for 0-based clusters */ dump_long("start_root ", start_root); current_cluster = 0; putstr("--ROOT--\n"); for(j = 0; j<root_size; j++) { rc = readblock(start_root + j, buf); for(i = 0; i<16; i++) { rc = (direntry(i)->deName)[0]; if (rc == SLOT_EMPTY || rc == SLOT_DELETED) continue; rc = direntry(i)->deAttributes & (ATTR_VOLUME|ATTR_DIRECTORY); if (rc) continue; current_cluster = getushort(direntry(i)->deStartCluster); bytes_left = getulong(direntry(i)->deFileSize); putstr(direntry(i)->deName); putnl(); /* printf("%12s %02x %ld %ld\n", direntry(i)->deName, direntry(i)->deAttributes & 0x18, current_cluster, bytes_left ); */ if (!strncmp(direntry(i)->deName, fname, 11)) { break; }; current_cluster = 0; }; if (current_cluster) break; }; if (!current_cluster) { putstr("file not found\n"); return -1; }; current_sector = 0; putstr("File ok\n"); return 0; }