libscf_sys/
lib.rs

1/*
2 * Copyright 2023 Oxide Computer Company
3 */
4
5#![allow(non_camel_case_types)]
6#![allow(dead_code)]
7
8use std::marker::{PhantomData, PhantomPinned};
9use std::os::raw::{c_char, c_int, c_ulong};
10
11#[macro_use]
12extern crate num_derive;
13
14pub type scf_version_t = c_ulong;
15
16pub const SCF_VERSION: scf_version_t = 1;
17
18pub const SCF_PG_FLAG_NONPERSISTENT: u32 = 0x1;
19
20/*
21 * Flags for the smf_enable_instance(3SCF) family of functions:
22 */
23pub const SMF_IMMEDIATE: c_int = 0x1;
24pub const SMF_TEMPORARY: c_int = 0x2;
25pub const SMF_AT_NEXT_BOOT: c_int = 0x4;
26
27macro_rules! opaque_handle {
28    ($type_name:ident) => {
29        #[repr(C)]
30        pub struct $type_name {
31            _data: [u8; 0],
32            /*
33             * See https://doc.rust-lang.org/nomicon/ffi.html; this marker
34             * guarantees our type does not implement `Send`, `Sync`, or
35             * `Unpin`.
36             */
37            _marker: PhantomData<(*mut u8, PhantomPinned)>,
38        }
39        impl Copy for $type_name {}
40        impl Clone for $type_name {
41            fn clone(&self) -> $type_name {
42                *self
43            }
44        }
45    };
46}
47
48opaque_handle!(scf_handle_t);
49opaque_handle!(scf_iter_t);
50opaque_handle!(scf_scope_t);
51opaque_handle!(scf_service_t);
52opaque_handle!(scf_instance_t);
53opaque_handle!(scf_snapshot_t);
54opaque_handle!(scf_propertygroup_t);
55opaque_handle!(scf_property_t);
56opaque_handle!(scf_value_t);
57opaque_handle!(scf_snaplevel_t);
58opaque_handle!(scf_transaction_t);
59opaque_handle!(scf_transaction_entry_t);
60
61#[derive(Debug, FromPrimitive, ToPrimitive)]
62#[repr(C)]
63pub enum scf_error_t {
64    SCF_ERROR_NONE = 1000,            /* no error */
65    SCF_ERROR_NOT_BOUND,              /* handle not bound */
66    SCF_ERROR_NOT_SET,                /* cannot use unset argument */
67    SCF_ERROR_NOT_FOUND,              /* nothing of that name found */
68    SCF_ERROR_TYPE_MISMATCH,          /* type does not match value */
69    SCF_ERROR_IN_USE,                 /* cannot modify while in-use */
70    SCF_ERROR_CONNECTION_BROKEN,      /* repository connection gone */
71    SCF_ERROR_INVALID_ARGUMENT,       /* bad argument */
72    SCF_ERROR_NO_MEMORY,              /* no memory available */
73    SCF_ERROR_CONSTRAINT_VIOLATED,    /* required constraint not met */
74    SCF_ERROR_EXISTS,                 /* object already exists */
75    SCF_ERROR_NO_SERVER,              /* repository server unavailable */
76    SCF_ERROR_NO_RESOURCES,           /* server has insufficient resources */
77    SCF_ERROR_PERMISSION_DENIED,      /* insufficient privileges for action */
78    SCF_ERROR_BACKEND_ACCESS,         /* backend refused access */
79    SCF_ERROR_HANDLE_MISMATCH,        /* mismatched SCF handles */
80    SCF_ERROR_HANDLE_DESTROYED,       /* object bound to destroyed handle */
81    SCF_ERROR_VERSION_MISMATCH,       /* incompatible SCF version */
82    SCF_ERROR_BACKEND_READONLY,       /* backend is read-only */
83    SCF_ERROR_DELETED,                /* object has been deleted */
84    SCF_ERROR_TEMPLATE_INVALID,       /* template data is invalid */
85    SCF_ERROR_CALLBACK_FAILED = 1080, /* user callback function failed */
86    SCF_ERROR_INTERNAL = 1101,        /* internal error */
87}
88
89#[derive(Debug, FromPrimitive, ToPrimitive, Clone, Copy)]
90#[repr(C)]
91pub enum scf_type_t {
92    SCF_TYPE_INVALID = 0,
93
94    SCF_TYPE_BOOLEAN,
95    SCF_TYPE_COUNT,
96    SCF_TYPE_INTEGER,
97    SCF_TYPE_TIME,
98    SCF_TYPE_ASTRING,
99    SCF_TYPE_OPAQUE,
100
101    SCF_TYPE_USTRING = 100,
102
103    SCF_TYPE_URI = 200,
104    SCF_TYPE_FMRI,
105
106    SCF_TYPE_HOST = 300,
107    SCF_TYPE_HOSTNAME,
108    SCF_TYPE_NET_ADDR_V4,
109    SCF_TYPE_NET_ADDR_V6,
110    SCF_TYPE_NET_ADDR,
111}
112
113pub const SCF_LIMIT_MAX_NAME_LENGTH: u32 = 0xfffff830;
114pub const SCF_LIMIT_MAX_VALUE_LENGTH: u32 = 0xfffff82f;
115pub const SCF_LIMIT_MAX_PG_TYPE_LENGTH: u32 = 0xfffff82e;
116pub const SCF_LIMIT_MAX_FMRI_LENGTH: u32 = 0xfffff82d;
117
118pub const SCF_SCOPE_LOCAL: &[u8] = b"localhost\0";
119
120pub const SCF_DECODE_FMRI_EXACT: c_int = 0x00000001;
121pub const SCF_DECODE_FMRI_TRUNCATE: c_int = 0x00000002;
122pub const SCF_DECODE_FMRI_REQUIRE_INSTANCE: c_int = 0x00000004;
123pub const SCF_DECODE_FMRI_REQUIRE_NO_INSTANCE: c_int = 0x00000008;
124
125pub const SCF_DECORATE_CLEAR: *mut scf_value_t = std::ptr::null_mut();
126
127pub mod decorations {
128    /**
129     * The "debug" decoration accepts a (count) value with debugging flags.
130     */
131    pub const DEBUG: &[u8] = b"debug\0";
132
133    /**
134     * The "zone" decoration is not Committed, and should not be used in
135     * applications.
136     */
137    pub const ZONE: &[u8] = b"zone\0";
138}
139
140#[cfg(target_os = "illumos")]
141mod native;
142#[cfg(target_os = "illumos")]
143pub use native::*;
144
145#[cfg(not(target_os = "illumos"))]
146mod stubs;
147#[cfg(not(target_os = "illumos"))]
148pub use stubs::*;