0

Leaving aside the need for that, I wanted to write (create a file) into /sys/devices/pci0000:00/{one-of-the-devices}/.

Running touch a returns touch: cannot touch 'a': Permission denied.
(I read somewhere that giving write permissions to the given folder is not enough — if one of the parent folders in the hierarchy does not have write permissions. I tested that and it does not seem to hold true.)

Anyway, I obviously tried using sudo and even impersonating as root user with sudo su root, but keep getting permission denied.

Does this there are folders in the file system that only kernel space is allowed to write to (as opposed to user space)? Perhaps virtual file systems that the OS refreshes/writes to intermittently? Perhaps the folder is a link and I do not know?

2
  • 1
    It's the x-permission that needs to be present all the way down before you can write (and read) a particular directory). Commented Dec 8, 2021 at 14:26
  • @Henriksupportsthecommunity: thanks for the clarification. Appreciated ! Commented Dec 8, 2021 at 15:27

1 Answer 1

4

Yes, most virtual file systems like /proc and /sys on Linux can’t be used arbitrarily, because they don’t store files, they provide access to objects internal to the kernel. So it’s not that

virtual file systems that the OS refreshes/writes to intermittently

— virtual file systems don’t store data which is refreshed by the kernel; reading from and writing to a virtual file system results in reading from and writing to data in the kernel.

New directories and files appear in /proc and /sys when new underlying data structures are added; trying to create directories and files there is meaningless.

5
  • Thanks ! How do I determine a given path is virtual ? In this case, /sys/devices/... ? Commented Dec 8, 2021 at 15:28
  • I think, in general, you can't, because there's a potentially infinite amount of file systems, and there's no clear distinction what is a "virtual" and a "normal" file system (is overlayfs virtual? What about tmpfs? How is a bind mount counted?…). But if you want to know on a "normal" system, you just check what mount a path is under, and check whether the file system there is among the "well-known" "regular storage" file systems (ext2/3/4, xfs, btrfs, reiserfs, zfs, vfat, exfat, ntfs, hfs, nfs, cifs, squashfs, iso9669, …). Commented Dec 8, 2021 at 15:47
  • generally, even more, your question is "how can I make sure I can create a file on a file system": and guess what, you can't create a file on a read-only file system, even if it's 100% backed by a storage device, and you can't create a file on a file system where you don't have permission to do so, or on a network filesystem if the server doesn't feel like it today, and you can't create a file on a file system that's full, and you can't create a file on a file system if SELinux decides that you're a rogue process, and … so, "virtual" is really not your problem. Just check whether you can. Commented Dec 8, 2021 at 15:49
  • 1
    @Veverke you need to determine what the closest mount point is, and then the corresponding file system type, and look it up in /proc/filesystems. If the relevant line in /proc/filesystems says nodev, then it is a virtual file system. Some virtual file systems do allow arbitrary storage (e.g. tmpfs and network file systems) but most don’t. Commented Dec 8, 2021 at 15:55
  • Let me rephrase that slightly; nodev means it doesn’t have a local backing device, so it’s either a network file system, a RAM-base file system, or some sort of virtual file system. Commented Dec 8, 2021 at 18:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.