Example #1
0
int link_open(link_transport_mdriver_t * driver, const char * path, int flags, ...){
	link_op_t op;
	link_reply_t reply;
	link_mode_t mode;
	int err;
	va_list ap;

	if ( flags & LINK_O_CREAT ){
		va_start(ap, flags);
		mode = va_arg(ap, link_mode_t);
		va_end(ap);
	} else {
		mode = 0;
	}

	if( driver == 0 ){
		return posix_open(path, convert_flags(flags) | POSIX_OPEN_FLAGS, mode);
	}

	link_debug(LINK_DEBUG_MESSAGE, "open %s 0%o 0x%X using %p", path, mode, flags, driver->dev.handle);


	op.open.cmd = LINK_CMD_OPEN;
	op.open.path_size = strlen(path) + 1;
	op.open.flags = flags;
	op.open.mode = mode;

	link_debug(LINK_DEBUG_MESSAGE, "Write open op (%p)", driver->dev.handle);
	err = link_transport_masterwrite(driver, &op, sizeof(link_open_t));
	if ( err < 0 ){
		link_error("failed to write open op with handle %p", driver->dev.handle);
		return link_handle_err(driver, err);
	}

	//Send the path on the bulk out endpoint
	link_debug(LINK_DEBUG_MESSAGE, "Write open path (%d bytes)", op.open.path_size);
	err = link_transport_masterwrite(driver, path, op.open.path_size);
	if ( err < 0 ){
		link_error("failed to write path");
		return link_handle_err(driver, err);
	}



	//read the reply to see if the file opened correctly
	err = link_transport_masterread(driver, &reply, sizeof(reply));
	if ( err < 0 ){
		link_error("failed to read the reply");
		return link_handle_err(driver, err);
	}

	if ( reply.err < 0 ){
		link_errno = reply.err_number;
		link_debug(LINK_DEBUG_WARNING, "Failed to ioctl file (%d)", link_errno);
	} else {
		link_debug(LINK_DEBUG_MESSAGE, "Opened fildes: %d", reply.err);
	}
	return reply.err;
}
Example #2
0
int link_open(link_phy_t handle, const char * path, int flags, ...){
	link_op_t op;
	link_reply_t reply;
	link_mode_t mode;
	int err;
	va_list ap;

	link_debug(5, "open %s 0%o\n", path, flags);

	if ( flags & LINK_O_CREAT ){
		va_start(ap, flags);
		mode = va_arg(ap, link_mode_t);
		va_end(ap);
	} else {
		mode = 0;
	}


	op.open.cmd = LINK_CMD_OPEN;
	op.open.path_size = strlen(path) + 1;
	op.open.flags = flags;
	op.open.mode = mode;

	link_debug(4, "Write open op (0x%lX)\n", (long unsigned int)link_dev);
	err = link_protocol_masterwrite(handle, &op, sizeof(link_open_t));
	if ( err < 0 ){
		link_error("failed to write open op\n");
		return link_handle_err(handle, err);
	}

	//Send the path on the bulk out endpoint
	link_debug(4, "Write open path (%d bytes)\n", op.open.path_size);
	err = link_protocol_masterwrite(handle, path, op.open.path_size);
	if ( err < 0 ){
		link_error("failed to write path\n");
		return link_handle_err(handle, err);
	}



	//read the reply to see if the file opened correctly
	err = link_protocol_masterread(handle, &reply, sizeof(reply));
	if ( err < 0 ){
		link_error("failed to read the reply\n");
		return link_handle_err(handle, err);
	}

	link_errno = reply.err_number;
	if ( reply.err < 0 ){
		link_debug(1, "Failed to open file (%d)\n", link_errno);
		return LINK_DEV_ERROR;
	}
	return reply.err;
}