Exemplo n.º 1
0
void ubc_break_work(void)
{
    char num_buffer[10];
    volatile short *p1_health = (unsigned short *) 0x8CCF6284;
    //unsigned short *p2_health = (unsigned short *) 0x8CCF7402;
    unsigned char *mem_start = (unsigned char *) 0x8C010000;
    unsigned char *mem_end = (unsigned char *) 0x8CFFFFFF;

    ubc_serial_init(57600);
    ubc_serial_flush();
    ubc_serial_write_str("[UBC] Hit from 0x");
    uint_to_string(spc(), num_buffer);
    ubc_serial_write_str(num_buffer);
    ubc_serial_write_str("\r\n");
    
#if 0

    /* Today we're scanning for the customized VR information */
    if (*p1_health < 500 && *p1_health > 50)
    {
        /* Search for the byte signature: */
        unsigned char prototem_sig[] = {
            0xE3, 0x8E, 0x38, 0xE3, 0x8E, 0x38, 0xE3, 0x8E, 0x38, 0xE3, 0x8E, 0x38, 0xE3, 0x8E, 0x38, 0xE3,
            0x8E, 0x38, 0xE3, 0x8E, 0x38, 0xE3, 0x8E, 0x38, 0xE3, 0x8E, 0x38, 0xE3, 0x8E, 0x38, 0xE3, 0x8E,
        };
        unsigned char *cur_loc;
        unsigned long did_find;

        ubc_serial_write_str("[UBC] Starting prototem search\n\r");

        did_find = 0;
        for (cur_loc = mem_start; cur_loc < mem_end; cur_loc++)
        {
            if (*cur_loc == prototem_sig[0])
            {
                if(!memcmp(cur_loc, prototem_sig, sizeof(prototem_sig)))
                {
                    unsigned char *check_loc;
                    char num_buffer[10];

                    /* MATCH */
                    ubc_serial_write_str("[UBC] Prototem match confirmed @ 0x");
                    uint_to_string((unsigned int) cur_loc, num_buffer);
                    ubc_serial_write_str(num_buffer);
                    ubc_serial_write_str("\r\n");

                    ubc_serial_write_str("[UBC] Writing ");
                    check_loc = cur_loc + (3*5);
                    for (; cur_loc <= check_loc; cur_loc++)
                    {
                        ubc_serial_write_str(".");
                        *cur_loc = 0xFF;
                    }
                    ubc_serial_write_str(" done!\r\n");

                    cur_loc += 1024 - (3*5);

                    did_find = (unsigned long) cur_loc;
                }
            }
        }
        ubc_serial_write_str("[UBC] Prototem search complete.\r\n");

#ifdef POINTER_FIND
        if (did_find)
        {
            ubc_serial_write_str("[UBC] Starting pointer search.\r\n");
            /* Now scan for the pointer in memory */
            for (cur_loc = mem_start; cur_loc < mem_end; cur_loc += 4)
            {
                if (*((unsigned long *) cur_loc) == did_find)
                {
                    char num_buffer[10];

                    ubc_serial_write_str("[UBC] Pointer match confirmed @ 0x");
                    uint_to_string((unsigned int) cur_loc, num_buffer);
                    ubc_serial_write_str(num_buffer);
                    ubc_serial_write_str("\r\n");
                }
            }
            ubc_serial_write_str("[UBC] Pointer search complete.\r\n");
        }
#endif
        
        ubc_serial_write_str("[UBC] All searches complete.\r\n");
        *p1_health = 1000;
    }
#endif
}
Exemplo n.º 2
0
void pbody (char *msg, ...)
{
    var_arg_to_str (msg);
    if (body != NULL)
        fprintf (body, "%s%s", spc(), str);
}
Exemplo n.º 3
0
static void show_sp(C *cp)
{
    Hx::shared_ptr<C> spc(cp->shared_from_this());
    show("from this", spc);
}
Exemplo n.º 4
0
int wc_count(Wc_t *wp, Sfio_t *fd, const char* file)
{
	register char*		type = wp->type;
	register unsigned char*	cp;
	register Sfoff_t	nbytes;
	register Sfoff_t	nchars;
	register Sfoff_t	nwords;
	register Sfoff_t	nlines;
	register Sfoff_t	eline = -1;
	register Sfoff_t	longest = 0;
	register ssize_t	c;
	register unsigned char*	endbuff;
	register int		lasttype = WC_SP;
	unsigned int		lastchar;
	ssize_t			n;
	ssize_t			o;
	unsigned char*		buff;
	wchar_t			x;
	unsigned char		side[32];

	sfset(fd,SF_WRITE,1);
	nlines = nwords = nchars = nbytes = 0;
	wp->longest = 0;
	if (wp->mb < 0 && (wp->mode & (WC_MBYTE|WC_WORDS)))
	{
		cp = buff = endbuff = 0;
		for (;;)
		{
			if (cp >= endbuff || (n = mb2wc(x, cp, endbuff-cp)) < 0)
			{
				if ((o = endbuff-cp) < sizeof(side))
				{
					if (buff)
					{
						if (o)
							memcpy(side, cp, o);
						mbinit();
					}
					else
						o = 0;
					cp = side + o;
					if (!(buff = (unsigned char*)sfreserve(fd, SF_UNBOUND, 0)) || (n = sfvalue(fd)) <= 0)
					{
						if ((nchars - longest) > wp->longest)
							wp->longest = nchars - longest;
						break;
					}
					nbytes += n;
					if ((c = sizeof(side) - o) > n)
						c = n;
					if (c)
						memcpy(cp, buff, c);
					endbuff = buff + n;
					cp = side;
					x = mbchar(cp);
					if ((cp-side) < o)
					{
						cp = buff;
						nchars += (cp-side) - 1;
					}
					else
						cp = buff + (cp-side) - o;
				}
				else
				{
					cp++;
					x = -1;
				}
				if (x == -1 && eline != nlines && !(wp->mode & WC_QUIET))
					eline = invalid(file, nlines);
			}
			else
				cp += n ? n : 1;
			if (x == '\n')
			{
				if ((nchars - longest) > wp->longest)
					wp->longest = nchars - longest;
				longest = nchars + 1;
				nlines++;
				lasttype = 1;
			}
			else if (iswspace(x))
				lasttype = 1;
			else if (lasttype)
			{
				lasttype = 0;
				nwords++;
			}
			nchars++;
		}
		if (!(wp->mode & WC_MBYTE))
			nchars = nbytes;
	}
	else if (!wp->mb && !(wp->mode & WC_LONGEST) || wp->mb > 0 && !(wp->mode & (WC_MBYTE|WC_WORDS|WC_LONGEST)))
	{
		if (!(wp->mode & (WC_MBYTE|WC_WORDS|WC_LONGEST)))
		{
			while ((cp = (unsigned char*)sfreserve(fd, SF_UNBOUND, 0)) && (c = sfvalue(fd)) > 0)
			{
				nchars += c;
				endbuff = cp + c;
				if (*--endbuff == '\n')
					nlines++;
				else
					*endbuff = '\n';
				for (;;)
					if (*cp++ == '\n')
					{
						if (cp > endbuff)
							break;
						nlines++;
					}
			}
		}
		else
		{
			while ((cp = buff = (unsigned char*)sfreserve(fd, SF_UNBOUND, 0)) && (c = sfvalue(fd)) > 0)
			{
				nchars += c;
				/* check to see whether first character terminates word */
				if (c==1)
				{
					if (eol(lasttype))
						nlines++;
					if ((c = type[*cp]) && !lasttype)
						nwords++;
					lasttype = c;
					continue;
				}
				if (!lasttype && type[*cp])
					nwords++;
				lastchar = cp[--c];
				*(endbuff = cp+c) = '\n';
				c = lasttype;
				/* process each buffer */
				for (;;)
				{
					/* process spaces and new-lines */
					do
					{
						if (eol(c))
							for (;;)
							{
								/* check for end of buffer */
								if (cp > endbuff)
									goto beob;
								nlines++;
								if (*cp != '\n')
									break;
								cp++;
							}
					} while (c = type[*cp++]);
					/* skip over word characters */
					while (!(c = type[*cp++]));
					nwords++;
				}
			beob:
				if ((cp -= 2) >= buff)
					c = type[*cp];
				else
					c = lasttype;
				lasttype = type[lastchar];
				/* see if was in word */
				if (!c && !lasttype)
					nwords--;
			}
			if (eol(lasttype))
				nlines++;
			else if (!lasttype)
				nwords++;
		}
	}
	else
	{
		int		lineoff=0;
		int		skip=0;
		int		adjust=0;
		int		state=0;
		int		oldc;
		int		xspace;
		int		wasspace = 1;
		unsigned char*	start;

		lastchar = 0;
		start = (endbuff = side) + 1;
		xspace = iswspace(0xa0) || iswspace(0x85);
		while ((cp = buff = (unsigned char*)sfreserve(fd, SF_UNBOUND, 0)) && (c = sfvalue(fd)) > 0)
		{
			nbytes += c;
			nchars += c;
			start = cp-lineoff;
			/* check to see whether first character terminates word */
			if(c==1)
			{
				if(eol(lasttype))
					nlines++;
				if((c = type[*cp]) && !lasttype)
					nwords++;
				lasttype = c;
				endbuff = start;
				continue;
			}
			lastchar = cp[--c];
			endbuff = cp+c;
			cp[c] = '\n';
			if(mbc(lasttype))
			{
				c = lasttype;
				goto mbyte;
			}
			if(!lasttype && spc(type[*cp]))
				nwords++;
			c = lasttype;
			/* process each buffer */
			for (;;)
			{
				/* process spaces and new-lines */
			spaces:
				do
				{
					if (eol(c))
					{
						/* check for end of buffer */
						if (cp > endbuff)
							goto eob;
						if(wp->mode&WC_LONGEST)
						{
							if((cp-start)-adjust > longest)
								longest = (cp-start)-adjust-1;
							start = cp;
						}
						nlines++;
						nchars -= adjust;
						adjust = 0;
					}
				} while (spc(c = type[*cp++]));
				wasspace=1;
				if(mbc(c))
				{
				mbyte:
					do
					{
						if(c&WC_ERR)
							goto err;
						if(skip && (c&7))
							break;
						if(!skip)
						{
							if(!(c&7))
							{
								skip=1;
								break;
							}
							skip = (c&7);
							adjust += skip;
							state = 0;
							if(skip==2 && (cp[-1]&0xc)==0 && (state=(cp[-1]&0x3)))
								oldc = *cp;
							else if(xspace && cp[-1]==0xc2)
							{
								state = 8;
								oldc = *cp;
							}
						}
						else
						{
							skip--;
							if(state && (state=chkstate(state,oldc)))
							{
								if(state==10)
								{
									if(!wasspace)
										nwords++;
									wasspace = 1;
									state=0;
									goto spaces;
								}
								oldc = *cp;
							}
						}
					} while (mbc(c = type[*cp++]));
					wasspace = 0;
					if(skip)
					{
						if(eol(c) && (cp > endbuff))
							goto eob;
				err:
						skip = 0;
						state = 0;
						if(eline!=nlines && !(wp->mode & WC_QUIET))
							eline = invalid(file, nlines);
						while(mbc(c) && ((c|WC_ERR) || (c&7)==0)) 
							c=type[*cp++];
						if(eol(c) && (cp > endbuff))
						{
							c = WC_MB|WC_ERR;
							goto eob;
						}
						if(mbc(c))
							goto mbyte;
						else if(c&WC_SP)
							goto spaces;
					}
					if(spc(c))
					{
						nwords++;
						continue;
					}
				}
				/* skip over word characters */
				while(!(c = type[*cp++]));
				if(mbc(c))
					goto mbyte;
				nwords++;
			}
		eob:
			lineoff = cp-start;
			if((cp -= 2) >= buff)
				c = type[*cp];
			else
				c = lasttype;
			lasttype = type[lastchar];
			/* see if was in word */
			if(!c && !lasttype)
				nwords--;
		}
		if ((wp->mode&WC_LONGEST) && ((endbuff + 1 - start) - adjust - (lastchar == '\n')) > longest)
			longest = (endbuff + 1 - start) - adjust - (lastchar == '\n');
		wp->longest = longest;
		if (eol(lasttype))
			nlines++;
		else if (!lasttype)
			nwords++;
		if (wp->mode & WC_MBYTE)
			nchars -= adjust;
		else
			nchars = nbytes;
	}
	wp->chars = nchars;
	wp->words = nwords;
	wp->lines = nlines;
	return 0;
}
Exemplo n.º 5
0
void LayoutTest::testLayout(const cv::Mat & src) const {

	// TODOS
	// - line spacing needs smoothing -> graphcut
	// - DBScan is very sensitive to the line spacing
	
	// Workflow:
	// - implement noise/text etc classification on SuperPixel level
	// - smooth labels using graphcut
	// - perform everything else without noise pixels
	// Training:
	// - open mode (whole image only contains e.g. machine printed)
	// - baseline mode -> overlap with superpixel

	cv::Mat img = src.clone();
	//cv::resize(src, img, cv::Size(), 0.25, 0.25, CV_INTER_AREA);

	Timer dt;

	// find super pixels
	rdf::SuperPixel superPixel(img);
	
	if (!superPixel.compute())
		qWarning() << "could not compute super pixel!";

	QVector<QSharedPointer<Pixel> > sp = superPixel.getSuperPixels();

	// find local orientation per pixel
	rdf::LocalOrientation lo(sp);
	if (!lo.compute())
		qWarning() << "could not compute local orientation";

	// smooth estimation
	rdf::GraphCutOrientation pse(sp);
	
	if (!pse.compute())
		qWarning() << "could not compute set orientation";
	
	// pixel labeling
	QSharedPointer<SuperPixelModel> model = SuperPixelModel::read(mConfig.classifierPath());
	//FeatureCollectionManager fcm = FeatureCollectionManager::read(mConfig.featureCachePath());

	//// train classifier
	//SuperPixelTrainer spt(fcm);

	//if (!spt.compute())
	//	qCritical() << "could not train data...";

	//auto model = spt.model();

	SuperPixelClassifier spc(src, sp);
	spc.setModel(model);

	if (!spc.compute())
		qWarning() << "could not classify SuperPixels";

	//// find tab stops
	//rdf::TabStopAnalysis tabStops(sp);
	//if (!tabStops.compute())
	//	qWarning() << "could not compute text block segmentation!";

	//// find text lines
	//rdf::TextLineSegmentation textLines(sp);
	//textLines.addLines(tabStops.tabStopLines(30));	// TODO: fix parameter
	//if (!textLines.compute())
	//	qWarning() << "could not compute text block segmentation!";

	qInfo() << "algorithm computation time" << dt;

	// drawing
	//cv::Mat rImg(img.rows, img.cols, CV_8UC1, cv::Scalar::all(150));
	cv::Mat rImg = img.clone();

	//// draw edges
	//rImg = textBlocks.draw(rImg);
	//rImg = lo.draw(rImg, "1012", 256);
	//rImg = lo.draw(rImg, "507", 128);
	//rImg = lo.draw(rImg, "507", 64);

	//// save super pixel image
	//rImg = superPixel.drawSuperPixels(rImg);
	//rImg = tabStops.draw(rImg);
	//rImg = textLines.draw(rImg);
	rImg = spc.draw(rImg);
	QString maskPath = rdf::Utils::instance().createFilePath(mConfig.outputPath(), "-classified");
	rdf::Image::save(rImg, maskPath);
	qDebug() << "debug image added" << maskPath;


	//// write XML -----------------------------------
	//QString loadXmlPath = rdf::PageXmlParser::imagePathToXmlPath(mConfig.imagePath());

	//rdf::PageXmlParser parser;
	//parser.read(loadXmlPath);
	//auto pe = parser.page();
	//pe->setCreator(QString("CVL"));
	//pe->setImageSize(QSize(img.rows, img.cols));
	//pe->setImageFileName(QFileInfo(mConfig.imagePath()).fileName());

	//// start writing content
	//auto ps = PixelSet::fromEdges(PixelSet::connect(sp, Rect(0, 0, img.cols, img.rows)));

	//if (!ps.empty()) {
	//	QSharedPointer<Region> textRegion = QSharedPointer<Region>(new Region());
	//	textRegion->setType(Region::type_text_region);
	//	textRegion->setPolygon(ps[0]->convexHull());
	//	
	//	for (auto tl : textLines.textLines()) {
	//		textRegion->addUniqueChild(tl);
	//	}

	//	pe->rootRegion()->addUniqueChild(textRegion);
	//}

	//parser.write(mConfig.xmlPath(), pe);
	//qDebug() << "results written to" << mConfig.xmlPath();

}
Exemplo n.º 6
0
/*ARGSUSED*/
void
print_partition(struct partition_info *pinfo, int partnum, int want_header)
{
	int		i;
	blkaddr_t	nblks;
	int		cyl1;
	int		cyl2;
	float		scaled;
	int		maxcyl2;
	int		ncyl2_digits;
	char		*s;
	blkaddr_t	maxnblks = 0;
	blkaddr_t	len;

	/*
	 * To align things nicely, we need to know the maximum
	 * width of the number of cylinders field.
	 */
	maxcyl2 = 0;
	for (i = 0; i < NDKMAP; i++) {
		nblks	= (uint_t)pinfo->pinfo_map[i].dkl_nblk;
		cyl1	= pinfo->pinfo_map[i].dkl_cylno;
		cyl2	= cyl1 + (nblks / spc()) - 1;
		if (nblks > 0) {
			maxcyl2 = max(cyl2, maxcyl2);
			maxnblks = max(nblks, maxnblks);
		}
	}
	/*
	 * Get the number of digits required
	 */
	ncyl2_digits = ndigits(maxcyl2);

	/*
	 * Print the header, if necessary
	 */
	if (want_header) {
		fmt_print("Part      ");
		fmt_print("Tag    Flag     ");
		fmt_print("Cylinders");
		nspaces(ncyl2_digits);
		fmt_print("    Size            Blocks\n");
	}

	/*
	 * Print the partition information
	 */
	nblks	= pinfo->pinfo_map[partnum].dkl_nblk;
	cyl1	= pinfo->pinfo_map[partnum].dkl_cylno;
	cyl2	= cyl1 + (nblks / spc()) - 1;

	fmt_print("  %x ", partnum);

	/*
	 * Print the partition tag.  If invalid, print -
	 */
	s = find_string(ptag_choices,
		(int)pinfo->vtoc.v_part[partnum].p_tag);
	if (s == (char *)NULL)
		s = "-";
	nspaces(10 - (int)strlen(s));
	fmt_print("%s", s);

	/*
	 * Print the partition flag.  If invalid print -
	 */
	s = find_string(pflag_choices,
		(int)pinfo->vtoc.v_part[partnum].p_flag);
	if (s == (char *)NULL)
		s = "-";
	nspaces(6 - (int)strlen(s));
	fmt_print("%s", s);

	nspaces(2);

	if (nblks == 0) {
		fmt_print("%6d      ", cyl1);
		nspaces(ncyl2_digits);
		fmt_print("     0         ");
	} else {
		fmt_print("%6d - ", cyl1);
		nspaces(ncyl2_digits - ndigits(cyl2));
		fmt_print("%d    ", cyl2);
		scaled = bn2mb(nblks);
		if (scaled > (float)1024.0 * 1024.0) {
			fmt_print("%8.2fTB    ",
				scaled/((float)1024.0 * 1024.0));
		} else if (scaled > (float)1024.0) {
			fmt_print("%8.2fGB    ", scaled/(float)1024.0);
		} else {
			fmt_print("%8.2fMB    ", scaled);
		}
	}
	fmt_print("(");
	pr_dblock(fmt_print, nblks);
	fmt_print(")");

	nspaces(ndigits(maxnblks/spc()) - ndigits(nblks/spc()));
	/*
	 * Allocates size of the printf format string.
	 * ndigits(ndigits(maxblks)) gives the byte size of
	 * the printf width field for maxnblks.
	 */
	len = strlen(" %") + ndigits(ndigits(maxnblks)) + strlen("d\n") + 1;
	s = zalloc(len);
	(void) snprintf(s, len, "%s%u%s", " %", ndigits(maxnblks), "u\n");
	fmt_print(s, nblks);
	(void) free(s);
}
Exemplo n.º 7
0
/*
 * This routine implements the 'select' command.  It allows the user
 * to make a pre-defined partition map the current map.
 */
int
p_select()
{
	struct partition_info	*pptr, *parts;
	u_ioparam_t		ioparam;
	int			i, index, deflt, *defltptr = NULL;
	blkaddr_t		b_cylno;
#if defined(i386)
	blkaddr_t		cyl_offset;
#endif

	parts = cur_dtype->dtype_plist;
	/*
	 * If there are no pre-defined maps for this disk type, it's
	 * an error.
	 */
	if (parts == NULL) {
		err_print("No defined partition tables.\n");
		return (-1);
	}

	/*
	 * Loop through the pre-defined maps and list them by name.  If
	 * the current map is one of them, make it the default.  If any
	 * the maps are unnamed, label them as such.
	 */
	for (i = 0, pptr = parts; pptr != NULL; pptr = pptr->pinfo_next) {
		if (cur_parts == pptr) {
			deflt = i;
			defltptr = &deflt;
		}
		if (pptr->pinfo_name == NULL)
			fmt_print("        %d. unnamed\n", i++);
		else
			fmt_print("        %d. %s\n", i++, pptr->pinfo_name);
	}
	ioparam.io_bounds.lower = 0;
	ioparam.io_bounds.upper = i - 1;
	/*
	 * Ask which map should be made current.
	 */
	index = input(FIO_INT, "Specify table (enter its number)", ':',
	    &ioparam, defltptr, DATA_INPUT);
	for (i = 0, pptr = parts; i < index; i++, pptr = pptr->pinfo_next)
		;
	if (cur_label == L_TYPE_EFI) {
		enter_critical();
		cur_disk->disk_parts = cur_parts = pptr;
		exit_critical();
		fmt_print("\n");
		return (0);
	}
#if defined(i386)
	/*
	 * Adjust for the boot and alternate sectors partition - assuming that
	 * the alternate sectors partition physical location follows
	 * immediately the boot partition and partition sizes are
	 * expressed in multiple of cylinder size.
	 */
	cyl_offset = pptr->pinfo_map[I_PARTITION].dkl_cylno + 1;
	if (pptr->pinfo_map[J_PARTITION].dkl_nblk != 0) {
		cyl_offset = pptr->pinfo_map[J_PARTITION].dkl_cylno +
			((pptr->pinfo_map[J_PARTITION].dkl_nblk +
				(spc() - 1)) / spc());
	}
#else	/* !defined(i386) */

	b_cylno = 0;

#endif	/* defined(i386) */

	/*
	 * Before we blow the current map away, do some limits checking.
	 */
	for (i = 0; i < NDKMAP; i++)  {

#if defined(i386)
		if (i == I_PARTITION || i == J_PARTITION || i == C_PARTITION) {
			b_cylno = 0;
		} else if (pptr->pinfo_map[i].dkl_nblk == 0) {
			/*
			 * Always accept starting cyl 0 if the size is 0 also
			 */
			b_cylno = 0;
		} else {
			b_cylno = cyl_offset;
		}
#endif		/* defined(i386) */
		if (pptr->pinfo_map[i].dkl_cylno < b_cylno ||
			pptr->pinfo_map[i].dkl_cylno > (ncyl-1)) {
			err_print(
"partition %c: starting cylinder %d is out of range\n",
				(PARTITION_BASE+i),
				pptr->pinfo_map[i].dkl_cylno);
			return (0);
		}
		if (pptr->pinfo_map[i].dkl_nblk > ((ncyl -
		    pptr->pinfo_map[i].dkl_cylno) * spc())) {
			err_print(
			    "partition %c: specified # of blocks, %u, "
			    "is out of range\n",
			    (PARTITION_BASE+i),
			    pptr->pinfo_map[i].dkl_nblk);
			return (0);
		}
	}
	/*
	 * Lock out interrupts so the lists don't get mangled.
	 */
	enter_critical();
	/*
	 * If the old current map is unnamed, delete it.
	 */
	if (cur_parts != NULL && cur_parts != pptr &&
	    cur_parts->pinfo_name == NULL)
		delete_partition(cur_parts);
	/*
	 * Make the selected map current.
	 */
	cur_disk->disk_parts = cur_parts = pptr;

#if defined(_SUNOS_VTOC_16)
	for (i = 0; i < NDKMAP; i++)  {
		cur_parts->vtoc.v_part[i].p_start =
		    (blkaddr_t)(cur_parts->pinfo_map[i].dkl_cylno *
		    (nhead * nsect));
		cur_parts->vtoc.v_part[i].p_size =
		    (blkaddr_t)cur_parts->pinfo_map[i].dkl_nblk;
	}
#endif	/* defined(_SUNOS_VTOC_16) */

	exit_critical();
	fmt_print("\n");
	return (0);
}
Exemplo n.º 8
0
 /**
  * Removes the progress bar. Call this before doing any other output.
  * The next time update() is called, the progress bar will be visible
  * again.
  */
 void remove() {
     if (m_enable) {
         std::cerr << spc() << "         \r";
         m_prev_percent = 100 + 1;
     }
 }
