1 | #! /bin/sh
|
---|
2 | # $Id: VBoxCreateUSBNode.sh 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
3 | ## @file
|
---|
4 | # VirtualBox USB Proxy Service, Linux Specialization.
|
---|
5 | # udev helper for creating and removing device nodes for VirtualBox USB devices
|
---|
6 | #
|
---|
7 |
|
---|
8 | #
|
---|
9 | # Copyright (C) 2010-2024 Oracle and/or its affiliates.
|
---|
10 | #
|
---|
11 | # This file is part of VirtualBox base platform packages, as
|
---|
12 | # available from https://www.virtualbox.org.
|
---|
13 | #
|
---|
14 | # This program is free software; you can redistribute it and/or
|
---|
15 | # modify it under the terms of the GNU General Public License
|
---|
16 | # as published by the Free Software Foundation, in version 3 of the
|
---|
17 | # License.
|
---|
18 | #
|
---|
19 | # This program is distributed in the hope that it will be useful, but
|
---|
20 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
22 | # General Public License for more details.
|
---|
23 | #
|
---|
24 | # You should have received a copy of the GNU General Public License
|
---|
25 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
26 | #
|
---|
27 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
28 | #
|
---|
29 |
|
---|
30 | # Constant, from the USB specifications
|
---|
31 | usb_class_hub=09
|
---|
32 |
|
---|
33 | do_remove=0
|
---|
34 | case "$1" in "--remove")
|
---|
35 | do_remove=1; shift;;
|
---|
36 | esac
|
---|
37 | bus=`expr "$2" '/' 128 + 1`
|
---|
38 | device=`expr "$2" '%' 128 + 1`
|
---|
39 | class="$3"
|
---|
40 | group="$4"
|
---|
41 | devdir="`printf "/dev/vboxusb/%.3d" $bus`"
|
---|
42 | devpath="`printf "/dev/vboxusb/%.3d/%.3d" $bus $device`"
|
---|
43 | case "$do_remove" in
|
---|
44 | 0)
|
---|
45 | if test -n "$class" -a "$class" = "$usb_class_hub"
|
---|
46 | then
|
---|
47 | exit 0
|
---|
48 | fi
|
---|
49 | case "$group" in "") group="vboxusers";; esac
|
---|
50 | mkdir /dev/vboxusb -m 0750 2>/dev/null
|
---|
51 | chown root:$group /dev/vboxusb 2>/dev/null
|
---|
52 | mkdir "$devdir" -m 0750 2>/dev/null
|
---|
53 | chown root:$group "$devdir" 2>/dev/null
|
---|
54 | mknod "$devpath" c $1 $2 -m 0660 2>/dev/null
|
---|
55 | chown root:$group "$devpath" 2>/dev/null
|
---|
56 | ;;
|
---|
57 | 1)
|
---|
58 | rm -f "$devpath"
|
---|
59 | ;;
|
---|
60 | esac
|
---|
61 |
|
---|