int _selfword( const char *method, xt_t *cache_xt ) { if( !*cache_xt ) *cache_xt = find_ih_method( method, my_self() ); if( *cache_xt ) { enterforth( *cache_xt ); return 0; } return -1; }
/* ( -- cstr|0 ) */ static void hfsp_files_volume_name( hfsp_info_t *mi ) { int fd; char *volname = malloc(VOLNAME_SIZE); fd = open_ih(my_self()); if (fd >= 0) { get_hfs_vol_name(fd, volname, VOLNAME_SIZE); close_io(fd); } else { volname[0] = '\0'; } PUSH(pointer2cell(volname)); }
/* ( -- success? ) */ static void dlabel_open( dlabel_info_t *di ) { char *path; char block0[512]; phandle_t ph; int success=0; cell status; path = my_args_copy(); DPRINTF("dlabel-open '%s'\n", path ); di->part_ih = 0; /* Find parent methods */ di->filesystem_ph = 0; di->parent_seek_xt = find_parent_method("seek"); di->parent_tell_xt = find_parent_method("tell"); di->parent_read_xt = find_parent_method("read"); /* If arguments have been passed, determine the partition/filesystem type */ if (path && strlen(path)) { /* Read first block from parent device */ DPUSH(0); call_package(di->parent_seek_xt, my_parent()); POP(); PUSH(pointer2cell(block0)); PUSH(sizeof(block0)); call_package(di->parent_read_xt, my_parent()); status = POP(); if (status != sizeof(block0)) goto out; /* Find partition handler */ PUSH( pointer2cell(block0) ); selfword("find-part-handler"); ph = POP_ph(); if( ph ) { /* We found a suitable partition handler, so interpose it */ DPRINTF("Partition found on disk - scheduling interpose with ph " FMT_ucellx "\n", ph); push_str(path); PUSH_ph(ph); fword("interpose"); success = 1; } else { /* unknown (or missing) partition map, * try the whole disk */ DPRINTF("Unknown or missing partition map; trying whole disk\n"); /* Probe for filesystem from start of device */ DPUSH ( 0 ); PUSH_ih( my_self() ); selfword("find-filesystem"); ph = POP_ph(); if( ph ) { /* If we have been asked to open a particular file, interpose the filesystem package with the passed filename as an argument */ di->filesystem_ph = ph; DPRINTF("Located filesystem with ph " FMT_ucellx "\n", ph); DPRINTF("path: %s length: %d\n", path, strlen(path)); if (path && strlen(path)) { DPRINTF("INTERPOSE!\n"); push_str( path ); PUSH_ph( ph ); fword("interpose"); } } else if (path && strcmp(path, "%BOOT") != 0) { goto out; } success = 1; } } else { /* No arguments were passed, so we just use the parent raw device directly */ success = 1; } out: if( path ) free( path ); if( !success ) { dlabel_close( di ); RET(0); } PUSH(-1); }