## knob.bash: primitives for kernel settings files (sysfs, procfs). ## write_knob writes a value into a kernel settings file. ## These files often read back in a different format than they accept ## (`lru_gen/enabled` takes `y` and reads back a hex bitmask), ## so a change is reported when the read-back moved, not by comparing it to VALUE. ## The write happens every time; these files reset at boot anyway, and rewriting a value is harmless. ## ## - @param $1 absolute path of the settings file. ## - @param $2 value to write. write_knob() { if [ "$#" -ne 2 ]; then _pave_error "usage: write_knob PATH VALUE" return 1 fi local path=$1 value=$2 before after _pave_need_abs "$path" || return 1 before=$(<"$path") || return 1 printf '%s\n' "$value" >"$path" || return 1 after=$(<"$path") || return 1 if [ "$before" != "$after" ]; then changed "$path: $before -> $after (wrote $value)" fi }