phantom_disk_partition_t *select_phantom_partition(void) { if(n_phantom_fs_partitions == 0) panic("no Phantom disk"); if(n_phantom_fs_partitions == 1) { assert( phantom_fs_partitions[0] ); char pname[128]; partGetName( phantom_fs_partitions[0], pname, sizeof(pname) ); SHOW_FLOW( 0, "Just one Phantom disks found (%s)", pname); return phantom_fs_partitions[0]; } printf("Select Phantom disk to boot:\n"); int i; for( i = 0; i < n_phantom_fs_partitions; i++ ) { phantom_disk_partition_t *p = phantom_fs_partitions[i]; if(p) { char pname[128]; partGetName( p, pname, sizeof(pname) ); printf("%2d: %s\n", i, pname ); } } do { printf("Press digit (0-%d): \n", n_phantom_fs_partitions-1 ); char c = getchar(); if( c < '0' || c > '9' ) continue; int n = c-'0'; if( (n > MAX_PFS_PARTS) || (n < 0) ) continue; phantom_disk_partition_t *p = phantom_fs_partitions[n]; if( !p ) continue; return p; } while(1); }
//! Get full name for partition (incl subparts) static errno_t doPartGetName( phantom_disk_partition_t *p, char *buf, size_t bufsz ) { if( p->base ) partGetName( p->base, buf, bufsz ); if( strlcat( buf, "/", bufsz ) >= bufsz ) return ENOMEM; if( strlcat( buf, p->name, bufsz ) >= bufsz ) return ENOMEM; return 0; }
errno_t lookup_fs(phantom_disk_partition_t *p) { char pname[128]; partGetName( p, pname, sizeof(pname) ); SHOW_INFO( 0, "Look for filesystems on partition %s", pname ); unsigned int i; for( i = 0; i < sizeof(fs_drivers)/sizeof(fs_probe_t); i++ ) { fs_probe_t *fp = &fs_drivers[i]; SHOW_INFO( 0, "probe %s fs on %s", fp->name, pname ); errno_t ret = fp->probe_f( p ); if( ret ) continue; SHOW_INFO( 0, "%s file sysem found on partition %s", fp->name, pname ); if(!fp->use_f) { SHOW_ERROR( 0, "%s file sysem is not implemented yet", fp->name ); continue; } #if FS_START_THREAD // BUG HACK - activate phantom fs syncronously, or else we will die attempting to use it if(fp->use_f == fs_use_phantom) fp->use_f( p ); else hal_start_kernel_thread_arg( (void (*)(void *))fp->use_f, p ); #else ret = fp->use_f( p ); if( ret ) { SHOW_ERROR( 0, "%s file sysem driver rejected partition %s", fp->name, pname ); continue; } SHOW_INFO( 0, "%s file sysem driver occupies partition %s", fp->name, pname ); #endif return 0; } return EINVAL; }
errno_t fs_use_phantom(phantom_disk_partition_t *p) { assert( p->flags | PART_FLAG_IS_PHANTOM_FSSB ); char pname[128]; partGetName( p, pname, sizeof(pname) ); if(n_phantom_fs_partitions < MAX_PFS_PARTS) { phantom_fs_partitions[n_phantom_fs_partitions++] = p; return 0; } else { SHOW_ERROR( 0, "Too many Phantom disks, skip %s", pname); return EMFILE; } }
void print_partition(phantom_disk_partition_t *p) { if( p == 0 ) { printf("attempt to print null Disk Partition\n"); return; } char pname[128]; if( partGetName( p, pname, sizeof(pname) ) ) { printf("Disk Partition ?? (%s)\n", p->label ); return; } long sz = p->block_size; sz *= p->size; sz /= 1024; char *un = "Kb"; if( sz > 1024*10 ) { un = "Mb"; sz /= 1024; } if( sz > 1024*10 ) { un = "Gb"; sz /= 1024; } printf("Disk Partition %s (%s), %ld %d, flags %b\n", pname, p->label, sz, un, p->flags, "\020\1PhantomPartType\2PhantomFS\5Bootable\6Divided\7IsDisk" ); }
void dump_partition(phantom_disk_partition_t *p) { if( p == 0 ) { printf("attempt to dump null Disk Partition\n"); return; } char pname[128]; if( partGetName( p, pname, sizeof(pname) ) ) { printf("Disk Partition ?? (%s)\n", p->label ); return; } printf("Disk Partition %s (%s)\n", pname, p->label ); printf(" - type %d%s\n", p->type, p->type == PHANTOM_PARTITION_TYPE_ID ? " (phantom)" : "" ); printf(" - flags %b\n", p->flags, "\020\1PhantomPartType\2PhantomFS\5Bootable\6Divided\7IsDisk" ); printf(" - blksz %d, start %ld, size %ld\n", p->block_size, p->shift, p->size ); printf(" - %s base, %s specific\n", p->base ? "has" : "no", p->specific ? "has" : "no" ); }