Skip to content

Commit

Permalink
storage/drivers/driver_btrfs_utils: properly calculate BTRFS_IOC_SET_…
Browse files Browse the repository at this point in the history
…RECEIVED_SUBVOL

Signed-off-by: Alexander Mikhalitsyn <[email protected]>
  • Loading branch information
mihalicyn committed May 31, 2024
1 parent 31d81ce commit 8e4d7cb
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions lxd/storage/drivers/driver_btrfs_utils.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
package drivers

/*
#include <linux/types.h>
#include <sys/ioctl.h>
#include <stdint.h>
// definitions are borrowed from include/uapi/linux/btrfs.h
#define BTRFS_IOCTL_MAGIC 0x94
#define BTRFS_UUID_SIZE 16
struct btrfs_ioctl_timespec {
__u64 sec;
__u32 nsec;
};
struct btrfs_ioctl_received_subvol_args {
char uuid[BTRFS_UUID_SIZE];
__u64 stransid;
__u64 rtransid;
struct btrfs_ioctl_timespec stime;
struct btrfs_ioctl_timespec rtime;
__u64 flags;
__u64 reserved[16];
};
#define BTRFS_IOC_SET_RECEIVED_SUBVOL _IOWR(BTRFS_IOCTL_MAGIC, 37, \
struct btrfs_ioctl_received_subvol_args)
*/
import "C"

import (
"bufio"
"bytes"
Expand Down Expand Up @@ -61,8 +93,7 @@ func setReceivedUUID(path string, UUID string) error {

copy(args.uuid[:], binUUID)

// 0xC0C09425 = _IOWR(BTRFS_IOCTL_MAGIC, 37, struct btrfs_ioctl_received_subvol_args)
_, _, errno := unix.Syscall(unix.SYS_IOCTL, f.Fd(), 0xC0C09425, uintptr(unsafe.Pointer(&args)))
_, _, errno := unix.Syscall(unix.SYS_IOCTL, f.Fd(), C.BTRFS_IOC_SET_RECEIVED_SUBVOL, uintptr(unsafe.Pointer(&args)))
if errno != 0 {
return fmt.Errorf("Failed setting received UUID: %w", unix.Errno(errno))
}
Expand Down

0 comments on commit 8e4d7cb

Please sign in to comment.