diff --git a/sbin/devd/apple.conf b/sbin/devd/apple.conf index 0729a9c86e7a..0a9143f7b5a5 100644 --- a/sbin/devd/apple.conf +++ b/sbin/devd/apple.conf @@ -1,80 +1,80 @@ # $FreeBSD$ # # PowerPC Apple specific devd events # Keyboard power key notify 0 { match "system" "PMU"; match "subsystem" "Button"; action "shutdown -p now"; }; # PowerBook and iBook lid close. notify 0 { match "system" "PMU"; match "subsystem" "lid"; match "type" "close"; action "shutdown -p now"; }; # The next blocks enable brightness hotkeys that can be found on Apple laptops notify 0 { match "system" "PMU"; match "subsystem" "keys"; match "type" "brightness"; match "notify" "down"; action "sysctl dev.backlight.0.level=\ $(expr `sysctl -n dev.backlight.0.level` - 10)"; }; notify 0 { match "system" "PMU"; match "subsystem" "keys"; match "type" "brightness"; match "notify" "up"; action "sysctl dev.backlight.0.level=\ $(expr `sysctl -n dev.backlight.0.level` + 10)"; }; # The next blocks enable volume hotkeys that can be found on Apple laptops notify 0 { match "system" "PMU"; match "subsystem" "keys"; match "type" "mute"; action "mixer vol.mute=^"; }; notify 0 { match "system" "PMU"; match "subsystem" "keys"; match "type" "volume"; match "notify" "down"; - action "mixer vol.volume=-10"; + action "mixer vol.volume=-10%"; }; notify 0 { match "system" "PMU"; match "subsystem" "keys"; match "type" "volume"; match "notify" "up"; - action "mixer vol.volume=+10"; + action "mixer vol.volume=+10%"; }; # Eject key notify 0 { match "system" "PMU"; match "subsystem" "keys"; match "type" "eject"; action "camcontrol eject cd0"; }; # Equivalent to the ACPI/ACAD notify notify 10 { match "system" "PMU"; match "subsystem" "POWER"; match "type" "ACLINE"; action "service power_profile $notify"; }; diff --git a/sbin/devd/asus.conf b/sbin/devd/asus.conf index eed369f6ca4d..0074e7a7c55f 100644 --- a/sbin/devd/asus.conf +++ b/sbin/devd/asus.conf @@ -1,74 +1,74 @@ # $FreeBSD$ # # ASUS specific devd events # The next blocks enable volume hotkeys that can be found on the Asus laptops notify 0 { match "system" "ACPI"; match "subsystem" "ASUS"; match "notify" "0x32"; action "mixer vol.volume=0"; }; notify 0 { match "system" "ACPI"; match "subsystem" "ASUS"; match "notify" "0x31"; - action "mixer vol.volume=-10"; + action "mixer vol.volume=-10%"; }; notify 0 { match "system" "ACPI"; match "subsystem" "ASUS"; match "notify" "0x30"; - action "mixer vol.volume=+10"; + action "mixer vol.volume=+10%"; }; # The next blocks enable volume hotkeys that can be found on the Asus EeePC notify 0 { match "system" "ACPI"; match "subsystem" "ASUS-Eee"; match "notify" "0x13"; action "mixer vol.volume=0"; }; notify 0 { match "system" "ACPI"; match "subsystem" "ASUS-Eee"; match "notify" "0x14"; - action "mixer vol.volume=-10"; + action "mixer vol.volume=-10%"; }; notify 0 { match "system" "ACPI"; match "subsystem" "ASUS-Eee"; match "notify" "0x15"; - action "mixer vol.volume=+10"; + action "mixer vol.volume=+10%"; }; # Enable user hotkeys that can be found on the Asus EeePC # The four keys above the keyboard notify 0x1a through to 0x1d respectively #notify 0 { # match "system" "ACPI"; # match "subsystem" "ASUS-Eee"; # match "notify" "0x1a"; # action ""; #}; #notify 0 { # match "system" "ACPI"; # match "subsystem" "ASUS-Eee"; # match "notify" "0x1b"; # action ""; #}; #notify 0 { # match "system" "ACPI"; # match "subsystem" "ASUS-Eee"; # match "notify" "0x1c"; # action ""; #}; #notify 0 { # match "system" "ACPI"; # match "subsystem" "ASUS-Eee"; # match "notify" "0x1d"; # action ""; #}; diff --git a/share/man/man4/acpi_ibm.4 b/share/man/man4/acpi_ibm.4 index 290c7d3b29c1..434a1a7cba2c 100644 --- a/share/man/man4/acpi_ibm.4 +++ b/share/man/man4/acpi_ibm.4 @@ -1,506 +1,506 @@ .\" Copyright (c) 2005 Christian Brueffer .\" Copyright (c) 2005 Markus Brueffer .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" .Dd March 13, 2022 .Dt ACPI_IBM 4 .Os .Sh NAME .Nm acpi_ibm .Nd "ThinkPad ACPI extras driver" .Sh SYNOPSIS To compile this driver into the kernel, place the following line in your kernel configuration file: .Bd -ragged -offset indent .Cd "device acpi_ibm" .Ed .Pp Alternatively, to load the driver as a module at boot time, place the following line in .Xr loader.conf 5 : .Bd -literal -offset indent acpi_ibm_load="YES" .Ed .Sh DESCRIPTION The .Nm driver provides support for hotkeys and other components of ThinkPad laptops. The main purpose of this driver is to provide an interface, accessible via .Xr sysctl 8 and .Xr devd 8 , through which applications can determine the status of various laptop components. .Pp While the .Xr sysctl 8 interface is enabled automatically after loading the driver, the .Xr devd 8 interface has to be enabled explicitly, as it may alter the default action of certain keys. This is done by setting the .Va events sysctl as described below. Specifying which keys should generate events is done by setting a bitmask, whereas each bit represents one key or key combination. This bitmask, accessible via the .Va eventmask sysctl, is set to .Va availmask by default, a value representing all possible keypress events on the specific ThinkPad model. .Ss Xr devd 8 Events Hotkey events received by .Xr devd 8 provide the following information: .Pp .Bl -tag -width "subsystem" -offset indent -compact .It system .Qq Li ACPI .It subsystem .Qq Li IBM .It type The source of the event in the ACPI namespace. The value depends on the model. .It notify Event code (see below). .El .Pp Depending on the ThinkPad model, event codes may vary. On a ThinkPad T41p these are as follows: .Pp .Bl -tag -width "subsystem" -offset indent -compact .It Li 0x01 Fn + F1 .It Li 0x02 Fn + F2 .It Li 0x03 Fn + F3 (LCD backlight) .It Li 0x04 Fn + F4 (Suspend to RAM) .It Li 0x05 Fn + F5 (Bluetooth) .It Li 0x06 Fn + F6 .It Li 0x07 Fn + F7 (Screen expand) .It Li 0x08 Fn + F8 .It Li 0x09 Fn + F9 .It Li 0x0a Fn + F10 .It Li 0x0b Fn + F11 .It Li 0x0c Fn + F12 (Suspend to disk) .It Li 0x0d Fn + Backspace .It Li 0x0e Fn + Insert .It Li 0x0f Fn + Delete .It Li 0x10 Fn + Home (Brightness up) .It Li 0x11 Fn + End (Brightness down) .It Li 0x12 Fn + PageUp (ThinkLight) .It Li 0x13 Fn + PageDown .It Li 0x14 Fn + Space (Zoom) .It Li 0x15 Volume Up .It Li 0x16 Volume Down .It Li 0x17 Mute .It Li 0x18 Access IBM Button .El .Ss Xr led 4 Interface The .Nm driver provides a .Xr led 4 interface for the ThinkLight. The ThinkLight can be made to blink by writing .Tn ASCII strings to the .Pa /dev/led/thinklight device. .Sh SYSCTL VARIABLES The following sysctls are currently implemented: .Bl -tag -width indent .It Va dev.acpi_ibm.0.initialmask (read-only) Bitmask of ACPI events before the .Nm driver was loaded. .It Va dev.acpi_ibm.0.availmask (read-only) Bitmask of all supported ACPI events. .It Va dev.acpi_ibm.0.events Enable ACPI events and set the .Va eventmask to .Va availmask . Without the .Nm driver being loaded, only the Fn+F4 button generates an ACPI event. .It Va dev.acpi_ibm.0.eventmask Sets the ACPI events which are reported to .Xr devd 8 . Fn+F3, Fn+F4 and Fn+F12 always generate ACPI events, regardless which value .Va eventmask has. Depending on the ThinkPad model, the meaning of different bits in the .Va eventmask may vary. On a ThinkPad T41p this is a bitwise OR of the following: .Pp .Bl -tag -width indent-two -compact .It Li 1 Fn + F1 .It Li 2 Fn + F2 .It Li 4 Fn + F3 (LCD backlight) .It Li 8 Fn + F4 (Suspend to RAM) .It Li 16 Fn + F5 (Bluetooth) .It Li 32 Fn + F6 .It Li 64 Fn + F7 (Screen expand) .It Li 128 Fn + F8 .It Li 256 Fn + F9 .It Li 512 Fn + F10 .It Li 1024 Fn + F11 .It Li 2048 Fn + F12 (Suspend to disk) .It Li 4096 Fn + Backspace .It Li 8192 Fn + Insert .It Li 16384 Fn + Delete .It Li 32768 Fn + Home (Brightness up) .It Li 65536 Fn + End (Brightness down) .It Li 131072 Fn + PageUp (ThinkLight) .It Li 262144 Fn + PageDown .It Li 524288 Fn + Space (Zoom) .It Li 1048576 Volume Up .It Li 2097152 Volume Down .It Li 4194304 Mute .It Li 8388608 Access IBM Button .El .It Va dev.acpi_ibm.0.hotkey (read-only) Status of several buttons. Every time a button is pressed, the respecting bit is toggled. It is a bitwise OR of the following: .Pp .Bl -tag -width indent-two -compact .It Li 1 Home Button .It Li 2 Search Button .It Li 4 Mail Button .It Li 8 Access IBM Button .It Li 16 Zoom .It Li 32 Wireless LAN Button .It Li 64 Video Button .It Li 128 Hibernate Button .It Li 256 ThinkLight Button .It Li 512 Screen Expand .It Li 1024 Brightness Up/Down Button .It Li 2048 Volume Up/Down/Mute Button .El .It Va dev.acpi_ibm.0.lcd_brightness Current brightness level of the display. .It Va dev.acpi_ibm.0.volume Speaker volume. .It Va dev.acpi_ibm.0.mute Indicates, whether the speakers are muted or not. .It Va dev.acpi_ibm.0.mic_mute Indicates, whether the microphone led (present on some model) is on or not. Note that this does not mean that the microphone input is muted. .It Va dev.acpi_ibm.0.thinklight Indicates, whether the ThinkLight keyboard light is activated or not. .It Va dev.acpi_ibm.0.bluetooth Toggle Bluetooth chip activity. .It Va dev.acpi_ibm.0.wlan (read-only) Indicates whether the WLAN chip is active or not. .It Va dev.acpi_ibm.0.fan Indicates whether the fan is in automatic (1) or manual (0) mode. Default is automatic mode. This sysctl should be used with extreme precaution, since disabling automatic fan control might overheat the ThinkPad and lead to permanent damage if the .Va fan_level is not set accordingly. .It Va dev.acpi_ibm.0.fan_level Indicates at what speed the fan should run when being in manual mode. Valid values range from 0 (off) to 7 (max) and 8. Level 8 is used by the driver to set the fan in unthrottled mode. In this mode, the fan is set to spin freely and will quickly reach a very high speed. Use this mode only if absolutely necessary, e.g., if the system has reached its critical temperature and it is about to shut down. The resulting speed differs from model to model. On a T41p this is as follows: .Pp .Bl -tag -width indent-two -compact .It Li 0 off .It Li 1, 2 ~3000 RPM .It Li 3, 4, 5 ~3600 RPM .It Li 6, 7 ~4300 RPM .It Li 8 ~6400 RPM (Full-speed, unthrottled) .El .It Va dev.acpi_ibm.0.fan_speed (read-only) Fan speed in rounds per minute. A few older ThinkPads report the fan speed in levels ranging from 0 (off) to 7 (max). .It Va dev.acpi_ibm.0.thermal (read-only) Shows the readings of up to eight different temperature sensors. Most ThinkPads include six or more temperature sensors but only expose the CPU temperature through .Xr acpi_thermal 4 . Some ThinkPads have the below sensor layout which might vary depending on the specific model: .Pp .Bl -enum -compact .It CPU .It Mini PCI Module .It HDD .It GPU .It Built-in battery .It UltraBay battery .It Built-in battery .It UltraBay battery .El .It Va dev.acpi_ibm.0.handlerevents .Xr devd 8 events handled by .Nm when .Va events is set to 1. Events are specified as a whitespace-separated list of event code in hexadecimal or decimal form. Note that the event maybe handled twice (e.g., Brightness up/down) if ACPI BIOS already handled the event. .El .Pp Defaults for these sysctls can be set in .Xr sysctl.conf 5 . .Sh FILES .Bl -tag -width ".Pa /dev/led/thinklight" .It Pa /dev/led/thinklight ThinkLight .Xr led 4 device node .El .Sh EXAMPLES The following can be added to .Xr devd.conf 5 in order to pass button events to a .Pa /usr/local/sbin/acpi_oem_exec.sh script: .Bd -literal -offset indent notify 10 { match "system" "ACPI"; match "subsystem" "IBM"; action "/usr/local/sbin/acpi_oem_exec.sh $notify ibm"; }; .Ed .Pp A possible .Pa /usr/local/sbin/acpi_oem_exec.sh script might look like: .Bd -literal -offset indent #!/bin/sh # if [ "$1" = "" -o "$2" = "" ] then echo "usage: $0 notify oem_name" exit 1 fi NOTIFY=`echo $1` LOGGER="logger" CALC="bc" BC_PRECOMMANDS="scale=2" ECHO="echo" CUT="cut" MAX_LCD_BRIGHTNESS=7 MAX_VOLUME=14 OEM=$2 DISPLAY_PIPE=/tmp/acpi_${OEM}_display case ${NOTIFY} in 0x05) LEVEL=`sysctl -n dev.acpi_${OEM}.0.bluetooth` if [ "$LEVEL" = "1" ] then sysctl dev.acpi_${OEM}.0.bluetooth=0 MESSAGE="bluetooth disabled" else sysctl dev.acpi_${OEM}.0.bluetooth=1 MESSAGE="bluetooth enabled" fi ;; 0x10|0x11) LEVEL=`sysctl -n dev.acpi_${OEM}.0.lcd_brightness` PERCENT=`${ECHO} "${BC_PRECOMMANDS} ; \\ ${LEVEL} / ${MAX_LCD_BRIGHTNESS} * 100" |\\ ${CALC} | ${CUT} -d . -f 1` MESSAGE="brightness level ${PERCENT}%" ;; 0x12) LEVEL=`sysctl -n dev.acpi_${OEM}.0.thinklight` if [ "$LEVEL" = "1" ] then MESSAGE="thinklight enabled" else MESSAGE="thinklight disabled" fi ;; 0x15|0x16) LEVEL=`sysctl -n dev.acpi_${OEM}.0.volume` PERCENT=`${ECHO} "${BC_PRECOMMANDS} ; \\ ${LEVEL} / ${MAX_VOLUME} * 100" | \\ ${CALC} | ${CUT} -d . -f 1` MESSAGE="volume level ${PERCENT}%" ;; 0x17) LEVEL=`sysctl -n dev.acpi_${OEM}.0.mute` if [ "$LEVEL" = "1" ] then MESSAGE="volume muted" else MESSAGE="volume unmuted" fi ;; 0x1b) LEVEL=`sysctl -n dev.acpi_ibm.0.mic_led` if [ $LEVEL -eq 0 ]; then sysctl dev.acpi_ibm.0.mic_led=1 mixer rec.volume=0 fi if [ $LEVEL -eq 1 ]; then sysctl dev.acpi_ibm.0.mic_led=0 - mixer rec.volume=30 + mixer rec.volume=30% fi ;; *) ;; esac ${LOGGER} ${MESSAGE} if [ -p ${DISPLAY_PIPE} ] then ${ECHO} ${MESSAGE} >> ${DISPLAY_PIPE} & fi exit 0 .Ed .Pp The following example specify that event code 0x04 (Suspend to RAM), 0x10 (Brightness up) and 0x11 (Brightness down) are handled by .Nm . .Bd -literal -offset indent sysctl dev.acpi_ibm.0.handlerevents='0x04 0x10 0x11' .Ed .Pp in .Xr sysctl.conf 5 : .Bd -literal -offset indent dev.acpi_ibm.0.handlerevents=0x04\\ 0x10\\ 0x11 .Ed .Sh SEE ALSO .Xr acpi 4 , .Xr led 4 , .Xr sysctl.conf 5 , .Xr devd 8 , .Xr sysctl 8 .Sh HISTORY The .Nm device driver first appeared in .Fx 6.0 . .Sh AUTHORS .An -nosplit The .Nm driver was written by .An Takanori Watanabe Aq Mt takawata@FreeBSD.org and later mostly rewritten by .An Markus Brueffer Aq Mt markus@FreeBSD.org . This manual page was written by .An Christian Brueffer Aq Mt brueffer@FreeBSD.org and .An Markus Brueffer Aq Mt markus@FreeBSD.org . diff --git a/usr.bin/fortune/datfiles/freebsd-tips b/usr.bin/fortune/datfiles/freebsd-tips index e8fa84e02489..930110a0c3fe 100644 --- a/usr.bin/fortune/datfiles/freebsd-tips +++ b/usr.bin/fortune/datfiles/freebsd-tips @@ -1,845 +1,845 @@ Any user that is a member of the wheel group can use "su -" to simulate a root login. You can add a user to the wheel group by editing /etc/group. -- Konstantinos Konstantinidis % By pressing "Scroll Lock" you can use the arrow keys to scroll backward through the console output. Press "Scroll Lock" again to turn it off. Don't have a "Scroll Lock" key? The "Pause / Break" key acts alike. % Can't remember if you've installed a certain port or not? Try "pkg info -x port_name". % Ever wonder what those numbers after command names were, as in cat(1)? It's the section of the manual the man page is in. "man man" will tell you more. -- David Scheidt % Forget how to spell a word or a variation of a word? Use look portion_of_word_you_know -- Dru % Forget what directory you are in? Type "pwd". -- Dru % Forget when Easter is? Try "ncal -e". If you need the date for Orthodox Easter, use "ncal -o" instead. -- Dru % FreeBSD is started up by the program 'init'. The first thing init does when starting multiuser mode (ie, starting the computer up for normal use) is to run the shell script /etc/rc. By reading /etc/rc and the /etc/rc.d/ scripts, you can learn a lot about how the system is put together, which again will make you more confident about what happens when you do something with it. % Handy bash(1) prompt: PS1="\u@\h \w \!$ " -- David Scheidt % Having trouble using fetch through a firewall? Try setting the environment variable FTP_PASSIVE_MODE to yes, and see fetch(3) for more details. % If other operating systems have damaged your Master Boot Record, you can reinstall it with gpart(8). See "man gpart" for details. % If you accidentally end up inside vi, you can quit it by pressing Escape, colon (:), q (q), bang (!) and pressing return. % If you do not want to get beeps in X11 (X Windows), you can turn them off with xset b off % If you have a CD-ROM drive in your machine, you can make the CD-ROM that is presently inserted available by typing 'mount /cdrom' as root. The CD-ROM will be available under /cdrom/. Remember to do 'umount /cdrom' before removing the CD-ROM (it will usually not be possible to remove the CD-ROM without doing this.) Note: This tip may not work in all configurations. % If you need a reminder to leave your terminal, type "leave +hhmm" where "hhmm" represents in how many hours and minutes you need to leave. -- Dru % If you need to ask a question on the FreeBSD-questions mailing list then https://docs.freebsd.org/en/articles/freebsd-questions contains lots of useful advice to help you get the best results. % If you write part of a filename in tcsh, pressing TAB will show you the available choices when there is more than one, or complete the filename if there's only one match. % If you `set watch = (0 any any)' in tcsh, you will be notified when someone logs in or out of your system. % If you use the C shell, add the following line to the .cshrc file in your home directory to prevent core files from being written to disk: limit coredumpsize 0 -- Dru % If you want df(1) and other commands to display disk sizes in kilobytes instead of 512-byte blocks, set BLOCKSIZE in your environment to 'K'. You can also use 'M' for Megabytes or 'G' for Gigabytes. If you want df(1) to automatically select the best size then use 'df -h'. % If you want to play CDs with FreeBSD, a utility for this is already included. Type 'cdcontrol' then 'help' to learn more. (You may need to set the CDROM environment variable in order to make cdcontrol want to start.) % If you'd like to keep track of applications in the FreeBSD ports tree, take a look at FreshPorts; https://www.freshports.org/ % In order to make fetch (the FreeBSD downloading tool) ask for username/password when it encounters a password-protected web page, you can set the environment variable HTTP_AUTH to 'basic:*'. % In order to search for a string in some files, use 'grep' like this: grep "string" filename1 [filename2 filename3 ...] This will print out the lines in the files that contain the string. grep can also do a lot more advanced searches - type 'man grep' for details. % In order to support national characters for European languages in tools like less without creating other nationalisation aspects, set the environment variable LC_ALL to 'en_US.UTF-8'. % "man firewall" will give advice for building a FreeBSD firewall using ipfw(8). -- David Scheidt % "man hier" will explain the way FreeBSD filesystems are normally laid out. -- David Scheidt % Man pages are divided into section depending on topic. There are 9 different sections numbered from 1 (General Commands) to 9 (Kernel Developer's Manual). You can get an introduction to each topic by typing man intro In other words, to get the intro to general commands, type man 1 intro % "man ports" gives many useful hints about installing FreeBSD ports. % "man security" gives very good advice on how to tune the security of your FreeBSD system. % "man tuning" gives some tips how to tune performance of your FreeBSD system. -- David Scheidt % Need to do a search in a manpage or in a file you've sent to a pager? Use "/search_word". To repeat the same search, type "n" for next or "p" for previous. -- Dru % Need to find the location of a program? Use "locate program_name". -- Dru % Need to leave your terminal for a few minutes and don't want to logout? Use "lock -p". When you return, use your password as the key to unlock the terminal. -- Dru % Need to quickly empty a file? Use ": > filename". -- Dru % Need to quickly return to your home directory? Type "cd". -- Dru % Need to remove all those ^M characters from a DOS file? Try tr -d \\r < dosfile > newfile -- Originally by Dru % Need to see the calendar for this month? Simply type "cal". To see the whole year, type "cal -y". -- Dru % Need to see which daemons are listening for connection requests? Use "sockstat -4l" for IPv4, and "sockstat -l" for IPv4 and IPv6. -- Dru % Need to see your routing table? Type "netstat -rn". The entry with the G flag is your gateway. -- Dru % Nice bash prompt: PS1='(\[$(tput md)\]\t <\w>\[$(tput me)\]) $(echo $?) \$ ' -- Mathieu % Over quota? "du -sh * | sort -h " will give you a sorted list of your directory sizes. -- David Scheidt % nc(1) (or netcat) is useful not only for redirecting input/output to TCP or UDP connections, but also for proxying them with inetd(8). % sh (the default Bourne shell in FreeBSD) supports command-line editing. Just ``set -o emacs'' or ``set -o vi'' to enable it. Use "" key to complete paths. % Simple tcsh prompt: set prompt = '%# ' % The default editor in FreeBSD is vi, which is efficient to use when you have learned it, but somewhat user-unfriendly. To use ee (an easier but less powerful editor) instead, set the environment variable EDITOR to /usr/bin/ee % Time to change your password? Type "passwd" and follow the prompts. -- Dru % To change an environment variable in /bin/sh use: $ VARIABLE="value" $ export VARIABLE % To change an environment variable in tcsh you use: setenv NAME "value" where NAME is the name of the variable and "value" its new value. % To clear the screen, use "clear". To re-display your screen buffer, press the scroll lock key and use your page up button. When you're finished, press the scroll lock key again to get your prompt back. -- Dru % You can press Ctrl-L while in the shell to clear the screen. % To determine whether a file is a text file, executable, or some other type of file, use file filename -- Dru % To do a fast search for a file, try locate filename locate uses a database that is updated every Saturday (assuming your computer is running FreeBSD at the time) to quickly find files based on name only. % To erase a line you've written at the command prompt, use "Ctrl-U". -- Dru % To find out the hostname associated with an IP address, use drill -x IP_address -- Dru % To obtain a neat PostScript rendering of a manual page, use ``-t'' switch of the man(1) utility: ``man -t ''. For example: man -t grep > grep.ps # Save the PostScript version to a file or man -t printf | lp # Send the PostScript directly to printer % To quickly create an empty file, use "touch filename". -- Dru % To read a compressed file without having to first uncompress it, use "zcat" or "zless" to view it. There is also "bzcat", "bzless", "xzcat" and "xzless". -- Dru % To save disk space in your home directory, compress files you rarely use with "gzip filename". -- Dru % To search for files that match a particular name, use find(1); for example find / -name "*GENERIC*" -ls will search '/', and all subdirectories, for files with 'GENERIC' in the name. -- Stephen Hilton % To see all of the directories on your FreeBSD system, type find / -type d | less All the files? find / -type f | less % To see how long it takes a command to run, type the word "time" before the command name. -- Dru % To see how much disk space is left on your UFS partitions, use df -h -- Dru % To see the 10 largest files in a directory or on a UFS partition, use du -h /partition_or_directory_name | sort -rh | head -- Dru % To see the IP addresses currently set on your active interfaces, type "ifconfig -u". -- Dru % To see the last 10 lines of a long file, use "tail filename". To see the first 10 lines, use "head filename". To see new lines as they're appended to a file, use "tail -f filename". -- Dru % To see the last time that you logged in, use lastlogin(8). -- Dru % To see the MAC addresses of the NICs on your system, type ifconfig -a -- Dru % To see the output from when your computer started, run dmesg(8). If it has been replaced with other messages, look at /var/run/dmesg.boot. -- Francisco Reyes % Want colour in your directory listings? Use "ls -G". "ls -F" is also useful, and they can be combined as "ls -FG". % Want to find a specific port? Just type the following under /usr/ports or one of its subdirectories: make search name= or make search key= % Want to know how many words, lines, or bytes are contained in a file? Type "wc filename". -- Dru % Want to see how much virtual memory you're using? Just type "swapinfo" to be shown information about the usage of your swap partitions. % Want to strip UTF-8 BOM(Byte Order Mark) from given files? sed -e '1s/^\xef\xbb\xbf//' < bomfile > newfile % Want to use sed(1) to edit a file in place? Well, to replace every 'e' with an 'o', in a file named 'foo', you can do: sed -i.bak s/e/o/g foo And you'll get a backup of the original in a file named 'foo.bak', but if you want no backup: sed -i '' s/e/o/g foo % When you've made modifications to a file in vi(1) and then find that you can't write it, type ``!rm -f %'' then ``:w!'' to force the write This won't work if you don't have write permissions to the directory and probably won't be suitable if you're editing through a symbolic link. If you have sudo(8) installed and permissions to use it, type ``w ! sudo tee %'' to force a write. % You can adjust the volume of various parts of the sound system in your -computer by typing 'mixer .volume='. To get a list of what +computer by typing 'mixer .volume=%'. To get a list of what you can adjust, just type 'mixer'. % You can automatically download and install binary packages by doing pkg install This will also automatically install the packages that are dependencies for the package you install (ie, the packages it needs in order to work.) % You can change the video mode on all consoles by adding something like the following to /etc/rc.conf: allscreens="80x30" You can use "vidcontrol -i mode | grep T" for a list of supported text modes. -- Konstantinos Konstantinidis % You can disable tcsh's terminal beep if you `set nobeep'. % You can install extra packages for FreeBSD by using the ports system. If you have installed it, you can download, compile, and install software by just typing # cd /usr/ports// # make install && make clean as root. The ports infrastructure will download the software, change it so it works on FreeBSD, compile it, install it, register the installation so it will be possible to automatically uninstall it, and clean out the temporary working space it used. You can remove an installed port you decide you do not want after all by typing # cd /usr/ports// # make deinstall as root. % You can look through a file in a nice text-based interface by typing less filename % You can make a log of your terminal session with script(1). % You can often get answers to your questions about FreeBSD by searching in the FreeBSD mailing list archives at http://freebsd.markmail.org % You can open up a new split-screen window in (n)vi with :N or :E and then use ^w to switch between the two. % You can permanently set environment variables for your shell by putting them in a startup file for the shell. The name of the startup file varies depending on the shell - csh and tcsh uses .login, bash, sh, ksh and zsh use .profile. When using bash, sh, ksh or zsh, don't forget to export the variable. % You can press Ctrl-D to quickly exit from a shell, or logout from a login shell. -- Konstantinos Konstantinidis % You can press up-arrow or down-arrow to walk through a list of previous commands in tcsh. % You can search for documentation on a keyword by typing apropos keyword % You can `set autologout = 30' to have tcsh log you off automatically if you leave the shell idle for more than 30 minutes. % You can use aliases to decrease the amount of typing you need to do to get commands you commonly use. Examples of fairly popular aliases include (in Bourne shell style, as in /bin/sh, bash, ksh, and zsh): alias lf="ls -FA" alias ll="ls -lA" alias su="su -m" In csh or tcsh, these would be alias lf ls -FA alias ll ls -lA alias su su -m To remove an alias, you can usually use 'unalias aliasname'. To list all aliases, you can usually type just 'alias'. % You can use /etc/make.conf to control the options used to compile software on this system. Example entries are in /usr/share/examples/etc/make.conf and in make.conf(5). For options that are set for building FreeBSD's kernel and its world, see src.conf(5). % You can use "pkg info" to see a list of packages you have installed. % You can use the 'fetch' command to retrieve files over ftp, http or https. fetch https://www.FreeBSD.org/images/beastie.png will download the beastie image from the FreeBSD web site. % You can use "whereis" to search standard binary, manual page and source directories for the specified programs. This can be particularly handy when you are trying to find where in the ports tree an application is. Try "whereis firefox" and "whereis whereis". -- Konstantinos Konstantinidis % Want to run the same command again? In many shells (e.g., tcsh, zsh, bash) you can type "!!". % Want to go the directory you were just in? Type "cd -" % Can't delete /usr/obj? Enter "chflags -R noschg /usr/obj" to remove the system immutable flag for all files in /usr/obj. -- Lars Engels % Want to list all files of an installed package? Enter "pkg info -l packagename". -- Lars Engels % Are you looking for a package? Search for it with "pkg search part_of_package_name" -- Lars Engels % If you want to recursively copy a directory preserving file and directory attributes use "cp -a source target" -- Lars Engels % Do you wonder what a terminal program is doing at the moment? dd(1) does not show any throughput? Hit "^T" (Control + t) to send SIGINFO to the process and see what it is doing. -- Lars Engels % Do you want to know which version of FreeBSD you are running? Enter "freebsd-version -ku" to display kernel and userland version. -- Lars Engels % If you want to end one or more processes at a time using a regular expression enter "pkill regex". -- Lars Engels % Do you want to run a program directly after some other process has ended? Use "pwait pid && new_program" -- Lars Engels % When you want your users to be able to reboot or shutdown FreeBSD, add them to the group "operator" and they are allowed to use shutdown(8) and poweroff(8). -- Lars Engels % If you need to create a FAT32 formatted USB thumb drive, find out its devicename running dmesg(8) after inserting it. Then create an MBR schema, a single slice and format it: # gpart create -s MBR ${devicename} # gpart add -t fat32 ${devicename} # newfs_msdos -F 32 -L thumbdrive ${devicename}s1 -- Lars Engels % If you want to get a sorted list of all services that are started when FreeBSD boots, enter "service -e". -- Lars Engels % To easily configure your installed FreeBSD use bsdconfig(8). -- Lars Engels % After you compiled and installed a new version of FreeBSD, use etcupdate(8) to merge configuration updates. Run "etcupdate extract" once when your sources match your running system, then run "etcupdate" after every upgrade and "etcupdate resolve" to resolve any conflicts. -- Lars Engels % Do you want to do a binary upgrade of your running FreeBSD installation? Use freebsd-update(8). To install updates and patches for the running branch use # freebsd-update fetch install To upgrade to a newer release use # freebsd-update upgrade -r ${name_of_release} -- Lars Engels % To run rc scripts in /etc/rc.d and /usr/local/etc/rc.d use service(8). Run "service ${name_of_rc_script} start" to start a daemon and "service ${name_of_rc_script} stop" to stop it. -- Lars Engels % If you don't want to edit /etc/rc.conf directly, use sysrc(8) to add and remove entries. Use "sysrc name=value" to add an entry and "sysrc -x name" to delete an entry. -- Lars Engels % You can upload the dmesg of your system to help developers get an overview of commonly used hardware and peripherals for FreeBSD. Use the curl package to upload it like this: curl -v -d "nickname=$USER" -d "description=FreeBSD/$(uname -m) on \ $(kenv smbios.system.maker) $(kenv smbios.system.product)" -d "do=addd" \ --data-urlencode 'dmesg@/var/run/dmesg.boot' http://dmesgd.nycbug.org/index.cgi % Want to know how much memory (in bytes) your machine has installed? Let sysctl(8) tell you with the following command: sysctl hw.realmem The realmem value is memory before the kernel and modules are loaded, whereas hw.physmem is what is left after they were loaded. The number of active CPUs is displayed using this command: sysctl hw.ncpu -- Benedict Reuschling % When using ZFS as the file system the "df" command is reporting the pool size and not file system sizes. It also does not know about descendent ZFS datasets, snapshots, quotas, and reservations with their individual space usage. Use the built-in "zfs list" command to get a better overview of space usage: zfs list -o space -- Benedict Reuschling % To learn more about what your system is doing, take a look at systat(1). For example, to get various statistics related to virtual memory usage, process scheduling, device interrupts, system name translation caching, and disk I/O, enter the following: systat -vmstat Other values are icmp, icmp6, ifstat, iostat, ip, ip6, netstat, pigs, sctp, swap, tcp, or zarc. You can switch between displays using : and exit back to your shell by typing :quit -- Benedict Reuschling % To set a quota of 10 GB for the user named foo on a ZFS dataset, run the following command: # zfs set userquota@foo=10G pool/home/foo The zfs userspace command can display the quota and current space usage: # zfs userspace pool/home/foo To unset a quota, assign "none" as the value. -- Benedict Reuschling % ZFS can display I/O statistics for a given pool using the iostat subcommand. By default, it will display one line of current activity. To display stats every 5 seconds run the following command (cancel with CTRL+C): zpool iostat 5 To view individual disk activities, specify the -v parameter: zpool iostat -v Of course, both can be combined. For more options, see zpool(8). -- Benedict Reuschling % FreeBSD's top(1) utility displays CPU statistics by default. To display I/O activity for each process instead, run top like this: top -m io -- Benedict Reuschling % ZFS keeps a history of commands run against a specific pool using the history subcommand to zpool: zpool history More details are available using the -i and -l parameters. Note that ZFS will not keep the complete pool history forever and will remove older events in favor of never ones. -- Benedict Reuschling % To display the compression ratio for the ZFS dataset /var/log on the pool mypool, run the following command: zfs get refcompressratio mypool/var/log The refcompressratio will only display the compression ratio for that specific dataset, not the descendant datasets. To include the child datasets, the command looks like this: zfs get compressratio mypool/var -- Benedict Reuschling % You can limit the depth of the displayed datasets in the "zfs list" output using the -d parameter. To display only the first level of datasets below mypool/usr and not the ones deeper than those, run this command: zfs list -d 1 mypool/usr -- Benedict Reuschling % The "zfs list" command can be filtered in multiple ways. To display just the dataset name, use the -o parameter: zfs list -o name mypool/usr More columns and their order can be defined by separating them with commas: zfs list -o mountpoint,name,avail -- Benedict Reuschling % The output of "zfs list" can be sorted by a specific column using -s. To sort the datasets by the "used" column in ascending order, run this command: zfs list -s used To sort in descending order instead, use -S: zfs list -S used -- Benedict Reuschling % To make the "zfs list" output more script-friendly, you can suppress the output of the headers for each column by passing the -H parameter: zfs list -H Another helpful option for script writers is -p, which displays the numbers in non-rounded, exact values: zfs list -p -- Benedict Reuschling % Before deleting a dataset or snapshot, perform a dry run using the -n parameter. This is to make sure you really want to delete just that dataset/snapshot and not any dependent ones. ZFS will display the resulting action when -n is combined with the -v option without actually performing it: zfs destroy -nrv mypool@mysnap Once you are sure this is exactly what you intend to do, remove the -n parameter to execute the destroy operation. -- Benedict Reuschling % You can delete a range of ZFS snapshots (a-z) in multiple ways. The following will delete d and all earlier snapshots: zfs destroy mypool/data@%d To delete d and all later snapshots: zfs destroy mypool/data@d% To delete all dataset snapshots: zfs destroy mypool/data@% Make sure to let ZFS perform a dry run (-n option) first and display (-v) what it would do to confirm that the delete operation is removing exactly what you intended. -- Benedict Reuschling % To set a custom ZFS property on the mypool pool, you need to provide it using the "key1:key2=value" syntax, where the colon (:) is used as the separator and identifier from the built-in ZFS properties: # zfs set warranty:expires=2038-01-19 mypool The custom property is applied to all datasets and can be queried like any built-in properties using zfs get: zfs get warranty:expires mypool To reset the value of a custom property, use the inherit subcommand: # zfs inherit warranty:expires mypool Removing a custom property from a pool is done using the -r flag to the "zfs inherit" command: # zfs inherit -r warranty:expires mypool -- Benedict Reuschling % To delete a range of ZFS snapshots, use the % (percent) character after the full path to the first snapshot that should be included. For example, to simulate deleting snapshots a through (including) d, use this command: # zfs destroy -rvn mypool/tmp@a%d Once you are sure that this is what you want, remove the -n option: # zfs destroy -rv mypool/tmp@a%d -- Benedict Reuschling % You can prevent the removal of a ZFS snapshot by using the hold subcommand. For example, to prevent the snapshot called milestone from deletion, run the following command: # zfs hold milestone_hold mypool/projects@my_milestone The "zfs holds" command will list all current snapshots that are protected this way (-r for a recursive list): # zfs holds -r mypool The TIMESTAMP column in the output of the above command is from when the hold was created, not the snapshot it holds. The "zfs destroy" command will echo a "dataset is busy" message on the console when it encounters a hold. Use "zfs release" to release the hold on the snapshot: # zfs release milestone_hold mypool/projects@my_milestone -- Benedict Reuschling % A user "sender" needs the following permissions set to send a ZFS dataset: # zfs allow -u sender send,snapshot txpool On the receiving side, the user "receiver" requires these permissions: # zfs allow -u receiver compression,mountpoint,mount,create,receive rxpool -- Benedict Reuschling % Don't let your zpool fill up completely by creating a dataset with reservation. # zfs create -o refreservation=<5% of total pool space> /reserved You can always shrink the reserve if you need the space, but your pool will always have space left this way. -- Benedict Reuschling % Sometimes a single slow HDD can cripple the performance of your entire system. You can spot one like this: # gstat -I5s | sort -rn -k9 | head -- Alan Somers % FreeBSD's ps(1) can create a dependency tree based on parent/child relationships between processes, like this: $ ps -d -- Daniel Ebdrup Jensen % It is possible to measure the resident memory set: $ vmstat -o | awk 'NR>1 { t[$7] += $1 } \ END { for (i in t) printf "%s %d\n",i,t[i] }' The rows have the following meaning: df = default (not assigned a specific pager) sw = swap df = virtual vn = vnode ph = heap md = memory device This will be reported in number of pages, so it needs to be multiplied by the page size of the architecture which can be found via: $ sysctl -n hw.pagesize -- Daniel Ebdrup Jensen % To establish a serial connection to anything including a USB device, nothing more than cu(1) is needed: $ cu -s 9600 -l /dev/ttyU0 -- Daniel Ebdrup Jensen % You can control kernel stack(9) traces on ^T (tty info) by setting kern.tty_info_kstacks to 0 (off), 1 (on), or 2 (verbose), e.g.: # sysctl kern.tty_info_kstacks=2 -- Michael Gmelin % diff --git a/usr.bin/usbhidaction/usbhidaction.1 b/usr.bin/usbhidaction/usbhidaction.1 index f50af8fff1ad..54d114925714 100644 --- a/usr.bin/usbhidaction/usbhidaction.1 +++ b/usr.bin/usbhidaction/usbhidaction.1 @@ -1,173 +1,173 @@ .\" $FreeBSD$ .\" $NetBSD: usbhidaction.1,v 1.8 2003/02/25 10:35:59 wiz Exp $ .\" .\" Copyright (c) 2000 The NetBSD Foundation, Inc. .\" All rights reserved. .\" .\" This code is derived from software contributed to The NetBSD Foundation .\" by Lennart Augustsson (lennart@augustsson.net). .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .Dd March 14, 2022 .Dt USBHIDACTION 1 .Os .Sh NAME .Nm usbhidaction .Nd perform actions according to USB HID controls .Sh SYNOPSIS .Nm .Op Fl diev .Fl c Ar config-file .Fl f Ar device .Op Fl p Ar pidfile .Op Fl t Ar tablefile .Ar arg ... .Sh DESCRIPTION The .Nm utility can be used to execute commands when certain values appear on HID controls. The normal operation for this program is to read the configuration file and then become a daemon and execute commands as the HID items specify. If a read from the HID device fails, the program dies; this will make it die when the USB device is unplugged. .Pp The options are as follows: .Bl -tag -width indent .It Fl d Toggle the daemon flag. .It Fl e Instruct .Nm to die early. Useful when specified with multiple verbose options to see how files are parsed. .It Fl i Ignore HID items in the configuration file that do not exist in the device. .It Fl v Be verbose, and do not become a daemon. .It Fl c Ar config-file Specify a path name for the configuration file. .It Fl t Ar tablefile Specify a path name for the HID usage table file. .It Fl f Ar device Specify a path name for the device to operate on. If .Ar device is numeric, it is taken to be the USB HID device number. If it is a relative path, it is taken to be the name of the device under .Pa /dev . An absolute path is taken to be the literal device pathname. .It Fl p Ar pidfile Specify an alternate file in which to store the process ID. .El .Pp The configuration file will be re-read if the process gets a .Dv SIGHUP signal. .Sh CONFIGURATION The configuration file has a very simple format. Each line describes an action; if a line begins with a whitespace, it is considered a continuation of the previous line. Lines beginning with .Ql # are considered as comments. .Pp Each line has four parts: a name of a USB HID item, a value for that item, a debounce value, and an action. There must be whitespace between the parts. .Pp The item names are similar to those used by .Xr usbhidctl 1 . .Pp The value is simply a numeric value. When the item reports this value, the action will be performed. If the value is .Ql * , it will match any value. .Pp The debounce value is an integer not less than 0. The value of 0 indicates that no debouncing should occur. A value of 1 will only execute the action when the state changes. Values greater than one specify that an action should be performed only when the value changes by that amount. .Pp The action is a normal command that is executed with .Xr system 3 . Before it is executed some substitution will occur: .Ql $n will be replaced by the .Ar n Ns th argument on the command line, .Ql $V will be replaced by the numeric value of the HID item, .Ql $N will be replaced by the name of the control, and .Ql $H will be replaced by the name of the HID device. .Sh FILES .Bl -tag -width ".Pa /usr/share/misc/usb_hid_usages" .It Pa /usr/share/misc/usb_hid_usages The HID usage table. .It Pa /var/run/usbaction.pid The default location of the PID file. .El .Sh EXAMPLES The following configuration file can be used to control a pair of Philips USB speakers with the HID controls on the speakers. .Bd -literal -offset indent # Configuration for various Philips USB speakers -Consumer:Volume_Increment 1 0 mixer -f $1 vol.volume=+1 -Consumer:Volume_Decrement 1 0 mixer -f $1 vol.volume=-1 +Consumer:Volume_Increment 1 0 mixer -f $1 vol.volume=+1% +Consumer:Volume_Decrement 1 0 mixer -f $1 vol.volume=-1% Consumer:Mute 1 0 mixer -f $1 vol.mute=^ -Consumer:Channel_Top.Microsoft:Base_Up 1 0 mixer -f $1 bass.volume=+1 -Consumer:Channel_Top.Microsoft:Base_Down 1 0 mixer -f $1 bass.volume=-1 +Consumer:Channel_Top.Microsoft:Base_Up 1 0 mixer -f $1 bass.volume=+1% +Consumer:Channel_Top.Microsoft:Base_Down 1 0 mixer -f $1 bass.volume=-1% .Ed .Pp A sample invocation using this configuration would be .Pp .Dl "usbhidaction -f /dev/uhid1 -c conf /dev/mixer1" .Pp The following example controls the mixer volume using a Logitech Wingman. Notice the debounce of 1 for buttons and 5 for the slider. .Bd -literal -offset indent -Button:Button_1 1 1 mixer vol.volume=+10 -Button:Button_2 1 1 mixer vol.volume=-10 -Generic_Desktop:Z * 5 mixer vol.volume=`echo $V | awk '{print int($$1/255*100)}'` +Button:Button_1 1 1 mixer vol.volume=+10% +Button:Button_2 1 1 mixer vol.volume=-10% +Generic_Desktop:Z * 5 mixer vol.volume=`echo $V | awk '{printf("%.02f", $$1/255)}'` .Ed .Sh SEE ALSO .Xr usbhidctl 1 , .Xr usbhid 3 , .Xr uhid 4 , .Xr usb 4 .Sh HISTORY The .Nm command first appeared in .Nx 1.6 . The .Nm command appeared in .Fx 5.1 . diff --git a/usr.sbin/mixer/mixer.8 b/usr.sbin/mixer/mixer.8 index 284750538f7e..9a76cbe41f65 100644 --- a/usr.sbin/mixer/mixer.8 +++ b/usr.sbin/mixer/mixer.8 @@ -1,270 +1,275 @@ .\"- .\" Copyright (c) 2021 Christos Margiolis .\" .\" Permission is hereby granted, free of charge, to any person obtaining a copy .\" of this software and associated documentation files (the "Software"), to deal .\" in the Software without restriction, including without limitation the rights .\" to use, copy, modify, merge, publish, distribute, sublicense, and/or sell .\" copies of the Software, and to permit persons to whom the Software is .\" furnished to do so, subject to the following conditions: .\" .\" The above copyright notice and this permission notice shall be included in .\" all copies or substantial portions of the Software. .\" .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR .\" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, .\" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE .\" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER .\" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, .\" OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN .\" THE SOFTWARE. .\" .\" $FreeBSD$ .\" -.Dd March 20, 2022 +.Dd April 29, 2022 .Dt MIXER 8 .Os .Sh NAME .Nm mixer .Nd manipulate soundcard mixer controls .Sh SYNOPSIS .Nm .Op Fl f Ar device .Op Fl d Ar unit .Op Fl os .Op Ar dev Ns Op Cm \&. Ns Ar control Ns Op Cm \&= Ns Ar value .Ar ... .Nm .Op Fl d Ar unit .Op Fl os .Fl a .Nm .Fl h .Sh DESCRIPTION The .Nm utility is used to set and display soundcard mixer device controls. .Pp The options are as follows: .Bl -tag -width "-f device" .It Fl a Print the values for all mixer devices available in the system .Pq see Sx FILES . .It Fl d Ar unit Change the default audio card to .Ar unit . The unit has to be an integer value. To see what unit values are available, look at the number each mixer device has by running .Nm . .It Fl f Ar device Open .Ar device as the mixer device .Pq see Sx FILES . .It Fl h Print a help message. .It Fl o Print mixer values in a format suitable for use inside scripts. The mixer's header (name, audio card name, ...) will not be printed. .It Fl s Print only the recording source(s) of the mixer device. .El .Pp The list of mixer devices that may be modified are: .Bd -ragged -offset indent .Cm vol , bass , treble , synth , pcm , speaker , line , mic , cd , mix , .Cm pcm2 , rec , .Cm igain , ogain , .Cm line1 , line2 , line3 , .Cm dig1 , dig2 , dig3 , .Cm phin , phout , video , radio , and .Cm monitor . .Ed .Pp Not all mixer devices are available. .Pp Without any arguments, .Nm displays all information for each one of the mixer's supported devices to .Ar stdout . If the .Ar dev argument is specified, .Nm displays only the values for .Ar dev . More than one device may be specified. .Pp Commands use the following format: .Bl -column xxxxxxxxxxxxxxxxxxxxxxxx -offset indent .It Sy Name Ta Sy Action .It Ar dev Ta Display all controls .It Ar dev Ns Cm \&. Ns Ar control Ta Display only the specified control .It Ar dev Ns Cm \&. Ns Ar control Ns Cm \&= Ns Ar value Ta Set control value .El .Pp The available controls are as follows (replace .Ar dev with one of the available devices): .Sm off .Bl -column xxxxxxxxxxxxxxxxxxxxxxxx -offset indent .It Sy Name Ta Sy Value .It Ar dev Cm .volume Ta Xo .Ar vol | -.Oo Cm \&+ | Cm \&- Oc Ar lvol -.Oo Cm \&: Oo Cm \&+ | Cm \&- Oc Ar rvol Oc +.Oo Cm \&+ | Cm \&- Oc Ar lvol Oo % Oc +.Oo Cm \&: Oo Cm \&+ | Cm \&- Oc Ar rvol Oo % Oc Oc .Xc .It Ar dev Cm .mute Ta Cm 0 | 1 | ^ .It Ar dev Cm .recsrc Ta Cm ^ | + | - | = .El .Sm on .Pp The .Ar dev Ns Cm .volume control modifies a device's volume. The optional .Ar lvol and/or .Ar rvol values have to be specified. -The values have to be normalized 32-bit floats, from 0.0 to 1.0 inclusively. -If no -.Ql \&. -character is present, the value is treated like a percentage, for backwards compatibility. +The values should typically be decimal numbers between 0 and 1 with at most 2 +digits after the decimal point. +A trailing percent sign indicates that the value should be treated as a +percentage of 1.0, rather than an absolute value. +Thus, 70% means the same as 0.7. If the left or right volume values are prefixed with .Cm + or .Cm - , the value following will be used as a relative adjustment, modifying the current settings by the amount specified. +Note that relative percentages are still relative to 1.0, not to the current +value. +If the volume is currently 0.40 and an adjustment of +20% is specified, then +thet final volume will be set to 0.60. .Pp Volume can also be set using the shorthand .Ar dev Ns Cm =value . This syntax does not apply to other controls. .Pp The .Ar dev Ns Cm .mute control (un)mutes a device. The following values are available: .Bl -tag -width = -offset indent .It Cm 0 unmutes .Ar dev .It Cm 1 mutes .Ar dev .It Cm ^ toggles the mute of .Ar dev .El .Pp The .Ar dev Ns Cm .recsrc control modifies the recording sources of a mixer. .Nm marks devices which can be used as a recording source with .Sy rec . Recording sources are marked with .Sy src . To modify the recording source you can use one of the following modifiers on a .Sy rec device: .Bl -tag -width = -offset indent .It Cm ^ toggles .Ar dev of possible recording devices .It Cm + adds .Ar dev to possible recording devices .It Cm - removes .Ar dev from possible recording devices .It Cm = sets the recording device to .Ar dev .El .Sh FILES .Bl -tag -width /dev/mixerN -compact .It Pa /dev/mixerN The mixer device, where .Ar N is the number of that device, for example .Ar /dev/mixer0 . PCM cards and mixers have a 1:1 relationship, which means that .Pa /dev/mixer0 is the mixer for .Pa /dev/pcm0 and so on. By default, .Nm prints both the audio card's number and the mixer associated with it in the form of .Ar pcmN:mixer . The .Pa /dev/mixer file, although it does not exist in the filesystem, points to the default mixer device and is the file .Nm opens when the .Fl f Ar device option has not been specified. .El .Sh EXAMPLES Change the volume for the .Cm vol device of the .Pa /dev/mixer0 mixer device to 0.65: .Bd -literal -offset indent $ mixer -f /dev/mixer0 vol.volume=0.65 .Ed .Pp Increase the .Cm mic device's left volume by 0.10 and decrease the right volume by 0.05: .Bd -literal -offset indent $ mixer mic.volume=+0.10:-0.05 .Ed .Pp Toggle the mute for .Cm vol : .Bd -literal -offset indent $ mixer vol.mute=^ .Ed .Pp Set .Cm mic and toggle .Cm line recording sources: .Bd -literal -offset indent $ mixer mic.recsrc=+ line.recsrc=^ .Ed .Pp Dump .Pa /dev/mixer0 information to a file and retrieve back later: .Bd -literal -offset indent $ mixer -f /dev/mixer0 -o > info \&... $ mixer -f /dev/mixer0 `cat info` .Ed .Sh SEE ALSO .Xr mixer 3 , .Xr sound 4 , .Xr sysctl 8 .Sh HISTORY The .Nm utility first appeared in .Fx 2.0.5 and was rewritten completely in .Fx 14.0 . .Sh AUTHORS .An Christos Margiolis Aq Mt christos@FreeBSD.org diff --git a/usr.sbin/mixer/mixer.c b/usr.sbin/mixer/mixer.c index c0a9ec25c6fa..e216efe3313c 100644 --- a/usr.sbin/mixer/mixer.c +++ b/usr.sbin/mixer/mixer.c @@ -1,513 +1,520 @@ /*- * Copyright (c) 2021 Christos Margiolis * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * $FreeBSD$ */ #include #include #include #include #include #include #include enum { C_VOL = 0, C_MUT, C_SRC, }; static void usage(void) __dead2; static void initctls(struct mixer *); static void printall(struct mixer *, int); static void printminfo(struct mixer *, int); static void printdev(struct mixer *, int); static void printrecsrc(struct mixer *, int); /* XXX: change name */ /* Control handlers */ static int mod_dunit(struct mix_dev *, void *); static int mod_volume(struct mix_dev *, void *); static int mod_mute(struct mix_dev *, void *); static int mod_recsrc(struct mix_dev *, void *); static int print_volume(struct mix_dev *, void *); static int print_mute(struct mix_dev *, void *); static int print_recsrc(struct mix_dev *, void *); static const mix_ctl_t ctl_dunit = { .parent_dev = NULL, .id = -1, .name = "default_unit", .mod = mod_dunit, .print = NULL }; int main(int argc, char *argv[]) { struct mixer *m; mix_ctl_t *cp; char *name = NULL, buf[NAME_MAX]; char *p, *q, *devstr, *ctlstr, *valstr = NULL; int dunit, i, n, pall = 1, shorthand; int aflag = 0, dflag = 0, oflag = 0, sflag = 0; int ch; while ((ch = getopt(argc, argv, "ad:f:hos")) != -1) { switch (ch) { case 'a': aflag = 1; break; case 'd': dunit = strtol(optarg, NULL, 10); if (errno == EINVAL || errno == ERANGE) err(1, "strtol"); dflag = 1; break; case 'f': name = optarg; break; case 'o': oflag = 1; break; case 's': sflag = 1; break; case 'h': /* FALLTHROUGH */ case '?': default: usage(); } } argc -= optind; argv += optind; /* Print all mixers and exit. */ if (aflag) { if ((n = mixer_get_nmixers()) < 0) err(1, "mixer_get_nmixers"); for (i = 0; i < n; i++) { (void)snprintf(buf, sizeof(buf), "/dev/mixer%d", i); if ((m = mixer_open(buf)) == NULL) err(1, "mixer_open: %s", buf); initctls(m); if (sflag) printrecsrc(m, oflag); else { printall(m, oflag); if (oflag) printf("\n"); } (void)mixer_close(m); } return (0); } if ((m = mixer_open(name)) == NULL) err(1, "mixer_open: %s", name); initctls(m); if (dflag && ctl_dunit.mod(m->dev, &dunit) < 0) goto parse; if (sflag) { printrecsrc(m, oflag); (void)mixer_close(m); return (0); } parse: while (argc > 0) { if ((p = strdup(*argv)) == NULL) err(1, "strdup(%s)", *argv); /* Check if we're using the shorthand syntax for volume setting. */ shorthand = 0; for (q = p; *q != '\0'; q++) { if (*q == '=') { q++; shorthand = ((*q >= '0' && *q <= '9') || *q == '+' || *q == '-' || *q == '.'); break; } else if (*q == '.') break; } /* Split the string into device, control and value. */ devstr = strsep(&p, ".="); if ((m->dev = mixer_get_dev_byname(m, devstr)) == NULL) { warnx("%s: no such device", devstr); goto next; } /* Input: `dev`. */ if (p == NULL) { printdev(m, 1); pall = 0; goto next; } else if (shorthand) { /* * Input: `dev=N` -> shorthand for `dev.volume=N`. * * We don't care what the rest of the string contains as * long as we're sure the very beginning is right, * mod_volume() will take care of parsing it properly. */ cp = mixer_get_ctl(m->dev, C_VOL); cp->mod(cp->parent_dev, p); goto next; } ctlstr = strsep(&p, "="); if ((cp = mixer_get_ctl_byname(m->dev, ctlstr)) == NULL) { warnx("%s.%s: no such control", devstr, ctlstr); goto next; } /* Input: `dev.control`. */ if (p == NULL) { (void)cp->print(cp->parent_dev, cp->name); pall = 0; goto next; } valstr = p; /* Input: `dev.control=val`. */ cp->mod(cp->parent_dev, valstr); next: free(p); argc--; argv++; } if (pall) printall(m, oflag); (void)mixer_close(m); return (0); } static void __dead2 usage(void) { fprintf(stderr, "usage: %1$s [-f device] [-d unit] [-os] [dev[.control[=value]]] ...\n" " %1$s [-d unit] [-os] -a\n" " %1$s -h\n", getprogname()); exit(1); } static void initctls(struct mixer *m) { struct mix_dev *dp; int rc = 0; TAILQ_FOREACH(dp, &m->devs, devs) { rc += mixer_add_ctl(dp, C_VOL, "volume", mod_volume, print_volume); rc += mixer_add_ctl(dp, C_MUT, "mute", mod_mute, print_mute); rc += mixer_add_ctl(dp, C_SRC, "recsrc", mod_recsrc, print_recsrc); } if (rc) { (void)mixer_close(m); err(1, "cannot make controls"); } } static void printall(struct mixer *m, int oflag) { struct mix_dev *dp; printminfo(m, oflag); TAILQ_FOREACH(dp, &m->devs, devs) { m->dev = dp; printdev(m, oflag); } } static void printminfo(struct mixer *m, int oflag) { int playrec = MIX_MODE_PLAY | MIX_MODE_REC; if (oflag) return; printf("%s:", m->mi.name); if (*m->ci.longname != '\0') printf(" <%s>", m->ci.longname); if (*m->ci.hw_info != '\0') printf(" %s", m->ci.hw_info); if (m->mode != 0) printf(" ("); if (m->mode & MIX_MODE_PLAY) printf("play"); if ((m->mode & playrec) == playrec) printf("/"); if (m->mode & MIX_MODE_REC) printf("rec"); if (m->mode != 0) printf(")"); if (m->f_default) printf(" (default)"); printf("\n"); } static void printdev(struct mixer *m, int oflag) { struct mix_dev *d = m->dev; mix_ctl_t *cp; if (!oflag) { printf(" %-10s= %.2f:%.2f ", d->name, d->vol.left, d->vol.right); if (!MIX_ISREC(m, d->devno)) printf(" pbk"); if (MIX_ISREC(m, d->devno)) printf(" rec"); if (MIX_ISRECSRC(m, d->devno)) printf(" src"); if (MIX_ISMUTE(m, d->devno)) printf(" mute"); printf("\n"); } else { TAILQ_FOREACH(cp, &d->ctls, ctls) { (void)cp->print(cp->parent_dev, cp->name); } } } static void printrecsrc(struct mixer *m, int oflag) { struct mix_dev *dp; int n = 0; if (!m->recmask) return; if (!oflag) printf("%s: ", m->mi.name); TAILQ_FOREACH(dp, &m->devs, devs) { if (MIX_ISRECSRC(m, dp->devno)) { if (n++ && !oflag) printf(", "); printf("%s", dp->name); if (oflag) printf(".%s=+%s", mixer_get_ctl(dp, C_SRC)->name, n ? " " : ""); } } printf("\n"); } static int mod_dunit(struct mix_dev *d, void *p) { int dunit = *((int *)p); int n; if ((n = mixer_get_dunit()) < 0) { warn("cannot get default unit"); return (-1); } if (mixer_set_dunit(d->parent_mixer, dunit) < 0) { warn("cannot set default unit to: %d", dunit); return (-1); } printf("%s: %d -> %d\n", ctl_dunit.name, n, dunit); return (0); } static int mod_volume(struct mix_dev *d, void *p) { struct mixer *m; mix_ctl_t *cp; mix_volume_t v; const char *val; - char lstr[8], rstr[8]; + char *endp, lstr[8], rstr[8]; float lprev, rprev, lrel, rrel; int n; m = d->parent_mixer; cp = mixer_get_ctl(m->dev, C_VOL); val = p; n = sscanf(val, "%7[^:]:%7s", lstr, rstr); if (n == EOF) { warnx("invalid volume value: %s", val); return (-1); } lrel = rrel = 0; if (n > 0) { if (*lstr == '+' || *lstr == '-') - lrel = rrel = 1; - v.left = strtof(lstr, NULL); + lrel = 1; + v.left = strtof(lstr, &endp); + if (*endp != '\0' && (*endp != '%' || *(endp + 1) != '\0')) { + warnx("invalid volume value: %s", lstr); + return (-1); + } - /* be backwards compatible */ - if (strstr(lstr, ".") == NULL) + if (*endp == '%') v.left /= 100.0f; } if (n > 1) { if (*rstr == '+' || *rstr == '-') rrel = 1; - v.right = strtof(rstr, NULL); + v.right = strtof(rstr, &endp); + if (*endp != '\0' && (*endp != '%' || *(endp + 1) != '\0')) { + warnx("invalid volume value: %s", rstr); + return (-1); + } - /* be backwards compatible */ - if (strstr(rstr, ".") == NULL) + if (*endp == '%') v.right /= 100.0f; } switch (n) { case 1: v.right = v.left; /* FALLTHROUGH */ + rrel = lrel; case 2: if (lrel) v.left += m->dev->vol.left; if (rrel) v.right += m->dev->vol.right; if (v.left < MIX_VOLMIN) v.left = MIX_VOLMIN; else if (v.left > MIX_VOLMAX) v.left = MIX_VOLMAX; if (v.right < MIX_VOLMIN) v.right = MIX_VOLMIN; else if (v.right > MIX_VOLMAX) v.right = MIX_VOLMAX; lprev = m->dev->vol.left; rprev = m->dev->vol.right; if (mixer_set_vol(m, v) < 0) warn("%s.%s=%.2f:%.2f", m->dev->name, cp->name, v.left, v.right); else printf("%s.%s: %.2f:%.2f -> %.2f:%.2f\n", m->dev->name, cp->name, lprev, rprev, v.left, v.right); } return (0); } static int mod_mute(struct mix_dev *d, void *p) { struct mixer *m; mix_ctl_t *cp; const char *val; int n, opt = -1; m = d->parent_mixer; cp = mixer_get_ctl(m->dev, C_MUT); val = p; switch (*val) { case '0': opt = MIX_UNMUTE; break; case '1': opt = MIX_MUTE; break; case '^': opt = MIX_TOGGLEMUTE; break; default: warnx("%c: no such modifier", *val); return (-1); } n = MIX_ISMUTE(m, m->dev->devno); if (mixer_set_mute(m, opt) < 0) warn("%s.%s=%c", m->dev->name, cp->name, *val); else printf("%s.%s: %d -> %d\n", m->dev->name, cp->name, n, MIX_ISMUTE(m, m->dev->devno)); return (0); } static int mod_recsrc(struct mix_dev *d, void *p) { struct mixer *m; mix_ctl_t *cp; const char *val; int n, opt = -1; m = d->parent_mixer; cp = mixer_get_ctl(m->dev, C_SRC); val = p; switch (*val) { case '+': opt = MIX_ADDRECSRC; break; case '-': opt = MIX_REMOVERECSRC; break; case '=': opt = MIX_SETRECSRC; break; case '^': opt = MIX_TOGGLERECSRC; break; default: warnx("%c: no such modifier", *val); return (-1); } n = MIX_ISRECSRC(m, m->dev->devno); if (mixer_mod_recsrc(m, opt) < 0) warn("%s.%s=%c", m->dev->name, cp->name, *val); else printf("%s.%s: %d -> %d\n", m->dev->name, cp->name, n, MIX_ISRECSRC(m, m->dev->devno)); return (0); } static int print_volume(struct mix_dev *d, void *p) { struct mixer *m = d->parent_mixer; const char *ctl_name = p; printf("%s.%s=%.2f:%.2f\n", m->dev->name, ctl_name, m->dev->vol.left, m->dev->vol.right); return (0); } static int print_mute(struct mix_dev *d, void *p) { struct mixer *m = d->parent_mixer; const char *ctl_name = p; printf("%s.%s=%d\n", m->dev->name, ctl_name, MIX_ISMUTE(m, m->dev->devno)); return (0); } static int print_recsrc(struct mix_dev *d, void *p) { struct mixer *m = d->parent_mixer; const char *ctl_name = p; if (!MIX_ISRECSRC(m, m->dev->devno)) return (-1); printf("%s.%s=+\n", m->dev->name, ctl_name); return (0); }