mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-23 00:00:02 +03:00
UUIDs
This commit is contained in:
parent
1d895a5a45
commit
7e97901075
3
61-bcache.rules
Normal file
3
61-bcache.rules
Normal file
@ -0,0 +1,3 @@
|
||||
KERNEL=="sd*", ENV{DEVTYPE}=="disk", IMPORT{program}="/sbin/probe-bcache -o udev $tempnode"
|
||||
|
||||
ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}"
|
13
Makefile
13
Makefile
@ -1,15 +1,20 @@
|
||||
|
||||
PREFIX=/usr/local
|
||||
#PREFIX=/usr/local
|
||||
CFLAGS=-O2 -Wall -g
|
||||
|
||||
all: make-bcache
|
||||
all: make-bcache probe-bcache
|
||||
|
||||
clean:
|
||||
rm -f make-bcache bcache-test *.o
|
||||
|
||||
install: make-bcache
|
||||
install: make-bcache probe-bcache
|
||||
install -m0755 make-bcache ${PREFIX}/sbin/
|
||||
install -m0755 bcache-test ${PREFIX}/sbin/
|
||||
install -m0755 probe-bcache ${PREFIX}/sbin/
|
||||
install -m0644 61-bcache.rules /lib/udev/rules.d/
|
||||
install -m0755 initramfs /usr/share/initramfs-tools/hooks/bcache
|
||||
# install -m0755 bcache-test ${PREFIX}/sbin/
|
||||
|
||||
|
||||
bcache-test: LDFLAGS += -lm -lssl -lcrypto
|
||||
make-bcache: LDFLAGS += -luuid
|
||||
probe-bcache: LDFLAGS += -luuid
|
||||
|
29
bcache.h
Normal file
29
bcache.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef _BCACHE_H
|
||||
#define _BCACHE_H
|
||||
|
||||
static const char bcache_magic[] = {
|
||||
0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca,
|
||||
0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81 };
|
||||
|
||||
struct cache_sb {
|
||||
uint8_t magic[16];
|
||||
#define CACHE_CLEAN 1
|
||||
#define CACHE_SYNC 2
|
||||
uint32_t version;
|
||||
uint16_t block_size; /* sectors */
|
||||
uint16_t bucket_size; /* sectors */
|
||||
uint32_t journal_start; /* buckets */
|
||||
uint32_t first_bucket; /* start of data */
|
||||
uint64_t nbuckets; /* device size */
|
||||
uint64_t btree_root;
|
||||
uint16_t btree_level;
|
||||
uint16_t _pad[3];
|
||||
uint8_t uuid[16];
|
||||
};
|
||||
|
||||
struct bucket_disk {
|
||||
uint16_t priority;
|
||||
uint8_t generation;
|
||||
} __attribute((packed));
|
||||
|
||||
#endif
|
11
initramfs
Normal file
11
initramfs
Normal file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh -e
|
||||
|
||||
case "$1" in
|
||||
prereqs)
|
||||
echo "udev"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
cp -p /lib/udev/rules.d/61-bcache.rules $DESTDIR/lib/udev/rules.d/
|
||||
cp -p /sbin/probe-bcache $DESTDIR/sbin
|
@ -12,27 +12,9 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
static const char bcache_magic[] = {
|
||||
0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca,
|
||||
0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81 };
|
||||
|
||||
struct cache_sb {
|
||||
uint8_t magic[16];
|
||||
uint32_t version;
|
||||
uint16_t block_size; /* sectors */
|
||||
uint16_t bucket_size; /* sectors */
|
||||
uint32_t journal_start; /* buckets */
|
||||
uint32_t first_bucket; /* start of data */
|
||||
uint64_t nbuckets; /* device size */
|
||||
uint64_t btree_root;
|
||||
uint16_t btree_level;
|
||||
};
|
||||
|
||||
struct bucket_disk {
|
||||
uint16_t priority;
|
||||
uint8_t generation;
|
||||
} __attribute((packed));
|
||||
#include "bcache.h"
|
||||
|
||||
char zero[4096];
|
||||
|
||||
@ -85,12 +67,21 @@ int main(int argc, char **argv)
|
||||
int64_t nblocks, bucketsize = 32, blocksize = 8;
|
||||
int fd, i, c;
|
||||
struct cache_sb sb;
|
||||
char uuid[40];
|
||||
|
||||
while ((c = getopt(argc, argv, "b:")) != -1)
|
||||
uuid_generate(sb.uuid);
|
||||
|
||||
while ((c = getopt(argc, argv, "U:b:")) != -1)
|
||||
switch (c) {
|
||||
case 'b':
|
||||
bucketsize = hatoi(optarg) / 512;
|
||||
break;
|
||||
case 'U':
|
||||
if (uuid_parse(optarg, sb.uuid)) {
|
||||
printf("Bad uuid\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (argc <= optind) {
|
||||
@ -117,6 +108,7 @@ int main(int argc, char **argv)
|
||||
sb.block_size = blocksize;
|
||||
sb.bucket_size = bucketsize;
|
||||
sb.nbuckets = nblocks / sb.bucket_size;
|
||||
uuid_unparse(sb.uuid, uuid);
|
||||
|
||||
do
|
||||
sb.first_bucket = ((--sb.nbuckets * sizeof(struct bucket_disk)) + (24 << 9)) / (sb.bucket_size << 9) + 1;
|
||||
@ -131,12 +123,14 @@ int main(int argc, char **argv)
|
||||
"bucket_size: %u\n"
|
||||
"journal_start: %u\n"
|
||||
"first_bucket: %u\n"
|
||||
"nbuckets: %ju\n",
|
||||
"nbuckets: %ju\n"
|
||||
"UUID: %s\n",
|
||||
sb.block_size,
|
||||
sb.bucket_size,
|
||||
sb.journal_start,
|
||||
sb.first_bucket,
|
||||
sb.nbuckets);
|
||||
sb.nbuckets,
|
||||
uuid);
|
||||
|
||||
/* Zero out priorities */
|
||||
lseek(fd, 4096, SEEK_SET);
|
||||
|
67
probe-bcache.c
Normal file
67
probe-bcache.c
Normal file
@ -0,0 +1,67 @@
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#define __USE_FILE_OFFSET64
|
||||
#define _XOPEN_SOURCE 500
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <linux/fs.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include "bcache.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
bool udev = false;
|
||||
int i, o;
|
||||
extern char *optarg;
|
||||
struct cache_sb sb;
|
||||
char uuid[40];
|
||||
|
||||
while ((o = getopt(argc, argv, "o:")) != EOF)
|
||||
switch (o) {
|
||||
case 'o':
|
||||
if (strcmp("udev", optarg)) {
|
||||
printf("Invalid output format %s\n", optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
udev = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
int fd = open(argv[i], O_RDONLY);
|
||||
if (fd == -1)
|
||||
continue;
|
||||
|
||||
|
||||
if (pread(fd, &sb, sizeof(sb), 4096) != sizeof(sb))
|
||||
continue;
|
||||
|
||||
if (memcmp(sb.magic, bcache_magic, 16))
|
||||
continue;
|
||||
|
||||
uuid_unparse(sb.uuid, uuid);
|
||||
|
||||
if (udev)
|
||||
printf("ID_FS_UUID=%s\n"
|
||||
"ID_FS_UUID_ENC=%s\n"
|
||||
"ID_FS_TYPE=bcache\n",
|
||||
uuid, uuid);
|
||||
else
|
||||
printf("%s: UUID=\"\" TYPE=\"bcache\"\n", uuid);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user