user2101303
user2101303

Reputation: 43

Create entries in /sys filesystem

I'm trying to add some files in /sys/devices/platform to test my program but looks like the sysfs is not editable. Is there a way I can add/fake a /sys entry?

Upvotes: 4

Views: 1603

Answers (1)

Dougall
Dougall

Reputation: 281

You can probably use a linux kernel module if you want to actually add files there, but I would advise against this for testing a program.

chroot could be used to make a fake filesystem to run your code in, but this is probably excessively complicated.

I'd suggest using a SYS_PATH value, so you could recompile your program for testing and have it look elsewhere.

#ifdef DEBUG
#define SYS_PATH "/home/user/myfakesys"
#else
#define SYS_PATH "/sys"
#endif

...

FILE *f = fopen(SYS_PATH "/devices/platform/...", "wb");

Upvotes: 2

Related Questions