File: bcache-register.c

package info (click to toggle)
bcache-tools 1.0.8-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 204 kB
  • sloc: ansic: 1,127; sh: 52; makefile: 30
file content (37 lines) | stat: -rw-r--r-- 691 bytes parent folder | download | duplicates (3)
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;
}