209-mini_fo.patch 215 KB

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