1/*
2 * Copyright 2002-2020, 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		// __create_dir_struct() already sets errno
71		_kern_close(fd);
72		return NULL;
73	}
74
75	return dir;
76}
77
78
79int
80fs_close_index_dir(DIR *dir)
81{
82	return closedir(dir);
83}
84
85
86struct dirent *
87fs_read_index_dir(DIR *dir)
88{
89	return readdir(dir);
90}
91
92
93void
94fs_rewind_index_dir(DIR *dir)
95{
96	rewinddir(dir);
97}
98
99