Ok idk how i can use it… but…

  1. Console mknod - make block or character special files
  2. C mknod - create a special or ordinary file

Mknode Console Example

mknod [params] filename filetype [major number] [minor number]

params - you can see all in man ( in this example -m 0777 - set file permission bits)
filename - it filename=)
filetype - type can be 3 types:
p
for a FIFO

b
for a block special file

c
for a character special file\

Major number - devices accordantly doc devices
Minor number - idk…

1
mknod -m 0777 /dev/loop10 b 7 10

Decribe:
Create - /dev/loop10
Type - b (its mean block)
Major number (Device) - 7 (“block Loopback”)
Minor number - 10 (idk how to use it, i think its will be equval loop number) \

1
2
mount -o loop=/dev/loop8 openSUSE-Leap-15.4-DVD-x86_64-Build243.2-Media.iso /mnt
#mount: /mnt: WARNING: source write-protected, mounted read-only

Ok its work.. Also with mknod we can create FIFO

1
mknod -m 777 /home/peter/fifo p

Same:

1
mkfifo /home/peter/fifo

Type - p mean its pipe

We can check it do:

1
tail -f /home/peter/fifo > /tmp/testfifo.log
1
echo "OLOLOL" >> /home/peter/fifo
1
cat /tmp/testfifo.log

We can see - OLOLOL

Remove fifo

1
unlink /home/peter/fifo

Mknode C Example

Ok there we need client and server:

client.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <stdlib.h>

#define FIFO_FILE  "myFifo"

int main(int argc, char *argv[])
{
        FILE *fp;

        if ( argc != 2 ) {
                printf("USAGE: fifoclient [string]\n");
                exit(1);
        }

        if((fp = fopen(FIFO_FILE, "w")) == NULL) {
                perror("fopen");
                exit(1);
        }

        fputs(argv[1], fp);

        fclose(fp);
        return(0);
}

server.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>

#define FIFO_FILE "myFifo"

int main(void)
{
        FILE *fp;
        char readbuf[80];

        /* Create the FIFO if it does not exist */
        umask(0);
        mknod(FIFO_FILE, S_IFIFO|0667, 0);

        while(1)
        {
                fp = fopen(FIFO_FILE, "r");
                fgets(readbuf, 80, fp);
                printf("Received string: %s\n", readbuf);
                fclose(fp);
        }

        return(0);
}

Start Server

1
2
gcc server.c -o server
./server

Start Client

1
2
gcc client.c -o client
./client ololol

In server terminal we can se ololol

Links

  1. how-to-add-more-dev-loop-devices-on-fedora-19
  2. komanda-mknod
  3. creating-fifo-in-c-using-mknod-system-call