⛏️ index : haiku.git

author Rene Gollent <anevilyak@gmail.com> 2009-08-29 22:12:35.0 +00:00:00
committer Rene Gollent <anevilyak@gmail.com> 2009-08-29 22:12:35.0 +00:00:00
commit
cd13c010dff4a0ddedc4e46ec77f4d71630a1b52 [patch]
tree
b6693c316d7dac748dcca6c24146966fc262d015
parent
b1cc2c45faadc944ec3342b05be50bc2c285c185
download
cd13c010dff4a0ddedc4e46ec77f4d71630a1b52.tar.gz

Merge 32819,32820 into alpha.


git-svn-id: file:///srv/svn/repos/haiku/haiku/branches/releases/r1alpha1@32821 a95241bf-73f2-0310-859d-f6bbb57e9c96

Diff

 headers/posix/dirent.h                                       | 20 ++++++++++----------
 headers/private/libroot/dirent_private.h                     | 24 ------------------------
 src/system/kernel/module.cpp                                 | 16 ++++++----------
 src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp | 44 +++++++++++++++++++++++++++++---------------
 src/system/libroot/os/Jamfile                                |  2 +-
 src/system/libroot/os/fs_attr.cpp                            | 32 ++++++++------------------------
 src/system/libroot/os/fs_index.c                             | 31 +++++++------------------------
 src/system/libroot/os/fs_query.cpp                           | 26 ++++++++------------------
 src/system/libroot/posix/dirent.c                            | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 9 files changed, 122 insertions(+), 153 deletions(-)

diff --git a/headers/posix/dirent.h b/headers/posix/dirent.h
index 354aa1c..25bc7b4 100644
--- a/headers/posix/dirent.h
+++ b/headers/posix/dirent.h
@@ -32,16 +32,16 @@
extern "C" {
#endif

DIR				*opendir(const char *dirname);
struct dirent	*readdir(DIR *dir);
int				readdir_r(DIR *dir, struct dirent *entry, struct dirent **_result);
int				closedir(DIR *dir);
void			rewinddir(DIR *dir);
void 			seekdir(DIR *dir, long int loc);
long int		telldir(DIR *);

/* Non-POSIX extension to get the FD out of the private DIR */
int				dirfd(const DIR *dir);
DIR*			fdopendir(int fd);
DIR*			opendir(const char* dirName);
struct dirent*	readdir(DIR* dir);
int				readdir_r(DIR* dir, struct dirent* entry,
					struct dirent** _result);
int				closedir(DIR* dir);
void			rewinddir(DIR* dir);
void 			seekdir(DIR* dir, long int position);
long int		telldir(DIR* dir);
int				dirfd(const DIR* dir);

#ifdef __cplusplus
}
diff --git a/headers/private/libroot/dirent_private.h b/headers/private/libroot/dirent_private.h
deleted file mode 100644
index 23b51c6..0000000 100644
--- a/headers/private/libroot/dirent_private.h
+++ /dev/null
@@ -1,24 +1,0 @@
/*
 * Copyright 2008, Axel Dörfler, axeld@pinc-software.de.
 * Distributed under the terms of the MIT License.
 */
#ifndef DIRENT_PRIVATE_H
#define DIRENT_PRIVATE_H


#include <dirent.h>


#define DIR_BUFFER_SIZE	4096
#define DIRENT_BUFFER_SIZE (DIR_BUFFER_SIZE - offsetof(struct __DIR, first_entry))

struct __DIR {
	int				fd;
	short			next_entry;
	unsigned short	entries_left;
	long			seek_position;
	long			current_position;
	struct dirent	first_entry;
};

#endif	/* DIRENT_PRIVATE_H */
diff --git a/src/system/kernel/module.cpp b/src/system/kernel/module.cpp
index 8b321b7..8449bd0 100644
--- a/src/system/kernel/module.cpp
+++ b/src/system/kernel/module.cpp
@@ -11,6 +11,7 @@

#include <kmodule.h>

#include <dirent.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@@ -19,8 +20,6 @@
#include <FindDirectory.h>
#include <NodeMonitor.h>

#include <dirent_private.h>

#include <boot_device.h>
#include <boot/elf.h>
#include <elf.h>
@@ -1529,24 +1528,21 @@
		}

		struct stat stat;
		status_t status = vfs_read_stat(dir->fd, dirent->d_name, true, &stat,
		status_t status = vfs_read_stat(dirfd(dir), dirent->d_name, true, &stat,
			true);
		if (status != B_OK)
			continue;

		if (S_ISDIR(stat.st_mode)) {
			int fd = _kern_open_dir(dir->fd, dirent->d_name);
			int fd = _kern_open_dir(dirfd(dir), dirent->d_name);
			if (fd < 0)
				continue;

			DIR* subDir = (DIR*)malloc(DIR_BUFFER_SIZE);
			DIR* subDir = fdopendir(fd);
			if (subDir == NULL) {
				close(fd);
				continue;
			}

			subDir->fd = fd;
			subDir->entries_left = 0;

			stack.Push(subDir);

@@ -1554,7 +1550,7 @@
				&& directMatch)
				directMatchAdded = true;
		} else if (S_ISREG(stat.st_mode)) {
			if (_AddModuleNode(stat.st_dev, stat.st_ino, dir->fd,
			if (_AddModuleNode(stat.st_dev, stat.st_ino, dirfd(dir),
					dirent->d_name) == B_OK && directMatch)
				directMatchAdded = true;
		}
@@ -1564,7 +1560,7 @@
		// We need to monitor this directory to see if a matching file
		// is added.
		struct stat stat;
		status_t status = vfs_read_stat(dir->fd, NULL, true, &stat, true);
		status_t status = vfs_read_stat(dirfd(dir), NULL, true, &stat, true);
		if (status == B_OK)
			_AddDirectoryNode(stat.st_dev, stat.st_ino);
	}
diff --git a/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp b/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp
index 649b729..39a4248 100644
--- a/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp
+++ b/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp
@@ -60,7 +60,6 @@
	dev_t					device;
	ino_t					directory;
	ino_t					node;
	NotificationListener*	listener;
};


@@ -159,8 +158,30 @@
				deviceEvent->device = event->GetInt32("device", -1);
				deviceEvent->directory = event->GetInt64("directory", -1);
				deviceEvent->node = event->GetInt64("node", -1);
				deviceEvent->listener = this;

				struct stat st;
				if (vfs_stat_node_ref(deviceEvent->device, 
					deviceEvent->node, &st) != 0) {
					delete deviceEvent;
					break;
				}
				if (S_ISDIR(st.st_mode)) {
					if (opcode == B_ENTRY_CREATED) {
						add_node_listener(
							deviceEvent->device,
							deviceEvent->node,
							B_WATCH_DIRECTORY,
							*this);
					} else {
						remove_node_listener(
							deviceEvent->device,
							deviceEvent->node,
							*this);
					}
					delete deviceEvent;
					break;
				}

				// TODO: a real in-kernel DPC mechanism would be preferred...
				thread_id thread = spawn_kernel_thread(_HandleDeviceEvent,
					"device event", B_NORMAL_PRIORITY, deviceEvent);
