209-mini_fo.patch 217 KB

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