on init
    # Make foreground and background I/O priority different. none-to-rt was
    # introduced in kernel 5.14. promote-to-rt was introduced in kernel 6.5.
    # Write none-to-rt first and promote-to-rt next to support both older and
    # newer kernel versions.
    write /dev/blkio/blkio.prio.class none-to-rt
    write /dev/blkio/blkio.prio.class promote-to-rt

on property:ro.build.type=eng
    write /dev/sys/block/bootdevice/pixel/enable_pixel_ufs_logging 1
    chown system /dev/sg3

on default_storage_mode
    # F2FS
    write /dev/sys/fs/by-name/userdata/data_io_flag 8
    write /dev/sys/fs/by-name/userdata/node_io_flag 8
    write /dev/sys/fs/by-name/userdata/max_io_bytes 524288
    write /dev/sys/fs/by-name/userdata/min_hot_blocks 0

    # Block
    write /dev/sys/block/by-name/rootdisk/queue/iostats 1
    write /dev/sys/block/by-name/rootdisk/queue/nr_requests 128
    write /dev/sys/block/by-name/rootdisk/queue/rq_affinity 2
    write /dev/sys/block/by-name/zoned_device/queue/rq_affinity 2

    # UFS
    write /dev/sys/block/bootdevice/clkgate_enable 1

on init
    # Symlink /dev/sys/block/bootdevice
    wait /dev/block/platform/${ro.boot.boot_devices}
    symlink /dev/block/platform/${ro.boot.boot_devices} /dev/block/bootdevice
    symlink /sys/devices/platform/${ro.boot.boot_devices} /dev/sys/block/bootdevice

    # F2FS
    write /dev/sys/fs/by-name/userdata/data_io_flag 56
    write /dev/sys/fs/by-name/userdata/node_io_flag 56

    # Block
    write /dev/sys/block/by-name/rootdisk/queue/iostats 0
    write /dev/sys/block/by-name/rootdisk/queue/nr_requests 256

    # UFS
    write /dev/sys/block/bootdevice/clkgate_enable 0
    write /dev/sys/block/bootdevice/wb_on 0
    write /dev/sys/block/bootdevice/enable_wb_buf_flush 0

on property:sys.boot_completed=1
    # Health Storage HAL
    chown system system /dev/sys/block/bootdevice/manual_gc
    write /dev/sys/block/bootdevice/manual_gc 0

    # Power HAL access
    chmod 0664 /dev/sys/block/bootdevice/manual_gc

    # Pixelstats
    chown system system /dev/sys/block/bootdevice/slowio_read_cnt
    chown system system /dev/sys/block/bootdevice/slowio_sync_cnt
    chown system system /dev/sys/block/bootdevice/slowio_unmap_cnt
    chown system system /dev/sys/block/bootdevice/slowio_write_cnt

    chown system system /dev/sys/fs/by-name/userdata/committed_atomic_block
    chown system system /dev/sys/fs/by-name/userdata/compr_new_inode
    chown system system /dev/sys/fs/by-name/userdata/compr_saved_block
    chown system system /dev/sys/fs/by-name/userdata/compr_written_block
    chown system system /dev/sys/fs/by-name/userdata/gc_reclaimed_segments
    chown system system /dev/sys/fs/by-name/userdata/gc_segment_mode
    chown system system /dev/sys/fs/by-name/userdata/peak_atomic_write
    chown system system /dev/sys/fs/by-name/userdata/revoked_atomic_block

    trigger default_storage_mode

on charger
    trigger default_storage_mode

on property:ro.boot.mode=charger && property:init.svc.vendor.charger=running
    trigger default_storage_mode
