Zašto ne mogu promijeniti datoteke u sustavu Windows kao što sam mogu na Linuxu i OS X?

Sadržaj:

Zašto ne mogu promijeniti datoteke u sustavu Windows kao što sam mogu na Linuxu i OS X?
Zašto ne mogu promijeniti datoteke u sustavu Windows kao što sam mogu na Linuxu i OS X?

Video: Zašto ne mogu promijeniti datoteke u sustavu Windows kao što sam mogu na Linuxu i OS X?

Video: Zašto ne mogu promijeniti datoteke u sustavu Windows kao što sam mogu na Linuxu i OS X?
Video: Upgrade Windows 8.1 to Windows 10 for Free - YouTube 2024, Travanj
Anonim
 Kada koristite Linux i OS X, operacijski sustav osvojio bi vas zaustavljanje brisanja datoteke koja je trenutno u uporabi, ali na Windowsu ćete biti izričito zabranjeni. Što daje? Zašto možete uređivati i brisati datoteke u uporabi na Unix-izvedenim sustavima, ali ne i za Windows?
Kada koristite Linux i OS X, operacijski sustav osvojio bi vas zaustavljanje brisanja datoteke koja je trenutno u uporabi, ali na Windowsu ćete biti izričito zabranjeni. Što daje? Zašto možete uređivati i brisati datoteke u uporabi na Unix-izvedenim sustavima, ali ne i za Windows?

Današnja pitanja o pitanjima i odgovorima daju nam zahvaljujući SuperUser, podjela Škole razmjene, zajednice-driven grupiranje Q & A web stranica.

Pitanje

Čitač SuperUser the.midget želi znati zašto Linux i Windows različito upravljaju datotekom u upotrebi:

One of the things that has puzzled me ever since I started using Linux is the fact that it allows you to change the name of a file or even delete it while it is being read. An example is how I accidentally tried to delete a video while it was playing. I succeeded, and was surprised as I learnt that you can change just about anything in a file without caring if it’s being used at the moment or not.

Dakle, što se događa iza scene i spriječiti ga da bezobzirno brisanje stvari u sustavu Windows kao što je on u Linuxu?

Odgovor

Dobavljači SuperUser-a rasvijetlili su situaciju za midi. Zaprepašteni piše:

Kad god otvorite ili izvršite datoteku u sustavu Windows, Windows zaključava datoteku na mjestu (ovo je pojednostavljenje, ali obično vrijedi). Datoteka koja je zaključana procesom ne može se izbrisati sve dok taj proces ne otpušta. To je razlog zašto svaki put kada se Windows mora ažurirati, trebate ponovno pokrenuti sustav kako bi bio na snazi.

S druge strane, operacijski sustavi slični Unixu kao što su Linux i Mac OS X ne mogu zaključati datoteku, nego temeljne diskove. To se može činiti trivijalnom razlikom, ali to znači da se zapis u datotečnom sustavu datoteka može izbrisati bez uznemiravanja bilo kojeg programa koji već ima datoteku otvoren. Tako možete izbrisati datoteku dok je još uvijek izvršavana ili na drugi način upotrebljavana i nastavit će postojati na disku sve dok neki proces ima otvorenu ručicu za njega iako je njegov unos u tablicu datoteka nestalo.

David Schwartz se širi idejom i ističe kako bi stvari trebale biti idealno i kako su u praksi:

Windows defaults to automatic, mandatory file locking. UNIXes default to manual, cooperative file locking. In both cases, the defaults can be overriden, but in both cases they usually aren’t.

A lot of old Windows code uses the C/C++ API (functions like fopen) rather than the native API (functions like CreateFile). The C/C++ API gives you no way to specify how mandatory locking will work, so you get the defaults. The default “share mode” tends to prohibit “conflicting” operations. If you open a file for writing, writes are assumed to conflict, even if you never actually write to the file. Ditto for renames.

And, here’s where it gets worse. Other than opening for read or write, the C/C++ API provides no way to specify what you intend to do with the file. So the API has to assume you are going to perform any legal operation. Since the locking is mandatory, an open that allows a conflicting operation will be refused, even if the code never intended to perform the conflicting operation but was just opening the file for another purpose.

So if code uses the C/C++ API, or uses the native API without specifically thinking about these issues, they will wind up preventing the maximum set of possible operations for every file they open and being unable to open a file unless every possible operation they could perform on it once opened is unconflicted.

In my opinion, the Windows method would work much better than the UNIX method if every program chose its share modes and open modes wisely and sanely handled failure cases. The UNIX method, however, works better if code doesn’t bother to think about these issues. Unfortunately, the basic C/C++ API doesn’t map well onto the Windows file API in a way that handles share modes and conflicting opens well. So the net result is a bit messy.

Tamo ga imate: dva različita pristupa postupanju s datotekama daju dva različita rezultata.

Imate li nešto za objašnjenje? Zvuči u komentarima. Želite li pročitati više odgovora od drugih tehnoloških korisnika Stack Exchangea? Pogledajte ovdje cijelu raspravu.

Preporučeni: