1/*
2 * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include <fs_index.h>
8
9#include <dirent.h>
10#include <errno.h>
11#include <fcntl.h>
12#include <stdlib.h>
13
14#include <dirent_private.h>
15#include <errno_private.h>
16#include <syscalls.h>
17#include <syscall_utils.h>
18
19
20int
21fs_create_index(dev_t device, const char *name, uint32 type, uint32 flags)
22{
23	status_t status = _kern_create_index(device, name, type, flags);
24
25	RETURN_AND_SET_ERRNO(status);
26}
27
28
29int
30fs_remove_index(dev_t device, const char *name)
31{
32	status_t status = _kern_remove_index(device, name);
33
34	RETURN_AND_SET_ERRNO(status);
35}
36
37
38int
39fs_stat_index(dev_t device, const char *name, struct index_info *indexInfo)
40{
41	struct stat stat;
42
43	status_t status = _kern_read_index_stat(device, name, &stat);
44	if (status == B_OK) {
45		indexInfo->type = stat.st_type;
46		indexInfo->size = stat.st_size;
47		indexInfo->modification_time = stat.st_mtime;
48		indexInfo->creation_time = stat.st_crtime;
49		indexInfo->uid = stat.st_uid;
50		indexInfo->gid = stat.st_gid;
51	}
52
53	RETURN_AND_SET_ERRNO(status);
54}
55
56
57DIR *
58fs_open_index_dir(dev_t device)
59{
60	DIR *dir;
61
62	int fd = _kern_open_index_dir(device);
63	if (fd < 0) {
64		__set_errno(fd);
65		return NULL;
66	}
67
68	// allocate the DIR structure
69	if ((dir = __create_dir_struct(fd)) == NULL) {
70		_kern_close(fd);
71		return NULL;
72	}
73
74	return dir;
75}
76
77
78int
79fs_close_index_dir(DIR *dir)
80{
81	return closedir(dir);
82}
83
84
85struct dirent *
86fs_read_index_dir(DIR *dir)
87{
88	return readdir(dir);
89}
90
91
92void
93fs_rewind_index_dir(DIR *dir)
94{
95	rewinddir(dir);
96}
97
98