mirror of
https://codeberg.org/wonky/udev-usb-sync.git
synced 2024-09-19 23:30:37 +02:00
Compare commits
3 commits
9e8236c88b
...
0130785971
Author | SHA1 | Date | |
---|---|---|---|
|
0130785971 | ||
|
e1ec0b47c3 | ||
|
1fe2ddca75 |
4 changed files with 37 additions and 60 deletions
19
.SRCINFO
19
.SRCINFO
|
@ -1,19 +0,0 @@
|
|||
pkgbase = udev-usb-sync
|
||||
pkgdesc = Fine tune write cache and impose buffer limits when USB storage device is plugged
|
||||
pkgver = 0.9
|
||||
pkgrel = 3
|
||||
url = https://codeberg.org/wonky/udev-usb-sync
|
||||
install = udev-usb-sync.install
|
||||
arch = any
|
||||
license = MIT
|
||||
depends = hdparm
|
||||
depends = bc
|
||||
backup = etc/udev-usb-sync/udev-usb-sync.conf
|
||||
source = 99-usb-sync.rules
|
||||
source = udev-usb-sync
|
||||
source = udev-usb-sync.conf
|
||||
sha256sums = fde345c047bbb3fb51cb2a66b6106a883a413638b760e0e8087c692a30f87514
|
||||
sha256sums = bdc35135e6f8074890a911a501ca4fb3e6a7888963b51c3a1edb98c23bb62ec2
|
||||
sha256sums = ec26baede73e94f9cfab77cd5aa6e0ffebcc413ff657a4e98eae6c9e2145655e
|
||||
|
||||
pkgname = udev-usb-sync
|
|
@ -31,13 +31,17 @@
|
|||
# : @linux-aarhus (Manjaro 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"
|
||||
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"
|
||||
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"
|
||||
ATTRS{bDeviceClass}!="09", ATTRS{speed}=="12", RUN+="/usr/bin/udev-usb-sync %k %s{speed}", GOTO="usb_limit_write_cache_end"
|
||||
PROGRAM+="/usr/bin/uname -r"
|
||||
|
||||
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"
|
||||
|
||||
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"
|
10
PKGBUILD
10
PKGBUILD
|
@ -1,17 +1,17 @@
|
|||
# Maintainer: root.nix.dk
|
||||
pkgname='udev-usb-sync'
|
||||
pkgver=0.9
|
||||
pkgrel=3
|
||||
pkgver=0.12
|
||||
pkgrel=1
|
||||
pkgdesc='Fine tune write cache and impose buffer limits when USB storage device is plugged'
|
||||
arch=('any')
|
||||
url='https://codeberg.org/wonky/udev-usb-sync'
|
||||
url='https://gitlab.manjaro.org/fhdk/udev-usb-sync'
|
||||
license=('MIT')
|
||||
depends=('hdparm' 'bc')
|
||||
backup=("etc/${pkgname}/${pkgname}.conf")
|
||||
install="${pkgname}.install"
|
||||
source=('99-usb-sync.rules' 'udev-usb-sync' 'udev-usb-sync.conf')
|
||||
sha256sums=('fde345c047bbb3fb51cb2a66b6106a883a413638b760e0e8087c692a30f87514'
|
||||
'bdc35135e6f8074890a911a501ca4fb3e6a7888963b51c3a1edb98c23bb62ec2'
|
||||
sha256sums=('b1463dc2f102b31d16b8e9b3ba39356bdf6ec791b6b2034f3ded5553f4c31f8a'
|
||||
'741fbc305c151c88dad3bdb2203289855c7dc2a2a7d581c8e325dd8ed286c6dc'
|
||||
'ec26baede73e94f9cfab77cd5aa6e0ffebcc413ff657a4e98eae6c9e2145655e')
|
||||
|
||||
package() {
|
||||
|
|
|
@ -41,30 +41,18 @@ CONFIG='/etc/udev-usb-sync/udev-usb-sync.conf'
|
|||
|
||||
BLOCKDEVICE="$1"
|
||||
SPEED="$2"
|
||||
KERNEL_MAJOR_VERSION=$(uname -r | awk -F'.' '{print $1}')
|
||||
|
||||
# disable write cache for device if possible
|
||||
[[ -n $(which hdparm) ]] && $(which hdparm) -W 0 /dev/$BLOCKDEVICE
|
||||
[[ -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 2.6
|
||||
# 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 ]]; then
|
||||
# the following rules is introduced with kernel 6.1
|
||||
# https://docs.kernel.org/admin-guide/abi-testing.html#abi-sys-class-bdi-bdi-strict-limit
|
||||
# the following rules is introduced with kernel 6.2
|
||||
# https://docs.kernel.org/admin-guide/abi-testing.html#abi-sys-class-bdi-bdi-max-bytes
|
||||
|
||||
# apply strict limit
|
||||
echo 1 > /sys/block/$BLOCKDEVICE/bdi/strict_limit
|
||||
|
||||
if [[ ${AUTOCALC} == 0 ]]; then
|
||||
# apply 16M as max_bytes
|
||||
case $AUTOCALC in
|
||||
0) # apply 16M as 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"}
|
||||
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
|
||||
|
@ -74,5 +62,9 @@ elif [[ $KERNEL_MAJOR_VERSION -ge 6 ]]; then
|
|||
# 85196800
|
||||
# apply calculated buffer size
|
||||
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