Tải bản đầy đủ - 0 (trang)
Chapter 28.  Heterogeneous Networking and Running Windows Programs

Chapter 28.  Heterogeneous Networking and Running Windows Programs

Tải bản đầy đủ - 0trang

noLinuxdriver,donotdespair.Althoughyoumayhavetowait

awhileforit,mostmainstreamhardwaredevicesthatare

supportedbyWindowswilleventuallybesupportedbyLinux,

too.Forexample,LinuxdriversforUSBdevicesusedtoberare

andflaky,butnowmanycommonUSBdevicesworkjustfineon

Linux.YoucangetupdatedinformationaboutwhichUSB

devicesworkonLinuxathttp://www.linux-usb.org.

YoumayalsoneedtorunWindowsinordertouse"standard"

applications,suchasPhotoshoporMicrosoftOffice.Inbothof

thesecases,therearefree,opensourceapplications(namely,

theGIMP,KOffice,andOpenOffice.org)thatcanmatchoreven

outdotheirproprietary,closed-sourceequivalents.However,it

isstillsometimesnecessarytorunWindowstoobtainaccessto

softwareproductsthathavenoLinuxequivalent,orforwhich

theLinuxcounterpartisnotfullycompatible.

ThereareessentiallyfourwaysinwhichLinuxandWindowscan

cooperate:

SharingremovablemediasuchasUSBkeys,CDs,and

floppydisks("sneakernet")

Sharingacomputerbybeinginstalledonseparate

partitions

Sharingdataoveranetwork

Runningconcurrentlyonthesamecomputerusingan

emulatororvirtualmachine

WhenWindowsandLinuxarerunningonseparatehardware,

andthesystemsarenotnetworked,afloppydiskorCD(either

CD-RorCD-RW)canbewrittenononesystemandreadonthe

other.BothWindowsandLinuxhavethecapabilitytoreadand

writeCDsinindustry-standard,ISO9660format.Thecdrecord



program,whichrunsonLinuxandotherUnixflavors,cancreate

CDsusingMicrosoft'sJolietextensionstotheISO9660

standard,makingWindowsfeelrightathomewiththedisk

format.

Amorecost-effectiveapproachistoinstallbothWindowsand

Linuxonthesamecomputer,eachinitsowndiskpartition.At

boottime,theuserisgiventhechoiceofwhichoperating

systemtorun."BootingtheSystem,"inChapter17,tellsyou

howtoconfigureamultibootsystem.Youcanthenmountyour

WindowspartitiondirectlyontotheLinuxfilesystemandaccess

theWindowsfilesinamannersimilartoregularUnixfiles.

Fornetworkedcomputers,themostoutstandingtoolforgetting

LinuxandWindowstocooperateisSamba,anopensource

softwaresuitethatletsyouaccessUnixfilesandprintersfrom

Windows.LinuxserversrunningSambacandependingonthe

circumstancesserveWindowscomputersevenfasterthan

Windowsserverscan!Inaddition,Sambahasproventobevery

stableandreliable.

TheSambapackagealsoincludesprogramsthatworkwiththe

smbfsfilesystemsupportedbyLinux,whichallowsdirectories

sharedbyWindowstobemountedontotheLinuxfilesystem.

WediscussthesmbfsfilesystemandSambainenoughdepthto

helpyoumountshareddirectoriesandgetabasic,functional

serverrunning.

Emulatorsorvirtualcomputersareformsofsoftwarethatlet

yourunWindowsapplicationsdirectlyunderLinux,orevenrun

Windowsitself.Wineisanopensourceprojectwiththegoalof

directlysupportingWindowsapplicationswithoutneedingto

installWindows.Anotherapproachisusedbythecommercial

VMwareapplication,whichisabletoconcurrentlyrunanumber

ofinstallationsofWindows,Linux,FreeBSD,orsomeother

operatingsystems.WhenrunningWindowsunderVMware,data

issharedwiththeLinuxhostusingtheSambatools.



Finally,remotedesktopapplicationsletusersononesystemlog

intoothersystemsandrunapplicationsthere,orevencontrol

theremotesystems.

Youshouldbealittleskepticalofsomeclaimsofcompatibility.

Youmightfind,forexample,thatyouneedtwicethedisk

storageinordertosupporttwooperatingsystemsandtheir

associatedfilesandapplicationsprograms,plusfileconversion

andgraphic-formatconversiontools,andsoon.Youmayfind

