All scientific libraries in Bavaria = all University libraries plus the state library - are open to the general interested scientific public, provided that they are over 18 years old. They can get a user card for free, provided that they have a primary residence in Germany. If they have no primary residence, they can get a user’s card for the reading room only. Some books may be restricted for use in the reading room only (cooking books, fiction, children’s books) because the state library archives those and wants their users to use them for scientific reasons, not trivial or private reason (so buy your cooking books in a bookstore or go to a normal public library, unless you’re writing a study about the change in cooking books over the centuries).
That’s all for books and printed journals.
E-journals are different, because each university has a different treaty. There was an attempt at concerted action because of the high prices, where each bavarian university would pick different journals and all together, they covered all journals.
If you belong to a university, either as student or employee, and need an article from an e-journal that another uni has (and there’s no paper print of said journal available alternativly) then you do interlibrary loan for a print/ copy.
If you are a private, interested, person, you go to the state library and follow the same route.
Outside Bavaria, inside Germany, all publications are collected at the Die Deutsche Bibliothek (Frankfurt and Leipzig) the German national library, similar to the Library of Congress or the British Library. Access to the reading rooms there is allowed for every interested person, who can read or make copies, but because they act as archive, no borrowing is allowed. Again, no cost for use, only for copies as usual.
University libraries may restrict borrowing of faculty libraries to their own students or generally, making it a reading room so that students have always access to the books. Universities may also restrict the lending of textbooks to their own students because of the huge cost and demand for those.
Libraries may restrict the lending time for electronic media, to increase circulation, or, as with e-journals and books, to give greater access to more people. E-Textbooks may be available by chapters for a week. Scanned text books may only be available at selected computers in the reading room to protect copyright. Technical restrictions on the PDF files make saving files or printing impossible. Adobe has a special tool that monitors the allowed time of lending and automatically deletes the local file when the time is up so that other users can read it.
For modern e-books, digital textbooks and e-journals, hard contracts are fought over the high price and conditions of access, leading to some of the above restrictions.
With older books where copyright has run out, google scans them with a robot and puts them online in return for broadening their amount on Google books.