blob: cdea243dc19a4fa678c38eb6bc4bd2d145d150f1 [file] [log] [blame]
Paul Crowley1a965262017-10-13 13:49:50 -07001#!/system/bin/sh
2#
3# Copyright (C) 2017 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Paul Crowley8e550662017-10-16 17:01:44 -070017# Set up or tear down subdirectories of vold-created directories.
18#
19# This is kept separate from vold because under the SELinux rules, it has privileges vold doesn't
20# have. In particular, prepare_dir sets SELinux labels on subdirectories based on file_contexts,
21# so this script has some relabelling privileges.
Paul Crowley1a965262017-10-13 13:49:50 -070022
Paul Crowley8e550662017-10-16 17:01:44 -070023
24set -e
25action="$1"
26dirtype="$2"
27volume_uuid="$3"
28user_id="$4"
29path="$5"
30
31case "$user_id" in
32 *[!0-9]* | '')
33 echo "Invalid user id"
34 exit -1
35 ;;
Paul Crowley1a965262017-10-13 13:49:50 -070036esac
37
Paul Crowley8e550662017-10-16 17:01:44 -070038if [ x"$volume_uuid" != x ] ; then
Paul Crowley1a965262017-10-13 13:49:50 -070039 echo "Volume must be root volume"
40 exit -1;
41fi
42
Paul Crowley8e550662017-10-16 17:01:44 -070043case "$dirtype" in
Paul Crowley1a965262017-10-13 13:49:50 -070044 misc_de|misc_ce)
Paul Crowley8e550662017-10-16 17:01:44 -070045 computed_path="/data/$dirtype/$user_id"
46 if [ x"$computed_path" != x"$path" ] ; then
Paul Crowley1a965262017-10-13 13:49:50 -070047 echo "Parameter path didn't match computed path: " $computed_path
48 exit -1;
49 fi
Paul Crowley8e550662017-10-16 17:01:44 -070050 case "$action" in
51 prepare)
52 /system/bin/prepare_dir --mode 700 --uid 0 --gid 0 -- "$computed_path"/vold
53 ;;
54 destroy)
55 rm -rf "$computed_path"/*
56 ;;
57 *)
58 echo "Unknown action: $action"
59 exit -1
60 ;;
61 esac
Paul Crowley1a965262017-10-13 13:49:50 -070062 ;;
63 *)
Paul Crowley8e550662017-10-16 17:01:44 -070064 echo "Unknown type: $dirtype"
65 exit -1
Paul Crowley1a965262017-10-13 13:49:50 -070066 ;;
67esac