Skip to content

Instantly share code, notes, and snippets.

@steveh
Created May 12, 2014 07:30
Show Gist options
  • Save steveh/7356e2ba93af5869f385 to your computer and use it in GitHub Desktop.
Save steveh/7356e2ba93af5869f385 to your computer and use it in GitHub Desktop.
Samba dfree and zfs on Ubuntu 14.04
# File: /etc/samba/smb.conf
dfree command = /usr/local/bin/dfree
# File: /etc/sudoers
ALL ALL = NOPASSWD: /usr/local/bin/zfs-get-used, /usr/local/bin/zfs-get-available
#!/bin/bash
# File: /usr/local/bin/dfree
CUR_PATH=$PWD
FILESYSTEM=$(df -PT $CUR_PATH | tail -1 | awk '{print $2}')
if [ $FILESYSTEM = 'zfs' ]; then
USED=$(sudo zfs-get-used $CUR_PATH)
AVAIL=$(sudo zfs-get-available $CUR_PATH)
AVAIL_KB=$(expr $AVAIL / 1024)
TOTAL_KB=$(expr $USED / 1024 + $AVAIL / 1024)
echo $TOTAL_KB $AVAIL_KB
else
df -PT $CUR_PATH | tail -1 | awk '{print $3" "$5}'
fi
#!/bin/bash
# File: /usr/local/bin/zfs-get-available
zfs get -o value -Hp available $1
#!/bin/bash
# File: /usr/local/bin/zfs-get-used
zfs get -o value -Hp used $1
@YSpoof
Copy link

YSpoof commented Oct 12, 2023

Also works on AlpineLinux

Kernel: 6.1.56-0-lts
Samba: 4.18.5-r0
ZFS: 2.1.11-1
Client: Win 11 Pro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment