Can I use old Pentax lenses from the film days on the newer Pentax DSLRs?
Are there any caveats or exceptions? Are adapters or modifications needed?
Yes, all Pentax DSLRs accept all K-mount lenses. This includes autofocusing (if applicable), focus confirmation, metering, IS, etc.
The oldest two series, K and M series (database), do not have aperture contacts, and thus do not work with Av and Tv mode. Instead, you'll have to use M mode, but you will get meter readings. It can also suggest a shutter speed if you push the +/- or green button (depending on camera model and settings). Metering on these digital SLRs tends to be noticeably more inconsistent than on on the film SLRs they were designed for. These two series do not get matrix metering, just center-weighted and spot, but do get focus-trap.
There is a rare breed of K-mount that Ricoh used, called "KR" mount. They have an extra pin which will get stuck if it is not removed.
You can also get a M42-PK adapter and use the endless supply of great cheap screwmount lenses available at ebay, pawnshops, etc. They will have focus confirmation, IS, center/spot metering, and can actually use Av mode as they will stop down with the aperture ring.
There is a great summary of K-mount features at Bojidar Dimitor's page. You should look for the "crippled" KAF2 body.
In addition to K-mount, there were Pentax 645 and Pentax 67, both are medium formats. Those lenses are quite heavy and you'll need an expensive adapter for them.
Before K-mount, Pentax used a screw-mount called M42; you'll need an adapter to use an M42 lens. There's a huge selection of those lenses available. Adapters are not too expensive, available from both Pentax and third parties. With third party adapters, make sure it is of the thin makes-even-surface-with-bayonet design - the ones that have a metal layer over bayonet will not let your M42 lens focus to infinity. I have three different adapters, and Pentax original one is clearly the best one as it allows focusing to infinity and the lens fixes with correct right side up.
You'll want to have either a preset lens, or one with fully manual diaphragm; your dSLR cannot trigger aperture pin on an M42 lens, sometimes the pin can be glued though.
With some non-Pentax M42 lens (especially wider or faster ones), you need to check that the rear element does not protrude enough to get in mirror's way. Same warning for aperture pins used on some designs evolved from M42 (your dSLR will not use the pin to stop down the lens).
Also, some designs have protrusions on back that will get stuck on auto-focus coupler or screw heads on the rim of bayonet, thus getting stuck on the camera. Always check for possible problems before screwing on an M42 lens for first time.
I hope this didn't sound too intimidating, I've been using 4 different M42 lenses with no significant problems.
The Pentax-M 50mm f2 lens works out of the box on my Pentax K-x, metering + aperture. However precise focusing is only possible via life view and the image quality is significantly lower than the kit lens.
A film era Sigma PK zoom that I tried could not be mounted because it was protruding too far inside the Pentax K-x body, it could presumably have been fixed with a metal file.
In general I found all consumer film era lenses I tried to be inferior to the kit lenses in terms of image quality (and of course handling).
Some old pro lenses provide similar or better image quality and some old telephoto lenses have more reach than the 50-200mm kit lens. For long telephoto lenses with a narrow field of view manual focus through the view finder works sufficiently precise.