1// This module contains bindings to the native Haiku API. The Haiku API
2// originates from BeOS, and it was the original way to perform low level
3// system and IO operations. The POSIX API was in that era was like a
4// compatibility layer. In current Haiku development, both the POSIX API and
5// the Haiku API are considered to be co-equal status. However, they are not
6// integrated like they are on other UNIX platforms, which means that for many
7// low level concepts there are two versions, like processes (POSIX) and
8// teams (Haiku), or pthreads and native threads.
9//
10// Both the POSIX API and the Haiku API live in libroot.so, the library that is
11// linked to any binary by default.
12//
13// This file follows the Haiku API for Haiku R1 beta 2. It is organized by the
14// C/C++ header files in which the concepts can be found, while adhering to the
15// style guide for this crate.
16
17// Helper macro to generate u32 constants. The Haiku API uses (non-standard)
18// multi-character constants (like 'UPDA' or 'MSGM') to represent 32 bit
19// integer constants.
20
21macro_rules! haiku_constant {
22    ($a:tt, $b:tt, $c:tt, $d:tt) => {
23        (($a as u32) << 24) + (($b as u32) << 16) + (($c as u32) << 8) + ($d as u32)
24    };
25}
26
27// support/SupportDefs.h
28pub type status_t = i32;
29pub type bigtime_t = i64;
30pub type nanotime_t = i64;
31pub type type_code = u32;
32pub type perform_code = u32;
33
34// kernel/OS.h
35pub type area_id = i32;
36pub type port_id = i32;
37pub type sem_id = i32;
38pub type team_id = i32;
39pub type thread_id = i32;
40
41pub type thread_func = extern "C" fn(*mut ::c_void) -> status_t;
42
43// kernel/image.h
44pub type image_id = i32;
45
46e! {
47    // kernel/OS.h
48    pub enum thread_state {
49        B_THREAD_RUNNING = 1,
50        B_THREAD_READY,
51        B_THREAD_RECEIVING,
52        B_THREAD_ASLEEP,
53        B_THREAD_SUSPENDED,
54        B_THREAD_WAITING
55    }
56
57    // kernel/image.h
58    pub enum image_type {
59        B_APP_IMAGE = 1,
60        B_LIBRARY_IMAGE,
61        B_ADD_ON_IMAGE,
62        B_SYSTEM_IMAGE
63    }
64
65    // kernel/scheduler.h
66
67    pub enum be_task_flags {
68        B_DEFAULT_MEDIA_PRIORITY = 0x000,
69        B_OFFLINE_PROCESSING = 0x001,
70        B_STATUS_RENDERING = 0x002,
71        B_USER_INPUT_HANDLING = 0x004,
72        B_LIVE_VIDEO_MANIPULATION = 0x008,
73        B_VIDEO_PLAYBACK = 0x010,
74        B_VIDEO_RECORDING = 0x020,
75        B_LIVE_AUDIO_MANIPULATION = 0x040,
76        B_AUDIO_PLAYBACK = 0x080,
77        B_AUDIO_RECORDING = 0x100,
78        B_LIVE_3D_RENDERING = 0x200,
79        B_NUMBER_CRUNCHING = 0x400,
80        B_MIDI_PROCESSING = 0x800,
81    }
82
83    pub enum schduler_mode {
84        SCHEDULER_MODE_LOW_LATENCY,
85        SCHEDULER_MODE_POWER_SAVING,
86    }
87
88    // FindDirectory.h
89    pub enum path_base_directory {
90        B_FIND_PATH_INSTALLATION_LOCATION_DIRECTORY,
91        B_FIND_PATH_ADD_ONS_DIRECTORY,
92        B_FIND_PATH_APPS_DIRECTORY,
93        B_FIND_PATH_BIN_DIRECTORY,
94        B_FIND_PATH_BOOT_DIRECTORY,
95        B_FIND_PATH_CACHE_DIRECTORY,
96        B_FIND_PATH_DATA_DIRECTORY,
97        B_FIND_PATH_DEVELOP_DIRECTORY,
98        B_FIND_PATH_DEVELOP_LIB_DIRECTORY,
99        B_FIND_PATH_DOCUMENTATION_DIRECTORY,
100        B_FIND_PATH_ETC_DIRECTORY,
101        B_FIND_PATH_FONTS_DIRECTORY,
102        B_FIND_PATH_HEADERS_DIRECTORY,
103        B_FIND_PATH_LIB_DIRECTORY,
104        B_FIND_PATH_LOG_DIRECTORY,
105        B_FIND_PATH_MEDIA_NODES_DIRECTORY,
106        B_FIND_PATH_PACKAGES_DIRECTORY,
107        B_FIND_PATH_PREFERENCES_DIRECTORY,
108        B_FIND_PATH_SERVERS_DIRECTORY,
109        B_FIND_PATH_SETTINGS_DIRECTORY,
110        B_FIND_PATH_SOUNDS_DIRECTORY,
111        B_FIND_PATH_SPOOL_DIRECTORY,
112        B_FIND_PATH_TRANSLATORS_DIRECTORY,
113        B_FIND_PATH_VAR_DIRECTORY,
114        B_FIND_PATH_IMAGE_PATH = 1000,
115        B_FIND_PATH_PACKAGE_PATH,
116    }
117
118    pub enum directory_which {
119        B_DESKTOP_DIRECTORY = 0,
120        B_TRASH_DIRECTORY,
121        B_SYSTEM_DIRECTORY = 1000,
122        B_SYSTEM_ADDONS_DIRECTORY = 1002,
123        B_SYSTEM_BOOT_DIRECTORY,
124        B_SYSTEM_FONTS_DIRECTORY,
125        B_SYSTEM_LIB_DIRECTORY,
126        B_SYSTEM_SERVERS_DIRECTORY,
127        B_SYSTEM_APPS_DIRECTORY,
128        B_SYSTEM_BIN_DIRECTORY,
129        B_SYSTEM_DOCUMENTATION_DIRECTORY = 1010,
130        B_SYSTEM_PREFERENCES_DIRECTORY,
131        B_SYSTEM_TRANSLATORS_DIRECTORY,
132        B_SYSTEM_MEDIA_NODES_DIRECTORY,
133        B_SYSTEM_SOUNDS_DIRECTORY,
134        B_SYSTEM_DATA_DIRECTORY,
135        B_SYSTEM_DEVELOP_DIRECTORY,
136        B_SYSTEM_PACKAGES_DIRECTORY,
137        B_SYSTEM_HEADERS_DIRECTORY,
138        B_SYSTEM_ETC_DIRECTORY = 2008,
139        B_SYSTEM_SETTINGS_DIRECTORY = 2010,
140        B_SYSTEM_LOG_DIRECTORY = 2012,
141        B_SYSTEM_SPOOL_DIRECTORY,
142        B_SYSTEM_TEMP_DIRECTORY,
143        B_SYSTEM_VAR_DIRECTORY,
144        B_SYSTEM_CACHE_DIRECTORY = 2020,
145        B_SYSTEM_NONPACKAGED_DIRECTORY = 2023,
146        B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY,
147        B_SYSTEM_NONPACKAGED_TRANSLATORS_DIRECTORY,
148        B_SYSTEM_NONPACKAGED_MEDIA_NODES_DIRECTORY,
149        B_SYSTEM_NONPACKAGED_BIN_DIRECTORY,
150        B_SYSTEM_NONPACKAGED_DATA_DIRECTORY,
151        B_SYSTEM_NONPACKAGED_FONTS_DIRECTORY,
152        B_SYSTEM_NONPACKAGED_SOUNDS_DIRECTORY,
153        B_SYSTEM_NONPACKAGED_DOCUMENTATION_DIRECTORY,
154        B_SYSTEM_NONPACKAGED_LIB_DIRECTORY,
155        B_SYSTEM_NONPACKAGED_HEADERS_DIRECTORY,
156        B_SYSTEM_NONPACKAGED_DEVELOP_DIRECTORY,
157        B_USER_DIRECTORY = 3000,
158        B_USER_CONFIG_DIRECTORY,
159        B_USER_ADDONS_DIRECTORY,
160        B_USER_BOOT_DIRECTORY,
161        B_USER_FONTS_DIRECTORY,
162        B_USER_LIB_DIRECTORY,
163        B_USER_SETTINGS_DIRECTORY,
164        B_USER_DESKBAR_DIRECTORY,
165        B_USER_PRINTERS_DIRECTORY,
166        B_USER_TRANSLATORS_DIRECTORY,
167        B_USER_MEDIA_NODES_DIRECTORY,
168        B_USER_SOUNDS_DIRECTORY,
169        B_USER_DATA_DIRECTORY,
170        B_USER_CACHE_DIRECTORY,
171        B_USER_PACKAGES_DIRECTORY,
172        B_USER_HEADERS_DIRECTORY,
173        B_USER_NONPACKAGED_DIRECTORY,
174        B_USER_NONPACKAGED_ADDONS_DIRECTORY,
175        B_USER_NONPACKAGED_TRANSLATORS_DIRECTORY,
176        B_USER_NONPACKAGED_MEDIA_NODES_DIRECTORY,
177        B_USER_NONPACKAGED_BIN_DIRECTORY,
178        B_USER_NONPACKAGED_DATA_DIRECTORY,
179        B_USER_NONPACKAGED_FONTS_DIRECTORY,
180        B_USER_NONPACKAGED_SOUNDS_DIRECTORY,
181        B_USER_NONPACKAGED_DOCUMENTATION_DIRECTORY,
182        B_USER_NONPACKAGED_LIB_DIRECTORY,
183        B_USER_NONPACKAGED_HEADERS_DIRECTORY,
184        B_USER_NONPACKAGED_DEVELOP_DIRECTORY,
185        B_USER_DEVELOP_DIRECTORY,
186        B_USER_DOCUMENTATION_DIRECTORY,
187        B_USER_SERVERS_DIRECTORY,
188        B_USER_APPS_DIRECTORY,
189        B_USER_BIN_DIRECTORY,
190        B_USER_PREFERENCES_DIRECTORY,
191        B_USER_ETC_DIRECTORY,
192        B_USER_LOG_DIRECTORY,
193        B_USER_SPOOL_DIRECTORY,
194        B_USER_VAR_DIRECTORY,
195        B_APPS_DIRECTORY = 4000,
196        B_PREFERENCES_DIRECTORY,
197        B_UTILITIES_DIRECTORY,
198        B_PACKAGE_LINKS_DIRECTORY,
199    }
200}
201
202s! {
203    // kernel/OS.h
204    pub struct area_info {
205        pub area: area_id,
206        pub name: [::c_char; B_OS_NAME_LENGTH],
207        pub size: usize,
208        pub lock: u32,
209        pub protection: u32,
210        pub team: team_id,
211        pub ram_size: u32,
212        pub copy_count: u32,
213        pub in_count: u32,
214        pub out_count: u32,
215        pub address: *mut ::c_void
216    }
217
218    pub struct port_info {
219        pub port: port_id,
220        pub team: team_id,
221        pub name: [::c_char; B_OS_NAME_LENGTH],
222        pub capacity: i32,
223        pub queue_count: i32,
224        pub total_count: i32,
225    }
226
227    pub struct port_message_info {
228        pub size: ::size_t,
229        pub sender: ::uid_t,
230        pub sender_group: ::gid_t,
231        pub sender_team: ::team_id
232    }
233
234    pub struct team_info {
235        pub team: team_id,
236        pub thread_count: i32,
237        pub image_count: i32,
238        pub area_count: i32,
239        pub debugger_nub_thread: thread_id,
240        pub debugger_nub_port: port_id,
241        pub argc: i32,
242        pub args: [::c_char; 64],
243        pub uid: ::uid_t,
244        pub gid: ::gid_t
245    }
246
247    pub struct sem_info {
248        pub sem: sem_id,
249        pub team: team_id,
250        pub name: [::c_char; B_OS_NAME_LENGTH],
251        pub count: i32,
252        pub latest_holder: thread_id
253    }
254
255    pub struct team_usage_info {
256        pub user_time: bigtime_t,
257        pub kernel_time: bigtime_t
258    }
259
260    pub struct thread_info {
261        pub thread: thread_id,
262        pub team: team_id,
263        pub name: [::c_char; B_OS_NAME_LENGTH],
264        pub state: thread_state,
265        pub priority: i32,
266        pub sem: sem_id,
267        pub user_time: bigtime_t,
268        pub kernel_time: bigtime_t,
269        pub stack_base: *mut ::c_void,
270        pub stack_end: *mut ::c_void
271    }
272
273    pub struct cpu_info {
274        pub active_time: bigtime_t,
275        pub enabled: bool,
276        pub current_frequency: u64
277    }
278
279    pub struct system_info {
280        pub boot_time: bigtime_t,
281        pub cpu_count: u32,
282        pub max_pages: u64,
283        pub used_pages: u64,
284        pub cached_pages: u64,
285        pub block_cache_pages: u64,
286        pub ignored_pages: u64,
287        pub needed_memory: u64,
288        pub free_memory: u64,
289        pub max_swap_pages: u64,
290        pub free_swap_pages: u64,
291        pub page_faults: u32,
292        pub max_sems: u32,
293        pub used_sems: u32,
294        pub max_ports: u32,
295        pub used_ports: u32,
296        pub max_threads: u32,
297        pub used_threads: u32,
298        pub max_teams: u32,
299        pub used_teams: u32,
300        pub kernel_name: [::c_char; B_FILE_NAME_LENGTH],
301        pub kernel_build_date: [::c_char; B_OS_NAME_LENGTH],
302        pub kernel_build_time: [::c_char; B_OS_NAME_LENGTH],
303        pub kernel_version: i64,
304        pub abi: u32
305    }
306
307    pub struct object_wait_info {
308        pub object: i32,
309        pub type_: u16,
310        pub events: u16
311    }
312
313    // kernel/fs_attr.h
314    pub struct attr_info {
315        pub type_: u32,
316        pub size: ::off_t
317    }
318
319    // kernel/fs_index.h
320    pub struct index_info {
321        pub type_: u32,
322        pub size: ::off_t,
323        pub modification_time: ::time_t,
324        pub creation_time: ::time_t,
325        pub uid: ::uid_t,
326        pub gid: ::gid_t
327    }
328
329    //kernel/fs_info.h
330    pub struct fs_info {
331        pub dev: ::dev_t,
332        pub root: ::ino_t,
333        pub flags: u32,
334        pub block_size: ::off_t,
335        pub io_size: ::off_t,
336        pub total_blocks: ::off_t,
337        pub free_blocks: ::off_t,
338        pub total_nodes: ::off_t,
339        pub free_nodes: ::off_t,
340        pub device_name: [::c_char; 128],
341        pub volume_name: [::c_char; B_FILE_NAME_LENGTH],
342        pub fsh_name: [::c_char; B_OS_NAME_LENGTH]
343    }
344
345    // kernel/image.h
346    pub struct image_info {
347        pub id: image_id,
348        pub image_type: ::c_int,
349        pub sequence: i32,
350        pub init_order: i32,
351        pub init_routine: extern "C" fn(),
352        pub term_routine: extern "C" fn(),
353        pub device: ::dev_t,
354        pub node: ::ino_t,
355        pub name: [::c_char; ::PATH_MAX as usize],
356        pub text: *mut ::c_void,
357        pub data: *mut ::c_void,
358        pub text_size: i32,
359        pub data_size: i32,
360        pub api_version: i32,
361        pub abi: i32
362    }
363
364    pub struct __c_anonymous_eax_0 {
365        pub max_eax: u32,
366        pub vendor_id: [::c_char; 12],
367    }
368
369    pub struct __c_anonymous_eax_1 {
370        pub stepping: u32,
371        pub model: u32,
372        pub family: u32,
373        pub tpe: u32,
374        __reserved_0: u32,
375        pub extended_model: u32,
376        pub extended_family: u32,
377        __reserved_1: u32,
378        pub brand_index: u32,
379        pub clflush: u32,
380        pub logical_cpus: u32,
381        pub apic_id: u32,
382        pub features: u32,
383        pub extended_features: u32,
384    }
385
386    pub struct __c_anonymous_eax_2 {
387        pub call_num: u8,
388        pub cache_descriptors: [u8; 15],
389    }
390
391    pub struct __c_anonymous_eax_3 {
392        __reserved: [u32; 2],
393        pub serial_number_high: u32,
394        pub serial_number_low: u32,
395    }
396
397    pub struct __c_anonymous_regs {
398        pub eax: u32,
399        pub ebx: u32,
400        pub edx: u32,
401        pub ecx: u32,
402    }
403}
404
405s_no_extra_traits! {
406    #[cfg(libc_union)]
407    pub union cpuid_info {
408        pub eax_0: __c_anonymous_eax_0,
409        pub eax_1: __c_anonymous_eax_1,
410        pub eax_2: __c_anonymous_eax_2,
411        pub eax_3: __c_anonymous_eax_3,
412        pub as_chars: [::c_char; 16],
413        pub regs: __c_anonymous_regs,
414    }
415}
416
417cfg_if! {
418    if #[cfg(feature = "extra_traits")] {
419        #[cfg(libc_union)]
420        impl PartialEq for cpuid_info {
421            fn eq(&self, other: &cpuid_info) -> bool {
422                unsafe {
423                self.eax_0 == other.eax_0
424                    || self.eax_1 == other.eax_1
425                    || self.eax_2 == other.eax_2
426                    || self.eax_3 == other.eax_3
427                    || self.as_chars == other.as_chars
428                    || self.regs == other.regs
429                }
430            }
431        }
432        #[cfg(libc_union)]
433        impl Eq for cpuid_info {}
434        #[cfg(libc_union)]
435        impl ::fmt::Debug for cpuid_info {
436            fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
437                unsafe {
438                f.debug_struct("cpuid_info")
439                    .field("eax_0", &self.eax_0)
440                    .field("eax_1", &self.eax_1)
441                    .field("eax_2", &self.eax_2)
442                    .field("eax_3", &self.eax_3)
443                    .field("as_chars", &self.as_chars)
444                    .field("regs", &self.regs)
445                    .finish()
446                }
447            }
448        }
449    }
450}
451
452// kernel/OS.h
453pub const B_OS_NAME_LENGTH: usize = 32;
454pub const B_PAGE_SIZE: usize = 4096;
455pub const B_INFINITE_TIMEOUT: usize = 9223372036854775807;
456
457pub const B_RELATIVE_TIMEOUT: u32 = 0x8;
458pub const B_ABSOLUTE_TIMEOUT: u32 = 0x10;
459pub const B_TIMEOUT_REAL_TIME_BASE: u32 = 0x40;
460pub const B_ABSOLUTE_REAL_TIME_TIMEOUT: u32 = B_ABSOLUTE_TIMEOUT | B_TIMEOUT_REAL_TIME_BASE;
461
462pub const B_NO_LOCK: u32 = 0;
463pub const B_LAZY_LOCK: u32 = 1;
464pub const B_FULL_LOCK: u32 = 2;
465pub const B_CONTIGUOUS: u32 = 3;
466pub const B_LOMEM: u32 = 4;
467pub const B_32_BIT_FULL_LOCK: u32 = 5;
468pub const B_32_BIT_CONTIGUOUS: u32 = 6;
469
470pub const B_ANY_ADDRESS: u32 = 0;
471pub const B_EXACT_ADDRESS: u32 = 1;
472pub const B_BASE_ADDRESS: u32 = 2;
473pub const B_CLONE_ADDRESS: u32 = 3;
474pub const B_ANY_KERNEL_ADDRESS: u32 = 4;
475pub const B_RANDOMIZED_ANY_ADDRESS: u32 = 6;
476pub const B_RANDOMIZED_BASE_ADDRESS: u32 = 7;
477
478pub const B_READ_AREA: u32 = 1 << 0;
479pub const B_WRITE_AREA: u32 = 1 << 1;
480pub const B_EXECUTE_AREA: u32 = 1 << 2;
481pub const B_STACK_AREA: u32 = 1 << 3;
482pub const B_CLONEABLE_AREA: u32 = 1 << 8;
483
484pub const B_CAN_INTERRUPT: u32 = 0x01;
485pub const B_CHECK_PERMISSION: u32 = 0x04;
486pub const B_KILL_CAN_INTERRUPT: u32 = 0x20;
487pub const B_DO_NOT_RESCHEDULE: u32 = 0x02;
488pub const B_RELEASE_ALL: u32 = 0x08;
489pub const B_RELEASE_IF_WAITING_ONLY: u32 = 0x10;
490
491pub const B_CURRENT_TEAM: team_id = 0;
492pub const B_SYSTEM_TEAM: team_id = 1;
493
494pub const B_TEAM_USAGE_SELF: i32 = 0;
495pub const B_TEAM_USAGE_CHILDREN: i32 = -1;
496
497pub const B_IDLE_PRIORITY: i32 = 0;
498pub const B_LOWEST_ACTIVE_PRIORITY: i32 = 1;
499pub const B_LOW_PRIORITY: i32 = 5;
500pub const B_NORMAL_PRIORITY: i32 = 10;
501pub const B_DISPLAY_PRIORITY: i32 = 15;
502pub const B_URGENT_DISPLAY_PRIORITY: i32 = 20;
503pub const B_REAL_TIME_DISPLAY_PRIORITY: i32 = 100;
504pub const B_URGENT_PRIORITY: i32 = 110;
505pub const B_REAL_TIME_PRIORITY: i32 = 120;
506
507pub const B_SYSTEM_TIMEBASE: i32 = 0;
508pub const B_FIRST_REAL_TIME_PRIORITY: i32 = B_REAL_TIME_DISPLAY_PRIORITY;
509
510pub const B_ONE_SHOT_ABSOLUTE_ALARM: u32 = 1;
511pub const B_ONE_SHOT_RELATIVE_ALARM: u32 = 2;
512pub const B_PERIODIC_ALARM: u32 = 3;
513
514pub const B_OBJECT_TYPE_FD: u16 = 0;
515pub const B_OBJECT_TYPE_SEMAPHORE: u16 = 1;
516pub const B_OBJECT_TYPE_PORT: u16 = 2;
517pub const B_OBJECT_TYPE_THREAD: u16 = 3;
518
519pub const B_EVENT_READ: u16 = 0x0001;
520pub const B_EVENT_WRITE: u16 = 0x0002;
521pub const B_EVENT_ERROR: u16 = 0x0004;
522pub const B_EVENT_PRIORITY_READ: u16 = 0x0008;
523pub const B_EVENT_PRIORITY_WRITE: u16 = 0x0010;
524pub const B_EVENT_HIGH_PRIORITY_READ: u16 = 0x0020;
525pub const B_EVENT_HIGH_PRIORITY_WRITE: u16 = 0x0040;
526pub const B_EVENT_DISCONNECTED: u16 = 0x0080;
527pub const B_EVENT_ACQUIRE_SEMAPHORE: u16 = 0x0001;
528pub const B_EVENT_INVALID: u16 = 0x1000;
529
530// kernel/fs_info.h
531pub const B_FS_IS_READONLY: u32 = 0x00000001;
532pub const B_FS_IS_REMOVABLE: u32 = 0x00000002;
533pub const B_FS_IS_PERSISTENT: u32 = 0x00000004;
534pub const B_FS_IS_SHARED: u32 = 0x00000008;
535pub const B_FS_HAS_MIME: u32 = 0x00010000;
536pub const B_FS_HAS_ATTR: u32 = 0x00020000;
537pub const B_FS_HAS_QUERY: u32 = 0x00040000;
538pub const B_FS_HAS_SELF_HEALING_LINKS: u32 = 0x00080000;
539pub const B_FS_HAS_ALIASES: u32 = 0x00100000;
540pub const B_FS_SUPPORTS_NODE_MONITORING: u32 = 0x00200000;
541pub const B_FS_SUPPORTS_MONITOR_CHILDREN: u32 = 0x00400000;
542
543// kernel/fs_query.h
544pub const B_LIVE_QUERY: u32 = 0x00000001;
545pub const B_QUERY_NON_INDEXED: u32 = 0x00000002;
546
547// kernel/fs_volume.h
548pub const B_MOUNT_READ_ONLY: u32 = 1;
549pub const B_MOUNT_VIRTUAL_DEVICE: u32 = 2;
550pub const B_FORCE_UNMOUNT: u32 = 1;
551
552// kernel/image.h
553pub const B_FLUSH_DCACHE: u32 = 0x0001;
554pub const B_FLUSH_ICACHE: u32 = 0x0004;
555pub const B_INVALIDATE_DCACHE: u32 = 0x0002;
556pub const B_INVALIDATE_ICACHE: u32 = 0x0008;
557
558pub const B_SYMBOL_TYPE_DATA: i32 = 0x1;
559pub const B_SYMBOL_TYPE_TEXT: i32 = 0x2;
560pub const B_SYMBOL_TYPE_ANY: i32 = 0x5;
561
562// storage/StorageDefs.h
563pub const B_DEV_NAME_LENGTH: usize = 128;
564pub const B_FILE_NAME_LENGTH: usize = ::FILENAME_MAX as usize;
565pub const B_PATH_NAME_LENGTH: usize = ::PATH_MAX as usize;
566pub const B_ATTR_NAME_LENGTH: usize = B_FILE_NAME_LENGTH - 1;
567pub const B_MIME_TYPE_LENGTH: usize = B_ATTR_NAME_LENGTH - 15;
568pub const B_MAX_SYMLINKS: usize = 16;
569
570// Haiku open modes in BFile are passed as u32
571pub const B_READ_ONLY: u32 = ::O_RDONLY as u32;
572pub const B_WRITE_ONLY: u32 = ::O_WRONLY as u32;
573pub const B_READ_WRITE: u32 = ::O_RDWR as u32;
574
575pub const B_FAIL_IF_EXISTS: u32 = ::O_EXCL as u32;
576pub const B_CREATE_FILE: u32 = ::O_CREAT as u32;
577pub const B_ERASE_FILE: u32 = ::O_TRUNC as u32;
578pub const B_OPEN_AT_END: u32 = ::O_APPEND as u32;
579
580pub const B_FILE_NODE: u32 = 0x01;
581pub const B_SYMLINK_NODE: u32 = 0x02;
582pub const B_DIRECTORY_NODE: u32 = 0x04;
583pub const B_ANY_NODE: u32 = 0x07;
584
585// support/Errors.h
586pub const B_GENERAL_ERROR_BASE: status_t = core::i32::MIN;
587pub const B_OS_ERROR_BASE: status_t = B_GENERAL_ERROR_BASE + 0x1000;
588pub const B_APP_ERROR_BASE: status_t = B_GENERAL_ERROR_BASE + 0x2000;
589pub const B_INTERFACE_ERROR_BASE: status_t = B_GENERAL_ERROR_BASE + 0x3000;
590pub const B_MEDIA_ERROR_BASE: status_t = B_GENERAL_ERROR_BASE + 0x4000;
591pub const B_TRANSLATION_ERROR_BASE: status_t = B_GENERAL_ERROR_BASE + 0x4800;
592pub const B_MIDI_ERROR_BASE: status_t = B_GENERAL_ERROR_BASE + 0x5000;
593pub const B_STORAGE_ERROR_BASE: status_t = B_GENERAL_ERROR_BASE + 0x6000;
594pub const B_POSIX_ERROR_BASE: status_t = B_GENERAL_ERROR_BASE + 0x7000;
595pub const B_MAIL_ERROR_BASE: status_t = B_GENERAL_ERROR_BASE + 0x8000;
596pub const B_PRINT_ERROR_BASE: status_t = B_GENERAL_ERROR_BASE + 0x9000;
597pub const B_DEVICE_ERROR_BASE: status_t = B_GENERAL_ERROR_BASE + 0xa000;
598pub const B_ERRORS_END: status_t = B_GENERAL_ERROR_BASE + 0xffff;
599
600// General errors
601pub const B_NO_MEMORY: status_t = B_GENERAL_ERROR_BASE + 0;
602pub const B_IO_ERROR: status_t = B_GENERAL_ERROR_BASE + 1;
603pub const B_PERMISSION_DENIED: status_t = B_GENERAL_ERROR_BASE + 2;
604pub const B_BAD_INDEX: status_t = B_GENERAL_ERROR_BASE + 3;
605pub const B_BAD_TYPE: status_t = B_GENERAL_ERROR_BASE + 4;
606pub const B_BAD_VALUE: status_t = B_GENERAL_ERROR_BASE + 5;
607pub const B_MISMATCHED_VALUES: status_t = B_GENERAL_ERROR_BASE + 6;
608pub const B_NAME_NOT_FOUND: status_t = B_GENERAL_ERROR_BASE + 7;
609pub const B_NAME_IN_USE: status_t = B_GENERAL_ERROR_BASE + 8;
610pub const B_TIMED_OUT: status_t = B_GENERAL_ERROR_BASE + 9;
611pub const B_INTERRUPTED: status_t = B_GENERAL_ERROR_BASE + 10;
612pub const B_WOULD_BLOCK: status_t = B_GENERAL_ERROR_BASE + 11;
613pub const B_CANCELED: status_t = B_GENERAL_ERROR_BASE + 12;
614pub const B_NO_INIT: status_t = B_GENERAL_ERROR_BASE + 13;
615pub const B_NOT_INITIALIZED: status_t = B_GENERAL_ERROR_BASE + 13;
616pub const B_BUSY: status_t = B_GENERAL_ERROR_BASE + 14;
617pub const B_NOT_ALLOWED: status_t = B_GENERAL_ERROR_BASE + 15;
618pub const B_BAD_DATA: status_t = B_GENERAL_ERROR_BASE + 16;
619pub const B_DONT_DO_THAT: status_t = B_GENERAL_ERROR_BASE + 17;
620
621pub const B_ERROR: status_t = -1;
622pub const B_OK: status_t = 0;
623pub const B_NO_ERROR: status_t = 0;
624
625// Kernel kit errors
626pub const B_BAD_SEM_ID: status_t = B_OS_ERROR_BASE + 0;
627pub const B_NO_MORE_SEMS: status_t = B_OS_ERROR_BASE + 1;
628
629pub const B_BAD_THREAD_ID: status_t = B_OS_ERROR_BASE + 0x100;
630pub const B_NO_MORE_THREADS: status_t = B_OS_ERROR_BASE + 0x101;
631pub const B_BAD_THREAD_STATE: status_t = B_OS_ERROR_BASE + 0x102;
632pub const B_BAD_TEAM_ID: status_t = B_OS_ERROR_BASE + 0x103;
633pub const B_NO_MORE_TEAMS: status_t = B_OS_ERROR_BASE + 0x104;
634
635pub const B_BAD_PORT_ID: status_t = B_OS_ERROR_BASE + 0x200;
636pub const B_NO_MORE_PORTS: status_t = B_OS_ERROR_BASE + 0x201;
637
638pub const B_BAD_IMAGE_ID: status_t = B_OS_ERROR_BASE + 0x300;
639pub const B_BAD_ADDRESS: status_t = B_OS_ERROR_BASE + 0x301;
640pub const B_NOT_AN_EXECUTABLE: status_t = B_OS_ERROR_BASE + 0x302;
641pub const B_MISSING_LIBRARY: status_t = B_OS_ERROR_BASE + 0x303;
642pub const B_MISSING_SYMBOL: status_t = B_OS_ERROR_BASE + 0x304;
643pub const B_UNKNOWN_EXECUTABLE: status_t = B_OS_ERROR_BASE + 0x305;
644pub const B_LEGACY_EXECUTABLE: status_t = B_OS_ERROR_BASE + 0x306;
645
646pub const B_DEBUGGER_ALREADY_INSTALLED: status_t = B_OS_ERROR_BASE + 0x400;
647
648// Application kit errors
649pub const B_BAD_REPLY: status_t = B_APP_ERROR_BASE + 0;
650pub const B_DUPLICATE_REPLY: status_t = B_APP_ERROR_BASE + 1;
651pub const B_MESSAGE_TO_SELF: status_t = B_APP_ERROR_BASE + 2;
652pub const B_BAD_HANDLER: status_t = B_APP_ERROR_BASE + 3;
653pub const B_ALREADY_RUNNING: status_t = B_APP_ERROR_BASE + 4;
654pub const B_LAUNCH_FAILED: status_t = B_APP_ERROR_BASE + 5;
655pub const B_AMBIGUOUS_APP_LAUNCH: status_t = B_APP_ERROR_BASE + 6;
656pub const B_UNKNOWN_MIME_TYPE: status_t = B_APP_ERROR_BASE + 7;
657pub const B_BAD_SCRIPT_SYNTAX: status_t = B_APP_ERROR_BASE + 8;
658pub const B_LAUNCH_FAILED_NO_RESOLVE_LINK: status_t = B_APP_ERROR_BASE + 9;
659pub const B_LAUNCH_FAILED_EXECUTABLE: status_t = B_APP_ERROR_BASE + 10;
660pub const B_LAUNCH_FAILED_APP_NOT_FOUND: status_t = B_APP_ERROR_BASE + 11;
661pub const B_LAUNCH_FAILED_APP_IN_TRASH: status_t = B_APP_ERROR_BASE + 12;
662pub const B_LAUNCH_FAILED_NO_PREFERRED_APP: status_t = B_APP_ERROR_BASE + 13;
663pub const B_LAUNCH_FAILED_FILES_APP_NOT_FOUND: status_t = B_APP_ERROR_BASE + 14;
664pub const B_BAD_MIME_SNIFFER_RULE: status_t = B_APP_ERROR_BASE + 15;
665pub const B_NOT_A_MESSAGE: status_t = B_APP_ERROR_BASE + 16;
666pub const B_SHUTDOWN_CANCELLED: status_t = B_APP_ERROR_BASE + 17;
667pub const B_SHUTTING_DOWN: status_t = B_APP_ERROR_BASE + 18;
668
669// Storage kit errors
670pub const B_FILE_ERROR: status_t = B_STORAGE_ERROR_BASE + 0;
671pub const B_FILE_EXISTS: status_t = B_STORAGE_ERROR_BASE + 2;
672pub const B_ENTRY_NOT_FOUND: status_t = B_STORAGE_ERROR_BASE + 3;
673pub const B_NAME_TOO_LONG: status_t = B_STORAGE_ERROR_BASE + 4;
674pub const B_NOT_A_DIRECTORY: status_t = B_STORAGE_ERROR_BASE + 5;
675pub const B_DIRECTORY_NOT_EMPTY: status_t = B_STORAGE_ERROR_BASE + 6;
676pub const B_DEVICE_FULL: status_t = B_STORAGE_ERROR_BASE + 7;
677pub const B_READ_ONLY_DEVICE: status_t = B_STORAGE_ERROR_BASE + 8;
678pub const B_IS_A_DIRECTORY: status_t = B_STORAGE_ERROR_BASE + 9;
679pub const B_NO_MORE_FDS: status_t = B_STORAGE_ERROR_BASE + 10;
680pub const B_CROSS_DEVICE_LINK: status_t = B_STORAGE_ERROR_BASE + 11;
681pub const B_LINK_LIMIT: status_t = B_STORAGE_ERROR_BASE + 12;
682pub const B_BUSTED_PIPE: status_t = B_STORAGE_ERROR_BASE + 13;
683pub const B_UNSUPPORTED: status_t = B_STORAGE_ERROR_BASE + 14;
684pub const B_PARTITION_TOO_SMALL: status_t = B_STORAGE_ERROR_BASE + 15;
685pub const B_PARTIAL_READ: status_t = B_STORAGE_ERROR_BASE + 16;
686pub const B_PARTIAL_WRITE: status_t = B_STORAGE_ERROR_BASE + 17;
687
688// Mapped posix errors
689pub const B_BUFFER_OVERFLOW: status_t = ::EOVERFLOW;
690pub const B_TOO_MANY_ARGS: status_t = ::E2BIG;
691pub const B_FILE_TOO_LARGE: status_t = ::EFBIG;
692pub const B_RESULT_NOT_REPRESENTABLE: status_t = ::ERANGE;
693pub const B_DEVICE_NOT_FOUND: status_t = ::ENODEV;
694pub const B_NOT_SUPPORTED: status_t = ::EOPNOTSUPP;
695
696// Media kit errors
697pub const B_STREAM_NOT_FOUND: status_t = B_MEDIA_ERROR_BASE + 0;
698pub const B_SERVER_NOT_FOUND: status_t = B_MEDIA_ERROR_BASE + 1;
699pub const B_RESOURCE_NOT_FOUND: status_t = B_MEDIA_ERROR_BASE + 2;
700pub const B_RESOURCE_UNAVAILABLE: status_t = B_MEDIA_ERROR_BASE + 3;
701pub const B_BAD_SUBSCRIBER: status_t = B_MEDIA_ERROR_BASE + 4;
702pub const B_SUBSCRIBER_NOT_ENTERED: status_t = B_MEDIA_ERROR_BASE + 5;
703pub const B_BUFFER_NOT_AVAILABLE: status_t = B_MEDIA_ERROR_BASE + 6;
704pub const B_LAST_BUFFER_ERROR: status_t = B_MEDIA_ERROR_BASE + 7;
705
706pub const B_MEDIA_SYSTEM_FAILURE: status_t = B_MEDIA_ERROR_BASE + 100;
707pub const B_MEDIA_BAD_NODE: status_t = B_MEDIA_ERROR_BASE + 101;
708pub const B_MEDIA_NODE_BUSY: status_t = B_MEDIA_ERROR_BASE + 102;
709pub const B_MEDIA_BAD_FORMAT: status_t = B_MEDIA_ERROR_BASE + 103;
710pub const B_MEDIA_BAD_BUFFER: status_t = B_MEDIA_ERROR_BASE + 104;
711pub const B_MEDIA_TOO_MANY_NODES: status_t = B_MEDIA_ERROR_BASE + 105;
712pub const B_MEDIA_TOO_MANY_BUFFERS: status_t = B_MEDIA_ERROR_BASE + 106;
713pub const B_MEDIA_NODE_ALREADY_EXISTS: status_t = B_MEDIA_ERROR_BASE + 107;
714pub const B_MEDIA_BUFFER_ALREADY_EXISTS: status_t = B_MEDIA_ERROR_BASE + 108;
715pub const B_MEDIA_CANNOT_SEEK: status_t = B_MEDIA_ERROR_BASE + 109;
716pub const B_MEDIA_CANNOT_CHANGE_RUN_MODE: status_t = B_MEDIA_ERROR_BASE + 110;
717pub const B_MEDIA_APP_ALREADY_REGISTERED: status_t = B_MEDIA_ERROR_BASE + 111;
718pub const B_MEDIA_APP_NOT_REGISTERED: status_t = B_MEDIA_ERROR_BASE + 112;
719pub const B_MEDIA_CANNOT_RECLAIM_BUFFERS: status_t = B_MEDIA_ERROR_BASE + 113;
720pub const B_MEDIA_BUFFERS_NOT_RECLAIMED: status_t = B_MEDIA_ERROR_BASE + 114;
721pub const B_MEDIA_TIME_SOURCE_STOPPED: status_t = B_MEDIA_ERROR_BASE + 115;
722pub const B_MEDIA_TIME_SOURCE_BUSY: status_t = B_MEDIA_ERROR_BASE + 116;
723pub const B_MEDIA_BAD_SOURCE: status_t = B_MEDIA_ERROR_BASE + 117;
724pub const B_MEDIA_BAD_DESTINATION: status_t = B_MEDIA_ERROR_BASE + 118;
725pub const B_MEDIA_ALREADY_CONNECTED: status_t = B_MEDIA_ERROR_BASE + 119;
726pub const B_MEDIA_NOT_CONNECTED: status_t = B_MEDIA_ERROR_BASE + 120;
727pub const B_MEDIA_BAD_CLIP_FORMAT: status_t = B_MEDIA_ERROR_BASE + 121;
728pub const B_MEDIA_ADDON_FAILED: status_t = B_MEDIA_ERROR_BASE + 122;
729pub const B_MEDIA_ADDON_DISABLED: status_t = B_MEDIA_ERROR_BASE + 123;
730pub const B_MEDIA_CHANGE_IN_PROGRESS: status_t = B_MEDIA_ERROR_BASE + 124;
731pub const B_MEDIA_STALE_CHANGE_COUNT: status_t = B_MEDIA_ERROR_BASE + 125;
732pub const B_MEDIA_ADDON_RESTRICTED: status_t = B_MEDIA_ERROR_BASE + 126;
733pub const B_MEDIA_NO_HANDLER: status_t = B_MEDIA_ERROR_BASE + 127;
734pub const B_MEDIA_DUPLICATE_FORMAT: status_t = B_MEDIA_ERROR_BASE + 128;
735pub const B_MEDIA_REALTIME_DISABLED: status_t = B_MEDIA_ERROR_BASE + 129;
736pub const B_MEDIA_REALTIME_UNAVAILABLE: status_t = B_MEDIA_ERROR_BASE + 130;
737
738// Mail kit errors
739pub const B_MAIL_NO_DAEMON: status_t = B_MAIL_ERROR_BASE + 0;
740pub const B_MAIL_UNKNOWN_USER: status_t = B_MAIL_ERROR_BASE + 1;
741pub const B_MAIL_WRONG_PASSWORD: status_t = B_MAIL_ERROR_BASE + 2;
742pub const B_MAIL_UNKNOWN_HOST: status_t = B_MAIL_ERROR_BASE + 3;
743pub const B_MAIL_ACCESS_ERROR: status_t = B_MAIL_ERROR_BASE + 4;
744pub const B_MAIL_UNKNOWN_FIELD: status_t = B_MAIL_ERROR_BASE + 5;
745pub const B_MAIL_NO_RECIPIENT: status_t = B_MAIL_ERROR_BASE + 6;
746pub const B_MAIL_INVALID_MAIL: status_t = B_MAIL_ERROR_BASE + 7;
747
748// Print kit errors
749pub const B_NO_PRINT_SERVER: status_t = B_PRINT_ERROR_BASE + 0;
750
751// Device kit errors
752pub const B_DEV_INVALID_IOCTL: status_t = B_DEVICE_ERROR_BASE + 0;
753pub const B_DEV_NO_MEMORY: status_t = B_DEVICE_ERROR_BASE + 1;
754pub const B_DEV_BAD_DRIVE_NUM: status_t = B_DEVICE_ERROR_BASE + 2;
755pub const B_DEV_NO_MEDIA: status_t = B_DEVICE_ERROR_BASE + 3;
756pub const B_DEV_UNREADABLE: status_t = B_DEVICE_ERROR_BASE + 4;
757pub const B_DEV_FORMAT_ERROR: status_t = B_DEVICE_ERROR_BASE + 5;
758pub const B_DEV_TIMEOUT: status_t = B_DEVICE_ERROR_BASE + 6;
759pub const B_DEV_RECALIBRATE_ERROR: status_t = B_DEVICE_ERROR_BASE + 7;
760pub const B_DEV_SEEK_ERROR: status_t = B_DEVICE_ERROR_BASE + 8;
761pub const B_DEV_ID_ERROR: status_t = B_DEVICE_ERROR_BASE + 9;
762pub const B_DEV_READ_ERROR: status_t = B_DEVICE_ERROR_BASE + 10;
763pub const B_DEV_WRITE_ERROR: status_t = B_DEVICE_ERROR_BASE + 11;
764pub const B_DEV_NOT_READY: status_t = B_DEVICE_ERROR_BASE + 12;
765pub const B_DEV_MEDIA_CHANGED: status_t = B_DEVICE_ERROR_BASE + 13;
766pub const B_DEV_MEDIA_CHANGE_REQUESTED: status_t = B_DEVICE_ERROR_BASE + 14;
767pub const B_DEV_RESOURCE_CONFLICT: status_t = B_DEVICE_ERROR_BASE + 15;
768pub const B_DEV_CONFIGURATION_ERROR: status_t = B_DEVICE_ERROR_BASE + 16;
769pub const B_DEV_DISABLED_BY_USER: status_t = B_DEVICE_ERROR_BASE + 17;
770pub const B_DEV_DOOR_OPEN: status_t = B_DEVICE_ERROR_BASE + 18;
771
772pub const B_DEV_INVALID_PIPE: status_t = B_DEVICE_ERROR_BASE + 19;
773pub const B_DEV_CRC_ERROR: status_t = B_DEVICE_ERROR_BASE + 20;
774pub const B_DEV_STALLED: status_t = B_DEVICE_ERROR_BASE + 21;
775pub const B_DEV_BAD_PID: status_t = B_DEVICE_ERROR_BASE + 22;
776pub const B_DEV_UNEXPECTED_PID: status_t = B_DEVICE_ERROR_BASE + 23;
777pub const B_DEV_DATA_OVERRUN: status_t = B_DEVICE_ERROR_BASE + 24;
778pub const B_DEV_DATA_UNDERRUN: status_t = B_DEVICE_ERROR_BASE + 25;
779pub const B_DEV_FIFO_OVERRUN: status_t = B_DEVICE_ERROR_BASE + 26;
780pub const B_DEV_FIFO_UNDERRUN: status_t = B_DEVICE_ERROR_BASE + 27;
781pub const B_DEV_PENDING: status_t = B_DEVICE_ERROR_BASE + 28;
782pub const B_DEV_MULTIPLE_ERRORS: status_t = B_DEVICE_ERROR_BASE + 29;
783pub const B_DEV_TOO_LATE: status_t = B_DEVICE_ERROR_BASE + 30;
784
785// translation kit errors
786pub const B_TRANSLATION_BASE_ERROR: status_t = B_TRANSLATION_ERROR_BASE + 0;
787pub const B_NO_TRANSLATOR: status_t = B_TRANSLATION_ERROR_BASE + 1;
788pub const B_ILLEGAL_DATA: status_t = B_TRANSLATION_ERROR_BASE + 2;
789
790// support/TypeConstants.h
791pub const B_AFFINE_TRANSFORM_TYPE: u32 = haiku_constant!('A', 'M', 'T', 'X');
792pub const B_ALIGNMENT_TYPE: u32 = haiku_constant!('A', 'L', 'G', 'N');
793pub const B_ANY_TYPE: u32 = haiku_constant!('A', 'N', 'Y', 'T');
794pub const B_ATOM_TYPE: u32 = haiku_constant!('A', 'T', 'O', 'M');
795pub const B_ATOMREF_TYPE: u32 = haiku_constant!('A', 'T', 'M', 'R');
796pub const B_BOOL_TYPE: u32 = haiku_constant!('B', 'O', 'O', 'L');
797pub const B_CHAR_TYPE: u32 = haiku_constant!('C', 'H', 'A', 'R');
798pub const B_COLOR_8_BIT_TYPE: u32 = haiku_constant!('C', 'L', 'R', 'B');
799pub const B_DOUBLE_TYPE: u32 = haiku_constant!('D', 'B', 'L', 'E');
800pub const B_FLOAT_TYPE: u32 = haiku_constant!('F', 'L', 'O', 'T');
801pub const B_GRAYSCALE_8_BIT_TYPE: u32 = haiku_constant!('G', 'R', 'Y', 'B');
802pub const B_INT16_TYPE: u32 = haiku_constant!('S', 'H', 'R', 'T');
803pub const B_INT32_TYPE: u32 = haiku_constant!('L', 'O', 'N', 'G');
804pub const B_INT64_TYPE: u32 = haiku_constant!('L', 'L', 'N', 'G');
805pub const B_INT8_TYPE: u32 = haiku_constant!('B', 'Y', 'T', 'E');
806pub const B_LARGE_ICON_TYPE: u32 = haiku_constant!('I', 'C', 'O', 'N');
807pub const B_MEDIA_PARAMETER_GROUP_TYPE: u32 = haiku_constant!('B', 'M', 'C', 'G');
808pub const B_MEDIA_PARAMETER_TYPE: u32 = haiku_constant!('B', 'M', 'C', 'T');
809pub const B_MEDIA_PARAMETER_WEB_TYPE: u32 = haiku_constant!('B', 'M', 'C', 'W');
810pub const B_MESSAGE_TYPE: u32 = haiku_constant!('M', 'S', 'G', 'G');
811pub const B_MESSENGER_TYPE: u32 = haiku_constant!('M', 'S', 'N', 'G');
812pub const B_MIME_TYPE: u32 = haiku_constant!('M', 'I', 'M', 'E');
813pub const B_MINI_ICON_TYPE: u32 = haiku_constant!('M', 'I', 'C', 'N');
814pub const B_MONOCHROME_1_BIT_TYPE: u32 = haiku_constant!('M', 'N', 'O', 'B');
815pub const B_OBJECT_TYPE: u32 = haiku_constant!('O', 'P', 'T', 'R');
816pub const B_OFF_T_TYPE: u32 = haiku_constant!('O', 'F', 'F', 'T');
817pub const B_PATTERN_TYPE: u32 = haiku_constant!('P', 'A', 'T', 'N');
818pub const B_POINTER_TYPE: u32 = haiku_constant!('P', 'N', 'T', 'R');
819pub const B_POINT_TYPE: u32 = haiku_constant!('B', 'P', 'N', 'T');
820pub const B_PROPERTY_INFO_TYPE: u32 = haiku_constant!('S', 'C', 'T', 'D');
821pub const B_RAW_TYPE: u32 = haiku_constant!('R', 'A', 'W', 'T');
822pub const B_RECT_TYPE: u32 = haiku_constant!('R', 'E', 'C', 'T');
823pub const B_REF_TYPE: u32 = haiku_constant!('R', 'R', 'E', 'F');
824pub const B_RGB_32_BIT_TYPE: u32 = haiku_constant!('R', 'G', 'B', 'B');
825pub const B_RGB_COLOR_TYPE: u32 = haiku_constant!('R', 'G', 'B', 'C');
826pub const B_SIZE_TYPE: u32 = haiku_constant!('S', 'I', 'Z', 'E');
827pub const B_SIZE_T_TYPE: u32 = haiku_constant!('S', 'I', 'Z', 'T');
828pub const B_SSIZE_T_TYPE: u32 = haiku_constant!('S', 'S', 'Z', 'T');
829pub const B_STRING_TYPE: u32 = haiku_constant!('C', 'S', 'T', 'R');
830pub const B_STRING_LIST_TYPE: u32 = haiku_constant!('S', 'T', 'R', 'L');
831pub const B_TIME_TYPE: u32 = haiku_constant!('T', 'I', 'M', 'E');
832pub const B_UINT16_TYPE: u32 = haiku_constant!('U', 'S', 'H', 'T');
833pub const B_UINT32_TYPE: u32 = haiku_constant!('U', 'L', 'N', 'G');
834pub const B_UINT64_TYPE: u32 = haiku_constant!('U', 'L', 'L', 'G');
835pub const B_UINT8_TYPE: u32 = haiku_constant!('U', 'B', 'Y', 'T');
836pub const B_VECTOR_ICON_TYPE: u32 = haiku_constant!('V', 'I', 'C', 'N');
837pub const B_XATTR_TYPE: u32 = haiku_constant!('X', 'A', 'T', 'R');
838pub const B_NETWORK_ADDRESS_TYPE: u32 = haiku_constant!('N', 'W', 'A', 'D');
839pub const B_MIME_STRING_TYPE: u32 = haiku_constant!('M', 'I', 'M', 'S');
840pub const B_ASCII_TYPE: u32 = haiku_constant!('T', 'E', 'X', 'T');
841
842extern "C" {
843    // kernel/OS.h
844    pub fn create_area(
845        name: *const ::c_char,
846        startAddress: *mut *mut ::c_void,
847        addressSpec: u32,
848        size: usize,
849        lock: u32,
850        protection: u32,
851    ) -> area_id;
852    pub fn clone_area(
853        name: *const ::c_char,
854        destAddress: *mut *mut ::c_void,
855        addressSpec: u32,
856        protection: u32,
857        source: area_id,
858    ) -> area_id;
859    pub fn find_area(name: *const ::c_char) -> area_id;
860    pub fn area_for(address: *mut ::c_void) -> area_id;
861    pub fn delete_area(id: area_id) -> status_t;
862    pub fn resize_area(id: area_id, newSize: usize) -> status_t;
863    pub fn set_area_protection(id: area_id, newProtection: u32) -> status_t;
864    pub fn _get_area_info(id: area_id, areaInfo: *mut area_info, size: usize) -> status_t;
865    pub fn _get_next_area_info(
866        team: team_id,
867        cookie: *mut isize,
868        areaInfo: *mut area_info,
869        size: usize,
870    ) -> status_t;
871
872    pub fn create_port(capacity: i32, name: *const ::c_char) -> port_id;
873    pub fn find_port(name: *const ::c_char) -> port_id;
874    pub fn read_port(
875        port: port_id,
876        code: *mut i32,
877        buffer: *mut ::c_void,
878        bufferSize: ::size_t,
879    ) -> ::ssize_t;
880    pub fn read_port_etc(
881        port: port_id,
882        code: *mut i32,
883        buffer: *mut ::c_void,
884        bufferSize: ::size_t,
885        flags: u32,
886        timeout: bigtime_t,
887    ) -> ::ssize_t;
888    pub fn write_port(
889        port: port_id,
890        code: i32,
891        buffer: *const ::c_void,
892        bufferSize: ::size_t,
893    ) -> status_t;
894    pub fn write_port_etc(
895        port: port_id,
896        code: i32,
897        buffer: *const ::c_void,
898        bufferSize: ::size_t,
899        flags: u32,
900        timeout: bigtime_t,
901    ) -> status_t;
902    pub fn close_port(port: port_id) -> status_t;
903    pub fn delete_port(port: port_id) -> status_t;
904    pub fn port_buffer_size(port: port_id) -> ::ssize_t;
905    pub fn port_buffer_size_etc(port: port_id, flags: u32, timeout: bigtime_t) -> ::ssize_t;
906    pub fn port_count(port: port_id) -> ::ssize_t;
907    pub fn set_port_owner(port: port_id, team: team_id) -> status_t;
908
909    pub fn _get_port_info(port: port_id, buf: *mut port_info, portInfoSize: ::size_t) -> status_t;
910    pub fn _get_next_port_info(
911        port: port_id,
912        cookie: *mut i32,
913        portInfo: *mut port_info,
914        portInfoSize: ::size_t,
915    ) -> status_t;
916    pub fn _get_port_message_info_etc(
917        port: port_id,
918        info: *mut port_message_info,
919        infoSize: ::size_t,
920        flags: u32,
921        timeout: bigtime_t,
922    ) -> status_t;
923
924    pub fn create_sem(count: i32, name: *const ::c_char) -> sem_id;
925    pub fn delete_sem(id: sem_id) -> status_t;
926    pub fn acquire_sem(id: sem_id) -> status_t;
927    pub fn acquire_sem_etc(id: sem_id, count: i32, flags: u32, timeout: bigtime_t) -> status_t;
928    pub fn release_sem(id: sem_id) -> status_t;
929    pub fn release_sem_etc(id: sem_id, count: i32, flags: u32) -> status_t;
930    pub fn switch_sem(semToBeReleased: sem_id, id: sem_id) -> status_t;
931    pub fn switch_sem_etc(
932        semToBeReleased: sem_id,
933        id: sem_id,
934        count: i32,
935        flags: u32,
936        timeout: bigtime_t,
937    ) -> status_t;
938    pub fn get_sem_count(id: sem_id, threadCount: *mut i32) -> status_t;
939    pub fn set_sem_owner(id: sem_id, team: team_id) -> status_t;
940    pub fn _get_sem_info(id: sem_id, info: *mut sem_info, infoSize: ::size_t) -> status_t;
941    pub fn _get_next_sem_info(
942        team: team_id,
943        cookie: *mut i32,
944        info: *mut sem_info,
945        infoSize: ::size_t,
946    ) -> status_t;
947
948    pub fn kill_team(team: team_id) -> status_t;
949    pub fn _get_team_info(team: team_id, info: *mut team_info, size: ::size_t) -> status_t;
950    pub fn _get_next_team_info(cookie: *mut i32, info: *mut team_info, size: ::size_t) -> status_t;
951
952    pub fn spawn_thread(
953        func: thread_func,
954        name: *const ::c_char,
955        priority: i32,
956        data: *mut ::c_void,
957    ) -> thread_id;
958    pub fn kill_thread(thread: thread_id) -> status_t;
959    pub fn resume_thread(thread: thread_id) -> status_t;
960    pub fn suspend_thread(thread: thread_id) -> status_t;
961
962    pub fn rename_thread(thread: thread_id, newName: *const ::c_char) -> status_t;
963    pub fn set_thread_priority(thread: thread_id, newPriority: i32) -> status_t;
964    pub fn suggest_thread_priority(
965        what: u32,
966        period: i32,
967        jitter: ::bigtime_t,
968        length: ::bigtime_t,
969    ) -> i32;
970    pub fn estimate_max_scheduling_latency(th: ::thread_id) -> ::bigtime_t;
971    pub fn exit_thread(status: status_t);
972    pub fn wait_for_thread(thread: thread_id, returnValue: *mut status_t) -> status_t;
973    pub fn on_exit_thread(callback: extern "C" fn(*mut ::c_void), data: *mut ::c_void) -> status_t;
974
975    pub fn find_thread(name: *const ::c_char) -> thread_id;
976
977    pub fn get_scheduler_mode() -> i32;
978    pub fn set_scheduler_mode(mode: i32) -> status_t;
979
980    pub fn send_data(
981        thread: thread_id,
982        code: i32,
983        buffer: *const ::c_void,
984        bufferSize: ::size_t,
985    ) -> status_t;
986    pub fn receive_data(sender: *mut thread_id, buffer: *mut ::c_void, bufferSize: ::size_t)
987        -> i32;
988    pub fn has_data(thread: thread_id) -> bool;
989
990    pub fn snooze(amount: bigtime_t) -> status_t;
991    pub fn snooze_etc(amount: bigtime_t, timeBase: ::c_int, flags: u32) -> status_t;
992    pub fn snooze_until(time: bigtime_t, timeBase: ::c_int) -> status_t;
993
994    pub fn _get_thread_info(id: thread_id, info: *mut thread_info, size: ::size_t) -> status_t;
995    pub fn _get_next_thread_info(
996        team: team_id,
997        cookie: *mut i32,
998        info: *mut thread_info,
999        size: ::size_t,
1000    ) -> status_t;
1001
1002    pub fn get_pthread_thread_id(thread: ::pthread_t) -> thread_id;
1003
1004    pub fn _get_team_usage_info(
1005        team: team_id,
1006        who: i32,
1007        info: *mut team_usage_info,
1008        size: ::size_t,
1009    ) -> status_t;
1010
1011    pub fn real_time_clock() -> ::c_ulong;
1012    pub fn set_real_time_clock(secsSinceJan1st1970: ::c_ulong);
1013    pub fn real_time_clock_usecs() -> bigtime_t;
1014    pub fn system_time() -> bigtime_t;
1015    pub fn system_time_nsecs() -> nanotime_t;
1016    // set_timezone() is deprecated and a no-op
1017
1018    pub fn set_alarm(when: bigtime_t, flags: u32) -> bigtime_t;
1019    pub fn debugger(message: *const ::c_char);
1020    pub fn disable_debugger(state: ::c_int) -> ::c_int;
1021
1022    pub fn get_system_info(info: *mut system_info) -> status_t;
1023    pub fn _get_cpu_info_etc(
1024        firstCPU: u32,
1025        cpuCount: u32,
1026        info: *mut cpu_info,
1027        size: ::size_t,
1028    ) -> status_t;
1029    pub fn is_computer_on() -> i32;
1030    pub fn is_computer_on_fire() -> ::c_double;
1031    pub fn send_signal(threadID: thread_id, signal: ::c_uint) -> ::c_int;
1032    pub fn set_signal_stack(base: *mut ::c_void, size: ::size_t);
1033
1034    pub fn wait_for_objects(infos: *mut object_wait_info, numInfos: ::c_int) -> ::ssize_t;
1035    pub fn wait_for_objects_etc(
1036        infos: *mut object_wait_info,
1037        numInfos: ::c_int,
1038        flags: u32,
1039        timeout: bigtime_t,
1040    ) -> ::ssize_t;
1041
1042    // kernel/fs_attr.h
1043    pub fn fs_read_attr(
1044        fd: ::c_int,
1045        attribute: *const ::c_char,
1046        type_: u32,
1047        pos: ::off_t,
1048        buffer: *mut ::c_void,
1049        readBytes: ::size_t,
1050    ) -> ::ssize_t;
1051    pub fn fs_write_attr(
1052        fd: ::c_int,
1053        attribute: *const ::c_char,
1054        type_: u32,
1055        pos: ::off_t,
1056        buffer: *const ::c_void,
1057        writeBytes: ::size_t,
1058    ) -> ::ssize_t;
1059    pub fn fs_remove_attr(fd: ::c_int, attribute: *const ::c_char) -> ::c_int;
1060    pub fn fs_stat_attr(
1061        fd: ::c_int,
1062        attribute: *const ::c_char,
1063        attrInfo: *mut attr_info,
1064    ) -> ::c_int;
1065
1066    pub fn fs_open_attr(
1067        path: *const ::c_char,
1068        attribute: *const ::c_char,
1069        type_: u32,
1070        openMode: ::c_int,
1071    ) -> ::c_int;
1072    pub fn fs_fopen_attr(
1073        fd: ::c_int,
1074        attribute: *const ::c_char,
1075        type_: u32,
1076        openMode: ::c_int,
1077    ) -> ::c_int;
1078    pub fn fs_close_attr(fd: ::c_int) -> ::c_int;
1079
1080    pub fn fs_open_attr_dir(path: *const ::c_char) -> *mut ::DIR;
1081    pub fn fs_lopen_attr_dir(path: *const ::c_char) -> *mut ::DIR;
1082    pub fn fs_fopen_attr_dir(fd: ::c_int) -> *mut ::DIR;
1083    pub fn fs_close_attr_dir(dir: *mut ::DIR) -> ::c_int;
1084    pub fn fs_read_attr_dir(dir: *mut ::DIR) -> *mut ::dirent;
1085    pub fn fs_rewind_attr_dir(dir: *mut ::DIR);
1086
1087    // kernel/fs_image.h
1088    pub fn fs_create_index(
1089        device: ::dev_t,
1090        name: *const ::c_char,
1091        type_: u32,
1092        flags: u32,
1093    ) -> ::c_int;
1094    pub fn fs_remove_index(device: ::dev_t, name: *const ::c_char) -> ::c_int;
1095    pub fn fs_stat_index(
1096        device: ::dev_t,
1097        name: *const ::c_char,
1098        indexInfo: *mut index_info,
1099    ) -> ::c_int;
1100
1101    pub fn fs_open_index_dir(device: ::dev_t) -> *mut ::DIR;
1102    pub fn fs_close_index_dir(indexDirectory: *mut ::DIR) -> ::c_int;
1103    pub fn fs_read_index_dir(indexDirectory: *mut ::DIR) -> *mut ::dirent;
1104    pub fn fs_rewind_index_dir(indexDirectory: *mut ::DIR);
1105
1106    // kernel/fs_info.h
1107    pub fn dev_for_path(path: *const ::c_char) -> ::dev_t;
1108    pub fn next_dev(pos: *mut i32) -> ::dev_t;
1109    pub fn fs_stat_dev(dev: ::dev_t, info: *mut fs_info) -> ::c_int;
1110
1111    // kernel/fs_query.h
1112    pub fn fs_open_query(device: ::dev_t, query: *const ::c_char, flags: u32) -> *mut ::DIR;
1113    pub fn fs_open_live_query(
1114        device: ::dev_t,
1115        query: *const ::c_char,
1116        flags: u32,
1117        port: port_id,
1118        token: i32,
1119    ) -> *mut ::DIR;
1120    pub fn fs_close_query(d: *mut ::DIR) -> ::c_int;
1121    pub fn fs_read_query(d: *mut ::DIR) -> *mut ::dirent;
1122    pub fn get_path_for_dirent(dent: *mut ::dirent, buf: *mut ::c_char, len: ::size_t) -> status_t;
1123
1124    // kernel/fs_volume.h
1125    pub fn fs_mount_volume(
1126        where_: *const ::c_char,
1127        device: *const ::c_char,
1128        filesystem: *const ::c_char,
1129        flags: u32,
1130        parameters: *const ::c_char,
1131    ) -> ::dev_t;
1132    pub fn fs_unmount_volume(path: *const ::c_char, flags: u32) -> status_t;
1133
1134    // kernel/image.h
1135    pub fn load_image(
1136        argc: i32,
1137        argv: *mut *const ::c_char,
1138        environ: *mut *const ::c_char,
1139    ) -> thread_id;
1140    pub fn load_add_on(path: *const ::c_char) -> image_id;
1141    pub fn unload_add_on(image: image_id) -> status_t;
1142    pub fn get_image_symbol(
1143        image: image_id,
1144        name: *const ::c_char,
1145        symbolType: i32,
1146        symbolLocation: *mut *mut ::c_void,
1147    ) -> status_t;
1148    pub fn get_nth_image_symbol(
1149        image: image_id,
1150        n: i32,
1151        nameBuffer: *mut ::c_char,
1152        nameLength: *mut i32,
1153        symbolType: *mut i32,
1154        symbolLocation: *mut *mut ::c_void,
1155    ) -> status_t;
1156    pub fn clear_caches(address: *mut ::c_void, length: ::size_t, flags: u32);
1157    pub fn _get_image_info(image: image_id, info: *mut image_info, size: ::size_t) -> status_t;
1158    pub fn _get_next_image_info(
1159        team: team_id,
1160        cookie: *mut i32,
1161        info: *mut image_info,
1162        size: ::size_t,
1163    ) -> status_t;
1164    pub fn find_path(
1165        codePointer: *const ::c_void,
1166        baseDirectory: path_base_directory,
1167        subPath: *const ::c_char,
1168        pathBuffer: *mut ::c_char,
1169        bufferSize: usize,
1170    ) -> status_t;
1171    pub fn find_path_etc(
1172        codePointer: *const ::c_void,
1173        dependency: *const ::c_char,
1174        architecture: *const ::c_char,
1175        baseDirectory: path_base_directory,
1176        subPath: *const ::c_char,
1177        flags: u32,
1178        pathBuffer: *mut ::c_char,
1179        bufferSize: ::size_t,
1180    ) -> status_t;
1181    pub fn find_path_for_path(
1182        path: *const ::c_char,
1183        baseDirectory: path_base_directory,
1184        subPath: *const ::c_char,
1185        pathBuffer: *mut ::c_char,
1186        bufferSize: ::size_t,
1187    ) -> status_t;
1188    pub fn find_path_for_path_etc(
1189        path: *const ::c_char,
1190        dependency: *const ::c_char,
1191        architectur: *const ::c_char,
1192        baseDirectory: path_base_directory,
1193        subPath: *const ::c_char,
1194        flags: u32,
1195        pathBuffer: *mut ::c_char,
1196        bufferSize: ::size_t,
1197    ) -> status_t;
1198    pub fn find_paths(
1199        baseDirectory: path_base_directory,
1200        subPath: *const ::c_char,
1201        _paths: *mut *mut *mut ::c_char,
1202        pathCount: *mut ::size_t,
1203    ) -> status_t;
1204    pub fn find_paths_etc(
1205        architecture: *const ::c_char,
1206        baseDirectory: path_base_directory,
1207        subPath: *const ::c_char,
1208        flags: u32,
1209        _paths: *mut *mut *mut ::c_char,
1210        pathCount: *mut ::size_t,
1211    ) -> status_t;
1212    pub fn find_directory(
1213        which: directory_which,
1214        volume: ::dev_t,
1215        createIt: bool,
1216        pathString: *mut ::c_char,
1217        length: i32,
1218    ) -> status_t;
1219}
1220
1221cfg_if! {
1222    if #[cfg(libc_union)] {
1223        extern "C" {
1224            pub fn get_cpuid(info: *mut cpuid_info, eaxRegister: u32, cpuNum: u32) -> status_t;
1225        }
1226    }
1227}
1228
1229// The following functions are defined as macros in C/C++
1230#[inline]
1231pub unsafe fn get_cpu_info(firstCPU: u32, cpuCount: u32, info: *mut cpu_info) -> status_t {
1232    _get_cpu_info_etc(
1233        firstCPU,
1234        cpuCount,
1235        info,
1236        core::mem::size_of::<cpu_info>() as ::size_t,
1237    )
1238}
1239
1240#[inline]
1241pub unsafe fn get_area_info(id: area_id, info: *mut area_info) -> status_t {
1242    _get_area_info(id, info, core::mem::size_of::<area_info>() as usize)
1243}
1244
1245#[inline]
1246pub unsafe fn get_next_area_info(
1247    team: team_id,
1248    cookie: *mut isize,
1249    info: *mut area_info,
1250) -> status_t {
1251    _get_next_area_info(
1252        team,
1253        cookie,
1254        info,
1255        core::mem::size_of::<area_info>() as usize,
1256    )
1257}
1258
1259#[inline]
1260pub unsafe fn get_port_info(port: port_id, buf: *mut port_info) -> status_t {
1261    _get_port_info(port, buf, core::mem::size_of::<port_info>() as ::size_t)
1262}
1263
1264#[inline]
1265pub unsafe fn get_next_port_info(
1266    port: port_id,
1267    cookie: *mut i32,
1268    portInfo: *mut port_info,
1269) -> status_t {
1270    _get_next_port_info(
1271        port,
1272        cookie,
1273        portInfo,
1274        core::mem::size_of::<port_info>() as ::size_t,
1275    )
1276}
1277
1278#[inline]
1279pub unsafe fn get_port_message_info_etc(
1280    port: port_id,
1281    info: *mut port_message_info,
1282    flags: u32,
1283    timeout: bigtime_t,
1284) -> status_t {
1285    _get_port_message_info_etc(
1286        port,
1287        info,
1288        core::mem::size_of::<port_message_info>() as ::size_t,
1289        flags,
1290        timeout,
1291    )
1292}
1293
1294#[inline]
1295pub unsafe fn get_sem_info(id: sem_id, info: *mut sem_info) -> status_t {
1296    _get_sem_info(id, info, core::mem::size_of::<sem_info>() as ::size_t)
1297}
1298
1299#[inline]
1300pub unsafe fn get_next_sem_info(team: team_id, cookie: *mut i32, info: *mut sem_info) -> status_t {
1301    _get_next_sem_info(
1302        team,
1303        cookie,
1304        info,
1305        core::mem::size_of::<sem_info>() as ::size_t,
1306    )
1307}
1308
1309#[inline]
1310pub unsafe fn get_team_info(team: team_id, info: *mut team_info) -> status_t {
1311    _get_team_info(team, info, core::mem::size_of::<team_info>() as ::size_t)
1312}
1313
1314#[inline]
1315pub unsafe fn get_next_team_info(cookie: *mut i32, info: *mut team_info) -> status_t {
1316    _get_next_team_info(cookie, info, core::mem::size_of::<team_info>() as ::size_t)
1317}
1318
1319#[inline]
1320pub unsafe fn get_team_usage_info(team: team_id, who: i32, info: *mut team_usage_info) -> status_t {
1321    _get_team_usage_info(
1322        team,
1323        who,
1324        info,
1325        core::mem::size_of::<team_usage_info>() as ::size_t,
1326    )
1327}
1328
1329#[inline]
1330pub unsafe fn get_thread_info(id: thread_id, info: *mut thread_info) -> status_t {
1331    _get_thread_info(id, info, core::mem::size_of::<thread_info>() as ::size_t)
1332}
1333
1334#[inline]
1335pub unsafe fn get_next_thread_info(
1336    team: team_id,
1337    cookie: *mut i32,
1338    info: *mut thread_info,
1339) -> status_t {
1340    _get_next_thread_info(
1341        team,
1342        cookie,
1343        info,
1344        core::mem::size_of::<thread_info>() as ::size_t,
1345    )
1346}
1347
1348// kernel/image.h
1349#[inline]
1350pub unsafe fn get_image_info(image: image_id, info: *mut image_info) -> status_t {
1351    _get_image_info(image, info, core::mem::size_of::<image_info>() as ::size_t)
1352}
1353
1354#[inline]
1355pub unsafe fn get_next_image_info(
1356    team: team_id,
1357    cookie: *mut i32,
1358    info: *mut image_info,
1359) -> status_t {
1360    _get_next_image_info(
1361        team,
1362        cookie,
1363        info,
1364        core::mem::size_of::<image_info>() as ::size_t,
1365    )
1366}
1367