status_t
UnixEndpoint::_Bind(struct vnode* vnode)
{
	struct stat st;
	status_t error = vfs_stat_vnode(vnode, &st);
	if (error != B_OK)
		RETURN_ERROR(error);

	fAddress.SetTo(st.st_dev, st.st_ino, vnode);
	RETURN_ERROR(B_OK);
}
Esempio n. 2
0
/*static*/ status_t
PackageFSRoot::RegisterVolume(Volume* volume)
{
	// Unless the volume is custom mounted, we stat the supposed root directory.
	// Get the volume mount point relative path to the root directory depending
	// on the mount type.
	const char* relativeRootPath = NULL;

	switch (volume->MountType()) {
		case PACKAGE_FS_MOUNT_TYPE_SYSTEM:
			relativeRootPath = "..";
			break;
		case PACKAGE_FS_MOUNT_TYPE_HOME:
			relativeRootPath = "../..";
			break;
		case PACKAGE_FS_MOUNT_TYPE_CUSTOM:
		default:
			break;
	}

	if (relativeRootPath != NULL) {
		struct vnode* vnode;
		status_t error = vfs_entry_ref_to_vnode(volume->MountPointDeviceID(),
			volume->MountPointNodeID(), relativeRootPath, &vnode);
		if (error != B_OK) {
			dprintf("packagefs: Failed to get root directory \"%s\": %s\n",
				relativeRootPath, strerror(error));
			RETURN_ERROR(error);
		}
		CObjectDeleter<struct vnode> vnodePutter(vnode, &vfs_put_vnode);

		// stat it
		struct stat st;
		error = vfs_stat_vnode(vnode, &st);
		if (error != B_OK) {
			dprintf("packagefs: Failed to stat root directory \"%s\": %s\n",
				relativeRootPath, strerror(error));
			RETURN_ERROR(error);
		}

		// get/create the root
		PackageFSRoot* root;
		error = PackageFSRoot::_GetOrCreateRoot(st.st_dev, st.st_ino, root);
		if (error != B_OK)
			RETURN_ERROR(error);

		// add the volume
		error = root->_AddVolume(volume);
		if (error != B_OK) {
			_PutRoot(root);
			RETURN_ERROR(error);
		}

		return B_OK;
	}

	// custom mount -- always create a new root
	PackageFSRoot* root = new(std::nothrow) PackageFSRoot(-1, 0);
	if (root == NULL)
		return B_NO_MEMORY;
	ObjectDeleter<PackageFSRoot> rootDeleter(root);

	status_t error = root->Init();
	if (error != B_OK)
		RETURN_ERROR(error);

	// add the volume
	error = root->_AddVolume(volume);
	if (error != B_OK) {
		_PutRoot(root);
		RETURN_ERROR(error);
	}

	// We don't add the root to the list.
	rootDeleter.Detach();
	return B_OK;
}