Beispiel #1
0
int CreateFileArea(const char name[], const char path[], unsigned int va, off_t offset,
	size_t size, int flags, PageProtection prot, Team &team)
{
	VNode *node;
	int error;
	
	if (offset % PAGE_SIZE) {
		printf("Unaligned file offset for area\n");
		return E_INVALID_OPERATION; // File offset must be page aligned
	}

	error = FileSystem::WalkPath(path, strlen(path), &node);
	if (error < 0) {
		printf("map_file: file not found\n");
		return error;
	}

	PageCache *cache = node->GetPageCache();

	// If this is a private area, construct a copy cache
	if ((flags & MAP_PRIVATE) != 0) {
		cache = new PageCache(0, cache);
		if (cache == 0) {
			node->ReleaseRef();
			return E_NO_MEMORY;
		}
	}

	// It is important that CreateArea not incur a fault!		
	char nameCopy[OS_NAME_LENGTH];
	if (!CopyUser(nameCopy, name, OS_NAME_LENGTH))
		return E_BAD_ADDRESS;

	Area *area = team.GetAddressSpace()->CreateArea(nameCopy, size, AREA_NOT_WIRED,
		prot, cache, offset, va, flags);
		
	if (area == 0) {
		printf("CreateArea failed\n");
		node->ReleaseRef();
		return E_ERROR;
	}
		
	return team.GetHandleTable()->Open(area);
}