xref: /freebsd/contrib/smart/libsmart_dev.h (revision 41c5a4a2f888765b513efb13befe32fa084ad7cb)
1 /*
2  * Copyright (c) 2017-2021 Chuck Tuffli <chuck@tuffli.net>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 #ifndef _LIBSMART_DEV_H
17 #define _LIBSMART_DEV_H
18 
19 /**
20  * Open a device to gather SMART information
21  *
22  * The call performs OS specific functions necessary to prepare the device
23  * to receive read log requests.
24  *
25  * Although opaque to the user, the handle must be a pointer to a structure
26  * with the first member being struct smart_s. The remaining members are OS
27  * specific and are not used by the library.
28  *
29  * @param protocol The desired protocol or "auto" to automatically detect it
30  * @param devname  The device name to open
31  *
32  * @return An opaque handle to the device or NULL on failure
33  */
34 extern smart_h device_open(smart_protocol_e, char *);
35 
36 /**
37  * Close a device and release the associated resources
38  *
39  * @param handle The handle returned from device_open()
40  *
41  * @return None
42  */
43 extern void device_close(smart_h);
44 
45 /**
46  * Read the log page
47  *
48  * This call reads the specified log page in the protocol specific manner
49  * needed by the device. The results are placed in the provided buffer.
50  *
51  * @param h SMART handle returned from device_open()
52  * @param page The log page ID
53  * @param buf Pointer to buffer containing the results of the read
54  * @param bsize Size of the buffer in bytes
55  *
56  * @return Zero on success, errno on failure
57  */
58 extern int32_t device_read_log(smart_h, uint32_t, void *, size_t);
59 
60 #endif /* !_LIBSMART_DEV_H */
61