Kāpēc es varu nomainīt lietojamos failus uz Windows, kā es varu Linux un OS X?

Satura rādītājs:

Kāpēc es varu nomainīt lietojamos failus uz Windows, kā es varu Linux un OS X?
Kāpēc es varu nomainīt lietojamos failus uz Windows, kā es varu Linux un OS X?

Video: Kāpēc es varu nomainīt lietojamos failus uz Windows, kā es varu Linux un OS X?

Video: Kāpēc es varu nomainīt lietojamos failus uz Windows, kā es varu Linux un OS X?
Video: How to RUN Android APPS in Windows 10 with BLUE STACKS! - YouTube 2024, Aprīlis
Anonim
 Kad jūs izmantojat Linux un OS X, operētājsistēma uzvarēs, ka jūs vairs neizdzēsīsiet šobrīd lietojamo failu uz Windows, jums to nepārprotami liegs. Kas dod? Kāpēc jūs varat rediģēt un dzēst lietojamos failus no Unix sistēmām, bet ne Windows?
Kad jūs izmantojat Linux un OS X, operētājsistēma uzvarēs, ka jūs vairs neizdzēsīsiet šobrīd lietojamo failu uz Windows, jums to nepārprotami liegs. Kas dod? Kāpēc jūs varat rediģēt un dzēst lietojamos failus no Unix sistēmām, bet ne Windows?

Šodien šī jautājumu un atbilžu sesija mums priecājas par "Stack Exchange" kopuzņēmuma SuperUser, "Sub" nodaļu, kas ir uz kopienām balstīta Q & A tīmekļa vietņu grupa.

Jautājums

SuperUser lasītājs the.Midget vēlas uzzināt, kāpēc Linux un Windows apstrādā lietojamos failus citādi:

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.

Tātad, kas notiek aiz ainas un neļauj viņam nevainīgi dzēst lietas Windows, kā viņš var Linux?

Atbilde

SuperUser atbalstītāji izskaidro situāciju, kas saistīta ar mēmizmēģinājumu. Amazed raksta:

Ikreiz, kad atverat vai izpildāt failu sistēmā Windows, sistēma Windows bloķē failu (tas ir vienkāršošana, bet parasti tā ir taisnība). Failu, ko bloķē kāds process, nevar izdzēst, kamēr šis process to neizlaiž. Tāpēc ikreiz, kad operētājsistēmai Windows ir jāatjaunina pati programma, tā ir jāpārstart, lai tā stātos spēkā.

No otras puses, Unix līdzīgās operētājsistēmas, piemēram, Linux un Mac OS X, neaizsargā failu, bet gan pamatā esošos diska sektorus. Tas var šķist nenozīmīgas diferenciācijas, bet tas nozīmē, ka faila sistēmas faila sistēmas satura ierakstu var izdzēst, netraucējot nevienu programmu, kurai jau ir atvērts fails. Tātad jūs varat izdzēst failu, kamēr tas joprojām tiek izpildīts vai citādi tiek izmantots, un tas turpinās pastāvēt diskā, kamēr kādam procesam ir atvērts rokturis, lai gan tā ieraksts failu tabulā ir pagājis.

David Schwartz izvērš ideju un uzsver, kā viss būtu ideāli un kā tas ir praktiski:

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.

Tur jums tas ir: divas atšķirīgas pieejas failu apstrādei dod divus dažādus rezultātus.

Vai kaut ko pievienot paskaidrojumam? Skatieties komentāros. Vēlaties lasīt citas atbildes no citiem tehnoloģiju savvy Stack Exchange lietotājiem? Šeit skatiet pilnu diskusiju pavedienu.

Ieteicams: