#!/bin/sh
#==============================================================================
# FILE: sfs_config
#
# DESCRIPTION:
# create files and give permissions to the files and directories needed by
# secure file system
#
# Copyright (c) 2017 Qualcomm Technologies, Inc.
# All Rights Reserved.
# Confidential and Proprietary - Qualcomm Technologies, Inc.
#==============================================================================
set -e

soc_id=`cat /sys/devices/soc0/soc_id`

if [[ "$soc_id" -ne "290" && "$soc_id" -ne "296" && "$soc_id" -ne "297" && "$soc_id" -ne "298" ]]; then

    echo "SFS configuration started." > /dev/kmsg

    if [ ! -d /data/misc ]; then
        echo "Creating /data/misc"
        mkdir /data/misc
    fi

    if [ "$soc_id" -eq "322" ]; then
        if [[ -e /data/persist && ! -e /persist ]]; then
            ln -sf /data/persist /persist
        fi
    fi

    if [ -e /persist ]; then
        if [ ! -d /persist/data ]; then
             echo "Creating /persist/data"
             mkdir /persist/data
        fi
        chmod o+rwx /persist/data
    fi

    chmod o+rwx /data/misc

    if [ ! -d /data/vendor/tzstorage ]; then
        echo "Creating /data/vendor/tzstorage"
        mkdir -p /data/vendor/tzstorage
    fi
    chmod o+rwx /data/vendor/tzstorage

    echo "SFS configuration completed." > /dev/kmsg
fi
exit 0
