As part of the partition process , both countries had agreed that the rulers of princely states would be allowed to opt for membership of either Pakistan or India , or in special cases to remain independent .