In my initramfs.cpio I have only these directories:
root@localhost extract]# ls
dev init tmp sys
dev has console and sys is empty.
init is a binary corresponding to program that I discussed in Accessing GPIO after kernel boots.
Now in the same GPIO program I would like to write code to mount a /sys. I understand it can be mounted using mount:
mount -t sysfs none /sys
How do I write a C program that will implement the above line. Please note that I do not have a file system; initramfs.cpio has empty folders: /sys, /tmp. I can put more empty folder if required. But I cannot put full file system.
My main intention To access GPIO using this program or otherwise, but without using a full file system. I dont need any other thing to run, but just want GPIO access (and LED blink)
mount() attaches the filesystem specified by source (which is often a pathname referring to a device, but can also be the pathname of a directory or file, or a dummy string) to the location (a directory or file) specified by the pathname in target .
You can mount NFS file system resources by using a client-side service called automounting (or AutoFS), which enables a system to automatically mount and unmount NFS resources whenever you access them. The resource remains mounted as long as you remain in the directory and are using a file.
Mounts all file systems specified in the /etc/vfstab file. The mountall command is run automatically when entering multiuser run states. Unmounts file systems and remote resources. Unmounts all file systems specified in the /etc/vfstab file.
Typically, a mount point is an empty directory. For instance, on a UNIX system, a file system containing a user's home directories might be mounted as /home; then, to access the directory structure within that file system, we could precede the directory names with ftiome, as in /homc/janc.
You use the mount(2)
system call. From the manpage:
SYNOPSIS
#include <sys/mount.h> int mount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *data);
So, in your C code, that'd look something like:
#include <sys/mount.h>
/* ... */
void mount_sys() {
if (0 != mount("none", "/sys", "sysfs", 0, "")) {
/* handle error */
}
}
(That last empty string is where you'd pass mount options, but AFAIK sysfs doesn't take any.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With