2 * Copyright 2002-2011, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
9 #include <syscall_utils.h>
14 #include <dirent_private.h>
15 #include <errno_private.h>
17 #include <syscall_utils.h>
20 // TODO: think about adding special syscalls for the read/write/stat functions
25 open_attr_dir(int file
, const char *path
, bool traverse
)
29 int fd
= _kern_open_attr_dir(file
, path
, traverse
);
35 // allocate the DIR structure
36 if ((dir
= __create_dir_struct(fd
)) == NULL
) {
49 fs_read_attr(int fd
, const char* attribute
, uint32
/*type*/, off_t pos
,
50 void* buffer
, size_t readBytes
)
52 ssize_t bytes
= _kern_read_attr(fd
, attribute
, pos
, buffer
, readBytes
);
53 RETURN_AND_SET_ERRNO(bytes
);
58 fs_write_attr(int fd
, const char* attribute
, uint32 type
, off_t pos
,
59 const void* buffer
, size_t writeBytes
)
61 // TODO: move this documentation into the Haiku book!
63 // NOTE: This call is deprecated in Haiku and has a number of problems:
64 // On BeOS, it was documented that the "pos" argument is ignored, however,
65 // that did not actually happen if the attribute was backed up by a real
67 // Also, it will truncate any existing attribute, disregarding the specified
70 // The implementation of this function tries to stay compatible with
71 // BeOS in that it clobbers the existing attribute when you write at offset
72 // 0, but it also tries to support programs which continue to write more
74 // The new Haiku way is to use fs_open_attr() to get a regular file handle
75 // and use that for writing, then use fs_close_attr() when done. As you
76 // see from this implementation, it saves 2 syscalls per writing a chunk
79 ssize_t bytes
= _kern_write_attr(fd
, attribute
, type
, pos
, buffer
,
81 RETURN_AND_SET_ERRNO(bytes
);
86 fs_remove_attr(int fd
, const char* attribute
)
88 status_t status
= _kern_remove_attr(fd
, attribute
);
90 RETURN_AND_SET_ERRNO(status
);
95 fs_stat_attr(int fd
, const char* attribute
, struct attr_info
* attrInfo
)
97 status_t status
= _kern_stat_attr(fd
, attribute
, attrInfo
);
98 RETURN_AND_SET_ERRNO(status
);
103 fs_open_attr(const char *path
, const char *attribute
, uint32 type
, int openMode
)
105 status_t status
= _kern_open_attr(-1, path
, attribute
, type
, openMode
);
106 RETURN_AND_SET_ERRNO(status
);
111 fs_fopen_attr(int fd
, const char* attribute
, uint32 type
, int openMode
)
113 status_t status
= _kern_open_attr(fd
, NULL
, attribute
, type
, openMode
);
114 RETURN_AND_SET_ERRNO(status
);
119 fs_close_attr(int fd
)
121 status_t status
= _kern_close(fd
);
123 RETURN_AND_SET_ERRNO(status
);
128 fs_open_attr_dir(const char* path
)
130 return open_attr_dir(-1, path
, true);
135 fs_lopen_attr_dir(const char* path
)
137 return open_attr_dir(-1, path
, false);
141 fs_fopen_attr_dir(int fd
)
143 return open_attr_dir(fd
, NULL
, false);
148 fs_close_attr_dir(DIR* dir
)
150 return closedir(dir
);
154 extern "C" struct dirent
*
155 fs_read_attr_dir(DIR* dir
)
162 fs_rewind_attr_dir(DIR* dir
)