Kodėl aš galiu keisti naudojamus failus Windows Kaip aš galiu Linux ir OS X?

Turinys:

Kodėl aš galiu keisti naudojamus failus Windows Kaip aš galiu Linux ir OS X?
Kodėl aš galiu keisti naudojamus failus Windows Kaip aš galiu Linux ir OS X?

Video: Kodėl aš galiu keisti naudojamus failus Windows Kaip aš galiu Linux ir OS X?

Video: Kodėl aš galiu keisti naudojamus failus Windows Kaip aš galiu Linux ir OS X?
Video: How to RUN Android APPS in Windows 10 with BLUE STACKS! - YouTube 2024, Balandis
Anonim
 Kai naudosite "Linux" ir "OS X", operacinė sistema netrukdys ištrinti dar šiuo metu naudojamo failo sistemoje "Windows", todėl jums bus aiškiai draudžiama tai padaryti. Kas duoda? Kodėl galite redaguoti ir ištrinti naudojamus failus iš "Unix" sistemose, bet ne "Windows"?
Kai naudosite "Linux" ir "OS X", operacinė sistema netrukdys ištrinti dar šiuo metu naudojamo failo sistemoje "Windows", todėl jums bus aiškiai draudžiama tai padaryti. Kas duoda? Kodėl galite redaguoti ir ištrinti naudojamus failus iš "Unix" sistemose, bet ne "Windows"?

Šiandien "Klausimų ir atsakymų sesija" pateikiama su "SuperUser", "Stack Exchange", "Community-driven Q &A" tinklalapių grupe.

Klausimas

"SuperUser" skaitytuvas the.midget nori sužinoti, kodėl "Linux" ir "Windows" naudoja skirtingus failus:

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.

Taigi, kas vyksta už scenų ir užkerta kelią jam netyčia ištrinti dalykus "Windows", kaip jis gali "Linux"?

Atsakymas

"SuperUser" autoriai atnešė šiek tiek informacijos apie padėtį. Amazed rašo:

Kai atidarote arba vykdyti failą "Windows", "Windows užrakina vietoje failą (tai yra supaprastinimas, tačiau paprastai tiesa.) Failą, kuris yra užrakintas procesas negali būti ištrintas, kol šis procesas spaudai ją. Štai kodėl kiekvieną kartą, kai "Windows" turi atnaujinti save, reikia iš naujo paleisti jį, kad jis įsigaliotų.

Kita vertus, "Unix" tipo operacinės sistemos, pvz., "Linux" ir "Mac OS X", neleidžia užfiksuoti failo, o pagrindinių disko sektorių. Tai gali atrodyti triviali diferencijavimas, bet tai reiškia, kad failų sistemos turinio failo įrašas gali būti ištrintas, netrukdant bet kuriai programai, kurioje jau atidarytas failas. Taigi, jūs galite ištrinti failą, kol jis vis dar vykdomas arba kitaip naudojamas, ir jis bus ir toliau diske, jei tam tikras procesas turi atvirą rankenėlę, nors jo įrašas į failų lentelę netenka.

Davidas Schwartzas išryškina idėją ir pabrėžia, kaip viskas turėtų būti idealiai ir kaip jie yra praktikoje:

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.

Čia jūs turite: du skirtingi požiūriai į failų tvarkymą du skirtingus rezultatus.

Ar turite ką nors įtraukti į paaiškinimą? Garsas išjungtas komentaruose. Norite skaityti daugiau atsakymų iš kitų "Tech-savvy Stack Exchange" vartotojų? Patikrinkite visą diskusijų temą čia.

Rekomenduojamas: