Пример #1
0
void cmp_tests() {
	int a = 1, b = 2;
	
	/* greater tests */
	gtl((char *)&a, (char *)&b); assert(*(int32_t *)ecx == 0);
	gtl((char *)&b, (char *)&a); assert(*(int32_t *)ecx == 1);
	gel((char *)&a, (char *)&b); assert(*(int32_t *)ecx == 0);
	gel((char *)&a, (char *)&a); assert(*(int32_t *)ecx == 1);
	gel((char *)&b, (char *)&a); assert(*(int32_t *)ecx == 1);

	/* less tests */
	ltl((char *)&a, (char *)&b); assert(*(int32_t *)ecx == 1);
	ltl((char *)&b, (char *)&a); assert(*(int32_t *)ecx == 0);
	lel((char *)&a, (char *)&b); assert(*(int32_t *)ecx == 1);
	lel((char *)&a, (char *)&a); assert(*(int32_t *)ecx == 1);
	lel((char *)&b, (char *)&a); assert(*(int32_t *)ecx == 0);

	/* (not) equal tests */
	eql((char *)&a, (char *)&b); assert(*(int32_t *)ecx == 0);
	eql((char *)&b, (char *)&b); assert(*(int32_t *)ecx == 1);
	nel((char *)&a, (char *)&b); assert(*(int32_t *)ecx == 1);
	nel((char *)&a, (char *)&a); assert(*(int32_t *)ecx == 0);

	/* and/or tests */
	a = 0, b = 1;
	andl((char *)&a, (char *)&a); assert(*(int32_t *)ecx == 0);
	andl((char *)&a, (char *)&b); assert(*(int32_t *)ecx == 0);
	andl((char *)&b, (char *)&b); assert(*(int32_t *)ecx == 1);
	orl((char *)&a, (char *)&a); assert(*(int32_t *)ecx == 0);
	orl((char *)&a, (char *)&b); assert(*(int32_t *)ecx == 1);
	orl((char *)&b, (char *)&b); assert(*(int32_t *)ecx == 1);
}
Пример #2
0
int
good_fdisk()
{
	char		buf[MAXPATHLEN];
	struct stat	statbuf;

	(void) get_pname(&buf[0]);
	if (stat(buf, &statbuf) == -1 ||
	    !S_ISCHR(statbuf.st_mode) ||
	    cur_label == L_TYPE_EFI) {
		/*
		 * Return if this disk does not support fdisk table or
		 * if the disk is labeled with EFI.
		 */
		return (1);
	}

	if (lel(cur_disk->fdisk_part.numsect) > 0)
		return (1);
	else
		return (0);
}
Пример #3
0
int main( int argc , char * argv[] )  {
    std::cout << "算术" << std::endl;
    int a = 10 , b = 20;
    int ret;

    std::plus<int>add;
    ret = add(a,b);
    std::cout << ret << std::endl;

    std::minus<int> min;
    ret = min(b,a);
    std::cout << ret << std::endl;

    std::multiplies<int> mp;
    ret = mp(a,b);
    std::cout << ret << std::endl;

    std::divides<int> divi;
    ret = divi(a,b);
    std::cout << ret << std::endl;

    std::modulus<int> mod;
    ret = mod(a,b);
    std::cout << ret << std::endl;

    std::negate<int> neg;
    ret = neg(a);
    std::cout << ret << std::endl;


    std::cout << "关系" <<std::endl;
    int a2 = 10 , b2 = 20;
    int ret2;
    std::equal_to<int> et;
    ret2 = et(a,b);
    std::cout << ret2 <<std::endl;

    std::not_equal_to<int> net;
    ret2 = net(a,b);
    std::cout << ret2 << std::endl;

    std::greater<int>gt;
    ret2 = gt(b,a);
    std::cout << ret2 << std::endl;

    std::greater_equal<int> gte;
    ret2 = gte(a,b);
    std::cout << ret2 <<std::endl;

    std::less<int> ls;
    ret2 = ls(a,b);
    std::cout << ret2 << std::endl;

    std::less_equal<int> lel;
    ret2 = lel(a,b);
    std::cout << ret2 << std::endl;

    std::cout << "逻辑" << std::endl;
    int ret3;
    std::logical_and<int> la;
    ret3 = la(a,b);
    std::cout << ret3 <<std::endl;

    std::logical_or<int> lo;
    ret3 = lo(a,b);
    std::cout << ret3 << std::endl;

    std::logical_not<int>ln;
    ret3 = ln(b);
    std::cout << ret3 <<std::endl;

    return EXIT_SUCCESS;
}
Пример #4
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);
}
Пример #5
0
int
copy_solaris_part(struct ipart *ipart)
{

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

	(void) get_pname(&buf[0]);
	if (stat(buf, &statbuf) == -1 ||
	    !S_ISCHR(statbuf.st_mode) ||
	    ((cur_label == L_TYPE_EFI) &&
		(cur_disk->disk_flags & DSK_LABEL_DIRTY))) {
		/*
		 * Make sure to reset solaris_offset to zero if it is
		 *	previously set by a selected disk that
		 *	supports the fdisk table.
		 */
		solaris_offset = 0;
		/*
		 * Return if this disk does not support fdisk table or
		 * if it uses an EFI label but has not yet been labelled.
		 * If the EFI label has not been written then the open
		 * on the partition will fail.
		 */
		return (0);
	}

	if ((fd = open(buf, O_RDONLY)) < 0) {
		err_print("Error: can't open disk '%s'.\n", buf);
		return (-1);
	}

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

	if (status != sizeof (struct mboot)) {
		err_print("Bad read of fdisk partition.\n");
		(void) close(fd);
		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 (ip.systid == SUNIXOS ||
		    ip.systid == SUNIXOS2 ||
		    ip.systid == EFI_PMBR) {
			solaris_offset = lel(ip.relsect);
			bcopy(&ip, ipart, sizeof (struct ipart));

			/*
			 * if the disk has an EFI label, we typically won't
			 * have values for nhead and nsect.  format seems to
			 * work without them, and we need to protect ourselves
			 * from FPE's
			 */
			if (nhead != 0 && nsect != 0) {
				pcyl = lel(ip.numsect) / (nhead * nsect);
				ncyl = pcyl - acyl;
			}
#ifdef DEBUG
			else {
				err_print("Critical geometry values are zero:\n"
					"\tnhead = %d; nsect = %d\n", nhead,
					nsect);
			}
#endif /* DEBUG */

			break;
		}
	}

	(void) close(fd);
	return (0);

}
Пример #6
0
static int
get_solaris_part(int fd, struct ipart *ipart)
{
	int		i;
	struct ipart	ip;
	int		status;
	char		*bootptr;
	struct dk_label	update_label;

	(void) lseek(fd, 0, 0);
	status = read(fd, (caddr_t)&boot_sec, NBPSCTR);

	if (status != NBPSCTR) {
		err_print("Bad read of fdisk partition. Status = %x\n", status);
		err_print("Cannot read fdisk partition information.\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 = &boot_sec.parts[ipc];
		(void) fill_ipart(bootptr, &ip);

		/*
		 * we are interested in Solaris and EFI partition types
		 */
		if (ip.systid == SUNIXOS ||
		    ip.systid == SUNIXOS2 ||
		    ip.systid == EFI_PMBR) {
			/*
			 * if the disk has an EFI label, nhead and nsect may
			 * be zero.  This test protects us from FPE's, and
			 * format still seems to work fine
			 */
			if (nhead != 0 && nsect != 0) {
				pcyl = lel(ip.numsect) / (nhead * nsect);
				xstart = lel(ip.relsect) / (nhead * nsect);
				ncyl = pcyl - acyl;
			}
#ifdef DEBUG
			else {
				err_print("Critical geometry values are zero:\n"
					"\tnhead = %d; nsect = %d\n", nhead,
					nsect);
			}
#endif /* DEBUG */

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

	if (i == FD_NUMPART) {
		err_print("Solaris fdisk partition not found\n");
		return (-1);
	}

	/*
	 * compare the previous and current Solaris partition
	 * but don't use bootid in determination of Solaris partition changes
	 */
	ipart->bootid = ip.bootid;
	status = bcmp(&ip, ipart, sizeof (struct ipart));

	bcopy(&ip, ipart, sizeof (struct ipart));

	/* if the disk partitioning has changed - get the VTOC */
	if (status) {
		status = ioctl(fd, DKIOCGVTOC, &cur_parts->vtoc);
		if (status == -1) {
			i = errno;
			err_print("Bad ioctl DKIOCGVTOC.\n");
			err_print("errno=%d %s\n", i, strerror(i));
			err_print("Cannot read vtoc information.\n");
			return (-1);
		}

		status = read_label(fd, &update_label);
		if (status == -1) {
			err_print("Cannot read label information.\n");
			return (-1);
		}

#if defined(_SUNOS_VTOC_16)
		/*
		 * this is to update the slice table on x86
		 * we don't care about VTOC8 here
		 */
		for (i = 0; i < NDKMAP; i ++) {
			cur_parts->pinfo_map[i].dkl_cylno =
			    update_label.dkl_vtoc.v_part[i].p_start /
			    ((int)(update_label.dkl_nhead *
			    update_label.dkl_nsect));
			cur_parts->pinfo_map[i].dkl_nblk =
			    update_label.dkl_vtoc.v_part[i].p_size;
		}
#endif /* defined(_SUNOS_VTOC_16) */

		cur_dtype->dtype_ncyl = update_label.dkl_ncyl;
		cur_dtype->dtype_pcyl = update_label.dkl_pcyl;
		cur_dtype->dtype_acyl = update_label.dkl_acyl;
		cur_dtype->dtype_nhead = update_label.dkl_nhead;
		cur_dtype->dtype_nsect = update_label.dkl_nsect;
		ncyl = cur_dtype->dtype_ncyl;
		acyl = cur_dtype->dtype_acyl;
		pcyl = cur_dtype->dtype_pcyl;
		nsect = cur_dtype->dtype_nsect;
		nhead = cur_dtype->dtype_nhead;
	}
	return (0);
}