You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
5.8 KiB
148 lines
5.8 KiB
/*-
|
|
* Copyright (c) 2026 Sergey Kiselev <root@dc365.ru>
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*/
|
|
|
|
#ifndef BSDDISKINFO_H
|
|
#define BSDDISKINFO_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <sys/param.h>
|
|
#include <sys/ucred.h>
|
|
#include <sys/mount.h>
|
|
|
|
#define MAX_MODEL_LEN 256 /* Buffer size for device model string */
|
|
#define MAX_SERIAL_LEN 64 /* Buffer size for drive serial number string */
|
|
#define MAX_TYPE_LEN 16 /* Buffer size for determined drive architecture type string */
|
|
#define MAX_FW_LEN 16 /* Buffer size for device firmware version revision string */
|
|
#define MAX_WWN_LEN 32 /* Buffer size for LU WWN Device Id hex string format */
|
|
#define MAX_FF_LEN 32 /* Buffer size for physical form factor string */
|
|
#define MAX_ATA_LEN 64 /* Buffer size for major/minor ATA standard specification */
|
|
#define MAX_SATA_LEN 64 /* Buffer size for SATA signaling capabilities and link speed */
|
|
#define MAX_SEC_LEN 32 /* Buffer size for internal ATA Security feature state */
|
|
|
|
#define MAX_MOUNTS 128 /* Maximum tracked active filesystem mount topologies */
|
|
#define MAX_DISKS 64 /* Maximum concurrent physical storage units allowed */
|
|
|
|
/*
|
|
* Base hardware identity properties (similar to smartctl -i output).
|
|
*/
|
|
struct disk_properties {
|
|
char model[MAX_MODEL_LEN]; /* Device model string */
|
|
char serial[MAX_SERIAL_LEN]; /* Serial number string */
|
|
char fw_version[MAX_FW_LEN]; /* Firmware version string */
|
|
char wwn[MAX_WWN_LEN]; /* LU WWN Device Id (hex string format) */
|
|
char type_str[MAX_TYPE_LEN]; /* Determined drive type: "ssd", "hdd", "usb", "sdcard", "nvme" */
|
|
|
|
uint64_t mediasize; /* Total storage capacity in bytes */
|
|
|
|
uint32_t logical_sector_size; /* Logical sector size in bytes */
|
|
uint32_t physical_sector_size; /* Physical sector size in bytes (Advanced Format) */
|
|
|
|
int rotation_rate; /* Nominal rotation rate: 0 = SSD, >0 = RPM, -1 = N/A */
|
|
|
|
int smart_supported; /* S.M.A.R.T. capability support: 1 = Yes, 0 = No, -1 = N/A */
|
|
int smart_enabled; /* S.M.A.R.T. active enablement: 1 = Yes, 0 = No, -1 = N/A */
|
|
|
|
/* Advanced ATA hardware descriptors */
|
|
char form_factor[MAX_FF_LEN]; /* Nominal physical drive form factor dimensions */
|
|
char ata_version[MAX_ATA_LEN]; /* Major/Minor ATA/ATAPI specification standard tracking */
|
|
char sata_version[MAX_SATA_LEN]; /* Active SATA signaling speed capabilities and status */
|
|
char security_status[MAX_SEC_LEN];/* Internal firmware ATA Security Feature Set execution state */
|
|
};
|
|
|
|
/*
|
|
* Active filesystem mount information related to a specific disk
|
|
* slice/partition.
|
|
*/
|
|
struct disk_mount {
|
|
char device[MNAMELEN]; /* Partition node name (e.g., "ada0p2") */
|
|
char path[MNAMELEN]; /* Mounted target filesystem path (e.g., "/usr") */
|
|
char fstype[MFSNAMELEN]; /* Filesystem type name (e.g., "zfs", "ufs") */
|
|
};
|
|
|
|
/*
|
|
* Decoded record for a single raw S.M.A.R.T. attribute vendor entry.
|
|
*/
|
|
struct smart_counter {
|
|
uint8_t id; /* Attribute ID tag (e.g., 0x05) */
|
|
uint8_t value; /* Current normalized value */
|
|
uint8_t worst; /* Worst historical normalized value */
|
|
uint64_t raw_val; /* Parsed 48-bit raw value (vendor specific data) */
|
|
};
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/*
|
|
* Verifies if the requested base device token node exists under /dev/ tree.
|
|
* Returns true if available, false otherwise.
|
|
*/
|
|
bool diskinfo_exists(const char *base_disk);
|
|
|
|
/*
|
|
* Fetches thorough hardware metadata descriptions from a physical storage
|
|
* target.
|
|
* Fills out the provided props target pointer structure.
|
|
* Returns 0 on success.
|
|
*/
|
|
int diskinfo_get_properties(
|
|
const char *base_disk,
|
|
struct disk_properties *props
|
|
);
|
|
|
|
/*
|
|
* Traverses active system mount points table to extract components matching
|
|
* base disk token.
|
|
* Populates mounts_out sequence array buffer up to max_mounts threshold limit.
|
|
* Returns count of extracted objects or a negative error runtime code on
|
|
* failures.
|
|
*/
|
|
int diskinfo_get_mounts(
|
|
const char *base_disk,
|
|
struct disk_mount *mounts_out,
|
|
int max_mounts
|
|
);
|
|
|
|
/*
|
|
* Requests raw S.M.A.R.T. memory structures via CAM userland subsystem
|
|
* interface layers.
|
|
* Unpacks entries straight into counters_out structural array up to
|
|
* max_counters.
|
|
* Returns absolute count of loaded valid records or negative error bounds
|
|
* code on runtime failures.
|
|
*/
|
|
int diskinfo_get_smart_counters(
|
|
const char *base_disk,
|
|
struct smart_counter *counters_out,
|
|
int max_counters
|
|
);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* BSDDISKINFO_H */
|
|
|