Пример #1
0
/*
 * Open file descriptor for current disk (cur_file)
 *	with "p0" path or cur_disk->disk_path
 */
void
open_cur_file(int mode)
{
	char	*dkpath;
	char	pbuf[MAXPATHLEN];

	switch (mode) {
	    case FD_USE_P0_PATH:
		(void) get_pname(&pbuf[0]);
		dkpath = pbuf;
		break;
	    case FD_USE_CUR_DISK_PATH:
		if (cur_disk->fdisk_part.systid == SUNIXOS ||
		    cur_disk->fdisk_part.systid == SUNIXOS2) {
			(void) get_sname(&pbuf[0]);
			dkpath = pbuf;
		} else {
			dkpath = cur_disk->disk_path;
		}
		break;
	    default:
		err_print("Error: Invalid mode option for opening cur_file\n");
		fullabort();
	}

	/* Close previous cur_file */
	(void) close(cur_file);
	/* Open cur_file with the required path dkpath */
	if ((cur_file = open_disk(dkpath, O_RDWR | O_NDELAY)) < 0) {
		err_print(
		    "Error: can't open selected disk '%s'.\n", dkpath);
		fullabort();
	}
}
Пример #2
0
/*
 *	Open device nodes of all disks, and store the file descriptors in fds.
 *	This has to be done in advance because accessing the device nodes
 *	might cause a disk to spin back up.
 */
static int open_disks(const char **disks, int *fds, int count)
{
	int i;

	for (i = 0; i < count; i++)
		fds[i] = open_disk(disks[i]);

	return 0;
}
Пример #3
0
int open_disks(struct sync_disk *disks, int num_disks)
{
	struct sync_disk *disk;
	int num_opens = 0;
	int d, err, rv = -1;
	uint32_t ss = 0;

	for (d = 0; d < num_disks; d++) {
		disk = &disks[d];

		if (disk->fd != -1) {
			log_error("open fd %d exists %s", disk->fd, disk->path);
			rv = -ENOTEMPTY;
			goto fail;
		}

		err = open_disk(disk);
		if (err < 0) {
			rv = err;
			continue;
		}

		if (!ss) {
			ss = disk->sector_size;
		} else if (ss != disk->sector_size) {
			log_error("inconsistent sector sizes %u %u %s",
				  ss, disk->sector_size, disk->path);
			goto fail;
		}

		num_opens++;
	}

	if (!majority_disks(num_disks, num_opens)) {
		/* rv is from open err */
		goto fail;
	}

	return 0;

 fail:
	close_disks(disks, num_disks);
	return rv;
}
Пример #4
0
void vir_machine_init()
{
	init_log_record();
	init_console();
	init_display_mem();
	open_disk();
	/**
	 * initialize cpu
	 */
	int i;
	for (i = 0; i < CPU_REG_NUM; i++)
		R[i] = 0;
	memory = (mem_word *)malloc(sizeof(mem_word) * MEM_SIZE);
	/**
	 * TODO !
	 * INITIAL CP0
	 * CP0[32]...
	 */
}
Пример #5
0
VOID
open_def( )
{
    REG WORD	i;
    REG WINDOW	*win;

    wind_update(1);

    win = winpd;

    for ( i = 0; i < MAXWIN; i++ )
    {
        if ( win[i].w_path[0] )
        {
            if ( !open_disk( 0, win[i].w_path, FALSE ) )
                win[i].w_path[0] = 0;
        }
    }

    wind_update(0);
}
Пример #6
0
/* Extract all files in an archive to the filesystem under the path given by
 * dest. Returns 0 on success or <0 on error.
 */
static int extract_all(struct archive *a, const char *dest, int flags)
{
    struct archive *disk;
    struct archive_entry *entry;
    int r;
    int eof;

    disk = open_disk(flags);
    if (!disk)
        return -1;

    while (1) {
        entry = read_header(a, &eof);
        if (eof)
            break;
        if (!entry) {
            r = -1;
            goto err_cleanup;
        }

        r = transform_all_paths(entry, dest);
        if (r == 1)
            continue;
        if (r < 0) {
            opkg_msg(ERROR, "Failed to transform path.\n");
            goto err_cleanup;
        }

        print_paths(entry);

        r = extract_entry(a, entry, disk);
        if (r < 0)
            goto err_cleanup;
    }

    r = ARCHIVE_OK;
 err_cleanup:
    archive_write_free(disk);
    return (r == ARCHIVE_OK) ? 0 : -1;
}
Пример #7
0
/*****************************************************************
Disk housekeeping that must be done for both source and destination disks
Open disk
get partition table
get base address of desired partition
deal with errors
write record keeping info to log file

drive is the disk to open
caption is either "source" or "destination" (for log file)
log is the log file
p is the command line
ask_for_partitions = true => do dialog to get partition index
px is the partition index (if supplied on command line)
return base -- partition base address (LBA)
return n -- number of sectors in partition
return disk -- disk control pointer to access drive
*****************************************************************/
int setup_disk (char* drive, char *caption, FILE *log, char **p, int ask_for_partitions,
		 int px, off_t *base, off_t *n, disk_control_ptr *disk)
{
	int	status;
	static	pte_rec pt[4];

	*disk = open_disk (drive,&status);
	if (status) {
		printf ("%s could not open drive %s, status code %d\n", p[0], drive, status);
		fprintf (log,"%s could not open drive %s, status code %d\n", p[0], drive, status);
		return 1;
	}
	status = get_partition_table(*disk,pt);
	if (status) {
		printf ("Could not read %s partition table on drive %s\n", caption, drive);
		fprintf (log,"Could not read %s partition table on drive %s\n", caption, drive);
		return 1;
	}
	if (ask_for_partitions) { /* ask if not given on command line */
		print_partition_table(stdout, pt, 1, 1);
		printf("Select partition: ");
		scanf("%d", &px);
		printf("\nPartition %d selected.\n", px);
	}

	status = get_partition_offset (pt, px, base, n);
	if (status) {
		printf ("Could not find %s partition %d\n", caption, px);
		return 1;
	}
	printf ("%s partition %d at %llu for %llu\n", caption, px, *base, *n);
	/* log information about disk and partition */
	log_disk (log, caption, *disk);
	print_partition_table(log, pt, 1, 1);
	fprintf (log,"%s partition %d at %llu for %llu\n", caption, px, *base, *n);
	return 0;
}
Пример #8
0
int main(int argc,char *argv[])
{
	FILE *fd;
	char sectbuf[256];
	int sector,read,err;

	if (argc!=4) {
		printf("Usage: writeblock disk_image blockfile sector_no\n");
		printf("\nThis tool will write <blockfile> onto side 2 of a double-sided disk image,\n");
		printf("starting at sector sector_no (zero-based).\n\n");
		printf("Caution:\n");
		printf("\t-the disk should have been previously formatted (17 sectors per track)\n");
		printf("\t-the logical sector number should not exceed the capacity of one side\n");
		exit(1);
	}
	if (open_disk(argv[1])) {
		printf("Cannot open disk image %s, or invalid disk image.\n",argv[1]);
		exit(2);
	}
	fd=fopen(argv[2],"rb");
	if (fd==NULL) {
		printf("Cannot open blockfile %s\n",argv[2]);
		exit(2);
	}
	sector=atoi(argv[3]);
	read=fread(sectbuf,1,256,fd);
	while (read>0) {
		err=write_sector(sectbuf,sector/17,1,sector%17+1);
		if (err) {
			printf("Cannot write sector, error %d\n",err);
			exit(4);
		}
		sector++;
		read=fread(sectbuf,1,256,fd);
	}
	close_disk();
}
Пример #9
0
/********************************************************************
*																	*
*						 Gestion du menu							*
*																	*
********************************************************************/
boolean MenuSelect(int object, int scan, int state, int button)
{
	int index, entree, key;

	if (object < 0)
	{
		/* attend qu'on relache la souris */
		NoClick();

		if (button < 0)
		{
			/* regarde la touche */
			key = scantoascii(scan);
			if (key == 0)
				key = scan & 0xFF00;	/* scan code */
			else
				key = UpperChar(key);

			for (index = 0; index < NbMenus; index++)
				for (entree = 0; entree < MenuShortCuts[index].nb_entrees; entree++)
					if (MenuShortCuts[index].menu[entree].key == key && MenuShortCuts[index].menu[entree].state == state)
					{
						if (ob_isstate(Menu, MenuShortCuts[index].menuid, DISABLED) == 0 && ob_isstate(Menu, MenuShortCuts[index].menu[entree].itemid, DISABLED) == 0)
						{
							object = MenuShortCuts[index].menu[entree].itemid;
							index = NbMenus;
						}
						break;
					}
		}
	}

	if (object < 0)
		return FALSE;	/* kein entsprechender Eintrag gefunden */

	/* Men�punkte 'Fenster wechseln' und 'Fenster schliežen' werden
	   inklusive der dazugeh”rigen Hotkeys automatisch verwaltet */

	switch (object)
	{
						/* menu Zorg */

		case INFORMATIONS:
			presentation();
			break;

						/* menu Etat */

		case INFORMATION:
			informations(Drive);
			break;

		case REPERTOIRE_LOUPE:
			if (ManageVFAT)
				open_directory_vfat();
			else
				open_directory_short();
			break;

		case TEST_STRUCTURE:
			if (ManageVFAT)
				structure_test_vfat(Drive);
			else
				structure_test_short(Drive);
			break;

		case STATISTIQUES:
			statistiques(Drive);
			break;

		case OCCUPATION:
			occupation(Drive);
			break;

		case TRACE_UN_FICHIER:
			trace_file();
			break;

		case QUITTER:
			if (Reset)
			{
				if (my_alert(1, 2, X_ICN_QUESTION, Messages(MENU_1), Messages(BOOT_32)) == 0)
					shutdown(TRUE);
			}
			else
			{
				button = my_alert(2, 3, X_ICN_QUESTION, Messages(MENU_2), Messages(MENU_4));
				if (button == 0 || button == 1 && (int)xbios(0x11) % 2)
					shutdown(FALSE);
			}
			break;

					/* menu Ouvre */

		case UNITE_LOGIQUE:
			open_disk();
			break;

		case OUVRE_DISQUETTE:
			raw_floppy(FALSE);
			break;

		case OUVRE_DISQUE_DUR:
			raw_hard(FALSE);
			break;

		case OUVRE_FICHIER:
			open_file();
			break;

		case OUVRE_FICHIER_FS:
			open_file_other_fs();
			break;

		case OUVRE_FICH_TEXTE:
			voir_fichier();
			break;

		case CREER_FICHIER:
			creer_fichier();
			break;

		case FERMER:
			fermer(Thefrontwin -> win -> handle);
			break;

		case LIRE_BOOT:
			lire_boot();
			break;

		case CHARGER_BOOT:
			charger_boot();
			break;

		case SAUVER_BOOT:
			sauver_boot();
			break;

		case ECRIRE_BOOT:
#ifdef TEST_VERSION
			/* relache la souris */
			NoClick();

			/* on attend avant de redessiner */
			Event_Timer(0, 0, TRUE);

			my_alert(1, FAIL, X_ICN_STOP, Messages(MENU_6), NULL);
#else
			ecrire_boot();
#endif
			break;

					/* menu Edition */

		case SAUVER_SECTEUR:
#ifdef TEST_VERSION
			/* relache la souris */
			NoClick();

			/* on attend avant de redessiner */
			Event_Timer(0, 0, TRUE);

			my_alert(1, FAIL, X_ICN_STOP, Messages(MENU_6), NULL);
#else
			save_secteur(Thefrontwin, MENU_EDITION);
#endif
			break;

		case COPIER_SECTEUR:
			copier_tampon(Thefrontwin);
			break;

		case COLLER_SECTEUR:
			coller_tampon(Thefrontwin);
			break;

		case ECHANGER_TAMPON:
			echanger_tampon(Thefrontwin);
			break;

		case RETOUR_INITIAL:
			load_secteur(Thefrontwin, MENU_EDITION);
			break;

		case OUVRIR_TAMPON:
			ouvrir_tampon();
			break;

		case SAUVER_TAMPON:
			sauver_tampon();
			break;

		case CHARGER_TB_ASCII:
			ascii_tampon();
			break;

		case EFFACER_TAMPON:
			effacer_tampon();
			break;

					/* menu Structure */

		case DEFRAGMENTATION:
#ifdef TEST_VERSION
			/* relache la souris */
			NoClick();

			/* on attend avant de redessiner */
			Event_Timer(0, 0, TRUE);

			my_alert(1, FAIL, X_ICN_STOP, Messages(MENU_6), NULL);
#else
			reconnect(Drive);
#endif
			break;

		case UNIQUE_LIBRE:
#ifdef TEST_VERSION
			/* relache la souris */
			NoClick();

			/* on attend avant de redessiner */
			Event_Timer(0, 0, TRUE);

			my_alert(1, FAIL, X_ICN_STOP, Messages(MENU_6), NULL);
#else
			compresse(Drive);
#endif
			break;

		case RESTO_COMPLETE:
#ifdef TEST_VERSION
			/* relache la souris */
			NoClick();

		/* on attend avant de redessiner */
			Event_Timer(0, 0, TRUE);

			my_alert(1, FAIL, X_ICN_STOP, Messages(MENU_6), NULL);
#else
			restauration_complete(Drive);
#endif
			break;

		case VIDE_CLST_LIBRES:
			nettoie_clusters_libres(Drive);
			break;

		case NETTOIE_REPERTOI:
#ifdef TEST_VERSION
			/* relache la souris */
			NoClick();

			/* on attend avant de redessiner */
			Event_Timer(0, 0, TRUE);

			my_alert(1, FAIL, X_ICN_STOP, Messages(MENU_6), NULL);
#else
			nettoie_repertoire(Drive);
#endif
			break;

					/* menu Deplacement */

		case SECTEUR_SUIVANT:
			next_secteur(Thefrontwin);
			break;

		case SECTEUR_PRECEDEN:
			previous_secteur(Thefrontwin);
			break;

		case BLOC_SUIVANT:
			next_bloc(Thefrontwin);
			break;

		case BLOC_PRECEDENT:
			previous_bloc(Thefrontwin);
			break;

		case MARQUER_POSITION:
			marquer_position(Thefrontwin);
			break;

		case ALLER_MARQUE:
			goto_marque(Thefrontwin);
			break;

		case ALLER_SECTEUR:
			goto_secteur(Thefrontwin);
			break;

		case CHERCHER_CHAINE:
			search_first(Thefrontwin);
			break;

		case CHERCHER_NOUVEAU:
			search_next(Thefrontwin);
			break;

					/* menu Fenˆtres */

		case CHOIX_FONTE:
			choix_fonte(Thefrontwin);
			break;

		case CHOIX_COULEURS:
			couleur(Thefrontwin);
			break;

		case TAILLE_IDEALE:
			taille_ideale(Thefrontwin);
			break;

		case ASCENSEURS:
			ascenseurs(Thefrontwin);
			break;

		case CYCLER_FENETRES:
			cycle_window();
			break;

		case WINDOW_LIST_1:
		case WINDOW_LIST_2:
		case WINDOW_LIST_3:
		case WINDOW_LIST_4:
		case WINDOW_LIST_5:
		case WINDOW_LIST_6:
		case WINDOW_LIST_7:
		case WINDOW_LIST_8:
		case WINDOW_LIST_9:
		case WINDOW_LIST_10:
			{
				windowptr thewin;

				for (thewin = Firstwindow; thewin; thewin = thewin -> next)
					if (thewin -> menu_entry == object - WINDOW_LIST_1)
						make_frontwin(thewin);
			}
			break;

						/* menu Options */

		case CONFIG_GENERALE:
			config_generale();
			break;

		case CONFIG_DSK:
			config_disques();
			break;

		case RACCOURCIS_CLAVI:
			raccourcis_clavier();
			break;

		case DONNEES_ZORG:
			from_zorg_inf(TRUE);
			break;

		case DONNEES_SYSTEME:
			from_zorg_inf(FALSE);
			break;

		case INVALIDE_CACHE:
			if (Kbshift(FAIL) & 4)
			{
				int i;

				for (i=0; i<MAX_DEVICES; i++)
					change_disque(i, FALSE);
			}
			else
				change_disque(Drive, TRUE);
			break;

		case UPDATE_SYSTEME:
			if (Kbshift(FAIL) & 4)
			{
				int i;

				for (i=0; i<MAX_DEVICES; i++)
					update_systeme(i);
			}
			else
				update_systeme(Drive);
			break;

		case VISU_TEXTE:
			really_voir_fichier(Thefrontwin -> fonction.fichier.nom);
			break;

		case VISU_ASCII:
			secteur_ascii(Thefrontwin);
			break;

		case VISU_HEXA:
			secteur_hexa(Thefrontwin);
			break;

		case AFFICHE_DECIMAL:
			affichage_decimal(Thefrontwin);
			break;

		case FICHIER_ASSOCIE:
			secteur_file(Thefrontwin);
			break;

		case CURSEUR_VISIBLE:
			curseur_on(Thefrontwin);
			break;

		case CLIPBOARD_GEM:
			clipboard_gem(Thefrontwin);
			break;

						/* menu Aide */

		case TABLE_ASCII:
			AsciiChar = m_ascii_box(AsciiChar, FALSE);
			break;

		case AIDE:
			aide();
			break;

		case EXECUTER_PROG:
			lance_prg();
			break;

		case RESET:
			if (Reset)
			{
				Reset = FALSE;
				menu_icheck(Menu, RESET, 0);
			}
			else
			{
				int button;

				button = my_alert(2, 3, X_ICN_QUESTION, Messages(MENU_3), Messages(MENU_5));
				if (button == 1)
					shutdown(TRUE);
				else
					if (button == 0)
						reset();
			}
			break;
	}

	return TRUE;
} /* MenuSelect */
Пример #10
0
ssize_t
efi_va_generate_file_device_path_from_esp(uint8_t *buf, ssize_t size,
				       const char *devpath, int partition,
				       const char *relpath,
				       uint32_t options, va_list ap)
{
	int rc;
	ssize_t ret = -1, off=0, sz;
	struct disk_info info = { 0, };
	int fd = -1;
	int saved_errno;

	fd = open(devpath, O_RDONLY);
	if (fd < 0)
		goto err;

	rc = eb_disk_info_from_fd(fd, &info);
	if (rc < 0 && errno != ENOSYS)
		goto err;

	if (partition > 0)
		info.part = partition;

	if (options & EFIBOOT_ABBREV_EDD10) {
		va_list aq;
		va_copy(aq, ap);

		info.edd10_devicenum = va_arg(aq, uint32_t);

		va_end(aq);
	}

	if ((options & EFIBOOT_ABBREV_EDD10)
			&& (!(options & EFIBOOT_ABBREV_FILE)
			    && !(options & EFIBOOT_ABBREV_HD))) {
		sz = efidp_make_edd10(buf, size, info.edd10_devicenum);
		if (sz < 0)
			return -1;
		off = sz;
	} else if (!(options & EFIBOOT_ABBREV_FILE)
		   && !(options & EFIBOOT_ABBREV_HD)) {
		/*
		 * We're probably on a modern kernel, so just parse the
		 * symlink from /sys/dev/block/$major:$minor and get it
		 * from there.
		 */
		sz = make_blockdev_path(buf, size, fd, &info);
		if (sz < 0)
			return -1;
		off += sz;
	}

	if (!(options & EFIBOOT_ABBREV_FILE)) {
		int disk_fd;
		int saved_errno;
		int rc;

		rc = set_disk_and_part_name(&info);
		if (rc < 0)
			goto err;

		disk_fd = open_disk(&info,
		    (options& EFIBOOT_OPTIONS_WRITE_SIGNATURE)?O_RDWR:O_RDONLY);
		if (disk_fd < 0)
			goto err;

		sz = make_hd_dn(buf, size, off, disk_fd, info.part, options);
		saved_errno = errno;
		close(disk_fd);
		errno = saved_errno;
		if (sz < 0)
			goto err;
		off += sz;
	}

	char *filepath = strdupa(relpath);
	tilt_slashes(filepath);
	sz = efidp_make_file(buf+off, size?size-off:0, filepath);
	if (sz < 0)
		goto err;
	off += sz;

	sz = efidp_make_end_entire(buf+off, size?size-off:0);
	if (sz < 0)
		goto err;
	off += sz;
	ret = off;
err:
	saved_errno = errno;
	if (info.disk_name) {
		free(info.disk_name);
		info.disk_name = NULL;
	}

	if (info.part_name) {
		free(info.part_name);
		info.part_name = NULL;
	}

	if (fd >= 0)
		close(fd);
	errno = saved_errno;
	return ret;
}
Пример #11
0
int main (int np, char **p)
{
	char		drive[NAME_LENGTH] = "/dev/hda";
	int		lname_given = 0,
			status,
			i,
			all,
			help = 0;
	static disk_control_block *dd;
	pte_rec		pt[4];
	FILE		*log;
	char		comment [NAME_LENGTH] = "",
			log_name[NAME_LENGTH],
			access[2] = "a";
	time_t		from;

	/*_stklen = 2*_stklen;*/
	time(&from);
	printf ("\n%s compiled at %s on %s\n", p[0],
		__TIME__,__DATE__);

/* get command line */
	if (np < 6) help = 1;
	else strncpy(drive, p[4], NAME_LENGTH - 1);
	for (i = 6; i < np; i++){
		if (strcmp(p[i],"-all") == 0) all = 1;
		else if (strcmp (p[i],"-new_log")== 0) access[0] = 'w';
		else if (strcmp (p[i],"-log_name")== 0) {
			if(++i >= np) {
				printf("%s: -log_name option requires a logfile name\n", p[0]);
				help = 1;
			} else {
				sprintf (log_name,"%s",p[i]);
				lname_given = 1;
			}
		} else if (strcmp(p[i],"-comment") == 0) {
			i++;
			if (i < np) strncpy (comment, p[i], NAME_LENGTH - 1);
			else help = 1;
		} else {
			printf("Invalid parameter: %s\n", p[i]);
			help = 1;
		}
	}
	if (help) {
		print_help(p[0]);
		return 0;
	}
	status = 1;
	printf ("Drive %s\n",drive);
/* open log file */
	if (lname_given == 0) sprintf (log_name,"pt-%s-log.txt", filename(&p[4][5]));

	log = log_open (log_name,access,comment,SCCS_ID,np,p);

/* open and log disk */
	dd = open_disk (drive,&status);
	if (status) {
		printf ("%s could not access drive %s, status code %d\n",p[0],
			drive,status); 
		fprintf (log,"%s could not access drive %s, status code %d\n",p[0],
			drive,status);
		return 1;
	}
	fprintf (log,"Drive label: %s\n",p[5]);
	log_disk (log,"Partition table",dd);

/* get and print partition table */
	status = get_partition_table(dd,pt);
	if (status == 0) print_partition_table(stdout, pt, 1, all);
	else if (status == -1) printf ("No partition table signature\n");
	else printf ("Error reading partition table, code %d\n",status);

	if (status == 0) print_partition_table(log, pt, 1, all);
	if (status)fprintf (log,"Error reading partition table, code %d\n",status);
	log_close (log,from);
	return 0;
}
Пример #12
0
main (int np, char **p)
{
	int		help = 0,/* request command line help */
			layout_only = 0; /* print disk layout only */
	int		status,/* disk open or I/O status return */
			i; /* loop index */

	/* variables to handle fill characters */
	unsigned char	src_fill = 'S',
			dst_fill = 'D';
	int		is_fill,
			id_fill;

	/* source disk parameters */
	static disk_control_ptr src_dcb; /* drive information */
	char		src_drive[NAME_LENGTH] = "/dev/hda"; /* source drive, default is Master on Primary IDE */
	pte_rec		src_pt[4]; /* partition table for source disk */
	int		src_n_regions = 0; /* number of chunks on the source */
	layout_ptr	src_layout = (layout_ptr) malloc(MAX_PARTITIONS*sizeof(layout_rec)); /* chunks */
   
	/* destination disk parameters */
	static disk_control_ptr dst_dcb;
	char		dst_drive[NAME_LENGTH] = "/dev/hdb";
	pte_rec		dst_pt[4];
	int		dst_n_regions = 0;
	layout_ptr	dst_layout = (layout_ptr) malloc(MAX_PARTITIONS*sizeof(layout_rec));

	FILE		*log; /* log file */
	char		comment [NAME_LENGTH] = "",
			log_name[NAME_LENGTH] = "cmpalog.txt",
			access[2] = "a"; /* tester (user) comment for log file */
	static time_t	from; /* time program started running */
	int		assign_regions = 0; /* flag: user wants to assign corresponding chunks */

/*	_stklen = 2*_stklen; */

	printf ("\n%s Version 3.1 compiled at %s on %s\n", p[0],
		__TIME__,__DATE__);
/******************************************************************************
Get command line
******************************************************************************/
	if (np < 8) {
		printf ("%s: Missing parameters\n",p[0]);
		help = 1;
	} else {
		sscanf (p[5],"%2x",&is_fill);
		src_fill = is_fill;
		sscanf (p[7],"%2x",&id_fill);
		dst_fill = id_fill;
		strncpy(src_drive, p[4], NAME_LENGTH - 1);
		strncpy(dst_drive, p[6], NAME_LENGTH - 1);
		printf ("Src drive %s dst drive %s\n",src_drive,dst_drive);
		printf ("Src fill 0x%02X dst fill 0x%02X\n",src_fill,dst_fill);
	}

	for (i = 8; i < np; i++) {
		if (strcmp(p[i], "-assign") == 0) assign_regions = 1;
		else if (strcmp (p[i], "-h") == 0) help = 1;
		else if (strcmp (p[i], "-layout") == 0) layout_only = 1;
		else if (strcmp (p[i], "-new_log")== 0) access[0] = 'w';
		else if (strcmp (p[i], "-log_name") == 0) {
			if(++i >= np) {
				printf("%s: -log_name option requires a logfile name\n", p[0]);
				help = 1;
			} else strncpy(log_name, p[i], NAME_LENGTH - 1);
		} else if (strcmp (p[i],"-comment")== 0) {
			i++;
			if (i >= np) {
				printf ("%s: comment required with -comment\n",	p[0]);
				print_help(p[0]);
				return 1;
			}
			strncpy (comment,p[i], NAME_LENGTH - 1);
		} else {
			printf("Invalid parameter: %s\n", p[i]);
			help = 1;
		}
	}
	if (help) {
		print_help(p[0]);
		return 0;
	}

/******************************************************************************
Start log file, open source disk and get partition table
******************************************************************************/
	log = log_open (log_name, access, comment, SCCS_ID, np, p);
	fprintf (log, "Src drive %s dst drive %s\n",src_drive,dst_drive);
	fprintf (log, "Src fill 0x%02X dst fill 0x%02X\n",src_fill,dst_fill);

	src_dcb = open_disk (src_drive,&status);
	if (status) {
		printf ("Could not access source drive %s status code %d\n",src_drive,status);
		return 1;
	}
	log_disk (log,"Source Disk",src_dcb);
	status = get_partition_table(src_dcb,src_pt);

	if (status == 0) {
		fprintf (log,"Source disk partition table\n");
		print_partition_table(log,src_pt,0,1);
		print_partition_table(stdout,src_pt,1,1);
	} else {
		fprintf (log,"Error reading src partition table code %d\n", status);
		printf ("No partition table signature or error reading partition table (code %d)\n",status);
		return 1;
	}
	time(&from);

	src_n_regions = layout_disk (src_pt,src_layout,src_dcb);
	printf ("%d regions\n",src_n_regions);
	fprintf (log,"Source disk layout: ");
	fprintf (log," %05llu/%03llu/%02llu ",
		src_dcb->disk_max.cylinder,
		src_dcb->disk_max.head,
		src_dcb->disk_max.sector);
	fprintf (log,"%llu total sectors on disk\n",src_dcb->n_sectors);
	fprintf (log,"%4s%10s%10s%10s%23s\n","","Start LBA","End LBA","Length",
		"Size: MB   (binary)");
	for (i = 0; i < src_n_regions; i++){
		printf ("%2d %c %9llu %9llu %9llu %8.2fMB %8.2fBMB\n",
			i,
			src_layout[i].chunk_class,
			src_layout[i].lba_start,
			src_layout[i].lba_start + src_layout[i].n_sectors - 1,
			src_layout[i].n_sectors,
			BYTES_PER_SECTOR*(float)src_layout[i].n_sectors/1000000.0,
			BYTES_PER_SECTOR*(float)src_layout[i].n_sectors/1048576.0);
		fprintf (log,"%2d %c %9llu %9llu %9llu %8.2fMB %8.2fBMB\n",
			i,
			src_layout[i].chunk_class,
			src_layout[i].lba_start,
			src_layout[i].lba_start + src_layout[i].n_sectors - 1,
			src_layout[i].n_sectors,
			BYTES_PER_SECTOR*(float)src_layout[i].n_sectors/1000000.0,
			BYTES_PER_SECTOR*(float)src_layout[i].n_sectors/1048576.0);
	}

/******************************************************************************
Open destination disk, get partition table
******************************************************************************/
	dst_dcb = open_disk (dst_drive,&status);
	if (status) {
		printf ("Could not access destination drive %s status code %d\n",dst_drive,status);
		return 1;
	}
	log_disk (log,"Destination Disk",dst_dcb);
	status = get_partition_table(dst_dcb,dst_pt);
	if (status == 0){
		fprintf (log,"Destination disk partition table\n");
		print_partition_table(log,dst_pt,0,1);
		print_partition_table(stdout,dst_pt,1,1);
	} else {
		fprintf (log,"Error reading src partition table code %d\n", status);
		printf ("No partition table signature or error reading partition table (code %d)\n",status);
		return 1;
	}

	dst_n_regions = layout_disk (dst_pt,dst_layout,dst_dcb);
	printf ("%d regions on %s\n",dst_n_regions,dst_drive);
	fprintf (log,"Destination disk layout: ");
	fprintf (log," %05llu/%03llu/%02llu ",
		dst_dcb->disk_max.cylinder,
		dst_dcb->disk_max.head,
		dst_dcb->disk_max.sector);
	fprintf (log,"%llu total sectors on disk\n",dst_dcb->n_sectors);
	fprintf (log,"%4s%10s%10s%10s%23s\n","","Start LBA","End LBA","Length",
		"Size: MB   (binary)");
	for (i = 0; i < dst_n_regions; i++){
		printf ("%2d %c %9llu %9llu %9llu %8.2fMB %8.2fBMB\n",
			i,
			dst_layout[i].chunk_class,
			dst_layout[i].lba_start,
			dst_layout[i].lba_start + dst_layout[i].n_sectors - 1,
			dst_layout[i].n_sectors,
			BYTES_PER_SECTOR * (double)dst_layout[i].n_sectors/1000000.0,
			BYTES_PER_SECTOR * (double)dst_layout[i].n_sectors/1048576.0);
		fprintf (log,"%2d %c %9llu %9llu %9llu %8.2fMB %8.2fBMB\n",
			i,
			dst_layout[i].chunk_class,
			dst_layout[i].lba_start,
			dst_layout[i].lba_start + dst_layout[i].n_sectors - 1,
			dst_layout[i].n_sectors,
			BYTES_PER_SECTOR * (double)dst_layout[i].n_sectors/1000000.0,
			BYTES_PER_SECTOR * (double)dst_layout[i].n_sectors/1048576.0);
	}
/******************************************************************************
Do the compare
******************************************************************************/
	if (layout_only == 0)
		status = do_compare(src_dcb,src_n_regions,src_layout,dst_dcb,dst_n_regions,
					dst_layout,src_fill,dst_fill,log,assign_regions,from);
/******************************************************************************
Close the log file
******************************************************************************/
	log_close(log,from);
	return 0;
}
Пример #13
0
main (int np, char **p) {
	char		src_drive[NAME_LENGTH],
			dst_drive[NAME_LENGTH]; /* drive devices */
	int		help = 0,
			status,
			i;
	static disk_control_ptr src_disk,
			dst_disk; /* disk information */
	off_t		lba = 0, /* index for looping through disk sectors */
			common, /* number of sectors common to source and dst */
			diffs = 0, /* number of sectors that do not match */
			nz, /* number of zero bytes in current sector */
			nfill,/* number of filled bytes in current sector */
			src_ns,dst_ns, /* number of sectors on src and dst */
		/* counts: sectors that ... */
			byte_diffs = 0,
			match = 0,
			zero = 0,
			sfill = 0,
			dfill = 0,
			ofill = 0,
			other = 0;
	int		big_src = 0,
			big_dst = 0,
			is_diff,
			src_status,
			dst_status; /* read status codes (should be zero) */
	static unsigned char *src_buff,
			*dst_buff; /* current src and dst sector data */
	static time_t	from; /* program start time */
	FILE		*log;  /* the log file */
	int		is_debug = 0;
	unsigned char	other_fill_char,
			src_fill_char,
			dst_fill_char; /* the fill characters */
	int		fill_char,
			other_fill_seen = 0;
	off_t		n_src_err = 0,
			n_dst_err = 0; /* count of number of read errs */
	char		comment[NAME_LENGTH] = "",
			access[2] = "a"; /* the user comment */
	char		log_name[NAME_LENGTH] = "cmplog.txt";
								/* sectors that ... */
	range_ptr d_r = create_range_list(), /* ... differ (do not match) */
			zf_r = create_range_list(), /* ... zeros filled */
			sf_r = create_range_list(),/* ... source filled */
			df_r = create_range_list(), /* ... dst filled */
			of_r = create_range_list(), /* ... filled with something else */
			o_r = create_range_list(); /* ... are not filled */

	time(&from);
	src_disk = dst_disk = NULL;

/*****************************************************************
Get the command line
*****************************************************************/
	if (np < 8) {
		print_help(p[0]); /* not enough parameters */
		return 1;
	}

	strncpy(src_drive, p[4], NAME_LENGTH - 1);
	strncpy(dst_drive, p[6], NAME_LENGTH - 1);

	printf ("Src drive %s dst drive %s\n",src_drive,dst_drive);

	sscanf (p[5],"%2x",&fill_char);
	src_fill_char = fill_char;
	sscanf (p[7],"%2x",&fill_char);
	dst_fill_char = fill_char;

	printf ("Src fill 0x%02X dst fill 0x%02X\n",src_fill_char,dst_fill_char);

	for (i = 8; i < np; i++) { /* optional parameters */
		if (strcmp (p[i],"-h") == 0) help = 1;
		else if (strcmp (p[i],"-debug")== 0) is_debug = 1;
		else if (strcmp (p[i],"-new_log")== 0) access[0] = 'w';
		else if (strcmp (p[i], "-log_name") == 0) {
			if(++i >= np) {
				printf("%s: -log_name option requires a logfile name\n", p[0]);
				help = 1;
			} else strncpy(log_name, p[i], NAME_LENGTH - 1);
		} else if (strcmp (p[i],"-comment")== 0) {
			if (++i >= np) {
				printf ("%s: comment required with -comment\n",	p[0]);
				help = 1;
			} else strncpy (comment, p[i], NAME_LENGTH - 1);
		} else {
			printf("Invalid parameter: %s\n", p[i]);
			help = 1;
		}
	}
	if (help) {
		print_help(p[0]);
		return 0;
	}
/*****************************************************************
Start log file
*****************************************************************/
	log = log_open(log_name,access,comment,SCCS_ID,np,p);
	src_disk = open_disk (src_drive,&status);
	if (status) {
		printf ("%s could not access src drive %s status code %d\n",
			p[0],src_drive,status);
		fprintf (log,"%s could not access src drive %s status code %d\n",
			p[0],src_drive,status);
		return 1;
	}
	log_disk(log,"Source",src_disk);
	dst_disk = open_disk (dst_drive,&status);
	if (status){
		printf ("%s could not access dst drive %s status code %d\n",
			p[0],dst_drive,status);
		fprintf (log,"%s could not access dst drive %s status code %d\n",
			p[0],dst_drive,status);
		return 1;
	}
	log_disk(log,"Destination",dst_disk);
	src_ns = n_sectors(src_disk);
	dst_ns = n_sectors(dst_disk);

	if (src_ns != dst_ns){
		if ( src_ns < dst_ns){
			common = src_ns;
			big_dst = 1;
		}
		else {
			common = dst_ns;
			big_src = 1;
		}
	}
	else common = src_ns; 
/*****************************************************************
Main scan loop: read corresponding sectors and compare
*****************************************************************/
	for (lba = 0; lba < common; is_debug?(lba+=100):lba++){
		is_diff = 0;
		feedback (from,0,lba,big_dst?dst_ns:common);
		src_status = read_lba(src_disk,lba,&src_buff);
		dst_status = read_lba(dst_disk,lba,&dst_buff);
		if (src_status) { /* if bad sectors, keep list of first 10 */
			n_src_err++;
			if (n_src_err < 11) {
				fprintf (log,"src read error 0x%02X on track starting at lba %llu\n",
					src_status,lba);
				printf ("src read error 0x%02X at lba %llu\n",src_status,lba);
			} else if (n_src_err == 11) {
				fprintf (log,"... more src read errors\n");
				printf ("... more src read errors\n");
			}
			continue;
		}
		if (dst_status) { /* if bad sectors, keep list of first 10 */
			n_dst_err++;
			if (n_dst_err < 11) {
				fprintf (log,"dst read error 0x%02X on track starting at lba %llu\n",
					dst_status,lba);
				printf ("dst read error 0x%02X at lba %llu\n",dst_status,lba);
			} else if (n_dst_err == 11) {
				fprintf (log,"... more dst read errors\n");
				printf ("... more dst read errors\n");
			}
			continue;
		}
		for (i = 0; i < BYTES_PER_SECTOR; i++){  /* count bytes different */
			if (src_buff[i] != dst_buff[i]){
				is_diff = 1;
				byte_diffs++;
			}
		}
		if (is_diff){/* sectors do not match */
			diffs++;
			add_to_range (d_r,lba);
		}
		else {
			match++;
		}
	}
	/* log results for corresponding sectors */
	fprintf (log,"Sectors compared: %8llu\n",common);
	fprintf (log,"Sectors match:    %8llu\n",match);
	fprintf (log,"Sectors differ:   %8llu\n",diffs);
	if (n_src_err + n_dst_err){ /* note any I/O errors */
		fprintf (log, "Sectors skipped:  %8llu (due to %llu src & %llu dst I/O errors)\n",
			n_src_err+n_dst_err,n_src_err,n_dst_err);
	}
	fprintf (log,"Bytes differ:     %8llu\n",byte_diffs);
	print_range_list(log,"Diffs range",d_r);
	if (big_src){
		fprintf (log,"Source (%llu) has %llu more sectors than destination (%llu)\n",
			src_ns,src_ns - dst_ns,
			dst_ns);
	}
	else if (big_dst){ /* examine remainder of a larger destination */
		fprintf (log,"Source (%llu) has %llu fewer sectors than destination (%llu)\n",
			src_ns,dst_ns - src_ns,
			dst_ns);
		zero = 0;
		ofill = sfill = dfill = 0;
		other = 0;
		printf ("Destination larger than source; scanning %llu sectors\n",
			dst_ns-common);
		for (lba = common; lba < dst_ns; is_debug?(lba+=100):lba++){
			feedback (from,0,lba,dst_ns);
			dst_status = read_lba(dst_disk,lba,&dst_buff);
			if (dst_status){
				n_dst_err++;
				if (n_dst_err < 11){
					fprintf (log,"dst read error 0x%02X on track starting at lba %llu\n",
						dst_status,lba);
					printf ("dst read error 0x%02X at lba %llu\n",dst_status,lba);
				}
				if (n_dst_err == 11) {
					fprintf (log,"... more dst read errors\n");
					printf ("... more dst read errors\n");
				}
				continue;
			}
			nz = 0;
			nfill = 0;
			for (i = 0; i < BYTES_PER_SECTOR; i++) {
				if (dst_buff[i] == 0) nz++;
				else if (dst_buff[i] == dst_buff[BUFF_OFF]) nfill++;
			}
			if (nz == BYTES_PER_SECTOR) {zero++; add_to_range(zf_r,lba);}
			else if (nfill > 480){  /* filled sector: figure out src, dst or other */
					if (dst_buff[BUFF_OFF] == src_fill_char){
						sfill++;
						add_to_range(sf_r,lba);
					}
					else if (dst_buff[BUFF_OFF] == dst_fill_char){
						dfill++;
						add_to_range(df_r,lba);
					}
					else {
						ofill++;
						add_to_range(of_r,lba);
						other_fill_seen = 1;
						other_fill_char = dst_buff[BUFF_OFF];
					}
			} else {
				other++;
				add_to_range (o_r,lba);
			}
		}
		/* log results of scan of extra dst sectors */
		fprintf (log,"Zero fill:          %8llu\n",zero);
		fprintf (log,"Src Byte fill (%02X): %8llu\n",src_fill_char,sfill);
		if (src_fill_char == dst_fill_char)
			fprintf (log,"Dst Fill Byte same as Src Fill Byte\n");
		else fprintf (log,"Dst Byte fill (%02X): %8llu\n",dst_fill_char,dfill);
		if (other_fill_seen)
				fprintf (log,"Other fill (%02X):    %8llu\n",other_fill_char,ofill);
		else fprintf (log,"Other fill:         %8llu\n",ofill);
		fprintf (log,"Other no fill:      %8llu\n",other);
		print_range_list (log,"Zero fill range: ",zf_r);
		print_range_list (log,"Src fill range: ",sf_r);
		print_range_list (log,"Dst fill range: ",df_r);
		print_range_list (log,"Other fill range: ",of_r);
		print_range_list (log,"Other not filled range: ",o_r);
	}
	fprintf (log,"%llu source read errors, %llu destination read errors\n",
		n_src_err,n_dst_err);

	log_close(log,from);
	return 0;
}
Пример #14
0
int
auto_solaris_part(struct dk_label *label)
{

	int		status, i, fd;
	struct mboot	mboot;
	struct ipart	ip;
	char		*bootptr;
	char		pbuf[MAXPATHLEN];


	(void) get_pname(&pbuf[0]);
	if ((fd = open_disk(pbuf, O_RDONLY)) < 0) {
		err_print("Error: can't open selected disk '%s'.\n", pbuf);
		return (-1);
	}

	status = read(fd, (caddr_t)&mboot, sizeof (struct mboot));

	if (status != sizeof (struct mboot)) {
		err_print("Bad read of fdisk partition.\n");
		return (-1);
	}

	for (i = 0; i < FD_NUMPART; i++) {
		int	ipc;

		ipc = i * sizeof (struct ipart);

		/* Handling the alignment problem of struct ipart */
		bootptr = &mboot.parts[ipc];
		(void) fill_ipart(bootptr, &ip);

		/*
		 * if the disk has an EFI label, the nhead and nsect fields
		 * the label may be zero.  This protects us from FPE's, and
		 * format still seems to work happily
		 */
		if (ip.systid == SUNIXOS ||
		    ip.systid == SUNIXOS2 ||
		    ip.systid == EFI_PMBR) {
			if ((label->dkl_nhead != 0) &&
			    (label->dkl_nsect != 0)) {
				label->dkl_pcyl = lel(ip.numsect) /
				    (label->dkl_nhead * label->dkl_nsect);
				label->dkl_ncyl = label->dkl_pcyl -
				    label->dkl_acyl;
			}
#ifdef DEBUG
			else {
				err_print("Critical label fields aren't "
					"non-zero:\n"
					"\tlabel->dkl_nhead = %d; "
					"label->dkl_nsect = "
					"%d\n", label->dkl_nhead,
					label->dkl_nsect);
			}
#endif /* DEBUG */

		solaris_offset = lel(ip.relsect);
		break;
		}
	}

	(void) close(fd);

	return (0);
}
Пример #15
0
static int do_delta_action(int action,
			   struct task *task,
			   struct sanlk_lockspace *ls,
			   int max_hosts,
			   char *our_host_name,
			   struct leader_record *leader_ret)
{
	struct leader_record leader;
	struct sync_disk sd;
	struct space space;
	char bitmap[HOSTID_BITMAP_SIZE];
	int read_result, rv;

