Sample Header Ad - 728x90

open() fails on some files with sudo permission

0 votes
0 answers
70 views
Running on Darwin Kernel Version 22.1.0. I have a program which goes through the devices in /dev/ directory to send an nvme command to them to get their ID information. On Linux the files I look for are of /dev/nvmeX variant, but on macOS the nvme devices look to be mapped to /dev/diskX or rdiskX. I am using
//p_dev =/dev/rdisk0;1,2,3...
int fd = open(p_dev, O_RDWR | O_SYNC);
if (fd < 0)
{
    printf("ERROR: %d %s open() failed on %s\n", errno, strerror(errno), p_dev);
}
for rdisk0..3 this returns,
ERROR: 1 Operation not permitted open() failed on /dev/rdisk0
ERROR: 16 Resource busy open() failed on /dev/rdisk1
ERROR: 1 Operation not permitted open() failed on /dev/rdisk2
ERROR: 1 Operation not permitted open() failed on /dev/rdisk3
Next, rdisk4 is the device I am looking for and it opens without any issue. I am running my program with sudo so not permitted doesn't make sense. I checked using diskutil and 0..3 are Apple's SSDs and its partitions. Are they somehow special? As far as I can tell from smartctl they are all NVMe devices. I am not familiar with Apple's implementation and proper use so hopefully someone might know what I might be missing? For now I worked around this by using: popen("diskutil info %s | grep 'Media Name'", "r") and looking for the relevant information. From command line using
SPNVMeDataType
shows the device Apple SSD and the
device but it doesn't show which device one or the other is in /dev/, neither is PCI vendor ID in the output. system_profiler SPNVMeDataType NVMExpress: Apple SSD Controller: APPLE SSD AP0512Q: Capacity: 500.28 GB (500,277,792,768 bytes) TRIM Support: Yes Model: APPLE SSD AP0512Q Revision: 873.40.4 Serial Number: xxxxxxxxxxxxxx Detachable Drive: No BSD Name: disk0 Partition Map Type: GPT (GUID Partition Table) Removable Media: No S.M.A.R.T. status: Verified Volumes: iSCPreboot: Capacity: 524.3 MB (524,288,000 bytes) BSD Name: disk0s1 Content: Apple_APFS_ISC Macintosh HD: Capacity: 494.38 GB (494,384,795,648 bytes) BSD Name: disk0s2 Content: Apple_APFS Recovery: Capacity: 5.37 GB (5,368,664,064 bytes) BSD Name: disk0s3 Content: Apple_APFS_Recovery Generic SSD Controller: xyz: Capacity: 123 TRIM Support: No Model: xyz Revision: ---zzz Serial Number: xxxxxxxxxxxxxxxxxxx Link Width: x4 Link Speed: 8.0 GT/s Detachable Drive: No BSD Name: disk4 Partition Map Type: Unknown Removable Media: No S.M.A.R.T. status: Verified Using
SPSerialATADataType
doesn't produce any output.
Asked by pointnotfoe (1 rep)
Jan 25, 2023, 09:20 PM
Last activity: Jan 26, 2023, 05:48 PM