I see that Filesystem types and file types are declared in /external/sepolicy/file.te in AOSP.
But each type is representing or mapped to particular directory as mentioned in the comments.

Link: https://android.googlesource.com/platform/external/sepolicy/+/refs/heads/lollipop-release/file.te

Example 1:

#Default type for anything under /system.
type system_file, file_type;

Example 2:

#/data/data subdirectories - app sandboxes
type app_data_file, file_type, data_file_type;

It means we are declaring a type app_data_file and associate this type to the attributes file_type and data_file_type

Note: All attributes are declared in the attributes file.

Link: https://android.googlesource.com/platform/external/sepolicy/+/refs/heads/lollipop-release/attributes

  1. It is mentioned that the type system_file is for the path /system and app_data_file is for /data/data subdirectories. But where are these types and paths mapped or associated explicitly? If they aren’t mapped anywhere, then how will the OS know that system_file is for /system

  2. If I have to create a new type my_app_type and map it to the dir /data/com.my_app/photos/, how do I achieve that?