thathardwaretunedforoneOSwon'tbetunedfortheother,or

thatevenwhenyou'veinstalledandcorrectlyconfiguredallthe

necessarysoftware,smallcompatibilityissuesremain.



28.1.SharingPartitions

Aswe'veexplainedinthesection"MountingFilesystems"in

Chapter10,partitionsonlocalharddisksareaccessedby

mountingthemontoadirectoryintheLinuxfilesystem.Tobe

abletoreadandwritetoaspecificfilesystem,theLinuxkernel

needstohavesupportforit.



28.1.1.FilesystemsandMounting

Linuxhasfilesystemdriversthatcanreadandwritefilesonthe

traditionalFATfilesystemandthenewerVFATfilesystem,which

wasintroducedwithWindows95andsupportslongfilenames.

Italsocanreadand(withsomecaveats)writetotheNTFS

filesystemofWindowsNT/2000/XP.

In"BuildingaNewKernel"inChapter18,youlearnedhowto

buildyourownkernel.InordertobeabletoaccessDOS(used

byMS-DOSandWindows3.x)andVFAT(usedbyWindows

95/98/ME)partitions,youneedtoenableDOSFATfssupportin

theFilesystemssectionduringkernelconfiguration.Afteryou

sayyestothatoption,youcanchooseMSDOSfssupportandVFAT

(Windows-95)fssupport.ThefirstletsyoumountFATpartitions,

andthesecondletsyoumountFAT32partitions.

IfyouwanttoaccessfilesonaWindowsNTpartitionthat

carriesanNTFSfilesystem,youneedanotherdriver.Activate

theoptionNTFSfilesystemsupportduringthekernelconfiguration.

ThisletsyoumountNTFSpartitionsbyspecifyingthefile

systemtypentfs.Note,however,thatthecurrentNTFSdriver

supportsjustread-onlyaccess.Thereisaversionofthisdriver

availablethatsupportswritingaswell,butatthetimeofthis

writing,itwasstillunderdevelopment,andnotguaranteedto

workreliablywhenwritingtotheNTFSpartition.Readthe



documentationcarefullybeforeinstallingandusingit!

WhileLinuxisrunning,youcanmountaWindowspartitionlike

anyothertypeofpartition.Forexample,ifthethirdpartitionon

yourfirstIDEharddiskcontainsyourWindows98installation,

youcanmakethefilesinitaccessiblewiththefollowing

command,whichmustbeexecutedasroot:

#mount-tvfat/dev/hda3/mnt/windows98



The/dev/hda3argumentspecifiesthediskdrivecorresponding

totheWindows98disk,andthe/mnt/windows98argumentcan

bechangedtoanydirectoryyou'vecreatedforthepurposeof

accessingthefiles.Buthowdoyouknowthatyouneed(inthis

case)/dev/hda3?Ifyou'refamiliarwiththenamingconventions

forLinuxfilesystems,you'llknowthathda3isthethirdpartition

ontheharddiskthatisthemasterontheprimaryIDEport.

You'llfindlifeeasierifyouwritedownthepartitionswhileyou

arecreatingthemwithfdisk,butifyouneglectedtodothat,

youcanrunfdiskagaintoviewthepartitiontable.

Thefilesystemdriverssupportanumberofoptionsthatcanbe

specifiedwiththe-ooptionofthemountcommand.The

mount(8)manualpagedocumentstheoptionsthatcanbeused,

withsectionsthatexplainoptionsspecifictothefatandntfs

filesystemtypes.Thesectionforfatappliestoboththemsdos

andvfatfilesystems,andtherearetwooptionslistedtherethat

areofspecialinterest.

Thecheckoptiondetermineswhetherthekernelshouldaccept

filenamesthatarenotpermissibleonMS-DOSandwhatit

shoulddowiththem.Thisappliesonlytocreatingandrenaming

files.Youcanspecifythreevaluesforcheck.relaxedletsyoudo

justabouteverythingwiththefilename.Ifitdoesn'tfitintothe

8.3conventionofMS-DOSfiles,thefilenamewillbetruncated

accordingly.normal,thedefault,willalsotruncatethefilenames



asneeded,andalsoremovesspecialcharacterssuchas*and?

thatarenotallowedinMS-DOSfilenames.Finally,strictforbids

bothlongfilenamesandthespecialcharacters.TomakeLinux

morerestrictivewithrespecttofilenamesonthepartition

mountedinourexample,themountcommandcouldbeusedas

