209-mini_fo.patch 213 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776
  1. --- a/fs/Kconfig
  2. +++ b/fs/Kconfig
  3. @@ -1449,6 +1449,9 @@ config VXFS_FS
  4. To compile this as a module, choose M here: the module will be
  5. called freevxfs. If unsure, say N.
  6. +config MINI_FO
  7. + tristate "Mini fanout overlay filesystem"
  8. +
  9. config MINIX_FS
  10. tristate "Minix file system support"
  11. depends on BLOCK
  12. --- a/fs/Makefile
  13. +++ b/fs/Makefile
  14. @@ -77,6 +77,7 @@ obj-$(CONFIG_SQUASHFS) += squashfs/
  15. obj-y += ramfs/
  16. obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
  17. obj-$(CONFIG_CODA_FS) += coda/
  18. +obj-$(CONFIG_MINI_FO) += mini_fo/
  19. obj-$(CONFIG_MINIX_FS) += minix/
  20. obj-$(CONFIG_FAT_FS) += fat/
  21. obj-$(CONFIG_MSDOS_FS) += msdos/
  22. --- /dev/null
  23. +++ b/fs/mini_fo/aux.c
  24. @@ -0,0 +1,577 @@
  25. +/*
  26. + * Copyright (c) 1997-2003 Erez Zadok
  27. + * Copyright (c) 2001-2003 Stony Brook University
  28. + *
  29. + * For specific licensing information, see the COPYING file distributed with
  30. + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
  31. + *
  32. + * This Copyright notice must be kept intact and distributed with all
  33. + * fistgen sources INCLUDING sources generated by fistgen.
  34. + */
  35. +/*
  36. + * Copyright (C) 2004, 2005 Markus Klotzbuecher <[email protected]>
  37. + *
  38. + * This program is free software; you can redistribute it and/or
  39. + * modify it under the terms of the GNU General Public License
  40. + * as published by the Free Software Foundation; either version
  41. + * 2 of the License, or (at your option) any later version.
  42. + */
  43. +/*
  44. + * $Id$
  45. + */
  46. +
  47. +#ifdef HAVE_CONFIG_H
  48. +# include <config.h>
  49. +#endif
  50. +
  51. +#include "fist.h"
  52. +#include "mini_fo.h"
  53. +
  54. +/* check if file exists in storage */
  55. +int exists_in_storage(dentry_t *dentry)
  56. +{
  57. + check_mini_fo_dentry(dentry);
  58. + if(dtost(dentry) == MODIFIED || dtost(dentry) == CREATED || dtost(dentry) == DEL_REWRITTEN)
  59. + return 1;
  60. + return 0;
  61. +}
  62. +
  63. +/* check if dentry is in an existing state */
  64. +int is_mini_fo_existant(dentry_t *dentry)
  65. +{
  66. + check_mini_fo_dentry(dentry);
  67. +
  68. + if(dtost(dentry) == DELETED || dtost(dentry) == NON_EXISTANT)
  69. + return 0;
  70. + else
  71. + return 1;
  72. +}
  73. +
  74. +/*
  75. + * This function will create a negative storage dentry for
  76. + * dentry, what is required for many create like options.
  77. + * It will create the storage structure if necessary.
  78. + */
  79. +int get_neg_sto_dentry(dentry_t *dentry)
  80. +{
  81. + int err = 0;
  82. + unsigned int len;
  83. + const unsigned char *name;
  84. +
  85. + if(!dentry ||
  86. + !dtopd(dentry) ||
  87. + !(dtost(dentry) == UNMODIFIED ||
  88. + dtost(dentry) == NON_EXISTANT ||
  89. + dtost(dentry) == DELETED)) {
  90. + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: invalid dentry passed.\n");
  91. + err = -1;
  92. + goto out;
  93. + }
  94. + /* Have we got a neg. dentry already? */
  95. + if(dtohd2(dentry)) {
  96. + err = 0;
  97. + goto out;
  98. + }
  99. + if(dtost(dentry->d_parent) == UNMODIFIED) {
  100. + /* build sto struct */
  101. + err = build_sto_structure(dentry->d_parent->d_parent, dentry->d_parent);
  102. + if(err ||
  103. + dtost(dentry->d_parent) != MODIFIED) {
  104. + printk(KERN_CRIT "mini_fo: get_neg_sto_dentry: ERROR building sto structure.\n");
  105. + err = -1;
  106. + goto out;
  107. + }
  108. + }
  109. +
  110. + len = dentry->d_name.len;
  111. + name = dentry->d_name.name;
  112. +
  113. + dtohd2(dentry) =
  114. + lookup_one_len(name, dtohd2(dentry->d_parent), len);
  115. +
  116. + out:
  117. + return err;
  118. +}
  119. +
  120. +int check_mini_fo_dentry(dentry_t *dentry)
  121. +{
  122. + ASSERT(dentry != NULL);
  123. + ASSERT(dtopd(dentry) != NULL);
  124. + ASSERT((dtohd(dentry) != NULL) || (dtohd2(dentry) != NULL));
  125. +
  126. +/* if(dtost(dentry) == MODIFIED) { */
  127. +/* ASSERT(dentry->d_inode != NULL); */
  128. +/* ASSERT(dtohd(dentry) != NULL); */
  129. +/* ASSERT(dtohd(dentry)->d_inode != NULL); */
  130. +/* ASSERT(dtohd2(dentry) != NULL); */
  131. +/* ASSERT(dtohd2(dentry)->d_inode != NULL); */
  132. +/* } */
  133. +/* else if(dtost(dentry) == UNMODIFIED) { */
  134. +/* ASSERT(dentry->d_inode != NULL); */
  135. +/* ASSERT( */
  136. +/* } */
  137. + return 0;
  138. +}
  139. +
  140. +int check_mini_fo_file(file_t *file)
  141. +{
  142. + ASSERT(file != NULL);
  143. + ASSERT(ftopd(file) != NULL);
  144. + ASSERT(file->f_dentry != NULL);
  145. +
  146. + /* violent checking, check depending of state and type
  147. + * if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {}
  148. + */
  149. + ASSERT((ftohf(file) != NULL) || (ftohf2(file) != NULL));
  150. + return 0;
  151. +}
  152. +
  153. +int check_mini_fo_inode(inode_t *inode)
  154. +{
  155. + ASSERT(inode != NULL);
  156. + ASSERT(itopd(inode) != NULL);
  157. + ASSERT((itohi(inode) != NULL) || (itohi2(inode) != NULL));
  158. + return 0;
  159. +}
  160. +
  161. +/*
  162. + * will walk a base path as provided by get_mini_fo_bpath and return
  163. + * the (hopefully ;-) ) positive dentry of the renamed base dir.
  164. + *
  165. + * This does some work of path_init.
  166. + */
  167. +dentry_t *bpath_walk(super_block_t *sb, char *bpath)
  168. +{
  169. + int err;
  170. + struct vfsmount *mnt;
  171. + struct nameidata nd;
  172. +
  173. + /* be paranoid */
  174. + if(!bpath || bpath[0] != '/') {
  175. + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid string.\n");
  176. + return NULL;
  177. + }
  178. + if(!sb || !stopd(sb)) {
  179. + printk(KERN_CRIT "mini_fo: bpath_walk: Invalid sb.\n");
  180. + return NULL;
  181. + }
  182. +
  183. + /* fix this: how do I reach this lock?
  184. + * read_lock(&current->fs->lock); */
  185. + mnt = mntget(stopd(sb)->hidden_mnt);
  186. + /* read_unlock(&current->fs->lock); */
  187. +
  188. + err = vfs_path_lookup(mnt->mnt_root, mnt, bpath+1, 0, &nd);
  189. +
  190. + /* validate */
  191. + if (err || !nd.dentry || !nd.dentry->d_inode) {
  192. + printk(KERN_CRIT "mini_fo: bpath_walk: path_walk failed.\n");
  193. + return NULL;
  194. + }
  195. + return nd.dentry;
  196. +}
  197. +
  198. +
  199. +/* returns the full path of the basefile incl. its name */
  200. +int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len)
  201. +{
  202. + char *buf_walker;
  203. + int len = 0;
  204. + dentry_t *sky_walker;
  205. +
  206. + if(!dentry || !dtohd(dentry)) {
  207. + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: invalid dentry passed.\n");
  208. + return -1;
  209. + }
  210. + sky_walker = dtohd(dentry);
  211. +
  212. + do {
  213. + len += sky_walker->d_name.len + 1 ; /* 1 for '/' */
  214. + sky_walker = sky_walker->d_parent;
  215. + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
  216. +
  217. + /* 1 to oil the loop */
  218. + *bpath = (char*) kmalloc(len + 1, GFP_KERNEL);
  219. + if(!*bpath) {
  220. + printk(KERN_CRIT "mini_fo: get_mini_fo_bpath: out of mem.\n");
  221. + return -1;
  222. + }
  223. + buf_walker = *bpath+len; /* put it on last char */
  224. + *buf_walker = '\n';
  225. + sky_walker = dtohd(dentry);
  226. +
  227. + do {
  228. + buf_walker -= sky_walker->d_name.len;
  229. + strncpy(buf_walker,
  230. + sky_walker->d_name.name,
  231. + sky_walker->d_name.len);
  232. + *(--buf_walker) = '/';
  233. + sky_walker = sky_walker->d_parent;
  234. + } while(sky_walker != stopd(dentry->d_inode->i_sb)->base_dir_dentry);
  235. +
  236. + /* bpath_len doesn't count newline! */
  237. + *bpath_len = len;
  238. + return 0;
  239. +}
  240. +
  241. +int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
  242. + dentry_t *src_dentry, struct vfsmount *src_mnt)
  243. +{
  244. + void *buf;
  245. + mm_segment_t old_fs;
  246. + file_t *tgt_file;
  247. + file_t *src_file;
  248. + int bytes, len, tmp, err;
  249. + err = 0;
  250. +
  251. + if(!(tgt_dentry->d_inode && src_dentry->d_inode)) {
  252. + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, neg. dentry passed.\n");
  253. + err = -EINVAL;
  254. + goto out;
  255. + }
  256. +
  257. + dget(tgt_dentry);
  258. + dget(src_dentry);
  259. + mntget(tgt_mnt);
  260. + mntget(src_mnt);
  261. +
  262. + /* open file write only */
  263. + tgt_file = dentry_open(tgt_dentry, tgt_mnt, 0x1);
  264. + if(!tgt_file || IS_ERR(tgt_file)) {
  265. + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening target file.\n");
  266. + err = PTR_ERR(tgt_file);
  267. + goto out_err;
  268. + }
  269. +
  270. + /* open file read only */
  271. + src_file = dentry_open(src_dentry, src_mnt, 0x0);
  272. + if(!src_file || IS_ERR(src_file)) {
  273. + printk(KERN_CRIT "mini_fo_cp_cont: ERROR opening source file.\n");
  274. + err = PTR_ERR(src_file);
  275. +
  276. + /* close target file */
  277. + fput(tgt_file);
  278. + goto out_err;
  279. + }
  280. +
  281. + /* check if the filesystem(s) support read respective write */
  282. + if(!src_file->f_op->read || !tgt_file->f_op->write) {
  283. + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, no fs read or write support.\n");
  284. + err = -EPERM;
  285. + goto out_close;
  286. + }
  287. +
  288. + /* allocate a page for transfering the data */
  289. + buf = (void *) __get_free_page(GFP_KERNEL);
  290. + if(!buf) {
  291. + printk(KERN_CRIT "mini_fo_cp_cont: ERROR, out of kernel mem.\n");
  292. + goto out_err;
  293. + }
  294. +
  295. + tgt_file->f_pos = 0;
  296. + src_file->f_pos = 0;
  297. +
  298. + old_fs = get_fs();
  299. + set_fs(KERNEL_DS);
  300. +
  301. + /* Doing this I assume that a read operation will return a full
  302. + * buffer while there is still data to read, and a less than
  303. + * full buffer when all data has been read.
  304. + */
  305. + bytes = len = PAGE_SIZE;
  306. + while(bytes == len) {
  307. + bytes = src_file->f_op->read(src_file, buf, len,
  308. + &src_file->f_pos);
  309. + tmp = tgt_file->f_op->write(tgt_file, buf, bytes,
  310. + &tgt_file->f_pos);
  311. + if(tmp != bytes) {
  312. + printk(KERN_CRIT "mini_fo_cp_cont: ERROR writing.\n");
  313. + goto out_close_unset;
  314. + }
  315. + }
  316. +
  317. + free_page((unsigned long) buf);
  318. + set_fs(old_fs);
  319. + fput(tgt_file);
  320. + fput(src_file);
  321. + goto out;
  322. +
  323. + out_close_unset:
  324. + free_page((unsigned long) buf);
  325. + set_fs(old_fs);
  326. +
  327. + out_close:
  328. + fput(tgt_file);
  329. + fput(src_file);
  330. +
  331. + out_err:
  332. + dput(tgt_dentry);
  333. + dput(src_dentry);
  334. +
  335. + /* mk: not sure if this need to be done */
  336. + mntput(tgt_mnt);
  337. + mntput(src_mnt);
  338. +
  339. + out:
  340. + return err;
  341. +}
  342. +
  343. +/* mk:
  344. + * ndl (no-duplicate list) stuff
  345. + * This is used in mini_fo_readdir, to save the storage directory contents
  346. + * and later when reading base, match them against the list in order
  347. + * to avoid duplicates.
  348. + */
  349. +
  350. +/* add a file specified by name and len to the ndl
  351. + * Return values: 0 on success, <0 on failure.
  352. + */
  353. +int ndl_add_entry(struct readdir_data *rd, const char *name, int len)
  354. +{
  355. + struct ndl_entry *tmp_entry;
  356. +
  357. + tmp_entry = (struct ndl_entry *)
  358. + kmalloc(sizeof(struct ndl_entry), GFP_KERNEL);
  359. + if(!tmp_entry) {
  360. + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
  361. + return -ENOMEM;
  362. + }
  363. + tmp_entry->name = (char*) kmalloc(len, GFP_KERNEL);
  364. + if(!tmp_entry->name) {
  365. + printk(KERN_CRIT "mini_fo: ndl_add_entry: out of mem.\n");
  366. + return -ENOMEM;
  367. + }
  368. + strncpy(tmp_entry->name, name, len);
  369. + tmp_entry->len = len;
  370. +
  371. + list_add(&tmp_entry->list, &rd->ndl_list);
  372. + rd->ndl_size++;
  373. + return 0;
  374. +}
  375. +
  376. +/* delete all list entries and free memory */
  377. +void ndl_put_list(struct readdir_data *rd)
  378. +{
  379. + struct list_head *tmp;
  380. + struct ndl_entry *tmp_entry;
  381. +
  382. + if(rd->ndl_size <= 0)
  383. + return;
  384. + while(!list_empty(&rd->ndl_list)) {
  385. + tmp = rd->ndl_list.next;
  386. + list_del(tmp);
  387. + tmp_entry = list_entry(tmp, struct ndl_entry, list);
  388. + kfree(tmp_entry->name);
  389. + kfree(tmp_entry);
  390. + }
  391. + rd->ndl_size = 0;
  392. +}
  393. +
  394. +/* Check if a file specified by name and len is in the ndl
  395. + * Return value: 0 if not in list, 1 if file is found in ndl.
  396. + */
  397. +int ndl_check_entry(struct readdir_data *rd, const char *name, int len)
  398. +{
  399. + struct list_head *tmp;
  400. + struct ndl_entry *tmp_entry;
  401. +
  402. + if(rd->ndl_size <= 0)
  403. + return 0;
  404. +
  405. + list_for_each(tmp, &rd->ndl_list) {
  406. + tmp_entry = list_entry(tmp, struct ndl_entry, list);
  407. + if(tmp_entry->len != len)
  408. + continue;
  409. + if(!strncmp(tmp_entry->name, name, len))
  410. + return 1;
  411. + }
  412. + return 0;
  413. +}
  414. +
  415. +/* mk:
  416. + * Recursive function to create corresponding directorys in the storage fs.
  417. + * The function will build the storage directorys up to dentry.
  418. + */
  419. +int build_sto_structure(dentry_t *dir, dentry_t *dentry)
  420. +{
  421. + int err;
  422. + dentry_t *hidden_sto_dentry;
  423. + dentry_t *hidden_sto_dir_dentry;
  424. +
  425. + if(dentry->d_parent != dir) {
  426. + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [1].\n");
  427. + return 1;
  428. + }
  429. +
  430. + if(dtost(dir) != MODIFIED) {
  431. + err = build_sto_structure(dir->d_parent, dentry->d_parent);
  432. + if(err)
  433. + return err;
  434. + }
  435. +
  436. + /* ok, coming back again. */
  437. + check_mini_fo_dentry(dentry);
  438. + hidden_sto_dentry = dtohd2(dentry);
  439. +
  440. + if(!hidden_sto_dentry) {
  441. + /*
  442. + * This is the case after creating the first
  443. + * hidden_sto_dentry.
  444. + * After one negative storage_dentry, all pointers to
  445. + * hidden_storage dentries are set to NULL. We need to
  446. + * create the negative dentry before we create the storage
  447. + * file.
  448. + */
  449. + unsigned int len;
  450. + const unsigned char *name;
  451. + len = dtohd(dentry)->d_name.len;
  452. + name = dtohd(dentry)->d_name.name;
  453. + hidden_sto_dentry = lookup_one_len(name, dtohd2(dir), len);
  454. + dtohd2(dentry) = hidden_sto_dentry;
  455. + }
  456. +
  457. + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
  458. + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
  459. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  460. + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  461. +#else
  462. + down(&hidden_sto_dir_dentry->d_inode->i_sem);
  463. +#endif
  464. + /* lets be safe */
  465. + if(dtohd2(dir) != hidden_sto_dir_dentry) {
  466. + printk(KERN_CRIT "mini_fo: build_sto_structure: invalid parameter or meta data corruption [2].\n");
  467. + return 1;
  468. + }
  469. +
  470. + /* check for errors in lock_parent */
  471. + err = PTR_ERR(hidden_sto_dir_dentry);
  472. + if(IS_ERR(hidden_sto_dir_dentry)) {
  473. + printk(KERN_CRIT "mini_fo: build_sto_structure: lock_parent failed.\n");
  474. + return err;
  475. + }
  476. +
  477. + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
  478. + hidden_sto_dentry,
  479. + dir->d_inode->i_mode);
  480. +
  481. + if(err) {
  482. + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [1].\n");
  483. + /* was: unlock_dir(dir); */
  484. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  485. + mutex_unlock(&dir->d_inode->i_mutex);
  486. +#else
  487. + up(&dir->d_inode->i_sem);
  488. +#endif
  489. + dput(dir);
  490. + return err;
  491. + }
  492. +
  493. + /* everything ok! */
  494. + if(!dtohd2(dentry)->d_inode) {
  495. + printk(KERN_CRIT "mini_fo: build_sto_structure: failed to create storage dir [2].\n");
  496. + /* was: unlock_dir(dir); */
  497. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  498. + mutex_unlock(&dir->d_inode->i_mutex);
  499. +#else
  500. + up(&dir->d_inode->i_sem);
  501. +#endif
  502. + dput(dir);
  503. + return 1;
  504. + }
  505. +
  506. + /* interpose the new inode and set new state */
  507. + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
  508. + dtopd(dentry)->state = MODIFIED;
  509. +
  510. + /* initalize the wol list */
  511. + itopd(dentry->d_inode)->deleted_list_size = -1;
  512. + itopd(dentry->d_inode)->renamed_list_size = -1;
  513. + meta_build_lists(dentry);
  514. +
  515. + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
  516. + fist_copy_attr_timesizes(dir->d_inode,
  517. + hidden_sto_dir_dentry->d_inode);
  518. + dir->d_inode->i_nlink++;
  519. + /* was: unlock_dir(hidden_sto_dir_dentry); */
  520. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  521. + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  522. +#else
  523. + up(&hidden_sto_dir_dentry->d_inode->i_sem);
  524. +#endif
  525. + dput(hidden_sto_dir_dentry);
  526. + return 0;
  527. +}
  528. +
  529. +
  530. +#if 0 /* unused */
  531. +
  532. +/*
  533. + * Read "len" bytes from "filename" into "buf".
  534. + * "buf" is in kernel space.
  535. + */
  536. +int
  537. +mini_fo_read_file(const char *filename, void *buf, int len)
  538. +{
  539. + file_t *filp;
  540. + mm_segment_t oldfs;
  541. + int bytes;
  542. + /* Chroot? Maybe NULL isn't right here */
  543. + filp = filp_open(filename, O_RDONLY, 0);
  544. + if (!filp || IS_ERR(filp)) {
  545. + printk("mini_fo_read_file err %d\n", (int) PTR_ERR(filp));
  546. + return -1; /* or do something else */
  547. + }
  548. +
  549. + if (!filp->f_op->read)
  550. + return -2; /* file(system) doesn't allow reads */
  551. +
  552. + /* now read len bytes from offset 0 */
  553. + filp->f_pos = 0; /* start offset */
  554. + oldfs = get_fs();
  555. + set_fs(KERNEL_DS);
  556. + bytes = filp->f_op->read(filp, buf, len, &filp->f_pos);
  557. + set_fs(oldfs);
  558. +
  559. + /* close the file */
  560. + fput(filp);
  561. +
  562. + return bytes;
  563. +}
  564. +
  565. +
  566. +
  567. +/*
  568. + * Write "len" bytes from "buf" to "filename"
  569. + * "buf" is in kernel space.
  570. + */
  571. +int
  572. +mini_fo_write_file(const char *filename, void *buf, int len)
  573. +{
  574. + file_t *filp;
  575. + mm_segment_t oldfs;
  576. + int bytes;
  577. + /* Chroot? Maybe NULL isn't right here */
  578. + filp = filp_open(filename, O_RDWR|O_CREAT, 0640);
  579. + if (!filp || IS_ERR(filp)) {
  580. + printk("mini_fo_write_file err %d\n", (int) PTR_ERR(filp));
  581. + return -1; /* or do something else */
  582. + }
  583. +
  584. + if (!filp->f_op->write)
  585. + return -2; /* file(system) doesn't allow writes */
  586. +
  587. + /* now write len bytes from offset 0 */
  588. + filp->f_pos = 0; /* start offset */
  589. + oldfs = get_fs();
  590. + set_fs(KERNEL_DS);
  591. + bytes = filp->f_op->write(filp, buf, len, &filp->f_pos);
  592. + set_fs(oldfs);
  593. +
  594. + /* close the file */
  595. + fput(filp);
  596. +
  597. + return bytes;
  598. +}
  599. +
  600. +#endif /* unused */
  601. +
  602. --- /dev/null
  603. +++ b/fs/mini_fo/ChangeLog
  604. @@ -0,0 +1,281 @@
  605. +2006-01-24 Markus Klotzbuecher <[email protected]>
  606. +
  607. + * Add tons of ugly ifdefs to Ed L. Cashin's mutex patch to
  608. + retain backwards compatibility.
  609. +
  610. +2006-01-24 Ed L. Cashin <[email protected]>
  611. +
  612. + * Support for the new mutex infrastructure
  613. + (7892f2f48d165a34b0b8130c8a195dfd807b8cb6)
  614. +
  615. +2005-10-15 Markus Klotzbuecher <[email protected]>
  616. +
  617. + * Bugfix for a serious memory leak in mini_fo_follow_link.
  618. +
  619. +2005-09-21 Markus Klotzbuecher <mk@mary>
  620. +
  621. + * new release 0.6.1
  622. +
  623. + * fix of a compiler warning due to changes in 2.6.13
  624. +
  625. +2005-09-21 Klaus Wenninger <[email protected]>
  626. +
  627. + * file.c: readdir: fix for a bug that caused directory entries
  628. + to show up twice when using storage filesystems such as
  629. + minixfs or pramfs.
  630. +
  631. +2005-06-30 Eric Lammerts <[email protected]>
  632. +
  633. + * fix for an oops when overwriting a binary thats beeing
  634. + executed.
  635. +
  636. +2005-06-09 <mk@mary>
  637. +
  638. + * Renamed overlay to mini_fo-overlay.
  639. +
  640. + * Added mini_fo-merge script to allow merging of storage and base
  641. + after making modifications.
  642. +
  643. +2005-05-22 root <mk@mary>
  644. +
  645. + * Added overlay script that allows to easily mount mini_fo ontop
  646. + of a given base directory
  647. +
  648. +2005-05-10 <mk@mary>
  649. +
  650. + * inode.c: xattr functions return -EOPNOSUPP instead of
  651. + -ENOSUPP, what confuses "ls -l"
  652. +
  653. + * Changed license from LGPL to GPL.
  654. +
  655. +2005-05-08 root <mk@mary>
  656. +
  657. + * Makefile: clean it up and added make install and make
  658. + uninstall.
  659. +
  660. +2005-05-06 <mk@mary>
  661. +
  662. + * merged devel branch back to main. [v0-6-0-pre3]
  663. +
  664. + * removed unused files print.c and fist_ioctl. [devel-0-0-18]
  665. +
  666. + * ioctl: removed fist_ioctl stuff, that is not needed for
  667. + now.
  668. +
  669. +2005-05-03 <mk@mary>
  670. +
  671. + * file.c: simplified mini_fo_open and mini_fo_setattr using
  672. + new state changing functions. [devel-0-0-17]
  673. +
  674. + * inode.c: Fixed getattr state bug (see below) in 2.4 function
  675. + mini_fo_inode revalidate.
  676. +
  677. + * inode.c: found an other bug in mini_fo_getattr. States are not
  678. + reliable in this function, as a file can be opened, unlinked and
  679. + the getattr function called. This results in a deleted dentry
  680. + with an inode. Fix is to ignore states and simply use the inode
  681. + available.
  682. +
  683. +2005-04-29 <mk@mary>
  684. +
  685. + * file.c: Bugfix and cleanup in fasync and fsync. [devel-0-0-16]
  686. +
  687. + * file.c: do not use mini_fo_lock so the generic version is
  688. + used (I guess).
  689. +
  690. + * inode.c: getattr, never call getattr on lower files, as this
  691. + will cause the inum to change.
  692. +
  693. + * inode.c: rename_reg_file renamed to rename_nondir, as it
  694. + doesn't matter as long it't not a dir. Removed all
  695. + rename_dev_file etc.
  696. +
  697. + * tagged as devel-0-0-15
  698. +
  699. + * inode.c: added support for chosing support for extended
  700. + attrs at compile time by XATTR define in mini_fo.h .
  701. +
  702. + * inode.c: fixed mini_fo_getattr to use mini_fo inode and not
  703. + lower again, what avoids inode number changes that confused
  704. + rm again. This is the proper solution.
  705. +
  706. +2005-04-24 <mk@mary>
  707. +
  708. + * all files: updated Copyright notive to 2005. [devel-0-0-14]
  709. +
  710. + * inode.c: fixed mini_fo_getattr to not change the inode
  711. + number, even if lower files change.
  712. +
  713. + * super.c: fixed a bug that caused deleted base file to show
  714. + up suddenly after some time, or after creating a special
  715. + file. The problem was that after some time or after special
  716. + file creating sync_sb_inodes is called by the vfs, that
  717. + called our mini_fo_put_inode. There was (wrongly) called
  718. + __meta_put_lists, that nuked the lists, although the inode
  719. + was going to continue its life. Moving __meta_put_lists to
  720. + mini_fo_clear_inode, where an inode is really destroyed,
  721. + solved the problem.
  722. +
  723. +
  724. +2005-04-23 <mk@mary>
  725. +
  726. + * state.c, aux.c: more cleaning up and
  727. + simplifications. [devel-0-0-13]
  728. +
  729. + * inode.c: implemented mini_fo_getattr, that was required for
  730. + 2.6 because inode_revalidate has been remove there, and the
  731. + old "du" bug returned.
  732. +
  733. +
  734. +2005-04-20 <mk@mary>
  735. +
  736. + * aux.c: get_neg_sto_dentry(): allow to be called for dentries
  737. + in state UNMODIFIED, NON_EXISTANT _and_ DELETED.
  738. +
  739. +2005-04-19 <mk@mary>
  740. +
  741. + * Fixed a bug under 2.6 that caused files deleted via mini_fo
  742. + not to be deleted properly and therefore the fs filled up
  743. + untill no memory was left. [devel-0-0-12]
  744. +
  745. + * Added basic hard link support. This means that creating
  746. + hardlinks will work, but existing ones will be treated as
  747. + individual files. [devel-0-0-11]
  748. +
  749. +2005-04-17 <mk@mary>
  750. +
  751. + * Bugfixes
  752. +
  753. +2005-04-13 root <mk@mary>
  754. +
  755. + * Added file state.c for the state transition
  756. + functions. Doesn't work very well yet, though...
  757. +
  758. +2005-04-12 <mk@mary>
  759. +
  760. + * Porting to 2.6 started, which is easier than expected, also
  761. + due to Olivier previous work.
  762. +
  763. +2005-04-08 <mk@mary>
  764. +
  765. + * Fixed the bug that caused du to return invalid sizes of
  766. + directory trees. The problem was that
  767. + mini_fo_inode_revalidate didn't always copy the attributes
  768. + from the base inode properly.
  769. +
  770. +2005-04-01 Markus Klotzbuecher <mk@chasey>
  771. +
  772. + * Merged devel branch back to main trunk and updated the
  773. + RELEASE notes. This will be 0-6-0-pre1.
  774. +
  775. +2005-03-31 Markus Klotzbuecher <mk@chasey>
  776. +
  777. + * Fixed some bugs in rename_reg_file, that only showed up in
  778. + the kernel compile test. Kernel compiles cleanly ontop of
  779. + mini_fo, now also make mrproper etc. work. Seems pretty stable.
  780. +
  781. +2005-03-28 Markus Klotzbuecher <mk@chasey>
  782. +
  783. + * Many, many directory renaming bugfixes and a lot of other
  784. + cleanup. Dir renaming seems to work relatively stable.
  785. +
  786. +2005-03-22 Markus Klotzbuecher <mk@chasey>
  787. +
  788. + * Finished implementing lightweight directory renaming. Some
  789. + basic testing indicates it works fine.
  790. + Next is to implement testcases for the testsuite and confirm
  791. + everything is really working ok.
  792. +
  793. +2005-03-18 Markus Klotzbuecher <mk@chasey>
  794. +
  795. + * Finished implementing meta.c stuff required for directory
  796. + renaming.
  797. +
  798. +2005-03-17 Markus Klotzbuecher <mk@chasey>
  799. +
  800. + * Fixed all compile warnings + an extremly old bug that
  801. + somehow crept in while reworking the wol stuff to the META
  802. + system. Turning on -Werror again... :-)
  803. +
  804. + * Fixed some bugs in the new rename_reg_file function.
  805. +
  806. + * Rewrote mini_fo rename and split it into several
  807. + subfunctions, that handle the different types
  808. + seperately. Rewrote the regular file function aswell, as it
  809. + was implemented somewhat inefficient.
  810. +
  811. +2005-03-16 Markus Klotzbuecher <mk@chasey>
  812. +
  813. + * Implemented new META subsystem, removed old WOL stuff in favor
  814. + if it.
  815. +
  816. + * After some basic testing everything seems ok...
  817. +
  818. +2005-03-11 Markus Klotzbuecher <mk@chasey>
  819. +
  820. + * Renaming a non regular file caused trouble because I always
  821. + tried to copy the contents. Now I only do this for regular
  822. + files. mini_fo_rename still isn't implemented properly, renaming
  823. + of device files, symlinks etc. results in a empty regular file
  824. + instead of the proper type.
  825. +
  826. + * Directory renaming suddenly works! What a surprise! I guess
  827. + this is because renaming is implemented as making a copy and
  828. + removing the original. Still this might not work
  829. + everywhere...
  830. +
  831. +2005-03-09 Markus Klotzbuecher <mk@chasey>
  832. +
  833. + * Bugfix, when a mini_fo directory that exists in storage
  834. + (state: MODIFIED, CREATED and DEL_REWRITTEN) is deleted, a
  835. + possibly existing WOL file contained in it needs to be
  836. + deleted too.
  837. +
  838. + * Starting cleanup: defined state names in order to get rid of
  839. + the state numbers.
  840. +
  841. +2005-03-08 Markus Klotzbuecher <mk@chasey>
  842. +
  843. + * Makefile fix, fist_ioctl was built against wrong sources if ARCH=um
  844. +
  845. + * Fixed a bug in dentry.c, mini_fo_d_hash. In state 4 =
  846. + DEL_REWRITTEN the hash was calculated from the base dentry,
  847. + which was wrong and and caused assertions in
  848. + __mini_fo_hidden_dentry to fail.
  849. +
  850. +2005-02-21 <mk@mary>
  851. +
  852. + * Implemented directory deleting (inode.c)
  853. +
  854. + * main.c: made mini_fo_parse_options a little more robust.
  855. +
  856. +2004-12-22 <mk@mary>
  857. +
  858. + * Makefile cleanup and uml stuff, removed unneccessary files
  859. +
  860. + * Created a new and hopefully more informative README
  861. +
  862. + * CHANGELOG: created a new CHANGELOG and added old entries reversely
  863. +
  864. +
  865. +2004-10-24 Gleb Natapov <[email protected]>
  866. +
  867. + * Fix: owner and group where not correctly copied from base to
  868. + storage.
  869. +
  870. +
  871. +2004-10-05 Gleb Natapov <[email protected]>
  872. +
  873. + * Implementation of fsync, fasync and lock mini_fo functions.
  874. +
  875. +
  876. +2004-09-29 Bob Lee <[email protected]>
  877. +
  878. + * Fix of a serious pointer bug
  879. +
  880. +
  881. +2004-09-28 Gleb Natapov <[email protected]>
  882. +
  883. + * Implementation of mini_fo_mknod and mini_fo_rename, support
  884. + for device files.
  885. +
  886. --- /dev/null
  887. +++ b/fs/mini_fo/dentry.c
  888. @@ -0,0 +1,244 @@
  889. +/*
  890. + * Copyright (c) 1997-2003 Erez Zadok
  891. + * Copyright (c) 2001-2003 Stony Brook University
  892. + *
  893. + * For specific licensing information, see the COPYING file distributed with
  894. + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
  895. + *
  896. + * This Copyright notice must be kept intact and distributed with all
  897. + * fistgen sources INCLUDING sources generated by fistgen.
  898. + */
  899. +/*
  900. + * Copyright (C) 2004, 2005 Markus Klotzbuecher <[email protected]>
  901. + *
  902. + * This program is free software; you can redistribute it and/or
  903. + * modify it under the terms of the GNU General Public License
  904. + * as published by the Free Software Foundation; either version
  905. + * 2 of the License, or (at your option) any later version.
  906. + */
  907. +
  908. +/*
  909. + * $Id$
  910. + */
  911. +
  912. +#ifdef HAVE_CONFIG_H
  913. +# include <config.h>
  914. +#endif
  915. +
  916. +#include "fist.h"
  917. +#include "mini_fo.h"
  918. +
  919. +/*
  920. + * THIS IS A BOOLEAN FUNCTION: returns 1 if valid, 0 otherwise.
  921. + */
  922. +STATIC int
  923. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  924. +mini_fo_d_revalidate(dentry_t *dentry, struct nameidata *nd)
  925. +#else
  926. +mini_fo_d_revalidate(dentry_t *dentry, int flags)
  927. +#endif
  928. +{
  929. + int err1 = 1; /* valid = 1, invalid = 0 */
  930. + int err2 = 1;
  931. + dentry_t *hidden_dentry;
  932. + dentry_t *hidden_sto_dentry;
  933. +
  934. +
  935. + check_mini_fo_dentry(dentry);
  936. +
  937. + hidden_dentry = dtohd(dentry);
  938. + hidden_sto_dentry = dtohd2(dentry);
  939. +
  940. + if(hidden_dentry &&
  941. + hidden_dentry->d_op &&
  942. + hidden_dentry->d_op->d_revalidate) {
  943. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  944. + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, nd);
  945. +#else
  946. + err1 = hidden_dentry->d_op->d_revalidate(hidden_dentry, flags);
  947. +#endif
  948. + }
  949. + if(hidden_sto_dentry &&
  950. + hidden_sto_dentry->d_op &&
  951. + hidden_sto_dentry->d_op->d_revalidate) {
  952. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  953. + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
  954. + nd);
  955. +#else
  956. + err2 = hidden_sto_dentry->d_op->d_revalidate(hidden_sto_dentry,
  957. + flags);
  958. +#endif
  959. + }
  960. +
  961. + /* mk: if one of the lower level dentries are valid,
  962. + * the mini_fo dentry is too.
  963. + */
  964. + return (err1 || err2);
  965. +}
  966. +
  967. +
  968. +STATIC int
  969. +mini_fo_d_hash(dentry_t *dentry, qstr_t *name)
  970. +{
  971. + int err = 0;
  972. + dentry_t *hidden_dentry;
  973. + dentry_t *hidden_sto_dentry;
  974. +
  975. + /* hidden_dentry = mini_fo_hidden_dentry(dentry);
  976. + * hidden_sto_dentry = mini_fo_hidden_sto_dentry(dentry); */
  977. +
  978. + /* state 1, 3, 4, 5: build the hash for the storage dentry */
  979. + if((dtopd(dentry)->state == MODIFIED) ||
  980. + (dtopd(dentry)->state == CREATED) ||
  981. + (dtopd(dentry)->state == DEL_REWRITTEN) ||
  982. + (dtopd(dentry)->state == DELETED)) {
  983. + hidden_sto_dentry = dtohd2(dentry);
  984. + if(hidden_sto_dentry &&
  985. + hidden_sto_dentry->d_op &&
  986. + hidden_sto_dentry->d_op->d_hash) {
  987. + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
  988. + }
  989. + goto out;
  990. + }
  991. + /* state 2: build the hash for the base dentry */
  992. + if(dtopd(dentry)->state == UNMODIFIED) {
  993. + hidden_dentry = dtohd(dentry);
  994. + if(hidden_dentry &&
  995. + hidden_dentry->d_op &&
  996. + hidden_dentry->d_op->d_hash) {
  997. + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
  998. + }
  999. + goto out;
  1000. + }
  1001. + /* state 6: build hash for the dentry that exists */
  1002. + if(dtopd(dentry)->state == NON_EXISTANT) {
  1003. + hidden_sto_dentry = dtohd2(dentry);
  1004. + if(hidden_sto_dentry &&
  1005. + hidden_sto_dentry->d_op &&
  1006. + hidden_sto_dentry->d_op->d_hash) {
  1007. + err = hidden_sto_dentry->d_op->d_hash(hidden_sto_dentry, name);
  1008. + goto out;
  1009. + }
  1010. + hidden_dentry = dtohd(dentry);
  1011. + if(hidden_dentry &&
  1012. + hidden_dentry->d_op &&
  1013. + hidden_dentry->d_op->d_hash) {
  1014. + err = hidden_dentry->d_op->d_hash(hidden_dentry, name);
  1015. + goto out;
  1016. + }
  1017. + }
  1018. +
  1019. + printk(KERN_CRIT "mini_fo: d_hash: invalid state detected.\n");
  1020. +
  1021. + out:
  1022. + return err;
  1023. +}
  1024. +
  1025. +
  1026. +STATIC int
  1027. +mini_fo_d_compare(dentry_t *dentry, qstr_t *a, qstr_t *b)
  1028. +{
  1029. + int err;
  1030. + dentry_t *hidden_dentry=NULL;
  1031. +
  1032. + /* hidden_dentry = mini_fo_hidden_dentry(dentry); */
  1033. + if(dtohd2(dentry))
  1034. + hidden_dentry = dtohd2(dentry);
  1035. + else if(dtohd(dentry))
  1036. + hidden_dentry = dtohd(dentry);
  1037. +
  1038. + if (hidden_dentry && hidden_dentry->d_op && hidden_dentry->d_op->d_compare) {
  1039. + err = hidden_dentry->d_op->d_compare(hidden_dentry, a, b);
  1040. + } else {
  1041. + err = ((a->len != b->len) || memcmp(a->name, b->name, b->len));
  1042. + }
  1043. +
  1044. + return err;
  1045. +}
  1046. +
  1047. +
  1048. +int
  1049. +mini_fo_d_delete(dentry_t *dentry)
  1050. +{
  1051. + dentry_t *hidden_dentry;
  1052. + dentry_t *hidden_sto_dentry;
  1053. + int err = 0;
  1054. +
  1055. + /* this could be a negative dentry, so check first */
  1056. + if (!dtopd(dentry)) {
  1057. + printk(KERN_CRIT "mini_fo_d_delete: negative dentry passed.\n");
  1058. + goto out;
  1059. + }
  1060. + hidden_dentry = dtohd(dentry);
  1061. + hidden_sto_dentry = dtohd2(dentry);
  1062. +
  1063. + if(hidden_dentry) {
  1064. + if(hidden_dentry->d_op &&
  1065. + hidden_dentry->d_op->d_delete) {
  1066. + err = hidden_dentry->d_op->d_delete(hidden_dentry);
  1067. + }
  1068. + }
  1069. + if(hidden_sto_dentry) {
  1070. + if(hidden_sto_dentry->d_op &&
  1071. + hidden_sto_dentry->d_op->d_delete) {
  1072. + err = hidden_sto_dentry->d_op->d_delete(hidden_sto_dentry);
  1073. + }
  1074. + }
  1075. +
  1076. + out:
  1077. + return err;
  1078. +}
  1079. +
  1080. +
  1081. +void
  1082. +mini_fo_d_release(dentry_t *dentry)
  1083. +{
  1084. + dentry_t *hidden_dentry;
  1085. + dentry_t *hidden_sto_dentry;
  1086. +
  1087. +
  1088. + /* this could be a negative dentry, so check first */
  1089. + if (!dtopd(dentry)) {
  1090. + printk(KERN_CRIT "mini_fo_d_release: no private data.\n");
  1091. + goto out;
  1092. + }
  1093. + hidden_dentry = dtohd(dentry);
  1094. + hidden_sto_dentry = dtohd2(dentry);
  1095. +
  1096. + if(hidden_dentry) {
  1097. + /* decrement hidden dentry's counter and free its inode */
  1098. + dput(hidden_dentry);
  1099. + }
  1100. + if(hidden_sto_dentry) {
  1101. + /* decrement hidden dentry's counter and free its inode */
  1102. + dput(hidden_sto_dentry);
  1103. + }
  1104. +
  1105. + /* free private data (mini_fo_dentry_info) here */
  1106. + kfree(dtopd(dentry));
  1107. + __dtopd(dentry) = NULL; /* just to be safe */
  1108. + out:
  1109. + return;
  1110. +}
  1111. +
  1112. +
  1113. +/*
  1114. + * we don't really need mini_fo_d_iput, because dentry_iput will call iput() if
  1115. + * mini_fo_d_iput is not defined. We left this implemented for ease of
  1116. + * tracing/debugging.
  1117. + */
  1118. +void
  1119. +mini_fo_d_iput(dentry_t *dentry, inode_t *inode)
  1120. +{
  1121. + iput(inode);
  1122. +}
  1123. +
  1124. +
  1125. +struct dentry_operations mini_fo_dops = {
  1126. + d_revalidate: mini_fo_d_revalidate,
  1127. + d_hash: mini_fo_d_hash,
  1128. + d_compare: mini_fo_d_compare,
  1129. + d_release: mini_fo_d_release,
  1130. + d_delete: mini_fo_d_delete,
  1131. + d_iput: mini_fo_d_iput,
  1132. +};
  1133. --- /dev/null
  1134. +++ b/fs/mini_fo/file.c
  1135. @@ -0,0 +1,713 @@
  1136. +/*
  1137. + * Copyright (c) 1997-2003 Erez Zadok
  1138. + * Copyright (c) 2001-2003 Stony Brook University
  1139. + *
  1140. + * For specific licensing information, see the COPYING file distributed with
  1141. + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
  1142. + *
  1143. + * This Copyright notice must be kept intact and distributed with all
  1144. + * fistgen sources INCLUDING sources generated by fistgen.
  1145. + */
  1146. +/*
  1147. + * Copyright (C) 2004, 2005 Markus Klotzbuecher <[email protected]>
  1148. + *
  1149. + * This program is free software; you can redistribute it and/or
  1150. + * modify it under the terms of the GNU General Public License
  1151. + * as published by the Free Software Foundation; either version
  1152. + * 2 of the License, or (at your option) any later version.
  1153. + */
  1154. +
  1155. +/*
  1156. + * $Id$
  1157. + */
  1158. +
  1159. +#ifdef HAVE_CONFIG_H
  1160. +# include <config.h>
  1161. +#endif
  1162. +
  1163. +#include "fist.h"
  1164. +#include "mini_fo.h"
  1165. +#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
  1166. +
  1167. +/*******************
  1168. + * File Operations *
  1169. + *******************/
  1170. +
  1171. +STATIC loff_t
  1172. +mini_fo_llseek(file_t *file, loff_t offset, int origin)
  1173. +{
  1174. + loff_t err;
  1175. + file_t *hidden_file = NULL;
  1176. +
  1177. + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
  1178. + /* Check if trying to llseek from a directory */
  1179. + err = -EISDIR;
  1180. + goto out;
  1181. + }
  1182. + if (ftopd(file) != NULL) {
  1183. + if(ftohf2(file)) {
  1184. + hidden_file = ftohf2(file);
  1185. + } else {
  1186. + hidden_file = ftohf(file);
  1187. + }
  1188. + }
  1189. +
  1190. + /* always set hidden position to this one */
  1191. + hidden_file->f_pos = file->f_pos;
  1192. +
  1193. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  1194. + memcpy(&(hidden_file->f_ra),
  1195. + &(file->f_ra),
  1196. + sizeof(struct file_ra_state));
  1197. +#else
  1198. + if (file->f_reada) { /* update readahead information if needed */
  1199. + hidden_file->f_reada = file->f_reada;
  1200. + hidden_file->f_ramax = file->f_ramax;
  1201. + hidden_file->f_raend = file->f_raend;
  1202. + hidden_file->f_ralen = file->f_ralen;
  1203. + hidden_file->f_rawin = file->f_rawin;
  1204. + }
  1205. +#endif
  1206. + if (hidden_file->f_op && hidden_file->f_op->llseek)
  1207. + err = hidden_file->f_op->llseek(hidden_file, offset, origin);
  1208. + else
  1209. + err = generic_file_llseek(hidden_file, offset, origin);
  1210. +
  1211. + if (err < 0)
  1212. + goto out;
  1213. +
  1214. + if (err != file->f_pos) {
  1215. + file->f_pos = err;
  1216. + // ION maybe this?
  1217. + // file->f_pos = hidden_file->f_pos;
  1218. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  1219. + file->f_reada = 0;
  1220. +#endif
  1221. + file->f_version++;
  1222. + }
  1223. +
  1224. + out:
  1225. + return err;
  1226. +}
  1227. +
  1228. +
  1229. +/* mk: fanout capable */
  1230. +STATIC ssize_t
  1231. +mini_fo_read(file_t *file, char *buf, size_t count, loff_t *ppos)
  1232. +{
  1233. + int err = -EINVAL;
  1234. + file_t *hidden_file = NULL;
  1235. + loff_t pos = *ppos;
  1236. +
  1237. + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
  1238. + /* Check if trying to read from a directory */
  1239. + /* printk(KERN_CRIT "mini_fo_read: ERROR: trying to read data from a directory.\n"); */
  1240. + err = -EISDIR;
  1241. + goto out;
  1242. + }
  1243. +
  1244. + if (ftopd(file) != NULL) {
  1245. + if(ftohf2(file)) {
  1246. + hidden_file = ftohf2(file);
  1247. + } else {
  1248. + hidden_file = ftohf(file);
  1249. + }
  1250. + }
  1251. +
  1252. + if (!hidden_file->f_op || !hidden_file->f_op->read)
  1253. + goto out;
  1254. +
  1255. + err = hidden_file->f_op->read(hidden_file, buf, count, &pos);
  1256. + *ppos = pos;
  1257. +
  1258. + if (err >= 0) {
  1259. + /* atime should also be updated for reads of size zero or more */
  1260. + fist_copy_attr_atime(file->f_dentry->d_inode,
  1261. + hidden_file->f_dentry->d_inode);
  1262. + }
  1263. +
  1264. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  1265. + /*
  1266. + * MAJOR HACK
  1267. + * because pread() does not have any way to tell us that it is
  1268. + * our caller, then we don't know for sure if we have to update
  1269. + * the file positions. This hack relies on read() having passed us
  1270. + * the "real" pointer of its struct file's f_pos field.
  1271. + */
  1272. + if (ppos == &file->f_pos)
  1273. + hidden_file->f_pos = *ppos = pos;
  1274. + if (hidden_file->f_reada) { /* update readahead information if needed */
  1275. + file->f_reada = hidden_file->f_reada;
  1276. + file->f_ramax = hidden_file->f_ramax;
  1277. + file->f_raend = hidden_file->f_raend;
  1278. + file->f_ralen = hidden_file->f_ralen;
  1279. + file->f_rawin = hidden_file->f_rawin;
  1280. + }
  1281. +#else
  1282. + memcpy(&(file->f_ra),&(hidden_file->f_ra),sizeof(struct file_ra_state));
  1283. +#endif
  1284. +
  1285. + out:
  1286. + return err;
  1287. +}
  1288. +
  1289. +
  1290. +/* this mini_fo_write() does not modify data pages! */
  1291. +STATIC ssize_t
  1292. +mini_fo_write(file_t *file, const char *buf, size_t count, loff_t *ppos)
  1293. +{
  1294. + int err = -EINVAL;
  1295. + file_t *hidden_file = NULL;
  1296. + inode_t *inode;
  1297. + inode_t *hidden_inode;
  1298. + loff_t pos = *ppos;
  1299. +
  1300. + /* mk: fan out: */
  1301. + if (ftopd(file) != NULL) {
  1302. + if(ftohf2(file)) {
  1303. + hidden_file = ftohf2(file);
  1304. + } else {
  1305. + /* This is bad! We have no storage file to write to. This
  1306. + * should never happen because if a file is opened for
  1307. + * writing, a copy should have been made earlier.
  1308. + */
  1309. + printk(KERN_CRIT "mini_fo: write : ERROR, no storage file to write.\n");
  1310. + err = -EINVAL;
  1311. + goto out;
  1312. + }
  1313. + }
  1314. +
  1315. + inode = file->f_dentry->d_inode;
  1316. + hidden_inode = itohi2(inode);
  1317. + if(!hidden_inode) {
  1318. + printk(KERN_CRIT "mini_fo: write: no sto inode found, not good.\n");
  1319. + goto out;
  1320. + }
  1321. +
  1322. + if (!hidden_file->f_op || !hidden_file->f_op->write)
  1323. + goto out;
  1324. +
  1325. + /* adjust for append -- seek to the end of the file */
  1326. + if (file->f_flags & O_APPEND)
  1327. + pos = inode->i_size;
  1328. +
  1329. + err = hidden_file->f_op->write(hidden_file, buf, count, &pos);
  1330. +
  1331. + /*
  1332. + * copy ctime and mtime from lower layer attributes
  1333. + * atime is unchanged for both layers
  1334. + */
  1335. + if (err >= 0)
  1336. + fist_copy_attr_times(inode, hidden_inode);
  1337. +
  1338. + *ppos = pos;
  1339. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  1340. + /*
  1341. + * XXX: MAJOR HACK
  1342. + *
  1343. + * because pwrite() does not have any way to tell us that it is
  1344. + * our caller, then we don't know for sure if we have to update
  1345. + * the file positions. This hack relies on write() having passed us
  1346. + * the "real" pointer of its struct file's f_pos field.
  1347. + */
  1348. + if (ppos == &file->f_pos)
  1349. + hidden_file->f_pos = *ppos = pos;
  1350. +#endif
  1351. + /* update this inode's size */
  1352. + if (pos > inode->i_size)
  1353. + inode->i_size = pos;
  1354. +
  1355. + out:
  1356. + return err;
  1357. +}
  1358. +
  1359. +/* Global variable to hold a file_t pointer.
  1360. + * This serves to allow mini_fo_filldir function to know which file is
  1361. + * beeing read, which is required for two reasons:
  1362. + *
  1363. + * - be able to call wol functions in order to avoid listing deleted
  1364. + * base files.
  1365. + * - if we're reading a directory which is in state 1, we need to
  1366. + * maintain a list (in mini_fo_filldir) of which files allready
  1367. + * have been copied to userspace,to detect files existing in base
  1368. + * and storage and not list them twice.
  1369. + */
  1370. +filldir_t mini_fo_filldir_orig;
  1371. +file_t *mini_fo_filldir_file;
  1372. +
  1373. +/* mainly copied from fs/readdir.c */
  1374. +STATIC int
  1375. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
  1376. +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
  1377. + u64 ino, unsigned int d_type)
  1378. +#else
  1379. +mini_fo_filldir(void * __buf, const char * name, int namlen, loff_t offset,
  1380. + ino_t ino, unsigned int d_type)
  1381. +#endif
  1382. +{
  1383. + struct getdents_callback * buf = (struct getdents_callback *) __buf;
  1384. + file_t* file = mini_fo_filldir_file;
  1385. +
  1386. + /* In theses states we filter meta files in storage (WOL) */
  1387. + if(file && (dtopd(file->f_dentry)->state == MODIFIED ||
  1388. + dtopd(file->f_dentry)->state == CREATED ||
  1389. + dtopd(file->f_dentry)->state == DEL_REWRITTEN)) {
  1390. +
  1391. + int tmp = strlen(META_FILENAME);
  1392. + if(tmp == namlen) {
  1393. + if(!strncmp(name, META_FILENAME, namlen))
  1394. + return 0;
  1395. + }
  1396. + }
  1397. +
  1398. + /* check if we are merging the contents of storage and base */
  1399. + if(file && dtopd(file->f_dentry)->state == MODIFIED) {
  1400. + /* check if we are still reading storage contents, if
  1401. + * yes, we just save the name of the file for duplicate
  1402. + * checking later. */
  1403. +
  1404. + if(!ftopd(file)->rd.sto_done) {
  1405. + /* put file into ndl list */
  1406. + if(ndl_add_entry(&ftopd(file)->rd, name, namlen))
  1407. + printk(KERN_CRIT "mini_fo_filldir: Error adding to ndl.\n");
  1408. + } else {
  1409. + /* check if file has been deleted */
  1410. + if(meta_check_d_entry(file->f_dentry, name, namlen))
  1411. + return 0;
  1412. +
  1413. + /* do duplicate checking */
  1414. + if(ndl_check_entry(&ftopd(file)->rd, name, namlen))
  1415. + return 0;
  1416. + }
  1417. + }
  1418. +
  1419. + return mini_fo_filldir_orig(buf, name, namlen, offset, ino, d_type);
  1420. +}
  1421. +
  1422. +
  1423. +STATIC int
  1424. +mini_fo_readdir(file_t *file, void *dirent, filldir_t filldir)
  1425. +{
  1426. + int err = 0;/* mk: ??? -ENOTDIR; */
  1427. + file_t *hidden_file = NULL;
  1428. + file_t *hidden_sto_file = NULL;
  1429. + inode_t *inode;
  1430. + struct getdents_callback *buf;
  1431. + int oldcount;
  1432. +
  1433. +#if defined(FIST_FILTER_NAME) || defined(FIST_FILTER_SCA)
  1434. + struct mini_fo_getdents_callback buf;
  1435. +#endif /* FIST_FILTER_NAME || FIST_FILTER_SCA */
  1436. +
  1437. + buf = (struct getdents_callback *) dirent;
  1438. + oldcount = buf->count;
  1439. + inode = file->f_dentry->d_inode;
  1440. + mini_fo_filldir_file = file;
  1441. + mini_fo_filldir_orig = filldir;
  1442. +
  1443. + ftopd(file)->rd.sto_done = 0;
  1444. + do {
  1445. + if (ftopd(file) != NULL) {
  1446. + if(ftohf2(file)) {
  1447. + hidden_sto_file = ftohf2(file);
  1448. + err = vfs_readdir(hidden_sto_file, mini_fo_filldir, dirent);
  1449. + file->f_pos = hidden_sto_file->f_pos;
  1450. + if (err > 0)
  1451. + fist_copy_attr_atime(inode, hidden_sto_file->f_dentry->d_inode);
  1452. + /* not finshed yet, we'll be called again */
  1453. + if (buf->count != oldcount)
  1454. + break;
  1455. + }
  1456. +
  1457. + ftopd(file)->rd.sto_done = 1;
  1458. +
  1459. + if(ftohf(file)) {
  1460. + hidden_file = ftohf(file);
  1461. + err = vfs_readdir(hidden_file, mini_fo_filldir, dirent);
  1462. + file->f_pos = hidden_file->f_pos;
  1463. + if (err > 0)
  1464. + fist_copy_attr_atime(inode, hidden_file->f_dentry->d_inode);
  1465. + }
  1466. +
  1467. + }
  1468. + } while (0);
  1469. +
  1470. + /* mk:
  1471. + * we need to check if all the directory data has been copied to userspace,
  1472. + * or if we will be called again by userspace to complete the operation.
  1473. + */
  1474. + if(buf->count == oldcount) {
  1475. + ndl_put_list(&ftopd(file)->rd);
  1476. + }
  1477. +
  1478. + /* unset this, safe */
  1479. + mini_fo_filldir_file = NULL;
  1480. + return err;
  1481. +}
  1482. +
  1483. +
  1484. +STATIC unsigned int
  1485. +mini_fo_poll(file_t *file, poll_table *wait)
  1486. +{
  1487. + unsigned int mask = DEFAULT_POLLMASK;
  1488. + file_t *hidden_file = NULL;
  1489. +
  1490. + if (ftopd(file) != NULL) {
  1491. + if(ftohf2(file)) {
  1492. + hidden_file = ftohf2(file);
  1493. + } else {
  1494. + hidden_file = ftohf(file);
  1495. + }
  1496. + }
  1497. +
  1498. + if (!hidden_file->f_op || !hidden_file->f_op->poll)
  1499. + goto out;
  1500. +
  1501. + mask = hidden_file->f_op->poll(hidden_file, wait);
  1502. +
  1503. + out:
  1504. + return mask;
  1505. +}
  1506. +
  1507. +/* FIST-LITE special version of mmap */
  1508. +STATIC int
  1509. +mini_fo_mmap(file_t *file, vm_area_t *vma)
  1510. +{
  1511. + int err = 0;
  1512. + file_t *hidden_file = NULL;
  1513. +
  1514. + /* fanout capability */
  1515. + if (ftopd(file) != NULL) {
  1516. + if(ftohf2(file)) {
  1517. + hidden_file = ftohf2(file);
  1518. + } else {
  1519. + hidden_file = ftohf(file);
  1520. + }
  1521. + }
  1522. +
  1523. + ASSERT(hidden_file != NULL);
  1524. + ASSERT(hidden_file->f_op != NULL);
  1525. + ASSERT(hidden_file->f_op->mmap != NULL);
  1526. +
  1527. + vma->vm_file = hidden_file;
  1528. + err = hidden_file->f_op->mmap(hidden_file, vma);
  1529. + get_file(hidden_file); /* make sure it doesn't get freed on us */
  1530. + fput(file); /* no need to keep extra ref on ours */
  1531. +
  1532. + return err;
  1533. +}
  1534. +
  1535. +
  1536. +
  1537. +STATIC int
  1538. +mini_fo_open(inode_t *inode, file_t *file)
  1539. +{
  1540. + int err = 0;
  1541. + int hidden_flags;
  1542. + file_t *hidden_file = NULL;
  1543. + dentry_t *hidden_dentry = NULL;
  1544. +
  1545. + /* fanout stuff */
  1546. + file_t *hidden_sto_file = NULL;
  1547. + dentry_t *hidden_sto_dentry = NULL;
  1548. +
  1549. + __ftopd(file) =
  1550. + kmalloc(sizeof(struct mini_fo_file_info), GFP_KERNEL);
  1551. + if (!ftopd(file)) {
  1552. + err = -ENOMEM;
  1553. + goto out;
  1554. + }
  1555. +
  1556. + /* init the readdir_helper structure */
  1557. + INIT_LIST_HEAD(&ftopd(file)->rd.ndl_list);
  1558. + ftopd(file)->rd.ndl_size = 0;
  1559. +
  1560. + /* In certain paths this could stay uninitalized and cause trouble */
  1561. + ftohf(file) = NULL;
  1562. + ftohf2(file) = NULL;
  1563. + hidden_flags = file->f_flags;
  1564. +
  1565. + /* create storage files? */
  1566. + if(dtost(file->f_dentry) == UNMODIFIED) {
  1567. + if(!IS_WRITE_FLAG(file->f_flags)) {
  1568. + hidden_dentry = dtohd(file->f_dentry);
  1569. + dget(hidden_dentry);
  1570. + /* dentry_open will decrement mnt refcnt if err.
  1571. + * otherwise fput() will do an mntput() for us upon file close. */
  1572. + mntget(stopd(inode->i_sb)->hidden_mnt);
  1573. + hidden_file = dentry_open(hidden_dentry,
  1574. + stopd(inode->i_sb)->hidden_mnt,
  1575. + hidden_flags);
  1576. + if (IS_ERR(hidden_file)) {
  1577. + err = PTR_ERR(hidden_file);
  1578. + dput(hidden_dentry);
  1579. + goto out;
  1580. + }
  1581. + ftohf(file) = hidden_file; /* link two files */
  1582. + goto out;
  1583. + }
  1584. + else {
  1585. + if(S_ISDIR(file->f_dentry->d_inode->i_mode)) {
  1586. + err = dir_unmod_to_mod(file->f_dentry);
  1587. + } else
  1588. + err = nondir_unmod_to_mod(file->f_dentry, 1);
  1589. +
  1590. + if (err) {
  1591. + printk("mini_fo_open: ERROR creating storage file.\n");
  1592. + goto out;
  1593. + }
  1594. + }
  1595. + }
  1596. + hidden_sto_dentry = dtohd2(file->f_dentry);
  1597. + dget(hidden_sto_dentry);
  1598. +
  1599. + if(dtopd(file->f_dentry)->state == MODIFIED) {
  1600. + /* Directorys are special, interpose on both lower level files */
  1601. + if(S_ISDIR(itohi(inode)->i_mode)) {
  1602. + /* check for invalid file types of lower level files */
  1603. + if(!(S_ISDIR(itohi(inode)->i_mode) && S_ISDIR(itohi2(inode)->i_mode))) {
  1604. + printk(KERN_CRIT "mini_fo_open: meta data corruption detected.\n");
  1605. + dput(hidden_sto_dentry);
  1606. + err = -EINVAL;
  1607. + goto out;
  1608. + }
  1609. +
  1610. + /* lower level directorys are ok, open the base file */
  1611. + hidden_dentry = dtohd(file->f_dentry);
  1612. + dget(hidden_dentry);
  1613. +
  1614. + mntget(stopd(inode->i_sb)->hidden_mnt);
  1615. + hidden_file = dentry_open(hidden_dentry,
  1616. + stopd(inode->i_sb)->hidden_mnt,
  1617. + hidden_flags);
  1618. + if (IS_ERR(hidden_file)) {
  1619. + err = PTR_ERR(hidden_file);
  1620. + dput(hidden_dentry);
  1621. + dput(hidden_sto_dentry);
  1622. + goto out;
  1623. + }
  1624. + ftohf(file) = hidden_file; /* link the two files */
  1625. + }
  1626. + }
  1627. +
  1628. + if(!exists_in_storage(file->f_dentry)) {
  1629. + printk(KERN_CRIT "mini_fo_open: invalid file state detected.\n");
  1630. + err = -EINVAL;
  1631. + dput(hidden_sto_dentry);
  1632. +
  1633. + /* If the base file has been opened, we need to close it here */
  1634. + if(ftohf(file)) {
  1635. + if (hidden_file->f_op && hidden_file->f_op->flush)
  1636. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
  1637. + hidden_file->f_op->flush(hidden_file, NULL);
  1638. +#else
  1639. + hidden_file->f_op->flush(hidden_file);
  1640. +#endif
  1641. + dput(hidden_dentry);
  1642. + }
  1643. + goto out;
  1644. + }
  1645. +
  1646. + /* ok, now we can safely open the storage file */
  1647. + mntget(stopd(inode->i_sb)->hidden_mnt2);
  1648. + hidden_sto_file = dentry_open(hidden_sto_dentry,
  1649. + stopd(inode->i_sb)->hidden_mnt2,
  1650. + hidden_flags);
  1651. +
  1652. + /* dentry_open dputs the dentry if it fails */
  1653. + if (IS_ERR(hidden_sto_file)) {
  1654. + err = PTR_ERR(hidden_sto_file);
  1655. + /* close base file if open */
  1656. + if(ftohf(file)) {
  1657. + if (hidden_file->f_op && hidden_file->f_op->flush)
  1658. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
  1659. + hidden_file->f_op->flush(hidden_file, NULL);
  1660. +#else
  1661. + hidden_file->f_op->flush(hidden_file);
  1662. +#endif
  1663. + dput(hidden_dentry);
  1664. + }
  1665. + goto out;
  1666. + }
  1667. + ftohf2(file) = hidden_sto_file; /* link storage file */
  1668. +
  1669. + out:
  1670. + if (err < 0 && ftopd(file)) {
  1671. + kfree(ftopd(file));
  1672. + }
  1673. + return err;
  1674. +}
  1675. +
  1676. +STATIC int
  1677. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
  1678. +mini_fo_flush(file_t *file, fl_owner_t id)
  1679. +#else
  1680. +mini_fo_flush(file_t *file)
  1681. +#endif
  1682. +{
  1683. + int err1 = 0; /* assume ok (see open.c:close_fp) */
  1684. + int err2 = 0;
  1685. + file_t *hidden_file = NULL;
  1686. +
  1687. + check_mini_fo_file(file);
  1688. +
  1689. + /* mk: we don't do any state checking here, as its not worth the time.
  1690. + * Just flush the lower level files if they exist.
  1691. + */
  1692. + if(ftopd(file) != NULL) {
  1693. + if(ftohf(file) != NULL) {
  1694. + hidden_file = ftohf(file);
  1695. + if (hidden_file->f_op && hidden_file->f_op->flush)
  1696. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
  1697. + err1 = hidden_file->f_op->flush(hidden_file, id);
  1698. +#else
  1699. + err1 = hidden_file->f_op->flush(hidden_file);
  1700. +#endif
  1701. + }
  1702. + if(ftohf2(file) != NULL) {
  1703. + hidden_file = ftohf2(file);
  1704. + if (hidden_file->f_op && hidden_file->f_op->flush)
  1705. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
  1706. + err2 = hidden_file->f_op->flush(hidden_file, id);
  1707. +#else
  1708. + err2 = hidden_file->f_op->flush(hidden_file);
  1709. +#endif
  1710. + }
  1711. + }
  1712. + return (err1 | err2);
  1713. +}
  1714. +
  1715. +
  1716. +STATIC int
  1717. +mini_fo_release(inode_t *inode, file_t *file)
  1718. +{
  1719. + int err = 0;
  1720. + file_t *hidden_file = NULL;
  1721. +
  1722. + if (ftopd(file) != NULL) {
  1723. + if(ftohf(file)) {
  1724. + hidden_file = ftohf(file);
  1725. + fput(hidden_file);
  1726. + }
  1727. + if(ftohf2(file)) {
  1728. + hidden_file = ftohf2(file);
  1729. + fput(hidden_file);
  1730. + }
  1731. + kfree(ftopd(file));
  1732. + }
  1733. + return err;
  1734. +}
  1735. +
  1736. +STATIC int
  1737. +mini_fo_fsync(file_t *file, dentry_t *dentry, int datasync)
  1738. +{
  1739. + int err1 = 0;
  1740. + int err2 = 0;
  1741. + file_t *hidden_file = NULL;
  1742. + dentry_t *hidden_dentry;
  1743. +
  1744. + check_mini_fo_file(file);
  1745. +
  1746. + if ((hidden_file = ftohf(file)) != NULL) {
  1747. + hidden_dentry = dtohd(dentry);
  1748. + if (hidden_file->f_op && hidden_file->f_op->fsync) {
  1749. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  1750. + mutex_lock(&hidden_dentry->d_inode->i_mutex);
  1751. +#else
  1752. + down(&hidden_dentry->d_inode->i_sem);
  1753. +#endif
  1754. + err1 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
  1755. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  1756. + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
  1757. +#else
  1758. + up(&hidden_dentry->d_inode->i_sem);
  1759. +#endif
  1760. + }
  1761. + }
  1762. +
  1763. + if ((hidden_file = ftohf2(file)) != NULL) {
  1764. + hidden_dentry = dtohd2(dentry);
  1765. + if (hidden_file->f_op && hidden_file->f_op->fsync) {
  1766. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  1767. + mutex_lock(&hidden_dentry->d_inode->i_mutex);
  1768. +#else
  1769. + down(&hidden_dentry->d_inode->i_sem);
  1770. +#endif
  1771. + err2 = hidden_file->f_op->fsync(hidden_file, hidden_dentry, datasync);
  1772. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  1773. + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
  1774. +#else
  1775. + up(&hidden_dentry->d_inode->i_sem);
  1776. +#endif
  1777. + }
  1778. + }
  1779. + else
  1780. + goto err;
  1781. +
  1782. +err:
  1783. + return (err1 || err2);
  1784. +}
  1785. +
  1786. +
  1787. +STATIC int
  1788. +mini_fo_fasync(int fd, file_t *file, int flag)
  1789. +{
  1790. + int err1 = 0;
  1791. + int err2 = 0;
  1792. +
  1793. + file_t *hidden_file = NULL;
  1794. +
  1795. + check_mini_fo_file(file);
  1796. +
  1797. + if((hidden_file = ftohf(file)) != NULL) {
  1798. + err1 = hidden_file->f_op->fasync(fd, hidden_file, flag);
  1799. + }
  1800. + if((hidden_file = ftohf2(file)) != NULL) {
  1801. + err2 = hidden_file->f_op->fasync(fd, hidden_file, flag);
  1802. + }
  1803. +
  1804. + return (err1 || err2);
  1805. +}
  1806. +
  1807. +
  1808. +
  1809. +struct file_operations mini_fo_dir_fops =
  1810. + {
  1811. + read: generic_read_dir,
  1812. + write: mini_fo_write,
  1813. + readdir: mini_fo_readdir,
  1814. + poll: mini_fo_poll,
  1815. + /* ioctl: mini_fo_ioctl, */
  1816. + mmap: mini_fo_mmap,
  1817. + open: mini_fo_open,
  1818. + flush: mini_fo_flush,
  1819. + release: mini_fo_release,
  1820. + fsync: mini_fo_fsync,
  1821. + fasync: mini_fo_fasync,
  1822. + /* not needed lock: mini_fo_lock, */
  1823. + /* not needed: readv */
  1824. + /* not needed: writev */
  1825. + /* not implemented: sendpage */
  1826. + /* not implemented: get_unmapped_area */
  1827. + };
  1828. +
  1829. +struct file_operations mini_fo_main_fops =
  1830. + {
  1831. + llseek: mini_fo_llseek,
  1832. + read: mini_fo_read,
  1833. + write: mini_fo_write,
  1834. + readdir: mini_fo_readdir,
  1835. + poll: mini_fo_poll,
  1836. + /* ioctl: mini_fo_ioctl, */
  1837. + mmap: mini_fo_mmap,
  1838. + open: mini_fo_open,
  1839. + flush: mini_fo_flush,
  1840. + release: mini_fo_release,
  1841. + fsync: mini_fo_fsync,
  1842. + fasync: mini_fo_fasync,
  1843. + /* not needed: lock: mini_fo_lock, */
  1844. + /* not needed: readv */
  1845. + /* not needed: writev */
  1846. + /* not implemented: sendpage */
  1847. + /* not implemented: get_unmapped_area */
  1848. + };
  1849. --- /dev/null
  1850. +++ b/fs/mini_fo/fist.h
  1851. @@ -0,0 +1,252 @@
  1852. +/*
  1853. + * Copyright (c) 1997-2003 Erez Zadok
  1854. + * Copyright (c) 2001-2003 Stony Brook University
  1855. + *
  1856. + * For specific licensing information, see the COPYING file distributed with
  1857. + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
  1858. + *
  1859. + * This Copyright notice must be kept intact and distributed with all
  1860. + * fistgen sources INCLUDING sources generated by fistgen.
  1861. + */
  1862. +/*
  1863. + * Copyright (C) 2004, 2005 Markus Klotzbuecher <[email protected]>
  1864. + *
  1865. + * This program is free software; you can redistribute it and/or
  1866. + * modify it under the terms of the GNU General Public License
  1867. + * as published by the Free Software Foundation; either version
  1868. + * 2 of the License, or (at your option) any later version.
  1869. + */
  1870. +
  1871. +
  1872. +/*
  1873. + * $Id$
  1874. + */
  1875. +
  1876. +#ifndef __FIST_H_
  1877. +#define __FIST_H_
  1878. +
  1879. +/*
  1880. + * KERNEL ONLY CODE:
  1881. + */
  1882. +#ifdef __KERNEL__
  1883. +#include <linux/version.h>
  1884. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
  1885. +#include <linux/autoconf.h>
  1886. +#else
  1887. +#include <linux/config.h>
  1888. +#endif
  1889. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  1890. +#ifdef CONFIG_MODVERSIONS
  1891. +# define MODVERSIONS
  1892. +# include <linux/modversions.h>
  1893. +#endif /* CONFIG_MODVERSIONS */
  1894. +#endif /* KERNEL_VERSION < 2.6.0 */
  1895. +#include <linux/sched.h>
  1896. +#include <linux/kernel.h>
  1897. +#include <linux/mm.h>
  1898. +#include <linux/string.h>
  1899. +#include <linux/stat.h>
  1900. +#include <linux/errno.h>
  1901. +#include <linux/wait.h>
  1902. +#include <linux/limits.h>
  1903. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  1904. +#include <linux/locks.h>
  1905. +#else
  1906. +#include <linux/buffer_head.h>
  1907. +#include <linux/pagemap.h>
  1908. +#include <linux/namei.h>
  1909. +#include <linux/module.h>
  1910. +#include <linux/mount.h>
  1911. +#include <linux/page-flags.h>
  1912. +#include <linux/writeback.h>
  1913. +#include <linux/statfs.h>
  1914. +#endif
  1915. +#include <linux/smp.h>
  1916. +#include <linux/smp_lock.h>
  1917. +#include <linux/file.h>
  1918. +#include <linux/slab.h>
  1919. +#include <linux/vmalloc.h>
  1920. +#include <linux/poll.h>
  1921. +#include <linux/list.h>
  1922. +#include <linux/init.h>
  1923. +
  1924. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
  1925. +#include <linux/xattr.h>
  1926. +#endif
  1927. +
  1928. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  1929. +#include <linux/security.h>
  1930. +#endif
  1931. +
  1932. +#include <linux/swap.h>
  1933. +
  1934. +#include <asm/system.h>
  1935. +/* #include <asm/segment.h> */
  1936. +#include <asm/mman.h>
  1937. +#include <linux/seq_file.h>
  1938. +
  1939. +/*
  1940. + * MACROS:
  1941. + */
  1942. +
  1943. +/* those mapped to ATTR_* were copied from linux/fs.h */
  1944. +#define FA_MODE ATTR_MODE
  1945. +#define FA_UID ATTR_UID
  1946. +#define FA_GID ATTR_GID
  1947. +#define FA_SIZE ATTR_SIZE
  1948. +#define FA_ATIME ATTR_ATIME
  1949. +#define FA_MTIME ATTR_MTIME
  1950. +#define FA_CTIME ATTR_CTIME
  1951. +#define FA_ATIME_SET ATTR_ATIME_SET
  1952. +#define FA_MTIME_SET ATTR_MTIME_SET
  1953. +#define FA_FORCE ATTR_FORCE
  1954. +#define FA_ATTR_FLAGS ATTR_ATTR_FLAG
  1955. +
  1956. +/* must be greater than all other ATTR_* flags! */
  1957. +#define FA_NLINK 2048
  1958. +#define FA_BLKSIZE 4096
  1959. +#define FA_BLOCKS 8192
  1960. +#define FA_TIMES (FA_ATIME|FA_MTIME|FA_CTIME)
  1961. +#define FA_ALL 0
  1962. +
  1963. +/* macros to manage changes between kernels */
  1964. +#define INODE_DATA(i) (&(i)->i_data)
  1965. +
  1966. +#define MIN(x,y) ((x < y) ? (x) : (y))
  1967. +#define MAX(x,y) ((x > y) ? (x) : (y))
  1968. +#define MAXPATHLEN PATH_MAX
  1969. +
  1970. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
  1971. +# define lookup_one_len(a,b,c) lookup_one(a,b)
  1972. +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */
  1973. +
  1974. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8)
  1975. +# define generic_file_llseek default_llseek
  1976. +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) */
  1977. +
  1978. +#ifndef SEEK_SET
  1979. +# define SEEK_SET 0
  1980. +#endif /* not SEEK_SET */
  1981. +
  1982. +#ifndef SEEK_CUR
  1983. +# define SEEK_CUR 1
  1984. +#endif /* not SEEK_CUR */
  1985. +
  1986. +#ifndef SEEK_END
  1987. +# define SEEK_END 2
  1988. +#endif /* not SEEK_END */
  1989. +
  1990. +#ifndef DEFAULT_POLLMASK
  1991. +# define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
  1992. +#endif /* not DEFAULT_POLLMASK */
  1993. +
  1994. +/* XXX: fix this so fistgen generates kfree() code directly */
  1995. +#define kfree_s(a,b) kfree(a)
  1996. +
  1997. +/*
  1998. + * TYPEDEFS:
  1999. + */
  2000. +typedef struct dentry dentry_t;
  2001. +typedef struct file file_t;
  2002. +typedef struct inode inode_t;
  2003. +typedef inode_t vnode_t;
  2004. +typedef struct page page_t;
  2005. +typedef struct qstr qstr_t;
  2006. +typedef struct super_block super_block_t;
  2007. +typedef super_block_t vfs_t;
  2008. +typedef struct vm_area_struct vm_area_t;
  2009. +
  2010. +
  2011. +/*
  2012. + * EXTERNALS:
  2013. + */
  2014. +
  2015. +#define FPPF(str,page) printk("PPF %s 0x%x/%d: Lck:%d Err:%d Ref:%d Upd:%d Other::%d:%d:%d:%d:\n", \
  2016. + str, \
  2017. + (int) page, \
  2018. + (int) page->index, \
  2019. + (PageLocked(page) ? 1 : 0), \
  2020. + (PageError(page) ? 1 : 0), \
  2021. + (PageReferenced(page) ? 1 : 0), \
  2022. + (Page_Uptodate(page) ? 1 : 0), \
  2023. + (PageDecrAfter(page) ? 1 : 0), \
  2024. + (PageSlab(page) ? 1 : 0), \
  2025. + (PageSwapCache(page) ? 1 : 0), \
  2026. + (PageReserved(page) ? 1 : 0) \
  2027. + )
  2028. +#define EZKDBG printk("EZK %s:%d:%s\n",__FILE__,__LINE__,__FUNCTION__)
  2029. +#if 0
  2030. +# define EZKDBG1 printk("EZK %s:%d\n",__FILE__,__LINE__)
  2031. +#else
  2032. +# define EZKDBG1
  2033. +#endif
  2034. +
  2035. +extern int fist_get_debug_value(void);
  2036. +extern int fist_set_debug_value(int val);
  2037. +#if 0 /* mini_fo doesn't need these */
  2038. +extern void fist_dprint_internal(int level, char *str,...);
  2039. +extern void fist_print_dentry(char *str, const dentry_t *dentry);
  2040. +extern void fist_print_inode(char *str, const inode_t *inode);
  2041. +extern void fist_print_file(char *str, const file_t *file);
  2042. +extern void fist_print_buffer_flags(char *str, struct buffer_head *buffer);
  2043. +extern void fist_print_page_flags(char *str, page_t *page);
  2044. +extern void fist_print_page_bytes(char *str, page_t *page);
  2045. +extern void fist_print_pte_flags(char *str, const page_t *page);
  2046. +extern void fist_checkinode(inode_t *inode, char *msg);
  2047. +extern void fist_print_sb(char *str, const super_block_t *sb);
  2048. +
  2049. +/* §$% by mk: special debug functions */
  2050. +extern void fist_mk_print_dentry(char *str, const dentry_t *dentry);
  2051. +extern void fist_mk_print_inode(char *str, const inode_t *inode);
  2052. +
  2053. +extern char *add_indent(void);
  2054. +extern char *del_indent(void);
  2055. +#endif/* mini_fo doesn't need these */
  2056. +
  2057. +
  2058. +#define STATIC
  2059. +#define ASSERT(EX) \
  2060. +do { \
  2061. + if (!(EX)) { \
  2062. + printk(KERN_CRIT "ASSERTION FAILED: %s at %s:%d (%s)\n", #EX, \
  2063. + __FILE__, __LINE__, __FUNCTION__); \
  2064. + (*((char *)0))=0; \
  2065. + } \
  2066. +} while (0)
  2067. +/* same ASSERT, but tell me who was the caller of the function */
  2068. +#define ASSERT2(EX) \
  2069. +do { \
  2070. + if (!(EX)) { \
  2071. + printk(KERN_CRIT "ASSERTION FAILED (caller): %s at %s:%d (%s)\n", #EX, \
  2072. + file, line, func); \
  2073. + (*((char *)0))=0; \
  2074. + } \
  2075. +} while (0)
  2076. +
  2077. +#if 0 /* mini_fo doesn't need these */
  2078. +#define dprintk(format, args...) printk(KERN_DEBUG format, ##args)
  2079. +#define fist_dprint(level, str, args...) fist_dprint_internal(level, KERN_DEBUG str, ## args)
  2080. +#define print_entry_location() fist_dprint(4, "%sIN: %s %s:%d\n", add_indent(), __FUNCTION__, __FILE__, __LINE__)
  2081. +#define print_exit_location() fist_dprint(4, "%s OUT: %s %s:%d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__)
  2082. +#define print_exit_status(status) fist_dprint(4, "%s OUT: %s %s:%d, STATUS: %d\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, status)
  2083. +#define print_exit_pointer(status) \
  2084. +do { \
  2085. + if (IS_ERR(status)) \
  2086. + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: %ld\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
  2087. + else \
  2088. + fist_dprint(4, "%s OUT: %s %s:%d, RESULT: 0x%x\n", del_indent(), __FUNCTION__, __FILE__, __LINE__, PTR_ERR(status)); \
  2089. +} while (0)
  2090. +#endif/* mini_fo doesn't need these */
  2091. +
  2092. +#endif /* __KERNEL__ */
  2093. +
  2094. +
  2095. +/*
  2096. + * DEFINITIONS FOR USER AND KERNEL CODE:
  2097. + * (Note: ioctl numbers 1--9 are reserved for fistgen, the rest
  2098. + * are auto-generated automatically based on the user's .fist file.)
  2099. + */
  2100. +# define FIST_IOCTL_GET_DEBUG_VALUE _IOR(0x15, 1, int)
  2101. +# define FIST_IOCTL_SET_DEBUG_VALUE _IOW(0x15, 2, int)
  2102. +
  2103. +#endif /* not __FIST_H_ */
  2104. --- /dev/null
  2105. +++ b/fs/mini_fo/inode.c
  2106. @@ -0,0 +1,1564 @@
  2107. +/*
  2108. + * Copyright (c) 1997-2003 Erez Zadok
  2109. + * Copyright (c) 2001-2003 Stony Brook University
  2110. + *
  2111. + * For specific licensing information, see the COPYING file distributed with
  2112. + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
  2113. + *
  2114. + * This Copyright notice must be kept intact and distributed with all
  2115. + * fistgen sources INCLUDING sources generated by fistgen.
  2116. + */
  2117. +/*
  2118. + * Copyright (C) 2004, 2005 Markus Klotzbuecher <[email protected]>
  2119. + *
  2120. + * This program is free software; you can redistribute it and/or
  2121. + * modify it under the terms of the GNU General Public License
  2122. + * as published by the Free Software Foundation; either version
  2123. + * 2 of the License, or (at your option) any later version.
  2124. + */
  2125. +
  2126. +/*
  2127. + * $Id$
  2128. + */
  2129. +
  2130. +#ifdef HAVE_CONFIG_H
  2131. +# include <config.h>
  2132. +#endif
  2133. +
  2134. +#include "fist.h"
  2135. +#include "mini_fo.h"
  2136. +
  2137. +STATIC int
  2138. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  2139. +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd)
  2140. +#else
  2141. +mini_fo_create(inode_t *dir, dentry_t *dentry, int mode)
  2142. +#endif
  2143. +{
  2144. + int err = 0;
  2145. +
  2146. + check_mini_fo_dentry(dentry);
  2147. +
  2148. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  2149. + err = create_sto_reg_file(dentry, mode, nd);
  2150. +#else
  2151. + err = create_sto_reg_file(dentry, mode);
  2152. +#endif
  2153. + check_mini_fo_dentry(dentry);
  2154. + return err;
  2155. +}
  2156. +
  2157. +
  2158. +STATIC dentry_t *
  2159. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  2160. +mini_fo_lookup(inode_t *dir, dentry_t *dentry, struct nameidata* nd)
  2161. +#else
  2162. +mini_fo_lookup(inode_t *dir, dentry_t *dentry)
  2163. +#endif
  2164. +{
  2165. + int err = 0;
  2166. + dentry_t *hidden_dir_dentry;
  2167. + dentry_t *hidden_dentry = NULL;
  2168. +
  2169. + dentry_t *hidden_sto_dir_dentry;
  2170. + dentry_t *hidden_sto_dentry = NULL;
  2171. +
  2172. + /* whiteout flag */
  2173. + int del_flag = 0;
  2174. + char *bpath = NULL;
  2175. +
  2176. + const char *name;
  2177. + unsigned int namelen;
  2178. +
  2179. + /* Don't allow lookups of META-files */
  2180. + namelen = strlen(META_FILENAME);
  2181. + if(namelen == dentry->d_name.len) {
  2182. + if(!strncmp(dentry->d_name.name, META_FILENAME, namelen)) {
  2183. + err = -ENOENT;
  2184. + goto out;
  2185. + }
  2186. + }
  2187. +
  2188. + hidden_dir_dentry = dtohd(dentry->d_parent);
  2189. + hidden_sto_dir_dentry = dtohd2(dentry->d_parent);
  2190. +
  2191. + name = dentry->d_name.name;
  2192. + namelen = dentry->d_name.len;
  2193. +
  2194. + /* must initialize dentry operations */
  2195. + dentry->d_op = &mini_fo_dops;
  2196. +
  2197. + /* setup the del_flag */
  2198. + del_flag = __meta_check_d_entry(dir, name, namelen);
  2199. + bpath = __meta_check_r_entry(dir, name, namelen);
  2200. +
  2201. + /* perform the lookups of base and storage files:
  2202. + *
  2203. + * This caused some serious trouble, as a lookup_one_len passing
  2204. + * a negative dentry oopses. Solution is to only do the lookup
  2205. + * if the dentry is positive, else we set it to NULL
  2206. + * More trouble, who said a *_dir_dentry can't be NULL?
  2207. + */
  2208. + if(bpath) {
  2209. + /* Cross-Interposing (C), yeah! */
  2210. + hidden_dentry = bpath_walk(dir->i_sb, bpath);
  2211. + if(!hidden_dentry || !hidden_dentry->d_inode) {
  2212. + printk(KERN_CRIT "mini_fo_lookup: bpath_walk failed.\n");
  2213. + err= -EINVAL;
  2214. + goto out;
  2215. + }
  2216. +
  2217. + /* this can be set up safely without fear of spaghetti
  2218. + * interposing as it is only used for copying times */
  2219. + hidden_dir_dentry = hidden_dentry->d_parent;
  2220. + kfree(bpath);
  2221. + }
  2222. + else if(hidden_dir_dentry && hidden_dir_dentry->d_inode)
  2223. + hidden_dentry =
  2224. + lookup_one_len(name, hidden_dir_dentry, namelen);
  2225. + else
  2226. + hidden_dentry = NULL;
  2227. +
  2228. + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
  2229. + hidden_sto_dentry =
  2230. + lookup_one_len(name, hidden_sto_dir_dentry, namelen);
  2231. + else
  2232. + hidden_sto_dentry = NULL;
  2233. +
  2234. + /* catch error in lookup */
  2235. + if (IS_ERR(hidden_dentry) || IS_ERR(hidden_sto_dentry)) {
  2236. + /* mk: we need to call dput on the dentry, whose
  2237. + * lookup_one_len operation failed, in order to avoid
  2238. + * unmount trouble.
  2239. + */
  2240. + if(IS_ERR(hidden_dentry)) {
  2241. + printk(KERN_CRIT "mini_fo_lookup: ERR from base dentry, lookup failed.\n");
  2242. + err = PTR_ERR(hidden_dentry);
  2243. + } else {
  2244. + dput(hidden_dentry);
  2245. + }
  2246. + if(IS_ERR(hidden_sto_dentry)) {
  2247. + printk(KERN_CRIT "mini_fo_lookup: ERR from storage dentry, lookup failed.\n");
  2248. + err = PTR_ERR(hidden_sto_dentry);
  2249. + } else {
  2250. + dput(hidden_sto_dentry);
  2251. + }
  2252. + goto out;
  2253. + }
  2254. +
  2255. + /* allocate dentry private data */
  2256. + __dtopd(dentry) = (struct mini_fo_dentry_info *)
  2257. + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
  2258. +
  2259. + if (!dtopd(dentry)) {
  2260. + err = -ENOMEM;
  2261. + goto out_dput;
  2262. + }
  2263. +
  2264. + /* check for different states of the mini_fo file to be looked up. */
  2265. +
  2266. + /* state 1, file has been modified */
  2267. + if(hidden_dentry && hidden_sto_dentry &&
  2268. + hidden_dentry->d_inode && hidden_sto_dentry->d_inode && !del_flag) {
  2269. +
  2270. + /* update parent directory's atime */
  2271. + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
  2272. +
  2273. + dtopd(dentry)->state = MODIFIED;
  2274. + dtohd(dentry) = hidden_dentry;
  2275. + dtohd2(dentry) = hidden_sto_dentry;
  2276. +
  2277. + err = mini_fo_tri_interpose(hidden_dentry,
  2278. + hidden_sto_dentry,
  2279. + dentry, dir->i_sb, 1);
  2280. + if (err) {
  2281. + printk(KERN_CRIT "mini_fo_lookup: error interposing (state1).\n");
  2282. + goto out_free;
  2283. + }
  2284. + goto out;
  2285. + }
  2286. + /* state 2, file is unmodified */
  2287. + if(hidden_dentry && hidden_dentry->d_inode && !del_flag) {
  2288. +
  2289. + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
  2290. +
  2291. + dtopd(dentry)->state = UNMODIFIED;
  2292. + dtohd(dentry) = hidden_dentry;
  2293. + dtohd2(dentry) = hidden_sto_dentry; /* could be negative */
  2294. +
  2295. + err = mini_fo_tri_interpose(hidden_dentry,
  2296. + hidden_sto_dentry,
  2297. + dentry, dir->i_sb, 1);
  2298. + if (err) {
  2299. + printk(KERN_CRIT "mini_fo_lookup: error interposing (state2).\n");
  2300. + goto out_free;
  2301. + }
  2302. + goto out;
  2303. + }
  2304. + /* state 3, file has been newly created */
  2305. + if(hidden_sto_dentry && hidden_sto_dentry->d_inode && !del_flag) {
  2306. +
  2307. + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
  2308. + dtopd(dentry)->state = CREATED;
  2309. + dtohd(dentry) = hidden_dentry; /* could be negative */
  2310. + dtohd2(dentry) = hidden_sto_dentry;
  2311. +
  2312. + err = mini_fo_tri_interpose(hidden_dentry,
  2313. + hidden_sto_dentry,
  2314. + dentry, dir->i_sb, 1);
  2315. + if (err) {
  2316. + printk(KERN_CRIT "mini_fo_lookup: error interposing (state3).\n");
  2317. + goto out_free;
  2318. + }
  2319. + goto out;
  2320. + }
  2321. +
  2322. + /* state 4, file has deleted and created again. */
  2323. + if(hidden_dentry && hidden_sto_dentry &&
  2324. + hidden_dentry->d_inode &&
  2325. + hidden_sto_dentry->d_inode && del_flag) {
  2326. +
  2327. + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
  2328. + dtopd(dentry)->state = DEL_REWRITTEN;
  2329. + dtohd(dentry) = NULL;
  2330. + dtohd2(dentry) = hidden_sto_dentry;
  2331. +
  2332. + err = mini_fo_tri_interpose(NULL,
  2333. + hidden_sto_dentry,
  2334. + dentry, dir->i_sb, 1);
  2335. + if (err) {
  2336. + printk(KERN_CRIT "mini_fo_lookup: error interposing (state4).\n");
  2337. + goto out_free;
  2338. + }
  2339. + /* We will never need this dentry again, as the file has been
  2340. + * deleted from base */
  2341. + dput(hidden_dentry);
  2342. + goto out;
  2343. + }
  2344. + /* state 5, file has been deleted in base */
  2345. + if(hidden_dentry && hidden_sto_dentry &&
  2346. + hidden_dentry->d_inode &&
  2347. + !hidden_sto_dentry->d_inode && del_flag) {
  2348. +
  2349. + /* check which parents atime we need for updating */
  2350. + if(hidden_sto_dir_dentry->d_inode)
  2351. + fist_copy_attr_atime(dir,
  2352. + hidden_sto_dir_dentry->d_inode);
  2353. + else
  2354. + fist_copy_attr_atime(dir,
  2355. + hidden_dir_dentry->d_inode);
  2356. +
  2357. + dtopd(dentry)->state = DELETED;
  2358. + dtohd(dentry) = NULL;
  2359. + dtohd2(dentry) = hidden_sto_dentry;
  2360. +
  2361. + /* add negative dentry to dcache to speed up lookups */
  2362. + d_add(dentry, NULL);
  2363. + dput(hidden_dentry);
  2364. + goto out;
  2365. + }
  2366. + /* state 6, file does not exist */
  2367. + if(((hidden_dentry && !hidden_dentry->d_inode) ||
  2368. + (hidden_sto_dentry && !hidden_sto_dentry->d_inode)) && !del_flag)
  2369. + {
  2370. + /* check which parents atime we need for updating */
  2371. + if(hidden_sto_dir_dentry && hidden_sto_dir_dentry->d_inode)
  2372. + fist_copy_attr_atime(dir, hidden_sto_dir_dentry->d_inode);
  2373. + else
  2374. + fist_copy_attr_atime(dir, hidden_dir_dentry->d_inode);
  2375. +
  2376. + dtopd(dentry)->state = NON_EXISTANT;
  2377. + dtohd(dentry) = hidden_dentry;
  2378. + dtohd2(dentry) = hidden_sto_dentry;
  2379. + d_add(dentry, NULL);
  2380. + goto out;
  2381. + }
  2382. +
  2383. + /* if we get to here, were in an invalid state. bad. */
  2384. + printk(KERN_CRIT "mini_fo_lookup: ERROR, meta data corruption detected.\n");
  2385. +
  2386. + /* end state checking */
  2387. + out_free:
  2388. + d_drop(dentry); /* so that our bad dentry will get destroyed */
  2389. + kfree(dtopd(dentry));
  2390. + __dtopd(dentry) = NULL; /* be safe */
  2391. +
  2392. + out_dput:
  2393. + if(hidden_dentry)
  2394. + dput(hidden_dentry);
  2395. + if(hidden_sto_dentry)
  2396. + dput(hidden_sto_dentry); /* drops usage count and marks for release */
  2397. +
  2398. + out:
  2399. + /* initalize wol if file exists and is directory */
  2400. + if(dentry->d_inode) {
  2401. + if(S_ISDIR(dentry->d_inode->i_mode)) {
  2402. + itopd(dentry->d_inode)->deleted_list_size = -1;
  2403. + itopd(dentry->d_inode)->renamed_list_size = -1;
  2404. + meta_build_lists(dentry);
  2405. + }
  2406. + }
  2407. + return ERR_PTR(err);
  2408. +}
  2409. +
  2410. +
  2411. +STATIC int
  2412. +mini_fo_link(dentry_t *old_dentry, inode_t *dir, dentry_t *new_dentry)
  2413. +{
  2414. + int err;
  2415. + dentry_t *hidden_old_dentry;
  2416. + dentry_t *hidden_new_dentry;
  2417. + dentry_t *hidden_dir_dentry;
  2418. +
  2419. +
  2420. + check_mini_fo_dentry(old_dentry);
  2421. + check_mini_fo_dentry(new_dentry);
  2422. + check_mini_fo_inode(dir);
  2423. +
  2424. + /* no links to directorys and existing targets target allowed */
  2425. + if(S_ISDIR(old_dentry->d_inode->i_mode) ||
  2426. + is_mini_fo_existant(new_dentry)) {
  2427. + err = -EPERM;
  2428. + goto out;
  2429. + }
  2430. +
  2431. + /* bring it directly from unmod to del_rew */
  2432. + if(dtost(old_dentry) == UNMODIFIED) {
  2433. + err = nondir_unmod_to_mod(old_dentry, 1);
  2434. + if(err) {
  2435. + err = -EINVAL;
  2436. + goto out;
  2437. + }
  2438. + err = meta_add_d_entry(old_dentry->d_parent,
  2439. + old_dentry->d_name.name,
  2440. + old_dentry->d_name.len);
  2441. + if(err) {
  2442. + err = -EINVAL;
  2443. + goto out;
  2444. + }
  2445. + dput(dtohd(old_dentry));
  2446. + dtohd(old_dentry) = NULL;
  2447. + dtost(old_dentry) = DEL_REWRITTEN;
  2448. + }
  2449. +
  2450. + err = get_neg_sto_dentry(new_dentry);
  2451. + if(err) {
  2452. + err = -EINVAL;
  2453. + goto out;
  2454. + }
  2455. +
  2456. + hidden_old_dentry = dtohd2(old_dentry);
  2457. + hidden_new_dentry = dtohd2(new_dentry);
  2458. +
  2459. + dget(hidden_old_dentry);
  2460. + dget(hidden_new_dentry);
  2461. +
  2462. + /* was: hidden_dir_dentry = lock_parent(hidden_new_dentry); */
  2463. + hidden_dir_dentry = dget(hidden_new_dentry->d_parent);
  2464. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  2465. + mutex_lock(&hidden_dir_dentry->d_inode->i_mutex);
  2466. +#else
  2467. + down(&hidden_dir_dentry->d_inode->i_sem);
  2468. +#endif
  2469. +
  2470. + err = vfs_link(hidden_old_dentry,
  2471. + hidden_dir_dentry->d_inode,
  2472. + hidden_new_dentry);
  2473. + if (err || !hidden_new_dentry->d_inode)
  2474. + goto out_lock;
  2475. +
  2476. + dtost(new_dentry) = CREATED;
  2477. + err = mini_fo_tri_interpose(NULL, hidden_new_dentry, new_dentry, dir->i_sb, 0);
  2478. + if (err)
  2479. + goto out_lock;
  2480. +
  2481. + fist_copy_attr_timesizes(dir, hidden_new_dentry->d_inode);
  2482. + /* propagate number of hard-links */
  2483. + old_dentry->d_inode->i_nlink = itohi2(old_dentry->d_inode)->i_nlink;
  2484. +
  2485. + out_lock:
  2486. + /* was: unlock_dir(hidden_dir_dentry); */
  2487. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  2488. + mutex_unlock(&hidden_dir_dentry->d_inode->i_mutex);
  2489. +#else
  2490. + up(&hidden_dir_dentry->d_inode->i_sem);
  2491. +#endif
  2492. + dput(hidden_dir_dentry);
  2493. +
  2494. + dput(hidden_new_dentry);
  2495. + dput(hidden_old_dentry);
  2496. + if (!new_dentry->d_inode)
  2497. + d_drop(new_dentry);
  2498. +
  2499. + out:
  2500. + return err;
  2501. +}
  2502. +
  2503. +
  2504. +STATIC int
  2505. +mini_fo_unlink(inode_t *dir, dentry_t *dentry)
  2506. +{
  2507. + int err = 0;
  2508. +
  2509. + dget(dentry);
  2510. + if(dtopd(dentry)->state == MODIFIED) {
  2511. + err = nondir_mod_to_del(dentry);
  2512. + goto out;
  2513. + }
  2514. + else if(dtopd(dentry)->state == UNMODIFIED) {
  2515. + err = nondir_unmod_to_del(dentry);
  2516. + goto out;
  2517. + }
  2518. + else if(dtopd(dentry)->state == CREATED) {
  2519. + err = nondir_creat_to_del(dentry);
  2520. + goto out;
  2521. + }
  2522. + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
  2523. + err = nondir_del_rew_to_del(dentry);
  2524. + goto out;
  2525. + }
  2526. +
  2527. + printk(KERN_CRIT "mini_fo_unlink: ERROR, invalid state detected.\n");
  2528. +
  2529. + out:
  2530. + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
  2531. +
  2532. + if(!err) {
  2533. + /* is this causing my pain? d_delete(dentry); */
  2534. + d_drop(dentry);
  2535. + }
  2536. +
  2537. + dput(dentry);
  2538. + return err;
  2539. +}
  2540. +
  2541. +
  2542. +STATIC int
  2543. +mini_fo_symlink(inode_t *dir, dentry_t *dentry, const char *symname)
  2544. +{
  2545. + int err=0;
  2546. + dentry_t *hidden_sto_dentry;
  2547. + dentry_t *hidden_sto_dir_dentry;
  2548. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  2549. + umode_t mode;
  2550. +#endif
  2551. +
  2552. + /* Fail if the symlink file exists */
  2553. + if(!(dtost(dentry) == DELETED ||
  2554. + dtost(dentry) == NON_EXISTANT)) {
  2555. + err = -EEXIST;
  2556. + goto out;
  2557. + }
  2558. +
  2559. + err = get_neg_sto_dentry(dentry);
  2560. + if(err) {
  2561. + err = -EINVAL;
  2562. + goto out;
  2563. + }
  2564. + hidden_sto_dentry = dtohd2(dentry);
  2565. +
  2566. + dget(hidden_sto_dentry);
  2567. + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
  2568. + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
  2569. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  2570. + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  2571. +#else
  2572. + down(&hidden_sto_dir_dentry->d_inode->i_sem);
  2573. +#endif
  2574. +
  2575. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  2576. + mode = S_IALLUGO;
  2577. + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
  2578. + hidden_sto_dentry, symname, mode);
  2579. +#else
  2580. + err = vfs_symlink(hidden_sto_dir_dentry->d_inode,
  2581. + hidden_sto_dentry,
  2582. + symname);
  2583. +#endif
  2584. + if (err || !hidden_sto_dentry->d_inode)
  2585. + goto out_lock;
  2586. +
  2587. + if(dtost(dentry) == DELETED) {
  2588. + dtost(dentry) = DEL_REWRITTEN;
  2589. + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
  2590. + if(err)
  2591. + goto out_lock;
  2592. + } else if(dtost(dentry) == NON_EXISTANT) {
  2593. + dtost(dentry) = CREATED;
  2594. + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
  2595. + if(err)
  2596. + goto out_lock;
  2597. + }
  2598. + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
  2599. +
  2600. + out_lock:
  2601. + /* was: unlock_dir(hidden_sto_dir_dentry); */
  2602. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  2603. + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  2604. +#else
  2605. + up(&hidden_sto_dir_dentry->d_inode->i_sem);
  2606. +#endif
  2607. + dput(hidden_sto_dir_dentry);
  2608. +
  2609. + dput(hidden_sto_dentry);
  2610. + if (!dentry->d_inode)
  2611. + d_drop(dentry);
  2612. + out:
  2613. + return err;
  2614. +}
  2615. +
  2616. +STATIC int
  2617. +mini_fo_mkdir(inode_t *dir, dentry_t *dentry, int mode)
  2618. +{
  2619. + int err;
  2620. +
  2621. + err = create_sto_dir(dentry, mode);
  2622. +
  2623. + check_mini_fo_dentry(dentry);
  2624. +
  2625. + return err;
  2626. +}
  2627. +
  2628. +
  2629. +STATIC int
  2630. +mini_fo_rmdir(inode_t *dir, dentry_t *dentry)
  2631. +{
  2632. + int err = 0;
  2633. +
  2634. + dentry_t *hidden_sto_dentry;
  2635. + dentry_t *hidden_sto_dir_dentry;
  2636. + dentry_t *meta_dentry;
  2637. + inode_t *hidden_sto_dir = NULL;
  2638. +
  2639. + check_mini_fo_dentry(dentry);
  2640. + check_mini_fo_inode(dir);
  2641. +
  2642. + dget(dentry);
  2643. + if(dtopd(dentry)->state == MODIFIED) {
  2644. + /* XXX: disabled, because it does not bother to check files on
  2645. + * the original filesystem - just a hack, but better than simply
  2646. + * removing it without testing */
  2647. + err = -EINVAL;
  2648. + goto out;
  2649. +
  2650. + hidden_sto_dir = itohi2(dir);
  2651. + hidden_sto_dentry = dtohd2(dentry);
  2652. +
  2653. + /* was:hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
  2654. + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
  2655. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  2656. + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  2657. +#else
  2658. + down(&hidden_sto_dir_dentry->d_inode->i_sem);
  2659. +#endif
  2660. +
  2661. + /* Delete an old WOL file contained in the storage dir */
  2662. + meta_dentry = lookup_one_len(META_FILENAME,
  2663. + hidden_sto_dentry,
  2664. + strlen(META_FILENAME));
  2665. + if(meta_dentry->d_inode) {
  2666. + err = vfs_unlink(hidden_sto_dentry->d_inode, meta_dentry);
  2667. + dput(meta_dentry);
  2668. + if(!err)
  2669. + d_delete(meta_dentry);
  2670. + }
  2671. +
  2672. + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
  2673. + dput(hidden_sto_dentry);
  2674. + if(!err)
  2675. + d_delete(hidden_sto_dentry);
  2676. +
  2677. + /* propagate number of hard-links */
  2678. + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
  2679. +
  2680. + dput(dtohd(dentry));
  2681. +
  2682. + dtohd(dentry) = NULL;
  2683. + dtopd(dentry)->state = DELETED;
  2684. +
  2685. + /* carefull with R files */
  2686. + if( __meta_is_r_entry(dir,
  2687. + dentry->d_name.name,
  2688. + dentry->d_name.len) == 1) {
  2689. + err = meta_remove_r_entry(dentry->d_parent,
  2690. + dentry->d_name.name,
  2691. + dentry->d_name.len);
  2692. + if(err) {
  2693. + printk(KERN_CRIT "mini_fo: rmdir: meta_remove_r_entry failed.\n");
  2694. + goto out;
  2695. + }
  2696. + }
  2697. + else {
  2698. + /* ok, add deleted file to META */
  2699. + meta_add_d_entry(dentry->d_parent,
  2700. + dentry->d_name.name,
  2701. + dentry->d_name.len);
  2702. + }
  2703. + /* was: unlock_dir(hidden_sto_dir_dentry); */
  2704. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  2705. + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  2706. +#else
  2707. + up(&hidden_sto_dir_dentry->d_inode->i_sem);
  2708. +#endif
  2709. + dput(hidden_sto_dir_dentry);
  2710. + goto out;
  2711. + }
  2712. + else if(dtopd(dentry)->state == UNMODIFIED) {
  2713. + /* XXX: simply adding it to the delete list here is fscking dangerous!
  2714. + * as a temporary hack, i will disable rmdir on unmodified directories
  2715. + * for now.
  2716. + */
  2717. + err = -EINVAL;
  2718. + goto out;
  2719. +
  2720. + err = get_neg_sto_dentry(dentry);
  2721. + if(err) {
  2722. + err = -EINVAL;
  2723. + goto out;
  2724. + }
  2725. +
  2726. + /* dput base dentry, this will relase the inode and free the
  2727. + * dentry, as we will never need it again. */
  2728. + dput(dtohd(dentry));
  2729. + dtohd(dentry) = NULL;
  2730. + dtopd(dentry)->state = DELETED;
  2731. +
  2732. + /* add deleted file to META-file */
  2733. + meta_add_d_entry(dentry->d_parent,
  2734. + dentry->d_name.name,
  2735. + dentry->d_name.len);
  2736. + goto out;
  2737. + }
  2738. + else if(dtopd(dentry)->state == CREATED) {
  2739. + hidden_sto_dir = itohi2(dir);
  2740. + hidden_sto_dentry = dtohd2(dentry);
  2741. +
  2742. + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
  2743. + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
  2744. +
  2745. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  2746. + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  2747. +#else
  2748. + down(&hidden_sto_dir_dentry->d_inode->i_sem);
  2749. +#endif
  2750. +
  2751. + /* Delete an old WOL file contained in the storage dir */
  2752. + meta_dentry = lookup_one_len(META_FILENAME,
  2753. + hidden_sto_dentry,
  2754. + strlen(META_FILENAME));
  2755. + if(meta_dentry->d_inode) {
  2756. + /* is this necessary? dget(meta_dentry); */
  2757. + err = vfs_unlink(hidden_sto_dentry->d_inode,
  2758. + meta_dentry);
  2759. + dput(meta_dentry);
  2760. + if(!err)
  2761. + d_delete(meta_dentry);
  2762. + }
  2763. +
  2764. + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
  2765. + dput(hidden_sto_dentry);
  2766. + if(!err)
  2767. + d_delete(hidden_sto_dentry);
  2768. +
  2769. + /* propagate number of hard-links */
  2770. + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
  2771. + dtopd(dentry)->state = NON_EXISTANT;
  2772. +
  2773. + /* was: unlock_dir(hidden_sto_dir_dentry); */
  2774. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  2775. + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  2776. +#else
  2777. + up(&hidden_sto_dir_dentry->d_inode->i_sem);
  2778. +#endif
  2779. + dput(hidden_sto_dir_dentry);
  2780. +
  2781. + goto out;
  2782. + }
  2783. + else if(dtopd(dentry)->state == DEL_REWRITTEN) {
  2784. + hidden_sto_dir = itohi2(dir);
  2785. + hidden_sto_dentry = dtohd2(dentry);
  2786. +
  2787. + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
  2788. + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
  2789. +
  2790. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  2791. + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  2792. +#else
  2793. + down(&hidden_sto_dir_dentry->d_inode->i_sem);
  2794. +#endif
  2795. +
  2796. + /* Delete an old WOL file contained in the storage dir */
  2797. + meta_dentry = lookup_one_len(META_FILENAME,
  2798. + hidden_sto_dentry,
  2799. + strlen(META_FILENAME));
  2800. + if(meta_dentry->d_inode) {
  2801. + /* is this necessary? dget(meta_dentry); */
  2802. + err = vfs_unlink(hidden_sto_dentry->d_inode,
  2803. + meta_dentry);
  2804. + dput(meta_dentry);
  2805. + if(!err)
  2806. + d_delete(meta_dentry);
  2807. + }
  2808. +
  2809. + err = vfs_rmdir(hidden_sto_dir, hidden_sto_dentry);
  2810. + dput(hidden_sto_dentry);
  2811. + if(!err)
  2812. + d_delete(hidden_sto_dentry);
  2813. +
  2814. + /* propagate number of hard-links */
  2815. + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
  2816. + dtopd(dentry)->state = DELETED;
  2817. + /* was: unlock_dir(hidden_sto_dir_dentry); */
  2818. +
  2819. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  2820. + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  2821. +#else
  2822. + up(&hidden_sto_dir_dentry->d_inode->i_sem);
  2823. +#endif
  2824. + dput(hidden_sto_dir_dentry);
  2825. + goto out;
  2826. + }
  2827. +
  2828. + printk(KERN_CRIT "mini_fo_rmdir: ERROR, invalid state detected.\n");
  2829. +
  2830. + out:
  2831. + if(!err) {
  2832. + d_drop(dentry);
  2833. + }
  2834. +
  2835. + fist_copy_attr_times(dir, itohi2(dentry->d_parent->d_inode));
  2836. + dput(dentry);
  2837. +
  2838. + return err;
  2839. +}
  2840. +
  2841. +
  2842. +STATIC int
  2843. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  2844. +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, dev_t dev)
  2845. +#else
  2846. +mini_fo_mknod(inode_t *dir, dentry_t *dentry, int mode, int dev)
  2847. +#endif
  2848. +{
  2849. + int err = 0;
  2850. +
  2851. + check_mini_fo_dentry(dentry);
  2852. +
  2853. + err = create_sto_nod(dentry, mode, dev);
  2854. + if(err) {
  2855. + printk(KERN_CRIT "mini_fo_mknod: creating sto nod failed.\n");
  2856. + err = -EINVAL;
  2857. + }
  2858. +
  2859. + check_mini_fo_dentry(dentry);
  2860. + return err;
  2861. +}
  2862. +
  2863. +
  2864. +STATIC int
  2865. +mini_fo_rename(inode_t *old_dir, dentry_t *old_dentry,
  2866. + inode_t *new_dir, dentry_t *new_dentry)
  2867. +{
  2868. + /* dispatch */
  2869. + if(S_ISDIR(old_dentry->d_inode->i_mode))
  2870. + return rename_directory(old_dir, old_dentry, new_dir, new_dentry);
  2871. + return rename_nondir(old_dir, old_dentry, new_dir, new_dentry);
  2872. +
  2873. +}
  2874. +
  2875. +int rename_directory(inode_t *old_dir, dentry_t *old_dentry,
  2876. + inode_t *new_dir, dentry_t *new_dentry)
  2877. +{
  2878. + int err, bpath_len;
  2879. + char *bpath;
  2880. +
  2881. + dentry_t *hidden_old_dentry;
  2882. + dentry_t *hidden_new_dentry;
  2883. + dentry_t *hidden_old_dir_dentry;
  2884. + dentry_t *hidden_new_dir_dentry;
  2885. +
  2886. + err = 0;
  2887. + bpath = NULL;
  2888. + bpath_len = 0;
  2889. +
  2890. + /* this is a test, chuck out if it works */
  2891. + if(!(dtopd(new_dentry)->state == DELETED ||
  2892. + dtopd(new_dentry)->state == NON_EXISTANT)) {
  2893. + printk(KERN_CRIT "mini_fo: rename_directory: \
  2894. + uh, ah, new_dentry not negative.\n");
  2895. + /* return -1; */
  2896. + }
  2897. +
  2898. + /* state = UNMODIFIED */
  2899. + if(dtopd(old_dentry)->state == UNMODIFIED) {
  2900. + err = dir_unmod_to_mod(old_dentry);
  2901. + if (err)
  2902. + goto out;
  2903. + }
  2904. +
  2905. + /* state = MODIFIED */
  2906. + if(dtopd(old_dentry)->state == MODIFIED) {
  2907. + bpath = meta_check_r_entry(old_dentry->d_parent,
  2908. + old_dentry->d_name.name,
  2909. + old_dentry->d_name.len);
  2910. + if(bpath) {
  2911. + err = meta_remove_r_entry(old_dentry->d_parent,
  2912. + old_dentry->d_name.name,
  2913. + old_dentry->d_name.len);
  2914. + if(err) {
  2915. + printk(KERN_CRIT "mini_fo: rename_directory:\
  2916. + meta_remove_r_entry \
  2917. + failed.\n");
  2918. + goto out;
  2919. + }
  2920. + err = meta_add_r_entry(new_dentry->d_parent,
  2921. + bpath,
  2922. + strlen(bpath),
  2923. + new_dentry->d_name.name,
  2924. + new_dentry->d_name.len);
  2925. + kfree(bpath);
  2926. + }
  2927. + else {/* wol it */
  2928. + err = meta_add_d_entry(old_dentry->d_parent,
  2929. + old_dentry->d_name.name,
  2930. + old_dentry->d_name.len);
  2931. + if (err)
  2932. + goto out;
  2933. + /* put it on rename list */
  2934. + err = get_mini_fo_bpath(old_dentry,
  2935. + &bpath,
  2936. + &bpath_len);
  2937. + if (err)
  2938. + goto out;
  2939. + err = meta_add_r_entry(new_dentry->d_parent,
  2940. + bpath, bpath_len,
  2941. + new_dentry->d_name.name,
  2942. + new_dentry->d_name.len);
  2943. + if (err)
  2944. + goto out;
  2945. + }
  2946. + /* no state change, MODIFIED stays MODIFIED */
  2947. + }
  2948. + /* state = CREATED */
  2949. + if(dtopd(old_dentry)->state == CREATED ||
  2950. + dtopd(old_dentry)->state == DEL_REWRITTEN) {
  2951. + if(dtohd(old_dentry))
  2952. + dput(dtohd(old_dentry));
  2953. +
  2954. + if(dtopd(new_dentry)->state == DELETED) {
  2955. + dtopd(old_dentry)->state = DEL_REWRITTEN;
  2956. + dtohd(old_dentry) = NULL;
  2957. + }
  2958. + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
  2959. + dtopd(old_dentry)->state = CREATED;
  2960. + /* steal new dentry's neg. base dentry */
  2961. + dtohd(old_dentry) = dtohd(new_dentry);
  2962. + dtohd(new_dentry) = NULL;
  2963. + }
  2964. + }
  2965. + if(dtopd(new_dentry)->state == UNMODIFIED ||
  2966. + dtopd(new_dentry)->state == NON_EXISTANT) {
  2967. + err = get_neg_sto_dentry(new_dentry);
  2968. + if(err)
  2969. + goto out;
  2970. + }
  2971. +
  2972. + /* now move sto file */
  2973. + hidden_old_dentry = dtohd2(old_dentry);
  2974. + hidden_new_dentry = dtohd2(new_dentry);
  2975. +
  2976. + dget(hidden_old_dentry);
  2977. + dget(hidden_new_dentry);
  2978. +
  2979. + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
  2980. + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
  2981. + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
  2982. +
  2983. + err = vfs_rename(hidden_old_dir_dentry->d_inode, hidden_old_dentry,
  2984. + hidden_new_dir_dentry->d_inode, hidden_new_dentry);
  2985. + if(err)
  2986. + goto out_lock;
  2987. +
  2988. + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
  2989. + if (new_dir != old_dir)
  2990. + fist_copy_attr_all(old_dir,
  2991. + hidden_old_dir_dentry->d_inode);
  2992. +
  2993. + out_lock:
  2994. + /* double_unlock will dput the new/old parent dentries
  2995. + * whose refcnts were incremented via get_parent above. */
  2996. + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
  2997. + dput(hidden_new_dentry);
  2998. + dput(hidden_old_dentry);
  2999. +
  3000. + out:
  3001. + return err;
  3002. +}
  3003. +
  3004. +int rename_nondir(inode_t *old_dir, dentry_t *old_dentry,
  3005. + inode_t *new_dir, dentry_t *new_dentry)
  3006. +{
  3007. + int err=0;
  3008. +
  3009. + check_mini_fo_dentry(old_dentry);
  3010. + check_mini_fo_dentry(new_dentry);
  3011. + check_mini_fo_inode(old_dir);
  3012. + check_mini_fo_inode(new_dir);
  3013. +
  3014. + /* state: UNMODIFIED */
  3015. + if(dtost(old_dentry) == UNMODIFIED) {
  3016. + err = nondir_unmod_to_mod(old_dentry, 1);
  3017. + if(err) {
  3018. + err = -EINVAL;
  3019. + goto out;
  3020. + }
  3021. + }
  3022. +
  3023. + /* the easy states */
  3024. + if(exists_in_storage(old_dentry)) {
  3025. +
  3026. + dentry_t *hidden_old_dentry;
  3027. + dentry_t *hidden_new_dentry;
  3028. + dentry_t *hidden_old_dir_dentry;
  3029. + dentry_t *hidden_new_dir_dentry;
  3030. +
  3031. + /* if old file is MODIFIED, add it to the deleted_list */
  3032. + if(dtopd(old_dentry)->state == MODIFIED) {
  3033. + meta_add_d_entry(old_dentry->d_parent,
  3034. + old_dentry->d_name.name,
  3035. + old_dentry->d_name.len);
  3036. +
  3037. + dput(dtohd(old_dentry));
  3038. + }
  3039. + /* if old file is CREATED, we only release the base dentry */
  3040. + if(dtopd(old_dentry)->state == CREATED) {
  3041. + if(dtohd(old_dentry))
  3042. + dput(dtohd(old_dentry));
  3043. + }
  3044. +
  3045. + /* now setup the new states (depends on new_dentry state) */
  3046. + /* new dentry state = MODIFIED */
  3047. + if(dtopd(new_dentry)->state == MODIFIED) {
  3048. + meta_add_d_entry(new_dentry->d_parent,
  3049. + new_dentry->d_name.name,
  3050. + new_dentry->d_name.len);
  3051. +
  3052. + /* new dentry will be d_put'ed later by the vfs
  3053. + * so don't do it here
  3054. + * dput(dtohd(new_dentry));
  3055. + */
  3056. + dtohd(old_dentry) = NULL;
  3057. + dtopd(old_dentry)->state = DEL_REWRITTEN;
  3058. + }
  3059. + /* new dentry state = UNMODIFIED */
  3060. + else if(dtopd(new_dentry)->state == UNMODIFIED) {
  3061. + if(get_neg_sto_dentry(new_dentry))
  3062. + return -EINVAL;
  3063. +
  3064. + meta_add_d_entry(new_dentry->d_parent,
  3065. + new_dentry->d_name.name,
  3066. + new_dentry->d_name.len);
  3067. +
  3068. + /* is this right??? */
  3069. + /*dput(dtohd(new_dentry));*/
  3070. + dtohd(old_dentry) = NULL;
  3071. + dtopd(old_dentry)->state = DEL_REWRITTEN;
  3072. + }
  3073. + /* new dentry state = CREATED */
  3074. + else if(dtopd(new_dentry)->state == CREATED) {
  3075. + /* we keep the neg. base dentry (if exists) */
  3076. + dtohd(old_dentry) = dtohd(new_dentry);
  3077. + /* ...and set it to Null, or we'll get
  3078. + * dcache.c:345 if it gets dput twice... */
  3079. + dtohd(new_dentry) = NULL;
  3080. + dtopd(old_dentry)->state = CREATED;
  3081. + }
  3082. + /* new dentry state = NON_EXISTANT */
  3083. + else if(dtopd(new_dentry)->state == NON_EXISTANT) {
  3084. + if(get_neg_sto_dentry(new_dentry))
  3085. + return -EINVAL;
  3086. +
  3087. + /* we keep the neg. base dentry (if exists) */
  3088. + dtohd(old_dentry) = dtohd(new_dentry);
  3089. + /* ...and set it to Null, or we'll get
  3090. + * Dr. dcache.c:345 if it gets dput twice... */
  3091. + dtohd(new_dentry) = NULL;
  3092. + dtopd(old_dentry)->state = CREATED;
  3093. + }
  3094. + /* new dentry state = DEL_REWRITTEN or DELETED */
  3095. + else if(dtopd(new_dentry)->state == DEL_REWRITTEN ||
  3096. + dtopd(new_dentry)->state == DELETED) {
  3097. + dtohd(old_dentry) = NULL;
  3098. + dtopd(old_dentry)->state = DEL_REWRITTEN;
  3099. + }
  3100. + else { /* not possible, uhh, ahh */
  3101. + printk(KERN_CRIT
  3102. + "mini_fo: rename_reg_file: invalid state detected [1].\n");
  3103. + return -1;
  3104. + }
  3105. +
  3106. + /* now we definitely have a sto file */
  3107. + hidden_old_dentry = dtohd2(old_dentry);
  3108. + hidden_new_dentry = dtohd2(new_dentry);
  3109. +
  3110. + dget(hidden_old_dentry);
  3111. + dget(hidden_new_dentry);
  3112. +
  3113. + hidden_old_dir_dentry = dget(hidden_old_dentry->d_parent);
  3114. + hidden_new_dir_dentry = dget(hidden_new_dentry->d_parent);
  3115. + double_lock(hidden_old_dir_dentry, hidden_new_dir_dentry);
  3116. +
  3117. + err = vfs_rename(hidden_old_dir_dentry->d_inode,
  3118. + hidden_old_dentry,
  3119. + hidden_new_dir_dentry->d_inode,
  3120. + hidden_new_dentry);
  3121. + if(err)
  3122. + goto out_lock;
  3123. +
  3124. + fist_copy_attr_all(new_dir, hidden_new_dir_dentry->d_inode);
  3125. + if (new_dir != old_dir)
  3126. + fist_copy_attr_all(old_dir, hidden_old_dir_dentry->d_inode);
  3127. +
  3128. + out_lock:
  3129. + /* double_unlock will dput the new/old parent dentries
  3130. + * whose refcnts were incremented via get_parent above.
  3131. + */
  3132. + double_unlock(hidden_old_dir_dentry, hidden_new_dir_dentry);
  3133. + dput(hidden_new_dentry);
  3134. + dput(hidden_old_dentry);
  3135. + out:
  3136. + return err;
  3137. + }
  3138. + else { /* invalid state */
  3139. + printk(KERN_CRIT "mini_fo: rename_reg_file: ERROR: invalid state detected [2].\n");
  3140. + return -1;
  3141. + }
  3142. +}
  3143. +
  3144. +
  3145. +STATIC int
  3146. +mini_fo_readlink(dentry_t *dentry, char *buf, int bufsiz)
  3147. +{
  3148. + int err=0;
  3149. + dentry_t *hidden_dentry = NULL;
  3150. +
  3151. + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
  3152. + hidden_dentry = dtohd2(dentry);
  3153. + } else if(dtohd(dentry) && dtohd(dentry)->d_inode) {
  3154. + hidden_dentry = dtohd(dentry);
  3155. + } else {
  3156. + goto out;
  3157. + }
  3158. +
  3159. + if (!hidden_dentry->d_inode->i_op ||
  3160. + !hidden_dentry->d_inode->i_op->readlink) {
  3161. + err = -EINVAL; goto out;
  3162. + }
  3163. +
  3164. + err = hidden_dentry->d_inode->i_op->readlink(hidden_dentry,
  3165. + buf,
  3166. + bufsiz);
  3167. + if (err > 0)
  3168. + fist_copy_attr_atime(dentry->d_inode, hidden_dentry->d_inode);
  3169. +
  3170. + out:
  3171. + return err;
  3172. +}
  3173. +
  3174. +
  3175. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
  3176. +static int mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
  3177. +#else
  3178. +static void* mini_fo_follow_link(dentry_t *dentry, struct nameidata *nd)
  3179. +#endif
  3180. +{
  3181. + char *buf;
  3182. + int len = PAGE_SIZE, err;
  3183. + mm_segment_t old_fs;
  3184. +
  3185. + /* in 2.6 this is freed by mini_fo_put_link called by __do_follow_link */
  3186. + buf = kmalloc(len, GFP_KERNEL);
  3187. + if (!buf) {
  3188. + err = -ENOMEM;
  3189. + goto out;
  3190. + }
  3191. +
  3192. + /* read the symlink, and then we will follow it */
  3193. + old_fs = get_fs();
  3194. + set_fs(KERNEL_DS);
  3195. + err = dentry->d_inode->i_op->readlink(dentry, buf, len);
  3196. + set_fs(old_fs);
  3197. + if (err < 0) {
  3198. + kfree(buf);
  3199. + buf = NULL;
  3200. + goto out;
  3201. + }
  3202. + buf[err] = 0;
  3203. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  3204. + nd_set_link(nd, buf);
  3205. + err = 0;
  3206. +#else
  3207. + err = vfs_follow_link(nd, buf);
  3208. +#endif
  3209. +
  3210. + out:
  3211. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  3212. + kfree(buf);
  3213. +#endif
  3214. +
  3215. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
  3216. + return err;
  3217. +#else
  3218. + return ERR_PTR(err);
  3219. +#endif
  3220. +}
  3221. +
  3222. +STATIC
  3223. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  3224. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
  3225. +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd)
  3226. +#else
  3227. +void mini_fo_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
  3228. +#endif
  3229. +{
  3230. + char *link;
  3231. + link = nd_get_link(nd);
  3232. + kfree(link);
  3233. +}
  3234. +#endif
  3235. +
  3236. +STATIC int
  3237. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  3238. +mini_fo_permission(inode_t *inode, int mask, struct nameidata *nd)
  3239. +#else
  3240. +mini_fo_permission(inode_t *inode, int mask)
  3241. +#endif
  3242. +{
  3243. + inode_t *hidden_inode;
  3244. + int mode;
  3245. + int err;
  3246. +
  3247. + if(itohi2(inode)) {
  3248. + hidden_inode = itohi2(inode);
  3249. + } else {
  3250. + hidden_inode = itohi(inode);
  3251. + }
  3252. + mode = inode->i_mode;
  3253. +
  3254. + /* not really needed, as permission handles everything:
  3255. + * err = vfs_permission(inode, mask);
  3256. + * if (err)
  3257. + * goto out;
  3258. + */
  3259. +
  3260. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  3261. + err = permission(hidden_inode, mask, nd);
  3262. +#else
  3263. + err = permission(hidden_inode, mask);
  3264. +#endif
  3265. +
  3266. + /* out: */
  3267. + return err;
  3268. +}
  3269. +
  3270. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  3271. +STATIC int
  3272. +mini_fo_inode_revalidate(dentry_t *dentry)
  3273. +{
  3274. + int err = 0;
  3275. + dentry_t *hidden_dentry;
  3276. + inode_t *hidden_inode;
  3277. +
  3278. + ASSERT(dentry->d_inode);
  3279. + ASSERT(itopd(dentry->d_inode));
  3280. +
  3281. + if(itohi2(dentry->d_inode)) {
  3282. + hidden_dentry = dtohd2(dentry);
  3283. + hidden_inode = hidden_dentry->d_inode;
  3284. + } else if(itohi(dentry->d_inode)) {
  3285. + hidden_dentry = dtohd(dentry);
  3286. + hidden_inode = hidden_dentry->d_inode;
  3287. + } else {
  3288. + printk(KERN_CRIT "mini_fo_inode_revalidate: ERROR, invalid state detected.\n");
  3289. + err = -ENOENT;
  3290. + goto out;
  3291. + }
  3292. + if (hidden_inode && hidden_inode->i_op && hidden_inode->i_op->revalidate){
  3293. + err = hidden_inode->i_op->revalidate(hidden_dentry);
  3294. + if (err)
  3295. + goto out;
  3296. + }
  3297. + fist_copy_attr_all(dentry->d_inode, hidden_inode);
  3298. + out:
  3299. + return err;
  3300. +}
  3301. +#endif
  3302. +
  3303. +STATIC int
  3304. +mini_fo_setattr(dentry_t *dentry, struct iattr *ia)
  3305. +{
  3306. + int err = 0;
  3307. +
  3308. + check_mini_fo_dentry(dentry);
  3309. +
  3310. + if(!is_mini_fo_existant(dentry)) {
  3311. + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [1].\n");
  3312. + goto out;
  3313. + }
  3314. +
  3315. + if(dtost(dentry) == UNMODIFIED) {
  3316. + if(!IS_COPY_FLAG(ia->ia_valid))
  3317. + goto out; /* we ignore these changes to base */
  3318. +
  3319. + if(S_ISDIR(dentry->d_inode->i_mode)) {
  3320. + err = dir_unmod_to_mod(dentry);
  3321. + } else {
  3322. + /* we copy contents if file is not beeing truncated */
  3323. + if(S_ISREG(dentry->d_inode->i_mode) &&
  3324. + !(ia->ia_size == 0 && (ia->ia_valid & ATTR_SIZE))) {
  3325. + err = nondir_unmod_to_mod(dentry, 1);
  3326. + } else
  3327. + err = nondir_unmod_to_mod(dentry, 0);
  3328. + }
  3329. + if(err) {
  3330. + err = -EINVAL;
  3331. + printk(KERN_CRIT "mini_fo_setattr: ERROR changing states.\n");
  3332. + goto out;
  3333. + }
  3334. + }
  3335. + if(!exists_in_storage(dentry)) {
  3336. + printk(KERN_CRIT "mini_fo_setattr: ERROR, invalid state detected [2].\n");
  3337. + err = -EINVAL;
  3338. + goto out;
  3339. + }
  3340. + ASSERT(dentry->d_inode);
  3341. + ASSERT(dtohd2(dentry));
  3342. + ASSERT(itopd(dentry->d_inode));
  3343. + ASSERT(itohi2(dentry->d_inode));
  3344. +
  3345. + err = notify_change(dtohd2(dentry), ia);
  3346. + fist_copy_attr_all(dentry->d_inode, itohi2(dentry->d_inode));
  3347. + out:
  3348. + return err;
  3349. +}
  3350. +
  3351. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  3352. +STATIC int
  3353. +mini_fo_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
  3354. +{
  3355. + int err = 0;
  3356. + dentry_t *hidden_dentry;
  3357. +
  3358. + ASSERT(dentry->d_inode);
  3359. + ASSERT(itopd(dentry->d_inode));
  3360. +
  3361. + if(itohi2(dentry->d_inode)) {
  3362. + hidden_dentry = dtohd2(dentry);
  3363. + } else if(itohi(dentry->d_inode)) {
  3364. + hidden_dentry = dtohd(dentry);
  3365. + } else {
  3366. + printk(KERN_CRIT "mini_fo_getattr: ERROR, invalid state detected.\n");
  3367. + err = -ENOENT;
  3368. + goto out;
  3369. + }
  3370. + fist_copy_attr_all(dentry->d_inode, hidden_dentry->d_inode);
  3371. +
  3372. + ASSERT(hidden_dentry);
  3373. + ASSERT(hidden_dentry->d_inode);
  3374. + ASSERT(hidden_dentry->d_inode->i_op);
  3375. +
  3376. + generic_fillattr(dentry->d_inode, stat);
  3377. + if (!stat->blksize) {
  3378. + struct super_block *s = hidden_dentry->d_inode->i_sb;
  3379. + unsigned blocks;
  3380. + blocks = (stat->size+s->s_blocksize-1) >> s->s_blocksize_bits;
  3381. + stat->blocks = (s->s_blocksize / 512) * blocks;
  3382. + stat->blksize = s->s_blocksize;
  3383. + }
  3384. + out:
  3385. + return err;
  3386. +}
  3387. +#endif
  3388. +
  3389. +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
  3390. +#if 0 /* no xattr_alloc() and xattr_free() */
  3391. +/* This is lifted from fs/xattr.c */
  3392. +static void *
  3393. +xattr_alloc(size_t size, size_t limit)
  3394. +{
  3395. + void *ptr;
  3396. +
  3397. + if (size > limit)
  3398. + return ERR_PTR(-E2BIG);
  3399. +
  3400. + if (!size) /* size request, no buffer is needed */
  3401. + return NULL;
  3402. + else if (size <= PAGE_SIZE)
  3403. + ptr = kmalloc((unsigned long) size, GFP_KERNEL);
  3404. + else
  3405. + ptr = vmalloc((unsigned long) size);
  3406. + if (!ptr)
  3407. + return ERR_PTR(-ENOMEM);
  3408. + return ptr;
  3409. +}
  3410. +
  3411. +static void
  3412. +xattr_free(void *ptr, size_t size)
  3413. +{
  3414. + if (!size) /* size request, no buffer was needed */
  3415. + return;
  3416. + else if (size <= PAGE_SIZE)
  3417. + kfree(ptr);
  3418. + else
  3419. + vfree(ptr);
  3420. +}
  3421. +#endif /* no xattr_alloc() and xattr_free() */
  3422. +
  3423. +/* BKL held by caller.
  3424. + * dentry->d_inode->i_sem down
  3425. + */
  3426. +STATIC int
  3427. +mini_fo_getxattr(struct dentry *dentry, const char *name, void *value, size_t size) {
  3428. + struct dentry *hidden_dentry = NULL;
  3429. + int err = -EOPNOTSUPP;
  3430. + /* Define these anyway so we don't need as much ifdef'ed code. */
  3431. + char *encoded_name = NULL;
  3432. + char *encoded_value = NULL;
  3433. +
  3434. + check_mini_fo_dentry(dentry);
  3435. +
  3436. + if(exists_in_storage(dentry))
  3437. + hidden_dentry = dtohd2(dentry);
  3438. + else
  3439. + hidden_dentry = dtohd(dentry);
  3440. +
  3441. + ASSERT(hidden_dentry);
  3442. + ASSERT(hidden_dentry->d_inode);
  3443. + ASSERT(hidden_dentry->d_inode->i_op);
  3444. +
  3445. + if (hidden_dentry->d_inode->i_op->getxattr) {
  3446. + encoded_name = (char *)name;
  3447. + encoded_value = (char *)value;
  3448. +
  3449. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  3450. + mutex_lock(&hidden_dentry->d_inode->i_mutex);
  3451. +#else
  3452. + down(&hidden_dentry->d_inode->i_sem);
  3453. +#endif
  3454. + /* lock_kernel() already done by caller. */
  3455. + err = hidden_dentry->d_inode->i_op->getxattr(hidden_dentry, encoded_name, encoded_value, size);
  3456. + /* unlock_kernel() will be done by caller. */
  3457. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  3458. + mutex_lock(&hidden_dentry->d_inode->i_mutex);
  3459. +#else
  3460. + up(&hidden_dentry->d_inode->i_sem);
  3461. +#endif
  3462. + }
  3463. + return err;
  3464. +}
  3465. +
  3466. +/* BKL held by caller.
  3467. + * dentry->d_inode->i_sem down
  3468. + */
  3469. +STATIC int
  3470. +#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21) \
  3471. + && LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,23)) \
  3472. + || LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
  3473. +mini_fo_setxattr(struct dentry *dentry, const char *name,
  3474. + const void *value, size_t size, int flags)
  3475. +#else
  3476. +mini_fo_setxattr(struct dentry *dentry, const char *name,
  3477. + void *value, size_t size, int flags)
  3478. +#endif
  3479. +
  3480. +{
  3481. + struct dentry *hidden_dentry = NULL;
  3482. + int err = -EOPNOTSUPP;
  3483. +
  3484. + /* Define these anyway, so we don't have as much ifdef'ed code. */
  3485. + char *encoded_value = NULL;
  3486. + char *encoded_name = NULL;
  3487. +
  3488. + check_mini_fo_dentry(dentry);
  3489. +
  3490. + if(exists_in_storage(dentry))
  3491. + hidden_dentry = dtohd2(dentry);
  3492. + else
  3493. + hidden_dentry = dtohd(dentry);
  3494. +
  3495. + ASSERT(hidden_dentry);
  3496. + ASSERT(hidden_dentry->d_inode);
  3497. + ASSERT(hidden_dentry->d_inode->i_op);
  3498. +
  3499. + if (hidden_dentry->d_inode->i_op->setxattr) {
  3500. + encoded_name = (char *)name;
  3501. + encoded_value = (char *)value;
  3502. +
  3503. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  3504. + mutex_lock(&hidden_dentry->d_inode->i_mutex);
  3505. +#else
  3506. + down(&hidden_dentry->d_inode->i_sem);
  3507. +#endif
  3508. + /* lock_kernel() already done by caller. */
  3509. + err = hidden_dentry->d_inode->i_op->setxattr(hidden_dentry, encoded_name, encoded_value, size, flags);
  3510. + /* unlock_kernel() will be done by caller. */
  3511. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  3512. + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
  3513. +#else
  3514. + up(&hidden_dentry->d_inode->i_sem);
  3515. +#endif
  3516. + }
  3517. + return err;
  3518. +}
  3519. +
  3520. +/* BKL held by caller.
  3521. + * dentry->d_inode->i_sem down
  3522. + */
  3523. +STATIC int
  3524. +mini_fo_removexattr(struct dentry *dentry, const char *name) {
  3525. + struct dentry *hidden_dentry = NULL;
  3526. + int err = -EOPNOTSUPP;
  3527. + char *encoded_name;
  3528. +
  3529. + check_mini_fo_dentry(dentry);
  3530. +
  3531. + if(exists_in_storage(dentry))
  3532. + hidden_dentry = dtohd2(dentry);
  3533. + else
  3534. + hidden_dentry = dtohd(dentry);
  3535. +
  3536. + ASSERT(hidden_dentry);
  3537. + ASSERT(hidden_dentry->d_inode);
  3538. + ASSERT(hidden_dentry->d_inode->i_op);
  3539. +
  3540. + if (hidden_dentry->d_inode->i_op->removexattr) {
  3541. + encoded_name = (char *)name;
  3542. +
  3543. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  3544. + mutex_lock(&hidden_dentry->d_inode->i_mutex);
  3545. +#else
  3546. + down(&hidden_dentry->d_inode->i_sem);
  3547. +#endif
  3548. + /* lock_kernel() already done by caller. */
  3549. + err = hidden_dentry->d_inode->i_op->removexattr(hidden_dentry, encoded_name);
  3550. + /* unlock_kernel() will be done by caller. */
  3551. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  3552. + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
  3553. +#else
  3554. + up(&hidden_dentry->d_inode->i_sem);
  3555. +#endif
  3556. + }
  3557. + return err;
  3558. +}
  3559. +
  3560. +/* BKL held by caller.
  3561. + * dentry->d_inode->i_sem down
  3562. + */
  3563. +STATIC int
  3564. +mini_fo_listxattr(struct dentry *dentry, char *list, size_t size) {
  3565. + struct dentry *hidden_dentry = NULL;
  3566. + int err = -EOPNOTSUPP;
  3567. + char *encoded_list = NULL;
  3568. +
  3569. + check_mini_fo_dentry(dentry);
  3570. +
  3571. + if(exists_in_storage(dentry))
  3572. + hidden_dentry = dtohd2(dentry);
  3573. + else
  3574. + hidden_dentry = dtohd(dentry);
  3575. +
  3576. + ASSERT(hidden_dentry);
  3577. + ASSERT(hidden_dentry->d_inode);
  3578. + ASSERT(hidden_dentry->d_inode->i_op);
  3579. +
  3580. + if (hidden_dentry->d_inode->i_op->listxattr) {
  3581. + encoded_list = list;
  3582. +
  3583. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  3584. + mutex_lock(&hidden_dentry->d_inode->i_mutex);
  3585. +#else
  3586. + down(&hidden_dentry->d_inode->i_sem);
  3587. +#endif
  3588. + /* lock_kernel() already done by caller. */
  3589. + err = hidden_dentry->d_inode->i_op->listxattr(hidden_dentry, encoded_list, size);
  3590. + /* unlock_kernel() will be done by caller. */
  3591. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  3592. + mutex_unlock(&hidden_dentry->d_inode->i_mutex);
  3593. +#else
  3594. + up(&hidden_dentry->d_inode->i_sem);
  3595. +#endif
  3596. + }
  3597. + return err;
  3598. +}
  3599. +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
  3600. +
  3601. +struct inode_operations mini_fo_symlink_iops =
  3602. + {
  3603. + readlink: mini_fo_readlink,
  3604. + follow_link: mini_fo_follow_link,
  3605. + /* mk: permission: mini_fo_permission, */
  3606. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  3607. + revalidate: mini_fo_inode_revalidate,
  3608. +#endif
  3609. + setattr: mini_fo_setattr,
  3610. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  3611. + getattr: mini_fo_getattr,
  3612. + put_link: mini_fo_put_link,
  3613. +#endif
  3614. +
  3615. +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
  3616. + setxattr: mini_fo_setxattr,
  3617. + getxattr: mini_fo_getxattr,
  3618. + listxattr: mini_fo_listxattr,
  3619. + removexattr: mini_fo_removexattr
  3620. +# endif /* defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)) */
  3621. + };
  3622. +
  3623. +struct inode_operations mini_fo_dir_iops =
  3624. + {
  3625. + create: mini_fo_create,
  3626. + lookup: mini_fo_lookup,
  3627. + link: mini_fo_link,
  3628. + unlink: mini_fo_unlink,
  3629. + symlink: mini_fo_symlink,
  3630. + mkdir: mini_fo_mkdir,
  3631. + rmdir: mini_fo_rmdir,
  3632. + mknod: mini_fo_mknod,
  3633. + rename: mini_fo_rename,
  3634. + /* no readlink/follow_link for non-symlinks */
  3635. + // off because we have setattr
  3636. + // truncate: mini_fo_truncate,
  3637. + /* mk:permission: mini_fo_permission, */
  3638. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  3639. + revalidate: mini_fo_inode_revalidate,
  3640. +#endif
  3641. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  3642. + getattr: mini_fo_getattr,
  3643. +#endif
  3644. + setattr: mini_fo_setattr,
  3645. +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
  3646. + setxattr: mini_fo_setxattr,
  3647. + getxattr: mini_fo_getxattr,
  3648. + listxattr: mini_fo_listxattr,
  3649. + removexattr: mini_fo_removexattr
  3650. +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
  3651. + };
  3652. +
  3653. +struct inode_operations mini_fo_main_iops =
  3654. + {
  3655. + /* permission: mini_fo_permission, */
  3656. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  3657. + revalidate: mini_fo_inode_revalidate,
  3658. +#endif
  3659. + setattr: mini_fo_setattr,
  3660. +
  3661. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  3662. + getattr: mini_fo_getattr,
  3663. +#endif
  3664. +#if defined(XATTR) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20))
  3665. + setxattr: mini_fo_setxattr,
  3666. + getxattr: mini_fo_getxattr,
  3667. + listxattr: mini_fo_listxattr,
  3668. + removexattr: mini_fo_removexattr
  3669. +# endif /* XATTR && LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) */
  3670. + };
  3671. --- /dev/null
  3672. +++ b/fs/mini_fo/main.c
  3673. @@ -0,0 +1,423 @@
  3674. +/*
  3675. + * Copyright (c) 1997-2003 Erez Zadok
  3676. + * Copyright (c) 2001-2003 Stony Brook University
  3677. + *
  3678. + * For specific licensing information, see the COPYING file distributed with
  3679. + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
  3680. + *
  3681. + * This Copyright notice must be kept intact and distributed with all
  3682. + * fistgen sources INCLUDING sources generated by fistgen.
  3683. + */
  3684. +/*
  3685. + * Copyright (C) 2004, 2005 Markus Klotzbuecher <[email protected]>
  3686. + *
  3687. + * This program is free software; you can redistribute it and/or
  3688. + * modify it under the terms of the GNU General Public License
  3689. + * as published by the Free Software Foundation; either version
  3690. + * 2 of the License, or (at your option) any later version.
  3691. + */
  3692. +
  3693. +/*
  3694. + * $Id$
  3695. + */
  3696. +
  3697. +#ifdef HAVE_CONFIG_H
  3698. +# include <config.h>
  3699. +#endif
  3700. +
  3701. +#include "fist.h"
  3702. +#include "mini_fo.h"
  3703. +#include <linux/module.h>
  3704. +
  3705. +/* This definition must only appear after we include <linux/module.h> */
  3706. +#ifndef MODULE_LICENSE
  3707. +# define MODULE_LICENSE(bison)
  3708. +#endif /* not MODULE_LICENSE */
  3709. +
  3710. +/*
  3711. + * This is the mini_fo tri interpose function, which extends the
  3712. + * functionality of the regular interpose by interposing a higher
  3713. + * level inode on top of two lower level ones: the base filesystem
  3714. + * inode and the storage filesystem inode.
  3715. + *
  3716. + * sb we pass is mini_fo's super_block
  3717. + */
  3718. +int
  3719. +mini_fo_tri_interpose(dentry_t *hidden_dentry,
  3720. + dentry_t *hidden_sto_dentry,
  3721. + dentry_t *dentry, super_block_t *sb, int flag)
  3722. +{
  3723. + inode_t *hidden_inode = NULL;
  3724. + inode_t *hidden_sto_inode = NULL; /* store corresponding storage inode */
  3725. + int err = 0;
  3726. + inode_t *inode;
  3727. +
  3728. + /* Pointer to hidden_sto_inode if exists, else to hidden_inode.
  3729. + * This is used to copy the attributes of the correct inode. */
  3730. + inode_t *master_inode;
  3731. +
  3732. + if(hidden_dentry)
  3733. + hidden_inode = hidden_dentry->d_inode;
  3734. + if(hidden_sto_dentry)
  3735. + hidden_sto_inode = hidden_sto_dentry->d_inode;
  3736. +
  3737. + ASSERT(dentry->d_inode == NULL);
  3738. +
  3739. + /* mk: One of the inodes associated with the dentrys is likely to
  3740. + * be NULL, so carefull:
  3741. + */
  3742. + ASSERT((hidden_inode != NULL) || (hidden_sto_inode != NULL));
  3743. +
  3744. + if(hidden_sto_inode)
  3745. + master_inode = hidden_sto_inode;
  3746. + else
  3747. + master_inode = hidden_inode;
  3748. +
  3749. + /*
  3750. + * We allocate our new inode below, by calling iget.
  3751. + * iget will call our read_inode which will initialize some
  3752. + * of the new inode's fields
  3753. + */
  3754. +
  3755. + /*
  3756. + * original: inode = iget(sb, hidden_inode->i_ino);
  3757. + */
  3758. + inode = iget(sb, iunique(sb, 25));
  3759. + if (!inode) {
  3760. + err = -EACCES; /* should be impossible??? */
  3761. + goto out;
  3762. + }
  3763. +
  3764. + /*
  3765. + * interpose the inode if not already interposed
  3766. + * this is possible if the inode is being reused
  3767. + * XXX: what happens if we get_empty_inode() but there's another already?
  3768. + * for now, ASSERT() that this can't happen; fix later.
  3769. + */
  3770. + if (itohi(inode) != NULL) {
  3771. + printk(KERN_CRIT "mini_fo_tri_interpose: itohi(inode) != NULL.\n");
  3772. + }
  3773. + if (itohi2(inode) != NULL) {
  3774. + printk(KERN_CRIT "mini_fo_tri_interpose: itohi2(inode) != NULL.\n");
  3775. + }
  3776. +
  3777. + /* mk: Carefull, igrab can't handle NULL inodes (ok, why should it?), so
  3778. + * we need to check here:
  3779. + */
  3780. + if(hidden_inode)
  3781. + itohi(inode) = igrab(hidden_inode);
  3782. + else
  3783. + itohi(inode) = NULL;
  3784. +
  3785. + if(hidden_sto_inode)
  3786. + itohi2(inode) = igrab(hidden_sto_inode);
  3787. + else
  3788. + itohi2(inode) = NULL;
  3789. +
  3790. +
  3791. + /* Use different set of inode ops for symlinks & directories*/
  3792. + if (S_ISLNK(master_inode->i_mode))
  3793. + inode->i_op = &mini_fo_symlink_iops;
  3794. + else if (S_ISDIR(master_inode->i_mode))
  3795. + inode->i_op = &mini_fo_dir_iops;
  3796. +
  3797. + /* Use different set of file ops for directories */
  3798. + if (S_ISDIR(master_inode->i_mode))
  3799. + inode->i_fop = &mini_fo_dir_fops;
  3800. +
  3801. + /* properly initialize special inodes */
  3802. + if (S_ISBLK(master_inode->i_mode) || S_ISCHR(master_inode->i_mode) ||
  3803. + S_ISFIFO(master_inode->i_mode) || S_ISSOCK(master_inode->i_mode)) {
  3804. + init_special_inode(inode, master_inode->i_mode, master_inode->i_rdev);
  3805. + }
  3806. +
  3807. + /* Fix our inode's address operations to that of the lower inode */
  3808. + if (inode->i_mapping->a_ops != master_inode->i_mapping->a_ops) {
  3809. + inode->i_mapping->a_ops = master_inode->i_mapping->a_ops;
  3810. + }
  3811. +
  3812. + /* only (our) lookup wants to do a d_add */
  3813. + if (flag)
  3814. + d_add(dentry, inode);
  3815. + else
  3816. + d_instantiate(dentry, inode);
  3817. +
  3818. + ASSERT(dtopd(dentry) != NULL);
  3819. +
  3820. + /* all well, copy inode attributes */
  3821. + fist_copy_attr_all(inode, master_inode);
  3822. +
  3823. + out:
  3824. + return err;
  3825. +}
  3826. +
  3827. +/* parse mount options "base=" and "sto=" */
  3828. +dentry_t *
  3829. +mini_fo_parse_options(super_block_t *sb, char *options)
  3830. +{
  3831. + dentry_t *hidden_root = ERR_PTR(-EINVAL);
  3832. + dentry_t *hidden_root2 = ERR_PTR(-EINVAL);
  3833. + struct nameidata nd, nd2;
  3834. + char *name, *tmp, *end;
  3835. + int err = 0;
  3836. +
  3837. + /* We don't want to go off the end of our arguments later on. */
  3838. + for (end = options; *end; end++);
  3839. +
  3840. + while (options < end) {
  3841. + tmp = options;
  3842. + while (*tmp && *tmp != ',')
  3843. + tmp++;
  3844. + *tmp = '\0';
  3845. + if (!strncmp("base=", options, 5)) {
  3846. + name = options + 5;
  3847. + printk(KERN_INFO "mini_fo: using base directory: %s\n", name);
  3848. +
  3849. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  3850. + if (path_init(name, LOOKUP_FOLLOW, &nd))
  3851. + err = path_walk(name, &nd);
  3852. +#else
  3853. + err = path_lookup(name, LOOKUP_FOLLOW, &nd);
  3854. +#endif
  3855. + if (err) {
  3856. + printk(KERN_CRIT "mini_fo: error accessing hidden directory '%s'\n", name);
  3857. + hidden_root = ERR_PTR(err);
  3858. + goto out;
  3859. + }
  3860. + hidden_root = nd.dentry;
  3861. + stopd(sb)->base_dir_dentry = nd.dentry;
  3862. + stopd(sb)->hidden_mnt = nd.mnt;
  3863. +
  3864. + } else if(!strncmp("sto=", options, 4)) {
  3865. + /* parse the storage dir */
  3866. + name = options + 4;
  3867. + printk(KERN_INFO "mini_fo: using storage directory: %s\n", name);
  3868. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  3869. + if(path_init(name, LOOKUP_FOLLOW, &nd2))
  3870. + err = path_walk(name, &nd2);
  3871. +#else
  3872. + err = path_lookup(name, LOOKUP_FOLLOW, &nd2);
  3873. +#endif
  3874. + if(err) {
  3875. + printk(KERN_CRIT "mini_fo: error accessing hidden storage directory '%s'\n", name);
  3876. +
  3877. + hidden_root2 = ERR_PTR(err);
  3878. + goto out;
  3879. + }
  3880. + hidden_root2 = nd2.dentry;
  3881. + stopd(sb)->storage_dir_dentry = nd2.dentry;
  3882. + stopd(sb)->hidden_mnt2 = nd2.mnt;
  3883. + stohs2(sb) = hidden_root2->d_sb;
  3884. +
  3885. + /* validate storage dir, this is done in
  3886. + * mini_fo_read_super for the base directory.
  3887. + */
  3888. + if (IS_ERR(hidden_root2)) {
  3889. + printk(KERN_WARNING "mini_fo_parse_options: storage dentry lookup failed (err = %ld)\n", PTR_ERR(hidden_root2));
  3890. + goto out;
  3891. + }
  3892. + if (!hidden_root2->d_inode) {
  3893. + printk(KERN_WARNING "mini_fo_parse_options: no storage dir to interpose on.\n");
  3894. + goto out;
  3895. + }
  3896. + stohs2(sb) = hidden_root2->d_sb;
  3897. + } else {
  3898. + printk(KERN_WARNING "mini_fo: unrecognized option '%s'\n", options);
  3899. + hidden_root = ERR_PTR(-EINVAL);
  3900. + goto out;
  3901. + }
  3902. + options = tmp + 1;
  3903. + }
  3904. +
  3905. + out:
  3906. + if(IS_ERR(hidden_root2))
  3907. + return hidden_root2;
  3908. + return hidden_root;
  3909. +}
  3910. +
  3911. +
  3912. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  3913. +static int
  3914. +#else
  3915. +super_block_t *
  3916. +#endif
  3917. +mini_fo_read_super(super_block_t *sb, void *raw_data, int silent)
  3918. +{
  3919. + dentry_t *hidden_root;
  3920. + int err = 0;
  3921. +
  3922. + if (!raw_data) {
  3923. + printk(KERN_WARNING "mini_fo_read_super: missing argument\n");
  3924. + err = -EINVAL;
  3925. + goto out;
  3926. + }
  3927. + /*
  3928. + * Allocate superblock private data
  3929. + */
  3930. + __stopd(sb) = kmalloc(sizeof(struct mini_fo_sb_info), GFP_KERNEL);
  3931. + if (!stopd(sb)) {
  3932. + printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
  3933. + err = -ENOMEM;
  3934. + goto out;
  3935. + }
  3936. + stohs(sb) = NULL;
  3937. +
  3938. + hidden_root = mini_fo_parse_options(sb, raw_data);
  3939. + if (IS_ERR(hidden_root)) {
  3940. + printk(KERN_WARNING "mini_fo_read_super: lookup_dentry failed (err = %ld)\n", PTR_ERR(hidden_root));
  3941. + err = PTR_ERR(hidden_root);
  3942. + goto out_free;
  3943. + }
  3944. + if (!hidden_root->d_inode) {
  3945. + printk(KERN_WARNING "mini_fo_read_super: no directory to interpose on\n");
  3946. + goto out_free;
  3947. + }
  3948. + stohs(sb) = hidden_root->d_sb;
  3949. +
  3950. + /*
  3951. + * Linux 2.4.2-ac3 and beyond has code in
  3952. + * mm/filemap.c:generic_file_write() that requires sb->s_maxbytes
  3953. + * to be populated. If not set, all write()s under that sb will
  3954. + * return 0.
  3955. + *
  3956. + * Linux 2.4.4+ automatically sets s_maxbytes to MAX_NON_LFS;
  3957. + * the filesystem should override it only if it supports LFS.
  3958. + */
  3959. + /* non-SCA code is good to go with LFS */
  3960. + sb->s_maxbytes = hidden_root->d_sb->s_maxbytes;
  3961. +
  3962. + sb->s_op = &mini_fo_sops;
  3963. + /*
  3964. + * we can't use d_alloc_root if we want to use
  3965. + * our own interpose function unchanged,
  3966. + * so we simply replicate *most* of the code in d_alloc_root here
  3967. + */
  3968. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  3969. + sb->s_root = d_alloc(NULL, &(const struct qstr) { "/", 1, 0 });
  3970. +#else
  3971. + sb->s_root = d_alloc(NULL, &(const struct qstr){hash: 0, name: "/", len : 1});
  3972. +#endif
  3973. + if (IS_ERR(sb->s_root)) {
  3974. + printk(KERN_WARNING "mini_fo_read_super: d_alloc failed\n");
  3975. + err = -ENOMEM;
  3976. + goto out_dput;
  3977. + }
  3978. +
  3979. + sb->s_root->d_op = &mini_fo_dops;
  3980. + sb->s_root->d_sb = sb;
  3981. + sb->s_root->d_parent = sb->s_root;
  3982. +
  3983. + /* link the upper and lower dentries */
  3984. + __dtopd(sb->s_root) = (struct mini_fo_dentry_info *)
  3985. + kmalloc(sizeof(struct mini_fo_dentry_info), GFP_KERNEL);
  3986. + if (!dtopd(sb->s_root)) {
  3987. + err = -ENOMEM;
  3988. + goto out_dput2;
  3989. + }
  3990. + dtopd(sb->s_root)->state = MODIFIED;
  3991. + dtohd(sb->s_root) = hidden_root;
  3992. +
  3993. + /* fanout relevant, interpose on storage root dentry too */
  3994. + dtohd2(sb->s_root) = stopd(sb)->storage_dir_dentry;
  3995. +
  3996. + /* ...and call tri-interpose to interpose root dir inodes
  3997. + * if (mini_fo_interpose(hidden_root, sb->s_root, sb, 0))
  3998. + */
  3999. + if(mini_fo_tri_interpose(hidden_root, dtohd2(sb->s_root), sb->s_root, sb, 0))
  4000. + goto out_dput2;
  4001. +
  4002. + /* initalize the wol list */
  4003. + itopd(sb->s_root->d_inode)->deleted_list_size = -1;
  4004. + itopd(sb->s_root->d_inode)->renamed_list_size = -1;
  4005. + meta_build_lists(sb->s_root);
  4006. +
  4007. + goto out;
  4008. +
  4009. + out_dput2:
  4010. + dput(sb->s_root);
  4011. + out_dput:
  4012. + dput(hidden_root);
  4013. + dput(dtohd2(sb->s_root)); /* release the hidden_sto_dentry too */
  4014. + out_free:
  4015. + kfree(stopd(sb));
  4016. + __stopd(sb) = NULL;
  4017. + out:
  4018. +
  4019. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  4020. + return err;
  4021. +#else
  4022. + if (err) {
  4023. + return ERR_PTR(err);
  4024. + } else {
  4025. + return sb;
  4026. + }
  4027. +#endif
  4028. +}
  4029. +
  4030. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  4031. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
  4032. +static int mini_fo_get_sb(struct file_system_type *fs_type,
  4033. + int flags, const char *dev_name,
  4034. + void *raw_data, struct vfsmount *mnt)
  4035. +{
  4036. + return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super, mnt);
  4037. +}
  4038. +#else
  4039. +static struct super_block *mini_fo_get_sb(struct file_system_type *fs_type,
  4040. + int flags, const char *dev_name,
  4041. + void *raw_data)
  4042. +{
  4043. + return get_sb_nodev(fs_type, flags, raw_data, mini_fo_read_super);
  4044. +}
  4045. +#endif
  4046. +
  4047. +void mini_fo_kill_block_super(struct super_block *sb)
  4048. +{
  4049. + generic_shutdown_super(sb);
  4050. + /*
  4051. + * XXX: BUG: Halcrow: Things get unstable sometime after this point:
  4052. + * lib/rwsem-spinlock.c:127: spin_is_locked on uninitialized
  4053. + * fs/fs-writeback.c:402: spin_lock(fs/super.c:a0381828) already
  4054. + * locked by fs/fs-writeback.c/402
  4055. + *
  4056. + * Apparently, someone's not releasing a lock on sb_lock...
  4057. + */
  4058. +}
  4059. +
  4060. +static struct file_system_type mini_fo_fs_type = {
  4061. + .owner = THIS_MODULE,
  4062. + .name = "mini_fo",
  4063. + .get_sb = mini_fo_get_sb,
  4064. + .kill_sb = mini_fo_kill_block_super,
  4065. + .fs_flags = 0,
  4066. +};
  4067. +
  4068. +
  4069. +#else
  4070. +static DECLARE_FSTYPE(mini_fo_fs_type, "mini_fo", mini_fo_read_super, 0);
  4071. +#endif
  4072. +
  4073. +static int __init init_mini_fo_fs(void)
  4074. +{
  4075. + printk("Registering mini_fo version $Id$\n");
  4076. + return register_filesystem(&mini_fo_fs_type);
  4077. +}
  4078. +static void __exit exit_mini_fo_fs(void)
  4079. +{
  4080. + printk("Unregistering mini_fo version $Id$\n");
  4081. + unregister_filesystem(&mini_fo_fs_type);
  4082. +}
  4083. +
  4084. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  4085. +EXPORT_NO_SYMBOLS;
  4086. +#endif
  4087. +
  4088. +MODULE_AUTHOR("Erez Zadok <[email protected]>");
  4089. +MODULE_DESCRIPTION("FiST-generated mini_fo filesystem");
  4090. +MODULE_LICENSE("GPL");
  4091. +
  4092. +/* MODULE_PARM(fist_debug_var, "i"); */
  4093. +/* MODULE_PARM_DESC(fist_debug_var, "Debug level"); */
  4094. +
  4095. +module_init(init_mini_fo_fs)
  4096. +module_exit(exit_mini_fo_fs)
  4097. --- /dev/null
  4098. +++ b/fs/mini_fo/Makefile
  4099. @@ -0,0 +1,17 @@
  4100. +#
  4101. +# Makefile for mini_fo 2.4 and 2.6 Linux kernels
  4102. +#
  4103. +# Copyright (C) 2004, 2005 Markus Klotzbuecher <[email protected]>
  4104. +#
  4105. +# This program is free software; you can redistribute it and/or
  4106. +# modify it under the terms of the GNU General Public License
  4107. +# as published by the Free Software Foundation; either version
  4108. +# 2 of the License, or (at your option) any later version.
  4109. +#
  4110. +
  4111. +obj-$(CONFIG_MINI_FO) := mini_fo.o
  4112. +mini_fo-objs := meta.o dentry.o file.o inode.o main.o super.o state.o aux.o
  4113. +
  4114. +# dependencies
  4115. +${mini_fo-objs}: mini_fo.h fist.h
  4116. +
  4117. --- /dev/null
  4118. +++ b/fs/mini_fo/meta.c
  4119. @@ -0,0 +1,1000 @@
  4120. +/*
  4121. + * Copyright (C) 2004, 2005 Markus Klotzbuecher <[email protected]>
  4122. + *
  4123. + * This program is free software; you can redistribute it and/or
  4124. + * modify it under the terms of the GNU General Public License
  4125. + * as published by the Free Software Foundation; either version
  4126. + * 2 of the License, or (at your option) any later version.
  4127. + */
  4128. +
  4129. +#ifdef HAVE_CONFIG_H
  4130. +# include <config.h>
  4131. +#endif /* HAVE_CONFIG_H */
  4132. +#include "fist.h"
  4133. +#include "mini_fo.h"
  4134. +
  4135. +int meta_build_lists(dentry_t *dentry)
  4136. +{
  4137. + struct mini_fo_inode_info *inode_info;
  4138. +
  4139. + dentry_t *meta_dentry = 0;
  4140. + file_t *meta_file = 0;
  4141. + mm_segment_t old_fs;
  4142. + void *buf;
  4143. +
  4144. + int bytes, len;
  4145. + struct vfsmount *meta_mnt;
  4146. + char *entry;
  4147. +
  4148. + inode_info = itopd(dentry->d_inode);
  4149. + if(!(inode_info->deleted_list_size == -1 &&
  4150. + inode_info->renamed_list_size == -1)) {
  4151. + printk(KERN_CRIT "mini_fo: meta_build_lists: \
  4152. + Error, list(s) not virgin.\n");
  4153. + return -1;
  4154. + }
  4155. +
  4156. + /* init our meta lists */
  4157. + INIT_LIST_HEAD(&inode_info->deleted_list);
  4158. + inode_info->deleted_list_size = 0;
  4159. +
  4160. + INIT_LIST_HEAD(&inode_info->renamed_list);
  4161. + inode_info->renamed_list_size = 0;
  4162. +
  4163. + /* might there be a META-file? */
  4164. + if(dtohd2(dentry) && dtohd2(dentry)->d_inode) {
  4165. + meta_dentry = lookup_one_len(META_FILENAME,
  4166. + dtohd2(dentry),
  4167. + strlen(META_FILENAME));
  4168. + if(!meta_dentry->d_inode) {
  4169. + dput(meta_dentry);
  4170. + goto out_ok;
  4171. + }
  4172. + /* $%& err, is this correct? */
  4173. + meta_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
  4174. + mntget(meta_mnt);
  4175. +
  4176. +
  4177. + /* open META-file for reading */
  4178. + meta_file = dentry_open(meta_dentry, meta_mnt, 0x0);
  4179. + if(!meta_file || IS_ERR(meta_file)) {
  4180. + printk(KERN_CRIT "mini_fo: meta_build_lists: \
  4181. + ERROR opening META file.\n");
  4182. + goto out_err;
  4183. + }
  4184. +
  4185. + /* check if fs supports reading */
  4186. + if(!meta_file->f_op->read) {
  4187. + printk(KERN_CRIT "mini_fo: meta_build_lists: \
  4188. + ERROR, fs does not support reading.\n");
  4189. + goto out_err_close;
  4190. + }
  4191. +
  4192. + /* allocate a page for transfering the data */
  4193. + buf = (void *) __get_free_page(GFP_KERNEL);
  4194. + if(!buf) {
  4195. + printk(KERN_CRIT "mini_fo: meta_build_lists: \
  4196. + ERROR, out of mem.\n");
  4197. + goto out_err_close;
  4198. + }
  4199. + meta_file->f_pos = 0;
  4200. + old_fs = get_fs();
  4201. + set_fs(KERNEL_DS);
  4202. + do {
  4203. + char *c;
  4204. + bytes = meta_file->f_op->read(meta_file, buf, PAGE_SIZE, &meta_file->f_pos);
  4205. + if(bytes == PAGE_SIZE) {
  4206. + /* trim a cut off filename and adjust f_pos to get it next time */
  4207. + for(c = (char*) buf+PAGE_SIZE;
  4208. + *c != '\n';
  4209. + c--, bytes--, meta_file->f_pos--);
  4210. + }
  4211. + entry = (char *) buf;
  4212. + while(entry < (char *) buf+bytes) {
  4213. +
  4214. + char *old_path;
  4215. + char *dir_name;
  4216. + int old_len, new_len;
  4217. +
  4218. + /* len without '\n'*/
  4219. + len = (int) (strchr(entry, '\n') - entry);
  4220. + switch (*entry) {
  4221. + case 'D':
  4222. + /* format: "D filename" */
  4223. + meta_list_add_d_entry(dentry,
  4224. + entry+2,
  4225. + len-2);
  4226. + break;
  4227. + case 'R':
  4228. + /* format: "R path/xy/dir newDir" */
  4229. + old_path = entry+2;
  4230. + dir_name = strchr(old_path, ' ') + 1;
  4231. + old_len = dir_name - old_path - 1;
  4232. + new_len = ((int) entry) + len - ((int ) dir_name);
  4233. + meta_list_add_r_entry(dentry,
  4234. + old_path,
  4235. + old_len,
  4236. + dir_name,
  4237. + new_len);
  4238. + break;
  4239. + default:
  4240. + /* unknown entry type detected */
  4241. + break;
  4242. + }
  4243. + entry += len+1;
  4244. + }
  4245. +
  4246. + } while(meta_file->f_pos < meta_dentry->d_inode->i_size);
  4247. +
  4248. + free_page((unsigned long) buf);
  4249. + set_fs(old_fs);
  4250. + fput(meta_file);
  4251. + }
  4252. + goto out_ok;
  4253. +
  4254. + out_err_close:
  4255. + fput(meta_file);
  4256. + out_err:
  4257. + mntput(meta_mnt);
  4258. + dput(meta_dentry);
  4259. + return -1;
  4260. + out_ok:
  4261. + return 1; /* check this!!! inode_info->wol_size; */
  4262. +}
  4263. +
  4264. +/* cleanups up all lists and free's the mem by dentry */
  4265. +int meta_put_lists(dentry_t *dentry)
  4266. +{
  4267. + if(!dentry || !dentry->d_inode) {
  4268. + printk("mini_fo: meta_put_lists: invalid dentry passed.\n");
  4269. + return -1;
  4270. + }
  4271. + return __meta_put_lists(dentry->d_inode);
  4272. +}
  4273. +
  4274. +/* cleanups up all lists and free's the mem by inode */
  4275. +int __meta_put_lists(inode_t *inode)
  4276. +{
  4277. + int err = 0;
  4278. + if(!inode || !itopd(inode)) {
  4279. + printk("mini_fo: __meta_put_lists: invalid inode passed.\n");
  4280. + return -1;
  4281. + }
  4282. + err = __meta_put_d_list(inode);
  4283. + err |= __meta_put_r_list(inode);
  4284. + return err;
  4285. +}
  4286. +
  4287. +int meta_sync_lists(dentry_t *dentry)
  4288. +{
  4289. + int err = 0;
  4290. + if(!dentry || !dentry->d_inode) {
  4291. + printk("mini_fo: meta_sync_lists: \
  4292. + invalid dentry passed.\n");
  4293. + return -1;
  4294. + }
  4295. + err = meta_sync_d_list(dentry, 0);
  4296. + err |= meta_sync_r_list(dentry, 1);
  4297. + return err;
  4298. +}
  4299. +
  4300. +
  4301. +/* remove all D entries from the renamed list and free the mem */
  4302. +int __meta_put_d_list(inode_t *inode)
  4303. +{
  4304. + struct list_head *tmp;
  4305. + struct deleted_entry *del_entry;
  4306. + struct mini_fo_inode_info *inode_info;
  4307. +
  4308. + if(!inode || !itopd(inode)) {
  4309. + printk(KERN_CRIT "mini_fo: __meta_put_d_list: \
  4310. + invalid inode passed.\n");
  4311. + return -1;
  4312. + }
  4313. + inode_info = itopd(inode);
  4314. +
  4315. + /* nuke the DELETED-list */
  4316. + if(inode_info->deleted_list_size <= 0)
  4317. + return 0;
  4318. +
  4319. + while(!list_empty(&inode_info->deleted_list)) {
  4320. + tmp = inode_info->deleted_list.next;
  4321. + list_del(tmp);
  4322. + del_entry = list_entry(tmp, struct deleted_entry, list);
  4323. + kfree(del_entry->name);
  4324. + kfree(del_entry);
  4325. + }
  4326. + inode_info->deleted_list_size = 0;
  4327. +
  4328. + return 0;
  4329. +}
  4330. +
  4331. +/* remove all R entries from the renamed list and free the mem */
  4332. +int __meta_put_r_list(inode_t *inode)
  4333. +{
  4334. + struct list_head *tmp;
  4335. + struct renamed_entry *ren_entry;
  4336. + struct mini_fo_inode_info *inode_info;
  4337. +
  4338. + if(!inode || !itopd(inode)) {
  4339. + printk(KERN_CRIT "mini_fo: meta_put_r_list: invalid inode.\n");
  4340. + return -1;
  4341. + }
  4342. + inode_info = itopd(inode);
  4343. +
  4344. + /* nuke the RENAMED-list */
  4345. + if(inode_info->renamed_list_size <= 0)
  4346. + return 0;
  4347. +
  4348. + while(!list_empty(&inode_info->renamed_list)) {
  4349. + tmp = inode_info->renamed_list.next;
  4350. + list_del(tmp);
  4351. + ren_entry = list_entry(tmp, struct renamed_entry, list);
  4352. + kfree(ren_entry->new_name);
  4353. + kfree(ren_entry->old_name);
  4354. + kfree(ren_entry);
  4355. + }
  4356. + inode_info->renamed_list_size = 0;
  4357. +
  4358. + return 0;
  4359. +}
  4360. +
  4361. +int meta_add_d_entry(dentry_t *dentry, const char *name, int len)
  4362. +{
  4363. + int err = 0;
  4364. + err = meta_list_add_d_entry(dentry, name, len);
  4365. + err |= meta_write_d_entry(dentry,name,len);
  4366. + return err;
  4367. +}
  4368. +
  4369. +/* add a D entry to the deleted list */
  4370. +int meta_list_add_d_entry(dentry_t *dentry, const char *name, int len)
  4371. +{
  4372. + struct deleted_entry *del_entry;
  4373. + struct mini_fo_inode_info *inode_info;
  4374. +
  4375. + if(!dentry || !dentry->d_inode) {
  4376. + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
  4377. + invalid dentry passed.\n");
  4378. + return -1;
  4379. + }
  4380. + inode_info = itopd(dentry->d_inode);
  4381. +
  4382. + if(inode_info->deleted_list_size < 0)
  4383. + return -1;
  4384. +
  4385. + del_entry = (struct deleted_entry *)
  4386. + kmalloc(sizeof(struct deleted_entry), GFP_KERNEL);
  4387. + del_entry->name = (char*) kmalloc(len, GFP_KERNEL);
  4388. + if(!del_entry || !del_entry->name) {
  4389. + printk(KERN_CRIT "mini_fo: meta_list_add_d_entry: \
  4390. + out of mem.\n");
  4391. + kfree(del_entry->name);
  4392. + kfree(del_entry);
  4393. + return -ENOMEM;
  4394. + }
  4395. +
  4396. + strncpy(del_entry->name, name, len);
  4397. + del_entry->len = len;
  4398. +
  4399. + list_add(&del_entry->list, &inode_info->deleted_list);
  4400. + inode_info->deleted_list_size++;
  4401. + return 0;
  4402. +}
  4403. +
  4404. +int meta_add_r_entry(dentry_t *dentry,
  4405. + const char *old_name, int old_len,
  4406. + const char *new_name, int new_len)
  4407. +{
  4408. + int err = 0;
  4409. + err = meta_list_add_r_entry(dentry,
  4410. + old_name, old_len,
  4411. + new_name, new_len);
  4412. + err |= meta_write_r_entry(dentry,
  4413. + old_name, old_len,
  4414. + new_name, new_len);
  4415. + return err;
  4416. +}
  4417. +
  4418. +/* add a R entry to the renamed list */
  4419. +int meta_list_add_r_entry(dentry_t *dentry,
  4420. + const char *old_name, int old_len,
  4421. + const char *new_name, int new_len)
  4422. +{
  4423. + struct renamed_entry *ren_entry;
  4424. + struct mini_fo_inode_info *inode_info;
  4425. +
  4426. + if(!dentry || !dentry->d_inode) {
  4427. + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
  4428. + invalid dentry passed.\n");
  4429. + return -1;
  4430. + }
  4431. + inode_info = itopd(dentry->d_inode);
  4432. +
  4433. + if(inode_info->renamed_list_size < 0)
  4434. + return -1;
  4435. +
  4436. + ren_entry = (struct renamed_entry *)
  4437. + kmalloc(sizeof(struct renamed_entry), GFP_KERNEL);
  4438. + ren_entry->old_name = (char*) kmalloc(old_len, GFP_KERNEL);
  4439. + ren_entry->new_name = (char*) kmalloc(new_len, GFP_KERNEL);
  4440. +
  4441. + if(!ren_entry || !ren_entry->old_name || !ren_entry->new_name) {
  4442. + printk(KERN_CRIT "mini_fo: meta_list_add_r_entry: \
  4443. + out of mem.\n");
  4444. + kfree(ren_entry->new_name);
  4445. + kfree(ren_entry->old_name);
  4446. + kfree(ren_entry);
  4447. + return -ENOMEM;
  4448. + }
  4449. +
  4450. + strncpy(ren_entry->old_name, old_name, old_len);
  4451. + ren_entry->old_len = old_len;
  4452. + strncpy(ren_entry->new_name, new_name, new_len);
  4453. + ren_entry->new_len = new_len;
  4454. +
  4455. + list_add(&ren_entry->list, &inode_info->renamed_list);
  4456. + inode_info->renamed_list_size++;
  4457. + return 0;
  4458. +}
  4459. +
  4460. +
  4461. +int meta_remove_r_entry(dentry_t *dentry, const char *name, int len)
  4462. +{
  4463. + int err = 0;
  4464. + if(!dentry || !dentry->d_inode) {
  4465. + printk(KERN_CRIT
  4466. + "mini_fo: meta_remove_r_entry: \
  4467. + invalid dentry passed.\n");
  4468. + return -1;
  4469. + }
  4470. +
  4471. + err = meta_list_remove_r_entry(dentry, name, len);
  4472. + err |= meta_sync_lists(dentry);
  4473. + return err;
  4474. +}
  4475. +
  4476. +int meta_list_remove_r_entry(dentry_t *dentry, const char *name, int len)
  4477. +{
  4478. + if(!dentry || !dentry->d_inode) {
  4479. + printk(KERN_CRIT
  4480. + "mini_fo: meta_list_remove_r_entry: \
  4481. + invalid dentry passed.\n");
  4482. + return -1;
  4483. + }
  4484. + return __meta_list_remove_r_entry(dentry->d_inode, name, len);
  4485. +}
  4486. +
  4487. +int __meta_list_remove_r_entry(inode_t *inode, const char *name, int len)
  4488. +{
  4489. + struct list_head *tmp;
  4490. + struct renamed_entry *ren_entry;
  4491. + struct mini_fo_inode_info *inode_info;
  4492. +
  4493. + if(!inode || !itopd(inode))
  4494. + printk(KERN_CRIT
  4495. + "mini_fo: __meta_list_remove_r_entry: \
  4496. + invalid inode passed.\n");
  4497. + inode_info = itopd(inode);
  4498. +
  4499. + if(inode_info->renamed_list_size < 0)
  4500. + return -1;
  4501. + if(inode_info->renamed_list_size == 0)
  4502. + return 1;
  4503. +
  4504. + list_for_each(tmp, &inode_info->renamed_list) {
  4505. + ren_entry = list_entry(tmp, struct renamed_entry, list);
  4506. + if(ren_entry->new_len != len)
  4507. + continue;
  4508. +
  4509. + if(!strncmp(ren_entry->new_name, name, len)) {
  4510. + list_del(tmp);
  4511. + kfree(ren_entry->new_name);
  4512. + kfree(ren_entry->old_name);
  4513. + kfree(ren_entry);
  4514. + inode_info->renamed_list_size--;
  4515. + return 0;
  4516. + }
  4517. + }
  4518. + return 1;
  4519. +}
  4520. +
  4521. +
  4522. +/* append a single D entry to the meta file */
  4523. +int meta_write_d_entry(dentry_t *dentry, const char *name, int len)
  4524. +{
  4525. + dentry_t *meta_dentry = 0;
  4526. + file_t *meta_file = 0;
  4527. + mm_segment_t old_fs;
  4528. +
  4529. + int bytes, err;
  4530. + struct vfsmount *meta_mnt = 0;
  4531. + char *buf;
  4532. +
  4533. + err = 0;
  4534. +
  4535. + if(itopd(dentry->d_inode)->deleted_list_size < 0) {
  4536. + err = -1;
  4537. + goto out;
  4538. + }
  4539. +
  4540. + if(dtopd(dentry)->state == UNMODIFIED) {
  4541. + err = build_sto_structure(dentry->d_parent, dentry);
  4542. + if(err) {
  4543. + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
  4544. + build_sto_structure failed.\n");
  4545. + goto out;
  4546. + }
  4547. + }
  4548. + meta_dentry = lookup_one_len(META_FILENAME,
  4549. + dtohd2(dentry), strlen (META_FILENAME));
  4550. +
  4551. + /* We need to create a META-file */
  4552. + if(!meta_dentry->d_inode) {
  4553. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  4554. + vfs_create(dtohd2(dentry)->d_inode,
  4555. + meta_dentry,
  4556. + S_IRUSR | S_IWUSR,
  4557. + NULL);
  4558. +#else
  4559. + vfs_create(dtohd2(dentry)->d_inode,
  4560. + meta_dentry,
  4561. + S_IRUSR | S_IWUSR);
  4562. +#endif
  4563. + }
  4564. + /* open META-file for writing */
  4565. + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
  4566. + if(!meta_file || IS_ERR(meta_file)) {
  4567. + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
  4568. + ERROR opening meta file.\n");
  4569. + mntput(meta_mnt); /* $%& is this necessary? */
  4570. + dput(meta_dentry);
  4571. + err = -1;
  4572. + goto out;
  4573. + }
  4574. +
  4575. + /* check if fs supports writing */
  4576. + if(!meta_file->f_op->write) {
  4577. + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
  4578. + ERROR, fs does not support writing.\n");
  4579. + goto out_err_close;
  4580. + }
  4581. +
  4582. + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
  4583. + old_fs = get_fs();
  4584. + set_fs(KERNEL_DS);
  4585. +
  4586. + /* size: len for name, 1 for \n and 2 for "D " */
  4587. + buf = (char *) kmalloc(len+3, GFP_KERNEL);
  4588. + if (!buf) {
  4589. + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
  4590. + out of mem.\n");
  4591. + return -ENOMEM;
  4592. + }
  4593. +
  4594. + buf[0] = 'D';
  4595. + buf[1] = ' ';
  4596. + strncpy(buf+2, name, len);
  4597. + buf[len+2] = '\n';
  4598. + bytes = meta_file->f_op->write(meta_file, buf, len+3,
  4599. + &meta_file->f_pos);
  4600. + if(bytes != len+3) {
  4601. + printk(KERN_CRIT "mini_fo: meta_write_d_entry: \
  4602. + ERROR writing.\n");
  4603. + err = -1;
  4604. + }
  4605. + kfree(buf);
  4606. + set_fs(old_fs);
  4607. +
  4608. + out_err_close:
  4609. + fput(meta_file);
  4610. + out:
  4611. + return err;
  4612. +}
  4613. +
  4614. +/* append a single R entry to the meta file */
  4615. +int meta_write_r_entry(dentry_t *dentry,
  4616. + const char *old_name, int old_len,
  4617. + const char *new_name, int new_len)
  4618. +{
  4619. + dentry_t *meta_dentry = 0;
  4620. + file_t *meta_file = 0;
  4621. + mm_segment_t old_fs;
  4622. +
  4623. + int bytes, err, buf_len;
  4624. + struct vfsmount *meta_mnt = 0;
  4625. + char *buf;
  4626. +
  4627. +
  4628. + err = 0;
  4629. +
  4630. + if(itopd(dentry->d_inode)->renamed_list_size < 0) {
  4631. + err = -1;
  4632. + goto out;
  4633. + }
  4634. +
  4635. + /* build the storage structure? */
  4636. + if(dtopd(dentry)->state == UNMODIFIED) {
  4637. + err = build_sto_structure(dentry->d_parent, dentry);
  4638. + if(err) {
  4639. + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
  4640. + build_sto_structure failed.\n");
  4641. + goto out;
  4642. + }
  4643. + }
  4644. + meta_dentry = lookup_one_len(META_FILENAME,
  4645. + dtohd2(dentry),
  4646. + strlen (META_FILENAME));
  4647. + if(!meta_dentry->d_inode) {
  4648. + /* We need to create a META-file */
  4649. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  4650. + vfs_create(dtohd2(dentry)->d_inode,
  4651. + meta_dentry, S_IRUSR | S_IWUSR, NULL);
  4652. +#else
  4653. + vfs_create(dtohd2(dentry)->d_inode,
  4654. + meta_dentry, S_IRUSR | S_IWUSR);
  4655. +#endif
  4656. + }
  4657. + /* open META-file for writing */
  4658. + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
  4659. + if(!meta_file || IS_ERR(meta_file)) {
  4660. + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
  4661. + ERROR opening meta file.\n");
  4662. + mntput(meta_mnt);
  4663. + dput(meta_dentry);
  4664. + err = -1;
  4665. + goto out;
  4666. + }
  4667. +
  4668. + /* check if fs supports writing */
  4669. + if(!meta_file->f_op->write) {
  4670. + printk(KERN_CRIT "mini_fo: meta_write_r_entry: \
  4671. + ERROR, fs does not support writing.\n");
  4672. + goto out_err_close;
  4673. + }
  4674. +
  4675. + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
  4676. + old_fs = get_fs();
  4677. + set_fs(KERNEL_DS);
  4678. +
  4679. + /* size: 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
  4680. + buf_len = old_len + new_len + 4;
  4681. + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
  4682. + if (!buf) {
  4683. + printk(KERN_CRIT "mini_fo: meta_write_r_entry: out of mem.\n");
  4684. + return -ENOMEM;
  4685. + }
  4686. +
  4687. + buf[0] = 'R';
  4688. + buf[1] = ' ';
  4689. + strncpy(buf + 2, old_name, old_len);
  4690. + buf[old_len + 2] = ' ';
  4691. + strncpy(buf + old_len + 3, new_name, new_len);
  4692. + buf[buf_len -1] = '\n';
  4693. + bytes = meta_file->f_op->write(meta_file, buf, buf_len, &meta_file->f_pos);
  4694. + if(bytes != buf_len) {
  4695. + printk(KERN_CRIT "mini_fo: meta_write_r_entry: ERROR writing.\n");
  4696. + err = -1;
  4697. + }
  4698. +
  4699. + kfree(buf);
  4700. + set_fs(old_fs);
  4701. +
  4702. + out_err_close:
  4703. + fput(meta_file);
  4704. + out:
  4705. + return err;
  4706. +}
  4707. +
  4708. +/* sync D list to disk, append data if app_flag is 1 */
  4709. +/* check the meta_mnt, which seems not to be used (properly) */
  4710. +
  4711. +int meta_sync_d_list(dentry_t *dentry, int app_flag)
  4712. +{
  4713. + dentry_t *meta_dentry;
  4714. + file_t *meta_file;
  4715. + mm_segment_t old_fs;
  4716. +
  4717. + int bytes, err;
  4718. + struct vfsmount *meta_mnt;
  4719. + char *buf;
  4720. +
  4721. + struct list_head *tmp;
  4722. + struct deleted_entry *del_entry;
  4723. + struct mini_fo_inode_info *inode_info;
  4724. +
  4725. + err = 0;
  4726. + meta_file=0;
  4727. + meta_mnt=0;
  4728. +
  4729. + if(!dentry || !dentry->d_inode) {
  4730. + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
  4731. + invalid inode passed.\n");
  4732. + err = -1;
  4733. + goto out;
  4734. + }
  4735. + inode_info = itopd(dentry->d_inode);
  4736. +
  4737. + if(inode_info->deleted_list_size < 0) {
  4738. + err = -1;
  4739. + goto out;
  4740. + }
  4741. +
  4742. + /* ok, there is something to sync */
  4743. +
  4744. + /* build the storage structure? */
  4745. + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
  4746. + err = build_sto_structure(dentry->d_parent, dentry);
  4747. + if(err) {
  4748. + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
  4749. + build_sto_structure failed.\n");
  4750. + goto out;
  4751. + }
  4752. + }
  4753. + meta_dentry = lookup_one_len(META_FILENAME,
  4754. + dtohd2(dentry),
  4755. + strlen(META_FILENAME));
  4756. + if(!meta_dentry->d_inode) {
  4757. + /* We need to create a META-file */
  4758. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  4759. + vfs_create(dtohd2(dentry)->d_inode,
  4760. + meta_dentry, S_IRUSR | S_IWUSR, NULL);
  4761. +#else
  4762. + vfs_create(dtohd2(dentry)->d_inode,
  4763. + meta_dentry, S_IRUSR | S_IWUSR);
  4764. +#endif
  4765. + app_flag = 0;
  4766. + }
  4767. + /* need we truncate the meta file? */
  4768. + if(!app_flag) {
  4769. + struct iattr newattrs;
  4770. + newattrs.ia_size = 0;
  4771. + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
  4772. +
  4773. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  4774. + mutex_lock(&meta_dentry->d_inode->i_mutex);
  4775. +#else
  4776. + down(&meta_dentry->d_inode->i_sem);
  4777. +#endif
  4778. + err = notify_change(meta_dentry, &newattrs);
  4779. +
  4780. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  4781. + mutex_unlock(&meta_dentry->d_inode->i_mutex);
  4782. +#else
  4783. + up(&meta_dentry->d_inode->i_sem);
  4784. +#endif
  4785. +
  4786. + if(err || meta_dentry->d_inode->i_size != 0) {
  4787. + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
  4788. + ERROR truncating meta file.\n");
  4789. + goto out_err_close;
  4790. + }
  4791. + }
  4792. +
  4793. + /* open META-file for writing */
  4794. + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
  4795. + if(!meta_file || IS_ERR(meta_file)) {
  4796. + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
  4797. + ERROR opening meta file.\n");
  4798. + /* we don't mntget so we dont't mntput (for now)
  4799. + * mntput(meta_mnt);
  4800. + */
  4801. + dput(meta_dentry);
  4802. + err = -1;
  4803. + goto out;
  4804. + }
  4805. +
  4806. + /* check if fs supports writing */
  4807. + if(!meta_file->f_op->write) {
  4808. + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
  4809. + ERROR, fs does not support writing.\n");
  4810. + goto out_err_close;
  4811. + }
  4812. +
  4813. + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
  4814. + old_fs = get_fs();
  4815. + set_fs(KERNEL_DS);
  4816. +
  4817. + /* here we go... */
  4818. + list_for_each(tmp, &inode_info->deleted_list) {
  4819. + del_entry = list_entry(tmp, struct deleted_entry, list);
  4820. +
  4821. + /* size: len for name, 1 for \n and 2 for "D " */
  4822. + buf = (char *) kmalloc(del_entry->len+3, GFP_KERNEL);
  4823. + if (!buf) {
  4824. + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
  4825. + out of mem.\n");
  4826. + return -ENOMEM;
  4827. + }
  4828. +
  4829. + buf[0] = 'D';
  4830. + buf[1] = ' ';
  4831. + strncpy(buf+2, del_entry->name, del_entry->len);
  4832. + buf[del_entry->len+2] = '\n';
  4833. + bytes = meta_file->f_op->write(meta_file, buf,
  4834. + del_entry->len+3,
  4835. + &meta_file->f_pos);
  4836. + if(bytes != del_entry->len+3) {
  4837. + printk(KERN_CRIT "mini_fo: meta_sync_d_list: \
  4838. + ERROR writing.\n");
  4839. + err |= -1;
  4840. + }
  4841. + kfree(buf);
  4842. + }
  4843. + set_fs(old_fs);
  4844. +
  4845. + out_err_close:
  4846. + fput(meta_file);
  4847. + out:
  4848. + return err;
  4849. +
  4850. +}
  4851. +
  4852. +int meta_sync_r_list(dentry_t *dentry, int app_flag)
  4853. +{
  4854. + dentry_t *meta_dentry;
  4855. + file_t *meta_file;
  4856. + mm_segment_t old_fs;
  4857. +
  4858. + int bytes, err, buf_len;
  4859. + struct vfsmount *meta_mnt;
  4860. + char *buf;
  4861. +
  4862. + struct list_head *tmp;
  4863. + struct renamed_entry *ren_entry;
  4864. + struct mini_fo_inode_info *inode_info;
  4865. +
  4866. + err = 0;
  4867. + meta_file=0;
  4868. + meta_mnt=0;
  4869. +
  4870. + if(!dentry || !dentry->d_inode) {
  4871. + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
  4872. + invalid dentry passed.\n");
  4873. + err = -1;
  4874. + goto out;
  4875. + }
  4876. + inode_info = itopd(dentry->d_inode);
  4877. +
  4878. + if(inode_info->deleted_list_size < 0) {
  4879. + err = -1;
  4880. + goto out;
  4881. + }
  4882. +
  4883. + /* ok, there is something to sync */
  4884. +
  4885. + /* build the storage structure? */
  4886. + if(!dtohd2(dentry) && !itohi2(dentry->d_inode)) {
  4887. + err = build_sto_structure(dentry->d_parent, dentry);
  4888. + if(err) {
  4889. + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
  4890. + build_sto_structure failed.\n");
  4891. + goto out;
  4892. + }
  4893. + }
  4894. + meta_dentry = lookup_one_len(META_FILENAME,
  4895. + dtohd2(dentry),
  4896. + strlen(META_FILENAME));
  4897. + if(!meta_dentry->d_inode) {
  4898. + /* We need to create a META-file */
  4899. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  4900. + vfs_create(dtohd2(dentry)->d_inode,
  4901. + meta_dentry, S_IRUSR | S_IWUSR, NULL);
  4902. +#else
  4903. + vfs_create(dtohd2(dentry)->d_inode,
  4904. + meta_dentry, S_IRUSR | S_IWUSR);
  4905. +#endif
  4906. + app_flag = 0;
  4907. + }
  4908. + /* need we truncate the meta file? */
  4909. + if(!app_flag) {
  4910. + struct iattr newattrs;
  4911. + newattrs.ia_size = 0;
  4912. + newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
  4913. +
  4914. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  4915. + mutex_lock(&meta_dentry->d_inode->i_mutex);
  4916. +#else
  4917. + down(&meta_dentry->d_inode->i_sem);
  4918. +#endif
  4919. + err = notify_change(meta_dentry, &newattrs);
  4920. +
  4921. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  4922. + mutex_unlock(&meta_dentry->d_inode->i_mutex);
  4923. +#else
  4924. + up(&meta_dentry->d_inode->i_sem);
  4925. +#endif
  4926. + if(err || meta_dentry->d_inode->i_size != 0) {
  4927. + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
  4928. + ERROR truncating meta file.\n");
  4929. + goto out_err_close;
  4930. + }
  4931. + }
  4932. +
  4933. + /* open META-file for writing */
  4934. + meta_file = dentry_open(meta_dentry, meta_mnt, 0x1);
  4935. + if(!meta_file || IS_ERR(meta_file)) {
  4936. + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
  4937. + ERROR opening meta file.\n");
  4938. + /* we don't mntget so we dont't mntput (for now)
  4939. + * mntput(meta_mnt);
  4940. + */
  4941. + dput(meta_dentry);
  4942. + err = -1;
  4943. + goto out;
  4944. + }
  4945. +
  4946. + /* check if fs supports writing */
  4947. + if(!meta_file->f_op->write) {
  4948. + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
  4949. + ERROR, fs does not support writing.\n");
  4950. + goto out_err_close;
  4951. + }
  4952. +
  4953. + meta_file->f_pos = meta_dentry->d_inode->i_size; /* append */
  4954. + old_fs = get_fs();
  4955. + set_fs(KERNEL_DS);
  4956. +
  4957. + /* here we go... */
  4958. + list_for_each(tmp, &inode_info->renamed_list) {
  4959. + ren_entry = list_entry(tmp, struct renamed_entry, list);
  4960. + /* size:
  4961. + * 2 for "R ", old_len+new_len for names, 1 blank+1 \n */
  4962. + buf_len = ren_entry->old_len + ren_entry->new_len + 4;
  4963. + buf = (char *) kmalloc(buf_len, GFP_KERNEL);
  4964. + if (!buf) {
  4965. + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
  4966. + out of mem.\n");
  4967. + return -ENOMEM;
  4968. + }
  4969. + buf[0] = 'R';
  4970. + buf[1] = ' ';
  4971. + strncpy(buf + 2, ren_entry->old_name, ren_entry->old_len);
  4972. + buf[ren_entry->old_len + 2] = ' ';
  4973. + strncpy(buf + ren_entry->old_len + 3,
  4974. + ren_entry->new_name, ren_entry->new_len);
  4975. + buf[buf_len - 1] = '\n';
  4976. + bytes = meta_file->f_op->write(meta_file, buf,
  4977. + buf_len, &meta_file->f_pos);
  4978. + if(bytes != buf_len) {
  4979. + printk(KERN_CRIT "mini_fo: meta_sync_r_list: \
  4980. + ERROR writing.\n");
  4981. + err |= -1;
  4982. + }
  4983. + kfree(buf);
  4984. + }
  4985. + set_fs(old_fs);
  4986. +
  4987. + out_err_close:
  4988. + fput(meta_file);
  4989. + out:
  4990. + return err;
  4991. +}
  4992. +
  4993. +int meta_check_d_entry(dentry_t *dentry, const char *name, int len)
  4994. +{
  4995. + if(!dentry || !dentry->d_inode)
  4996. + printk(KERN_CRIT "mini_fo: meta_check_d_dentry: \
  4997. + invalid dentry passed.\n");
  4998. + return __meta_check_d_entry(dentry->d_inode, name, len);
  4999. +}
  5000. +
  5001. +int __meta_check_d_entry(inode_t *inode, const char *name, int len)
  5002. +{
  5003. + struct list_head *tmp;
  5004. + struct deleted_entry *del_entry;
  5005. + struct mini_fo_inode_info *inode_info;
  5006. +
  5007. + if(!inode || !itopd(inode))
  5008. + printk(KERN_CRIT "mini_fo: __meta_check_d_dentry: \
  5009. + invalid inode passed.\n");
  5010. +
  5011. + inode_info = itopd(inode);
  5012. +
  5013. + if(inode_info->deleted_list_size <= 0)
  5014. + return 0;
  5015. +
  5016. + list_for_each(tmp, &inode_info->deleted_list) {
  5017. + del_entry = list_entry(tmp, struct deleted_entry, list);
  5018. + if(del_entry->len != len)
  5019. + continue;
  5020. +
  5021. + if(!strncmp(del_entry->name, name, len))
  5022. + return 1;
  5023. + }
  5024. + return 0;
  5025. +}
  5026. +
  5027. +/*
  5028. + * check if file has been renamed and return path to orig. base dir.
  5029. + * Implements no error return values so far, what of course sucks.
  5030. + * String is null terminated.'
  5031. + */
  5032. +char* meta_check_r_entry(dentry_t *dentry, const char *name, int len)
  5033. +{
  5034. + if(!dentry || !dentry->d_inode) {
  5035. + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
  5036. + invalid dentry passed.\n");
  5037. + return NULL;
  5038. + }
  5039. + return __meta_check_r_entry(dentry->d_inode, name, len);
  5040. +}
  5041. +
  5042. +char* __meta_check_r_entry(inode_t *inode, const char *name, int len)
  5043. +{
  5044. + struct list_head *tmp;
  5045. + struct renamed_entry *ren_entry;
  5046. + struct mini_fo_inode_info *inode_info;
  5047. + char *old_path;
  5048. +
  5049. + if(!inode || !itopd(inode)) {
  5050. + printk(KERN_CRIT "mini_fo: meta_check_r_dentry: \
  5051. + invalid inode passed.\n");
  5052. + return NULL;
  5053. + }
  5054. + inode_info = itopd(inode);
  5055. +
  5056. + if(inode_info->renamed_list_size <= 0)
  5057. + return NULL;
  5058. +
  5059. + list_for_each(tmp, &inode_info->renamed_list) {
  5060. + ren_entry = list_entry(tmp, struct renamed_entry, list);
  5061. + if(ren_entry->new_len != len)
  5062. + continue;
  5063. +
  5064. + if(!strncmp(ren_entry->new_name, name, len)) {
  5065. + old_path = (char *)
  5066. + kmalloc(ren_entry->old_len+1, GFP_KERNEL);
  5067. + strncpy(old_path,
  5068. + ren_entry->old_name,
  5069. + ren_entry->old_len);
  5070. + old_path[ren_entry->old_len]='\0';
  5071. + return old_path;
  5072. + }
  5073. + }
  5074. + return NULL;
  5075. +}
  5076. +
  5077. +/*
  5078. + * This version only checks if entry exists and return:
  5079. + * 1 if exists,
  5080. + * 0 if not,
  5081. + * -1 if error.
  5082. + */
  5083. +int meta_is_r_entry(dentry_t *dentry, const char *name, int len)
  5084. +{
  5085. + if(!dentry || !dentry->d_inode) {
  5086. + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
  5087. + invalid dentry passed.\n");
  5088. + return -1;
  5089. + }
  5090. + return __meta_is_r_entry(dentry->d_inode, name, len);
  5091. +}
  5092. +
  5093. +int __meta_is_r_entry(inode_t *inode, const char *name, int len)
  5094. +{
  5095. + struct list_head *tmp;
  5096. + struct renamed_entry *ren_entry;
  5097. + struct mini_fo_inode_info *inode_info;
  5098. +
  5099. + if(!inode || !itopd(inode)) {
  5100. + printk(KERN_CRIT "mini_fo: meta_check_r_dentry [2]: \
  5101. + invalid inode passed.\n");
  5102. + return -1;
  5103. + }
  5104. + inode_info = itopd(inode);
  5105. +
  5106. + if(inode_info->renamed_list_size <= 0)
  5107. + return -1;
  5108. +
  5109. + list_for_each(tmp, &inode_info->renamed_list) {
  5110. + ren_entry = list_entry(tmp, struct renamed_entry, list);
  5111. + if(ren_entry->new_len != len)
  5112. + continue;
  5113. +
  5114. + if(!strncmp(ren_entry->new_name, name, len))
  5115. + return 1;
  5116. + }
  5117. + return 0;
  5118. +}
  5119. +
  5120. --- /dev/null
  5121. +++ b/fs/mini_fo/mini_fo.h
  5122. @@ -0,0 +1,510 @@
  5123. +/*
  5124. + * Copyright (c) 1997-2003 Erez Zadok
  5125. + * Copyright (c) 2001-2003 Stony Brook University
  5126. + *
  5127. + * For specific licensing information, see the COPYING file distributed with
  5128. + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
  5129. + *
  5130. + * This Copyright notice must be kept intact and distributed with all
  5131. + * fistgen sources INCLUDING sources generated by fistgen.
  5132. + */
  5133. +/*
  5134. + * Copyright (C) 2004, 2005 Markus Klotzbuecher <[email protected]>
  5135. + *
  5136. + * This program is free software; you can redistribute it and/or
  5137. + * modify it under the terms of the GNU General Public License
  5138. + * as published by the Free Software Foundation; either version
  5139. + * 2 of the License, or (at your option) any later version.
  5140. + */
  5141. +
  5142. +/*
  5143. + * $Id$
  5144. + */
  5145. +
  5146. +#ifndef __MINI_FO_H_
  5147. +#define __MINI_FO_H_
  5148. +
  5149. +#ifdef __KERNEL__
  5150. +
  5151. +/* META stuff */
  5152. +#define META_FILENAME "META_dAfFgHE39ktF3HD2sr"
  5153. +
  5154. +/* use xattrs? */
  5155. +#define XATTR
  5156. +
  5157. +/* File attributes that when changed, result in a file beeing copied to storage */
  5158. +#define COPY_FLAGS ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_SIZE
  5159. +
  5160. +/*
  5161. + * mini_fo filestates
  5162. + */
  5163. +#define MODIFIED 1
  5164. +#define UNMODIFIED 2
  5165. +#define CREATED 3
  5166. +#define DEL_REWRITTEN 4
  5167. +#define DELETED 5
  5168. +#define NON_EXISTANT 6
  5169. +
  5170. +/* fist file systems superblock magic */
  5171. +# define MINI_FO_SUPER_MAGIC 0xf15f
  5172. +
  5173. +/*
  5174. + * STRUCTURES:
  5175. + */
  5176. +
  5177. +/* mini_fo inode data in memory */
  5178. +struct mini_fo_inode_info {
  5179. + inode_t *wii_inode;
  5180. + inode_t *wii_inode2; /* pointer to storage inode */
  5181. +
  5182. + /* META-data lists */
  5183. + /* deleted list, ex wol */
  5184. + struct list_head deleted_list;
  5185. + int deleted_list_size;
  5186. +
  5187. + /* renamed list */
  5188. + struct list_head renamed_list;
  5189. + int renamed_list_size;
  5190. +
  5191. + /* add other lists here ... */
  5192. +};
  5193. +
  5194. +/* mini_fo dentry data in memory */
  5195. +struct mini_fo_dentry_info {
  5196. + dentry_t *wdi_dentry;
  5197. + dentry_t *wdi_dentry2; /* pointer to storage dentry */
  5198. + unsigned int state; /* state of the mini_fo dentry */
  5199. +};
  5200. +
  5201. +
  5202. +/* mini_fo super-block data in memory */
  5203. +struct mini_fo_sb_info {
  5204. + super_block_t *wsi_sb, *wsi_sb2; /* mk: might point to the same sb */
  5205. + struct vfsmount *hidden_mnt, *hidden_mnt2;
  5206. + dentry_t *base_dir_dentry;
  5207. + dentry_t *storage_dir_dentry;
  5208. + ;
  5209. +};
  5210. +
  5211. +/* readdir_data, readdir helper struct */
  5212. +struct readdir_data {
  5213. + struct list_head ndl_list; /* linked list head ptr */
  5214. + int ndl_size; /* list size */
  5215. + int sto_done; /* flag to show that the storage dir entries have
  5216. + * all been read an now follow base entries */
  5217. +};
  5218. +
  5219. +/* file private data. */
  5220. +struct mini_fo_file_info {
  5221. + struct file *wfi_file;
  5222. + struct file *wfi_file2; /* pointer to storage file */
  5223. + struct readdir_data rd;
  5224. +};
  5225. +
  5226. +/* struct ndl_entry */
  5227. +struct ndl_entry {
  5228. + struct list_head list;
  5229. + char *name;
  5230. + int len;
  5231. +};
  5232. +
  5233. +/********************************
  5234. + * META-data structures
  5235. + ********************************/
  5236. +
  5237. +/* deleted entry */
  5238. +struct deleted_entry {
  5239. + struct list_head list;
  5240. + char *name;
  5241. + int len;
  5242. +};
  5243. +
  5244. +/* renamed entry */
  5245. +struct renamed_entry {
  5246. + struct list_head list;
  5247. + char *old_name; /* old directory with full path */
  5248. + int old_len; /* length of above string */
  5249. + char *new_name; /* new directory name */
  5250. + int new_len; /* length of above string */
  5251. +};
  5252. +
  5253. +/* attr_change entry */
  5254. +struct attr_change_entry {
  5255. + struct list_head list;
  5256. + char *name;
  5257. + int len;
  5258. +};
  5259. +
  5260. +/* link entry */
  5261. +struct link_entry {
  5262. + struct list_head list;
  5263. + int links_moved;
  5264. + int inum_base;
  5265. + int inum_sto;
  5266. + char *weird_name;
  5267. + int weird_name_len;
  5268. +};
  5269. +
  5270. +
  5271. +/* Some other stuff required for mini_fo_filldir64, copied from
  5272. + * fs/readdir.c
  5273. + */
  5274. +
  5275. +#define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
  5276. +#define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
  5277. +
  5278. +
  5279. +struct linux_dirent64 {
  5280. + u64 d_ino;
  5281. + s64 d_off;
  5282. + unsigned short d_reclen;
  5283. + unsigned char d_type;
  5284. + char d_name[0];
  5285. +};
  5286. +
  5287. +
  5288. +struct getdents_callback64 {
  5289. + struct linux_dirent64 * current_dir;
  5290. + struct linux_dirent64 * previous;
  5291. + int count;
  5292. + int error;
  5293. +};
  5294. +
  5295. +struct linux_dirent {
  5296. + unsigned long d_ino;
  5297. + unsigned long d_off;
  5298. + unsigned short d_reclen;
  5299. + char d_name[1];
  5300. +};
  5301. +
  5302. +struct getdents_callback {
  5303. + struct linux_dirent * current_dir;
  5304. + struct linux_dirent * previous;
  5305. + int count;
  5306. + int error;
  5307. +};
  5308. +
  5309. +
  5310. +/*
  5311. + * MACROS:
  5312. + */
  5313. +
  5314. +/* file TO private_data */
  5315. +# define ftopd(file) ((struct mini_fo_file_info *)((file)->private_data))
  5316. +# define __ftopd(file) ((file)->private_data)
  5317. +/* file TO hidden_file */
  5318. +# define ftohf(file) ((ftopd(file))->wfi_file)
  5319. +# define ftohf2(file) ((ftopd(file))->wfi_file2)
  5320. +
  5321. +/* inode TO private_data */
  5322. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
  5323. +# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->i_private)
  5324. +# define __itopd(ino) ((ino)->i_private)
  5325. +#else
  5326. +# define itopd(ino) ((struct mini_fo_inode_info *)(ino)->u.generic_ip)
  5327. +# define __itopd(ino) ((ino)->u.generic_ip)
  5328. +#endif
  5329. +/* inode TO hidden_inode */
  5330. +# define itohi(ino) (itopd(ino)->wii_inode)
  5331. +# define itohi2(ino) (itopd(ino)->wii_inode2)
  5332. +
  5333. +/* superblock TO private_data */
  5334. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  5335. +# define stopd(super) ((struct mini_fo_sb_info *)(super)->s_fs_info)
  5336. +# define __stopd(super) ((super)->s_fs_info)
  5337. +#else
  5338. +# define stopd(super) ((struct mini_fo_sb_info *)(super)->u.generic_sbp)
  5339. +# define __stopd(super) ((super)->u.generic_sbp)
  5340. +#endif
  5341. +
  5342. +/* unused? # define vfs2priv stopd */
  5343. +/* superblock TO hidden_superblock */
  5344. +
  5345. +# define stohs(super) (stopd(super)->wsi_sb)
  5346. +# define stohs2(super) (stopd(super)->wsi_sb2)
  5347. +
  5348. +/* dentry TO private_data */
  5349. +# define dtopd(dentry) ((struct mini_fo_dentry_info *)(dentry)->d_fsdata)
  5350. +# define __dtopd(dentry) ((dentry)->d_fsdata)
  5351. +/* dentry TO hidden_dentry */
  5352. +# define dtohd(dent) (dtopd(dent)->wdi_dentry)
  5353. +# define dtohd2(dent) (dtopd(dent)->wdi_dentry2)
  5354. +
  5355. +/* dentry to state */
  5356. +# define dtost(dent) (dtopd(dent)->state)
  5357. +# define sbt(sb) ((sb)->s_type->name)
  5358. +
  5359. +#define IS_WRITE_FLAG(flag) (flag & (O_RDWR | O_WRONLY | O_APPEND))
  5360. +#define IS_COPY_FLAG(flag) (flag & (COPY_FLAGS))
  5361. +
  5362. +/* macros to simplify non-SCA code */
  5363. +# define MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages)
  5364. +# define MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages)
  5365. +# define FREE_PAGE_POINTERS(hidden_pages, num)
  5366. +# define FREE_PAGEDATA_POINTERS(hidden_pages_data, num)
  5367. +# define FOR_EACH_PAGE
  5368. +# define CURRENT_HIDDEN_PAGE hidden_page
  5369. +# define CURRENT_HIDDEN_PAGEDATA hidden_page_data
  5370. +# define CURRENT_HIDDEN_PAGEINDEX page->index
  5371. +
  5372. +/*
  5373. + * EXTERNALS:
  5374. + */
  5375. +extern struct file_operations mini_fo_main_fops;
  5376. +extern struct file_operations mini_fo_dir_fops;
  5377. +extern struct inode_operations mini_fo_main_iops;
  5378. +extern struct inode_operations mini_fo_dir_iops;
  5379. +extern struct inode_operations mini_fo_symlink_iops;
  5380. +extern struct super_operations mini_fo_sops;
  5381. +extern struct dentry_operations mini_fo_dops;
  5382. +extern struct vm_operations_struct mini_fo_shared_vmops;
  5383. +extern struct vm_operations_struct mini_fo_private_vmops;
  5384. +extern struct address_space_operations mini_fo_aops;
  5385. +
  5386. +#if 0 /* unused by mini_fo */
  5387. +extern int mini_fo_interpose(dentry_t *hidden_dentry, dentry_t *this_dentry, super_block_t *sb, int flag);
  5388. +#if defined(FIST_FILTER_DATA) || defined(FIST_FILTER_SCA)
  5389. +extern page_t *mini_fo_get1page(file_t *file, int index);
  5390. +extern int mini_fo_fill_zeros(file_t *file, page_t *page, unsigned from);
  5391. +# endif /* FIST_FILTER_DATA || FIST_FILTER_SCA */
  5392. +
  5393. +
  5394. +# define mini_fo_hidden_dentry(d) __mini_fo_hidden_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
  5395. +# define mini_fo_hidden_sto_dentry(d) __mini_fo_hidden_sto_dentry(__FILE__,__FUNCTION__,__LINE__,(d))
  5396. +
  5397. +extern dentry_t *__mini_fo_hidden_dentry(char *file, char *func, int line, dentry_t *this_dentry);
  5398. +extern dentry_t *__mini_fo_hidden_sto_dentry(char *file, char *func, int line, dentry_t *this_dentry);
  5399. +
  5400. +extern int mini_fo_read_file(const char *filename, void *buf, int len);
  5401. +extern int mini_fo_write_file(const char *filename, void *buf, int len);
  5402. +extern dentry_t *fist_lookup(dentry_t *dir, const char *name, vnode_t **out, uid_t uid, gid_t gid);
  5403. +#endif /* unused by mini_fo */
  5404. +
  5405. +/* state transition functions */
  5406. +extern int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag);
  5407. +extern int nondir_del_rew_to_del(dentry_t *dentry);
  5408. +extern int nondir_creat_to_del(dentry_t *dentry);
  5409. +extern int nondir_mod_to_del(dentry_t *dentry);
  5410. +extern int nondir_unmod_to_del(dentry_t *dentry);
  5411. +
  5412. +extern int dir_unmod_to_mod(dentry_t *dentry);
  5413. +
  5414. +/* rename specials */
  5415. +extern int rename_directory(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
  5416. +extern int rename_nondir(inode_t *old_dir, dentry_t *old_dentry, inode_t *new_dir, dentry_t *new_dentry);
  5417. +
  5418. +/* misc stuff */
  5419. +extern int mini_fo_tri_interpose(dentry_t *hidden_dentry,
  5420. + dentry_t *hidden_sto_dentry,
  5421. + dentry_t *dentry,
  5422. + super_block_t *sb, int flag);
  5423. +
  5424. +extern int mini_fo_cp_cont(dentry_t *tgt_dentry, struct vfsmount *tgt_mnt,
  5425. + dentry_t *src_dentry, struct vfsmount *src_mnt);
  5426. +
  5427. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  5428. +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode, struct nameidata *nd);
  5429. +
  5430. +extern int create_sto_nod(dentry_t *dentry, int mode, dev_t dev);
  5431. +extern int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd);
  5432. +#else
  5433. +extern int mini_fo_create(inode_t *dir, dentry_t *dentry, int mode);
  5434. +
  5435. +extern int create_sto_nod(dentry_t *dentry, int mode, int dev);
  5436. +extern int create_sto_reg_file(dentry_t *dentry, int mode);
  5437. +#endif
  5438. +
  5439. +extern int create_sto_dir(dentry_t *dentry, int mode);
  5440. +
  5441. +extern int exists_in_storage(dentry_t *dentry);
  5442. +extern int is_mini_fo_existant(dentry_t *dentry);
  5443. +extern int get_neg_sto_dentry(dentry_t *dentry);
  5444. +extern int build_sto_structure(dentry_t *dir, dentry_t *dentry);
  5445. +extern int get_mini_fo_bpath(dentry_t *dentry, char **bpath, int *bpath_len);
  5446. +extern dentry_t *bpath_walk(super_block_t *sb, char *bpath);
  5447. +extern int bpath_put(dentry_t *dentry);
  5448. +
  5449. +/* check_mini_fo types functions */
  5450. +extern int check_mini_fo_dentry(dentry_t *dentry);
  5451. +extern int check_mini_fo_file(file_t *file);
  5452. +extern int check_mini_fo_inode(inode_t *inode);
  5453. +
  5454. +/* General meta functions, can be called from outside of meta.c */
  5455. +extern int meta_build_lists(dentry_t *dentry);
  5456. +extern int meta_put_lists(dentry_t *dentry);
  5457. +extern int __meta_put_lists(inode_t *inode);
  5458. +
  5459. +extern int meta_add_d_entry(dentry_t *dentry, const char *name, int len);
  5460. +extern int meta_add_r_entry(dentry_t *dentry,
  5461. + const char *old_name, int old_len,
  5462. + const char *new_name, int new_len);
  5463. +
  5464. +extern int meta_remove_r_entry(dentry_t *dentry, const char *name, int len);
  5465. +
  5466. +extern int meta_check_d_entry(dentry_t *dentry, const char *name, int len);
  5467. +extern int __meta_check_d_entry(inode_t *inode, const char *name, int len);
  5468. +
  5469. +extern char* meta_check_r_entry(dentry_t *dentry, const char *name, int len);
  5470. +extern char* __meta_check_r_entry(inode_t *inode, const char *name, int len);
  5471. +extern int meta_is_r_entry(dentry_t *dentry, const char *name, int len);
  5472. +extern int __meta_is_r_entry(inode_t *inode, const char *name, int len);
  5473. +
  5474. +/* Specific meta functions, should be called only inside meta.c */
  5475. +extern int __meta_put_d_list(inode_t *inode);
  5476. +extern int __meta_put_r_list(inode_t *inode);
  5477. +
  5478. +extern int meta_list_add_d_entry(dentry_t *dentry,
  5479. + const char *name, int len);
  5480. +extern int meta_list_add_r_entry(dentry_t *dentry,
  5481. + const char *old_name, int old_len,
  5482. + const char *new_name, int new_len);
  5483. +
  5484. +extern int meta_list_remove_r_entry(dentry_t *dentry,
  5485. + const char *name, int len);
  5486. +
  5487. +extern int __meta_list_remove_r_entry(inode_t *inode,
  5488. + const char *name, int len);
  5489. +
  5490. +extern int meta_write_d_entry(dentry_t *dentry, const char *name, int len);
  5491. +extern int meta_write_r_entry(dentry_t *dentry,
  5492. + const char *old_name, int old_len,
  5493. + const char *new_name, int new_len);
  5494. +
  5495. +extern int meta_sync_lists(dentry_t *dentry);
  5496. +extern int meta_sync_d_list(dentry_t *dentry, int app_flag);
  5497. +extern int meta_sync_r_list(dentry_t *dentry, int app_flag);
  5498. +
  5499. +/* ndl stuff */
  5500. +extern int ndl_add_entry(struct readdir_data *rd, const char *name, int len);
  5501. +extern void ndl_put_list(struct readdir_data *rd);
  5502. +extern int ndl_check_entry(struct readdir_data *rd,
  5503. + const char *name, int len);
  5504. +
  5505. +
  5506. +# define copy_inode_size(dst, src) \
  5507. + dst->i_size = src->i_size; \
  5508. + dst->i_blocks = src->i_blocks;
  5509. +
  5510. +static inline void
  5511. +fist_copy_attr_atime(inode_t *dest, const inode_t *src)
  5512. +{
  5513. + ASSERT(dest != NULL);
  5514. + ASSERT(src != NULL);
  5515. + dest->i_atime = src->i_atime;
  5516. +}
  5517. +static inline void
  5518. +fist_copy_attr_times(inode_t *dest, const inode_t *src)
  5519. +{
  5520. + ASSERT(dest != NULL);
  5521. + ASSERT(src != NULL);
  5522. + dest->i_atime = src->i_atime;
  5523. + dest->i_mtime = src->i_mtime;
  5524. + dest->i_ctime = src->i_ctime;
  5525. +}
  5526. +static inline void
  5527. +fist_copy_attr_timesizes(inode_t *dest, const inode_t *src)
  5528. +{
  5529. + ASSERT(dest != NULL);
  5530. + ASSERT(src != NULL);
  5531. + dest->i_atime = src->i_atime;
  5532. + dest->i_mtime = src->i_mtime;
  5533. + dest->i_ctime = src->i_ctime;
  5534. + copy_inode_size(dest, src);
  5535. +}
  5536. +static inline void
  5537. +fist_copy_attr_all(inode_t *dest, const inode_t *src)
  5538. +{
  5539. + ASSERT(dest != NULL);
  5540. + ASSERT(src != NULL);
  5541. + dest->i_mode = src->i_mode;
  5542. + dest->i_nlink = src->i_nlink;
  5543. + dest->i_uid = src->i_uid;
  5544. + dest->i_gid = src->i_gid;
  5545. + dest->i_rdev = src->i_rdev;
  5546. + dest->i_atime = src->i_atime;
  5547. + dest->i_mtime = src->i_mtime;
  5548. + dest->i_ctime = src->i_ctime;
  5549. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
  5550. + dest->i_blksize = src->i_blksize;
  5551. +#endif
  5552. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,12)
  5553. + dest->i_blkbits = src->i_blkbits;
  5554. +# endif /* linux 2.4.12 and newer */
  5555. + copy_inode_size(dest, src);
  5556. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  5557. + dest->i_attr_flags = src->i_attr_flags;
  5558. +#else
  5559. + dest->i_flags = src->i_flags;
  5560. +#endif
  5561. +}
  5562. +
  5563. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  5564. +/* copied from linux/fs.h */
  5565. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  5566. +static inline void double_lock(struct dentry *d1, struct dentry *d2)
  5567. +{
  5568. + struct mutex *m1 = &d1->d_inode->i_mutex;
  5569. + struct mutex *m2 = &d2->d_inode->i_mutex;
  5570. + if (m1 != m2) {
  5571. + if ((unsigned long) m1 < (unsigned long) m2) {
  5572. + struct mutex *tmp = m2;
  5573. + m2 = m1; m1 = tmp;
  5574. + }
  5575. + mutex_lock(m1);
  5576. + }
  5577. + mutex_lock(m2);
  5578. +}
  5579. +
  5580. +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
  5581. +{
  5582. + struct mutex *m1 = &d1->d_inode->i_mutex;
  5583. + struct mutex *m2 = &d2->d_inode->i_mutex;
  5584. + mutex_unlock(m1);
  5585. + if (m1 != m2)
  5586. + mutex_unlock(m2);
  5587. + dput(d1);
  5588. + dput(d2);
  5589. +}
  5590. +
  5591. +#else
  5592. +static inline void double_down(struct semaphore *s1, struct semaphore *s2)
  5593. +{
  5594. + if (s1 != s2) {
  5595. + if ((unsigned long) s1 < (unsigned long) s2) {
  5596. + struct semaphore *tmp = s2;
  5597. + s2 = s1; s1 = tmp;
  5598. + }
  5599. + down(s1);
  5600. + }
  5601. + down(s2);
  5602. +}
  5603. +
  5604. +static inline void double_up(struct semaphore *s1, struct semaphore *s2)
  5605. +{
  5606. + up(s1);
  5607. + if (s1 != s2)
  5608. + up(s2);
  5609. +}
  5610. +
  5611. +static inline void double_lock(struct dentry *d1, struct dentry *d2)
  5612. +{
  5613. + double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
  5614. +}
  5615. +
  5616. +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
  5617. +{
  5618. + double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
  5619. + dput(d1);
  5620. + dput(d2);
  5621. +}
  5622. +#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) */
  5623. +#endif /* if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) */
  5624. +#endif /* __KERNEL__ */
  5625. +
  5626. +/*
  5627. + * Definitions for user and kernel code
  5628. + */
  5629. +
  5630. +/* ioctls */
  5631. +
  5632. +#endif /* not __MINI_FO_H_ */
  5633. --- /dev/null
  5634. +++ b/fs/mini_fo/mini_fo-merge
  5635. @@ -0,0 +1,180 @@
  5636. +#!/bin/bash
  5637. +#
  5638. +# Copyright (C) 2005 Markus Klotzbuecher <[email protected]>
  5639. +# This program is free software; you can redistribute it and/or
  5640. +# modify it under the terms of the GNU General Public License
  5641. +# as published by the Free Software Foundation; either version
  5642. +# 2 of the License, or (at your option) any later version.
  5643. +#
  5644. +
  5645. +BASE=
  5646. +STO=
  5647. +HELP=
  5648. +DRYRUN=
  5649. +VERBOSE=
  5650. +TMP="/tmp/"
  5651. +META_NAME="META_dAfFgHE39ktF3HD2sr"
  5652. +SKIP_DEL_LIST="skip-delete-list.mini_fo-merge"
  5653. +
  5654. +COMMAND=
  5655. +exec_command()
  5656. +{
  5657. + if [ x$DRYRUN == "xset" ]; then
  5658. + echo " would run: $COMMAND"
  5659. + elif ! [ x$DRYRUN == "xset" ]; then
  5660. + if [ x$VERBOSE == "xset" ]; then
  5661. + echo " running: $COMMAND"
  5662. + fi
  5663. + eval $COMMAND
  5664. + fi
  5665. +}
  5666. +
  5667. +usage()
  5668. +{
  5669. +cat <<EOF
  5670. +
  5671. +USAGE: $0 -b <base dir> -s <storage dir>
  5672. +Version 0.1
  5673. +
  5674. +This script merges the contents of a mini_fo storage file system back
  5675. +to the base file system.
  5676. +
  5677. +!!! Warning: This will modify the base filesystem and can destroy data
  5678. + if used wrongly.
  5679. +
  5680. +Options:
  5681. + -b <base dir>
  5682. + the directory of the base file system.
  5683. +
  5684. + -s <storage dir>
  5685. + the directory of the storage file system.
  5686. +
  5687. + -d dry run, will not change anything and print the commands that
  5688. + would be executed.
  5689. +
  5690. + -t tmp dir for storing temporary file. default: $TMP
  5691. +
  5692. + -v show what operations are performed.
  5693. +
  5694. + -h displays this message.
  5695. +
  5696. +EOF
  5697. +}
  5698. +
  5699. +# parse parameters
  5700. +while getopts hdvt:b:s: OPTS
  5701. + do
  5702. + case $OPTS in
  5703. + h) HELP="set";;
  5704. + d) DRYRUN="set";;
  5705. + v) VERBOSE="set";;
  5706. + b) BASE="$OPTARG";;
  5707. + s) STO="$OPTARG";;
  5708. + t) TMP="$OPTARG";;
  5709. + ?) usage
  5710. + exit 1;;
  5711. + esac
  5712. +done
  5713. +
  5714. +if [ "x$HELP" == "xset" ]; then
  5715. + usage
  5716. + exit -1
  5717. +fi
  5718. +
  5719. +if ! [ -d "$BASE" ] || ! [ -d "$STO" ]; then
  5720. + echo -e "$0:\n Error, -s and/or -b argument missing. type $0 -h for help."
  5721. + exit -1;
  5722. +fi
  5723. +
  5724. +# get full paths
  5725. +pushd $STO; STO=`pwd`; popd
  5726. +pushd $BASE; BASE=`pwd`; popd
  5727. +TMP=${TMP%/}
  5728. +
  5729. +
  5730. +cat<<EOF
  5731. +###############################################################################
  5732. +# mini_fo-merge
  5733. +#
  5734. +# base dir: $BASE
  5735. +# storage dir: $STO
  5736. +# meta filename: $META_NAME
  5737. +# dry run: $DRYRUN
  5738. +# verbose: $VERBOSE
  5739. +# tmp files: $TMP
  5740. +###############################################################################
  5741. +
  5742. +EOF
  5743. +
  5744. +rm $TMP/$SKIP_DEL_LIST
  5745. +
  5746. +# first process all renamed dirs
  5747. +echo "Merging renamed directories..."
  5748. +pushd $STO &> /dev/null
  5749. +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^R ' | tr -s ':R' ' ' | while read ENTRY; do
  5750. + echo "entry: $ENTRY"
  5751. + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
  5752. + OLD_B_DIR=`echo $ENTRY | cut -d ' ' -f 2 | sed -e 's/\///'`
  5753. + NEW_NAME=`echo $ENTRY | cut -d ' ' -f 3`
  5754. + NEW_B_DIR=`echo $META_FILE | sed -e "s/$META_NAME/$NEW_NAME/" | sed -e 's/^\.\///'`
  5755. + echo "META_FILE: $META_FILE"
  5756. + echo "OLD_B_DIR: $OLD_B_DIR"
  5757. + echo "NEW_NAME: $NEW_NAME"
  5758. + echo "NEW_B_DIR: $NEW_B_DIR"
  5759. +
  5760. + pushd $BASE &> /dev/null
  5761. + # remove an existing dir in storage
  5762. + COMMAND="rm -rf $NEW_B_DIR"; exec_command
  5763. + COMMAND="cp -R $OLD_B_DIR $NEW_B_DIR"; exec_command
  5764. + echo ""
  5765. + popd &> /dev/null
  5766. +
  5767. + # remember this dir to exclude it from deleting later
  5768. + echo $NEW_B_DIR >> $TMP/$SKIP_DEL_LIST
  5769. +done
  5770. +
  5771. +# delete all whiteouted files from base
  5772. +echo -e "\nDeleting whiteout'ed files from base file system..."
  5773. +find . -name $META_NAME -type f -print0 | xargs -0 -e grep -e '^D ' | sed -e 's/:D//' | while read ENTRY; do
  5774. + META_FILE=`echo $ENTRY | cut -d ' ' -f 1`
  5775. + DEL_NAME=`echo $ENTRY | cut -d ' ' -f 2`
  5776. + DEL_FILE=`echo $META_FILE | sed -e "s/$META_NAME/$DEL_NAME/" | sed -e 's/^\.\///'`
  5777. + grep -x $DEL_FILE $TMP/$SKIP_DEL_LIST &> /dev/null
  5778. + if [ $? -ne 0 ]; then
  5779. + pushd $BASE &> /dev/null
  5780. + COMMAND="rm -rf $DEL_FILE"; exec_command
  5781. + popd &> /dev/null
  5782. + else
  5783. + echo " excluding: $DEL_FILE as in skip-del-list."
  5784. + fi
  5785. +done
  5786. +
  5787. +# create all dirs and update permissions
  5788. +echo -e "\nSetting up directory structures in base file system..."
  5789. +find . -type d | sed -e 's/^\.\///' | while read DIR; do
  5790. + PERMS=`stat -c %a $DIR`
  5791. + DIR_UID=`stat -c %u $DIR`
  5792. + DIR_GID=`stat -c %g $DIR`
  5793. + pushd $BASE &> /dev/null
  5794. + if ! [ -d $DIR ]; then
  5795. + COMMAND="mkdir -p $DIR"; exec_command
  5796. + fi
  5797. + COMMAND="chmod $PERMS $DIR"; exec_command
  5798. + COMMAND="chown $DIR_UID:$DIR_GID $DIR"; exec_command
  5799. + popd &> /dev/null
  5800. +done
  5801. +
  5802. +# merge all non-directory files
  5803. +echo -e "\nMerging all non-directory files...."
  5804. +for i in b c p f l s; do
  5805. + find . -type $i | sed -e 's/^\.\///' | grep -v "$META_NAME" | while read FILE; do
  5806. + pushd $BASE #&> /dev/null
  5807. + COMMAND="cp -df $STO/$FILE $BASE/$FILE"; exec_command
  5808. + popd &> /dev/null
  5809. + done
  5810. +done
  5811. +popd &> /dev/null
  5812. +
  5813. +#rm $TMP/$SKIP_DEL_LIST
  5814. +
  5815. +echo "Done!"
  5816. --- /dev/null
  5817. +++ b/fs/mini_fo/mini_fo-overlay
  5818. @@ -0,0 +1,130 @@
  5819. +#!/bin/bash
  5820. +#
  5821. +# Copyright (C) 2005 Markus Klotzbuecher <[email protected]>
  5822. +# This program is free software; you can redistribute it and/or
  5823. +# modify it under the terms of the GNU General Public License
  5824. +# as published by the Free Software Foundation; either version
  5825. +# 2 of the License, or (at your option) any later version.
  5826. +#
  5827. +
  5828. +HELP=
  5829. +SUFF=
  5830. +MNTP=
  5831. +MNT_DIR="/mnt"
  5832. +STO=
  5833. +STO_DIR="/tmp"
  5834. +BASE=
  5835. +
  5836. +usage()
  5837. +{
  5838. +cat <<EOF
  5839. +
  5840. +Usage: $0 [-s suffix] [-d sto_dir_dir] [-m mount point] base_dir
  5841. +Version 0.1
  5842. +
  5843. +This script overlays the given base directory using the mini_fo file
  5844. +system. If only the base directory base_dir is given, $0
  5845. +will use a storage directory called "sto-<base_dir_name>" in $STO_DIR,
  5846. +and mount point "mini_fo-<base_dir_dir>" in $MNT_DIR.
  5847. +
  5848. +Options:
  5849. + -s <suffix>
  5850. + add given suffix to storage directory and the mount
  5851. + point. This is usefull for overlaying one base directory
  5852. + several times and avoiding conflicts with storage directory
  5853. + names and mount points.
  5854. +
  5855. + -d <sto_dir_dir>
  5856. + change the directory in which the storage directory will be
  5857. + created (default is currently "$STO_DIR".
  5858. +
  5859. + -m <mount point>
  5860. + use an alternative directory to create the mini_fo
  5861. + mountpoint (default is currently "$MNT_DIR".
  5862. +
  5863. + -h displays this message.
  5864. +
  5865. +EOF
  5866. +exit 1;
  5867. +}
  5868. +
  5869. +while getopts hm:s:d: OPTS
  5870. + do
  5871. + case $OPTS in
  5872. + s) SUFF="$OPTARG";;
  5873. + d) STO_DIR="$OPTARG";;
  5874. + m) MNT_DIR="$OPTARG";;
  5875. + h) HELP="set";;
  5876. + ?) usage
  5877. + exit 1;;
  5878. + esac
  5879. +done
  5880. +shift $(($OPTIND - 1))
  5881. +
  5882. +BASE="$1"
  5883. +
  5884. +if [ "x$HELP" == "xset" ]; then
  5885. + usage
  5886. + exit -1
  5887. +fi
  5888. +
  5889. +# fix suffix
  5890. +if [ "x$SUFF" != "x" ]; then
  5891. + SUFF="-$SUFF"
  5892. +fi
  5893. +
  5894. +# kill trailing slashes
  5895. +MNT_DIR=${MNT_DIR%/}
  5896. +STO_DIR=${STO_DIR%/}
  5897. +BASE=${BASE%/}
  5898. +
  5899. +
  5900. +if ! [ -d "$BASE" ]; then
  5901. + echo "invalid base dir $BASE, run $0 -h for help."
  5902. + exit -1
  5903. +fi
  5904. +
  5905. +# check opts
  5906. +if ! [ -d "$MNT_DIR" ]; then
  5907. + echo "invalid mount dir $MNT_DIR, run $0 -h for help."
  5908. + exit -1
  5909. +fi
  5910. +
  5911. +if ! [ -d "$STO_DIR" ]; then
  5912. + echo "invalid sto_dir_dir $STO_DIR, run $0 -h for help."
  5913. + exit -1
  5914. +fi
  5915. +
  5916. +MNTP="$MNT_DIR/mini_fo-`basename $BASE`$SUFF"
  5917. +STO="$STO_DIR/sto-`basename $BASE`$SUFF"
  5918. +
  5919. +# create the mount point if it doesn't exist
  5920. +mkdir -p $MNTP
  5921. +if [ $? -ne 0 ]; then
  5922. + echo "Error, failed to create mount point $MNTP"
  5923. +fi
  5924. +
  5925. +mkdir -p $STO
  5926. +if [ $? -ne 0 ]; then
  5927. + echo "Error, failed to create storage dir $STO"
  5928. +fi
  5929. +
  5930. +# check if fs is already mounted
  5931. +mount | grep mini_fo | grep $MNTP &> /dev/null
  5932. +if [ $? -eq 0 ]; then
  5933. + echo "Error, existing mini_fo mount at $MNTP."
  5934. + exit -1
  5935. +fi
  5936. +
  5937. +mount | grep mini_fo | grep $STO &> /dev/null
  5938. +if [ $? -eq 0 ]; then
  5939. + echo "Error, $STO seems to be used already."
  5940. + exit -1
  5941. +fi
  5942. +
  5943. +# mount
  5944. +mount -t mini_fo -o base=$BASE,sto=$STO $BASE $MNTP
  5945. +
  5946. +if [ $? -ne 0 ]; then
  5947. + echo "Error, mounting failed, maybe no permisson to mount?"
  5948. +fi
  5949. --- /dev/null
  5950. +++ b/fs/mini_fo/mmap.c
  5951. @@ -0,0 +1,637 @@
  5952. +/*
  5953. + * Copyright (c) 1997-2003 Erez Zadok
  5954. + * Copyright (c) 2001-2003 Stony Brook University
  5955. + *
  5956. + * For specific licensing information, see the COPYING file distributed with
  5957. + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
  5958. + *
  5959. + * This Copyright notice must be kept intact and distributed with all
  5960. + * fistgen sources INCLUDING sources generated by fistgen.
  5961. + */
  5962. +/*
  5963. + * Copyright (C) 2004, 2005 Markus Klotzbuecher <[email protected]>
  5964. + *
  5965. + * This program is free software; you can redistribute it and/or
  5966. + * modify it under the terms of the GNU General Public License
  5967. + * as published by the Free Software Foundation; either version
  5968. + * 2 of the License, or (at your option) any later version.
  5969. + */
  5970. +
  5971. +/*
  5972. + * $Id$
  5973. + */
  5974. +
  5975. +#ifdef HAVE_CONFIG_H
  5976. +# include <config.h>
  5977. +#endif /* HAVE_CONFIG_H */
  5978. +
  5979. +#include "fist.h"
  5980. +#include "mini_fo.h"
  5981. +
  5982. +
  5983. +#ifdef FIST_COUNT_WRITES
  5984. +/* for counting writes in the middle vs. regular writes */
  5985. +unsigned long count_writes = 0, count_writes_middle = 0;
  5986. +#endif /* FIST_COUNT_WRITES */
  5987. +
  5988. +/* forward declaration of commit write and prepare write */
  5989. +STATIC int mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to);
  5990. +STATIC int mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to);
  5991. +
  5992. +
  5993. +/*
  5994. + * Function for handling creation of holes when lseek-ing past the
  5995. + * end of the file and then writing some data.
  5996. + */
  5997. +int
  5998. +mini_fo_fill_zeros(file_t* file, page_t *page, unsigned from)
  5999. +{
  6000. + int err = 0;
  6001. + dentry_t *dentry = file->f_dentry;
  6002. + inode_t *inode = dentry->d_inode;
  6003. + page_t *tmp_page;
  6004. + int index;
  6005. +
  6006. + print_entry_location();
  6007. +
  6008. + for (index = inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
  6009. + tmp_page = mini_fo_get1page(file, index);
  6010. + if (IS_ERR(tmp_page)) {
  6011. + err = PTR_ERR(tmp_page);
  6012. + goto out;
  6013. + }
  6014. +
  6015. + /*
  6016. + * zero out rest of the contents of the page between the appropriate
  6017. + * offsets.
  6018. + */
  6019. + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
  6020. +
  6021. + if (! (err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
  6022. + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
  6023. +
  6024. + page_cache_release(tmp_page);
  6025. + if (err < 0)
  6026. + goto out;
  6027. + if (current->need_resched)
  6028. + schedule();
  6029. + }
  6030. +
  6031. + /* zero out appropriate parts of last page */
  6032. +
  6033. + /*
  6034. + * if the encoding type is block, then adjust the 'from' (where the
  6035. + * zeroing will start) offset appropriately
  6036. + */
  6037. + from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
  6038. +
  6039. + if ((from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0) {
  6040. +
  6041. + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, from - (inode->i_size & ~PAGE_CACHE_MASK));
  6042. + if (! (err = mini_fo_prepare_write(file, page, 0, PAGE_CACHE_SIZE)))
  6043. + err = mini_fo_commit_write(file, page, 0, PAGE_CACHE_SIZE);
  6044. +
  6045. + if (err < 0)
  6046. + goto out;
  6047. + if (current->need_resched)
  6048. + schedule();
  6049. + }
  6050. +
  6051. + out:
  6052. + print_exit_status(err);
  6053. + return err;
  6054. +}
  6055. +
  6056. +
  6057. +
  6058. +STATIC int
  6059. +mini_fo_writepage(page_t *page)
  6060. +{
  6061. + int err = -EIO;
  6062. + inode_t *inode;
  6063. + inode_t *hidden_inode;
  6064. + page_t *hidden_page;
  6065. + char *kaddr, *hidden_kaddr;
  6066. +
  6067. + print_entry_location();
  6068. +
  6069. + inode = page->mapping->host;
  6070. + hidden_inode = itohi(inode);
  6071. +
  6072. + /*
  6073. + * writepage is called when shared mmap'ed files need to write
  6074. + * their pages, while prepare/commit_write are called from the
  6075. + * non-paged write() interface. (However, in 2.3 the two interfaces
  6076. + * share the same cache, while in 2.2 they didn't.)
  6077. + *
  6078. + * So we pretty much have to duplicate much of what commit_write does.
  6079. + */
  6080. +
  6081. + /* find lower page (returns a locked page) */
  6082. + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
  6083. + if (!hidden_page)
  6084. + goto out;
  6085. +
  6086. + /* get page address, and encode it */
  6087. + kaddr = (char *) kmap(page);
  6088. + hidden_kaddr = (char*) kmap(hidden_page);
  6089. + mini_fo_encode_block(kaddr, hidden_kaddr, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
  6090. + /* if encode_block could fail, then return error */
  6091. + kunmap(page);
  6092. + kunmap(hidden_page);
  6093. +
  6094. + /* call lower writepage (expects locked page) */
  6095. + err = hidden_inode->i_mapping->a_ops->writepage(hidden_page);
  6096. +
  6097. + /*
  6098. + * update mtime and ctime of lower level file system
  6099. + * mini_fo' mtime and ctime are updated by generic_file_write
  6100. + */
  6101. + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
  6102. +
  6103. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,1)
  6104. + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
  6105. +# endif /* kernel older than 2.4.1 */
  6106. + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
  6107. +
  6108. + if (err)
  6109. + ClearPageUptodate(page);
  6110. + else
  6111. + SetPageUptodate(page);
  6112. + out:
  6113. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,1)
  6114. + UnlockPage(page);
  6115. +# endif /* kernel 2.4.1 and newer */
  6116. + print_exit_status(err);
  6117. + return err;
  6118. +}
  6119. +
  6120. +
  6121. +/*
  6122. + * get one page from cache or lower f/s, return error otherwise.
  6123. + * returns unlocked, up-to-date page (if ok), with increased refcnt.
  6124. + */
  6125. +page_t *
  6126. +mini_fo_get1page(file_t *file, int index)
  6127. +{
  6128. + page_t *page;
  6129. + dentry_t *dentry;
  6130. + inode_t *inode;
  6131. + struct address_space *mapping;
  6132. + int err;
  6133. +
  6134. + print_entry_location();
  6135. +
  6136. + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
  6137. + inode = dentry->d_inode;
  6138. + mapping = inode->i_mapping;
  6139. +
  6140. + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
  6141. + if (index < 0) {
  6142. + printk("%s BUG: index=%d\n", __FUNCTION__, index);
  6143. + page = ERR_PTR(-EIO);
  6144. + goto out;
  6145. + }
  6146. + page = read_cache_page(mapping,
  6147. + index,
  6148. + (filler_t *) mapping->a_ops->readpage,
  6149. + (void *) file);
  6150. + if (IS_ERR(page))
  6151. + goto out;
  6152. + wait_on_page(page);
  6153. + if (!Page_Uptodate(page)) {
  6154. + lock_page(page);
  6155. + err = mapping->a_ops->readpage(file, page);
  6156. + if (err) {
  6157. + page = ERR_PTR(err);
  6158. + goto out;
  6159. + }
  6160. + wait_on_page(page);
  6161. + if (!Page_Uptodate(page)) {
  6162. + page = ERR_PTR(-EIO);
  6163. + goto out;
  6164. + }
  6165. + }
  6166. +
  6167. + out:
  6168. + print_exit_pointer(page);
  6169. + return page;
  6170. +}
  6171. +
  6172. +
  6173. +/*
  6174. + * get one page from cache or lower f/s, return error otherwise.
  6175. + * similar to get1page, but doesn't guarantee that it will return
  6176. + * an unlocked page.
  6177. + */
  6178. +page_t *
  6179. +mini_fo_get1page_cached(file_t *file, int index)
  6180. +{
  6181. + page_t *page;
  6182. + dentry_t *dentry;
  6183. + inode_t *inode;
  6184. + struct address_space *mapping;
  6185. + int err;
  6186. +
  6187. + print_entry_location();
  6188. +
  6189. + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
  6190. + inode = dentry->d_inode;
  6191. + mapping = inode->i_mapping;
  6192. +
  6193. + fist_dprint(8, "%s: read page index %d pid %d\n", __FUNCTION__, index, current->pid);
  6194. + if (index < 0) {
  6195. + printk("%s BUG: index=%d\n", __FUNCTION__, index);
  6196. + page = ERR_PTR(-EIO);
  6197. + goto out;
  6198. + }
  6199. + page = read_cache_page(mapping,
  6200. + index,
  6201. + (filler_t *) mapping->a_ops->readpage,
  6202. + (void *) file);
  6203. + if (IS_ERR(page))
  6204. + goto out;
  6205. +
  6206. + out:
  6207. + print_exit_pointer(page);
  6208. + return page;
  6209. +}
  6210. +
  6211. +
  6212. +/*
  6213. + * readpage is called from generic_page_read and the fault handler.
  6214. + * If your file system uses generic_page_read for the read op, it
  6215. + * must implement readpage.
  6216. + *
  6217. + * Readpage expects a locked page, and must unlock it.
  6218. + */
  6219. +STATIC int
  6220. +mini_fo_do_readpage(file_t *file, page_t *page)
  6221. +{
  6222. + int err = -EIO;
  6223. + dentry_t *dentry;
  6224. + file_t *hidden_file = NULL;
  6225. + dentry_t *hidden_dentry;
  6226. + inode_t *inode;
  6227. + inode_t *hidden_inode;
  6228. + char *page_data;
  6229. + page_t *hidden_page;
  6230. + char *hidden_page_data;
  6231. + int real_size;
  6232. +
  6233. + print_entry_location();
  6234. +
  6235. + dentry = file->f_dentry; /* CPW: Moved below print_entry_location */
  6236. + if (ftopd(file) != NULL)
  6237. + hidden_file = ftohf(file);
  6238. + hidden_dentry = dtohd(dentry);
  6239. + inode = dentry->d_inode;
  6240. + hidden_inode = itohi(inode);
  6241. +
  6242. + fist_dprint(7, "%s: requesting page %d from file %s\n", __FUNCTION__, page->index, dentry->d_name.name);
  6243. +
  6244. + MALLOC_PAGE_POINTERS(hidden_pages, num_hidden_pages);
  6245. + MALLOC_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
  6246. + FOR_EACH_PAGE
  6247. + CURRENT_HIDDEN_PAGE = NULL;
  6248. +
  6249. + /* find lower page (returns a locked page) */
  6250. + FOR_EACH_PAGE {
  6251. + fist_dprint(8, "%s: Current page index = %d\n", __FUNCTION__, CURRENT_HIDDEN_PAGEINDEX);
  6252. + CURRENT_HIDDEN_PAGE = read_cache_page(hidden_inode->i_mapping,
  6253. + CURRENT_HIDDEN_PAGEINDEX,
  6254. + (filler_t *) hidden_inode->i_mapping->a_ops->readpage,
  6255. + (void *) hidden_file);
  6256. + if (IS_ERR(CURRENT_HIDDEN_PAGE)) {
  6257. + err = PTR_ERR(CURRENT_HIDDEN_PAGE);
  6258. + CURRENT_HIDDEN_PAGE = NULL;
  6259. + goto out_release;
  6260. + }
  6261. + }
  6262. +
  6263. + /*
  6264. + * wait for the page data to show up
  6265. + * (signaled by readpage as unlocking the page)
  6266. + */
  6267. + FOR_EACH_PAGE {
  6268. + wait_on_page(CURRENT_HIDDEN_PAGE);
  6269. + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
  6270. + /*
  6271. + * call readpage() again if we returned from wait_on_page with a
  6272. + * page that's not up-to-date; that can happen when a partial
  6273. + * page has a few buffers which are ok, but not the whole
  6274. + * page.
  6275. + */
  6276. + lock_page(CURRENT_HIDDEN_PAGE);
  6277. + err = hidden_inode->i_mapping->a_ops->readpage(hidden_file,
  6278. + CURRENT_HIDDEN_PAGE);
  6279. + if (err) {
  6280. + CURRENT_HIDDEN_PAGE = NULL;
  6281. + goto out_release;
  6282. + }
  6283. + wait_on_page(CURRENT_HIDDEN_PAGE);
  6284. + if (!Page_Uptodate(CURRENT_HIDDEN_PAGE)) {
  6285. + err = -EIO;
  6286. + goto out_release;
  6287. + }
  6288. + }
  6289. + }
  6290. +
  6291. + /* map pages, get their addresses */
  6292. + page_data = (char *) kmap(page);
  6293. + FOR_EACH_PAGE
  6294. + CURRENT_HIDDEN_PAGEDATA = (char *) kmap(CURRENT_HIDDEN_PAGE);
  6295. +
  6296. + /* if decode_block could fail, then return error */
  6297. + err = 0;
  6298. + real_size = hidden_inode->i_size - (page->index << PAGE_CACHE_SHIFT);
  6299. + if (real_size <= 0)
  6300. + memset(page_data, 0, PAGE_CACHE_SIZE);
  6301. + else if (real_size < PAGE_CACHE_SIZE) {
  6302. + mini_fo_decode_block(hidden_page_data, page_data, real_size, inode, inode->i_sb, page->index);
  6303. + memset(page_data + real_size, 0, PAGE_CACHE_SIZE - real_size);
  6304. + } else
  6305. + mini_fo_decode_block(hidden_page_data, page_data, PAGE_CACHE_SIZE, inode, inode->i_sb, page->index);
  6306. +
  6307. + FOR_EACH_PAGE
  6308. + kunmap(CURRENT_HIDDEN_PAGE);
  6309. + kunmap(page);
  6310. +
  6311. + out_release:
  6312. + FOR_EACH_PAGE
  6313. + if (CURRENT_HIDDEN_PAGE)
  6314. + page_cache_release(CURRENT_HIDDEN_PAGE); /* undo read_cache_page */
  6315. +
  6316. + FREE_PAGE_POINTERS(hidden_pages, num_hidden_pages);
  6317. + FREE_PAGEDATA_POINTERS(hidden_pages_data, num_hidden_pages);
  6318. +
  6319. + out:
  6320. + if (err == 0)
  6321. + SetPageUptodate(page);
  6322. + else
  6323. + ClearPageUptodate(page);
  6324. +
  6325. + print_exit_status(err);
  6326. + return err;
  6327. +}
  6328. +
  6329. +
  6330. +STATIC int
  6331. +mini_fo_readpage(file_t *file, page_t *page)
  6332. +{
  6333. + int err;
  6334. + print_entry_location();
  6335. +
  6336. + err = mini_fo_do_readpage(file, page);
  6337. +
  6338. + /*
  6339. + * we have to unlock our page, b/c we _might_ have gotten a locked page.
  6340. + * but we no longer have to wakeup on our page here, b/c UnlockPage does
  6341. + * it
  6342. + */
  6343. + UnlockPage(page);
  6344. +
  6345. + print_exit_status(err);
  6346. + return err;
  6347. +}
  6348. +
  6349. +
  6350. +STATIC int
  6351. +mini_fo_prepare_write(file_t *file, page_t *page, unsigned from, unsigned to)
  6352. +{
  6353. + int err = 0;
  6354. +
  6355. + print_entry_location();
  6356. +
  6357. + /*
  6358. + * we call kmap(page) only here, and do the kunmap
  6359. + * and the actual downcalls, including unlockpage and uncache
  6360. + * in commit_write.
  6361. + */
  6362. + kmap(page);
  6363. +
  6364. + /* fast path for whole page writes */
  6365. + if (from == 0 && to == PAGE_CACHE_SIZE)
  6366. + goto out;
  6367. + /* read the page to "revalidate" our data */
  6368. + /* call the helper function which doesn't unlock the page */
  6369. + if (!Page_Uptodate(page))
  6370. + err = mini_fo_do_readpage(file, page);
  6371. +
  6372. + out:
  6373. + print_exit_status(err);
  6374. + return err;
  6375. +}
  6376. +
  6377. +
  6378. +
  6379. +STATIC int
  6380. +mini_fo_commit_write(file_t *file, page_t *page, unsigned from, unsigned to)
  6381. +{
  6382. + int err = -ENOMEM;
  6383. + inode_t *inode;
  6384. + inode_t *hidden_inode;
  6385. + page_t *hidden_page;
  6386. + file_t *hidden_file = NULL;
  6387. + loff_t pos;
  6388. + unsigned bytes = to - from;
  6389. + unsigned hidden_from, hidden_to, hidden_bytes;
  6390. +
  6391. + print_entry_location();
  6392. +
  6393. + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
  6394. + hidden_inode = itohi(inode);
  6395. +
  6396. + ASSERT(file != NULL);
  6397. + /*
  6398. + * here we have a kmapped page, with data from the user copied
  6399. + * into it. we need to encode_block it, and then call the lower
  6400. + * commit_write. We also need to simulate same behavior of
  6401. + * generic_file_write, and call prepare_write on the lower f/s first.
  6402. + */
  6403. +#ifdef FIST_COUNT_WRITES
  6404. + count_writes++;
  6405. +# endif /* FIST_COUNT_WRITES */
  6406. +
  6407. + /* this is append and/or extend -- we can't have holes so fill them in */
  6408. + if (page->index > (hidden_inode->i_size >> PAGE_CACHE_SHIFT)) {
  6409. + page_t *tmp_page;
  6410. + int index;
  6411. + for (index = hidden_inode->i_size >> PAGE_CACHE_SHIFT; index < page->index; index++) {
  6412. + tmp_page = mini_fo_get1page(file, index);
  6413. + if (IS_ERR(tmp_page)) {
  6414. + err = PTR_ERR(tmp_page);
  6415. + goto out;
  6416. + }
  6417. + /* zero out the contents of the page at the appropriate offsets */
  6418. + memset((char*)page_address(tmp_page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, PAGE_CACHE_SIZE - (inode->i_size & ~PAGE_CACHE_MASK));
  6419. + if (!(err = mini_fo_prepare_write(file, tmp_page, 0, PAGE_CACHE_SIZE)))
  6420. + err = mini_fo_commit_write(file, tmp_page, 0, PAGE_CACHE_SIZE);
  6421. + page_cache_release(tmp_page);
  6422. + if (err < 0)
  6423. + goto out;
  6424. + if (current->need_resched)
  6425. + schedule();
  6426. + }
  6427. + }
  6428. +
  6429. + if (ftopd(file) != NULL)
  6430. + hidden_file = ftohf(file);
  6431. +
  6432. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  6433. + mutex_lock(&hidden_inode->i_mutex);
  6434. +#else
  6435. + down(&hidden_inode->i_sem);
  6436. +#endif
  6437. + /* find lower page (returns a locked page) */
  6438. + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
  6439. + if (!hidden_page)
  6440. + goto out;
  6441. +
  6442. +#if FIST_ENCODING_BLOCKSIZE > 1
  6443. +# error encoding_blocksize greater than 1 is not yet supported
  6444. +# endif /* FIST_ENCODING_BLOCKSIZE > 1 */
  6445. +
  6446. + hidden_from = from & (~(FIST_ENCODING_BLOCKSIZE - 1));
  6447. + hidden_to = ((to + FIST_ENCODING_BLOCKSIZE - 1) & (~(FIST_ENCODING_BLOCKSIZE - 1)));
  6448. + if ((page->index << PAGE_CACHE_SHIFT) + to > hidden_inode->i_size) {
  6449. +
  6450. + /*
  6451. + * if this call to commit_write had introduced holes and the code
  6452. + * for handling holes was invoked, then the beginning of this page
  6453. + * must be zeroed out
  6454. + * zero out bytes from 'size_of_file%pagesize' to 'from'.
  6455. + */
  6456. + if ((hidden_from - (inode->i_size & ~PAGE_CACHE_MASK)) > 0)
  6457. + memset((char*)page_address(page) + (inode->i_size & ~PAGE_CACHE_MASK), 0, hidden_from - (inode->i_size & ~PAGE_CACHE_MASK));
  6458. +
  6459. + }
  6460. + hidden_bytes = hidden_to - hidden_from;
  6461. +
  6462. + /* call lower prepare_write */
  6463. + err = -EINVAL;
  6464. + if (hidden_inode->i_mapping &&
  6465. + hidden_inode->i_mapping->a_ops &&
  6466. + hidden_inode->i_mapping->a_ops->prepare_write)
  6467. + err = hidden_inode->i_mapping->a_ops->prepare_write(hidden_file,
  6468. + hidden_page,
  6469. + hidden_from,
  6470. + hidden_to);
  6471. + if (err)
  6472. + /* don't leave locked pages behind, esp. on an ENOSPC */
  6473. + goto out_unlock;
  6474. +
  6475. + fist_dprint(8, "%s: encoding %d bytes\n", __FUNCTION__, hidden_bytes);
  6476. + mini_fo_encode_block((char *) page_address(page) + hidden_from, (char*) page_address(hidden_page) + hidden_from, hidden_bytes, inode, inode->i_sb, page->index);
  6477. + /* if encode_block could fail, then goto unlock and return error */
  6478. +
  6479. + /* call lower commit_write */
  6480. + err = hidden_inode->i_mapping->a_ops->commit_write(hidden_file,
  6481. + hidden_page,
  6482. + hidden_from,
  6483. + hidden_to);
  6484. +
  6485. + if (err < 0)
  6486. + goto out_unlock;
  6487. +
  6488. + err = bytes; /* convert error to no. of bytes */
  6489. +
  6490. + inode->i_blocks = hidden_inode->i_blocks;
  6491. + /* we may have to update i_size */
  6492. + pos = (page->index << PAGE_CACHE_SHIFT) + to;
  6493. + if (pos > inode->i_size)
  6494. + inode->i_size = pos;
  6495. +
  6496. + /*
  6497. + * update mtime and ctime of lower level file system
  6498. + * mini_fo' mtime and ctime are updated by generic_file_write
  6499. + */
  6500. + hidden_inode->i_mtime = hidden_inode->i_ctime = CURRENT_TIME;
  6501. +
  6502. + mark_inode_dirty_sync(inode);
  6503. +
  6504. + out_unlock:
  6505. + UnlockPage(hidden_page);
  6506. + page_cache_release(hidden_page);
  6507. + kunmap(page); /* kmap was done in prepare_write */
  6508. + out:
  6509. + /* we must set our page as up-to-date */
  6510. + if (err < 0)
  6511. + ClearPageUptodate(page);
  6512. + else
  6513. + SetPageUptodate(page);
  6514. +
  6515. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  6516. + mutex_unlock(&hidden_inode->i_mutex);
  6517. +#else
  6518. + up(&hidden_inode->i_sem);
  6519. +#endif
  6520. + print_exit_status(err);
  6521. + return err; /* assume all is ok */
  6522. +}
  6523. +
  6524. +
  6525. +STATIC int
  6526. +mini_fo_bmap(struct address_space *mapping, long block)
  6527. +{
  6528. + int err = 0;
  6529. + inode_t *inode;
  6530. + inode_t *hidden_inode;
  6531. +
  6532. + print_entry_location();
  6533. +
  6534. + inode = (inode_t *) mapping->host;
  6535. + hidden_inode = itohi(inode);
  6536. +
  6537. + if (hidden_inode->i_mapping->a_ops->bmap)
  6538. + err = hidden_inode->i_mapping->a_ops->bmap(hidden_inode->i_mapping, block);
  6539. + print_exit_location();
  6540. + return err;
  6541. +}
  6542. +
  6543. +
  6544. +/*
  6545. + * This function is copied verbatim from mm/filemap.c.
  6546. + * XXX: It should be simply moved to some header file instead -- bug Al about it!
  6547. + */
  6548. +static inline int sync_page(struct page *page)
  6549. +{
  6550. + struct address_space *mapping = page->mapping;
  6551. +
  6552. + if (mapping && mapping->a_ops && mapping->a_ops->sync_page)
  6553. + return mapping->a_ops->sync_page(page);
  6554. + return 0;
  6555. +}
  6556. +
  6557. +
  6558. +/*
  6559. + * XXX: we may not need this function if not FIST_FILTER_DATA.
  6560. + * FIXME: for FIST_FILTER_SCA, get all lower pages and sync them each.
  6561. + */
  6562. +STATIC int
  6563. +mini_fo_sync_page(page_t *page)
  6564. +{
  6565. + int err = 0;
  6566. + inode_t *inode;
  6567. + inode_t *hidden_inode;
  6568. + page_t *hidden_page;
  6569. +
  6570. + print_entry_location();
  6571. +
  6572. + inode = page->mapping->host; /* CPW: Moved below print_entry_location */
  6573. + hidden_inode = itohi(inode);
  6574. +
  6575. + /* find lower page (returns a locked page) */
  6576. + hidden_page = grab_cache_page(hidden_inode->i_mapping, page->index);
  6577. + if (!hidden_page)
  6578. + goto out;
  6579. +
  6580. + err = sync_page(hidden_page);
  6581. +
  6582. + UnlockPage(hidden_page); /* b/c grab_cache_page locked it */
  6583. + page_cache_release(hidden_page); /* b/c grab_cache_page increased refcnt */
  6584. +
  6585. + out:
  6586. + print_exit_status(err);
  6587. + return err;
  6588. +}
  6589. --- /dev/null
  6590. +++ b/fs/mini_fo/README
  6591. @@ -0,0 +1,163 @@
  6592. +README for the mini_fo overlay file system
  6593. +=========================================
  6594. +
  6595. +
  6596. +WHAT IS MINI_FO?
  6597. +----------------
  6598. +
  6599. +mini_fo is a virtual kernel file system that can make read-only
  6600. +file systems writable. This is done by redirecting modifying operations
  6601. +to a writeable location called "storage directory", and leaving the
  6602. +original data in the "base directory" untouched. When reading, the
  6603. +file system merges the modifed and original data so that only the
  6604. +newest versions will appear. This occurs transparently to the user,
  6605. +who can access the data like on any other read-write file system.
  6606. +
  6607. +Base and storage directories may be located on the same or on
  6608. +different partitions and may be of different file system types. While
  6609. +the storage directory obviously needs to be writable, the base may or
  6610. +may not be writable, what doesn't matter as it will no be modified
  6611. +anyway.
  6612. +
  6613. +
  6614. +WHAT IS GOOD FOR?
  6615. +-----------------
  6616. +
  6617. +The primary purpose of the mini_fo file system is to allow easy
  6618. +software updates to embedded systems, that often store their root
  6619. +file system in a read-only flash file system, but there are many
  6620. +more as for example sandboxing, or for allowing live-cds to
  6621. +permanently store information.
  6622. +
  6623. +
  6624. +BUILDING
  6625. +--------
  6626. +This should be simple. Adjust the Makefile to point to the correct
  6627. +kernel headers you want to build the module for. Then:
  6628. +
  6629. + # make
  6630. +
  6631. +should build "mini_fo.o" for a 2.4 kernel or "mini_fo.ko" for a 2.6
  6632. +kernel.
  6633. +
  6634. +If you are building the module for you current kernel, you can install
  6635. +the module (as root):
  6636. +
  6637. + # make install
  6638. +
  6639. +or uninstall with
  6640. +
  6641. + # make uninstall
  6642. +
  6643. +
  6644. +USING THE FILE SYSTEM
  6645. +--------------------
  6646. +
  6647. +the general mount syntax is:
  6648. +
  6649. + mount -t mini_fo -o base=<base directory>,sto=<storage directory>\
  6650. + <base directory> <mount point>
  6651. +
  6652. +Example:
  6653. +
  6654. +You have mounted a cdrom to /mnt/cdrom and want to modifiy some files
  6655. +on it:
  6656. +
  6657. +load the module (as root)
  6658. +
  6659. + # insmod mini_fo.o for a 2.4 kernel or
  6660. +
  6661. + # insmod mini_fo.ko for a 2.6 kernel
  6662. +
  6663. +
  6664. +create a storage dir in tmp and a mountpoint for mini_fo:
  6665. +
  6666. + # mkdir /tmp/sto
  6667. + # mkdir /mnt/mini_fo
  6668. +
  6669. +and mount the mini_fo file system:
  6670. +
  6671. + # mount -t mini_fo -o base=/mnt/cdrom,sto=/tmp/sto /mnt/cdrom /mnt/mini_fo
  6672. +
  6673. +
  6674. +Now the data stored on the cd can be accessed via the mini_fo
  6675. +mountpoint just like any read-write file system, files can be modified
  6676. +and deleted, new ones can be created and so on. When done unmount the
  6677. +file system:
  6678. +
  6679. + # unmount /mnt/mini_fo
  6680. +
  6681. +Note that if the file system is mounted again using the same storage
  6682. +file system, of course it will appear in the modified state again. If
  6683. +you remount it using an new empty storage directory, it will be
  6684. +unmodified. Therefore by executing:
  6685. +
  6686. + # cd /tmp/sto
  6687. + # rm -rf *
  6688. +
  6689. +you can nuke all the changes you made to the original file system. But
  6690. + remember NEVER do this while the mini_fo file system is mounted!
  6691. +
  6692. +
  6693. +Alternatively you can use the mini_fo-overlay bash script, that
  6694. +simplifies managing mini_fo mounts. See TOOLS Section.
  6695. +
  6696. +
  6697. +TOOLS
  6698. +-----
  6699. +
  6700. +mini_fo-merge (experimental):
  6701. +
  6702. +This is a bash script that will merge changes contained in the storage
  6703. +directory back to the base directory. This allows mini_fo to function
  6704. +as a cache file system by overlaying a slow (network, ...) file system
  6705. +and using a fast (ramdisk, ...) as storage. When done, changes can be
  6706. +merged back to the (slow) base with mini_fo-merge. See "mini_fo-merge
  6707. +-h" for details.
  6708. +
  6709. +It can be usefull for merging changes back after a successfull test
  6710. +(patches, software updates...)
  6711. +
  6712. +
  6713. +mini_fo-overlay:
  6714. +
  6715. +This bash script simplifies managing one or more mini_fo mounts. For
  6716. +overlaying a directory called "basedir1", you can just call:
  6717. +
  6718. + # mini_fo-overlay basedir1
  6719. +
  6720. +This will mount mini_fo with "basedir1" as base, "/tmp/sto-basedir1/"
  6721. +as storage to "/mnt/mini_fo-basedir1/". It has more options though,
  6722. +type "mini_fo-overlay -h" for details.
  6723. +
  6724. +
  6725. +DOCUMENTATION, REPORTING BUGS, GETTING HELP
  6726. +-------------------------------------------
  6727. +
  6728. +Please visit the mini_fo project page at:
  6729. +
  6730. +http://www.denx.de/twiki/bin/view/Know/MiniFOHome
  6731. +
  6732. +
  6733. +WARNINGS
  6734. +--------
  6735. +
  6736. +Never modify the base or the storage directorys while the mini_fo
  6737. +file system is mounted, or you might crash you system. Simply accessing
  6738. +and reading should not cause any trouble.
  6739. +
  6740. +Exporting a mini_fo mount point via NFS has not been tested, and may
  6741. +or may not work.
  6742. +
  6743. +Check the RELEASE_NOTES for details on bugs and features.
  6744. +
  6745. +
  6746. +
  6747. +Copyright (C) 2004, 2005 Markus Klotzbuecher <[email protected]>
  6748. +
  6749. +This program is free software; you can redistribute it and/or
  6750. +modify it under the terms of the GNU General Public License
  6751. +as published by the Free Software Foundation; either version
  6752. +2 of the License, or (at your option) any later version.
  6753. +
  6754. +
  6755. --- /dev/null
  6756. +++ b/fs/mini_fo/RELEASE_NOTES
  6757. @@ -0,0 +1,111 @@
  6758. +Release: mini_fo-0.6.1 (v0-6-1)
  6759. +Date: 21.09.2005
  6760. +
  6761. +
  6762. +Changes:
  6763. +--------
  6764. +v0-6-1:
  6765. +
  6766. +- bugfixes (see ChangeLog)
  6767. +
  6768. +- two helper scripts "mini_fo_merge" and "mini_fo_overlay" (see
  6769. + README for details).
  6770. +
  6771. +v0-6-0:
  6772. +
  6773. +- Support for 2.4 and 2.6 (see Makefile)
  6774. +
  6775. +- Partial hard link support (creating works as expected, but already
  6776. + existing links in the base file system will be treated as if they
  6777. + were individual files).
  6778. +
  6779. +- Various bugfixes and cleanups.
  6780. +
  6781. +
  6782. +v0-6-0-pre1:
  6783. +
  6784. +- This is mini_fo-0-6-0-pre1! This release is a complete rewrite of
  6785. + many vital mini_fo parts such as the old whiteout list code which
  6786. + has been replaced by the new META subsystem.
  6787. +
  6788. +- Light weight directory renaming implemented. This means if a
  6789. + directory is renamed via the mini_fo filesystem this will no longer
  6790. + result in a complete copy in storage, instead only one empty
  6791. + directory will be created. All base filed contained in the original
  6792. + directory stay there until modified.
  6793. +
  6794. +- Special files (creating, renaming, deleting etc.) now working.
  6795. +
  6796. +- Many bugfixes and cleanup, mini_fo is now a lot more stable.
  6797. +
  6798. +
  6799. +v0-5-10:
  6800. +
  6801. +- Final release of the 0-5-* versions. Next will be a complete rewrite
  6802. + of many features. This release contains several bugfixes related to
  6803. + directory renaming.
  6804. +
  6805. +
  6806. +v0-5-10-pre6:
  6807. +
  6808. +- Lots of cleanup and several bugfixes related to directory deleting
  6809. +
  6810. +- Directory renaming suddenly works, what is most likely due to the
  6811. + fact tha that "mv" is smart: if the classic rename doesn't work it
  6812. + will assume that source and target file are on different fs and will
  6813. + copy the directory and try to remove the source directory. Until
  6814. + directory removing wasn't implemented, it would fail to do this and
  6815. + rollback.
  6816. + So, directory renaming works for now, but it doesn't yet do what you
  6817. + would expect from a overlay fs, so use with care.
  6818. +
  6819. +
  6820. +v0-5-10-pre5:
  6821. +
  6822. +- implemented directory deleting
  6823. +- made parsing of mount options more stable
  6824. +- New format of mount options! (See README)
  6825. +- I can't reproduce the unknown panic with 2.4.25 anymore, so I'll
  6826. + happily assume it never existed!
  6827. +
  6828. +
  6829. +Implemented features:
  6830. +---------------------
  6831. +
  6832. +- creating hard links (see BUGS on already existing hard links)
  6833. +- lightweight directory renaming
  6834. +- renaming device files, pipes, sockets, etc.
  6835. +- creating, renaming, deleting of special files
  6836. +- deleting directorys
  6837. +- general directory reading (simple "ls" )
  6838. +- creating files in existing directorys
  6839. +- creating directorys
  6840. +- renaming files.
  6841. +- reading and writing files (involves opening)
  6842. +- appending to files (creates copy in storage)
  6843. +- deleting files
  6844. +- llseek works too, what allows editors to work
  6845. +- persistency (a deleted file stay deleted over remounts)
  6846. +- use of symbolic links
  6847. +- creating of device files
  6848. +
  6849. +
  6850. +Not (yet) implemented features:
  6851. +-------------------------------
  6852. +
  6853. +- full hard link support.
  6854. +
  6855. +
  6856. +
  6857. +BUGS:
  6858. +-----
  6859. +
  6860. +Hard links in the base file system will be treated as individual
  6861. +files, not as links to one inode.
  6862. +
  6863. +The main problem with hard links isn't allowing to create them, but
  6864. +their pure existence. If you modify a base hard link, the changes made
  6865. +will only show up on this link, the other link will remain in the
  6866. +original state. I hope to fix this someday. Please note that this does
  6867. +not effect the special hard links '.' and '..', that are handled
  6868. +seperately by the lower fs.
  6869. --- /dev/null
  6870. +++ b/fs/mini_fo/state.c
  6871. @@ -0,0 +1,620 @@
  6872. +/*
  6873. + * Copyright (C) 2005 Markus Klotzbuecher <[email protected]>
  6874. + *
  6875. + * This program is free software; you can redistribute it and/or
  6876. + * modify it under the terms of the GNU General Public License
  6877. + * as published by the Free Software Foundation; either version
  6878. + * 2 of the License, or (at your option) any later version.
  6879. + */
  6880. +
  6881. +#ifdef HAVE_CONFIG_H
  6882. +# include <config.h>
  6883. +#endif /* HAVE_CONFIG_H */
  6884. +
  6885. +#include "fist.h"
  6886. +#include "mini_fo.h"
  6887. +
  6888. +
  6889. +/* create the storage file, setup new states */
  6890. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  6891. +int create_sto_reg_file(dentry_t *dentry, int mode, struct nameidata *nd)
  6892. +#else
  6893. +int create_sto_reg_file(dentry_t *dentry, int mode)
  6894. +#endif
  6895. +{
  6896. + int err = 0;
  6897. + inode_t *dir;
  6898. + dentry_t *hidden_sto_dentry;
  6899. + dentry_t *hidden_sto_dir_dentry;
  6900. +
  6901. + if(exists_in_storage(dentry)) {
  6902. + printk(KERN_CRIT "mini_fo: create_sto_file: wrong type or state.\n");
  6903. + err = -EINVAL;
  6904. + goto out;
  6905. + }
  6906. + err = get_neg_sto_dentry(dentry);
  6907. +
  6908. + if (err) {
  6909. + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR getting neg. sto dentry.\n");
  6910. + goto out;
  6911. + }
  6912. +
  6913. + dir = dentry->d_parent->d_inode;
  6914. + hidden_sto_dentry = dtohd2(dentry);
  6915. +
  6916. + /* lock parent */
  6917. + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
  6918. +
  6919. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  6920. + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  6921. +#else
  6922. + down(&hidden_sto_dir_dentry->d_inode->i_sem);
  6923. +#endif
  6924. +
  6925. + err = PTR_ERR(hidden_sto_dir_dentry);
  6926. + if (IS_ERR(hidden_sto_dir_dentry))
  6927. + goto out;
  6928. +
  6929. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  6930. + err = vfs_create(hidden_sto_dir_dentry->d_inode,
  6931. + hidden_sto_dentry,
  6932. + mode, nd);
  6933. +#else
  6934. + err = vfs_create(hidden_sto_dir_dentry->d_inode,
  6935. + hidden_sto_dentry,
  6936. + mode);
  6937. +#endif
  6938. + if(err) {
  6939. + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file.\n");
  6940. + goto out_lock;
  6941. + }
  6942. +
  6943. + if(!dtohd2(dentry)->d_inode) {
  6944. + printk(KERN_CRIT "mini_fo: create_sto_file: ERROR creating sto file [2].\n");
  6945. + err = -EINVAL;
  6946. + goto out_lock;
  6947. + }
  6948. +
  6949. + /* interpose the new inode */
  6950. + if(dtost(dentry) == DELETED) {
  6951. + dtost(dentry) = DEL_REWRITTEN;
  6952. + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
  6953. + if(err)
  6954. + goto out_lock;
  6955. + }
  6956. + else if(dtost(dentry) == NON_EXISTANT) {
  6957. + dtost(dentry) = CREATED;
  6958. + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
  6959. + if(err)
  6960. + goto out_lock;
  6961. + }
  6962. + else if(dtost(dentry) == UNMODIFIED) {
  6963. + dtost(dentry) = MODIFIED;
  6964. + /* interpose on new inode */
  6965. + if(itohi2(dentry->d_inode) != NULL) {
  6966. + printk(KERN_CRIT "mini_fo: create_sto_file: invalid inode detected.\n");
  6967. + err = -EINVAL;
  6968. + goto out_lock;
  6969. + }
  6970. + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
  6971. + }
  6972. + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
  6973. + hidden_sto_dir_dentry->d_inode);
  6974. +
  6975. + out_lock:
  6976. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  6977. + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  6978. +#else
  6979. + up(&hidden_sto_dir_dentry->d_inode->i_sem);
  6980. +#endif
  6981. + dput(hidden_sto_dir_dentry);
  6982. + out:
  6983. + return err;
  6984. +}
  6985. +
  6986. +/* create the sto dir, setup states */
  6987. +int create_sto_dir(dentry_t *dentry, int mode)
  6988. +{
  6989. + int err = 0;
  6990. + inode_t *dir;
  6991. + dentry_t *hidden_sto_dentry;
  6992. + dentry_t *hidden_sto_dir_dentry;
  6993. +
  6994. + /* had to take the "!S_ISDIR(mode))" check out, because it failed */
  6995. + if(exists_in_storage(dentry)) {
  6996. + printk(KERN_CRIT "mini_fo: create_sto_dir: wrong type or state.\\
  6997. +n");
  6998. + err = -EINVAL;
  6999. + goto out;
  7000. + }
  7001. +
  7002. + err = get_neg_sto_dentry(dentry);
  7003. + if(err) {
  7004. + err = -EINVAL;
  7005. + goto out;
  7006. + }
  7007. +
  7008. + dir = dentry->d_parent->d_inode;
  7009. + hidden_sto_dentry = dtohd2(dentry);
  7010. +
  7011. + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
  7012. + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
  7013. +
  7014. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  7015. + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  7016. +#else
  7017. + down(&hidden_sto_dir_dentry->d_inode->i_sem);
  7018. +#endif
  7019. +
  7020. + err = PTR_ERR(hidden_sto_dir_dentry);
  7021. + if (IS_ERR(hidden_sto_dir_dentry))
  7022. + goto out;
  7023. +
  7024. + err = vfs_mkdir(hidden_sto_dir_dentry->d_inode,
  7025. + hidden_sto_dentry,
  7026. + mode);
  7027. + if(err) {
  7028. + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir.\n");
  7029. + goto out_lock;
  7030. + }
  7031. +
  7032. + if(!dtohd2(dentry)->d_inode) {
  7033. + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR creating sto dir [2].\n");
  7034. + err = -EINVAL;
  7035. + goto out_lock;
  7036. + }
  7037. +
  7038. + /* interpose the new inode */
  7039. + if(dtost(dentry) == DELETED) {
  7040. + dtost(dentry) = DEL_REWRITTEN;
  7041. + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
  7042. + if(err)
  7043. + goto out_lock;
  7044. + }
  7045. + else if(dtopd(dentry)->state == NON_EXISTANT) {
  7046. + dtopd(dentry)->state = CREATED;
  7047. + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
  7048. + if(err)
  7049. + goto out_lock;
  7050. + }
  7051. + else if(dtopd(dentry)->state == UNMODIFIED) {
  7052. + dtopd(dentry)->state = MODIFIED;
  7053. + /* interpose on new inode */
  7054. + if(itohi2(dentry->d_inode) != NULL) {
  7055. + printk(KERN_CRIT "mini_fo: create_sto_dir: ERROR, invalid inode detected.\n");
  7056. + err = -EINVAL;
  7057. + goto out_lock;
  7058. + }
  7059. + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
  7060. + }
  7061. +
  7062. + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
  7063. +
  7064. + /* initalize the wol list */
  7065. + itopd(dentry->d_inode)->deleted_list_size = -1;
  7066. + itopd(dentry->d_inode)->renamed_list_size = -1;
  7067. + meta_build_lists(dentry);
  7068. +
  7069. +
  7070. + out_lock:
  7071. + /* was: unlock_dir(hidden_sto_dir_dentry); */
  7072. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  7073. + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  7074. +#else
  7075. + up(&hidden_sto_dir_dentry->d_inode->i_sem);
  7076. +#endif
  7077. + dput(hidden_sto_dir_dentry);
  7078. + out:
  7079. + return err;
  7080. +}
  7081. +
  7082. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  7083. +int create_sto_nod(dentry_t *dentry, int mode, dev_t dev)
  7084. +#else
  7085. +int create_sto_nod(dentry_t *dentry, int mode, int dev)
  7086. +#endif
  7087. +{
  7088. + int err = 0;
  7089. + inode_t *dir;
  7090. + dentry_t *hidden_sto_dentry;
  7091. + dentry_t *hidden_sto_dir_dentry;
  7092. +
  7093. + if(exists_in_storage(dentry)) {
  7094. + err = -EEXIST;
  7095. + goto out;
  7096. + }
  7097. + err = get_neg_sto_dentry(dentry);
  7098. +
  7099. + if (err) {
  7100. + printk(KERN_CRIT "mini_fo: create_sto_nod: ERROR getting neg. sto dentry.\n");
  7101. + goto out;
  7102. + }
  7103. +
  7104. + dir = dentry->d_parent->d_inode;
  7105. + hidden_sto_dentry = dtohd2(dentry);
  7106. +
  7107. + /* lock parent */
  7108. + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
  7109. +
  7110. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  7111. + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  7112. +#else
  7113. + down(&hidden_sto_dir_dentry->d_inode->i_sem);
  7114. +#endif
  7115. +
  7116. + err = PTR_ERR(hidden_sto_dir_dentry);
  7117. + if (IS_ERR(hidden_sto_dir_dentry))
  7118. + goto out;
  7119. +
  7120. + err = vfs_mknod(hidden_sto_dir_dentry->d_inode, hidden_sto_dentry, mode, dev);
  7121. + if(err)
  7122. + goto out_lock;
  7123. +
  7124. + if(!dtohd2(dentry)->d_inode) {
  7125. + printk(KERN_CRIT "mini_fo: create_sto_nod: creating storage inode failed [1].\n");
  7126. + err = -EINVAL; /* return something indicating failure */
  7127. + goto out_lock;
  7128. + }
  7129. +
  7130. + /* interpose the new inode */
  7131. + if(dtost(dentry) == DELETED) {
  7132. + dtost(dentry) = DEL_REWRITTEN;
  7133. + err = mini_fo_tri_interpose(NULL, hidden_sto_dentry, dentry, dir->i_sb, 0);
  7134. + if(err)
  7135. + goto out_lock;
  7136. + }
  7137. + else if(dtost(dentry) == NON_EXISTANT) {
  7138. + dtost(dentry) = CREATED;
  7139. + err = mini_fo_tri_interpose(dtohd(dentry), hidden_sto_dentry, dentry, dir->i_sb, 0);
  7140. + if(err)
  7141. + goto out_lock;
  7142. + }
  7143. + else if(dtost(dentry) == UNMODIFIED) {
  7144. + dtost(dentry) = MODIFIED;
  7145. + /* interpose on new inode */
  7146. + if(itohi2(dentry->d_inode) != NULL) {
  7147. + printk(KERN_CRIT "mini_fo: create_sto_nod: error, invalid inode detected.\n");
  7148. + err = -EINVAL;
  7149. + goto out_lock;
  7150. + }
  7151. + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
  7152. + }
  7153. +
  7154. + fist_copy_attr_timesizes(dir, hidden_sto_dir_dentry->d_inode);
  7155. +
  7156. + out_lock:
  7157. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  7158. + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  7159. +#else
  7160. + up(&hidden_sto_dir_dentry->d_inode->i_sem);
  7161. +#endif
  7162. + dput(hidden_sto_dir_dentry);
  7163. + out:
  7164. + return err;
  7165. +}
  7166. +
  7167. +
  7168. +/* unimplemented (and possibly not usefull):
  7169. +
  7170. + nondir-del_to_del_rew
  7171. + nondir-non_exist_to_creat
  7172. +
  7173. + dir-unmod_to_del
  7174. + dir-mod_to_del
  7175. + dir-creat_to_del
  7176. + dir-del_rew_to_del
  7177. + dir-del_to_del_rew
  7178. + dir-non_exist_to_creat
  7179. +*/
  7180. +
  7181. +
  7182. +/* bring a file of any type from state UNMODIFIED to MODIFIED */
  7183. +int nondir_unmod_to_mod(dentry_t *dentry, int cp_flag)
  7184. +{
  7185. + int err = 0;
  7186. + struct vfsmount *tgt_mnt;
  7187. + struct vfsmount *src_mnt;
  7188. + dentry_t *tgt_dentry;
  7189. + dentry_t *src_dentry;
  7190. + dentry_t *hidden_sto_dentry;
  7191. + dentry_t *hidden_sto_dir_dentry;
  7192. +
  7193. + check_mini_fo_dentry(dentry);
  7194. +
  7195. + if((dtost(dentry) != UNMODIFIED) ||
  7196. + S_ISDIR(dentry->d_inode->i_mode)) {
  7197. + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
  7198. + wrong type or state.\n");
  7199. + err = -1;
  7200. + goto out;
  7201. + }
  7202. + err = get_neg_sto_dentry(dentry);
  7203. +
  7204. + if (err) {
  7205. + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
  7206. + ERROR getting neg. sto dentry.\n");
  7207. + goto out;
  7208. + }
  7209. +
  7210. + /* create sto file */
  7211. + hidden_sto_dentry = dtohd2(dentry);
  7212. +
  7213. + /* lock parent */
  7214. + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
  7215. +
  7216. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  7217. + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  7218. +#else
  7219. + down(&hidden_sto_dir_dentry->d_inode->i_sem);
  7220. +#endif
  7221. +
  7222. + err = PTR_ERR(hidden_sto_dir_dentry);
  7223. + if (IS_ERR(hidden_sto_dir_dentry))
  7224. + goto out;
  7225. +
  7226. + /* handle different types of nondirs */
  7227. + if(S_ISCHR(dentry->d_inode->i_mode) ||
  7228. + S_ISBLK(dentry->d_inode->i_mode)) {
  7229. + err = vfs_mknod(hidden_sto_dir_dentry->d_inode,
  7230. + hidden_sto_dentry,
  7231. + dtohd(dentry)->d_inode->i_mode,
  7232. + dtohd(dentry)->d_inode->i_rdev);
  7233. + }
  7234. +
  7235. + else if(S_ISREG(dentry->d_inode->i_mode)) {
  7236. +
  7237. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  7238. + err = vfs_create(hidden_sto_dir_dentry->d_inode,
  7239. + hidden_sto_dentry,
  7240. + dtohd(dentry)->d_inode->i_mode, NULL);
  7241. +#else
  7242. + err = vfs_create(hidden_sto_dir_dentry->d_inode,
  7243. + hidden_sto_dentry,
  7244. + dtohd(dentry)->d_inode->i_mode);
  7245. +#endif
  7246. + }
  7247. + if(err) {
  7248. + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
  7249. + ERROR creating sto file.\n");
  7250. + goto out_lock;
  7251. + }
  7252. +
  7253. + /* interpose on new inode */
  7254. + if(itohi2(dentry->d_inode) != NULL) {
  7255. + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
  7256. + ERROR, invalid inode detected.\n");
  7257. + err = -EINVAL;
  7258. + goto out_lock;
  7259. + }
  7260. +
  7261. + itohi2(dentry->d_inode) = igrab(dtohd2(dentry)->d_inode);
  7262. +
  7263. + fist_copy_attr_timesizes(dentry->d_parent->d_inode,
  7264. + hidden_sto_dir_dentry->d_inode);
  7265. + dtost(dentry) = MODIFIED;
  7266. +
  7267. + /* copy contents if regular file and cp_flag = 1 */
  7268. + if((cp_flag == 1) && S_ISREG(dentry->d_inode->i_mode)) {
  7269. +
  7270. + /* unlock first */
  7271. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  7272. + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  7273. +#else
  7274. + up(&hidden_sto_dir_dentry->d_inode->i_sem);
  7275. +#endif
  7276. +
  7277. + dput(hidden_sto_dir_dentry);
  7278. +
  7279. + tgt_dentry = dtohd2(dentry);
  7280. + tgt_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt2;
  7281. + src_dentry = dtohd(dentry);
  7282. + src_mnt = stopd(dentry->d_inode->i_sb)->hidden_mnt;
  7283. +
  7284. + err = mini_fo_cp_cont(tgt_dentry, tgt_mnt,
  7285. + src_dentry, src_mnt);
  7286. + if(err) {
  7287. + printk(KERN_CRIT "mini_fo: nondir_unmod_to_mod: \
  7288. + ERROR copying contents.\n");
  7289. + }
  7290. + goto out;
  7291. + }
  7292. +
  7293. + out_lock:
  7294. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  7295. + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  7296. +#else
  7297. + up(&hidden_sto_dir_dentry->d_inode->i_sem);
  7298. +#endif
  7299. + dput(hidden_sto_dir_dentry);
  7300. + out:
  7301. + return err;
  7302. +}
  7303. +
  7304. +/* this function is currently identical to nondir_creat_to_del */
  7305. +int nondir_del_rew_to_del(dentry_t *dentry)
  7306. +{
  7307. + return nondir_creat_to_del(dentry);
  7308. +}
  7309. +
  7310. +int nondir_creat_to_del(dentry_t *dentry)
  7311. +{
  7312. + int err = 0;
  7313. +
  7314. + inode_t *hidden_sto_dir_inode;
  7315. + dentry_t *hidden_sto_dir_dentry;
  7316. + dentry_t *hidden_sto_dentry;
  7317. +
  7318. + check_mini_fo_dentry(dentry);
  7319. +
  7320. + /* for now this function serves for both state DEL_REWRITTEN and
  7321. + * CREATED */
  7322. + if(!(dtost(dentry) == CREATED || (dtost(dentry) == DEL_REWRITTEN)) ||
  7323. + S_ISDIR(dentry->d_inode->i_mode)) {
  7324. + printk(KERN_CRIT "mini_fo: nondir_mod_to_del/del_rew_to_del: \
  7325. + wrong type or state.\n");
  7326. + err = -1;
  7327. + goto out;
  7328. + }
  7329. +
  7330. + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
  7331. + hidden_sto_dentry = dtohd2(dentry);
  7332. +
  7333. + /* was: hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry);*/
  7334. + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
  7335. +
  7336. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  7337. + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  7338. +#else
  7339. + down(&hidden_sto_dir_dentry->d_inode->i_sem);
  7340. +#endif
  7341. +
  7342. + /* avoid destroying the hidden inode if the file is in use */
  7343. + dget(hidden_sto_dentry);
  7344. + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
  7345. + dput(hidden_sto_dentry);
  7346. + if(!err)
  7347. + d_delete(hidden_sto_dentry);
  7348. +
  7349. + /* propagate number of hard-links */
  7350. + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
  7351. +
  7352. + dtost(dentry) = NON_EXISTANT;
  7353. +
  7354. + /* was: unlock_dir(hidden_sto_dir_dentry); */
  7355. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  7356. + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  7357. +#else
  7358. + up(&hidden_sto_dir_dentry->d_inode->i_sem);
  7359. +#endif
  7360. + dput(hidden_sto_dir_dentry);
  7361. +
  7362. + out:
  7363. + return err;
  7364. +}
  7365. +
  7366. +int nondir_mod_to_del(dentry_t *dentry)
  7367. +{
  7368. + int err;
  7369. + dentry_t *hidden_sto_dentry;
  7370. + inode_t *hidden_sto_dir_inode;
  7371. + dentry_t *hidden_sto_dir_dentry;
  7372. +
  7373. + check_mini_fo_dentry(dentry);
  7374. +
  7375. + if(dtost(dentry) != MODIFIED ||
  7376. + S_ISDIR(dentry->d_inode->i_mode)) {
  7377. + printk(KERN_CRIT "mini_fo: nondir_mod_to_del: \
  7378. + wrong type or state.\n");
  7379. + err = -1;
  7380. + goto out;
  7381. + }
  7382. +
  7383. + hidden_sto_dir_inode = itohi2(dentry->d_parent->d_inode);
  7384. + hidden_sto_dentry = dtohd2(dentry);
  7385. +
  7386. + /* was hidden_sto_dir_dentry = lock_parent(hidden_sto_dentry); */
  7387. + hidden_sto_dir_dentry = dget(hidden_sto_dentry->d_parent);
  7388. +
  7389. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  7390. + mutex_lock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  7391. +#else
  7392. + down(&hidden_sto_dir_dentry->d_inode->i_sem);
  7393. +#endif
  7394. +
  7395. + /* avoid destroying the hidden inode if the file is in use */
  7396. + dget(hidden_sto_dentry);
  7397. + err = vfs_unlink(hidden_sto_dir_inode, hidden_sto_dentry);
  7398. + dput(hidden_sto_dentry);
  7399. + if(!err)
  7400. + d_delete(hidden_sto_dentry);
  7401. +
  7402. + /* propagate number of hard-links */
  7403. + dentry->d_inode->i_nlink = itohi2(dentry->d_inode)->i_nlink;
  7404. +
  7405. + /* dput base dentry, this will relase the inode and free the
  7406. + * dentry, as we will never need it again. */
  7407. + dput(dtohd(dentry));
  7408. + dtohd(dentry) = NULL;
  7409. + dtost(dentry) = DELETED;
  7410. +
  7411. + /* add deleted file to META-file */
  7412. + meta_add_d_entry(dentry->d_parent,
  7413. + dentry->d_name.name,
  7414. + dentry->d_name.len);
  7415. +
  7416. + /* was: unlock_dir(hidden_sto_dir_dentry); */
  7417. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
  7418. + mutex_unlock(&hidden_sto_dir_dentry->d_inode->i_mutex);
  7419. +#else
  7420. + up(&hidden_sto_dir_dentry->d_inode->i_sem);
  7421. +#endif
  7422. + dput(hidden_sto_dir_dentry);
  7423. +
  7424. + out:
  7425. + return err;
  7426. +}
  7427. +
  7428. +int nondir_unmod_to_del(dentry_t *dentry)
  7429. +{
  7430. + int err = 0;
  7431. +
  7432. + check_mini_fo_dentry(dentry);
  7433. +
  7434. + if(dtost(dentry) != UNMODIFIED ||
  7435. + S_ISDIR(dentry->d_inode->i_mode)) {
  7436. + printk(KERN_CRIT "mini_fo: nondir_unmod_to_del: \
  7437. + wrong type or state.\n");
  7438. + err = -1;
  7439. + goto out;
  7440. + }
  7441. +
  7442. + /* next we have to get a negative dentry for the storage file */
  7443. + err = get_neg_sto_dentry(dentry);
  7444. +
  7445. + if(err)
  7446. + goto out;
  7447. +
  7448. + /* add deleted file to META lists */
  7449. + err = meta_add_d_entry(dentry->d_parent,
  7450. + dentry->d_name.name,
  7451. + dentry->d_name.len);
  7452. +
  7453. + if(err)
  7454. + goto out;
  7455. +
  7456. + /* dput base dentry, this will relase the inode and free the
  7457. + * dentry, as we will never need it again. */
  7458. + dput(dtohd(dentry));
  7459. + dtohd(dentry) = NULL;
  7460. + dtost(dentry) = DELETED;
  7461. +
  7462. + out:
  7463. + return err;
  7464. +}
  7465. +
  7466. +/* bring a dir from state UNMODIFIED to MODIFIED */
  7467. +int dir_unmod_to_mod(dentry_t *dentry)
  7468. +{
  7469. + int err;
  7470. +
  7471. + check_mini_fo_dentry(dentry);
  7472. +
  7473. + if(dtost(dentry) != UNMODIFIED ||
  7474. + !S_ISDIR(dentry->d_inode->i_mode)) {
  7475. + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
  7476. + wrong type or state.\n");
  7477. + err = -1;
  7478. + goto out;
  7479. + }
  7480. +
  7481. + /* this creates our dir incl. sto. structure */
  7482. + err = build_sto_structure(dentry->d_parent, dentry);
  7483. + if(err) {
  7484. + printk(KERN_CRIT "mini_fo: dir_unmod_to_mod: \
  7485. + build_sto_structure failed.\n");
  7486. + goto out;
  7487. + }
  7488. + out:
  7489. + return err;
  7490. +}
  7491. +
  7492. --- /dev/null
  7493. +++ b/fs/mini_fo/super.c
  7494. @@ -0,0 +1,281 @@
  7495. +/*
  7496. + * Copyright (c) 1997-2003 Erez Zadok
  7497. + * Copyright (c) 2001-2003 Stony Brook University
  7498. + *
  7499. + * For specific licensing information, see the COPYING file distributed with
  7500. + * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING.
  7501. + *
  7502. + * This Copyright notice must be kept intact and distributed with all
  7503. + * fistgen sources INCLUDING sources generated by fistgen.
  7504. + */
  7505. +/*
  7506. + * Copyright (C) 2004, 2005 Markus Klotzbuecher <[email protected]>
  7507. + *
  7508. + * This program is free software; you can redistribute it and/or
  7509. + * modify it under the terms of the GNU General Public License
  7510. + * as published by the Free Software Foundation; either version
  7511. + * 2 of the License, or (at your option) any later version.
  7512. + */
  7513. +
  7514. +/*
  7515. + * $Id$
  7516. + */
  7517. +
  7518. +#ifdef HAVE_CONFIG_H
  7519. +# include <config.h>
  7520. +#endif
  7521. +
  7522. +#include "fist.h"
  7523. +#include "mini_fo.h"
  7524. +
  7525. +
  7526. +STATIC void
  7527. +mini_fo_read_inode(inode_t *inode)
  7528. +{
  7529. + static struct address_space_operations mini_fo_empty_aops;
  7530. +
  7531. + __itopd(inode) = kmalloc(sizeof(struct mini_fo_inode_info), GFP_KERNEL);
  7532. + if (!itopd(inode)) {
  7533. + printk("<0>%s:%s:%d: No kernel memory!\n", __FILE__, __FUNCTION__, __LINE__);
  7534. + ASSERT(NULL);
  7535. + }
  7536. + itohi(inode) = NULL;
  7537. + itohi2(inode) = NULL;
  7538. +
  7539. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  7540. + inode->i_version++;
  7541. +#else
  7542. + inode->i_version = ++event; /* increment inode version */
  7543. +#endif
  7544. + inode->i_op = &mini_fo_main_iops;
  7545. + inode->i_fop = &mini_fo_main_fops;
  7546. +#if 0
  7547. + /*
  7548. + * XXX: To export a file system via NFS, it has to have the
  7549. + * FS_REQUIRES_DEV flag, so turn it on. But should we inherit it from
  7550. + * the lower file system, or can we allow our file system to be exported
  7551. + * even if the lower one cannot be natively exported.
  7552. + */
  7553. + inode->i_sb->s_type->fs_flags |= FS_REQUIRES_DEV;
  7554. + /*
  7555. + * OK, the above was a hack, which is now turned off because it may
  7556. + * cause a panic/oops on some systems. The correct way to export a
  7557. + * "nodev" filesystem is via using nfs-utils > 1.0 and the "fsid=" export
  7558. + * parameter, which requires 2.4.20 or later.
  7559. + */
  7560. +#endif
  7561. + /* I don't think ->a_ops is ever allowed to be NULL */
  7562. + inode->i_mapping->a_ops = &mini_fo_empty_aops;
  7563. +}
  7564. +
  7565. +
  7566. +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
  7567. +/*
  7568. + * No need to call write_inode() on the lower inode, as it
  7569. + * will have been marked 'dirty' anyway. But we might need
  7570. + * to write some of our own stuff to disk.
  7571. + */
  7572. +STATIC void
  7573. +mini_fo_write_inode(inode_t *inode, int sync)
  7574. +{
  7575. + print_entry_location();
  7576. + print_exit_location();
  7577. +}
  7578. +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
  7579. +
  7580. +
  7581. +STATIC void
  7582. +mini_fo_put_inode(inode_t *inode)
  7583. +{
  7584. + /*
  7585. + * This is really funky stuff:
  7586. + * Basically, if i_count == 1, iput will then decrement it and this inode will be destroyed.
  7587. + * It is currently holding a reference to the hidden inode.
  7588. + * Therefore, it needs to release that reference by calling iput on the hidden inode.
  7589. + * iput() _will_ do it for us (by calling our clear_inode), but _only_ if i_nlink == 0.
  7590. + * The problem is, NFS keeps i_nlink == 1 for silly_rename'd files.
  7591. + * So we must for our i_nlink to 0 here to trick iput() into calling our clear_inode.
  7592. + */
  7593. + if (atomic_read(&inode->i_count) == 1)
  7594. + inode->i_nlink = 0;
  7595. +}
  7596. +
  7597. +
  7598. +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
  7599. +/*
  7600. + * we now define delete_inode, because there are two VFS paths that may
  7601. + * destroy an inode: one of them calls clear inode before doing everything
  7602. + * else that's needed, and the other is fine. This way we truncate the inode
  7603. + * size (and its pages) and then clear our own inode, which will do an iput
  7604. + * on our and the lower inode.
  7605. + */
  7606. +STATIC void
  7607. +mini_fo_delete_inode(inode_t *inode)
  7608. +{
  7609. + print_entry_location();
  7610. +
  7611. + fist_checkinode(inode, "mini_fo_delete_inode IN");
  7612. + inode->i_size = 0; /* every f/s seems to do that */
  7613. + clear_inode(inode);
  7614. +
  7615. + print_exit_location();
  7616. +}
  7617. +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
  7618. +
  7619. +
  7620. +/* final actions when unmounting a file system */
  7621. +STATIC void
  7622. +mini_fo_put_super(super_block_t *sb)
  7623. +{
  7624. + if (stopd(sb)) {
  7625. + mntput(stopd(sb)->hidden_mnt);
  7626. + mntput(stopd(sb)->hidden_mnt2);
  7627. +
  7628. + /* mk: no! dput(stopd(sb)->base_dir_dentry);
  7629. + dput(stopd(sb)->storage_dir_dentry); */
  7630. +
  7631. + kfree(stopd(sb));
  7632. + __stopd(sb) = NULL;
  7633. + }
  7634. +}
  7635. +
  7636. +
  7637. +#ifdef NOT_NEEDED
  7638. +/*
  7639. + * This is called in do_umount before put_super.
  7640. + * The superblock lock is not held yet.
  7641. + * We probably do not need to define this or call write_super
  7642. + * on the hidden_sb, because sync_supers() will get to hidden_sb
  7643. + * sooner or later. But it is also called from file_fsync()...
  7644. + */
  7645. +STATIC void
  7646. +mini_fo_write_super(super_block_t *sb)
  7647. +{
  7648. + return;
  7649. +}
  7650. +#endif /* NOT_NEEDED */
  7651. +
  7652. +
  7653. +STATIC int
  7654. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
  7655. +mini_fo_statfs(struct dentry *d, struct kstatfs *buf)
  7656. +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
  7657. +mini_fo_statfs(super_block_t *sb, struct kstatfs *buf)
  7658. +#else
  7659. +mini_fo_statfs(super_block_t *sb, struct statfs *buf)
  7660. +#endif
  7661. +{
  7662. + int err = 0;
  7663. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
  7664. + struct dentry *hidden_d;
  7665. +
  7666. + hidden_d = dtohd(d);
  7667. + err = vfs_statfs(hidden_d, buf);
  7668. +#else
  7669. + super_block_t *hidden_sb;
  7670. +
  7671. + hidden_sb = stohs(sb);
  7672. + err = vfs_statfs(hidden_sb, buf);
  7673. +#endif
  7674. +
  7675. + return err;
  7676. +}
  7677. +
  7678. +
  7679. +/*
  7680. + * XXX: not implemented. This is not allowed yet.
  7681. + * Should we call this on the hidden_sb? Probably not.
  7682. + */
  7683. +STATIC int
  7684. +mini_fo_remount_fs(super_block_t *sb, int *flags, char *data)
  7685. +{
  7686. + //printk(KERN_CRIT "mini_fo_remount_fs: WARNING, this function is umimplemented.\n");
  7687. + return -ENOSYS;
  7688. +}
  7689. +
  7690. +
  7691. +/*
  7692. + * Called by iput() when the inode reference count reached zero
  7693. + * and the inode is not hashed anywhere. Used to clear anything
  7694. + * that needs to be, before the inode is completely destroyed and put
  7695. + * on the inode free list.
  7696. + */
  7697. +STATIC void
  7698. +mini_fo_clear_inode(inode_t *inode)
  7699. +{
  7700. + /*
  7701. + * Decrement a reference to a hidden_inode, which was incremented
  7702. + * by our read_inode when it was created initially.
  7703. + */
  7704. +
  7705. + /* release the wol_list */
  7706. + if(S_ISDIR(inode->i_mode)) {
  7707. + __meta_put_lists(inode);
  7708. + }
  7709. +
  7710. + /* mk: fan out fun */
  7711. + if(itohi(inode))
  7712. + iput(itohi(inode));
  7713. + if(itohi2(inode))
  7714. + iput(itohi2(inode));
  7715. +
  7716. + // XXX: why this assertion fails?
  7717. + // because it doesn't like us
  7718. + // ASSERT((inode->i_state & I_DIRTY) == 0);
  7719. + kfree(itopd(inode));
  7720. + __itopd(inode) = NULL;
  7721. +}
  7722. +
  7723. +
  7724. +/*
  7725. + * Called in do_umount() if the MNT_FORCE flag was used and this
  7726. + * function is defined. See comment in linux/fs/super.c:do_umount().
  7727. + * Used only in nfs, to kill any pending RPC tasks, so that subsequent
  7728. + * code can actually succeed and won't leave tasks that need handling.
  7729. + *
  7730. + * PS. I wonder if this is somehow useful to undo damage that was
  7731. + * left in the kernel after a user level file server (such as amd)
  7732. + * dies.
  7733. + */
  7734. +STATIC void
  7735. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
  7736. +mini_fo_umount_begin(struct vfsmount *mnt, int flags)
  7737. +{
  7738. + struct vfsmount *hidden_mnt;
  7739. +
  7740. + hidden_mnt = stopd(mnt->mnt_sb)->hidden_mnt;
  7741. +
  7742. + if (hidden_mnt->mnt_sb->s_op->umount_begin)
  7743. + hidden_mnt->mnt_sb->s_op->umount_begin(hidden_mnt, flags);
  7744. +
  7745. +}
  7746. +#else
  7747. +mini_fo_umount_begin(super_block_t *sb)
  7748. +{
  7749. + super_block_t *hidden_sb;
  7750. +
  7751. + hidden_sb = stohs(sb);
  7752. +
  7753. + if (hidden_sb->s_op->umount_begin)
  7754. + hidden_sb->s_op->umount_begin(hidden_sb);
  7755. +
  7756. +}
  7757. +#endif
  7758. +
  7759. +
  7760. +struct super_operations mini_fo_sops =
  7761. +{
  7762. + read_inode: mini_fo_read_inode,
  7763. +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
  7764. + write_inode: mini_fo_write_inode,
  7765. +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
  7766. + put_inode: mini_fo_put_inode,
  7767. +#if defined(FIST_DEBUG) || defined(FIST_FILTER_SCA)
  7768. + delete_inode: mini_fo_delete_inode,
  7769. +#endif /* defined(FIST_DEBUG) || defined(FIST_FILTER_SCA) */
  7770. + put_super: mini_fo_put_super,
  7771. + statfs: mini_fo_statfs,
  7772. + remount_fs: mini_fo_remount_fs,
  7773. + clear_inode: mini_fo_clear_inode,
  7774. + umount_begin: mini_fo_umount_begin,
  7775. +};