231-mini_fo.patch 215 KB

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