@@ -179,22 +200,8 @@
	static status_t _HandleDeviceEvent(void* _event)
	{
		device_event* event = (device_event*)_event;

		struct stat st;
		if (vfs_stat_node_ref(event->device, event->node, &st) != 0) {
			delete event;
			return B_ERROR;
		}

		if (S_ISDIR(st.st_mode)) {
			if (event->opcode == B_ENTRY_CREATED) {
				add_node_listener(event->device, event->node, B_WATCH_DIRECTORY,
					*event->listener);
			} else {
				remove_node_listener(event->device, event->node,
					*event->listener);
			}
		} else if (strcmp(event->name, "raw") == 0) {
		
		if (strcmp(event->name, "raw") == 0) {
			// a new raw device was added/removed
			KPath path(B_PATH_NAME_LENGTH + 1);
			if (path.InitCheck() != B_OK
@@ -206,7 +213,6 @@
			}

			path.UnlockBuffer();

			if (event->opcode == B_ENTRY_CREATED)
				KDiskDeviceManager::Default()->CreateDevice(path.Path());
			else
diff --git a/src/system/libroot/os/Jamfile b/src/system/libroot/os/Jamfile
index 2ee6734..cc21069 100644
--- a/src/system/libroot/os/Jamfile
+++ b/src/system/libroot/os/Jamfile
@@ -1,9 +1,9 @@
SubDir HAIKU_TOP src system libroot os ;

UsePrivateSystemHeaders ;
UsePrivateHeaders kernel ;
	# for util/KMessage.h
UsePrivateHeaders libroot runtime_loader ;
UsePrivateHeaders libroot runtime_loader shared ;

MergeObject os_main.o :
	area.c
diff --git a/src/system/libroot/os/fs_attr.cpp b/src/system/libroot/os/fs_attr.cpp
index 65a071c..22413ee 100644
--- a/src/system/libroot/os/fs_attr.cpp
+++ b/src/system/libroot/os/fs_attr.cpp
@@ -6,25 +6,17 @@

#include <fs_attr.h>

#include <stdlib.h>
#include <fcntl.h>
#include <syscall_utils.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>

#include "dirent_private.h"
#include "syscalls.h"
#include <syscalls.h>
#include <syscall_utils.h>


// TODO: think about adding special syscalls for the read/write/stat functions
// to speed them up

#define RETURN_AND_SET_ERRNO(status) \
	{ \
		if (status < 0) { \
			errno = status; \
			return -1; \
		} \
		return status; \
	}


static DIR *
@@ -38,15 +30,11 @@
		return NULL;
	}

	/* allocate the memory for the DIR structure */
	if ((dir = (DIR *)malloc(DIR_BUFFER_SIZE)) == NULL) {
		errno = B_NO_MEMORY;
	// allocate the DIR structure
	if ((dir = fdopendir(fd)) == NULL) {
		_kern_close(fd);
		return NULL;
	}

	dir->fd = fd;
	dir->entries_left = 0;

	return dir;
}
@@ -151,11 +139,7 @@
extern "C" int
fs_close_attr_dir(DIR* dir)
{
	int status = _kern_close(dir->fd);

	free(dir);

	RETURN_AND_SET_ERRNO(status);
	return closedir(dir);
}


diff --git a/src/system/libroot/os/fs_index.c b/src/system/libroot/os/fs_index.c
index c352cd0..872f8ac 100644
--- a/src/system/libroot/os/fs_index.c
+++ b/src/system/libroot/os/fs_index.c
@@ -6,24 +6,15 @@

#include <fs_index.h>

#include <stdlib.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>

#include <dirent_private.h>
#include <syscalls.h>

#include <syscall_utils.h>

#define RETURN_AND_SET_ERRNO(status) \
	{ \
		if (status < 0) { \
			errno = status; \
			return -1; \
		} \
		return status; \
	}


int
fs_create_index(dev_t device, const char *name, uint32 type, uint32 flags)
{
@@ -72,15 +63,11 @@
		return NULL;
	}

	/* allocate the memory for the DIR structure */
	if ((dir = (DIR *)malloc(DIR_BUFFER_SIZE)) == NULL) {
		errno = B_NO_MEMORY;
	// allocate the DIR structure
	if ((dir = fdopendir(fd)) == NULL) {
		_kern_close(fd);
		return NULL;
	}

	dir->fd = fd;
	dir->entries_left = 0;

	return dir;
}
@@ -89,11 +76,7 @@
int
fs_close_index_dir(DIR *dir)
{
	int status = _kern_close(dir->fd);

	free(dir);

	RETURN_AND_SET_ERRNO(status);
	return closedir(dir);
}


diff --git a/src/system/libroot/os/fs_query.cpp b/src/system/libroot/os/fs_query.cpp
index b74f116..c9e5daa 100644
--- a/src/system/libroot/os/fs_query.cpp
+++ b/src/system/libroot/os/fs_query.cpp
@@ -6,13 +6,14 @@

#include <fs_query.h>

#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>

#include <dirent_private.h>
#include <syscalls.h>
#include <syscall_utils.h>


static DIR *
@@ -31,17 +32,13 @@
		return NULL;
	}

	// allocate a DIR
	DIR *dir = (DIR *)malloc(DIR_BUFFER_SIZE);
	if (!dir) {
	// allocate the DIR structure
	DIR *dir = fdopendir(fd);
	if (dir == NULL) {
		_kern_close(fd);
		errno = B_NO_MEMORY;
		return NULL;
	}

	dir->fd = fd;
	dir->entries_left = 0;

	return dir;
}

@@ -70,14 +67,7 @@
int
fs_close_query(DIR *dir)
{
	if (dir == NULL) {
		errno = B_BAD_VALUE;
		return -1;
	}

	int fd = dir->fd;
	free(dir);
	return _kern_close(fd);
	return closedir(dir);
}


diff --git a/src/system/libroot/posix/dirent.c b/src/system/libroot/posix/dirent.c
index cee73ff..5db1f26 100644
--- a/src/system/libroot/posix/dirent.c
+++ b/src/system/libroot/posix/dirent.c
@@ -6,15 +6,28 @@


#include <dirent.h>

#include <errno.h>
#include <limits.h>
#include <stdlib.h>

#include <dirent_private.h>
#include <syscalls.h>
#include <syscall_utils.h>


#define DIR_BUFFER_SIZE	4096


struct __DIR {
	int				fd;
	short			next_entry;
	unsigned short	entries_left;
	long			seek_position;
	long			current_position;
	struct dirent	first_entry;
};


static int
do_seek_dir(DIR* dir)
{
@@ -62,8 +75,8 @@
		dir->current_position += dir->entries_left;
		dir->entries_left = 0;

		count = _kern_read_dir(dir->fd, &dir->first_entry, DIRENT_BUFFER_SIZE,
			USHRT_MAX);
		count = _kern_read_dir(dir->fd, &dir->first_entry,
			(char*)dir + DIR_BUFFER_SIZE - (char*)&dir->first_entry, USHRT_MAX);
		if (count <= 0) {
			if (count < 0)
				errno = count;
@@ -83,21 +96,14 @@
// #pragma mark -


DIR *
opendir(const char *path)
DIR*
fdopendir(int fd)
{
	DIR *dir;

	int fd = _kern_open_dir(-1, path);
	if (fd < 0) {
		errno = fd;
		return NULL;
	}
	DIR* dir;

	/* allocate the memory for the DIR structure */
	if ((dir = (DIR *)malloc(DIR_BUFFER_SIZE)) == NULL) {
	if ((dir = (DIR*)malloc(DIR_BUFFER_SIZE)) == NULL) {
		errno = B_NO_MEMORY;
		_kern_close(fd);
		return NULL;
	}

@@ -105,15 +111,43 @@
	dir->entries_left = 0;
	dir->seek_position = 0;
	dir->current_position = 0;

	return dir;
}


DIR*
opendir(const char* path)
{
	DIR* dir;

	int fd = _kern_open_dir(-1, path);
	if (fd < 0) {
		errno = fd;
		return NULL;
	}

	// allocate the DIR structure
	if ((dir = fdopendir(fd)) == NULL) {
		_kern_close(fd);
		return NULL;
	}

	return dir;
}


int
closedir(DIR *dir)
closedir(DIR* dir)
{
	int status = _kern_close(dir->fd);
	int status;

	if (dir == NULL) {
		errno = B_BAD_VALUE;
		return -1;
	}

	status = _kern_close(dir->fd);

	free(dir);

@@ -121,8 +155,8 @@
}


struct dirent *
readdir(DIR *dir)
struct dirent*
readdir(DIR* dir)
{
	ssize_t count;

@@ -145,8 +179,8 @@

	// we need to retrieve new entries

	count = _kern_read_dir(dir->fd, &dir->first_entry, DIRENT_BUFFER_SIZE,
		USHRT_MAX);
	count = _kern_read_dir(dir->fd, &dir->first_entry,
		(char*)dir + DIR_BUFFER_SIZE - (char*)&dir->first_entry, USHRT_MAX);
	if (count <= 0) {
		if (count < 0)
			errno = count;
@@ -165,7 +199,7 @@


int
readdir_r(DIR *dir, struct dirent *entry, struct dirent **_result)
readdir_r(DIR* dir, struct dirent* entry, struct dirent** _result)
{
	ssize_t count = _kern_read_dir(dir->fd, entry, sizeof(struct dirent)
		+ B_FILE_NAME_LENGTH, 1);
@@ -183,7 +217,7 @@


void
rewinddir(DIR *dir)
rewinddir(DIR* dir)
{
	dir->seek_position = 0;
}
@@ -204,7 +238,7 @@


int
dirfd(const DIR *dir)
dirfd(const DIR* dir)
{
	return dir->fd;
}