I show that the principle of equipartition, applied to area elements of a
surface which are in equilibrium at the local Davies-Unruh temperature, allows
one to determine the surface number density of the microscopic spacetime
degrees of freedom in any diffeomorphism invariant theory of gravity. The
entropy associated with these degrees of freedom matches with the Wald entropy
for the theory. This result also allows one to attribute an entropy density to
the spacetime in a natural manner. The field equations of the theory can then
be obtained by extremising this entropy. Moreover, when the microscopic degrees
of freedom are in local thermal equilibrium, the spacetime entropy of a bulk
region resides on its boundary.Comment: v1: 20 pages; no figures. v2: Sec 4 added; 23 page