mirror of
https://github.com/freebsd/freebsd-src
synced 2024-07-21 18:27:22 +00:00
nvmecontrol: Allow optional /dev/ for device names
nvmecontrol operates on devices. Allow a user to specify the /dev/ if they want. Any device that starts with / will be treated as if it was a full path for maximum flexbility. Sponsored by: Netflix
This commit is contained in:
parent
c40e0bff72
commit
b12cae88cf
|
@ -33,7 +33,7 @@
|
||||||
.\"
|
.\"
|
||||||
.\" Author: Jim Harris <jimharris@FreeBSD.org>
|
.\" Author: Jim Harris <jimharris@FreeBSD.org>
|
||||||
.\"
|
.\"
|
||||||
.Dd April 17, 2024
|
.Dd May 3, 2024
|
||||||
.Dt NVMECONTROL 8
|
.Dt NVMECONTROL 8
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
@ -687,7 +687,7 @@ or
|
||||||
.Pa nvdZ .
|
.Pa nvdZ .
|
||||||
The leading
|
The leading
|
||||||
.Pa /dev/
|
.Pa /dev/
|
||||||
is omitted.
|
may be omitted.
|
||||||
Where
|
Where
|
||||||
.Aq Ar device-id
|
.Aq Ar device-id
|
||||||
is required, you can use either the
|
is required, you can use either the
|
||||||
|
|
|
@ -145,9 +145,12 @@ read_namespace_data(int fd, uint32_t nsid, struct nvme_namespace_data *nsdata)
|
||||||
int
|
int
|
||||||
open_dev(const char *str, int *fd, int write, int exit_on_error)
|
open_dev(const char *str, int *fd, int write, int exit_on_error)
|
||||||
{
|
{
|
||||||
char full_path[64];
|
char full_path[MAXPATHLEN];
|
||||||
|
|
||||||
snprintf(full_path, sizeof(full_path), _PATH_DEV"%s", str);
|
if (str[0] == '/') /* Full path */
|
||||||
|
strlcpy(full_path, str, sizeof(full_path));
|
||||||
|
else /* Add /dev/ */
|
||||||
|
snprintf(full_path, sizeof(full_path), _PATH_DEV"%s", str);
|
||||||
*fd = open(full_path, write ? O_RDWR : O_RDONLY);
|
*fd = open(full_path, write ? O_RDWR : O_RDONLY);
|
||||||
if (*fd < 0) {
|
if (*fd < 0) {
|
||||||
if (exit_on_error) {
|
if (exit_on_error) {
|
||||||
|
|
Loading…
Reference in a new issue