1 | #! /bin/sh
|
---|
2 | # $Id: VBoxCreateUSBNode.sh 93115 2022-01-01 11:31:46Z 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-2022 Oracle Corporation
|
---|
10 | #
|
---|
11 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | # available from http://www.virtualbox.org. This file is free software;
|
---|
13 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | # General Public License (GPL) as published by the Free Software
|
---|
15 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | #
|
---|
19 |
|
---|
20 | # Constant, from the USB specifications
|
---|
21 | usb_class_hub=09
|
---|
22 |
|
---|
23 | do_remove=0
|
---|
24 | case "$1" in "--remove")
|
---|
25 | do_remove=1; shift;;
|
---|
26 | esac
|
---|
27 | bus=`expr "$2" '/' 128 + 1`
|
---|
28 | device=`expr "$2" '%' 128 + 1`
|
---|
29 | class="$3"
|
---|
30 | group="$4"
|
---|
31 | devdir="`printf "/dev/vboxusb/%.3d" $bus`"
|
---|
32 | devpath="`printf "/dev/vboxusb/%.3d/%.3d" $bus $device`"
|
---|
33 | case "$do_remove" in
|
---|
34 | 0)
|
---|
35 | if test -n "$class" -a "$class" = "$usb_class_hub"
|
---|
36 | then
|
---|
37 | exit 0
|
---|
38 | fi
|
---|
39 | case "$group" in "") group="vboxusers";; esac
|
---|
40 | mkdir /dev/vboxusb -m 0750 2>/dev/null
|
---|
41 | chown root:$group /dev/vboxusb 2>/dev/null
|
---|
42 | mkdir "$devdir" -m 0750 2>/dev/null
|
---|
43 | chown root:$group "$devdir" 2>/dev/null
|
---|
44 | mknod "$devpath" c $1 $2 -m 0660 2>/dev/null
|
---|
45 | chown root:$group "$devpath" 2>/dev/null
|
---|
46 | ;;
|
---|
47 | 1)
|
---|
48 | rm -f "$devpath"
|
---|
49 | ;;
|
---|
50 | esac
|
---|
51 |
|
---|