follows:

#mount-ocheck=strict-tmsdos/dev/sda5/mnt/dos



Thisoptionisusedwithmsdosfilesystemsonly;therestrictions

onfilenamelengthdonotapplytovfatfilesystems.

Theconvoptioncanbeuseful,butnotascommonlyasyou

mightatfirstthink.WindowsandUnixsystemshavedifferent

conventionsforhowalineendingismarkedintextfiles.

Windowsusesbothacarriagereturnandalinefeedcharacter,

whereasUnixonlyusesalinefeed.Althoughthisdoesnotmake

thefilescompletelyillegibleontheothersystem,itcanstillbe

abother.Totellthekerneltoperformtheconversionbetween

WindowsandUnixtext-filestylesautomatically,passthemount

commandtheoptionconv,whichhasthreepossiblevalues:

binary,thedefault,doesnotperformanyconversion;text

convertseveryfile;andautotriestoguesswhetherthefilein

questionisatextfileorabinaryfile.autodoesthisbylookingat

thefilenameextension.Ifthisextensionisincludedinthelistof

"knownbinaryextensions,"itisnotconverted;otherwise,itwill

beconverted.

Itisnotgenerallyadvisabletousetext,becausethiswill

invariablydamageanybinaryfiles,includinggraphicsfilesand

fileswrittenbywordprocessors,spreadsheets,andother

programs.Likewise,autocanbedangerous,becausethe

extension-baseddetectionmechanismisnotverysophisticated.

Sowesuggestyoudon'tusetheconvoptionunlessyouare

surethepartitioncontainsonlytextfiles.Stickwithbinary(the



default)andconvertyourfilesmanuallyonanas-neededbasis.

See"FileTranslationUtilities,"laterinthischapter,for

directionsonhowtodothis.

Aswithotherfilesystemtypes,youcanmountMS-DOSand

NTFSfilesystemsautomaticallyatsystembootupbyplacingan

entryinyour/etc/fstabfile.Forexample,thefollowinglinein

/etc/fstabmountsaWindows98partitiononto/win:



/dev/hda1/winvfatdefaults,umask=002,uid=500,gid=500



Whenaccessinganyofthemsdos,vfat,orntfsfilesystemsfrom

Linux,thesystemmustsomehowassignUnixpermissionsand

ownershipstothefiles.Bydefault,ownershipsandpermissions

aredeterminedusingtheuserIDandgroupID,andumasking

ofthecallingprocess.Thisworksacceptablywellwhenusing

themountcommandfromtheshell,butwhenrunfromthe

bootscripts,itwillassignfileownershipstoroot,whichmaynot

bedesired.Inthepreviousexample,weusetheumaskoption

tospecifythefileanddirectorycreationmaskthesystemwill

usewhencreatingfilesanddirectoriesinthefilesystem.Theuid

optionspecifiestheowner(asanumericuserID,ratherthana

textname),andthegidoptionspecifiesthegroup(asa

numericgroupID).Allfilesinthefilesystemwillappearonthe

Linuxsystemashavingthisownerandgroup.Sincedual-boot

systemsaregenerallyusedasworkstationsbyasingleuser,

youwillprobablywanttosettheuidandgidoptionstotheuser

IDandgroupIDofthatuser'saccount.



28.1.2.FileTranslationUtilities

Oneofthemostprominentproblemswhenitcomestosharing

filesbetweenLinuxandWindowsisthatthetwosystemshave

differentconventionsforthelineendingsintextfiles.Luckily,



thereareafewwaystosolvethisproblem:

Ifyouaccessfilesonamountedpartitiononthesame

machine,letthekernelconvertthefilesautomatically,as

describedin"FilesystemsandMounting"earlierinthis

chapter.Usethiswithcare!

WhencreatingormodifyingfilesonLinux,commoneditors

suchasEmacsandvicanhandletheconversion

automaticallyforyou.

Thereareanumberoftoolsthatconvertfilesfromonelineendingconventiontotheother.Someofthesetoolscan

alsohandleotherconversiontasksaswell.

Useyourfavoriteprogramminglanguagetowriteyourown

conversionutility.

Ifallyouareinterestedinisconvertingnewlinecharacters,

writingprogramstoperformtheconversionsissurprisingly

simple.ToconvertfromDOSformattoUnixformat,replace

everyoccurrenceof(\r\for\r\n)inthefiletoa

newline(\n).Togotheotherway,converteverynewlinetoa

