Esempio n. 1
0
status_t
FileDevice::Open(const char* path, int openMode, void** _cookie)
{
	// get the vnode
	struct vnode* vnode;
	status_t error = vfs_get_vnode_from_fd(fFD, true, &vnode);
	if (error != B_OK)
		return error;

	// open it
	int fd = vfs_open_vnode(vnode, openMode, true);
	if (fd < 0) {
		vfs_put_vnode(vnode);
		return fd;
	}
	// our vnode reference does now belong to the FD

	Cookie* cookie = new(std::nothrow) Cookie(fd);
	if (cookie == NULL) {
		close(fd);
		return B_NO_MEMORY;
	}

	*_cookie = cookie;
	return B_OK;
}
Esempio n. 2
0
status_t
PackagesDirectory::_Init(struct vnode* vnode, struct stat& _st)
{
	fDirFD = vfs_open_vnode(vnode, O_RDONLY, true);

	if (fDirFD < 0) {
		ERROR("Failed to open packages directory \"%s\"\n", strerror(fDirFD));
		vfs_put_vnode(vnode);
		RETURN_ERROR(fDirFD);
	}
	// Our vnode reference has been transferred to the FD.

	// Is it a directory at all?
	struct stat& st = _st;
	if (fstat(fDirFD, &st) < 0)
		RETURN_ERROR(errno);

	fNodeRef.device = st.st_dev;
	fNodeRef.node = st.st_ino;

	// get a normalized path
	KPath normalizedPath;
	if (normalizedPath.InitCheck() != B_OK)
		RETURN_ERROR(normalizedPath.InitCheck());

	char* normalizedPathBuffer = normalizedPath.LockBuffer();
	status_t error = vfs_entry_ref_to_path(fNodeRef.device, fNodeRef.node, NULL,
		true, normalizedPathBuffer, normalizedPath.BufferSize());
	if (error != B_OK)
		RETURN_ERROR(error);

	fPath = strdup(normalizedPathBuffer);
	if (fPath == NULL)
		RETURN_ERROR(B_NO_MEMORY);

	return B_OK;
}