summaryrefslogtreecommitdiff
path: root/bcache-register.c
blob: ae3a2babea7552725e9d29a33630854bb4b7de18 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
/*
 * Author: Simon Gomizelj <simongmzlj@gmail.com>
 *
 * GPLv2
 */

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

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

    if (argc != 2)
    {
        fprintf(stderr, "bcache-register takes exactly one argument\n");
        return 1;
    }

    fd = open("/sys/fs/bcache/register", O_WRONLY);
    if (fd < 0)
    {
        perror("Error opening /sys/fs/bcache/register");
        fprintf(stderr, "The bcache kernel module must be loaded\n");
        return 1;
    }

    if (dprintf(fd, "%s\n", argv[1]) < 0)
    {
        fprintf(stderr, "Error registering %s with bcache: %m\n", argv[1]);
        return 1;
    }

    return 0;
}