	memset(bitmap, 0, sizeof(bitmap));

	/* for log_space in delta functions */
	memset(&space, 0, sizeof(space));

	if (!ls->host_id_disk.path[0])
		return -ENODEV;

	memset(&sd, 0, sizeof(struct sync_disk));
	memcpy(&sd, &ls->host_id_disk, sizeof(struct sanlk_disk));
	sd.fd = -1;

	rv = open_disk(&sd);
	if (rv < 0)
		return -ENODEV;

	switch (action) {
	case ACT_DIRECT_INIT:
		rv = delta_lease_init(task, &sd, ls->name, max_hosts);
		break;

	case ACT_ACQUIRE_ID:
		rv = delta_lease_acquire(task, &space, &sd,
					 ls->name,
					 our_host_name,
					 ls->host_id,
					 &leader);
		break;
	case ACT_RENEW_ID:
		rv = delta_lease_leader_read(task, &sd,
					     ls->name,
					     ls->host_id,
					     &leader,
					     "direct_renew");
		if (rv < 0)
			return rv;
		rv = delta_lease_renew(task, &space, &sd,
				       ls->name,
				       bitmap,
				       -1,
				       &read_result,
				       &leader,
				       &leader);
		break;
	case ACT_RELEASE_ID:
		rv = delta_lease_leader_read(task, &sd,
					     ls->name,
					     ls->host_id,
					     &leader,
					     "direct_release");
		if (rv < 0)
			return rv;
		rv = delta_lease_release(task, &space, &sd,
					 ls->name,
					 &leader,
					 &leader);
		break;
	case ACT_READ_ID:
	case ACT_READ_LEADER:
		rv = delta_lease_leader_read(task, &sd,
					     ls->name,
					     ls->host_id,
					     &leader,
					     "direct_read");
		break;
	}

