<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def file_hash(load, fnd):
    '''
    Return a file hash based on the hash type set in the master config
    '''
    if not all(x in load for x in ('path', 'saltenv')):
        return '', None
    ret = {'hash_type': __opts__['hash_type']}
    relpath = fnd['rel']
    path = fnd['path']
    hash_cachedir = os.path.join(__opts__['cachedir'], 'azurefs', 'hashes')
    hashdest = salt.utils.path.join(hash_cachedir,
                                    load['saltenv'],
                                    '{0}.hash.{1}'.format(relpath,
                                                          __opts__['hash_type']))
    if not os.path.isfile(hashdest):
        if not os.path.exists(os.path.dirname(hashdest)):
            os.makedirs(os.path.dirname(hashdest))
        ret['hsum'] = salt.utils.hashutils.get_hash(path, __opts__['hash_type'])
        with salt.utils.files.fopen(hashdest, 'w+') as fp_:
            fp_.write(salt.utils.stringutils.to_str(ret['hsum']))
        return ret
    else:
        with salt.utils.files.fopen(hashdest, 'rb') as fp_:
            ret['hsum'] = salt.utils.stringutils.to_unicode(fp_.read())
        return ret