19c5c79adSAxel Dörfler/*
29c5c79adSAxel Dörfler * Copyright 2002-2008, Axel D��rfler, axeld@pinc-software.de.
39c5c79adSAxel Dörfler * Distributed under the terms of the MIT License.
49c5c79adSAxel Dörfler */
564b00573SAxel Dörfler
664b00573SAxel Dörfler
764b00573SAxel Dörfler#include <fs_index.h>
864b00573SAxel Dörfler
9adbf8b25SIngo Weinhold#include <dirent.h>
1064b00573SAxel Dörfler#include <errno.h>
11adbf8b25SIngo Weinhold#include <fcntl.h>
12adbf8b25SIngo Weinhold#include <stdlib.h>
1364b00573SAxel Dörfler
149e81ddeeSIngo Weinhold#include <dirent_private.h>
15ae901935SOliver Tappe#include <errno_private.h>
169c5c79adSAxel Dörfler#include <syscalls.h>
17adbf8b25SIngo Weinhold#include <syscall_utils.h>
1864b00573SAxel Dörfler
1964b00573SAxel Dörfler
2064b00573SAxel Dörflerint
2164b00573SAxel Dörflerfs_create_index(dev_t device, const char *name, uint32 type, uint32 flags)
2264b00573SAxel Dörfler{
23b640ca78SAxel Dörfler	status_t status = _kern_create_index(device, name, type, flags);
2464b00573SAxel Dörfler
2564b00573SAxel Dörfler	RETURN_AND_SET_ERRNO(status);
2664b00573SAxel Dörfler}
2764b00573SAxel Dörfler
2864b00573SAxel Dörfler
299c5c79adSAxel Dörflerint
3064b00573SAxel Dörflerfs_remove_index(dev_t device, const char *name)
3164b00573SAxel Dörfler{
32b640ca78SAxel Dörfler	status_t status = _kern_remove_index(device, name);
3364b00573SAxel Dörfler
3464b00573SAxel Dörfler	RETURN_AND_SET_ERRNO(status);
3564b00573SAxel Dörfler}
3664b00573SAxel Dörfler
3764b00573SAxel Dörfler
389c5c79adSAxel Dörflerint
3964b00573SAxel Dörflerfs_stat_index(dev_t device, const char *name, struct index_info *indexInfo)
4064b00573SAxel Dörfler{
4164b00573SAxel Dörfler	struct stat stat;
4264b00573SAxel Dörfler
43b640ca78SAxel Dörfler	status_t status = _kern_read_index_stat(device, name, &stat);
4464b00573SAxel Dörfler	if (status == B_OK) {
4564b00573SAxel Dörfler		indexInfo->type = stat.st_type;
4664b00573SAxel Dörfler		indexInfo->size = stat.st_size;
4764b00573SAxel Dörfler		indexInfo->modification_time = stat.st_mtime;
4864b00573SAxel Dörfler		indexInfo->creation_time = stat.st_crtime;
4964b00573SAxel Dörfler		indexInfo->uid = stat.st_uid;
5064b00573SAxel Dörfler		indexInfo->gid = stat.st_gid;
5164b00573SAxel Dörfler	}
5264b00573SAxel Dörfler
5364b00573SAxel Dörfler	RETURN_AND_SET_ERRNO(status);
5464b00573SAxel Dörfler}
5564b00573SAxel Dörfler
5664b00573SAxel Dörfler
5764b00573SAxel DörflerDIR *
5864b00573SAxel Dörflerfs_open_index_dir(dev_t device)
5964b00573SAxel Dörfler{
6064b00573SAxel Dörfler	DIR *dir;
6164b00573SAxel Dörfler
62b640ca78SAxel Dörfler	int fd = _kern_open_index_dir(device);
6364b00573SAxel Dörfler	if (fd < 0) {
64ae901935SOliver Tappe		__set_errno(fd);
6564b00573SAxel Dörfler		return NULL;
6664b00573SAxel Dörfler	}
6764b00573SAxel Dörfler
68adbf8b25SIngo Weinhold	// allocate the DIR structure
699e81ddeeSIngo Weinhold	if ((dir = __create_dir_struct(fd)) == NULL) {
70b640ca78SAxel Dörfler		_kern_close(fd);
7164b00573SAxel Dörfler		return NULL;
7264b00573SAxel Dörfler	}
7364b00573SAxel Dörfler
7464b00573SAxel Dörfler	return dir;
7564b00573SAxel Dörfler}
7664b00573SAxel Dörfler
7764b00573SAxel Dörfler
789c5c79adSAxel Dörflerint
7964b00573SAxel Dörflerfs_close_index_dir(DIR *dir)
8064b00573SAxel Dörfler{
81adbf8b25SIngo Weinhold	return closedir(dir);
8264b00573SAxel Dörfler}
8364b00573SAxel Dörfler
8464b00573SAxel Dörfler
8564b00573SAxel Dörflerstruct dirent *
8664b00573SAxel Dörflerfs_read_index_dir(DIR *dir)
8764b00573SAxel Dörfler{
889c5c79adSAxel Dörfler	return readdir(dir);
8964b00573SAxel Dörfler}
9064b00573SAxel Dörfler
9164b00573SAxel Dörfler
929c5c79adSAxel Dörflervoid
9364b00573SAxel Dörflerfs_rewind_index_dir(DIR *dir)
9464b00573SAxel Dörfler{
959c5c79adSAxel Dörfler	rewinddir(dir);
9664b00573SAxel Dörfler}
9764b00573SAxel Dörfler
98