diff --git a/docs/guide/discovery.rst b/docs/guide/discovery.rst index ce3a03f..b4b5df0 100644 --- a/docs/guide/discovery.rst +++ b/docs/guide/discovery.rst @@ -24,10 +24,10 @@ For our example system, this would give us: .. code-block:: python - LinuxNVMEDevice(path="/dev/nvme0n1") + LinuxNVMeDevice(path="/dev/nvme0n1") LinuxSCSIDevice(path="/dev/sdb") LinuxSCSIDevice(path="/dev/sdc") - LinuxNVMEDevice(path="/dev/nvme1n1") + LinuxNVMeDevice(path="/dev/nvme1n1") LinuxSCSIDevice(path="/dev/sda") diff --git a/docs/guide/low_level.rst b/docs/guide/low_level.rst index 63291d1..b5fd0fc 100644 --- a/docs/guide/low_level.rst +++ b/docs/guide/low_level.rst @@ -21,12 +21,12 @@ type of device you have: from smartie.device import get_device from smartie.scsi import SCSIDevice - from smartie.nvme import NVMEDevice + from smartie.nvme import NVMeDevice with get_device('\\\\.\\PhysicalDrive0') as device: if isinstance(device, SCSIDevice): print('SCSI device') - elif isinstance(device, NVMEDevice): + elif isinstance(device, NVMeDevice): print('NVMe device') else: print('Unknown device type') @@ -83,10 +83,10 @@ To send an NVMe IDENTIFY command to a device: with get_device('/dev/nvme0') as device: # The structure that will be populated with the response. - data = structures.NVMEIdentifyResponse() + data = structures.NVMeIdentifyResponse() device.issue_admin_command( - structures.NVMEAdminCommand( - opcode=structures.NVMEAdminCommands.IDENTIFY, + structures.NVMeAdminCommand( + opcode=structures.NVMeAdminCommands.IDENTIFY, addr=ctypes.addressof(data), data_len=ctypes.sizeof(data), cdw10=1 diff --git a/docs/index.rst b/docs/index.rst index b33452f..0dec5a4 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -85,10 +85,10 @@ from a device: with get_device('/dev/nvme0') as device: # The structure that will be populated with the response. - data = structures.NVMEIdentifyResponse() + data = structures.NVMeIdentifyResponse() device.issue_admin_command( - structures.NVMEAdminCommand( - opcode=structures.NVMEAdminCommands.IDENTIFY, + structures.NVMeAdminCommand( + opcode=structures.NVMeAdminCommands.IDENTIFY, addr=ctypes.addressof(data), data_len=ctypes.sizeof(data), cdw10=1 @@ -108,7 +108,7 @@ Supported Platforms * - OS - Device Discovery - SCSI/ATA Supported - - NVME Supported + - NVMe Supported * - Linux - Yes - Yes diff --git a/smartie/cli.py b/smartie/cli.py index ea80fa6..e8a209b 100644 --- a/smartie/cli.py +++ b/smartie/cli.py @@ -9,7 +9,7 @@ from smartie.database import DRIVE_DATABASE, get_matching_drive_entries from smartie.device import get_all_devices, get_device -from smartie.nvme import NVMEDevice +from smartie.nvme import NVMeDevice from smartie.scsi import SCSIDevice from smartie.structures import c_uint128, embed_bytes from smartie.util import grouper_it @@ -155,11 +155,11 @@ def blocks_to_gb(blocks: int) -> float: str(entry.threshold), entry.unit.name, ) - elif isinstance(device, NVMEDevice): + elif isinstance(device, NVMeDevice): smart_table.add_column("Name", style="magenta") smart_table.add_column("Value", style="green", justify="right") - smart,_ = device.smart() + smart, _ = device.smart() # We only show a selection of attributes, as the full list is # not terribly useful. @@ -254,7 +254,7 @@ def dump_command(path: str, command: str, display: str = "pretty"): return structure = result()[0] - elif isinstance(device, NVMEDevice): + elif isinstance(device, NVMeDevice): result = {"identify": device.identify, "smart": device.smart}.get( command ) @@ -396,7 +396,7 @@ def api_get_command(path: str): "unit": entry.unit.name, "flags": entry.flags, } - elif isinstance(device, NVMEDevice): + elif isinstance(device, NVMeDevice): result["smart"] = device.smart_table print(json.dumps(result, indent=4, sort_keys=True)) diff --git a/smartie/device.py b/smartie/device.py index bbb3f18..9aee3e9 100644 --- a/smartie/device.py +++ b/smartie/device.py @@ -103,11 +103,11 @@ def get_device(path: Union[Path, str]) -> Device: return WindowsSCSIDevice(path) elif system == "Linux": - from smartie.nvme.linux import LinuxNVMEDevice + from smartie.nvme.linux import LinuxNVMeDevice from smartie.scsi.linux import LinuxSCSIDevice if "nvme" in str(path): - return LinuxNVMEDevice(path) + return LinuxNVMeDevice(path) return LinuxSCSIDevice(path) else: raise NotImplementedError("Device not implemented for this platform.") diff --git a/smartie/nvme/__init__.py b/smartie/nvme/__init__.py index 0c55f1d..4a2f66b 100644 --- a/smartie/nvme/__init__.py +++ b/smartie/nvme/__init__.py @@ -1,4 +1,4 @@ -__all__ = ("NVMEDevice",) +__all__ = ("NVMeDevice",) import abc import sys import ctypes @@ -9,9 +9,9 @@ from smartie.device import Device from smartie.nvme.errors import NVMeStatusFieldError from smartie.nvme.structures import ( - NVMEAdminCommand, - NVMEAdminCommands, - NVMEIdentifyResponse, + NVMeAdminCommand, + NVMeAdminCommands, + NVMeIdentifyResponse, NVMeCQEStatusField, SMARTPageResponse, ) @@ -43,7 +43,7 @@ class NVMeResponse: #: The status field data returned by the device. status_field: Optional[NVMeCQEStatusField] #: The command issued to the device. - command: Union[NVMEAdminCommand,] + command: Union[NVMeAdminCommand,] #: Keep aligned with SCSIResponse. Not used for now. #: The actual number of bytes transferred. bytes_transferred: Optional[int] @@ -58,7 +58,7 @@ def __bool__(self): return self.succeeded -class NVMEDevice(Device, abc.ABC): +class NVMeDevice(Device, abc.ABC): @classmethod def parse_status_field(cls, status_blob) -> Optional[NVMeCQEStatusField]: """ @@ -81,15 +81,15 @@ def parse_status_field(cls, status_blob) -> Optional[NVMeCQEStatusField]: def issue_admin_command(self, command): pass - def identify(self) -> Tuple[NVMEIdentifyResponse, NVMeResponse]: + def identify(self) -> Tuple[NVMeIdentifyResponse, NVMeResponse]: """ Returns the parsed IDENTIFY results for CNS 01h, which contains the controller information. """ - data = NVMEIdentifyResponse() + data = NVMeIdentifyResponse() response = self.issue_admin_command( - NVMEAdminCommand( - opcode=NVMEAdminCommands.IDENTIFY, + NVMeAdminCommand( + opcode=NVMeAdminCommands.IDENTIFY, addr=ctypes.addressof(data), data_len=ctypes.sizeof(data), cdw10=1, @@ -116,8 +116,8 @@ def read_log_page( self, log_page_id: int, data: ctypes.Structure ) -> tuple[ctypes.Structure, NVMeResponse]: response = self.issue_admin_command( - NVMEAdminCommand( - opcode=NVMEAdminCommands.GET_LOG_PAGE, + NVMeAdminCommand( + opcode=NVMeAdminCommands.GET_LOG_PAGE, addr=ctypes.addressof(data), data_len=ctypes.sizeof(data), nsid=0xFFFFFFFF, diff --git a/smartie/nvme/linux.py b/smartie/nvme/linux.py index 61af240..d304950 100644 --- a/smartie/nvme/linux.py +++ b/smartie/nvme/linux.py @@ -2,15 +2,15 @@ import os from smartie.nvme import ( - NVMEDevice, + NVMeDevice, NVMeResponse, local_byteorder, ) from smartie.platforms.linux import get_libc -from smartie.nvme.structures import IOCTL_NVME_ADMIN_CMD, NVMEAdminCommand +from smartie.nvme.structures import IOCTL_NVMe_ADMIN_CMD, NVMeAdminCommand -class LinuxNVMEDevice(NVMEDevice): +class LinuxNVMeDevice(NVMeDevice): """ Represents an NVMe device on a Linux system. """ @@ -28,9 +28,9 @@ def __exit__(self, exc_type, exc_val, exc_tb): self.fd = None return False - def issue_admin_command(self, command: NVMEAdminCommand) -> NVMeResponse: + def issue_admin_command(self, command: NVMeAdminCommand) -> NVMeResponse: result = get_libc().ioctl( - self.fd, IOCTL_NVME_ADMIN_CMD, ctypes.byref(command) + self.fd, IOCTL_NVMe_ADMIN_CMD, ctypes.byref(command) ) return NVMeResponse( diff --git a/smartie/nvme/structures.py b/smartie/nvme/structures.py index f5166f0..fa2af73 100644 --- a/smartie/nvme/structures.py +++ b/smartie/nvme/structures.py @@ -1,6 +1,6 @@ """ This file contains the various low-level structure definitions used for sending -and receiving NVME commands, as well as the structures required for +and receiving NVMe commands, as well as the structures required for platform-specific APIs. """ import ctypes @@ -9,15 +9,15 @@ from smartie.structures import c_uint128 #: IOCTL for NVMe Admin commands on Linux. -IOCTL_NVME_ADMIN_CMD = 0xC0484E41 +IOCTL_NVMe_ADMIN_CMD = 0xC0484E41 -class NVMEAdminCommands(enum.IntEnum): +class NVMeAdminCommands(enum.IntEnum): GET_LOG_PAGE = 0x02 IDENTIFY = 0x06 -class NVMEAdminCommand(ctypes.Structure): +class NVMeAdminCommand(ctypes.Structure): _pack_ = 1 _fields_ = [ ("opcode", ctypes.c_ubyte), @@ -55,7 +55,7 @@ class NVMeCQEStatusField(ctypes.Structure): ] -class NVMEIdentifyResponse(ctypes.Structure): +class NVMeIdentifyResponse(ctypes.Structure): _fields_ = [ ("vendor_id", ctypes.c_uint16), ("ssvid", ctypes.c_uint16),