コード例 #1
0
ファイル: wait.c プロジェクト: CanuxCheng/APUE
int main(int argc, char **argv)
{
	pid_t pid;
	int status;

	if ((pid = fork()) < 0)
		err_sys("fork error");
	else if (pid == 0)
		exit(7);
	if (wait(&status) != pid)
		err_sys("wait error");
	mystatus(status);

	if ((pid = fork()) < 0)
		err_sys("fork error");
	else if (pid == 0)
		abort();
	if (wait(&status) != pid)
		err_sys("wait error");
	mystatus(status);

	if ((pid = fork()) < 0)
		err_sys("fork error");
	else if (pid == 0)
		status /= 0;
	if (wait(&status) != pid)
		err_sys("wait error");
	mystatus(status);

	exit(0);
}
コード例 #2
0
ファイル: utils.c プロジェクト: freedict/fd-dictionaries
void mysave(void)
{
    g_return_if_fail(teidoc);
    int ret = xmlSaveFile(selected_filename, teidoc);
    if(ret==-1)
    {
        mystatus(_("Saving to %s failed."), selected_filename);
    }

    if(file_modified)
    {
        file_modified = FALSE;
        on_file_modified_changed();
    }

    mystatus(_("Saved."));
}
コード例 #3
0
ファイル: virtio_blk.c プロジェクト: AgamAgarwal/minix
static int
virtio_blk_flush(void)
{
	struct vumap_phys phys[2];
	size_t phys_cnt = sizeof(phys) / sizeof(phys[0]);

	/* Which thread is doing this request? */
	thread_id_t tid = blockdriver_mt_get_tid();

	/* Host may not support flushing */
	if (!virtio_host_supports(blk_dev, VIRTIO_BLK_F_FLUSH))
		return EOPNOTSUPP;

	/* Prepare the header */
	memset(&hdrs_vir[tid], 0, sizeof(hdrs_vir[0]));
	hdrs_vir[tid].type = VIRTIO_BLK_T_FLUSH;

	/* Let this be a barrier if the host supports it */
	if (virtio_host_supports(blk_dev, VIRTIO_BLK_F_BARRIER))
		hdrs_vir[tid].type |= VIRTIO_BLK_T_BARRIER;

	/* Header and status for the queue */
	phys[0].vp_addr = hdrs_phys + tid * sizeof(hdrs_vir[0]);
	phys[0].vp_size = sizeof(hdrs_vir[0]);
	phys[1].vp_addr = status_phys + tid * sizeof(status_vir[0]);
	phys[1].vp_size = 1;

	/* Status always needs write access */
	phys[1].vp_addr |= 1;

	/* Send flush request to queue */
	virtio_to_queue(blk_dev, 0, phys, phys_cnt, &tid);

	blockdriver_mt_sleep();

	/* All was good */
	if (mystatus(tid) == VIRTIO_BLK_S_OK)
		return OK;

	/* Error path */
	dprintf(("ERROR status=%02x op=flush t=%d", mystatus(tid), tid));

	return virtio_blk_status2error(mystatus(tid));
}
コード例 #4
0
ファイル: system.c プロジェクト: crazy-canux/cAPI
int main(int argc, char **argv)
{
	int status;
	if ((status = system("date")) < 0)
		err_sys("system error");
	printf("%d\n", status);
	mystatus(status);

	if ((status = system("no")) < 0)
		err_sys("system error");
	printf("%d\n", status);
	mystatus(status);

	if ((status = system("who; exit 44")) < 0)
		err_sys("system error");
	printf("%d\n", status);
	mystatus(status);

	exit(0);
}
コード例 #5
0
ファイル: virtio_blk.c プロジェクト: AgamAgarwal/minix
static ssize_t
virtio_blk_transfer(dev_t minor, int write, u64_t position, endpoint_t endpt,
		    iovec_t *iovec, unsigned int cnt, int flags)
{
	/* Need to translate vir to phys */
	struct vumap_vir vir[NR_IOREQS];

	/* Physical addresses of buffers, including header and trailer */
	struct vumap_phys phys[NR_IOREQS + 2];

	/* Which thread is doing the transfer? */
	thread_id_t tid = blockdriver_mt_get_tid();

	vir_bytes size = 0;
	vir_bytes size_tmp = 0;
	struct device *dv;
	u64_t sector;
	u64_t end_part;
	int r, pcnt = sizeof(phys) / sizeof(phys[0]);

	iovec_s_t *iv = (iovec_s_t *)iovec;
	int access = write ? VUA_READ : VUA_WRITE;

	/* Make sure we don't touch this one anymore */
	iovec = NULL;

	if (cnt > NR_IOREQS)
		return EINVAL;

	/* position greater than capacity? */
	if (position >= blk_config.capacity * VIRTIO_BLK_BLOCK_SIZE)
		return 0;

	dv = virtio_blk_part(minor);

	/* Does device exist? */
	if (!dv)
		return ENXIO;

	position += dv->dv_base;
	end_part = dv->dv_base + dv->dv_size;

	/* Hmmm, AHCI tries to fix this up, but lets just say everything
	 * needs to be sector (512 byte) aligned...
	 */
	if (position % VIRTIO_BLK_BLOCK_SIZE) {
		dprintf(("Non sector-aligned access %016llx", position));
		return EINVAL;
	}

	sector = position / VIRTIO_BLK_BLOCK_SIZE;

	r = prepare_vir_vec(endpt, vir, iv, cnt, &size);

	if (r != OK)
		return r;

	if (position >= end_part)
		return 0;

	/* Truncate if the partition is smaller than that */
	if (position + size > end_part - 1) {
		size = end_part - position;

		/* Fix up later */
		size_tmp = 0;
		cnt = 0;
	} else {
		/* Use all buffers */
		size_tmp = size;
	}

	/* Fix up the number of vectors if size was truncated */
	while (size_tmp < size)
		size_tmp += vir[cnt++].vv_size;

	/* If the last vector was too big, just truncate it */
	if (size_tmp > size) {
		vir[cnt - 1].vv_size = vir[cnt -1].vv_size - (size_tmp - size);
		size_tmp -= (size_tmp - size);
	}

	if (size % VIRTIO_BLK_BLOCK_SIZE) {
		dprintf(("non-sector sized read (%lu) from %d", size, endpt));
		return EINVAL;
	}

	/* Map vir to phys */
	if ((r = sys_vumap(endpt, vir, cnt, 0, access,
			   &phys[1], &pcnt)) != OK) {

		dprintf(("Unable to map memory from %d (%d)", endpt, r));
		return r;
	}

	/* Prepare the header */
	memset(&hdrs_vir[tid], 0, sizeof(hdrs_vir[0]));

	if (write)
		hdrs_vir[tid].type = VIRTIO_BLK_T_OUT;
	else
		hdrs_vir[tid].type = VIRTIO_BLK_T_IN;

	hdrs_vir[tid].ioprio = 0;
	hdrs_vir[tid].sector = sector;

	/* First the header */
	phys[0].vp_addr = hdrs_phys + tid * sizeof(hdrs_vir[0]);
	phys[0].vp_size = sizeof(hdrs_vir[0]);

	/* Put the physical buffers into phys */
	if ((r = prepare_bufs(vir, &phys[1], pcnt, write)) != OK)
		return r;

	/* Put the status at the end */
	phys[pcnt + 1].vp_addr = status_phys + tid * sizeof(status_vir[0]);
	phys[pcnt + 1].vp_size = sizeof(u8_t);

	/* Status always needs write access */
	phys[1 + pcnt].vp_addr |= 1;

	/* Send addresses to queue */
	virtio_to_queue(blk_dev, 0, phys, 2 + pcnt, &tid);

	/* Wait for completion */
	blockdriver_mt_sleep();

	/* All was good */
	if (mystatus(tid) == VIRTIO_BLK_S_OK)
		return size;

	/* Error path */
	dprintf(("ERROR status=%02x sector=%llu len=%lx cnt=%d op=%s t=%d",
		 mystatus(tid), sector, size, pcnt,
		 write ? "write" : "read", tid));

	return virtio_blk_status2error(mystatus(tid));
}