Exemplo n.º 9
0
/*
 * This routine allows the user to change the boundaries of the given
 * partition in the current partition map.
 */
void
change_partition(int num)
{
	int		i;
	uint64_t	i64, j64;
	int		j;
	int		deflt;
	part_deflt_t	p_deflt;
	u_ioparam_t	ioparam;
	int		tag;
	int		flag;
	char		msg[256];
	long		cyl_offset = 0;
	efi_deflt_t	efi_deflt;

	/*
	 * check if there exists a partition table for the disk.
	 */
	if (cur_parts == NULL) {
		err_print("Current Disk has no partition table.\n");
		return;
	}

	if (cur_label == L_TYPE_EFI) {
	    if (num > cur_parts->etoc->efi_nparts - 1) {
		err_print("Invalid partition for EFI label\n");
		return;
	    }
	    print_efi_partition(cur_parts->etoc, num, 1);
	    fmt_print("\n");
		/*
		 * Prompt for p_tag and p_flag values for this partition
		 */
	    deflt = cur_parts->etoc->efi_parts[num].p_tag;
	    if (deflt == V_UNASSIGNED) {
		deflt = V_USR;
	    }
	    (void) sprintf(msg, "Enter partition id tag");
	    ioparam.io_slist = ptag_choices;
	    tag = input(FIO_SLIST, msg, ':', &ioparam, &deflt, DATA_INPUT);

	    deflt = cur_parts->etoc->efi_parts[num].p_flag;
	    (void) sprintf(msg, "Enter partition permission flags");
	    ioparam.io_slist = pflag_choices;
	    flag = input(FIO_SLIST, msg, ':', &ioparam, &deflt, DATA_INPUT);

	    ioparam.io_bounds.lower = 34;
	    ioparam.io_bounds.upper = cur_parts->etoc->efi_last_u_lba;

	    efi_deflt.start_sector = maxofN(cur_parts->etoc);
	    if ((cur_parts->etoc->efi_parts[num].p_start != 0) &&
		(cur_parts->etoc->efi_parts[num].p_size != 0)) {
		    efi_deflt.start_sector =
			cur_parts->etoc->efi_parts[num].p_start;
	    }
	    efi_deflt.end_sector = ioparam.io_bounds.upper -
					efi_deflt.start_sector;
	    i64 = input(FIO_INT64, "Enter new starting Sector", ':', &ioparam,
		(int *)&efi_deflt, DATA_INPUT);

	    ioparam.io_bounds.lower = 0;
	    ioparam.io_bounds.upper = cur_parts->etoc->efi_last_u_lba;
	    efi_deflt.end_sector = cur_parts->etoc->efi_parts[num].p_size;
	    efi_deflt.start_sector = i64;
	    j64 = input(FIO_EFI, "Enter partition size", ':', &ioparam,
		(int *)&efi_deflt, DATA_INPUT);
	    if (j64 == 0) {
		tag = V_UNASSIGNED;
		i64 = 0;
	    } else if ((j64 != 0) && (tag == V_UNASSIGNED)) {
		tag = V_USR;
	    }

	    if (cur_parts->pinfo_name != NULL)
		make_partition();

	    cur_parts->etoc->efi_parts[num].p_tag = tag;
	    cur_parts->etoc->efi_parts[num].p_flag = flag;
	    cur_parts->etoc->efi_parts[num].p_start = i64;
	    cur_parts->etoc->efi_parts[num].p_size = j64;
	/*
	 * We are now done with EFI part, so return now
	 */
	    return;
	}
	/*
	 * Print out the given partition so the user knows what he/she's
	 * getting into.
	 */
	print_partition(cur_parts, num, 1);
	fmt_print("\n");

	/*
	 * Prompt for p_tag and p_flag values for this partition.
	 */
	assert(cur_parts->vtoc.v_version == V_VERSION);
	deflt = cur_parts->vtoc.v_part[num].p_tag;
	(void) sprintf(msg, "Enter partition id tag");
	ioparam.io_slist = ptag_choices;
	tag = input(FIO_SLIST, msg, ':', &ioparam, &deflt, DATA_INPUT);

	deflt = cur_parts->vtoc.v_part[num].p_flag;
	(void) sprintf(msg, "Enter partition permission flags");
	ioparam.io_slist = pflag_choices;
	flag = input(FIO_SLIST, msg, ':', &ioparam, &deflt, DATA_INPUT);

	/*
	 * Ask for the new values.  The old values are the defaults, and
	 * strict bounds checking is done on the values given.
	 */

#if defined(i386) || defined(__arm)

	if (tag != V_UNASSIGNED && tag != V_BACKUP && tag != V_BOOT) {
		/*
		 * Determine cyl offset for boot and alternate partitions.
		 * Assuming that the alternate sectors partition (slice)
		 * physical location immediately follows the boot
		 * partition and partition sizes are expressed in multiples
		 * of cylinder size.
		 */
		cyl_offset = cur_parts->pinfo_map[I_PARTITION].dkl_cylno + 1;
		if (tag != V_ALTSCTR) {
			if (cur_parts->pinfo_map[J_PARTITION].dkl_nblk != 0) {
				cyl_offset =
				cur_parts->pinfo_map[J_PARTITION].dkl_cylno +
				((cur_parts->pinfo_map[J_PARTITION].dkl_nblk +
				(spc()-1)) / spc());
			}
		}
	}
#endif	/* defined(i386) || defined(__arm) */

	ioparam.io_bounds.lower = 0;
	ioparam.io_bounds.upper = ncyl - 1;
	deflt = max(cur_parts->pinfo_map[num].dkl_cylno,
		cyl_offset);
	i = input(FIO_INT, "Enter new starting cyl", ':', &ioparam,
	    &deflt, DATA_INPUT);

	ioparam.io_bounds.lower = 0;
	ioparam.io_bounds.upper = (ncyl - i) * spc();

	/* fill in defaults for the current partition */
	p_deflt.start_cyl = i;
	p_deflt.deflt_size =
		min(cur_parts->pinfo_map[num].dkl_nblk,
		    ioparam.io_bounds.upper);

	/* call input, passing p_deflt's address, typecast to (int *) */
	j = input(FIO_ECYL, "Enter partition size", ':', &ioparam,
	    (int *)&p_deflt, DATA_INPUT);

	/*
	 * If the current partition has a size of zero change the
	 * tag to Unassigned and the starting cylinder to zero
	 */

	if (j == 0) {
		tag = V_UNASSIGNED;
		i = 0;
	}


#if defined(i386) || defined(__arm)

	if (i < cyl_offset && tag != V_UNASSIGNED && tag != V_BACKUP &&
	    tag != V_BOOT) {
		/*
		 * This slice overlaps boot and/or alternates slice
		 * Check if it's the boot or alternates slice and warn
		 * accordingly
		 */
		if (i < cur_parts->pinfo_map[I_PARTITION].dkl_cylno + 1) {
			fmt_print("\nWarning: Partition overlaps boot ");
			fmt_print("partition. Specify different start cyl.\n");
			return;
		}
		/*
		 * Cyl offset for alternates partition was calculated before
		 */
		if (i < cyl_offset) {
			fmt_print("\nWarning: Partition overlaps alternates ");
			fmt_print("partition. Specify different start cyl.\n");
			return;
		}
	}

#endif	/* defined(i386) || defined(__arm) */

	/*
	 * If user has entered a V_BACKUP tag then the partition
	 * size should specify full disk capacity else
	 * return an Error.
	 */
	if (tag == V_BACKUP) {
		int fullsz;

		fullsz = ncyl * nhead * nsect;
		if (fullsz != j) {
		/*
		 * V_BACKUP Tag Partition != full disk capacity.
		 * print useful messages.
		 */
		fmt_print("\nWarning: Partition with V_BACKUP tag should ");
		fmt_print("specify full disk capacity. \n");
		return;
		}
	}


	/*
	 * If the current partition is named, we can't change it.
	 * We create a new current partition map instead.
	 */
	if (cur_parts->pinfo_name != NULL)
		make_partition();
	/*
	 * Change the values.
	 */
	cur_parts->pinfo_map[num].dkl_cylno = i;
	cur_parts->pinfo_map[num].dkl_nblk = j;

#if defined(_SUNOS_VTOC_16)
	cur_parts->vtoc.v_part[num].p_start = (daddr_t)(i * (nhead * nsect));
	cur_parts->vtoc.v_part[num].p_size = (long)j;
#endif	/* defined(_SUNOS_VTOC_16) */

	/*
	 * Install the p_tag and p_flag values for this partition
	 */
	assert(cur_parts->vtoc.v_version == V_VERSION);
	cur_parts->vtoc.v_part[num].p_tag = (ushort_t)tag;
	cur_parts->vtoc.v_part[num].p_flag = (ushort_t)flag;
}