.Forexample,weshowyoutwoPerlprogramsthat

dothejob.Thefirst,whichwecalld2u,convertsfromDOS

formattoUnixformat:

#!/usr/bin/perl

while(){s/\r$//;print}



Andthefollowingprogram(whichwecallu2d)convertsfrom

UnixformattoDOSformat:

#!/usr/bin/perl



while(){s/$/\r/;print}



Bothcommandsreadtheinputfilefromthestandardinput,and

writetheoutputfiletostandardoutput.Youcaneasilymodify

ourexamplestoaccepttheinputandoutputfilenamesonthe

commandline.Ifyouaretoolazytowritetheutilitiesyourself,

youcanseeifyourLinuxinstallationcontainstheprograms

dos2unixandunix2dos,whichworksimilarlytooursimpled2u

andu2dutilities,andalsoacceptfilenamesonthecommand

line.Anothersimilarpairofutilitiesisfromdosandtodos.Ifyou

cannotfindanyofthese,thentrytheflipcommand,whichis

abletotranslateinbothdirections.

Ifyoufindthesesimpleutilitiesunderpowered,youmaywant

totryrecode,aprogramthatcanconvertjustaboutanytextfilestandardtoanyother.

Themostsimplewaytouserecodeistospecifyboththeold

andthenewcharactersets(encodingsoftext-fileconventions)

andthefiletoconvert.recodewilloverwritetheoldfilewiththe

convertedone;itwillhavethesamefilename.Forexample,to

convertatextfilefromWindowstoUnix,youwouldenter:

recodeibmpc:latin1textfile



textfileisthenreplacedbytheconvertedversion.Youcan



probablyguessthattoconvertthesamefilebacktoWindows

conventions,youwoulduse:

recodelatin1:ibmpctextfile



Inadditiontoibmpc(asusedonWindows)andlatin1(asusedon



Unix),thereareotherpossibilitiesavailable,suchaslatexfor

theLATEXstyleofencodingdiacriticsandtexteforencoding

Frenchemailmessages.Youcangetthefulllistbyissuing:

recode-l



Ifyoudonotlikerecode'shabitofoverwritingyouroldfilewith

thenewone,youcanmakeuseofthefactthatrecodecanalso

readfromstandardinputandwritetostandardoutput.To

convertdostextfiletounixtextfilewithoutdeletingdostextfile,

youcoulduse:

recodeibmpc:latin1unixtextfile



Withthetoolsjustdescribed,youcanhandletextfilesquite

comfortably,butthisisonlythebeginning.Forexample,pixel

graphicsonWindowsareusuallysavedasbmpfiles.

Fortunately,thereareanumberoftoolsavailablethatcan

convertbmpfilestographicsfileformats,suchaspngorxpm,

thataremorecommononUnix.AmongthesearetheGIMP,

whichisprobablyincludedwithyourdistribution.

Thingsarelesseasywhenitcomestootherfileformats,such

asthosesavedbyofficeproductivityprograms.Althoughthe

variousincarnationsofthe.docfileformatusedbyMicrosoft

Wordhavebecomeadefactolinguafrancaforwordprocessor

filesonWindows,itwasuntilrecentlyalmostimpossibletoread

thosefilesonLinux.Fortunately,anumberofsoftware

packageshaveappearedthatcanread(andsometimeseven

write).docfiles.Amongthemaretheofficeproductivitysuite

KOffice,thefreelyavailableOpenOffice.org,andthecommercial

StarOffice6.0,acloserelativetoOpenOffice.org.Beaware,

though,thattheseconversionswillneverbeperfect;itisvery



likelythatyouwillhavetomanuallyeditthefilesafterward.

EvenonWindows,conversionscanneverbe100%correct;if

youtryimportingaMicrosoftWordfileintoWordPerfect(orvice

versa),youwillseewhatwemean.

Ingeneral,themorecommonafileformatisonWindows,the

morelikelyitisthatLinuxdeveloperswillprovideameansto

readorevenwriteit.Anotherapproachmightbetoswitchto

openfileformats,suchasRichTextFormat(RTF)orExtensible

MarkupLanguage(XML),whencreatingdocumentson

Windows.IntheageoftheInternet,whereinformationis

supposedtofloatfreely,closed,undocumentedfileformatsare

ananachronism.



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 28.  Heterogeneous Networking and Running Windows Programs

Tải bản đầy đủ ngay(0 tr)

×