cat: read error: Operation not supported for /sys/class/net/eth0/phys_*

I customized the system using Kernel 6.4.0 and Busybox, but I don’t know why the three files starting with phys_ cannot be accessed, and other files in the same folder can.

# pwd
/sys/class/net/eth0
# ls
addr_assign_type      carrier_up_count      gro_flush_timeout     napi_defer_hard_irqs  proto_down            tx_queue_len
addr_len              dev_id                ifalias               netdev_group          queues                type
address               dev_port              ifindex               operstate             speed                 uevent
broadcast             device                iflink                phys_port_id          statistics
carrier               dormant               link_mode             phys_port_name        subsystem
carrier_changes       duplex                mtu                   phys_switch_id        testing
carrier_down_count    flags                 name_assign_type      power                 threaded
#
#
#
# cat dev_
dev_id    dev_port
# cat dev_port
0
# cat phys_port_id
cat: read error: Operation not supported
#
# ls -lt dev_port
-r--r--r--    1 root     root          4096 Oct 27 14:50 dev_port
# ls -lt phys_port_id
-r--r--r--    1 root     root          4096 Oct 27 15:36 phys_port_id
Asked By: ABeginner

||

None of the files under /sys are real – they are all representations of values maintained within the kernel.

A list of them under /sys/class/net is available at https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net

The relevant section for phys_port_id and phys_port_name is this:

What:     /sys/class/net/<iface>/phys_port_id
Date:     July 2013
KernelVersion:    3.12
Contact:  netdev@vger.kernel.org
Description:
      Indicates the interface unique physical port identifier within
      the NIC, as a string.

What:     /sys/class/net/<iface>/phys_port_name
Date:     March 2015
KernelVersion:    4.0
Contact:  netdev@vger.kernel.org
Description:
      Indicates the interface physical port name within the NIC,
      as a string.

As described, these two values provide an identification for the physical port on a card with multiple ports (search for "4 port NIC", for example).

Answered By: Chris Davies

The contents of that phys_port_id file is generated upon request (when a process reads it) by the phys_port_id_show() function in the Linux kernel.

You can see that it returns EOPNOTSUPP if the driver for the network interface doesn’t implement a ndo_get_phys_port_id operation. If you look for ndo_get_phys_port_id in the drivers/net/ethernet directory, you’ll find that not many Ethernet drivers (Broadcom bnx2x, Intel i40e and a handful of others) implement it (probably because not many Ethernet hardware devices provide that information which as detailed by @ChrisDavies is only relevant for NICs with more than one port).

You can tell what driver drives your eth0 ethernet device with:

readlink /sys/class/net/eth0/device/driver

Or ls -l /sys/class/net/eth0/device/driver if the readlink applet is not enabled in your build of busybox.

Answered By: Stéphane Chazelas
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.