209-mini_fo.patch 213 KB

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