For flexible manufacturing systems, this paper presents a Petri net based deadlock prevention method to obtain highly permissive and structurally minimal supervisors in the presence of uncontrollable and unobservable transitions. First, we define admissible markings which form a maximal strongly connected component (SCC) containing the initial marking and not leading outside the SCC uncontrollably. Then, an integer linear programming problem is formulated to construct a supervisor which permits all admissible markings and forbids all the very first inadmissible states from the admissible zone. It also ensures that no uncontrollable transitions are controlled and no unobservable ones are observed by the supervisor. The method can be applied to the plant nets whose crucial transitions are uncontrollable and/or unobservable. In addition, the obtained supervisors are deadlock-free, highly permissive, and structurally minimal in the presence of controllability and observability.