libroot_debug: Merge guarded heap into libroot_debug.
[haiku.git] / src / system / libroot / os / fs_query.cpp
blob3feac4462f28949a606a1d439b25608ba51d3edc
1 /*
2 * Copyright 2004-2008, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <fs_query.h>
9 #include <dirent.h>
10 #include <errno.h>
11 #include <fcntl.h>
12 #include <stdlib.h>
13 #include <string.h>
15 #include <dirent_private.h>
16 #include <errno_private.h>
17 #include <syscalls.h>
18 #include <syscall_utils.h>
21 static DIR *
22 open_query_etc(dev_t device, const char *query,
23 uint32 flags, port_id port, int32 token)
25 if (device < 0 || query == NULL || query[0] == '\0') {
26 __set_errno(B_BAD_VALUE);
27 return NULL;
30 // open
31 int fd = _kern_open_query(device, query, strlen(query), flags, port, token);
32 if (fd < 0) {
33 __set_errno(fd);
34 return NULL;
37 // allocate the DIR structure
38 DIR *dir = __create_dir_struct(fd);
39 if (dir == NULL) {
40 _kern_close(fd);
41 return NULL;
44 return dir;
48 DIR *
49 fs_open_query(dev_t device, const char *query, uint32 flags)
51 return open_query_etc(device, query, flags, -1, -1);
55 DIR *
56 fs_open_live_query(dev_t device, const char *query,
57 uint32 flags, port_id port, int32 token)
59 // check parameters
60 if (port < 0) {
61 __set_errno(B_BAD_VALUE);
62 return NULL;
65 return open_query_etc(device, query, flags | B_LIVE_QUERY, port, token);
69 int
70 fs_close_query(DIR *dir)
72 return closedir(dir);
76 struct dirent *
77 fs_read_query(DIR *dir)
79 return readdir(dir);
83 status_t
84 get_path_for_dirent(struct dirent *dent, char *buffer, size_t length)
86 if (dent == NULL || buffer == NULL)
87 return B_BAD_VALUE;
89 return _kern_entry_ref_to_path(dent->d_pdev, dent->d_pino, dent->d_name,
90 buffer, length);