//This program reads /proc/misc, to know what's the device address of device-mapper, since that number is allocated dynamically
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <linux/kdev_t.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

int main(int argcchar **argvchar **envp) {
        FILE *file=fopen("/proc/misc""r");
        char *buf=NULL;
        size_t len=-1;
        //Use getline for easier coding
        while(getline(&buf, &lenfile)>0) {
                char dev_name[256];
                int dev_nb=-1;
                // /proc/misc is of the form "type number"
                sscanf(buf"\t%d %255s\n", &dev_nbdev_name);
                //If the type is device-mapper
                if(strcmp(dev_name"device-mapper")==0) {
                        //Then show the number (and repeat the type in case we forgot what we code)
                        printf("%d:%s\n"dev_nbdev_name);
                        //And create the corresponding device in /dev
                        mknod("/dev/mapper/control"S_IFCHR|0700,MKDEV(/*misc devices */10,dev_nb));
                }
                free(buf);
                buf=NULL;
        }
        fclose(file);
        return 0;
}