I'm a little bit confused as to why quasi-static process cannot lose energy to friction in order to be reversible. This is how I'm thinking: Suppose you have a container of gas with a piston, and on top of the piston you have a pile of infinitesimally fine powder. Removing the powder, one grain at a time, defines a path $\gamma$ from state $A$ to $B$ in state space.
Here's where I'm confused: Does irreversible mean that you can't get from $B$ to $A$ by ONLY adding each of the grains you removed, or does it mean that if you're at $B$, then there is no way to figure out a process that would define $-\gamma$ ending at $A$? If irreversible means the former, then I'm fine. If it means the latter, then I don't understand. If you just went from $A$ to $B$, you know what it took to get there, and in theory, you even know the amount of energy lost to friction at each infinitesimal step of the way in the path. So to define $-\gamma$, you would have to add a certain amount of heat at each stage to compensate, but the amount is something you could in theory determine.