コード例 #1
0
ファイル: SystemCall.cpp プロジェクト: FFalcon/jbushOS
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);
}
コード例 #2
0
ファイル: SystemCall.cpp プロジェクト: FFalcon/jbushOS
status_t chdir(const char path[])
{
	VNode *dir;
	int error = FileSystem::WalkPath(path, strlen(path), &dir);
	if (error < 0)
		return error;

	VNode *subdir;
	error = dir->Lookup(".", 1, &subdir);
	if (error < 0) {
		dir->ReleaseRef();
		return E_NO_SUCH_FILE;
	}

	subdir->ReleaseRef();

	Thread::GetRunningThread()->SetCurrentDir(dir);
	return E_NO_ERROR;
}
コード例 #3
0
ファイル: SystemCall.cpp プロジェクト: FFalcon/jbushOS
status_t mount(const char device[], const char dir[], const char type[], int,
	char*)
{
	int error;
	int devfd = -1;
	if (strlen(device) > 0) {
		devfd = open(device, 0);
		if (devfd < 0) {
			printf("mount: error opening device\n");
			return E_NO_SUCH_FILE;
		}
	}
	
	VNode *node;
	error = FileSystem::WalkPath(dir, strlen(dir), &node);
	if (error < 0) {
		printf("mount: mount point does not exist\n");
		close_handle(devfd);
		return error;
	}

	if (node->GetCoveredBy() != 0) {
		// Attempting to re-mount an already mounted directory
		printf("mount: filesystem already mounted at this point\n");
		node->ReleaseRef();
		close_handle(devfd);
		return E_NOT_ALLOWED;
	}

	FileSystem *fs;
	error = FileSystem::InstantiateFsType(type, devfd, &fs);
	if (error < 0) {
		node->ReleaseRef();
		close_handle(devfd);
		return error;
	}
	
	node->CoverWith(fs);
	fs->Cover(node);
	return 0;
}
コード例 #4
0
ファイル: SystemCall.cpp プロジェクト: FFalcon/jbushOS
int rmdir(const char path[])
{
	VNode *dir;
	char entry[256];
	int error;
	
	error = FileSystem::GetDirEntry(path, strlen(path), entry, 256, &dir);
	if (error < 0)
		return error;

	error = dir->RemoveDir(entry, strlen(entry));
	dir->ReleaseRef();
	return error;
}
コード例 #5
0
ファイル: SystemCall.cpp プロジェクト: FFalcon/jbushOS
int open(const char path[], int)
{
	VNode *node;
	int error = FileSystem::WalkPath(path, strlen(path), &node);
	if (error < 0)
		return error;

	FileDescriptor *desc;
	error = node->Open(&desc);
	if (error < 0) {
		node->ReleaseRef();
		return error;
	}

	desc->SetName(path);
	return OpenHandle(desc);
}