	close_disks(&sd, 1);

	if (rv == SANLK_OK)
		rv = 0;

	if (leader_ret)
		memcpy(leader_ret, &leader, sizeof(struct leader_record));

	return rv;
}
Пример #16
0
int direct_dump(struct task *task, char *dump_path, int force_mode)
{
	char *data, *bitmap;
	char *colon, *off_str;
	struct leader_record *lr;
	struct request_record *rr;
	struct sync_disk sd;
	char sname[NAME_ID_SIZE+1];
	char rname[NAME_ID_SIZE+1];
	uint64_t sector_nr;
	int sector_count, datalen, align_size;
	int i, rv, b;

	memset(&sd, 0, sizeof(struct sync_disk));

	colon = strstr(dump_path, ":");
	if (colon) {
		off_str = colon + 1;
		*colon = '\0';
		sd.offset = atoll(off_str);
	}

	strncpy(sd.path, dump_path, SANLK_PATH_LEN);
	sd.fd = -1;

	rv = open_disk(&sd);
	if (rv < 0)
		return -ENODEV;

	rv = direct_align(&sd);
	if (rv < 0)
		goto out_close;

	align_size = rv;
	datalen = align_size;
	sector_count = align_size / sd.sector_size;

	data = malloc(datalen);
	if (!data) {
		rv = -ENOMEM;
		goto out_close;
	}

	printf("%8s %36s %48s %10s %4s %4s %s",
	       "offset",
	       "lockspace",
	       "resource",
	       "timestamp",
	       "own",
	       "gen",
	       "lver");

	if (force_mode)
		printf("/req/mode");

	printf("\n");

	sector_nr = 0;

	while (1) {
		memset(sname, 0, sizeof(rname));
		memset(rname, 0, sizeof(rname));
		memset(data, 0, sd.sector_size);

		rv = read_sectors(&sd, sector_nr, sector_count, data, datalen,
				  task, "dump");

		lr = (struct leader_record *)data;

		if (lr->magic == DELTA_DISK_MAGIC) {
			for (i = 0; i < sector_count; i++) {
				lr = (struct leader_record *)(data + (i * sd.sector_size));

				if (!lr->magic)
					continue;

				/* has never been acquired, don't print */
				if (!lr->owner_id && !lr->owner_generation)
					continue;

				strncpy(sname, lr->space_name, NAME_ID_SIZE);
				strncpy(rname, lr->resource_name, NAME_ID_SIZE);

				printf("%08llu %36s %48s %010llu %04llu %04llu",
					(unsigned long long)((sector_nr + i) * sd.sector_size),
					sname, rname,
					(unsigned long long)lr->timestamp,
					(unsigned long long)lr->owner_id,
					(unsigned long long)lr->owner_generation);

				if (force_mode) {
					bitmap = (char *)lr + LEADER_RECORD_MAX;
					for (b = 0; b < DEFAULT_MAX_HOSTS; b++) {
						if (test_id_bit(b+1, bitmap))
							printf(" %d", b+1);
					}
				}
				printf("\n");
			}
		} else if (lr->magic == PAXOS_DISK_MAGIC) {
			strncpy(sname, lr->space_name, NAME_ID_SIZE);
			strncpy(rname, lr->resource_name, NAME_ID_SIZE);

			printf("%08llu %36s %48s %010llu %04llu %04llu %llu",
			       (unsigned long long)(sector_nr * sd.sector_size),
			       sname, rname,
			       (unsigned long long)lr->timestamp,
			       (unsigned long long)lr->owner_id,
			       (unsigned long long)lr->owner_generation,
			       (unsigned long long)lr->lver);

			if (force_mode) {
				rr = (struct request_record *)(data + sd.sector_size);
				printf("/%llu/%u",
				       (unsigned long long)rr->lver, rr->force_mode);
			}
			printf("\n");

			for (i = 0; i < lr->num_hosts; i++) {
				char *pd = data + ((2 + i) * sd.sector_size);
				struct mode_block *mb = (struct mode_block *)(pd + MBLOCK_OFFSET);

				if (!(mb->flags & MBLOCK_SHARED))
					continue;

				printf("                                                                                                          ");
				printf("%04u %04llu SH\n", i+1, (unsigned long long)mb->generation);
			}
		} else {
			break;
		}

		sector_nr += sector_count;
	}

	rv = 0;
	free(data);
 out_close:
	close_disks(&sd, 1);
	return rv;
}
Пример #17
0
uint8_t* shoebill_extract_kernel(const char *disk_path, const char *kernel_path, char *error_str, uint32_t *len)
{
    uint8_t *pool_data, *kernel_data = NULL;
    disk_t *disk;
    svfs_t *svfs_mount_obj;
    ufs_t *ufs_mount_obj;
    int32_t apm_part_num;
    
    strcpy(error_str, "");
    
    disk = open_disk(disk_path, error_str);
    if (!disk)
        goto done;
    
    apm_part_num = find_root_partition_number(disk, 0);
    if (apm_part_num == -1) {
        sprintf(error_str, "Couldn't find root partition");
        goto done;
    }
    slog("apm_part_num = %u\n", apm_part_num);
    
    svfs_mount_obj = svfs_mount(&disk->partitions[apm_part_num]);
    if (svfs_mount_obj) {
        svfs_inode_t *inode = svfs_traverse_path(svfs_mount_obj, kernel_path);
        if (!inode)
            goto done;
        
        pool_data = svfs_read_inode_data(svfs_mount_obj, inode);
        if (!pool_data)
            goto done;
        
        kernel_data = malloc(inode->size);
        memcpy(kernel_data, pool_data, inode->size);
        *len = inode->size;
        goto done;
    }
    
    ufs_mount_obj = ufs_mount(&disk->partitions[apm_part_num]);
    if (ufs_mount_obj) {
        ufs_inode_t *inode = ufs_traverse_path(ufs_mount_obj, kernel_path);
        if (!inode)
            goto done;
        
        pool_data = ufs_read_inode_data(ufs_mount_obj, inode);
        if (!pool_data)
            goto done;
        
        kernel_data = malloc(inode->size);
        memcpy(kernel_data, pool_data, inode->size);
        *len = inode->size;
        goto done;
    }
    
    sprintf(error_str, "I can read the partition map, but the filesystem doesn't seem to be UFS or SVFS");
    
done:
    if (strlen(error_str))
        slog("error: [%s]\n", error_str);
    if (disk)
        close_disk(disk);
    return kernel_data;
}