231-mini_fo.patch 212 KB

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