mirror of
https://codeberg.org/wonky/udev-usb-sync.git
synced 2024-09-19 23:30:37 +02:00
update kernel check
This commit is contained in:
parent
e1ec0b47c3
commit
0130785971
3 changed files with 35 additions and 45 deletions
|
@ -31,13 +31,17 @@
|
||||||
# : @linux-aarhus (Manjaro Forum)
|
# : @linux-aarhus (Manjaro Forum)
|
||||||
# inspired by : @kwg (EndeavourOS Forum)
|
# inspired by : @kwg (EndeavourOS Forum)
|
||||||
|
|
||||||
KERNEL!="sd[a-z]", GOTO="usb_limit_write_cache_end"
|
KERNEL!="sd[a-z]|sd[a-z][0-9]", GOTO="usb_limit_write_cache_end"
|
||||||
ENV{ID_USB_TYPE}!="disk", GOTO="usb_limit_write_cache_end"
|
ENV{ID_USB_TYPE}!="disk", GOTO="usb_limit_write_cache_end"
|
||||||
ACTION!="add|change", GOTO="usb_limit_write_cache_end"
|
ACTION!="add|change", GOTO="usb_limit_write_cache_end"
|
||||||
|
|
||||||
ATTRS{bDeviceClass}!="09", ATTRS{speed}=="10000", RUN+="/usr/bin/udev-usb-sync %k %s{speed}", GOTO="usb_limit_write_cache_end"
|
PROGRAM+="/usr/bin/uname -r"
|
||||||
ATTRS{bDeviceClass}!="09", ATTRS{speed}=="5000", RUN+="/usr/bin/udev-usb-sync %k %s{speed}", GOTO="usb_limit_write_cache_end"
|
|
||||||
ATTRS{bDeviceClass}!="09", ATTRS{speed}=="480", RUN+="/usr/bin/udev-usb-sync %k %s{speed}", GOTO="usb_limit_write_cache_end"
|
RESULT=="4*|5*|6.1.*", ENV{ID_FS_USAGE}=="filesystem", ENV{UDISKS_MOUNT_OPTIONS_DEFAULTS}+="sync", ENV{UDISKS_MOUNT_OPTIONS_ALLOW}+="sync", GOTO="usb_limit_write_cache_end"
|
||||||
ATTRS{bDeviceClass}!="09", ATTRS{speed}=="12", RUN+="/usr/bin/udev-usb-sync %k %s{speed}", GOTO="usb_limit_write_cache_end"
|
|
||||||
|
RESULT!="4*|5*|6.1.*", ATTRS{bDeviceClass}!="09", ATTRS{speed}=="10000", RUN+="/usr/bin/udev-usb-sync %k %s{speed}", GOTO="usb_limit_write_cache_end"
|
||||||
|
RESULT!="4*|5*|6.1.*", ATTRS{bDeviceClass}!="09", ATTRS{speed}=="5000", RUN+="/usr/bin/udev-usb-sync %k %s{speed}", GOTO="usb_limit_write_cache_end"
|
||||||
|
RESULT!="4*|5*|6.1.*", ATTRS{bDeviceClass}!="09", ATTRS{speed}=="480", RUN+="/usr/bin/udev-usb-sync %k %s{speed}", GOTO="usb_limit_write_cache_end"
|
||||||
|
RESULT!="4*|5*|6.1.*", ATTRS{bDeviceClass}!="09", ATTRS{speed}=="12", RUN+="/usr/bin/udev-usb-sync %k %s{speed}", GOTO="usb_limit_write_cache_end"
|
||||||
|
|
||||||
LABEL="usb_limit_write_cache_end"
|
LABEL="usb_limit_write_cache_end"
|
8
PKGBUILD
8
PKGBUILD
|
@ -1,17 +1,17 @@
|
||||||
# Maintainer: root.nix.dk
|
# Maintainer: root.nix.dk
|
||||||
pkgname='udev-usb-sync'
|
pkgname='udev-usb-sync'
|
||||||
pkgver=0.11
|
pkgver=0.12
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc='Fine tune write cache and impose buffer limits when USB storage device is plugged'
|
pkgdesc='Fine tune write cache and impose buffer limits when USB storage device is plugged'
|
||||||
arch=('any')
|
arch=('any')
|
||||||
url='https://codeberg.org/wonky/udev-usb-sync'
|
url='https://gitlab.manjaro.org/fhdk/udev-usb-sync'
|
||||||
license=('MIT')
|
license=('MIT')
|
||||||
depends=('hdparm' 'bc')
|
depends=('hdparm' 'bc')
|
||||||
backup=("etc/${pkgname}/${pkgname}.conf")
|
backup=("etc/${pkgname}/${pkgname}.conf")
|
||||||
install="${pkgname}.install"
|
install="${pkgname}.install"
|
||||||
source=('99-usb-sync.rules' 'udev-usb-sync' 'udev-usb-sync.conf')
|
source=('99-usb-sync.rules' 'udev-usb-sync' 'udev-usb-sync.conf')
|
||||||
sha256sums=('fde345c047bbb3fb51cb2a66b6106a883a413638b760e0e8087c692a30f87514'
|
sha256sums=('b1463dc2f102b31d16b8e9b3ba39356bdf6ec791b6b2034f3ded5553f4c31f8a'
|
||||||
'49f7c0617c986c52d009ea76afb22af2c57d6655b285ddc0aea81fb2ba4c44a0'
|
'741fbc305c151c88dad3bdb2203289855c7dc2a2a7d581c8e325dd8ed286c6dc'
|
||||||
'ec26baede73e94f9cfab77cd5aa6e0ffebcc413ff657a4e98eae6c9e2145655e')
|
'ec26baede73e94f9cfab77cd5aa6e0ffebcc413ff657a4e98eae6c9e2145655e')
|
||||||
|
|
||||||
package() {
|
package() {
|
||||||
|
|
|
@ -41,36 +41,18 @@ CONFIG='/etc/udev-usb-sync/udev-usb-sync.conf'
|
||||||
|
|
||||||
BLOCKDEVICE="$1"
|
BLOCKDEVICE="$1"
|
||||||
SPEED="$2"
|
SPEED="$2"
|
||||||
KERNEL_MAJOR_VERSION=$(uname -r | awk -F'.' '{print $1}')
|
|
||||||
KERNEL_MINOR_VERSION=$(uname -r | awk -F'.' '{print $2}')
|
|
||||||
|
|
||||||
# disable write cache for device if possible
|
# disable write cache for device if possible
|
||||||
[[ -n $(which hdparm) ]] && $(which hdparm) -W 0 /dev/$BLOCKDEVICE > /dev/null
|
[[ -n $(which hdparm) ]] && $(which hdparm) -W 0 /dev/$BLOCKDEVICE > /dev/null
|
||||||
|
|
||||||
if [[ $KERNEL_MAJOR_VERSION -le 5 ]]; then
|
# the following rules is introduced with kernel 6.2
|
||||||
# the following rules is introduced with kernel 2.6
|
# https://docs.kernel.org/admin-guide/abi-testing.html#abi-sys-class-bdi-bdi-max-bytes
|
||||||
# https://docs.kernel.org/admin-guide/abi-testing.html#abi-sys-class-bdi-bdi-max-ratio
|
|
||||||
# 1% of available RAM -> 8046522kB -> 80.465kB -> 80MB
|
|
||||||
echo 1 > /sys/block/$BLOCKDEVICE/bdi/max_ratio
|
|
||||||
|
|
||||||
elif [[ $KERNEL_MAJOR_VERSION -ge 6 ]] && [[ $KERNEL_MINOR_VERSION -le 2 ]]; then
|
case $AUTOCALC in
|
||||||
# 1% of available RAM -> 8046522kB -> 80.465kB -> 80MB
|
0) # apply 16M as max_bytes
|
||||||
echo 1 > /sys/block/$BLOCKDEVICE/bdi/max_ratio
|
|
||||||
|
|
||||||
elif [[ $KERNEL_MAJOR_VERSION -ge 6 ]] && [[ $KERNEL_MINOR_VERSION -ge 2 ]]; then
|
|
||||||
# the following rules is introduced with kernel 6.2
|
|
||||||
# https://docs.kernel.org/admin-guide/abi-testing.html#abi-sys-class-bdi-bdi-strict-limit
|
|
||||||
# https://docs.kernel.org/admin-guide/abi-testing.html#abi-sys-class-bdi-bdi-max-bytes
|
|
||||||
# Turning strictlimit on has no visible effect if max_ratio is equal to 100%.
|
|
||||||
echo 50 > /sys/block/$BLOCKDEVICE/bdi/max_ratio
|
|
||||||
# apply strict limit
|
|
||||||
echo 1 > /sys/block/$BLOCKDEVICE/bdi/strict_limit
|
|
||||||
|
|
||||||
if [[ ${AUTOCALC} == 0 ]]; then
|
|
||||||
# apply 16M as max_bytes
|
|
||||||
echo 16777216 > /sys/block/$BLOCKDEVICE/bdi/max_bytes
|
echo 16777216 > /sys/block/$BLOCKDEVICE/bdi/max_bytes
|
||||||
elif [[ ${AUTOCALC} == 1 ]]; then
|
;;
|
||||||
BUFFER_TIME=${BUFFER_TIME:-"0.05"}
|
1) BUFFER_TIME=${BUFFER_TIME:-"0.05"}
|
||||||
SAFETY_FACTOR=${SAFETY_FACTOR:-"1.3"}
|
SAFETY_FACTOR=${SAFETY_FACTOR:-"1.3"}
|
||||||
BUFFER_SIZE=$(printf '%.0f' `echo "( ($SPEED / 8) * $BUFFER_TIME * $SAFETY_FACTOR) * 1024 * 1024" | bc`)
|
BUFFER_SIZE=$(printf '%.0f' `echo "( ($SPEED / 8) * $BUFFER_TIME * $SAFETY_FACTOR) * 1024 * 1024" | bc`)
|
||||||
# for x in 12 480 5000 10000; do echo -n "$x -> " ;printf "%.0f\n" ` echo "(($x / 8) * 0.05 * 1.3) * 1024 * 1024" | bc`; done
|
# for x in 12 480 5000 10000; do echo -n "$x -> " ;printf "%.0f\n" ` echo "(($x / 8) * 0.05 * 1.3) * 1024 * 1024" | bc`; done
|
||||||
|
@ -80,5 +62,9 @@ elif [[ $KERNEL_MAJOR_VERSION -ge 6 ]] && [[ $KERNEL_MINOR_VERSION -ge 2 ]]; the
|
||||||
# 85196800
|
# 85196800
|
||||||
# apply calculated buffer size
|
# apply calculated buffer size
|
||||||
echo "$BUFFER_SIZE" > /sys/block/$BLOCKDEVICE/bdi/max_bytes
|
echo "$BUFFER_SIZE" > /sys/block/$BLOCKDEVICE/bdi/max_bytes
|
||||||
fi
|
;;
|
||||||
fi
|
esac
|
||||||
|
|
||||||
|
# https://docs.kernel.org/admin-guide/abi-testing.html#abi-sys-class-bdi-bdi-strict-limit
|
||||||
|
# apply strict limit
|
||||||
|
echo 1 > /sys/block/$BLOCKDEVICE/bdi/strict_limit
|
Loading…
Reference in a new issue