test_paths.toml 216 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250
  1. # simple path test
  2. [cases.test_paths_simple]
  3. defines.DIR = [false, true]
  4. code = '''
  5. lfs_t lfs;
  6. lfs_format(&lfs, cfg) => 0;
  7. lfs_mount(&lfs, cfg) => 0;
  8. // create paths
  9. lfs_mkdir(&lfs, "coffee") => 0;
  10. if (DIR) {
  11. lfs_mkdir(&lfs, "coffee/drip") => 0;
  12. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  13. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  14. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  15. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  16. lfs_mkdir(&lfs, "coffee/thai") => 0;
  17. } else {
  18. lfs_file_t file;
  19. lfs_file_open(&lfs, &file, "coffee/drip",
  20. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  21. lfs_file_close(&lfs, &file) => 0;
  22. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  23. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  24. lfs_file_close(&lfs, &file) => 0;
  25. lfs_file_open(&lfs, &file, "coffee/turkish",
  26. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  27. lfs_file_close(&lfs, &file) => 0;
  28. lfs_file_open(&lfs, &file, "coffee/tubruk",
  29. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  30. lfs_file_close(&lfs, &file) => 0;
  31. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  32. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  33. lfs_file_close(&lfs, &file) => 0;
  34. lfs_file_open(&lfs, &file, "coffee/thai",
  35. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  36. lfs_file_close(&lfs, &file) => 0;
  37. }
  38. // stat paths
  39. struct lfs_info info;
  40. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  41. assert(strcmp(info.name, "drip") == 0);
  42. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  43. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  44. assert(strcmp(info.name, "coldbrew") == 0);
  45. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  46. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  47. assert(strcmp(info.name, "turkish") == 0);
  48. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  49. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  50. assert(strcmp(info.name, "tubruk") == 0);
  51. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  52. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  53. assert(strcmp(info.name, "vietnamese") == 0);
  54. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  55. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  56. assert(strcmp(info.name, "thai") == 0);
  57. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  58. // file open paths, only works on files!
  59. if (DIR) {
  60. lfs_file_t file;
  61. lfs_file_open(&lfs, &file, "coffee/drip",
  62. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  63. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  64. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  65. lfs_file_open(&lfs, &file, "coffee/turkish",
  66. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  67. lfs_file_open(&lfs, &file, "coffee/tubruk",
  68. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  69. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  70. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  71. lfs_file_open(&lfs, &file, "coffee/thai",
  72. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  73. } else {
  74. lfs_file_t file;
  75. lfs_file_open(&lfs, &file, "coffee/drip",
  76. LFS_O_RDONLY) => 0;
  77. lfs_file_close(&lfs, &file) => 0;
  78. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  79. LFS_O_RDONLY) => 0;
  80. lfs_file_close(&lfs, &file) => 0;
  81. lfs_file_open(&lfs, &file, "coffee/turkish",
  82. LFS_O_RDONLY) => 0;
  83. lfs_file_close(&lfs, &file) => 0;
  84. lfs_file_open(&lfs, &file, "coffee/tubruk",
  85. LFS_O_RDONLY) => 0;
  86. lfs_file_close(&lfs, &file) => 0;
  87. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  88. LFS_O_RDONLY) => 0;
  89. lfs_file_close(&lfs, &file) => 0;
  90. lfs_file_open(&lfs, &file, "coffee/thai",
  91. LFS_O_RDONLY) => 0;
  92. lfs_file_close(&lfs, &file) => 0;
  93. }
  94. // dir open paths, only works on dirs!
  95. if (DIR) {
  96. lfs_dir_t dir;
  97. lfs_dir_open(&lfs, &dir, "coffee/drip") => 0;
  98. lfs_dir_close(&lfs, &dir) => 0;
  99. lfs_dir_open(&lfs, &dir, "coffee/coldbrew") => 0;
  100. lfs_dir_close(&lfs, &dir) => 0;
  101. lfs_dir_open(&lfs, &dir, "coffee/turkish") => 0;
  102. lfs_dir_close(&lfs, &dir) => 0;
  103. lfs_dir_open(&lfs, &dir, "coffee/tubruk") => 0;
  104. lfs_dir_close(&lfs, &dir) => 0;
  105. lfs_dir_open(&lfs, &dir, "coffee/vietnamese") => 0;
  106. lfs_dir_close(&lfs, &dir) => 0;
  107. lfs_dir_open(&lfs, &dir, "coffee/thai") => 0;
  108. lfs_dir_close(&lfs, &dir) => 0;
  109. } else {
  110. lfs_dir_t dir;
  111. lfs_dir_open(&lfs, &dir, "coffee/drip") => LFS_ERR_NOTDIR;
  112. lfs_dir_open(&lfs, &dir, "coffee/coldbrew") => LFS_ERR_NOTDIR;
  113. lfs_dir_open(&lfs, &dir, "coffee/turkish") => LFS_ERR_NOTDIR;
  114. lfs_dir_open(&lfs, &dir, "coffee/tubruk") => LFS_ERR_NOTDIR;
  115. lfs_dir_open(&lfs, &dir, "coffee/vietnamese") => LFS_ERR_NOTDIR;
  116. lfs_dir_open(&lfs, &dir, "coffee/thai") => LFS_ERR_NOTDIR;
  117. }
  118. // rename paths
  119. lfs_mkdir(&lfs, "espresso") => 0;
  120. lfs_rename(&lfs,
  121. "coffee/drip",
  122. "espresso/espresso") => 0;
  123. lfs_rename(&lfs,
  124. "coffee/coldbrew",
  125. "espresso/americano") => 0;
  126. lfs_rename(&lfs,
  127. "coffee/turkish",
  128. "espresso/macchiato") => 0;
  129. lfs_rename(&lfs,
  130. "coffee/tubruk",
  131. "espresso/latte") => 0;
  132. lfs_rename(&lfs,
  133. "coffee/vietnamese",
  134. "espresso/cappuccino") => 0;
  135. lfs_rename(&lfs,
  136. "coffee/thai",
  137. "espresso/mocha") => 0;
  138. // stat paths
  139. lfs_stat(&lfs, "espresso/espresso", &info) => 0;
  140. assert(strcmp(info.name, "espresso") == 0);
  141. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  142. lfs_stat(&lfs, "espresso/americano", &info) => 0;
  143. assert(strcmp(info.name, "americano") == 0);
  144. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  145. lfs_stat(&lfs, "espresso/macchiato", &info) => 0;
  146. assert(strcmp(info.name, "macchiato") == 0);
  147. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  148. lfs_stat(&lfs, "espresso/latte", &info) => 0;
  149. assert(strcmp(info.name, "latte") == 0);
  150. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  151. lfs_stat(&lfs, "espresso/cappuccino", &info) => 0;
  152. assert(strcmp(info.name, "cappuccino") == 0);
  153. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  154. lfs_stat(&lfs, "espresso/mocha", &info) => 0;
  155. assert(strcmp(info.name, "mocha") == 0);
  156. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  157. lfs_stat(&lfs, "coffee/drip", &info) => LFS_ERR_NOENT;
  158. lfs_stat(&lfs, "coffee/coldbrew", &info) => LFS_ERR_NOENT;
  159. lfs_stat(&lfs, "coffee/turkish", &info) => LFS_ERR_NOENT;
  160. lfs_stat(&lfs, "coffee/tubruk", &info) => LFS_ERR_NOENT;
  161. lfs_stat(&lfs, "coffee/vietnamese", &info) => LFS_ERR_NOENT;
  162. lfs_stat(&lfs, "coffee/thai", &info) => LFS_ERR_NOENT;
  163. // remove paths
  164. lfs_remove(&lfs, "espresso/espresso") => 0;
  165. lfs_remove(&lfs, "espresso/americano") => 0;
  166. lfs_remove(&lfs, "espresso/macchiato") => 0;
  167. lfs_remove(&lfs, "espresso/latte") => 0;
  168. lfs_remove(&lfs, "espresso/cappuccino") => 0;
  169. lfs_remove(&lfs, "espresso/mocha") => 0;
  170. // stat paths
  171. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  172. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  173. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  174. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  175. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  176. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  177. lfs_unmount(&lfs) => 0;
  178. '''
  179. # absolute path test
  180. #
  181. # littlefs does not provide cd, so these are the same as relative paths
  182. [cases.test_paths_absolute]
  183. defines.DIR = [false, true]
  184. code = '''
  185. lfs_t lfs;
  186. lfs_format(&lfs, cfg) => 0;
  187. lfs_mount(&lfs, cfg) => 0;
  188. // create paths
  189. lfs_mkdir(&lfs, "coffee") => 0;
  190. if (DIR) {
  191. lfs_mkdir(&lfs, "/coffee/drip") => 0;
  192. lfs_mkdir(&lfs, "/coffee/coldbrew") => 0;
  193. lfs_mkdir(&lfs, "/coffee/turkish") => 0;
  194. lfs_mkdir(&lfs, "/coffee/tubruk") => 0;
  195. lfs_mkdir(&lfs, "/coffee/vietnamese") => 0;
  196. lfs_mkdir(&lfs, "/coffee/thai") => 0;
  197. } else {
  198. lfs_file_t file;
  199. lfs_file_open(&lfs, &file, "/coffee/drip",
  200. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  201. lfs_file_close(&lfs, &file) => 0;
  202. lfs_file_open(&lfs, &file, "/coffee/coldbrew",
  203. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  204. lfs_file_close(&lfs, &file) => 0;
  205. lfs_file_open(&lfs, &file, "/coffee/turkish",
  206. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  207. lfs_file_close(&lfs, &file) => 0;
  208. lfs_file_open(&lfs, &file, "/coffee/tubruk",
  209. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  210. lfs_file_close(&lfs, &file) => 0;
  211. lfs_file_open(&lfs, &file, "/coffee/vietnamese",
  212. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  213. lfs_file_close(&lfs, &file) => 0;
  214. lfs_file_open(&lfs, &file, "/coffee/thai",
  215. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  216. lfs_file_close(&lfs, &file) => 0;
  217. }
  218. // stat paths
  219. struct lfs_info info;
  220. lfs_stat(&lfs, "/coffee/drip", &info) => 0;
  221. assert(strcmp(info.name, "drip") == 0);
  222. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  223. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  224. assert(strcmp(info.name, "coldbrew") == 0);
  225. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  226. lfs_stat(&lfs, "/coffee/turkish", &info) => 0;
  227. assert(strcmp(info.name, "turkish") == 0);
  228. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  229. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  230. assert(strcmp(info.name, "tubruk") == 0);
  231. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  232. lfs_stat(&lfs, "/coffee/vietnamese", &info) => 0;
  233. assert(strcmp(info.name, "vietnamese") == 0);
  234. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  235. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  236. assert(strcmp(info.name, "thai") == 0);
  237. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  238. // file open paths, only works on files!
  239. if (DIR) {
  240. lfs_file_t file;
  241. lfs_file_open(&lfs, &file, "/coffee/drip",
  242. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  243. lfs_file_open(&lfs, &file, "/coffee/coldbrew",
  244. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  245. lfs_file_open(&lfs, &file, "/coffee/turkish",
  246. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  247. lfs_file_open(&lfs, &file, "/coffee/tubruk",
  248. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  249. lfs_file_open(&lfs, &file, "/coffee/vietnamese",
  250. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  251. lfs_file_open(&lfs, &file, "/coffee/thai",
  252. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  253. } else {
  254. lfs_file_t file;
  255. lfs_file_open(&lfs, &file, "/coffee/drip",
  256. LFS_O_RDONLY) => 0;
  257. lfs_file_close(&lfs, &file) => 0;
  258. lfs_file_open(&lfs, &file, "/coffee/coldbrew",
  259. LFS_O_RDONLY) => 0;
  260. lfs_file_close(&lfs, &file) => 0;
  261. lfs_file_open(&lfs, &file, "/coffee/turkish",
  262. LFS_O_RDONLY) => 0;
  263. lfs_file_close(&lfs, &file) => 0;
  264. lfs_file_open(&lfs, &file, "/coffee/tubruk",
  265. LFS_O_RDONLY) => 0;
  266. lfs_file_close(&lfs, &file) => 0;
  267. lfs_file_open(&lfs, &file, "/coffee/vietnamese",
  268. LFS_O_RDONLY) => 0;
  269. lfs_file_close(&lfs, &file) => 0;
  270. lfs_file_open(&lfs, &file, "/coffee/thai",
  271. LFS_O_RDONLY) => 0;
  272. lfs_file_close(&lfs, &file) => 0;
  273. }
  274. // dir open paths, only works on dirs!
  275. if (DIR) {
  276. lfs_dir_t dir;
  277. lfs_dir_open(&lfs, &dir, "/coffee/drip") => 0;
  278. lfs_dir_close(&lfs, &dir) => 0;
  279. lfs_dir_open(&lfs, &dir, "/coffee/coldbrew") => 0;
  280. lfs_dir_close(&lfs, &dir) => 0;
  281. lfs_dir_open(&lfs, &dir, "/coffee/turkish") => 0;
  282. lfs_dir_close(&lfs, &dir) => 0;
  283. lfs_dir_open(&lfs, &dir, "/coffee/tubruk") => 0;
  284. lfs_dir_close(&lfs, &dir) => 0;
  285. lfs_dir_open(&lfs, &dir, "/coffee/vietnamese") => 0;
  286. lfs_dir_close(&lfs, &dir) => 0;
  287. lfs_dir_open(&lfs, &dir, "/coffee/thai") => 0;
  288. lfs_dir_close(&lfs, &dir) => 0;
  289. } else {
  290. lfs_dir_t dir;
  291. lfs_dir_open(&lfs, &dir, "/coffee/drip") => LFS_ERR_NOTDIR;
  292. lfs_dir_open(&lfs, &dir, "/coffee/coldbrew") => LFS_ERR_NOTDIR;
  293. lfs_dir_open(&lfs, &dir, "/coffee/turkish") => LFS_ERR_NOTDIR;
  294. lfs_dir_open(&lfs, &dir, "/coffee/tubruk") => LFS_ERR_NOTDIR;
  295. lfs_dir_open(&lfs, &dir, "/coffee/vietnamese") => LFS_ERR_NOTDIR;
  296. lfs_dir_open(&lfs, &dir, "/coffee/thai") => LFS_ERR_NOTDIR;
  297. }
  298. // rename paths
  299. lfs_mkdir(&lfs, "espresso") => 0;
  300. lfs_rename(&lfs,
  301. "coffee/drip",
  302. "/espresso/espresso") => 0;
  303. lfs_rename(&lfs,
  304. "coffee/coldbrew",
  305. "/espresso/americano") => 0;
  306. lfs_rename(&lfs,
  307. "/coffee/turkish",
  308. "espresso/macchiato") => 0;
  309. lfs_rename(&lfs,
  310. "/coffee/tubruk",
  311. "espresso/latte") => 0;
  312. lfs_rename(&lfs,
  313. "/coffee/vietnamese",
  314. "/espresso/cappuccino") => 0;
  315. lfs_rename(&lfs,
  316. "/coffee/thai",
  317. "/espresso/mocha") => 0;
  318. // stat paths
  319. lfs_stat(&lfs, "/espresso/espresso", &info) => 0;
  320. assert(strcmp(info.name, "espresso") == 0);
  321. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  322. lfs_stat(&lfs, "espresso/americano", &info) => 0;
  323. assert(strcmp(info.name, "americano") == 0);
  324. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  325. lfs_stat(&lfs, "/espresso/macchiato", &info) => 0;
  326. assert(strcmp(info.name, "macchiato") == 0);
  327. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  328. lfs_stat(&lfs, "espresso/latte", &info) => 0;
  329. assert(strcmp(info.name, "latte") == 0);
  330. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  331. lfs_stat(&lfs, "/espresso/cappuccino", &info) => 0;
  332. assert(strcmp(info.name, "cappuccino") == 0);
  333. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  334. lfs_stat(&lfs, "espresso/mocha", &info) => 0;
  335. assert(strcmp(info.name, "mocha") == 0);
  336. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  337. lfs_stat(&lfs, "/coffee/drip", &info) => LFS_ERR_NOENT;
  338. lfs_stat(&lfs, "/coffee/coldbrew", &info) => LFS_ERR_NOENT;
  339. lfs_stat(&lfs, "/coffee/turkish", &info) => LFS_ERR_NOENT;
  340. lfs_stat(&lfs, "/coffee/tubruk", &info) => LFS_ERR_NOENT;
  341. lfs_stat(&lfs, "/coffee/vietnamese", &info) => LFS_ERR_NOENT;
  342. lfs_stat(&lfs, "/coffee/thai", &info) => LFS_ERR_NOENT;
  343. // remove paths
  344. lfs_remove(&lfs, "/espresso/espresso") => 0;
  345. lfs_remove(&lfs, "/espresso/americano") => 0;
  346. lfs_remove(&lfs, "/espresso/macchiato") => 0;
  347. lfs_remove(&lfs, "/espresso/latte") => 0;
  348. lfs_remove(&lfs, "/espresso/cappuccino") => 0;
  349. lfs_remove(&lfs, "/espresso/mocha") => 0;
  350. // stat paths
  351. lfs_stat(&lfs, "/espresso/espresso", &info) => LFS_ERR_NOENT;
  352. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  353. lfs_stat(&lfs, "/espresso/macchiato", &info) => LFS_ERR_NOENT;
  354. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  355. lfs_stat(&lfs, "/espresso/cappuccino", &info) => LFS_ERR_NOENT;
  356. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  357. lfs_unmount(&lfs) => 0;
  358. '''
  359. # redundant slashes
  360. [cases.test_paths_redundant_slashes]
  361. defines.DIR = [false, true]
  362. code = '''
  363. lfs_t lfs;
  364. lfs_format(&lfs, cfg) => 0;
  365. lfs_mount(&lfs, cfg) => 0;
  366. // create paths
  367. lfs_mkdir(&lfs, "coffee") => 0;
  368. if (DIR) {
  369. lfs_mkdir(&lfs, "/coffee/drip") => 0;
  370. lfs_mkdir(&lfs, "//coffee//coldbrew") => 0;
  371. lfs_mkdir(&lfs, "///coffee///turkish") => 0;
  372. lfs_mkdir(&lfs, "////coffee////tubruk") => 0;
  373. lfs_mkdir(&lfs, "/////coffee/////vietnamese") => 0;
  374. lfs_mkdir(&lfs, "//////coffee//////thai") => 0;
  375. } else {
  376. lfs_file_t file;
  377. lfs_file_open(&lfs, &file, "/coffee/drip",
  378. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  379. lfs_file_close(&lfs, &file) => 0;
  380. lfs_file_open(&lfs, &file, "//coffee//coldbrew",
  381. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  382. lfs_file_close(&lfs, &file) => 0;
  383. lfs_file_open(&lfs, &file, "///coffee///turkish",
  384. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  385. lfs_file_close(&lfs, &file) => 0;
  386. lfs_file_open(&lfs, &file, "////coffee////tubruk",
  387. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  388. lfs_file_close(&lfs, &file) => 0;
  389. lfs_file_open(&lfs, &file, "/////coffee/////vietnamese",
  390. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  391. lfs_file_close(&lfs, &file) => 0;
  392. lfs_file_open(&lfs, &file, "//////coffee//////thai",
  393. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  394. lfs_file_close(&lfs, &file) => 0;
  395. }
  396. // stat paths
  397. struct lfs_info info;
  398. lfs_stat(&lfs, "//////coffee//////drip", &info) => 0;
  399. assert(strcmp(info.name, "drip") == 0);
  400. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  401. lfs_stat(&lfs, "/////coffee/////coldbrew", &info) => 0;
  402. assert(strcmp(info.name, "coldbrew") == 0);
  403. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  404. lfs_stat(&lfs, "////coffee////turkish", &info) => 0;
  405. assert(strcmp(info.name, "turkish") == 0);
  406. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  407. lfs_stat(&lfs, "///coffee///tubruk", &info) => 0;
  408. assert(strcmp(info.name, "tubruk") == 0);
  409. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  410. lfs_stat(&lfs, "//coffee//vietnamese", &info) => 0;
  411. assert(strcmp(info.name, "vietnamese") == 0);
  412. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  413. lfs_stat(&lfs, "/coffee/thai", &info) => 0;
  414. assert(strcmp(info.name, "thai") == 0);
  415. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  416. // file open paths, only works on files!
  417. if (DIR) {
  418. lfs_file_t file;
  419. lfs_file_open(&lfs, &file, "/coffee/drip",
  420. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  421. lfs_file_open(&lfs, &file, "//coffee//coldbrew",
  422. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  423. lfs_file_open(&lfs, &file, "///coffee///turkish",
  424. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  425. lfs_file_open(&lfs, &file, "////coffee////tubruk",
  426. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  427. lfs_file_open(&lfs, &file, "/////coffee/////vietnamese",
  428. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  429. lfs_file_open(&lfs, &file, "//////coffee//////thai",
  430. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  431. } else {
  432. lfs_file_t file;
  433. lfs_file_open(&lfs, &file, "/coffee/drip",
  434. LFS_O_RDONLY) => 0;
  435. lfs_file_close(&lfs, &file) => 0;
  436. lfs_file_open(&lfs, &file, "//coffee//coldbrew",
  437. LFS_O_RDONLY) => 0;
  438. lfs_file_close(&lfs, &file) => 0;
  439. lfs_file_open(&lfs, &file, "///coffee///turkish",
  440. LFS_O_RDONLY) => 0;
  441. lfs_file_close(&lfs, &file) => 0;
  442. lfs_file_open(&lfs, &file, "////coffee////tubruk",
  443. LFS_O_RDONLY) => 0;
  444. lfs_file_close(&lfs, &file) => 0;
  445. lfs_file_open(&lfs, &file, "/////coffee/////vietnamese",
  446. LFS_O_RDONLY) => 0;
  447. lfs_file_close(&lfs, &file) => 0;
  448. lfs_file_open(&lfs, &file, "//////coffee//////thai",
  449. LFS_O_RDONLY) => 0;
  450. lfs_file_close(&lfs, &file) => 0;
  451. }
  452. // dir open paths, only works on dirs!
  453. if (DIR) {
  454. lfs_dir_t dir;
  455. lfs_dir_open(&lfs, &dir, "/coffee/drip") => 0;
  456. lfs_dir_close(&lfs, &dir) => 0;
  457. lfs_dir_open(&lfs, &dir, "//coffee//coldbrew") => 0;
  458. lfs_dir_close(&lfs, &dir) => 0;
  459. lfs_dir_open(&lfs, &dir, "///coffee///turkish") => 0;
  460. lfs_dir_close(&lfs, &dir) => 0;
  461. lfs_dir_open(&lfs, &dir, "////coffee////tubruk") => 0;
  462. lfs_dir_close(&lfs, &dir) => 0;
  463. lfs_dir_open(&lfs, &dir, "/////coffee/////vietnamese") => 0;
  464. lfs_dir_close(&lfs, &dir) => 0;
  465. lfs_dir_open(&lfs, &dir, "//////coffee//////thai") => 0;
  466. lfs_dir_close(&lfs, &dir) => 0;
  467. } else {
  468. lfs_dir_t dir;
  469. lfs_dir_open(&lfs, &dir, "/coffee/drip") => LFS_ERR_NOTDIR;
  470. lfs_dir_open(&lfs, &dir, "//coffee//coldbrew") => LFS_ERR_NOTDIR;
  471. lfs_dir_open(&lfs, &dir, "///coffee///turkish") => LFS_ERR_NOTDIR;
  472. lfs_dir_open(&lfs, &dir, "////coffee////tubruk") => LFS_ERR_NOTDIR;
  473. lfs_dir_open(&lfs, &dir, "/////coffee/////vietnamese") => LFS_ERR_NOTDIR;
  474. lfs_dir_open(&lfs, &dir, "//////coffee//////thai") => LFS_ERR_NOTDIR;
  475. }
  476. // rename paths
  477. lfs_mkdir(&lfs, "espresso") => 0;
  478. lfs_rename(&lfs,
  479. "//////coffee//////drip",
  480. "/espresso/espresso") => 0;
  481. lfs_rename(&lfs,
  482. "/////coffee/////coldbrew",
  483. "//espresso//americano") => 0;
  484. lfs_rename(&lfs,
  485. "////coffee////turkish",
  486. "///espresso///macchiato") => 0;
  487. lfs_rename(&lfs,
  488. "///coffee///tubruk",
  489. "////espresso////latte") => 0;
  490. lfs_rename(&lfs,
  491. "//coffee//vietnamese",
  492. "/////espresso/////cappuccino") => 0;
  493. lfs_rename(&lfs,
  494. "/coffee/thai",
  495. "//////espresso//////mocha") => 0;
  496. // stat paths
  497. lfs_stat(&lfs, "//////espresso//////espresso", &info) => 0;
  498. assert(strcmp(info.name, "espresso") == 0);
  499. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  500. lfs_stat(&lfs, "/////espresso/////americano", &info) => 0;
  501. assert(strcmp(info.name, "americano") == 0);
  502. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  503. lfs_stat(&lfs, "////espresso////macchiato", &info) => 0;
  504. assert(strcmp(info.name, "macchiato") == 0);
  505. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  506. lfs_stat(&lfs, "///espresso///latte", &info) => 0;
  507. assert(strcmp(info.name, "latte") == 0);
  508. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  509. lfs_stat(&lfs, "//espresso//cappuccino", &info) => 0;
  510. assert(strcmp(info.name, "cappuccino") == 0);
  511. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  512. lfs_stat(&lfs, "/espresso/mocha", &info) => 0;
  513. assert(strcmp(info.name, "mocha") == 0);
  514. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  515. lfs_stat(&lfs, "//////coffee//////drip", &info) => LFS_ERR_NOENT;
  516. lfs_stat(&lfs, "/////coffee/////coldbrew", &info) => LFS_ERR_NOENT;
  517. lfs_stat(&lfs, "////coffee////turkish", &info) => LFS_ERR_NOENT;
  518. lfs_stat(&lfs, "///coffee///tubruk", &info) => LFS_ERR_NOENT;
  519. lfs_stat(&lfs, "//coffee//vietnamese", &info) => LFS_ERR_NOENT;
  520. lfs_stat(&lfs, "/coffee/thai", &info) => LFS_ERR_NOENT;
  521. // remove paths
  522. lfs_remove(&lfs, "/espresso/espresso") => 0;
  523. lfs_remove(&lfs, "//espresso//americano") => 0;
  524. lfs_remove(&lfs, "///espresso///macchiato") => 0;
  525. lfs_remove(&lfs, "////espresso////latte") => 0;
  526. lfs_remove(&lfs, "/////espresso/////cappuccino") => 0;
  527. lfs_remove(&lfs, "//////espresso//////mocha") => 0;
  528. // stat paths
  529. lfs_stat(&lfs, "//////espresso//////espresso", &info) => LFS_ERR_NOENT;
  530. lfs_stat(&lfs, "/////espresso/////americano", &info) => LFS_ERR_NOENT;
  531. lfs_stat(&lfs, "////espresso////macchiato", &info) => LFS_ERR_NOENT;
  532. lfs_stat(&lfs, "///espresso///latte", &info) => LFS_ERR_NOENT;
  533. lfs_stat(&lfs, "//espresso//cappuccino", &info) => LFS_ERR_NOENT;
  534. lfs_stat(&lfs, "/espresso/mocha", &info) => LFS_ERR_NOENT;
  535. lfs_unmount(&lfs) => 0;
  536. '''
  537. # test trailing slashes
  538. #
  539. # trailing slashes are only allowed on directories
  540. [cases.test_paths_trailing_slashes]
  541. defines.DIR = [false, true]
  542. code = '''
  543. lfs_t lfs;
  544. lfs_format(&lfs, cfg) => 0;
  545. lfs_mount(&lfs, cfg) => 0;
  546. // create paths
  547. lfs_mkdir(&lfs, "coffee") => 0;
  548. if (DIR) {
  549. lfs_mkdir(&lfs, "coffee/drip/") => 0;
  550. lfs_mkdir(&lfs, "coffee/coldbrew//") => 0;
  551. lfs_mkdir(&lfs, "coffee/turkish///") => 0;
  552. lfs_mkdir(&lfs, "coffee/tubruk////") => 0;
  553. lfs_mkdir(&lfs, "coffee/vietnamese/////") => 0;
  554. lfs_mkdir(&lfs, "coffee/thai//////") => 0;
  555. } else {
  556. lfs_file_t file;
  557. lfs_file_open(&lfs, &file, "coffee/drip/",
  558. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_ISDIR;
  559. lfs_file_open(&lfs, &file, "coffee/coldbrew//",
  560. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_ISDIR;
  561. lfs_file_open(&lfs, &file, "coffee/turkish///",
  562. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_ISDIR;
  563. lfs_file_open(&lfs, &file, "coffee/tubruk////",
  564. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_ISDIR;
  565. lfs_file_open(&lfs, &file, "coffee/vietnamese/////",
  566. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_ISDIR;
  567. lfs_file_open(&lfs, &file, "coffee/thai//////",
  568. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_ISDIR;
  569. // still create so we have something to test
  570. lfs_file_open(&lfs, &file, "coffee/drip",
  571. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  572. lfs_file_close(&lfs, &file) => 0;
  573. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  574. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  575. lfs_file_close(&lfs, &file) => 0;
  576. lfs_file_open(&lfs, &file, "coffee/turkish",
  577. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  578. lfs_file_close(&lfs, &file) => 0;
  579. lfs_file_open(&lfs, &file, "coffee/tubruk",
  580. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  581. lfs_file_close(&lfs, &file) => 0;
  582. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  583. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  584. lfs_file_close(&lfs, &file) => 0;
  585. lfs_file_open(&lfs, &file, "coffee/thai",
  586. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  587. lfs_file_close(&lfs, &file) => 0;
  588. }
  589. // stat paths
  590. struct lfs_info info;
  591. if (DIR) {
  592. lfs_stat(&lfs, "coffee/drip//////", &info) => 0;
  593. assert(strcmp(info.name, "drip") == 0);
  594. assert(info.type == LFS_TYPE_DIR);
  595. lfs_stat(&lfs, "coffee/coldbrew/////", &info) => 0;
  596. assert(strcmp(info.name, "coldbrew") == 0);
  597. assert(info.type == LFS_TYPE_DIR);
  598. lfs_stat(&lfs, "coffee/turkish////", &info) => 0;
  599. assert(strcmp(info.name, "turkish") == 0);
  600. assert(info.type == LFS_TYPE_DIR);
  601. lfs_stat(&lfs, "coffee/tubruk///", &info) => 0;
  602. assert(strcmp(info.name, "tubruk") == 0);
  603. assert(info.type == LFS_TYPE_DIR);
  604. lfs_stat(&lfs, "coffee/vietnamese//", &info) => 0;
  605. assert(strcmp(info.name, "vietnamese") == 0);
  606. assert(info.type == LFS_TYPE_DIR);
  607. lfs_stat(&lfs, "coffee/thai/", &info) => 0;
  608. assert(strcmp(info.name, "thai") == 0);
  609. assert(info.type == LFS_TYPE_DIR);
  610. } else {
  611. lfs_stat(&lfs, "coffee/drip//////", &info) => LFS_ERR_NOTDIR;
  612. lfs_stat(&lfs, "coffee/coldbrew/////", &info) => LFS_ERR_NOTDIR;
  613. lfs_stat(&lfs, "coffee/turkish////", &info) => LFS_ERR_NOTDIR;
  614. lfs_stat(&lfs, "coffee/tubruk///", &info) => LFS_ERR_NOTDIR;
  615. lfs_stat(&lfs, "coffee/vietnamese//", &info) => LFS_ERR_NOTDIR;
  616. lfs_stat(&lfs, "coffee/thai/", &info) => LFS_ERR_NOTDIR;
  617. }
  618. // file open paths, only works on files!
  619. if (DIR) {
  620. lfs_file_t file;
  621. lfs_file_open(&lfs, &file, "coffee/drip/",
  622. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  623. lfs_file_open(&lfs, &file, "coffee/coldbrew//",
  624. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  625. lfs_file_open(&lfs, &file, "coffee/turkish///",
  626. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  627. lfs_file_open(&lfs, &file, "coffee/tubruk////",
  628. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  629. lfs_file_open(&lfs, &file, "coffee/vietnamese/////",
  630. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  631. lfs_file_open(&lfs, &file, "coffee/thai//////",
  632. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  633. } else {
  634. lfs_file_t file;
  635. lfs_file_open(&lfs, &file, "coffee/drip/",
  636. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  637. lfs_file_open(&lfs, &file, "coffee/coldbrew//",
  638. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  639. lfs_file_open(&lfs, &file, "coffee/turkish///",
  640. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  641. lfs_file_open(&lfs, &file, "coffee/tubruk////",
  642. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  643. lfs_file_open(&lfs, &file, "coffee/vietnamese/////",
  644. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  645. lfs_file_open(&lfs, &file, "coffee/thai//////",
  646. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  647. }
  648. // dir open paths, only works on dirs!
  649. if (DIR) {
  650. lfs_dir_t dir;
  651. lfs_dir_open(&lfs, &dir, "coffee/drip/") => 0;
  652. lfs_dir_close(&lfs, &dir) => 0;
  653. lfs_dir_open(&lfs, &dir, "coffee/coldbrew//") => 0;
  654. lfs_dir_close(&lfs, &dir) => 0;
  655. lfs_dir_open(&lfs, &dir, "coffee/turkish///") => 0;
  656. lfs_dir_close(&lfs, &dir) => 0;
  657. lfs_dir_open(&lfs, &dir, "coffee/tubruk////") => 0;
  658. lfs_dir_close(&lfs, &dir) => 0;
  659. lfs_dir_open(&lfs, &dir, "coffee/vietnamese/////") => 0;
  660. lfs_dir_close(&lfs, &dir) => 0;
  661. lfs_dir_open(&lfs, &dir, "coffee/thai//////") => 0;
  662. lfs_dir_close(&lfs, &dir) => 0;
  663. } else {
  664. lfs_dir_t dir;
  665. lfs_dir_open(&lfs, &dir, "coffee/drip/") => LFS_ERR_NOTDIR;
  666. lfs_dir_open(&lfs, &dir, "coffee/coldbrew//") => LFS_ERR_NOTDIR;
  667. lfs_dir_open(&lfs, &dir, "coffee/turkish///") => LFS_ERR_NOTDIR;
  668. lfs_dir_open(&lfs, &dir, "coffee/tubruk////") => LFS_ERR_NOTDIR;
  669. lfs_dir_open(&lfs, &dir, "coffee/vietnamese/////") => LFS_ERR_NOTDIR;
  670. lfs_dir_open(&lfs, &dir, "coffee/thai//////") => LFS_ERR_NOTDIR;
  671. }
  672. // rename paths
  673. lfs_mkdir(&lfs, "espresso") => 0;
  674. if (DIR) {
  675. lfs_rename(&lfs,
  676. "coffee/drip//////",
  677. "espresso/espresso/") => 0;
  678. lfs_rename(&lfs,
  679. "coffee/coldbrew/////",
  680. "espresso/americano//") => 0;
  681. lfs_rename(&lfs,
  682. "coffee/turkish////",
  683. "espresso/macchiato///") => 0;
  684. lfs_rename(&lfs,
  685. "coffee/tubruk///",
  686. "espresso/latte////") => 0;
  687. lfs_rename(&lfs,
  688. "coffee/vietnamese//",
  689. "espresso/cappuccino/////") => 0;
  690. lfs_rename(&lfs,
  691. "coffee/thai/",
  692. "espresso/mocha//////") => 0;
  693. // stat paths
  694. lfs_stat(&lfs, "espresso/espresso//////", &info) => 0;
  695. assert(strcmp(info.name, "espresso") == 0);
  696. assert(info.type == LFS_TYPE_DIR);
  697. lfs_stat(&lfs, "espresso/americano/////", &info) => 0;
  698. assert(strcmp(info.name, "americano") == 0);
  699. assert(info.type == LFS_TYPE_DIR);
  700. lfs_stat(&lfs, "espresso/macchiato////", &info) => 0;
  701. assert(strcmp(info.name, "macchiato") == 0);
  702. assert(info.type == LFS_TYPE_DIR);
  703. lfs_stat(&lfs, "espresso/latte///", &info) => 0;
  704. assert(strcmp(info.name, "latte") == 0);
  705. assert(info.type == LFS_TYPE_DIR);
  706. lfs_stat(&lfs, "espresso/cappuccino//", &info) => 0;
  707. assert(strcmp(info.name, "cappuccino") == 0);
  708. assert(info.type == LFS_TYPE_DIR);
  709. lfs_stat(&lfs, "espresso/mocha/", &info) => 0;
  710. assert(strcmp(info.name, "mocha") == 0);
  711. assert(info.type == LFS_TYPE_DIR);
  712. lfs_stat(&lfs, "coffee/drip//////", &info) => LFS_ERR_NOENT;
  713. lfs_stat(&lfs, "coffee/coldbrew/////", &info) => LFS_ERR_NOENT;
  714. lfs_stat(&lfs, "coffee/turkish////", &info) => LFS_ERR_NOENT;
  715. lfs_stat(&lfs, "coffee/tubruk///", &info) => LFS_ERR_NOENT;
  716. lfs_stat(&lfs, "coffee/vietnamese//", &info) => LFS_ERR_NOENT;
  717. lfs_stat(&lfs, "coffee/thai/", &info) => LFS_ERR_NOENT;
  718. // remove paths
  719. lfs_remove(&lfs, "espresso/espresso/") => 0;
  720. lfs_remove(&lfs, "espresso/americano//") => 0;
  721. lfs_remove(&lfs, "espresso/macchiato///") => 0;
  722. lfs_remove(&lfs, "espresso/latte////") => 0;
  723. lfs_remove(&lfs, "espresso/cappuccino/////") => 0;
  724. lfs_remove(&lfs, "espresso/mocha//////") => 0;
  725. // stat paths
  726. lfs_stat(&lfs, "espresso/espresso//////", &info) => LFS_ERR_NOENT;
  727. lfs_stat(&lfs, "espresso/americano/////", &info) => LFS_ERR_NOENT;
  728. lfs_stat(&lfs, "espresso/macchiato////", &info) => LFS_ERR_NOENT;
  729. lfs_stat(&lfs, "espresso/latte///", &info) => LFS_ERR_NOENT;
  730. lfs_stat(&lfs, "espresso/cappuccino//", &info) => LFS_ERR_NOENT;
  731. lfs_stat(&lfs, "espresso/mocha/", &info) => LFS_ERR_NOENT;
  732. } else {
  733. // bad source
  734. lfs_rename(&lfs,
  735. "coffee/drip//////",
  736. "espresso/espresso") => LFS_ERR_NOTDIR;
  737. lfs_rename(&lfs,
  738. "coffee/coldbrew/////",
  739. "espresso/americano") => LFS_ERR_NOTDIR;
  740. lfs_rename(&lfs,
  741. "coffee/turkish////",
  742. "espresso/macchiato") => LFS_ERR_NOTDIR;
  743. lfs_rename(&lfs,
  744. "coffee/tubruk///",
  745. "espresso/latte") => LFS_ERR_NOTDIR;
  746. lfs_rename(&lfs,
  747. "coffee/vietnamese//",
  748. "espresso/cappuccino") => LFS_ERR_NOTDIR;
  749. lfs_rename(&lfs,
  750. "coffee/thai/",
  751. "espresso/mocha") => LFS_ERR_NOTDIR;
  752. // bad destination
  753. lfs_rename(&lfs,
  754. "coffee/drip",
  755. "espresso/espresso/") => LFS_ERR_NOTDIR;
  756. lfs_rename(&lfs,
  757. "coffee/coldbrew",
  758. "espresso/americano//") => LFS_ERR_NOTDIR;
  759. lfs_rename(&lfs,
  760. "coffee/turkish",
  761. "espresso/macchiato///") => LFS_ERR_NOTDIR;
  762. lfs_rename(&lfs,
  763. "coffee/tubruk",
  764. "espresso/latte////") => LFS_ERR_NOTDIR;
  765. lfs_rename(&lfs,
  766. "coffee/vietnamese",
  767. "espresso/cappuccino/////") => LFS_ERR_NOTDIR;
  768. lfs_rename(&lfs,
  769. "coffee/thai",
  770. "espresso/mocha//////") => LFS_ERR_NOTDIR;
  771. // bad source and bad destination
  772. lfs_rename(&lfs,
  773. "coffee/drip//////",
  774. "espresso/espresso/") => LFS_ERR_NOTDIR;
  775. lfs_rename(&lfs,
  776. "coffee/coldbrew/////",
  777. "espresso/americano//") => LFS_ERR_NOTDIR;
  778. lfs_rename(&lfs,
  779. "coffee/turkish////",
  780. "espresso/macchiato///") => LFS_ERR_NOTDIR;
  781. lfs_rename(&lfs,
  782. "coffee/tubruk///",
  783. "espresso/latte////") => LFS_ERR_NOTDIR;
  784. lfs_rename(&lfs,
  785. "coffee/vietnamese//",
  786. "espresso/cappuccino/////") => LFS_ERR_NOTDIR;
  787. lfs_rename(&lfs,
  788. "coffee/thai/",
  789. "espresso/mocha//////") => LFS_ERR_NOTDIR;
  790. // remove paths
  791. lfs_remove(&lfs, "coffee/drip/") => LFS_ERR_NOTDIR;
  792. lfs_remove(&lfs, "coffee/coldbrew//") => LFS_ERR_NOTDIR;
  793. lfs_remove(&lfs, "coffee/turkish///") => LFS_ERR_NOTDIR;
  794. lfs_remove(&lfs, "coffee/tubruk////") => LFS_ERR_NOTDIR;
  795. lfs_remove(&lfs, "coffee/vietnamese/////") => LFS_ERR_NOTDIR;
  796. lfs_remove(&lfs, "coffee/thai//////") => LFS_ERR_NOTDIR;
  797. // stat paths
  798. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  799. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  800. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  801. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  802. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  803. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  804. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  805. assert(strcmp(info.name, "drip") == 0);
  806. assert(info.type == LFS_TYPE_REG);
  807. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  808. assert(strcmp(info.name, "coldbrew") == 0);
  809. assert(info.type == LFS_TYPE_REG);
  810. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  811. assert(strcmp(info.name, "turkish") == 0);
  812. assert(info.type == LFS_TYPE_REG);
  813. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  814. assert(strcmp(info.name, "tubruk") == 0);
  815. assert(info.type == LFS_TYPE_REG);
  816. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  817. assert(strcmp(info.name, "vietnamese") == 0);
  818. assert(info.type == LFS_TYPE_REG);
  819. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  820. assert(strcmp(info.name, "thai") == 0);
  821. assert(info.type == LFS_TYPE_REG);
  822. }
  823. lfs_unmount(&lfs) => 0;
  824. '''
  825. # dot path tests
  826. [cases.test_paths_dots]
  827. defines.DIR = [false, true]
  828. code = '''
  829. lfs_t lfs;
  830. lfs_format(&lfs, cfg) => 0;
  831. lfs_mount(&lfs, cfg) => 0;
  832. // create paths
  833. lfs_mkdir(&lfs, "coffee") => 0;
  834. if (DIR) {
  835. lfs_mkdir(&lfs, "/coffee/drip") => 0;
  836. lfs_mkdir(&lfs, "/./coffee/./coldbrew") => 0;
  837. lfs_mkdir(&lfs, "/././coffee/././turkish") => 0;
  838. lfs_mkdir(&lfs, "/./././coffee/./././tubruk") => 0;
  839. lfs_mkdir(&lfs, "/././././coffee/././././vietnamese") => 0;
  840. lfs_mkdir(&lfs, "/./././././coffee/./././././thai") => 0;
  841. } else {
  842. lfs_file_t file;
  843. lfs_file_open(&lfs, &file, "/coffee/drip",
  844. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  845. lfs_file_close(&lfs, &file) => 0;
  846. lfs_file_open(&lfs, &file, "/./coffee/./coldbrew",
  847. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  848. lfs_file_close(&lfs, &file) => 0;
  849. lfs_file_open(&lfs, &file, "/././coffee/././turkish",
  850. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  851. lfs_file_close(&lfs, &file) => 0;
  852. lfs_file_open(&lfs, &file, "/./././coffee/./././tubruk",
  853. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  854. lfs_file_close(&lfs, &file) => 0;
  855. lfs_file_open(&lfs, &file, "/././././coffee/././././vietnamese",
  856. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  857. lfs_file_close(&lfs, &file) => 0;
  858. lfs_file_open(&lfs, &file, "/./././././coffee/./././././thai",
  859. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  860. lfs_file_close(&lfs, &file) => 0;
  861. }
  862. // stat paths
  863. struct lfs_info info;
  864. lfs_stat(&lfs, "/./././././coffee/./././././drip", &info) => 0;
  865. assert(strcmp(info.name, "drip") == 0);
  866. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  867. lfs_stat(&lfs, "/././././coffee/././././coldbrew", &info) => 0;
  868. assert(strcmp(info.name, "coldbrew") == 0);
  869. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  870. lfs_stat(&lfs, "/./././coffee/./././turkish", &info) => 0;
  871. assert(strcmp(info.name, "turkish") == 0);
  872. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  873. lfs_stat(&lfs, "/././coffee/././tubruk", &info) => 0;
  874. assert(strcmp(info.name, "tubruk") == 0);
  875. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  876. lfs_stat(&lfs, "/./coffee/./vietnamese", &info) => 0;
  877. assert(strcmp(info.name, "vietnamese") == 0);
  878. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  879. lfs_stat(&lfs, "/coffee/thai", &info) => 0;
  880. assert(strcmp(info.name, "thai") == 0);
  881. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  882. // file open paths, only works on files!
  883. if (DIR) {
  884. lfs_file_t file;
  885. lfs_file_open(&lfs, &file, "/coffee/drip",
  886. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  887. lfs_file_open(&lfs, &file, "/./coffee/./coldbrew",
  888. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  889. lfs_file_open(&lfs, &file, "/././coffee/././turkish",
  890. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  891. lfs_file_open(&lfs, &file, "/./././coffee/./././tubruk",
  892. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  893. lfs_file_open(&lfs, &file, "/././././coffee/././././vietnamese",
  894. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  895. lfs_file_open(&lfs, &file, "/./././././coffee/./././././thai",
  896. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  897. } else {
  898. lfs_file_t file;
  899. lfs_file_open(&lfs, &file, "/coffee/drip",
  900. LFS_O_RDONLY) => 0;
  901. lfs_file_close(&lfs, &file) => 0;
  902. lfs_file_open(&lfs, &file, "/./coffee/./coldbrew",
  903. LFS_O_RDONLY) => 0;
  904. lfs_file_close(&lfs, &file) => 0;
  905. lfs_file_open(&lfs, &file, "/././coffee/././turkish",
  906. LFS_O_RDONLY) => 0;
  907. lfs_file_close(&lfs, &file) => 0;
  908. lfs_file_open(&lfs, &file, "/./././coffee/./././tubruk",
  909. LFS_O_RDONLY) => 0;
  910. lfs_file_close(&lfs, &file) => 0;
  911. lfs_file_open(&lfs, &file, "/././././coffee/././././vietnamese",
  912. LFS_O_RDONLY) => 0;
  913. lfs_file_close(&lfs, &file) => 0;
  914. lfs_file_open(&lfs, &file, "/./././././coffee/./././././thai",
  915. LFS_O_RDONLY) => 0;
  916. lfs_file_close(&lfs, &file) => 0;
  917. }
  918. // dir open paths, only works on dirs!
  919. if (DIR) {
  920. lfs_dir_t dir;
  921. lfs_dir_open(&lfs, &dir, "/coffee/drip") => 0;
  922. lfs_dir_close(&lfs, &dir) => 0;
  923. lfs_dir_open(&lfs, &dir, "/./coffee/./coldbrew") => 0;
  924. lfs_dir_close(&lfs, &dir) => 0;
  925. lfs_dir_open(&lfs, &dir, "/././coffee/././turkish") => 0;
  926. lfs_dir_close(&lfs, &dir) => 0;
  927. lfs_dir_open(&lfs, &dir, "/./././coffee/./././tubruk") => 0;
  928. lfs_dir_close(&lfs, &dir) => 0;
  929. lfs_dir_open(&lfs, &dir, "/././././coffee/././././vietnamese") => 0;
  930. lfs_dir_close(&lfs, &dir) => 0;
  931. lfs_dir_open(&lfs, &dir, "/./././././coffee/./././././thai") => 0;
  932. lfs_dir_close(&lfs, &dir) => 0;
  933. } else {
  934. lfs_dir_t dir;
  935. lfs_dir_open(&lfs, &dir, "/coffee/drip") => LFS_ERR_NOTDIR;
  936. lfs_dir_open(&lfs, &dir, "/./coffee/./coldbrew") => LFS_ERR_NOTDIR;
  937. lfs_dir_open(&lfs, &dir, "/././coffee/././turkish") => LFS_ERR_NOTDIR;
  938. lfs_dir_open(&lfs, &dir, "/./././coffee/./././tubruk") => LFS_ERR_NOTDIR;
  939. lfs_dir_open(&lfs, &dir, "/././././coffee/././././vietnamese") => LFS_ERR_NOTDIR;
  940. lfs_dir_open(&lfs, &dir, "/./././././coffee/./././././thai") => LFS_ERR_NOTDIR;
  941. }
  942. // rename paths
  943. lfs_mkdir(&lfs, "espresso") => 0;
  944. lfs_rename(&lfs,
  945. "/./././././coffee/./././././drip",
  946. "/espresso/espresso") => 0;
  947. lfs_rename(&lfs,
  948. "/././././coffee/././././coldbrew",
  949. "/./espresso/./americano") => 0;
  950. lfs_rename(&lfs,
  951. "/./././coffee/./././turkish",
  952. "/././espresso/././macchiato") => 0;
  953. lfs_rename(&lfs,
  954. "/././coffee/././tubruk",
  955. "/./././espresso/./././latte") => 0;
  956. lfs_rename(&lfs,
  957. "/./coffee/./vietnamese",
  958. "/././././espresso/././././cappuccino") => 0;
  959. lfs_rename(&lfs,
  960. "/coffee/thai",
  961. "/./././././espresso/./././././mocha") => 0;
  962. // stat paths
  963. lfs_stat(&lfs, "/./././././espresso/./././././espresso", &info) => 0;
  964. assert(strcmp(info.name, "espresso") == 0);
  965. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  966. lfs_stat(&lfs, "/././././espresso/././././americano", &info) => 0;
  967. assert(strcmp(info.name, "americano") == 0);
  968. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  969. lfs_stat(&lfs, "/./././espresso/./././macchiato", &info) => 0;
  970. assert(strcmp(info.name, "macchiato") == 0);
  971. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  972. lfs_stat(&lfs, "/././espresso/././latte", &info) => 0;
  973. assert(strcmp(info.name, "latte") == 0);
  974. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  975. lfs_stat(&lfs, "/./espresso/./cappuccino", &info) => 0;
  976. assert(strcmp(info.name, "cappuccino") == 0);
  977. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  978. lfs_stat(&lfs, "/espresso/mocha", &info) => 0;
  979. assert(strcmp(info.name, "mocha") == 0);
  980. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  981. lfs_stat(&lfs, "/./././././coffee/./././././drip", &info) => LFS_ERR_NOENT;
  982. lfs_stat(&lfs, "/././././coffee/././././coldbrew", &info) => LFS_ERR_NOENT;
  983. lfs_stat(&lfs, "/./././coffee/./././turkish", &info) => LFS_ERR_NOENT;
  984. lfs_stat(&lfs, "/././coffee/././tubruk", &info) => LFS_ERR_NOENT;
  985. lfs_stat(&lfs, "/./coffee/./vietnamese", &info) => LFS_ERR_NOENT;
  986. lfs_stat(&lfs, "/coffee/thai", &info) => LFS_ERR_NOENT;
  987. // remove paths
  988. lfs_remove(&lfs, "/espresso/espresso") => 0;
  989. lfs_remove(&lfs, "/./espresso/./americano") => 0;
  990. lfs_remove(&lfs, "/././espresso/././macchiato") => 0;
  991. lfs_remove(&lfs, "/./././espresso/./././latte") => 0;
  992. lfs_remove(&lfs, "/././././espresso/././././cappuccino") => 0;
  993. lfs_remove(&lfs, "/./././././espresso/./././././mocha") => 0;
  994. // stat paths
  995. lfs_stat(&lfs, "/./././././espresso/./././././espresso", &info) => LFS_ERR_NOENT;
  996. lfs_stat(&lfs, "/././././espresso/././././americano", &info) => LFS_ERR_NOENT;
  997. lfs_stat(&lfs, "/./././espresso/./././macchiato", &info) => LFS_ERR_NOENT;
  998. lfs_stat(&lfs, "/././espresso/././latte", &info) => LFS_ERR_NOENT;
  999. lfs_stat(&lfs, "/./espresso/./cappuccino", &info) => LFS_ERR_NOENT;
  1000. lfs_stat(&lfs, "/espresso/mocha", &info) => LFS_ERR_NOENT;
  1001. lfs_unmount(&lfs) => 0;
  1002. '''
  1003. # test trailing dots, these get a bit weird
  1004. #
  1005. # POSIX deviations:
  1006. #
  1007. # - We accept modifications of directories with trailing dots:
  1008. # - littlefs: remove("a/.") => 0
  1009. # - POSIX: remove("a/.") => EBUSY
  1010. # Reason: Not worth implementing.
  1011. #
  1012. [cases.test_paths_trailing_dots]
  1013. defines.DIR = [false, true]
  1014. code = '''
  1015. lfs_t lfs;
  1016. lfs_format(&lfs, cfg) => 0;
  1017. lfs_mount(&lfs, cfg) => 0;
  1018. // create paths
  1019. lfs_mkdir(&lfs, "coffee") => 0;
  1020. if (DIR) {
  1021. lfs_mkdir(&lfs, "coffee/drip/.") => LFS_ERR_NOENT;
  1022. lfs_mkdir(&lfs, "coffee/coldbrew/./.") => LFS_ERR_NOENT;
  1023. lfs_mkdir(&lfs, "coffee/turkish/././.") => LFS_ERR_NOENT;
  1024. lfs_mkdir(&lfs, "coffee/tubruk/./././.") => LFS_ERR_NOENT;
  1025. lfs_mkdir(&lfs, "coffee/vietnamese/././././.") => LFS_ERR_NOENT;
  1026. lfs_mkdir(&lfs, "coffee/thai/./././././.") => LFS_ERR_NOENT;
  1027. // still create so we have something to test
  1028. lfs_mkdir(&lfs, "coffee/drip") => 0;
  1029. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  1030. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  1031. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  1032. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  1033. lfs_mkdir(&lfs, "coffee/thai") => 0;
  1034. } else {
  1035. lfs_file_t file;
  1036. lfs_file_open(&lfs, &file, "coffee/drip/.",
  1037. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1038. lfs_file_open(&lfs, &file, "coffee/coldbrew/./.",
  1039. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1040. lfs_file_open(&lfs, &file, "coffee/turkish/././.",
  1041. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1042. lfs_file_open(&lfs, &file, "coffee/tubruk/./././.",
  1043. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1044. lfs_file_open(&lfs, &file, "coffee/vietnamese/././././.",
  1045. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1046. lfs_file_open(&lfs, &file, "coffee/thai/./././././.",
  1047. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1048. // still create so we have something to test
  1049. lfs_file_open(&lfs, &file, "coffee/drip",
  1050. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1051. lfs_file_close(&lfs, &file) => 0;
  1052. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  1053. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1054. lfs_file_close(&lfs, &file) => 0;
  1055. lfs_file_open(&lfs, &file, "coffee/turkish",
  1056. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1057. lfs_file_close(&lfs, &file) => 0;
  1058. lfs_file_open(&lfs, &file, "coffee/tubruk",
  1059. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1060. lfs_file_close(&lfs, &file) => 0;
  1061. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  1062. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1063. lfs_file_close(&lfs, &file) => 0;
  1064. lfs_file_open(&lfs, &file, "coffee/thai",
  1065. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1066. lfs_file_close(&lfs, &file) => 0;
  1067. }
  1068. // stat paths
  1069. struct lfs_info info;
  1070. if (DIR) {
  1071. lfs_stat(&lfs, "coffee/drip/./././././.", &info) => 0;
  1072. assert(strcmp(info.name, "drip") == 0);
  1073. assert(info.type == LFS_TYPE_DIR);
  1074. lfs_stat(&lfs, "coffee/coldbrew/././././.", &info) => 0;
  1075. assert(strcmp(info.name, "coldbrew") == 0);
  1076. assert(info.type == LFS_TYPE_DIR);
  1077. lfs_stat(&lfs, "coffee/turkish/./././.", &info) => 0;
  1078. assert(strcmp(info.name, "turkish") == 0);
  1079. assert(info.type == LFS_TYPE_DIR);
  1080. lfs_stat(&lfs, "coffee/tubruk/././.", &info) => 0;
  1081. assert(strcmp(info.name, "tubruk") == 0);
  1082. assert(info.type == LFS_TYPE_DIR);
  1083. lfs_stat(&lfs, "coffee/vietnamese/./.", &info) => 0;
  1084. assert(strcmp(info.name, "vietnamese") == 0);
  1085. assert(info.type == LFS_TYPE_DIR);
  1086. lfs_stat(&lfs, "coffee/thai/.", &info) => 0;
  1087. assert(strcmp(info.name, "thai") == 0);
  1088. assert(info.type == LFS_TYPE_DIR);
  1089. } else {
  1090. lfs_stat(&lfs, "coffee/drip/./././././.", &info) => LFS_ERR_NOTDIR;
  1091. lfs_stat(&lfs, "coffee/coldbrew/././././.", &info) => LFS_ERR_NOTDIR;
  1092. lfs_stat(&lfs, "coffee/turkish/./././.", &info) => LFS_ERR_NOTDIR;
  1093. lfs_stat(&lfs, "coffee/tubruk/././.", &info) => LFS_ERR_NOTDIR;
  1094. lfs_stat(&lfs, "coffee/vietnamese/./.", &info) => LFS_ERR_NOTDIR;
  1095. lfs_stat(&lfs, "coffee/thai/.", &info) => LFS_ERR_NOTDIR;
  1096. }
  1097. // file open paths, only works on files!
  1098. if (DIR) {
  1099. lfs_file_t file;
  1100. lfs_file_open(&lfs, &file, "coffee/drip/.",
  1101. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1102. lfs_file_open(&lfs, &file, "coffee/coldbrew/./.",
  1103. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1104. lfs_file_open(&lfs, &file, "coffee/turkish/././.",
  1105. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1106. lfs_file_open(&lfs, &file, "coffee/tubruk/./././.",
  1107. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1108. lfs_file_open(&lfs, &file, "coffee/vietnamese/././././.",
  1109. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1110. lfs_file_open(&lfs, &file, "coffee/thai/./././././.",
  1111. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1112. } else {
  1113. lfs_file_t file;
  1114. lfs_file_open(&lfs, &file, "coffee/drip/.",
  1115. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1116. lfs_file_open(&lfs, &file, "coffee/coldbrew/./.",
  1117. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1118. lfs_file_open(&lfs, &file, "coffee/turkish/././.",
  1119. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1120. lfs_file_open(&lfs, &file, "coffee/tubruk/./././.",
  1121. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1122. lfs_file_open(&lfs, &file, "coffee/vietnamese/././././.",
  1123. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1124. lfs_file_open(&lfs, &file, "coffee/thai/./././././.",
  1125. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1126. }
  1127. // dir open paths, only works on dirs!
  1128. if (DIR) {
  1129. lfs_dir_t dir;
  1130. lfs_dir_open(&lfs, &dir, "coffee/drip/.") => 0;
  1131. lfs_dir_close(&lfs, &dir) => 0;
  1132. lfs_dir_open(&lfs, &dir, "coffee/coldbrew/./.") => 0;
  1133. lfs_dir_close(&lfs, &dir) => 0;
  1134. lfs_dir_open(&lfs, &dir, "coffee/turkish/././.") => 0;
  1135. lfs_dir_close(&lfs, &dir) => 0;
  1136. lfs_dir_open(&lfs, &dir, "coffee/tubruk/./././.") => 0;
  1137. lfs_dir_close(&lfs, &dir) => 0;
  1138. lfs_dir_open(&lfs, &dir, "coffee/vietnamese/././././.") => 0;
  1139. lfs_dir_close(&lfs, &dir) => 0;
  1140. lfs_dir_open(&lfs, &dir, "coffee/thai/./././././.") => 0;
  1141. lfs_dir_close(&lfs, &dir) => 0;
  1142. } else {
  1143. lfs_dir_t dir;
  1144. lfs_dir_open(&lfs, &dir, "coffee/drip/.") => LFS_ERR_NOTDIR;
  1145. lfs_dir_open(&lfs, &dir, "coffee/coldbrew/./.") => LFS_ERR_NOTDIR;
  1146. lfs_dir_open(&lfs, &dir, "coffee/turkish/././.") => LFS_ERR_NOTDIR;
  1147. lfs_dir_open(&lfs, &dir, "coffee/tubruk/./././.") => LFS_ERR_NOTDIR;
  1148. lfs_dir_open(&lfs, &dir, "coffee/vietnamese/././././.") => LFS_ERR_NOTDIR;
  1149. lfs_dir_open(&lfs, &dir, "coffee/thai/./././././.") => LFS_ERR_NOTDIR;
  1150. }
  1151. // rename paths
  1152. lfs_mkdir(&lfs, "espresso") => 0;
  1153. if (DIR) {
  1154. // bad destination
  1155. lfs_rename(&lfs,
  1156. "coffee/drip",
  1157. "espresso/espresso/.") => LFS_ERR_NOENT;
  1158. lfs_rename(&lfs,
  1159. "coffee/coldbrew",
  1160. "espresso/americano/./.") => LFS_ERR_NOENT;
  1161. lfs_rename(&lfs,
  1162. "coffee/turkish",
  1163. "espresso/macchiato/././.") => LFS_ERR_NOENT;
  1164. lfs_rename(&lfs,
  1165. "coffee/tubruk",
  1166. "espresso/latte/./././.") => LFS_ERR_NOENT;
  1167. lfs_rename(&lfs,
  1168. "coffee/vietnamese",
  1169. "espresso/cappuccino/././././.") => LFS_ERR_NOENT;
  1170. lfs_rename(&lfs,
  1171. "coffee/thai",
  1172. "espresso/mocha/./././././.") => LFS_ERR_NOENT;
  1173. // bad source and bad destination
  1174. lfs_rename(&lfs,
  1175. "coffee/drip/./././././.",
  1176. "espresso/espresso/.") => LFS_ERR_NOENT;
  1177. lfs_rename(&lfs,
  1178. "coffee/coldbrew/././././.",
  1179. "espresso/americano/./.") => LFS_ERR_NOENT;
  1180. lfs_rename(&lfs,
  1181. "coffee/turkish/./././.",
  1182. "espresso/macchiato/././.") => LFS_ERR_NOENT;
  1183. lfs_rename(&lfs,
  1184. "coffee/tubruk/././.",
  1185. "espresso/latte/./././.") => LFS_ERR_NOENT;
  1186. lfs_rename(&lfs,
  1187. "coffee/vietnamese/./.",
  1188. "espresso/cappuccino/././././.") => LFS_ERR_NOENT;
  1189. lfs_rename(&lfs,
  1190. "coffee/thai/.",
  1191. "espresso/mocha/./././././.") => LFS_ERR_NOENT;
  1192. // this one works
  1193. lfs_rename(&lfs,
  1194. "coffee/drip/./././././.",
  1195. "espresso/espresso") => 0;
  1196. lfs_rename(&lfs,
  1197. "coffee/coldbrew/././././.",
  1198. "espresso/americano") => 0;
  1199. lfs_rename(&lfs,
  1200. "coffee/turkish/./././.",
  1201. "espresso/macchiato") => 0;
  1202. lfs_rename(&lfs,
  1203. "coffee/tubruk/././.",
  1204. "espresso/latte") => 0;
  1205. lfs_rename(&lfs,
  1206. "coffee/vietnamese/./.",
  1207. "espresso/cappuccino") => 0;
  1208. lfs_rename(&lfs,
  1209. "coffee/thai/.",
  1210. "espresso/mocha") => 0;
  1211. // stat paths
  1212. lfs_stat(&lfs, "espresso/espresso/./././././.", &info) => 0;
  1213. assert(strcmp(info.name, "espresso") == 0);
  1214. assert(info.type == LFS_TYPE_DIR);
  1215. lfs_stat(&lfs, "espresso/americano/././././.", &info) => 0;
  1216. assert(strcmp(info.name, "americano") == 0);
  1217. assert(info.type == LFS_TYPE_DIR);
  1218. lfs_stat(&lfs, "espresso/macchiato/./././.", &info) => 0;
  1219. assert(strcmp(info.name, "macchiato") == 0);
  1220. assert(info.type == LFS_TYPE_DIR);
  1221. lfs_stat(&lfs, "espresso/latte/././.", &info) => 0;
  1222. assert(strcmp(info.name, "latte") == 0);
  1223. assert(info.type == LFS_TYPE_DIR);
  1224. lfs_stat(&lfs, "espresso/cappuccino/./.", &info) => 0;
  1225. assert(strcmp(info.name, "cappuccino") == 0);
  1226. assert(info.type == LFS_TYPE_DIR);
  1227. lfs_stat(&lfs, "espresso/mocha/.", &info) => 0;
  1228. assert(strcmp(info.name, "mocha") == 0);
  1229. assert(info.type == LFS_TYPE_DIR);
  1230. lfs_stat(&lfs, "coffee/drip/./././././.", &info) => LFS_ERR_NOENT;
  1231. lfs_stat(&lfs, "coffee/coldbrew/././././.", &info) => LFS_ERR_NOENT;
  1232. lfs_stat(&lfs, "coffee/turkish/./././.", &info) => LFS_ERR_NOENT;
  1233. lfs_stat(&lfs, "coffee/tubruk/././.", &info) => LFS_ERR_NOENT;
  1234. lfs_stat(&lfs, "coffee/vietnamese/./.", &info) => LFS_ERR_NOENT;
  1235. lfs_stat(&lfs, "coffee/thai/.", &info) => LFS_ERR_NOENT;
  1236. // remove paths
  1237. lfs_remove(&lfs, "espresso/espresso/.") => 0;
  1238. lfs_remove(&lfs, "espresso/americano/./.") => 0;
  1239. lfs_remove(&lfs, "espresso/macchiato/././.") => 0;
  1240. lfs_remove(&lfs, "espresso/latte/./././.") => 0;
  1241. lfs_remove(&lfs, "espresso/cappuccino/././././.") => 0;
  1242. lfs_remove(&lfs, "espresso/mocha/./././././.") => 0;
  1243. // stat paths
  1244. lfs_stat(&lfs, "espresso/espresso/./././././.", &info) => LFS_ERR_NOENT;
  1245. lfs_stat(&lfs, "espresso/americano/././././.", &info) => LFS_ERR_NOENT;
  1246. lfs_stat(&lfs, "espresso/macchiato/./././.", &info) => LFS_ERR_NOENT;
  1247. lfs_stat(&lfs, "espresso/latte/././.", &info) => LFS_ERR_NOENT;
  1248. lfs_stat(&lfs, "espresso/cappuccino/./.", &info) => LFS_ERR_NOENT;
  1249. lfs_stat(&lfs, "espresso/mocha/.", &info) => LFS_ERR_NOENT;
  1250. } else {
  1251. // bad source
  1252. lfs_rename(&lfs,
  1253. "coffee/drip/./././././.",
  1254. "espresso/espresso") => LFS_ERR_NOTDIR;
  1255. lfs_rename(&lfs,
  1256. "coffee/coldbrew/././././.",
  1257. "espresso/americano") => LFS_ERR_NOTDIR;
  1258. lfs_rename(&lfs,
  1259. "coffee/turkish/./././.",
  1260. "espresso/macchiato") => LFS_ERR_NOTDIR;
  1261. lfs_rename(&lfs,
  1262. "coffee/tubruk/././.",
  1263. "espresso/latte") => LFS_ERR_NOTDIR;
  1264. lfs_rename(&lfs,
  1265. "coffee/vietnamese/./.",
  1266. "espresso/cappuccino") => LFS_ERR_NOTDIR;
  1267. lfs_rename(&lfs,
  1268. "coffee/thai/.",
  1269. "espresso/mocha") => LFS_ERR_NOTDIR;
  1270. // bad destination
  1271. lfs_rename(&lfs,
  1272. "coffee/drip",
  1273. "espresso/espresso/.") => LFS_ERR_NOENT;
  1274. lfs_rename(&lfs,
  1275. "coffee/coldbrew",
  1276. "espresso/americano/./.") => LFS_ERR_NOENT;
  1277. lfs_rename(&lfs,
  1278. "coffee/turkish",
  1279. "espresso/macchiato/././.") => LFS_ERR_NOENT;
  1280. lfs_rename(&lfs,
  1281. "coffee/tubruk",
  1282. "espresso/latte/./././.") => LFS_ERR_NOENT;
  1283. lfs_rename(&lfs,
  1284. "coffee/vietnamese",
  1285. "espresso/cappuccino/././././.") => LFS_ERR_NOENT;
  1286. lfs_rename(&lfs,
  1287. "coffee/thai",
  1288. "espresso/mocha/./././././.") => LFS_ERR_NOENT;
  1289. // bad source and bad destination
  1290. lfs_rename(&lfs,
  1291. "coffee/drip/./././././.",
  1292. "espresso/espresso/.") => LFS_ERR_NOTDIR;
  1293. lfs_rename(&lfs,
  1294. "coffee/coldbrew/././././.",
  1295. "espresso/americano/./.") => LFS_ERR_NOTDIR;
  1296. lfs_rename(&lfs,
  1297. "coffee/turkish/./././.",
  1298. "espresso/macchiato/././.") => LFS_ERR_NOTDIR;
  1299. lfs_rename(&lfs,
  1300. "coffee/tubruk/././.",
  1301. "espresso/latte/./././.") => LFS_ERR_NOTDIR;
  1302. lfs_rename(&lfs,
  1303. "coffee/vietnamese/./.",
  1304. "espresso/cappuccino/././././.") => LFS_ERR_NOTDIR;
  1305. lfs_rename(&lfs,
  1306. "coffee/thai/.",
  1307. "espresso/mocha/./././././.") => LFS_ERR_NOTDIR;
  1308. // remove paths
  1309. lfs_remove(&lfs, "coffee/drip/.") => LFS_ERR_NOTDIR;
  1310. lfs_remove(&lfs, "coffee/coldbrew/./.") => LFS_ERR_NOTDIR;
  1311. lfs_remove(&lfs, "coffee/turkish/././.") => LFS_ERR_NOTDIR;
  1312. lfs_remove(&lfs, "coffee/tubruk/./././.") => LFS_ERR_NOTDIR;
  1313. lfs_remove(&lfs, "coffee/vietnamese/././././.") => LFS_ERR_NOTDIR;
  1314. lfs_remove(&lfs, "coffee/thai/./././././.") => LFS_ERR_NOTDIR;
  1315. // stat paths
  1316. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  1317. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  1318. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  1319. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  1320. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  1321. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  1322. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  1323. assert(strcmp(info.name, "drip") == 0);
  1324. assert(info.type == LFS_TYPE_REG);
  1325. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  1326. assert(strcmp(info.name, "coldbrew") == 0);
  1327. assert(info.type == LFS_TYPE_REG);
  1328. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  1329. assert(strcmp(info.name, "turkish") == 0);
  1330. assert(info.type == LFS_TYPE_REG);
  1331. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  1332. assert(strcmp(info.name, "tubruk") == 0);
  1333. assert(info.type == LFS_TYPE_REG);
  1334. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  1335. assert(strcmp(info.name, "vietnamese") == 0);
  1336. assert(info.type == LFS_TYPE_REG);
  1337. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  1338. assert(strcmp(info.name, "thai") == 0);
  1339. assert(info.type == LFS_TYPE_REG);
  1340. }
  1341. lfs_unmount(&lfs) => 0;
  1342. '''
  1343. # dot dot path tests
  1344. [cases.test_paths_dotdots]
  1345. defines.DIR = [false, true]
  1346. code = '''
  1347. lfs_t lfs;
  1348. lfs_format(&lfs, cfg) => 0;
  1349. lfs_mount(&lfs, cfg) => 0;
  1350. // create paths
  1351. lfs_mkdir(&lfs, "no") => 0;
  1352. lfs_mkdir(&lfs, "no/no") => 0;
  1353. lfs_mkdir(&lfs, "coffee") => 0;
  1354. lfs_mkdir(&lfs, "coffee/no") => 0;
  1355. if (DIR) {
  1356. lfs_mkdir(&lfs, "/coffee/drip") => 0;
  1357. lfs_mkdir(&lfs, "/no/../coffee/coldbrew") => 0;
  1358. lfs_mkdir(&lfs, "/coffee/no/../turkish") => 0;
  1359. lfs_mkdir(&lfs, "/no/no/../../coffee/tubruk") => 0;
  1360. lfs_mkdir(&lfs, "/no/no/../../coffee/no/../vietnamese") => 0;
  1361. lfs_mkdir(&lfs, "/no/no/../../no/no/../../coffee/thai") => 0;
  1362. } else {
  1363. lfs_file_t file;
  1364. lfs_file_open(&lfs, &file, "/coffee/drip",
  1365. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1366. lfs_file_close(&lfs, &file) => 0;
  1367. lfs_file_open(&lfs, &file, "/no/../coffee/coldbrew",
  1368. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1369. lfs_file_close(&lfs, &file) => 0;
  1370. lfs_file_open(&lfs, &file, "/coffee/no/../turkish",
  1371. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1372. lfs_file_close(&lfs, &file) => 0;
  1373. lfs_file_open(&lfs, &file, "/no/no/../../coffee/tubruk",
  1374. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1375. lfs_file_close(&lfs, &file) => 0;
  1376. lfs_file_open(&lfs, &file, "/no/no/../../coffee/no/../vietnamese",
  1377. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1378. lfs_file_close(&lfs, &file) => 0;
  1379. lfs_file_open(&lfs, &file, "/no/no/../../no/no/../../coffee/thai",
  1380. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1381. lfs_file_close(&lfs, &file) => 0;
  1382. }
  1383. // stat paths
  1384. struct lfs_info info;
  1385. lfs_stat(&lfs, "/no/no/../../no/no/../../coffee/drip", &info) => 0;
  1386. assert(strcmp(info.name, "drip") == 0);
  1387. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1388. lfs_stat(&lfs, "/no/no/../../coffee/no/../coldbrew", &info) => 0;
  1389. assert(strcmp(info.name, "coldbrew") == 0);
  1390. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1391. lfs_stat(&lfs, "/no/no/../../coffee/turkish", &info) => 0;
  1392. assert(strcmp(info.name, "turkish") == 0);
  1393. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1394. lfs_stat(&lfs, "/coffee/no/../tubruk", &info) => 0;
  1395. assert(strcmp(info.name, "tubruk") == 0);
  1396. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1397. lfs_stat(&lfs, "/no/../coffee/vietnamese", &info) => 0;
  1398. assert(strcmp(info.name, "vietnamese") == 0);
  1399. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1400. lfs_stat(&lfs, "/coffee/thai", &info) => 0;
  1401. assert(strcmp(info.name, "thai") == 0);
  1402. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1403. // file open paths, only works on files!
  1404. if (DIR) {
  1405. lfs_file_t file;
  1406. lfs_file_open(&lfs, &file, "/coffee/drip",
  1407. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1408. lfs_file_open(&lfs, &file, "/no/../coffee/coldbrew",
  1409. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1410. lfs_file_open(&lfs, &file, "/coffee/no/../turkish",
  1411. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1412. lfs_file_open(&lfs, &file, "/no/no/../../coffee/tubruk",
  1413. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1414. lfs_file_open(&lfs, &file, "/no/no/../../coffee/no/../vietnamese",
  1415. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1416. lfs_file_open(&lfs, &file, "/no/no/../../no/no/../../coffee/thai",
  1417. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1418. } else {
  1419. lfs_file_t file;
  1420. lfs_file_open(&lfs, &file, "/coffee/drip",
  1421. LFS_O_RDONLY) => 0;
  1422. lfs_file_close(&lfs, &file) => 0;
  1423. lfs_file_open(&lfs, &file, "/no/../coffee/coldbrew",
  1424. LFS_O_RDONLY) => 0;
  1425. lfs_file_close(&lfs, &file) => 0;
  1426. lfs_file_open(&lfs, &file, "/coffee/no/../turkish",
  1427. LFS_O_RDONLY) => 0;
  1428. lfs_file_close(&lfs, &file) => 0;
  1429. lfs_file_open(&lfs, &file, "/no/no/../../coffee/tubruk",
  1430. LFS_O_RDONLY) => 0;
  1431. lfs_file_close(&lfs, &file) => 0;
  1432. lfs_file_open(&lfs, &file, "/no/no/../../coffee/no/../vietnamese",
  1433. LFS_O_RDONLY) => 0;
  1434. lfs_file_close(&lfs, &file) => 0;
  1435. lfs_file_open(&lfs, &file, "/no/no/../../no/no/../../coffee/thai",
  1436. LFS_O_RDONLY) => 0;
  1437. lfs_file_close(&lfs, &file) => 0;
  1438. }
  1439. // dir open paths, only works on dirs!
  1440. if (DIR) {
  1441. lfs_dir_t dir;
  1442. lfs_dir_open(&lfs, &dir, "/coffee/drip") => 0;
  1443. lfs_dir_close(&lfs, &dir) => 0;
  1444. lfs_dir_open(&lfs, &dir, "/no/../coffee/coldbrew") => 0;
  1445. lfs_dir_close(&lfs, &dir) => 0;
  1446. lfs_dir_open(&lfs, &dir, "/coffee/no/../turkish") => 0;
  1447. lfs_dir_close(&lfs, &dir) => 0;
  1448. lfs_dir_open(&lfs, &dir, "/no/no/../../coffee/tubruk") => 0;
  1449. lfs_dir_close(&lfs, &dir) => 0;
  1450. lfs_dir_open(&lfs, &dir, "/no/no/../../coffee/no/../vietnamese") => 0;
  1451. lfs_dir_close(&lfs, &dir) => 0;
  1452. lfs_dir_open(&lfs, &dir, "/no/no/../../no/no/../../coffee/thai") => 0;
  1453. lfs_dir_close(&lfs, &dir) => 0;
  1454. } else {
  1455. lfs_dir_t dir;
  1456. lfs_dir_open(&lfs, &dir, "/coffee/drip") => LFS_ERR_NOTDIR;
  1457. lfs_dir_open(&lfs, &dir, "/no/../coffee/coldbrew") => LFS_ERR_NOTDIR;
  1458. lfs_dir_open(&lfs, &dir, "/coffee/no/../turkish") => LFS_ERR_NOTDIR;
  1459. lfs_dir_open(&lfs, &dir, "/no/no/../../coffee/tubruk") => LFS_ERR_NOTDIR;
  1460. lfs_dir_open(&lfs, &dir, "/no/no/../../coffee/no/../vietnamese") => LFS_ERR_NOTDIR;
  1461. lfs_dir_open(&lfs, &dir, "/no/no/../../no/no/../../coffee/thai") => LFS_ERR_NOTDIR;
  1462. }
  1463. // rename paths
  1464. lfs_mkdir(&lfs, "espresso") => 0;
  1465. lfs_rename(&lfs,
  1466. "/no/no/../../no/no/../../coffee/drip",
  1467. "/espresso/espresso") => 0;
  1468. lfs_rename(&lfs,
  1469. "/no/no/../../coffee/no/../coldbrew",
  1470. "/no/../espresso/americano") => 0;
  1471. lfs_rename(&lfs,
  1472. "/no/no/../../coffee/turkish",
  1473. "/espresso/no/../macchiato") => 0;
  1474. lfs_rename(&lfs,
  1475. "/coffee/no/../tubruk",
  1476. "/no/no/../../espresso/latte") => 0;
  1477. lfs_rename(&lfs,
  1478. "/no/../coffee/vietnamese",
  1479. "/no/no/../../espresso/no/../cappuccino") => 0;
  1480. lfs_rename(&lfs,
  1481. "/coffee/thai",
  1482. "/no/no/../../no/no/../../espresso/mocha") => 0;
  1483. // stat paths
  1484. lfs_stat(&lfs, "/no/no/../../no/no/../../espresso/espresso", &info) => 0;
  1485. assert(strcmp(info.name, "espresso") == 0);
  1486. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1487. lfs_stat(&lfs, "/no/no/../../espresso/no/../americano", &info) => 0;
  1488. assert(strcmp(info.name, "americano") == 0);
  1489. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1490. lfs_stat(&lfs, "/no/no/../../espresso/macchiato", &info) => 0;
  1491. assert(strcmp(info.name, "macchiato") == 0);
  1492. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1493. lfs_stat(&lfs, "/espresso/no/../latte", &info) => 0;
  1494. assert(strcmp(info.name, "latte") == 0);
  1495. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1496. lfs_stat(&lfs, "/no/../espresso/cappuccino", &info) => 0;
  1497. assert(strcmp(info.name, "cappuccino") == 0);
  1498. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1499. lfs_stat(&lfs, "/espresso/mocha", &info) => 0;
  1500. assert(strcmp(info.name, "mocha") == 0);
  1501. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1502. lfs_stat(&lfs, "/no/no/../../no/no/../../coffee/drip", &info) => LFS_ERR_NOENT;
  1503. lfs_stat(&lfs, "/no/no/../../coffee/no/../coldbrew", &info) => LFS_ERR_NOENT;
  1504. lfs_stat(&lfs, "/no/no/../../coffee/turkish", &info) => LFS_ERR_NOENT;
  1505. lfs_stat(&lfs, "/coffee/no/../tubruk", &info) => LFS_ERR_NOENT;
  1506. lfs_stat(&lfs, "/no/../coffee/vietnamese", &info) => LFS_ERR_NOENT;
  1507. lfs_stat(&lfs, "/coffee/thai", &info) => LFS_ERR_NOENT;
  1508. // remove paths
  1509. lfs_remove(&lfs, "/espresso/espresso") => 0;
  1510. lfs_remove(&lfs, "/no/../espresso/americano") => 0;
  1511. lfs_remove(&lfs, "/espresso/no/../macchiato") => 0;
  1512. lfs_remove(&lfs, "/no/no/../../espresso/latte") => 0;
  1513. lfs_remove(&lfs, "/no/no/../../espresso/no/../cappuccino") => 0;
  1514. lfs_remove(&lfs, "/no/no/../../no/no/../../espresso/mocha") => 0;
  1515. // stat paths
  1516. lfs_stat(&lfs, "/no/no/../../no/no/../../espresso/espresso", &info) => LFS_ERR_NOENT;
  1517. lfs_stat(&lfs, "/no/no/../../espresso/no/../americano", &info) => LFS_ERR_NOENT;
  1518. lfs_stat(&lfs, "/no/no/../../espresso/macchiato", &info) => LFS_ERR_NOENT;
  1519. lfs_stat(&lfs, "/espresso/no/../latte", &info) => LFS_ERR_NOENT;
  1520. lfs_stat(&lfs, "/no/../espresso/cappuccino", &info) => LFS_ERR_NOENT;
  1521. lfs_stat(&lfs, "/espresso/mocha", &info) => LFS_ERR_NOENT;
  1522. lfs_unmount(&lfs) => 0;
  1523. '''
  1524. # test trailing dot dots, these get really weird
  1525. #
  1526. # POSIX deviations:
  1527. #
  1528. # - We do not check for existance of directories followed by dotdots:
  1529. # - littlefs: stat("a/missing/..") => 0
  1530. # - POSIX: stat("a/missing/..") => ENOENT
  1531. # Reason: Difficult to implement non-recursively.
  1532. #
  1533. # - We accept modifications of directories with trailing dotdots:
  1534. # - littlefs: rename("a/b/..", "c") => 0
  1535. # - POSIX: rename("a/b/..", "c") => EBUSY
  1536. # Reason: Not worth implementing.
  1537. #
  1538. [cases.test_paths_trailing_dotdots]
  1539. defines.DIR = [false, true]
  1540. code = '''
  1541. lfs_t lfs;
  1542. lfs_format(&lfs, cfg) => 0;
  1543. lfs_mount(&lfs, cfg) => 0;
  1544. // create paths
  1545. lfs_mkdir(&lfs, "coffee") => 0;
  1546. if (DIR) {
  1547. lfs_mkdir(&lfs, "coffee/drip/..") => LFS_ERR_EXIST;
  1548. lfs_mkdir(&lfs, "coffee/coldbrew/../..") => LFS_ERR_EXIST;
  1549. lfs_mkdir(&lfs, "coffee/turkish/../../..") => LFS_ERR_EXIST;
  1550. lfs_mkdir(&lfs, "coffee/tubruk/../../../..") => LFS_ERR_EXIST;
  1551. lfs_mkdir(&lfs, "coffee/vietnamese/../../../../..") => LFS_ERR_EXIST;
  1552. lfs_mkdir(&lfs, "coffee/thai/../../../../../..") => LFS_ERR_EXIST;
  1553. // still create so we have something to test
  1554. lfs_mkdir(&lfs, "coffee/drip") => 0;
  1555. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  1556. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  1557. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  1558. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  1559. lfs_mkdir(&lfs, "coffee/thai") => 0;
  1560. } else {
  1561. lfs_file_t file;
  1562. lfs_file_open(&lfs, &file, "coffee/drip/..",
  1563. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_EXIST;
  1564. lfs_file_open(&lfs, &file, "coffee/coldbrew/../..",
  1565. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_EXIST;
  1566. lfs_file_open(&lfs, &file, "coffee/turkish/../../..",
  1567. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_EXIST;
  1568. lfs_file_open(&lfs, &file, "coffee/tubruk/../../../..",
  1569. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_EXIST;
  1570. lfs_file_open(&lfs, &file, "coffee/vietnamese/../../../../..",
  1571. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_EXIST;
  1572. lfs_file_open(&lfs, &file, "coffee/thai/../../../../../..",
  1573. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_EXIST;
  1574. // still create so we have something to test
  1575. lfs_file_open(&lfs, &file, "coffee/drip",
  1576. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1577. lfs_file_close(&lfs, &file) => 0;
  1578. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  1579. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1580. lfs_file_close(&lfs, &file) => 0;
  1581. lfs_file_open(&lfs, &file, "coffee/turkish",
  1582. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1583. lfs_file_close(&lfs, &file) => 0;
  1584. lfs_file_open(&lfs, &file, "coffee/tubruk",
  1585. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1586. lfs_file_close(&lfs, &file) => 0;
  1587. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  1588. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1589. lfs_file_close(&lfs, &file) => 0;
  1590. lfs_file_open(&lfs, &file, "coffee/thai",
  1591. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1592. lfs_file_close(&lfs, &file) => 0;
  1593. }
  1594. // stat paths
  1595. struct lfs_info info;
  1596. lfs_stat(&lfs, "coffee/drip/../../../../../..", &info) => 0;
  1597. assert(strcmp(info.name, "/") == 0);
  1598. assert(info.type == LFS_TYPE_DIR);
  1599. lfs_stat(&lfs, "coffee/coldbrew/../../../../..", &info) => 0;
  1600. assert(strcmp(info.name, "/") == 0);
  1601. assert(info.type == LFS_TYPE_DIR);
  1602. lfs_stat(&lfs, "coffee/turkish/../../../..", &info) => 0;
  1603. assert(strcmp(info.name, "/") == 0);
  1604. assert(info.type == LFS_TYPE_DIR);
  1605. lfs_stat(&lfs, "coffee/tubruk/../../..", &info) => 0;
  1606. assert(strcmp(info.name, "/") == 0);
  1607. assert(info.type == LFS_TYPE_DIR);
  1608. lfs_stat(&lfs, "coffee/vietnamese/../..", &info) => 0;
  1609. assert(strcmp(info.name, "/") == 0);
  1610. assert(info.type == LFS_TYPE_DIR);
  1611. lfs_stat(&lfs, "coffee/thai/..", &info) => 0;
  1612. assert(strcmp(info.name, "coffee") == 0);
  1613. assert(info.type == LFS_TYPE_DIR);
  1614. // file open paths, only works on files!
  1615. lfs_file_t file;
  1616. lfs_file_open(&lfs, &file, "coffee/drip/..",
  1617. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1618. lfs_file_open(&lfs, &file, "coffee/coldbrew/../..",
  1619. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1620. lfs_file_open(&lfs, &file, "coffee/turkish/../../..",
  1621. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1622. lfs_file_open(&lfs, &file, "coffee/tubruk/../../../..",
  1623. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1624. lfs_file_open(&lfs, &file, "coffee/vietnamese/../../../../..",
  1625. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1626. lfs_file_open(&lfs, &file, "coffee/thai/../../../../../..",
  1627. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1628. // dir open paths, only works on dirs!
  1629. lfs_dir_t dir;
  1630. lfs_dir_open(&lfs, &dir, "coffee/drip/..") => 0;
  1631. lfs_dir_close(&lfs, &dir) => 0;
  1632. lfs_dir_open(&lfs, &dir, "coffee/coldbrew/../..") => 0;
  1633. lfs_dir_close(&lfs, &dir) => 0;
  1634. lfs_dir_open(&lfs, &dir, "coffee/turkish/../../..") => 0;
  1635. lfs_dir_close(&lfs, &dir) => 0;
  1636. lfs_dir_open(&lfs, &dir, "coffee/tubruk/../../../..") => 0;
  1637. lfs_dir_close(&lfs, &dir) => 0;
  1638. lfs_dir_open(&lfs, &dir, "coffee/vietnamese/../../../../..") => 0;
  1639. lfs_dir_close(&lfs, &dir) => 0;
  1640. lfs_dir_open(&lfs, &dir, "coffee/thai/../../../../../..") => 0;
  1641. lfs_dir_close(&lfs, &dir) => 0;
  1642. // rename paths
  1643. lfs_mkdir(&lfs, "espresso") => 0;
  1644. // bad source
  1645. lfs_rename(&lfs,
  1646. "coffee/drip/../../../../../..",
  1647. "espresso/espresso") => LFS_ERR_INVAL;
  1648. lfs_rename(&lfs,
  1649. "coffee/coldbrew/../../../../..",
  1650. "espresso/americano") => LFS_ERR_INVAL;
  1651. lfs_rename(&lfs,
  1652. "coffee/turkish/../../../..",
  1653. "espresso/macchiato") => LFS_ERR_INVAL;
  1654. lfs_rename(&lfs,
  1655. "coffee/tubruk/../../..",
  1656. "espresso/latte") => LFS_ERR_INVAL;
  1657. lfs_rename(&lfs,
  1658. "coffee/vietnamese/../..",
  1659. "espresso/cappuccino") => LFS_ERR_INVAL;
  1660. // this one works
  1661. lfs_rename(&lfs,
  1662. "coffee/thai/..",
  1663. "espresso/mocha") => 0;
  1664. lfs_rename(&lfs,
  1665. "espresso/mocha",
  1666. "coffee") => 0;
  1667. // bad destination
  1668. if (DIR) {
  1669. // this one works
  1670. lfs_rename(&lfs,
  1671. "coffee/drip",
  1672. "espresso/espresso/..") => 0;
  1673. lfs_rename(&lfs,
  1674. "espresso",
  1675. "coffee/drip") => 0;
  1676. } else {
  1677. lfs_rename(&lfs,
  1678. "coffee/drip",
  1679. "espresso/espresso/..") => LFS_ERR_ISDIR;
  1680. }
  1681. lfs_rename(&lfs,
  1682. "coffee/coldbrew",
  1683. "espresso/americano/../..") => LFS_ERR_INVAL;
  1684. lfs_rename(&lfs,
  1685. "coffee/turkish",
  1686. "espresso/macchiato/../../..") => LFS_ERR_INVAL;
  1687. lfs_rename(&lfs,
  1688. "coffee/tubruk",
  1689. "espresso/latte/../../../..") => LFS_ERR_INVAL;
  1690. lfs_rename(&lfs,
  1691. "coffee/vietnamese",
  1692. "espresso/cappuccino/../../../../..") => LFS_ERR_INVAL;
  1693. lfs_rename(&lfs,
  1694. "coffee/thai",
  1695. "espresso/mocha/../../../../../..") => LFS_ERR_INVAL;
  1696. // bad source and bad destination
  1697. lfs_rename(&lfs,
  1698. "coffee/drip/../../../../../..",
  1699. "espresso/espresso/..") => LFS_ERR_INVAL;
  1700. lfs_rename(&lfs,
  1701. "coffee/coldbrew/../../../../..",
  1702. "espresso/americano/../..") => LFS_ERR_INVAL;
  1703. lfs_rename(&lfs,
  1704. "coffee/turkish/../../../..",
  1705. "espresso/macchiato/../../..") => LFS_ERR_INVAL;
  1706. lfs_rename(&lfs,
  1707. "coffee/tubruk/../../..",
  1708. "espresso/latte/../../../..") => LFS_ERR_INVAL;
  1709. lfs_rename(&lfs,
  1710. "coffee/vietnamese/../..",
  1711. "espresso/cappuccino/../../../../..") => LFS_ERR_INVAL;
  1712. lfs_rename(&lfs,
  1713. "coffee/thai/..",
  1714. "espresso/mocha/../../../../../..") => LFS_ERR_INVAL;
  1715. // remove paths
  1716. lfs_remove(&lfs, "coffee/drip/..") => LFS_ERR_NOTEMPTY;
  1717. lfs_remove(&lfs, "coffee/coldbrew/../..") => LFS_ERR_INVAL;
  1718. lfs_remove(&lfs, "coffee/turkish/../../..") => LFS_ERR_INVAL;
  1719. lfs_remove(&lfs, "coffee/tubruk/../../../..") => LFS_ERR_INVAL;
  1720. lfs_remove(&lfs, "coffee/vietnamese/../../../../..") => LFS_ERR_INVAL;
  1721. lfs_remove(&lfs, "coffee/thai/../../../../../..") => LFS_ERR_INVAL;
  1722. // stat paths
  1723. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  1724. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  1725. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  1726. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  1727. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  1728. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  1729. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  1730. assert(strcmp(info.name, "drip") == 0);
  1731. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1732. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  1733. assert(strcmp(info.name, "coldbrew") == 0);
  1734. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1735. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  1736. assert(strcmp(info.name, "turkish") == 0);
  1737. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1738. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  1739. assert(strcmp(info.name, "tubruk") == 0);
  1740. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1741. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  1742. assert(strcmp(info.name, "vietnamese") == 0);
  1743. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1744. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  1745. assert(strcmp(info.name, "thai") == 0);
  1746. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1747. lfs_unmount(&lfs) => 0;
  1748. '''
  1749. # dot dot dot path tests
  1750. [cases.test_paths_dotdotdots]
  1751. defines.DIR = [false, true]
  1752. code = '''
  1753. lfs_t lfs;
  1754. lfs_format(&lfs, cfg) => 0;
  1755. lfs_mount(&lfs, cfg) => 0;
  1756. // create paths
  1757. lfs_mkdir(&lfs, "coffee") => 0;
  1758. lfs_mkdir(&lfs, "coffee/...") => 0;
  1759. if (DIR) {
  1760. lfs_mkdir(&lfs, "/coffee/.../drip") => 0;
  1761. lfs_mkdir(&lfs, "/coffee/.../coldbrew") => 0;
  1762. lfs_mkdir(&lfs, "/coffee/.../turkish") => 0;
  1763. lfs_mkdir(&lfs, "/coffee/.../tubruk") => 0;
  1764. lfs_mkdir(&lfs, "/coffee/.../vietnamese") => 0;
  1765. lfs_mkdir(&lfs, "/coffee/.../thai") => 0;
  1766. } else {
  1767. lfs_file_t file;
  1768. lfs_file_open(&lfs, &file, "/coffee/.../drip",
  1769. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1770. lfs_file_close(&lfs, &file) => 0;
  1771. lfs_file_open(&lfs, &file, "/coffee/.../coldbrew",
  1772. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1773. lfs_file_close(&lfs, &file) => 0;
  1774. lfs_file_open(&lfs, &file, "/coffee/.../turkish",
  1775. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1776. lfs_file_close(&lfs, &file) => 0;
  1777. lfs_file_open(&lfs, &file, "/coffee/.../tubruk",
  1778. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1779. lfs_file_close(&lfs, &file) => 0;
  1780. lfs_file_open(&lfs, &file, "/coffee/.../vietnamese",
  1781. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1782. lfs_file_close(&lfs, &file) => 0;
  1783. lfs_file_open(&lfs, &file, "/coffee/.../thai",
  1784. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1785. lfs_file_close(&lfs, &file) => 0;
  1786. }
  1787. // stat paths
  1788. struct lfs_info info;
  1789. lfs_stat(&lfs, "/coffee/.../drip", &info) => 0;
  1790. assert(strcmp(info.name, "drip") == 0);
  1791. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1792. lfs_stat(&lfs, "/coffee/.../coldbrew", &info) => 0;
  1793. assert(strcmp(info.name, "coldbrew") == 0);
  1794. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1795. lfs_stat(&lfs, "/coffee/.../turkish", &info) => 0;
  1796. assert(strcmp(info.name, "turkish") == 0);
  1797. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1798. lfs_stat(&lfs, "/coffee/.../tubruk", &info) => 0;
  1799. assert(strcmp(info.name, "tubruk") == 0);
  1800. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1801. lfs_stat(&lfs, "/coffee/.../vietnamese", &info) => 0;
  1802. assert(strcmp(info.name, "vietnamese") == 0);
  1803. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1804. lfs_stat(&lfs, "/coffee/.../thai", &info) => 0;
  1805. assert(strcmp(info.name, "thai") == 0);
  1806. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1807. // file open paths, only works on files!
  1808. if (DIR) {
  1809. lfs_file_t file;
  1810. lfs_file_open(&lfs, &file, "/coffee/.../drip",
  1811. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1812. lfs_file_open(&lfs, &file, "/coffee/.../coldbrew",
  1813. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1814. lfs_file_open(&lfs, &file, "/coffee/.../turkish",
  1815. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1816. lfs_file_open(&lfs, &file, "/coffee/.../tubruk",
  1817. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1818. lfs_file_open(&lfs, &file, "/coffee/.../vietnamese",
  1819. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1820. lfs_file_open(&lfs, &file, "/coffee/.../thai",
  1821. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1822. } else {
  1823. lfs_file_t file;
  1824. lfs_file_open(&lfs, &file, "/coffee/.../drip",
  1825. LFS_O_RDONLY) => 0;
  1826. lfs_file_close(&lfs, &file) => 0;
  1827. lfs_file_open(&lfs, &file, "/coffee/.../coldbrew",
  1828. LFS_O_RDONLY) => 0;
  1829. lfs_file_close(&lfs, &file) => 0;
  1830. lfs_file_open(&lfs, &file, "/coffee/.../turkish",
  1831. LFS_O_RDONLY) => 0;
  1832. lfs_file_close(&lfs, &file) => 0;
  1833. lfs_file_open(&lfs, &file, "/coffee/.../tubruk",
  1834. LFS_O_RDONLY) => 0;
  1835. lfs_file_close(&lfs, &file) => 0;
  1836. lfs_file_open(&lfs, &file, "/coffee/.../vietnamese",
  1837. LFS_O_RDONLY) => 0;
  1838. lfs_file_close(&lfs, &file) => 0;
  1839. lfs_file_open(&lfs, &file, "/coffee/.../thai",
  1840. LFS_O_RDONLY) => 0;
  1841. lfs_file_close(&lfs, &file) => 0;
  1842. }
  1843. // dir open paths, only works on dirs!
  1844. if (DIR) {
  1845. lfs_dir_t dir;
  1846. lfs_dir_open(&lfs, &dir, "/coffee/.../drip") => 0;
  1847. lfs_dir_close(&lfs, &dir) => 0;
  1848. lfs_dir_open(&lfs, &dir, "/coffee/.../coldbrew") => 0;
  1849. lfs_dir_close(&lfs, &dir) => 0;
  1850. lfs_dir_open(&lfs, &dir, "/coffee/.../turkish") => 0;
  1851. lfs_dir_close(&lfs, &dir) => 0;
  1852. lfs_dir_open(&lfs, &dir, "/coffee/.../tubruk") => 0;
  1853. lfs_dir_close(&lfs, &dir) => 0;
  1854. lfs_dir_open(&lfs, &dir, "/coffee/.../vietnamese") => 0;
  1855. lfs_dir_close(&lfs, &dir) => 0;
  1856. lfs_dir_open(&lfs, &dir, "/coffee/.../thai") => 0;
  1857. lfs_dir_close(&lfs, &dir) => 0;
  1858. } else {
  1859. lfs_dir_t dir;
  1860. lfs_dir_open(&lfs, &dir, "/coffee/.../drip") => LFS_ERR_NOTDIR;
  1861. lfs_dir_open(&lfs, &dir, "/coffee/.../coldbrew") => LFS_ERR_NOTDIR;
  1862. lfs_dir_open(&lfs, &dir, "/coffee/.../turkish") => LFS_ERR_NOTDIR;
  1863. lfs_dir_open(&lfs, &dir, "/coffee/.../tubruk") => LFS_ERR_NOTDIR;
  1864. lfs_dir_open(&lfs, &dir, "/coffee/.../vietnamese") => LFS_ERR_NOTDIR;
  1865. lfs_dir_open(&lfs, &dir, "/coffee/.../thai") => LFS_ERR_NOTDIR;
  1866. }
  1867. // rename paths
  1868. lfs_mkdir(&lfs, "espresso") => 0;
  1869. lfs_mkdir(&lfs, "espresso/...") => 0;
  1870. lfs_rename(&lfs,
  1871. "/coffee/.../drip",
  1872. "/espresso/.../espresso") => 0;
  1873. lfs_rename(&lfs,
  1874. "/coffee/.../coldbrew",
  1875. "/espresso/.../americano") => 0;
  1876. lfs_rename(&lfs,
  1877. "/coffee/.../turkish",
  1878. "/espresso/.../macchiato") => 0;
  1879. lfs_rename(&lfs,
  1880. "/coffee/.../tubruk",
  1881. "/espresso/.../latte") => 0;
  1882. lfs_rename(&lfs,
  1883. "/coffee/.../vietnamese",
  1884. "/espresso/.../cappuccino") => 0;
  1885. lfs_rename(&lfs,
  1886. "/coffee/.../thai",
  1887. "/espresso/.../mocha") => 0;
  1888. // stat paths
  1889. lfs_stat(&lfs, "/espresso/.../espresso", &info) => 0;
  1890. assert(strcmp(info.name, "espresso") == 0);
  1891. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1892. lfs_stat(&lfs, "/espresso/.../americano", &info) => 0;
  1893. assert(strcmp(info.name, "americano") == 0);
  1894. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1895. lfs_stat(&lfs, "/espresso/.../macchiato", &info) => 0;
  1896. assert(strcmp(info.name, "macchiato") == 0);
  1897. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1898. lfs_stat(&lfs, "/espresso/.../latte", &info) => 0;
  1899. assert(strcmp(info.name, "latte") == 0);
  1900. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1901. lfs_stat(&lfs, "/espresso/.../cappuccino", &info) => 0;
  1902. assert(strcmp(info.name, "cappuccino") == 0);
  1903. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1904. lfs_stat(&lfs, "/espresso/.../mocha", &info) => 0;
  1905. assert(strcmp(info.name, "mocha") == 0);
  1906. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1907. lfs_stat(&lfs, "coffee/.../drip", &info) => LFS_ERR_NOENT;
  1908. lfs_stat(&lfs, "coffee/.../coldbrew", &info) => LFS_ERR_NOENT;
  1909. lfs_stat(&lfs, "coffee/.../turkish", &info) => LFS_ERR_NOENT;
  1910. lfs_stat(&lfs, "coffee/.../tubruk", &info) => LFS_ERR_NOENT;
  1911. lfs_stat(&lfs, "coffee/.../vietnamese", &info) => LFS_ERR_NOENT;
  1912. lfs_stat(&lfs, "coffee/.../thai", &info) => LFS_ERR_NOENT;
  1913. // remove paths
  1914. lfs_remove(&lfs, "/espresso/.../espresso") => 0;
  1915. lfs_remove(&lfs, "/espresso/.../americano") => 0;
  1916. lfs_remove(&lfs, "/espresso/.../macchiato") => 0;
  1917. lfs_remove(&lfs, "/espresso/.../latte") => 0;
  1918. lfs_remove(&lfs, "/espresso/.../cappuccino") => 0;
  1919. lfs_remove(&lfs, "/espresso/.../mocha") => 0;
  1920. // stat paths
  1921. lfs_stat(&lfs, "/espresso/.../espresso", &info) => LFS_ERR_NOENT;
  1922. lfs_stat(&lfs, "/espresso/.../americano", &info) => LFS_ERR_NOENT;
  1923. lfs_stat(&lfs, "/espresso/.../macchiato", &info) => LFS_ERR_NOENT;
  1924. lfs_stat(&lfs, "/espresso/.../latte", &info) => LFS_ERR_NOENT;
  1925. lfs_stat(&lfs, "/espresso/.../cappuccino", &info) => LFS_ERR_NOENT;
  1926. lfs_stat(&lfs, "/espresso/.../mocha", &info) => LFS_ERR_NOENT;
  1927. lfs_unmount(&lfs) => 0;
  1928. '''
  1929. # leading dot path test
  1930. [cases.test_paths_leading_dots]
  1931. defines.DIR = [false, true]
  1932. code = '''
  1933. lfs_t lfs;
  1934. lfs_format(&lfs, cfg) => 0;
  1935. lfs_mount(&lfs, cfg) => 0;
  1936. // create paths
  1937. lfs_mkdir(&lfs, "coffee") => 0;
  1938. if (DIR) {
  1939. lfs_mkdir(&lfs, "/coffee/.drip") => 0;
  1940. lfs_mkdir(&lfs, "/coffee/..coldbrew") => 0;
  1941. lfs_mkdir(&lfs, "/coffee/...turkish") => 0;
  1942. lfs_mkdir(&lfs, "/coffee/....tubruk") => 0;
  1943. lfs_mkdir(&lfs, "/coffee/.....vietnamese") => 0;
  1944. lfs_mkdir(&lfs, "/coffee/......thai") => 0;
  1945. } else {
  1946. lfs_file_t file;
  1947. lfs_file_open(&lfs, &file, "/coffee/.drip",
  1948. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1949. lfs_file_close(&lfs, &file) => 0;
  1950. lfs_file_open(&lfs, &file, "/coffee/..coldbrew",
  1951. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1952. lfs_file_close(&lfs, &file) => 0;
  1953. lfs_file_open(&lfs, &file, "/coffee/...turkish",
  1954. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1955. lfs_file_close(&lfs, &file) => 0;
  1956. lfs_file_open(&lfs, &file, "/coffee/....tubruk",
  1957. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1958. lfs_file_close(&lfs, &file) => 0;
  1959. lfs_file_open(&lfs, &file, "/coffee/.....vietnamese",
  1960. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1961. lfs_file_close(&lfs, &file) => 0;
  1962. lfs_file_open(&lfs, &file, "/coffee/......thai",
  1963. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1964. lfs_file_close(&lfs, &file) => 0;
  1965. }
  1966. // stat paths
  1967. struct lfs_info info;
  1968. lfs_stat(&lfs, "/coffee/.drip", &info) => 0;
  1969. assert(strcmp(info.name, ".drip") == 0);
  1970. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1971. lfs_stat(&lfs, "/coffee/..coldbrew", &info) => 0;
  1972. assert(strcmp(info.name, "..coldbrew") == 0);
  1973. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1974. lfs_stat(&lfs, "/coffee/...turkish", &info) => 0;
  1975. assert(strcmp(info.name, "...turkish") == 0);
  1976. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1977. lfs_stat(&lfs, "/coffee/....tubruk", &info) => 0;
  1978. assert(strcmp(info.name, "....tubruk") == 0);
  1979. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1980. lfs_stat(&lfs, "/coffee/.....vietnamese", &info) => 0;
  1981. assert(strcmp(info.name, ".....vietnamese") == 0);
  1982. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1983. lfs_stat(&lfs, "/coffee/......thai", &info) => 0;
  1984. assert(strcmp(info.name, "......thai") == 0);
  1985. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1986. // file open paths, only works on files!
  1987. if (DIR) {
  1988. lfs_file_t file;
  1989. lfs_file_open(&lfs, &file, "/coffee/.drip",
  1990. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1991. lfs_file_open(&lfs, &file, "/coffee/..coldbrew",
  1992. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1993. lfs_file_open(&lfs, &file, "/coffee/...turkish",
  1994. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1995. lfs_file_open(&lfs, &file, "/coffee/....tubruk",
  1996. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1997. lfs_file_open(&lfs, &file, "/coffee/.....vietnamese",
  1998. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1999. lfs_file_open(&lfs, &file, "/coffee/......thai",
  2000. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2001. } else {
  2002. lfs_file_t file;
  2003. lfs_file_open(&lfs, &file, "/coffee/.drip",
  2004. LFS_O_RDONLY) => 0;
  2005. lfs_file_close(&lfs, &file) => 0;
  2006. lfs_file_open(&lfs, &file, "/coffee/..coldbrew",
  2007. LFS_O_RDONLY) => 0;
  2008. lfs_file_close(&lfs, &file) => 0;
  2009. lfs_file_open(&lfs, &file, "/coffee/...turkish",
  2010. LFS_O_RDONLY) => 0;
  2011. lfs_file_close(&lfs, &file) => 0;
  2012. lfs_file_open(&lfs, &file, "/coffee/....tubruk",
  2013. LFS_O_RDONLY) => 0;
  2014. lfs_file_close(&lfs, &file) => 0;
  2015. lfs_file_open(&lfs, &file, "/coffee/.....vietnamese",
  2016. LFS_O_RDONLY) => 0;
  2017. lfs_file_close(&lfs, &file) => 0;
  2018. lfs_file_open(&lfs, &file, "/coffee/......thai",
  2019. LFS_O_RDONLY) => 0;
  2020. lfs_file_close(&lfs, &file) => 0;
  2021. }
  2022. // dir open paths, only works on dirs!
  2023. if (DIR) {
  2024. lfs_dir_t dir;
  2025. lfs_dir_open(&lfs, &dir, "/coffee/.drip") => 0;
  2026. lfs_dir_close(&lfs, &dir) => 0;
  2027. lfs_dir_open(&lfs, &dir, "/coffee/..coldbrew") => 0;
  2028. lfs_dir_close(&lfs, &dir) => 0;
  2029. lfs_dir_open(&lfs, &dir, "/coffee/...turkish") => 0;
  2030. lfs_dir_close(&lfs, &dir) => 0;
  2031. lfs_dir_open(&lfs, &dir, "/coffee/....tubruk") => 0;
  2032. lfs_dir_close(&lfs, &dir) => 0;
  2033. lfs_dir_open(&lfs, &dir, "/coffee/.....vietnamese") => 0;
  2034. lfs_dir_close(&lfs, &dir) => 0;
  2035. lfs_dir_open(&lfs, &dir, "/coffee/......thai") => 0;
  2036. lfs_dir_close(&lfs, &dir) => 0;
  2037. } else {
  2038. lfs_dir_t dir;
  2039. lfs_dir_open(&lfs, &dir, "/coffee/.drip") => LFS_ERR_NOTDIR;
  2040. lfs_dir_open(&lfs, &dir, "/coffee/..coldbrew") => LFS_ERR_NOTDIR;
  2041. lfs_dir_open(&lfs, &dir, "/coffee/...turkish") => LFS_ERR_NOTDIR;
  2042. lfs_dir_open(&lfs, &dir, "/coffee/....tubruk") => LFS_ERR_NOTDIR;
  2043. lfs_dir_open(&lfs, &dir, "/coffee/.....vietnamese") => LFS_ERR_NOTDIR;
  2044. lfs_dir_open(&lfs, &dir, "/coffee/......thai") => LFS_ERR_NOTDIR;
  2045. }
  2046. // rename paths
  2047. lfs_mkdir(&lfs, "espresso") => 0;
  2048. lfs_rename(&lfs,
  2049. "/coffee/.drip",
  2050. "/espresso/.espresso") => 0;
  2051. lfs_rename(&lfs,
  2052. "/coffee/..coldbrew",
  2053. "/espresso/..americano") => 0;
  2054. lfs_rename(&lfs,
  2055. "/coffee/...turkish",
  2056. "/espresso/...macchiato") => 0;
  2057. lfs_rename(&lfs,
  2058. "/coffee/....tubruk",
  2059. "/espresso/....latte") => 0;
  2060. lfs_rename(&lfs,
  2061. "/coffee/.....vietnamese",
  2062. "/espresso/.....cappuccino") => 0;
  2063. lfs_rename(&lfs,
  2064. "/coffee/......thai",
  2065. "/espresso/......mocha") => 0;
  2066. // stat paths
  2067. lfs_stat(&lfs, "/espresso/.espresso", &info) => 0;
  2068. assert(strcmp(info.name, ".espresso") == 0);
  2069. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2070. lfs_stat(&lfs, "/espresso/..americano", &info) => 0;
  2071. assert(strcmp(info.name, "..americano") == 0);
  2072. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2073. lfs_stat(&lfs, "/espresso/...macchiato", &info) => 0;
  2074. assert(strcmp(info.name, "...macchiato") == 0);
  2075. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2076. lfs_stat(&lfs, "/espresso/....latte", &info) => 0;
  2077. assert(strcmp(info.name, "....latte") == 0);
  2078. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2079. lfs_stat(&lfs, "/espresso/.....cappuccino", &info) => 0;
  2080. assert(strcmp(info.name, ".....cappuccino") == 0);
  2081. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2082. lfs_stat(&lfs, "/espresso/......mocha", &info) => 0;
  2083. assert(strcmp(info.name, "......mocha") == 0);
  2084. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2085. lfs_stat(&lfs, "coffee/.drip", &info) => LFS_ERR_NOENT;
  2086. lfs_stat(&lfs, "coffee/..coldbrew", &info) => LFS_ERR_NOENT;
  2087. lfs_stat(&lfs, "coffee/...turkish", &info) => LFS_ERR_NOENT;
  2088. lfs_stat(&lfs, "coffee/....tubruk", &info) => LFS_ERR_NOENT;
  2089. lfs_stat(&lfs, "coffee/.....vietnamese", &info) => LFS_ERR_NOENT;
  2090. lfs_stat(&lfs, "coffee/......thai", &info) => LFS_ERR_NOENT;
  2091. // remove paths
  2092. lfs_remove(&lfs, "/espresso/.espresso") => 0;
  2093. lfs_remove(&lfs, "/espresso/..americano") => 0;
  2094. lfs_remove(&lfs, "/espresso/...macchiato") => 0;
  2095. lfs_remove(&lfs, "/espresso/....latte") => 0;
  2096. lfs_remove(&lfs, "/espresso/.....cappuccino") => 0;
  2097. lfs_remove(&lfs, "/espresso/......mocha") => 0;
  2098. // stat paths
  2099. lfs_stat(&lfs, "/espresso/.espresso", &info) => LFS_ERR_NOENT;
  2100. lfs_stat(&lfs, "/espresso/..americano", &info) => LFS_ERR_NOENT;
  2101. lfs_stat(&lfs, "/espresso/...macchiato", &info) => LFS_ERR_NOENT;
  2102. lfs_stat(&lfs, "/espresso/....latte", &info) => LFS_ERR_NOENT;
  2103. lfs_stat(&lfs, "/espresso/.....cappuccino", &info) => LFS_ERR_NOENT;
  2104. lfs_stat(&lfs, "/espresso/......mocha", &info) => LFS_ERR_NOENT;
  2105. lfs_unmount(&lfs) => 0;
  2106. '''
  2107. # root dot dot path test
  2108. [cases.test_paths_root_dotdots]
  2109. defines.DIR = [false, true]
  2110. code = '''
  2111. lfs_t lfs;
  2112. lfs_format(&lfs, cfg) => 0;
  2113. lfs_mount(&lfs, cfg) => 0;
  2114. // create paths
  2115. lfs_mkdir(&lfs, "no") => 0;
  2116. lfs_mkdir(&lfs, "coffee") => 0;
  2117. if (DIR) {
  2118. lfs_mkdir(&lfs, "/../coffee/drip") => 0;
  2119. lfs_mkdir(&lfs, "/../../coffee/coldbrew") => 0;
  2120. lfs_mkdir(&lfs, "/../../../coffee/turkish") => 0;
  2121. lfs_mkdir(&lfs, "/no/../../coffee/tubruk") => 0;
  2122. lfs_mkdir(&lfs, "/no/../../../coffee/vietnamese") => 0;
  2123. lfs_mkdir(&lfs, "/no/../../../../coffee/thai") => 0;
  2124. } else {
  2125. lfs_file_t file;
  2126. lfs_file_open(&lfs, &file, "/../coffee/drip",
  2127. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2128. lfs_file_close(&lfs, &file) => 0;
  2129. lfs_file_open(&lfs, &file, "/../../coffee/coldbrew",
  2130. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2131. lfs_file_close(&lfs, &file) => 0;
  2132. lfs_file_open(&lfs, &file, "/../../../coffee/turkish",
  2133. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2134. lfs_file_close(&lfs, &file) => 0;
  2135. lfs_file_open(&lfs, &file, "/no/../../coffee/tubruk",
  2136. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2137. lfs_file_close(&lfs, &file) => 0;
  2138. lfs_file_open(&lfs, &file, "/no/../../../coffee/vietnamese",
  2139. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2140. lfs_file_close(&lfs, &file) => 0;
  2141. lfs_file_open(&lfs, &file, "/no/../../../../coffee/thai",
  2142. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2143. lfs_file_close(&lfs, &file) => 0;
  2144. }
  2145. // stat paths
  2146. struct lfs_info info;
  2147. lfs_stat(&lfs, "/no/../../../../coffee/drip", &info) => 0;
  2148. assert(strcmp(info.name, "drip") == 0);
  2149. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2150. lfs_stat(&lfs, "/no/../../../coffee/coldbrew", &info) => 0;
  2151. assert(strcmp(info.name, "coldbrew") == 0);
  2152. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2153. lfs_stat(&lfs, "/no/../../coffee/turkish", &info) => 0;
  2154. assert(strcmp(info.name, "turkish") == 0);
  2155. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2156. lfs_stat(&lfs, "/../../../coffee/tubruk", &info) => 0;
  2157. assert(strcmp(info.name, "tubruk") == 0);
  2158. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2159. lfs_stat(&lfs, "/../../coffee/vietnamese", &info) => 0;
  2160. assert(strcmp(info.name, "vietnamese") == 0);
  2161. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2162. lfs_stat(&lfs, "/../coffee/thai", &info) => 0;
  2163. assert(strcmp(info.name, "thai") == 0);
  2164. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2165. // file open paths, only works on files!
  2166. if (DIR) {
  2167. lfs_file_t file;
  2168. lfs_file_open(&lfs, &file, "/../coffee/drip",
  2169. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2170. lfs_file_open(&lfs, &file, "/../../coffee/coldbrew",
  2171. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2172. lfs_file_open(&lfs, &file, "/../../../coffee/turkish",
  2173. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2174. lfs_file_open(&lfs, &file, "/no/../../coffee/tubruk",
  2175. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2176. lfs_file_open(&lfs, &file, "/no/../../../coffee/vietnamese",
  2177. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2178. lfs_file_open(&lfs, &file, "/no/../../../../coffee/thai",
  2179. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2180. } else {
  2181. lfs_file_t file;
  2182. lfs_file_open(&lfs, &file, "/../coffee/drip",
  2183. LFS_O_RDONLY) => 0;
  2184. lfs_file_close(&lfs, &file) => 0;
  2185. lfs_file_open(&lfs, &file, "/../../coffee/coldbrew",
  2186. LFS_O_RDONLY) => 0;
  2187. lfs_file_close(&lfs, &file) => 0;
  2188. lfs_file_open(&lfs, &file, "/../../../coffee/turkish",
  2189. LFS_O_RDONLY) => 0;
  2190. lfs_file_close(&lfs, &file) => 0;
  2191. lfs_file_open(&lfs, &file, "/no/../../coffee/tubruk",
  2192. LFS_O_RDONLY) => 0;
  2193. lfs_file_close(&lfs, &file) => 0;
  2194. lfs_file_open(&lfs, &file, "/no/../../../coffee/vietnamese",
  2195. LFS_O_RDONLY) => 0;
  2196. lfs_file_close(&lfs, &file) => 0;
  2197. lfs_file_open(&lfs, &file, "/no/../../../../coffee/thai",
  2198. LFS_O_RDONLY) => 0;
  2199. lfs_file_close(&lfs, &file) => 0;
  2200. }
  2201. // dir open paths, only works on dirs!
  2202. if (DIR) {
  2203. lfs_dir_t dir;
  2204. lfs_dir_open(&lfs, &dir, "/../coffee/drip") => 0;
  2205. lfs_dir_close(&lfs, &dir) => 0;
  2206. lfs_dir_open(&lfs, &dir, "/../../coffee/coldbrew") => 0;
  2207. lfs_dir_close(&lfs, &dir) => 0;
  2208. lfs_dir_open(&lfs, &dir, "/../../../coffee/turkish") => 0;
  2209. lfs_dir_close(&lfs, &dir) => 0;
  2210. lfs_dir_open(&lfs, &dir, "/no/../../coffee/tubruk") => 0;
  2211. lfs_dir_close(&lfs, &dir) => 0;
  2212. lfs_dir_open(&lfs, &dir, "/no/../../../coffee/vietnamese") => 0;
  2213. lfs_dir_close(&lfs, &dir) => 0;
  2214. lfs_dir_open(&lfs, &dir, "/no/../../../../coffee/thai") => 0;
  2215. lfs_dir_close(&lfs, &dir) => 0;
  2216. } else {
  2217. lfs_dir_t dir;
  2218. lfs_dir_open(&lfs, &dir, "/../coffee/drip") => LFS_ERR_NOTDIR;
  2219. lfs_dir_open(&lfs, &dir, "/../../coffee/coldbrew") => LFS_ERR_NOTDIR;
  2220. lfs_dir_open(&lfs, &dir, "/../../../coffee/turkish") => LFS_ERR_NOTDIR;
  2221. lfs_dir_open(&lfs, &dir, "/no/../coffee/tubruk") => LFS_ERR_NOTDIR;
  2222. lfs_dir_open(&lfs, &dir, "/no/../../coffee/vietnamese") => LFS_ERR_NOTDIR;
  2223. lfs_dir_open(&lfs, &dir, "/no/../../../coffee/thai") => LFS_ERR_NOTDIR;
  2224. }
  2225. // rename paths
  2226. lfs_mkdir(&lfs, "espresso") => 0;
  2227. lfs_rename(&lfs,
  2228. "/no/../../../../coffee/drip",
  2229. "/../espresso/espresso") => 0;
  2230. lfs_rename(&lfs,
  2231. "/no/../../../coffee/coldbrew",
  2232. "/../../espresso/americano") => 0;
  2233. lfs_rename(&lfs,
  2234. "/no/../../coffee/turkish",
  2235. "/../../../espresso/macchiato") => 0;
  2236. lfs_rename(&lfs,
  2237. "/../../../coffee/tubruk",
  2238. "/no/../../espresso/latte") => 0;
  2239. lfs_rename(&lfs,
  2240. "/../../coffee/vietnamese",
  2241. "/no/../../../espresso/cappuccino") => 0;
  2242. lfs_rename(&lfs,
  2243. "/../coffee/thai",
  2244. "/no/../../../../espresso/mocha") => 0;
  2245. // stat paths
  2246. lfs_stat(&lfs, "/no/../../../../espresso/espresso", &info) => 0;
  2247. assert(strcmp(info.name, "espresso") == 0);
  2248. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2249. lfs_stat(&lfs, "/no/../../../espresso/americano", &info) => 0;
  2250. assert(strcmp(info.name, "americano") == 0);
  2251. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2252. lfs_stat(&lfs, "/no/../../espresso/macchiato", &info) => 0;
  2253. assert(strcmp(info.name, "macchiato") == 0);
  2254. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2255. lfs_stat(&lfs, "/../../../espresso/latte", &info) => 0;
  2256. assert(strcmp(info.name, "latte") == 0);
  2257. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2258. lfs_stat(&lfs, "/../../espresso/cappuccino", &info) => 0;
  2259. assert(strcmp(info.name, "cappuccino") == 0);
  2260. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2261. lfs_stat(&lfs, "/../espresso/mocha", &info) => 0;
  2262. assert(strcmp(info.name, "mocha") == 0);
  2263. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2264. lfs_stat(&lfs, "/no/../../../../coffee/drip", &info) => LFS_ERR_NOENT;
  2265. lfs_stat(&lfs, "/no/../../../coffee/coldbrew", &info) => LFS_ERR_NOENT;
  2266. lfs_stat(&lfs, "/no/../../coffee/turkish", &info) => LFS_ERR_NOENT;
  2267. lfs_stat(&lfs, "/../../../coffee/tubruk", &info) => LFS_ERR_NOENT;
  2268. lfs_stat(&lfs, "/../../coffee/vietnamese", &info) => LFS_ERR_NOENT;
  2269. lfs_stat(&lfs, "/../coffee/thai", &info) => LFS_ERR_NOENT;
  2270. // remove paths
  2271. lfs_remove(&lfs, "/../espresso/espresso") => 0;
  2272. lfs_remove(&lfs, "/../../espresso/americano") => 0;
  2273. lfs_remove(&lfs, "/../../../espresso/macchiato") => 0;
  2274. lfs_remove(&lfs, "/no/../../espresso/latte") => 0;
  2275. lfs_remove(&lfs, "/no/../../../espresso/cappuccino") => 0;
  2276. lfs_remove(&lfs, "/no/../../../../espresso/mocha") => 0;
  2277. // stat paths
  2278. lfs_stat(&lfs, "/no/../../../../espresso/espresso", &info) => LFS_ERR_NOENT;
  2279. lfs_stat(&lfs, "/no/../../../espresso/americano", &info) => LFS_ERR_NOENT;
  2280. lfs_stat(&lfs, "/no/../../espresso/macchiato", &info) => LFS_ERR_NOENT;
  2281. lfs_stat(&lfs, "/../../../espresso/latte", &info) => LFS_ERR_NOENT;
  2282. lfs_stat(&lfs, "/../../espresso/cappuccino", &info) => LFS_ERR_NOENT;
  2283. lfs_stat(&lfs, "/../espresso/mocha", &info) => LFS_ERR_NOENT;
  2284. lfs_unmount(&lfs) => 0;
  2285. '''
  2286. # trailing noent tests
  2287. [cases.test_paths_noent]
  2288. defines.DIR = [false, true]
  2289. code = '''
  2290. lfs_t lfs;
  2291. lfs_format(&lfs, cfg) => 0;
  2292. lfs_mount(&lfs, cfg) => 0;
  2293. // create paths
  2294. lfs_mkdir(&lfs, "coffee") => 0;
  2295. if (DIR) {
  2296. lfs_mkdir(&lfs, "coffee/drip") => 0;
  2297. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  2298. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  2299. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  2300. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  2301. lfs_mkdir(&lfs, "coffee/thai") => 0;
  2302. } else {
  2303. lfs_file_t file;
  2304. lfs_file_open(&lfs, &file, "coffee/drip",
  2305. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2306. lfs_file_close(&lfs, &file) => 0;
  2307. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  2308. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2309. lfs_file_close(&lfs, &file) => 0;
  2310. lfs_file_open(&lfs, &file, "coffee/turkish",
  2311. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2312. lfs_file_close(&lfs, &file) => 0;
  2313. lfs_file_open(&lfs, &file, "coffee/tubruk",
  2314. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2315. lfs_file_close(&lfs, &file) => 0;
  2316. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  2317. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2318. lfs_file_close(&lfs, &file) => 0;
  2319. lfs_file_open(&lfs, &file, "coffee/thai",
  2320. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2321. lfs_file_close(&lfs, &file) => 0;
  2322. }
  2323. // stat paths
  2324. struct lfs_info info;
  2325. lfs_stat(&lfs, "coffee/_rip", &info) => LFS_ERR_NOENT;
  2326. lfs_stat(&lfs, "coffee/c_ldbrew", &info) => LFS_ERR_NOENT;
  2327. lfs_stat(&lfs, "coffee/tu_kish", &info) => LFS_ERR_NOENT;
  2328. lfs_stat(&lfs, "coffee/tub_uk", &info) => LFS_ERR_NOENT;
  2329. lfs_stat(&lfs, "coffee/_vietnamese", &info) => LFS_ERR_NOENT;
  2330. lfs_stat(&lfs, "coffee/thai_", &info) => LFS_ERR_NOENT;
  2331. // file open paths, only works on files!
  2332. lfs_file_t file;
  2333. lfs_file_open(&lfs, &file, "coffee/_rip",
  2334. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2335. lfs_file_open(&lfs, &file, "coffee/c_ldbrew",
  2336. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2337. lfs_file_open(&lfs, &file, "coffee/tu_kish",
  2338. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2339. lfs_file_open(&lfs, &file, "coffee/tub_uk",
  2340. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2341. lfs_file_open(&lfs, &file, "coffee/_vietnamese",
  2342. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2343. lfs_file_open(&lfs, &file, "coffee/thai_",
  2344. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2345. // dir open paths, only works on dirs!
  2346. lfs_dir_t dir;
  2347. lfs_dir_open(&lfs, &dir, "coffee/_rip") => LFS_ERR_NOENT;
  2348. lfs_dir_open(&lfs, &dir, "coffee/c_ldbrew") => LFS_ERR_NOENT;
  2349. lfs_dir_open(&lfs, &dir, "coffee/tu_kish") => LFS_ERR_NOENT;
  2350. lfs_dir_open(&lfs, &dir, "coffee/tub_uk") => LFS_ERR_NOENT;
  2351. lfs_dir_open(&lfs, &dir, "coffee/_vietnamese") => LFS_ERR_NOENT;
  2352. lfs_dir_open(&lfs, &dir, "coffee/thai_") => LFS_ERR_NOENT;
  2353. // rename paths
  2354. lfs_mkdir(&lfs, "espresso") => 0;
  2355. lfs_rename(&lfs,
  2356. "coffee/_rip",
  2357. "espresso/espresso") => LFS_ERR_NOENT;
  2358. lfs_rename(&lfs,
  2359. "coffee/c_ldbrew",
  2360. "espresso/americano") => LFS_ERR_NOENT;
  2361. lfs_rename(&lfs,
  2362. "coffee/tu_kish",
  2363. "espresso/macchiato") => LFS_ERR_NOENT;
  2364. lfs_rename(&lfs,
  2365. "coffee/tub_uk",
  2366. "espresso/latte") => LFS_ERR_NOENT;
  2367. lfs_rename(&lfs,
  2368. "coffee/_vietnamese",
  2369. "espresso/cappuccino") => LFS_ERR_NOENT;
  2370. lfs_rename(&lfs,
  2371. "coffee/thai_",
  2372. "espresso/mocha") => LFS_ERR_NOENT;
  2373. // remove paths
  2374. lfs_remove(&lfs, "coffee/_rip") => LFS_ERR_NOENT;
  2375. lfs_remove(&lfs, "coffee/c_ldbrew") => LFS_ERR_NOENT;
  2376. lfs_remove(&lfs, "coffee/tu_kish") => LFS_ERR_NOENT;
  2377. lfs_remove(&lfs, "coffee/tub_uk") => LFS_ERR_NOENT;
  2378. lfs_remove(&lfs, "coffee/_vietnamese") => LFS_ERR_NOENT;
  2379. lfs_remove(&lfs, "coffee/thai_") => LFS_ERR_NOENT;
  2380. // stat paths
  2381. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  2382. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  2383. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  2384. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  2385. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  2386. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  2387. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  2388. assert(strcmp(info.name, "drip") == 0);
  2389. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2390. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  2391. assert(strcmp(info.name, "coldbrew") == 0);
  2392. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2393. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  2394. assert(strcmp(info.name, "turkish") == 0);
  2395. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2396. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  2397. assert(strcmp(info.name, "tubruk") == 0);
  2398. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2399. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  2400. assert(strcmp(info.name, "vietnamese") == 0);
  2401. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2402. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  2403. assert(strcmp(info.name, "thai") == 0);
  2404. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2405. lfs_unmount(&lfs) => 0;
  2406. '''
  2407. # parent noent tests
  2408. [cases.test_paths_noent_parent]
  2409. defines.DIR = [false, true]
  2410. code = '''
  2411. lfs_t lfs;
  2412. lfs_format(&lfs, cfg) => 0;
  2413. lfs_mount(&lfs, cfg) => 0;
  2414. // create paths
  2415. lfs_mkdir(&lfs, "coffee") => 0;
  2416. if (DIR) {
  2417. lfs_mkdir(&lfs, "_offee/drip") => LFS_ERR_NOENT;
  2418. lfs_mkdir(&lfs, "c_ffee/coldbrew") => LFS_ERR_NOENT;
  2419. lfs_mkdir(&lfs, "co_fee/turkish") => LFS_ERR_NOENT;
  2420. lfs_mkdir(&lfs, "cof_ee/tubruk") => LFS_ERR_NOENT;
  2421. lfs_mkdir(&lfs, "_coffee/vietnamese") => LFS_ERR_NOENT;
  2422. lfs_mkdir(&lfs, "coffee_/thai") => LFS_ERR_NOENT;
  2423. } else {
  2424. lfs_file_t file;
  2425. lfs_file_open(&lfs, &file, "_offee/drip",
  2426. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2427. lfs_file_open(&lfs, &file, "c_ffee/coldbrew",
  2428. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2429. lfs_file_open(&lfs, &file, "co_fee/turkish",
  2430. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2431. lfs_file_open(&lfs, &file, "cof_ee/tubruk",
  2432. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2433. lfs_file_open(&lfs, &file, "_coffee/vietnamese",
  2434. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2435. lfs_file_open(&lfs, &file, "coffee_/thai",
  2436. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2437. }
  2438. // ok, actually create paths
  2439. if (DIR) {
  2440. lfs_mkdir(&lfs, "coffee/drip") => 0;
  2441. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  2442. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  2443. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  2444. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  2445. lfs_mkdir(&lfs, "coffee/thai") => 0;
  2446. } else {
  2447. lfs_file_t file;
  2448. lfs_file_open(&lfs, &file, "coffee/drip",
  2449. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2450. lfs_file_close(&lfs, &file) => 0;
  2451. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  2452. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2453. lfs_file_close(&lfs, &file) => 0;
  2454. lfs_file_open(&lfs, &file, "coffee/turkish",
  2455. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2456. lfs_file_close(&lfs, &file) => 0;
  2457. lfs_file_open(&lfs, &file, "coffee/tubruk",
  2458. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2459. lfs_file_close(&lfs, &file) => 0;
  2460. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  2461. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2462. lfs_file_close(&lfs, &file) => 0;
  2463. lfs_file_open(&lfs, &file, "coffee/thai",
  2464. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2465. lfs_file_close(&lfs, &file) => 0;
  2466. }
  2467. // stat paths
  2468. struct lfs_info info;
  2469. lfs_stat(&lfs, "_offee/drip", &info) => LFS_ERR_NOENT;
  2470. lfs_stat(&lfs, "c_ffee/coldbrew", &info) => LFS_ERR_NOENT;
  2471. lfs_stat(&lfs, "co_fee/turkish", &info) => LFS_ERR_NOENT;
  2472. lfs_stat(&lfs, "cof_ee/tubruk", &info) => LFS_ERR_NOENT;
  2473. lfs_stat(&lfs, "_coffee/vietnamese", &info) => LFS_ERR_NOENT;
  2474. lfs_stat(&lfs, "coffee_/thai", &info) => LFS_ERR_NOENT;
  2475. // file open paths, only works on files!
  2476. lfs_file_t file;
  2477. lfs_file_open(&lfs, &file, "_offee/drip",
  2478. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2479. lfs_file_open(&lfs, &file, "c_ffee/coldbrew",
  2480. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2481. lfs_file_open(&lfs, &file, "co_fee/turkish",
  2482. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2483. lfs_file_open(&lfs, &file, "cof_ee/tubruk",
  2484. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2485. lfs_file_open(&lfs, &file, "_coffee/vietnamese",
  2486. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2487. lfs_file_open(&lfs, &file, "coffee_/thai",
  2488. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2489. // dir open paths, only works on dirs!
  2490. lfs_dir_t dir;
  2491. lfs_dir_open(&lfs, &dir, "_offee/drip") => LFS_ERR_NOENT;
  2492. lfs_dir_open(&lfs, &dir, "c_ffee/coldbrew") => LFS_ERR_NOENT;
  2493. lfs_dir_open(&lfs, &dir, "co_fee/turkish") => LFS_ERR_NOENT;
  2494. lfs_dir_open(&lfs, &dir, "cof_ee/tubruk") => LFS_ERR_NOENT;
  2495. lfs_dir_open(&lfs, &dir, "_coffee/vietnamese") => LFS_ERR_NOENT;
  2496. lfs_dir_open(&lfs, &dir, "coffee_/thai") => LFS_ERR_NOENT;
  2497. // rename paths
  2498. lfs_mkdir(&lfs, "espresso") => 0;
  2499. // bad source
  2500. lfs_rename(&lfs,
  2501. "_offee/drip",
  2502. "espresso/espresso") => LFS_ERR_NOENT;
  2503. lfs_rename(&lfs,
  2504. "c_ffee/coldbrew",
  2505. "espresso/americano") => LFS_ERR_NOENT;
  2506. lfs_rename(&lfs,
  2507. "co_fee/turkish",
  2508. "espresso/macchiato") => LFS_ERR_NOENT;
  2509. lfs_rename(&lfs,
  2510. "cof_ee/tubruk",
  2511. "espresso/latte") => LFS_ERR_NOENT;
  2512. lfs_rename(&lfs,
  2513. "_coffee/vietnamese",
  2514. "espresso/cappuccino") => LFS_ERR_NOENT;
  2515. lfs_rename(&lfs,
  2516. "coffee_/thai",
  2517. "espresso/mocha") => LFS_ERR_NOENT;
  2518. // bad destination
  2519. lfs_rename(&lfs,
  2520. "coffee/drip",
  2521. "_spresso/espresso") => LFS_ERR_NOENT;
  2522. lfs_rename(&lfs,
  2523. "coffee/coldbrew",
  2524. "e_presso/americano") => LFS_ERR_NOENT;
  2525. lfs_rename(&lfs,
  2526. "coffee/turkish",
  2527. "es_resso/macchiato") => LFS_ERR_NOENT;
  2528. lfs_rename(&lfs,
  2529. "coffee/tubruk",
  2530. "esp_esso/latte") => LFS_ERR_NOENT;
  2531. lfs_rename(&lfs,
  2532. "coffee/vietnamese",
  2533. "_espresso/cappuccino") => LFS_ERR_NOENT;
  2534. lfs_rename(&lfs,
  2535. "coffee/thai",
  2536. "espresso_/mocha") => LFS_ERR_NOENT;
  2537. // bad source and bad destination
  2538. lfs_rename(&lfs,
  2539. "_offee/drip",
  2540. "_spresso/espresso") => LFS_ERR_NOENT;
  2541. lfs_rename(&lfs,
  2542. "c_ffee/coldbrew",
  2543. "e_presso/americano") => LFS_ERR_NOENT;
  2544. lfs_rename(&lfs,
  2545. "co_fee/turkish",
  2546. "es_resso/macchiato") => LFS_ERR_NOENT;
  2547. lfs_rename(&lfs,
  2548. "cof_ee/tubruk",
  2549. "esp_esso/latte") => LFS_ERR_NOENT;
  2550. lfs_rename(&lfs,
  2551. "_coffee/vietnamese",
  2552. "_espresso/cappuccino") => LFS_ERR_NOENT;
  2553. lfs_rename(&lfs,
  2554. "coffee_/thai",
  2555. "espresso_/mocha") => LFS_ERR_NOENT;
  2556. // here's a weird one, what happens if our rename is also a noop?
  2557. lfs_rename(&lfs,
  2558. "_offee/drip",
  2559. "_offee/drip") => LFS_ERR_NOENT;
  2560. lfs_rename(&lfs,
  2561. "c_ffee/coldbrew",
  2562. "c_ffee/coldbrew") => LFS_ERR_NOENT;
  2563. lfs_rename(&lfs,
  2564. "co_fee/turkish",
  2565. "co_fee/turkish") => LFS_ERR_NOENT;
  2566. lfs_rename(&lfs,
  2567. "cof_ee/tubruk",
  2568. "cof_ee/tubruk") => LFS_ERR_NOENT;
  2569. lfs_rename(&lfs,
  2570. "_coffee/vietnamese",
  2571. "_coffee/vietnamese") => LFS_ERR_NOENT;
  2572. lfs_rename(&lfs,
  2573. "coffee_/thai",
  2574. "coffee_/thai") => LFS_ERR_NOENT;
  2575. // remove paths
  2576. lfs_remove(&lfs, "_offee/drip") => LFS_ERR_NOENT;
  2577. lfs_remove(&lfs, "c_ffee/coldbrew") => LFS_ERR_NOENT;
  2578. lfs_remove(&lfs, "co_fee/turkish") => LFS_ERR_NOENT;
  2579. lfs_remove(&lfs, "cof_ee/tubruk") => LFS_ERR_NOENT;
  2580. lfs_remove(&lfs, "_coffee/vietnamese") => LFS_ERR_NOENT;
  2581. lfs_remove(&lfs, "coffee_/thai") => LFS_ERR_NOENT;
  2582. // stat paths
  2583. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  2584. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  2585. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  2586. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  2587. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  2588. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  2589. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  2590. assert(strcmp(info.name, "drip") == 0);
  2591. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2592. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  2593. assert(strcmp(info.name, "coldbrew") == 0);
  2594. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2595. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  2596. assert(strcmp(info.name, "turkish") == 0);
  2597. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2598. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  2599. assert(strcmp(info.name, "tubruk") == 0);
  2600. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2601. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  2602. assert(strcmp(info.name, "vietnamese") == 0);
  2603. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2604. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  2605. assert(strcmp(info.name, "thai") == 0);
  2606. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2607. lfs_unmount(&lfs) => 0;
  2608. '''
  2609. # parent notdir tests
  2610. [cases.test_paths_notdir_parent]
  2611. defines.DIR = [false, true]
  2612. code = '''
  2613. lfs_t lfs;
  2614. lfs_format(&lfs, cfg) => 0;
  2615. lfs_mount(&lfs, cfg) => 0;
  2616. // create paths
  2617. lfs_file_t file;
  2618. lfs_file_open(&lfs, &file, "drip",
  2619. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2620. lfs_file_close(&lfs, &file) => 0;
  2621. lfs_file_open(&lfs, &file, "coldbrew",
  2622. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2623. lfs_file_close(&lfs, &file) => 0;
  2624. lfs_file_open(&lfs, &file, "turkish",
  2625. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2626. lfs_file_close(&lfs, &file) => 0;
  2627. lfs_file_open(&lfs, &file, "tubruk",
  2628. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2629. lfs_file_close(&lfs, &file) => 0;
  2630. lfs_file_open(&lfs, &file, "vietnamese",
  2631. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2632. lfs_file_close(&lfs, &file) => 0;
  2633. lfs_file_open(&lfs, &file, "thai",
  2634. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2635. lfs_file_close(&lfs, &file) => 0;
  2636. if (DIR) {
  2637. lfs_mkdir(&lfs, "drip/coffee") => LFS_ERR_NOTDIR;
  2638. lfs_mkdir(&lfs, "coldbrew/coffee") => LFS_ERR_NOTDIR;
  2639. lfs_mkdir(&lfs, "turkish/coffee") => LFS_ERR_NOTDIR;
  2640. lfs_mkdir(&lfs, "tubruk/coffee") => LFS_ERR_NOTDIR;
  2641. lfs_mkdir(&lfs, "vietnamese/coffee") => LFS_ERR_NOTDIR;
  2642. lfs_mkdir(&lfs, "thai/coffee") => LFS_ERR_NOTDIR;
  2643. } else {
  2644. lfs_file_t file;
  2645. lfs_file_open(&lfs, &file, "drip/coffee",
  2646. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2647. lfs_file_open(&lfs, &file, "coldbrew/coffee",
  2648. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2649. lfs_file_open(&lfs, &file, "turkish/coffee",
  2650. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2651. lfs_file_open(&lfs, &file, "tubruk/coffee",
  2652. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2653. lfs_file_open(&lfs, &file, "vietnamese/coffee",
  2654. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2655. lfs_file_open(&lfs, &file, "thai/coffee",
  2656. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2657. }
  2658. // stat paths
  2659. struct lfs_info info;
  2660. lfs_stat(&lfs, "drip/coffee", &info) => LFS_ERR_NOTDIR;
  2661. lfs_stat(&lfs, "coldbrew/coffee", &info) => LFS_ERR_NOTDIR;
  2662. lfs_stat(&lfs, "turkish/coffee", &info) => LFS_ERR_NOTDIR;
  2663. lfs_stat(&lfs, "tubruk/coffee", &info) => LFS_ERR_NOTDIR;
  2664. lfs_stat(&lfs, "vietnamese/coffee", &info) => LFS_ERR_NOTDIR;
  2665. lfs_stat(&lfs, "thai/coffee", &info) => LFS_ERR_NOTDIR;
  2666. // file open paths, only works on files!
  2667. lfs_file_open(&lfs, &file, "drip/coffee",
  2668. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2669. lfs_file_open(&lfs, &file, "coldbrew/coffee",
  2670. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2671. lfs_file_open(&lfs, &file, "turkish/coffee",
  2672. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2673. lfs_file_open(&lfs, &file, "tubruk/coffee",
  2674. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2675. lfs_file_open(&lfs, &file, "vietnamese/coffee",
  2676. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2677. lfs_file_open(&lfs, &file, "thai/coffee",
  2678. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2679. // dir open paths, only works on dirs!
  2680. lfs_dir_t dir;
  2681. lfs_dir_open(&lfs, &dir, "drip/coffee") => LFS_ERR_NOTDIR;
  2682. lfs_dir_open(&lfs, &dir, "coldbrew/coffee") => LFS_ERR_NOTDIR;
  2683. lfs_dir_open(&lfs, &dir, "turkish/coffee") => LFS_ERR_NOTDIR;
  2684. lfs_dir_open(&lfs, &dir, "tubruk/coffee") => LFS_ERR_NOTDIR;
  2685. lfs_dir_open(&lfs, &dir, "vietnamese/coffee") => LFS_ERR_NOTDIR;
  2686. lfs_dir_open(&lfs, &dir, "thai/coffee") => LFS_ERR_NOTDIR;
  2687. // make some normal paths so we have something to rename
  2688. lfs_mkdir(&lfs, "coffee") => 0;
  2689. if (DIR) {
  2690. lfs_mkdir(&lfs, "coffee/drip") => 0;
  2691. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  2692. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  2693. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  2694. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  2695. lfs_mkdir(&lfs, "coffee/thai") => 0;
  2696. } else {
  2697. lfs_file_t file;
  2698. lfs_file_open(&lfs, &file, "coffee/drip",
  2699. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2700. lfs_file_close(&lfs, &file) => 0;
  2701. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  2702. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2703. lfs_file_close(&lfs, &file) => 0;
  2704. lfs_file_open(&lfs, &file, "coffee/turkish",
  2705. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2706. lfs_file_close(&lfs, &file) => 0;
  2707. lfs_file_open(&lfs, &file, "coffee/tubruk",
  2708. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2709. lfs_file_close(&lfs, &file) => 0;
  2710. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  2711. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2712. lfs_file_close(&lfs, &file) => 0;
  2713. lfs_file_open(&lfs, &file, "coffee/thai",
  2714. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2715. lfs_file_close(&lfs, &file) => 0;
  2716. }
  2717. // rename paths
  2718. lfs_mkdir(&lfs, "espresso") => 0;
  2719. // bad source
  2720. lfs_rename(&lfs,
  2721. "drip/coffee",
  2722. "espresso/espresso") => LFS_ERR_NOTDIR;
  2723. lfs_rename(&lfs,
  2724. "coldbrew/coffee",
  2725. "espresso/americano") => LFS_ERR_NOTDIR;
  2726. lfs_rename(&lfs,
  2727. "turkish/coffee",
  2728. "espresso/macchiato") => LFS_ERR_NOTDIR;
  2729. lfs_rename(&lfs,
  2730. "tubruk/coffee",
  2731. "espresso/latte") => LFS_ERR_NOTDIR;
  2732. lfs_rename(&lfs,
  2733. "vietnamese/coffee",
  2734. "espresso/cappuccino") => LFS_ERR_NOTDIR;
  2735. lfs_rename(&lfs,
  2736. "thai/coffee",
  2737. "espresso/mocha") => LFS_ERR_NOTDIR;
  2738. // bad destination
  2739. lfs_rename(&lfs,
  2740. "coffee/drip",
  2741. "drip/espresso") => LFS_ERR_NOTDIR;
  2742. lfs_rename(&lfs,
  2743. "coffee/coldbrew",
  2744. "coldbrew/espresso") => LFS_ERR_NOTDIR;
  2745. lfs_rename(&lfs,
  2746. "coffee/turkish",
  2747. "turkish/espresso") => LFS_ERR_NOTDIR;
  2748. lfs_rename(&lfs,
  2749. "coffee/tubruk",
  2750. "tubruk/espresso") => LFS_ERR_NOTDIR;
  2751. lfs_rename(&lfs,
  2752. "coffee/vietnamese",
  2753. "vietnamese/espresso") => LFS_ERR_NOTDIR;
  2754. lfs_rename(&lfs,
  2755. "coffee/thai",
  2756. "thai/espresso") => LFS_ERR_NOTDIR;
  2757. // bad source and bad destination
  2758. lfs_rename(&lfs,
  2759. "drip/coffee",
  2760. "drip/espresso") => LFS_ERR_NOTDIR;
  2761. lfs_rename(&lfs,
  2762. "coldbrew/coffee",
  2763. "coldbrew/espresso") => LFS_ERR_NOTDIR;
  2764. lfs_rename(&lfs,
  2765. "turkish/coffee",
  2766. "turkish/espresso") => LFS_ERR_NOTDIR;
  2767. lfs_rename(&lfs,
  2768. "tubruk/coffee",
  2769. "tubruk/espresso") => LFS_ERR_NOTDIR;
  2770. lfs_rename(&lfs,
  2771. "vietnamese/coffee",
  2772. "vietnamese/espresso") => LFS_ERR_NOTDIR;
  2773. lfs_rename(&lfs,
  2774. "thai/coffee",
  2775. "thai/espresso") => LFS_ERR_NOTDIR;
  2776. // here's a weird one, what happens if our rename is also a noop?
  2777. lfs_rename(&lfs,
  2778. "drip/coffee",
  2779. "drip/coffee") => LFS_ERR_NOTDIR;
  2780. lfs_rename(&lfs,
  2781. "coldbrew/coffee",
  2782. "coldbrew/coffee") => LFS_ERR_NOTDIR;
  2783. lfs_rename(&lfs,
  2784. "turkish/coffee",
  2785. "turkish/coffee") => LFS_ERR_NOTDIR;
  2786. lfs_rename(&lfs,
  2787. "tubruk/coffee",
  2788. "tubruk/coffee") => LFS_ERR_NOTDIR;
  2789. lfs_rename(&lfs,
  2790. "vietnamese/coffee",
  2791. "vietnamese/coffee") => LFS_ERR_NOTDIR;
  2792. lfs_rename(&lfs,
  2793. "thai/coffee",
  2794. "thai/coffee") => LFS_ERR_NOTDIR;
  2795. // remove paths
  2796. lfs_stat(&lfs, "drip/espresso", &info) => LFS_ERR_NOTDIR;
  2797. lfs_stat(&lfs, "coldbrew/espresso", &info) => LFS_ERR_NOTDIR;
  2798. lfs_stat(&lfs, "turkish/espresso", &info) => LFS_ERR_NOTDIR;
  2799. lfs_stat(&lfs, "tubruk/espresso", &info) => LFS_ERR_NOTDIR;
  2800. lfs_stat(&lfs, "vietnamese/espresso", &info) => LFS_ERR_NOTDIR;
  2801. lfs_stat(&lfs, "thai/espresso", &info) => LFS_ERR_NOTDIR;
  2802. // stat paths
  2803. lfs_stat(&lfs, "drip/espresso", &info) => LFS_ERR_NOTDIR;
  2804. lfs_stat(&lfs, "coldbrew/espresso", &info) => LFS_ERR_NOTDIR;
  2805. lfs_stat(&lfs, "turkish/espresso", &info) => LFS_ERR_NOTDIR;
  2806. lfs_stat(&lfs, "tubruk/espresso", &info) => LFS_ERR_NOTDIR;
  2807. lfs_stat(&lfs, "vietnamese/espresso", &info) => LFS_ERR_NOTDIR;
  2808. lfs_stat(&lfs, "thai/espresso", &info) => LFS_ERR_NOTDIR;
  2809. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  2810. assert(strcmp(info.name, "drip") == 0);
  2811. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2812. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  2813. assert(strcmp(info.name, "coldbrew") == 0);
  2814. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2815. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  2816. assert(strcmp(info.name, "turkish") == 0);
  2817. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2818. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  2819. assert(strcmp(info.name, "tubruk") == 0);
  2820. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2821. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  2822. assert(strcmp(info.name, "vietnamese") == 0);
  2823. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2824. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  2825. assert(strcmp(info.name, "thai") == 0);
  2826. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2827. lfs_unmount(&lfs) => 0;
  2828. '''
  2829. # root operations
  2830. #
  2831. # POSIX deviations:
  2832. #
  2833. # - Root modifications return EINVAL instead of EBUSY:
  2834. # - littlefs: remove("/") => EINVAL
  2835. # - POSIX: remove("/") => EBUSY
  2836. # Reason: This would be the only use of EBUSY in the system.
  2837. #
  2838. [cases.test_paths_root]
  2839. defines.DIR = [false, true]
  2840. code = '''
  2841. lfs_t lfs;
  2842. lfs_format(&lfs, cfg) => 0;
  2843. lfs_mount(&lfs, cfg) => 0;
  2844. struct lfs_info info;
  2845. // create root, this should error
  2846. if (DIR) {
  2847. lfs_mkdir(&lfs, "/") => LFS_ERR_EXIST;
  2848. } else {
  2849. lfs_file_t file;
  2850. lfs_file_open(&lfs, &file, "/",
  2851. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2852. }
  2853. // stat root
  2854. lfs_stat(&lfs, "/", &info) => 0;
  2855. assert(strcmp(info.name, "/") == 0);
  2856. assert(info.type == LFS_TYPE_DIR);
  2857. // file open root, only works on files!
  2858. lfs_file_t file;
  2859. lfs_file_open(&lfs, &file, "/",
  2860. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2861. // dir open root, only works on dirs!
  2862. lfs_dir_t dir;
  2863. lfs_dir_open(&lfs, &dir, "/") => 0;
  2864. lfs_dir_close(&lfs, &dir) => 0;
  2865. // rename root, this should error
  2866. lfs_rename(&lfs, "/", "coffee") => LFS_ERR_INVAL;
  2867. lfs_mkdir(&lfs, "coffee") => 0;
  2868. lfs_rename(&lfs, "coffee", "/") => LFS_ERR_INVAL;
  2869. lfs_remove(&lfs, "coffee") => 0;
  2870. lfs_rename(&lfs, "/", "/") => LFS_ERR_INVAL;
  2871. // stat root
  2872. lfs_stat(&lfs, "/", &info) => 0;
  2873. assert(strcmp(info.name, "/") == 0);
  2874. assert(info.type == LFS_TYPE_DIR);
  2875. // remove root, this should error
  2876. lfs_remove(&lfs, "/") => LFS_ERR_INVAL;
  2877. // stat root
  2878. lfs_stat(&lfs, "/", &info) => 0;
  2879. assert(strcmp(info.name, "/") == 0);
  2880. assert(info.type == LFS_TYPE_DIR);
  2881. lfs_unmount(&lfs) => 0;
  2882. '''
  2883. # other root representations
  2884. [cases.test_paths_root_aliases]
  2885. defines.DIR = [false, true]
  2886. code = '''
  2887. lfs_t lfs;
  2888. lfs_format(&lfs, cfg) => 0;
  2889. lfs_mount(&lfs, cfg) => 0;
  2890. struct lfs_info info;
  2891. // create root, this should error
  2892. if (DIR) {
  2893. lfs_mkdir(&lfs, "/") => LFS_ERR_EXIST;
  2894. lfs_mkdir(&lfs, "") => LFS_ERR_EXIST;
  2895. lfs_mkdir(&lfs, ".") => LFS_ERR_EXIST;
  2896. lfs_mkdir(&lfs, "..") => LFS_ERR_EXIST;
  2897. lfs_mkdir(&lfs, "./") => LFS_ERR_EXIST;
  2898. lfs_mkdir(&lfs, "/.") => LFS_ERR_EXIST;
  2899. lfs_mkdir(&lfs, "//") => LFS_ERR_EXIST;
  2900. } else {
  2901. lfs_file_t file;
  2902. lfs_file_open(&lfs, &file, "/",
  2903. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2904. lfs_file_open(&lfs, &file, "",
  2905. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2906. lfs_file_open(&lfs, &file, ".",
  2907. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2908. lfs_file_open(&lfs, &file, "..",
  2909. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2910. lfs_file_open(&lfs, &file, "./",
  2911. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2912. lfs_file_open(&lfs, &file, "/.",
  2913. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2914. lfs_file_open(&lfs, &file, "//",
  2915. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2916. }
  2917. // stat root
  2918. lfs_stat(&lfs, "/", &info) => 0;
  2919. assert(strcmp(info.name, "/") == 0);
  2920. assert(info.type == LFS_TYPE_DIR);
  2921. lfs_stat(&lfs, "", &info) => 0;
  2922. assert(strcmp(info.name, "/") == 0);
  2923. assert(info.type == LFS_TYPE_DIR);
  2924. lfs_stat(&lfs, ".", &info) => 0;
  2925. assert(strcmp(info.name, "/") == 0);
  2926. assert(info.type == LFS_TYPE_DIR);
  2927. lfs_stat(&lfs, "..", &info) => 0;
  2928. assert(strcmp(info.name, "/") == 0);
  2929. assert(info.type == LFS_TYPE_DIR);
  2930. lfs_stat(&lfs, "./", &info) => 0;
  2931. assert(strcmp(info.name, "/") == 0);
  2932. assert(info.type == LFS_TYPE_DIR);
  2933. lfs_stat(&lfs, "/.", &info) => 0;
  2934. assert(strcmp(info.name, "/") == 0);
  2935. assert(info.type == LFS_TYPE_DIR);
  2936. lfs_stat(&lfs, "//", &info) => 0;
  2937. assert(strcmp(info.name, "/") == 0);
  2938. assert(info.type == LFS_TYPE_DIR);
  2939. // file open root, only works on files!
  2940. lfs_file_t file;
  2941. lfs_file_open(&lfs, &file, "/",
  2942. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2943. lfs_file_open(&lfs, &file, "",
  2944. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2945. lfs_file_open(&lfs, &file, ".",
  2946. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2947. lfs_file_open(&lfs, &file, "..",
  2948. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2949. lfs_file_open(&lfs, &file, "./",
  2950. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2951. lfs_file_open(&lfs, &file, "/.",
  2952. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2953. lfs_file_open(&lfs, &file, "//",
  2954. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2955. // dir open root, only works on dirs!
  2956. lfs_dir_t dir;
  2957. lfs_dir_open(&lfs, &dir, "/") => 0;
  2958. lfs_dir_close(&lfs, &dir) => 0;
  2959. lfs_dir_open(&lfs, &dir, "") => 0;
  2960. lfs_dir_close(&lfs, &dir) => 0;
  2961. lfs_dir_open(&lfs, &dir, ".") => 0;
  2962. lfs_dir_close(&lfs, &dir) => 0;
  2963. lfs_dir_open(&lfs, &dir, "..") => 0;
  2964. lfs_dir_close(&lfs, &dir) => 0;
  2965. lfs_dir_open(&lfs, &dir, "./") => 0;
  2966. lfs_dir_close(&lfs, &dir) => 0;
  2967. lfs_dir_open(&lfs, &dir, "/.") => 0;
  2968. lfs_dir_close(&lfs, &dir) => 0;
  2969. lfs_dir_open(&lfs, &dir, "//") => 0;
  2970. lfs_dir_close(&lfs, &dir) => 0;
  2971. // rename root, this should error
  2972. lfs_rename(&lfs, "/", "coffee") => LFS_ERR_INVAL;
  2973. lfs_rename(&lfs, "", "coffee") => LFS_ERR_INVAL;
  2974. lfs_rename(&lfs, ".", "coffee") => LFS_ERR_INVAL;
  2975. lfs_rename(&lfs, "..", "coffee") => LFS_ERR_INVAL;
  2976. lfs_rename(&lfs, "./", "coffee") => LFS_ERR_INVAL;
  2977. lfs_rename(&lfs, "/.", "coffee") => LFS_ERR_INVAL;
  2978. lfs_rename(&lfs, "//", "coffee") => LFS_ERR_INVAL;
  2979. lfs_mkdir(&lfs, "coffee") => 0;
  2980. lfs_rename(&lfs, "coffee", "/") => LFS_ERR_INVAL;
  2981. lfs_rename(&lfs, "coffee", "") => LFS_ERR_INVAL;
  2982. lfs_rename(&lfs, "coffee", ".") => LFS_ERR_INVAL;
  2983. lfs_rename(&lfs, "coffee", "..") => LFS_ERR_INVAL;
  2984. lfs_rename(&lfs, "coffee", "./") => LFS_ERR_INVAL;
  2985. lfs_rename(&lfs, "coffee", "/.") => LFS_ERR_INVAL;
  2986. lfs_rename(&lfs, "coffee", "//") => LFS_ERR_INVAL;
  2987. lfs_remove(&lfs, "coffee") => 0;
  2988. lfs_rename(&lfs, "/", "/") => LFS_ERR_INVAL;
  2989. lfs_rename(&lfs, "", "") => LFS_ERR_INVAL;
  2990. lfs_rename(&lfs, ".", ".") => LFS_ERR_INVAL;
  2991. lfs_rename(&lfs, "..", "..") => LFS_ERR_INVAL;
  2992. lfs_rename(&lfs, "./", "./") => LFS_ERR_INVAL;
  2993. lfs_rename(&lfs, "/.", "/.") => LFS_ERR_INVAL;
  2994. lfs_rename(&lfs, "//", "//") => LFS_ERR_INVAL;
  2995. // stat root
  2996. lfs_stat(&lfs, "/", &info) => 0;
  2997. assert(strcmp(info.name, "/") == 0);
  2998. assert(info.type == LFS_TYPE_DIR);
  2999. lfs_stat(&lfs, "", &info) => 0;
  3000. assert(strcmp(info.name, "/") == 0);
  3001. assert(info.type == LFS_TYPE_DIR);
  3002. lfs_stat(&lfs, ".", &info) => 0;
  3003. assert(strcmp(info.name, "/") == 0);
  3004. assert(info.type == LFS_TYPE_DIR);
  3005. lfs_stat(&lfs, "..", &info) => 0;
  3006. assert(strcmp(info.name, "/") == 0);
  3007. assert(info.type == LFS_TYPE_DIR);
  3008. lfs_stat(&lfs, "./", &info) => 0;
  3009. assert(strcmp(info.name, "/") == 0);
  3010. assert(info.type == LFS_TYPE_DIR);
  3011. lfs_stat(&lfs, "/.", &info) => 0;
  3012. assert(strcmp(info.name, "/") == 0);
  3013. assert(info.type == LFS_TYPE_DIR);
  3014. lfs_stat(&lfs, "//", &info) => 0;
  3015. assert(strcmp(info.name, "/") == 0);
  3016. assert(info.type == LFS_TYPE_DIR);
  3017. // remove root, this should error
  3018. lfs_remove(&lfs, "/") => LFS_ERR_INVAL;
  3019. lfs_remove(&lfs, "") => LFS_ERR_INVAL;
  3020. lfs_remove(&lfs, ".") => LFS_ERR_INVAL;
  3021. lfs_remove(&lfs, "..") => LFS_ERR_INVAL;
  3022. lfs_remove(&lfs, "./") => LFS_ERR_INVAL;
  3023. lfs_remove(&lfs, "/.") => LFS_ERR_INVAL;
  3024. lfs_remove(&lfs, "//") => LFS_ERR_INVAL;
  3025. // stat root
  3026. lfs_stat(&lfs, "/", &info) => 0;
  3027. assert(strcmp(info.name, "/") == 0);
  3028. assert(info.type == LFS_TYPE_DIR);
  3029. lfs_stat(&lfs, "", &info) => 0;
  3030. assert(strcmp(info.name, "/") == 0);
  3031. assert(info.type == LFS_TYPE_DIR);
  3032. lfs_stat(&lfs, ".", &info) => 0;
  3033. assert(strcmp(info.name, "/") == 0);
  3034. assert(info.type == LFS_TYPE_DIR);
  3035. lfs_stat(&lfs, "..", &info) => 0;
  3036. assert(strcmp(info.name, "/") == 0);
  3037. assert(info.type == LFS_TYPE_DIR);
  3038. lfs_stat(&lfs, "./", &info) => 0;
  3039. assert(strcmp(info.name, "/") == 0);
  3040. assert(info.type == LFS_TYPE_DIR);
  3041. lfs_stat(&lfs, "/.", &info) => 0;
  3042. assert(strcmp(info.name, "/") == 0);
  3043. assert(info.type == LFS_TYPE_DIR);
  3044. lfs_stat(&lfs, "//", &info) => 0;
  3045. assert(strcmp(info.name, "/") == 0);
  3046. assert(info.type == LFS_TYPE_DIR);
  3047. lfs_unmount(&lfs) => 0;
  3048. '''
  3049. # superblock magic shouldn't appear as a file
  3050. [cases.test_paths_magic_noent]
  3051. code = '''
  3052. lfs_t lfs;
  3053. lfs_format(&lfs, cfg) => 0;
  3054. lfs_mount(&lfs, cfg) => 0;
  3055. // stat littlefs, which shouldn't exist
  3056. struct lfs_info info;
  3057. lfs_stat(&lfs, "littlefs", &info) => LFS_ERR_NOENT;
  3058. // dir open littlefs, which shouldn't exist
  3059. lfs_dir_t dir;
  3060. lfs_dir_open(&lfs, &dir, "littlefs") => LFS_ERR_NOENT;
  3061. // rename littlefs, which shouldn't exist
  3062. lfs_rename(&lfs, "littlefs", "coffee") => LFS_ERR_NOENT;
  3063. // remove littlefs, which shouldn't exist
  3064. lfs_remove(&lfs, "littlefs") => LFS_ERR_NOENT;
  3065. // stat littlefs, which shouldn't exist
  3066. lfs_stat(&lfs, "coffee", &info) => LFS_ERR_NOENT;
  3067. lfs_stat(&lfs, "littlefs", &info) => LFS_ERR_NOENT;
  3068. lfs_unmount(&lfs) => 0;
  3069. '''
  3070. # superblock magic shouldn't conflict with files, that would be silly
  3071. [cases.test_paths_magic_conflict]
  3072. defines.DIR = [false, true]
  3073. code = '''
  3074. lfs_t lfs;
  3075. lfs_format(&lfs, cfg) => 0;
  3076. lfs_mount(&lfs, cfg) => 0;
  3077. // create littlefs
  3078. if (DIR) {
  3079. lfs_mkdir(&lfs, "littlefs") => 0;
  3080. } else {
  3081. lfs_file_t file;
  3082. lfs_file_open(&lfs, &file, "littlefs",
  3083. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3084. lfs_file_close(&lfs, &file) => 0;
  3085. }
  3086. // stat littlefs
  3087. struct lfs_info info;
  3088. lfs_stat(&lfs, "littlefs", &info) => 0;
  3089. assert(strcmp(info.name, "littlefs") == 0);
  3090. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3091. // file open littlefs, only works on files!
  3092. if (DIR) {
  3093. lfs_file_t file;
  3094. lfs_file_open(&lfs, &file, "littlefs",
  3095. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3096. } else {
  3097. lfs_file_t file;
  3098. lfs_file_open(&lfs, &file, "littlefs",
  3099. LFS_O_RDONLY) => 0;
  3100. lfs_file_close(&lfs, &file) => 0;
  3101. }
  3102. // dir open littlefs, only works on dirs!
  3103. if (DIR) {
  3104. lfs_dir_t dir;
  3105. lfs_dir_open(&lfs, &dir, "littlefs") => 0;
  3106. lfs_dir_close(&lfs, &dir) => 0;
  3107. } else {
  3108. lfs_dir_t dir;
  3109. lfs_dir_open(&lfs, &dir, "littlefs") => LFS_ERR_NOTDIR;
  3110. }
  3111. // rename littlefs
  3112. lfs_rename(&lfs, "littlefs", "coffee") => 0;
  3113. lfs_rename(&lfs, "coffee", "littlefs") => 0;
  3114. // stat littlefs
  3115. lfs_stat(&lfs, "littlefs", &info) => 0;
  3116. assert(strcmp(info.name, "littlefs") == 0);
  3117. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3118. lfs_stat(&lfs, "coffee", &info) => LFS_ERR_NOENT;
  3119. // remove littlefs
  3120. lfs_remove(&lfs, "littlefs") => 0;
  3121. // stat littlefs
  3122. lfs_stat(&lfs, "littlefs", &info) => LFS_ERR_NOENT;
  3123. lfs_unmount(&lfs) => 0;
  3124. '''
  3125. # test name too long
  3126. [cases.test_paths_nametoolong]
  3127. defines.DIR = [false, true]
  3128. code = '''
  3129. lfs_t lfs;
  3130. lfs_format(&lfs, cfg) => 0;
  3131. lfs_mount(&lfs, cfg) => 0;
  3132. char a_name[512];
  3133. memset(a_name, 'a', LFS_NAME_MAX+1);
  3134. a_name[LFS_NAME_MAX+1] = '\0';
  3135. // create names that are too long, should error
  3136. char path[1024];
  3137. lfs_mkdir(&lfs, "coffee") => 0;
  3138. if (DIR) {
  3139. sprintf(path, "coffee/%s", a_name);
  3140. lfs_mkdir(&lfs, path) => LFS_ERR_NAMETOOLONG;
  3141. } else {
  3142. lfs_file_t file;
  3143. sprintf(path, "coffee/%s", a_name);
  3144. lfs_file_open(&lfs, &file, path,
  3145. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NAMETOOLONG;
  3146. }
  3147. // stat paths
  3148. struct lfs_info info;
  3149. sprintf(path, "coffee/%s", a_name);
  3150. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3151. // file open paths, only works on files!
  3152. lfs_file_t file;
  3153. sprintf(path, "coffee/%s", a_name);
  3154. lfs_file_open(&lfs, &file, path,
  3155. LFS_O_RDONLY) => LFS_ERR_NOENT;
  3156. // dir open paths, only works on dirs!
  3157. lfs_dir_t dir;
  3158. sprintf(path, "coffee/%s", a_name);
  3159. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOENT;
  3160. // rename paths
  3161. lfs_mkdir(&lfs, "espresso") => 0;
  3162. sprintf(path, "coffee/%s", a_name);
  3163. lfs_rename(&lfs, path, "espresso/espresso") => LFS_ERR_NOENT;
  3164. // renaming with too long a destination is tricky!
  3165. if (DIR) {
  3166. lfs_mkdir(&lfs, "coffee/drip") => 0;
  3167. } else {
  3168. lfs_file_t file;
  3169. lfs_file_open(&lfs, &file, "coffee/drip",
  3170. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3171. lfs_file_close(&lfs, &file) => 0;
  3172. }
  3173. sprintf(path, "espresso/%s", a_name);
  3174. lfs_rename(&lfs, "coffee/drip", path) => LFS_ERR_NAMETOOLONG;
  3175. // stat paths
  3176. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  3177. assert(strcmp(info.name, "drip") == 0);
  3178. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3179. sprintf(path, "espresso/%s", a_name);
  3180. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3181. // remove paths
  3182. sprintf(path, "espresso/%s", a_name);
  3183. lfs_remove(&lfs, path) => LFS_ERR_NOENT;
  3184. // stat paths
  3185. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  3186. assert(strcmp(info.name, "drip") == 0);
  3187. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3188. sprintf(path, "espresso/%s", a_name);
  3189. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3190. lfs_unmount(&lfs) => 0;
  3191. '''
  3192. # test name really long but not too long
  3193. [cases.test_paths_namejustlongenough]
  3194. defines.DIR = [false, true]
  3195. code = '''
  3196. lfs_t lfs;
  3197. lfs_format(&lfs, cfg) => 0;
  3198. lfs_mount(&lfs, cfg) => 0;
  3199. char a_name[512];
  3200. memset(a_name, 'a', LFS_NAME_MAX);
  3201. a_name[LFS_NAME_MAX] = '\0';
  3202. char b_name[512];
  3203. memset(b_name, 'b', LFS_NAME_MAX);
  3204. b_name[LFS_NAME_MAX] = '\0';
  3205. char c_name[512];
  3206. memset(c_name, 'c', LFS_NAME_MAX);
  3207. c_name[LFS_NAME_MAX] = '\0';
  3208. char d_name[512];
  3209. memset(d_name, 'd', LFS_NAME_MAX);
  3210. d_name[LFS_NAME_MAX] = '\0';
  3211. char e_name[512];
  3212. memset(e_name, 'e', LFS_NAME_MAX);
  3213. e_name[LFS_NAME_MAX] = '\0';
  3214. char f_name[512];
  3215. memset(f_name, 'f', LFS_NAME_MAX);
  3216. f_name[LFS_NAME_MAX] = '\0';
  3217. char g_name[512];
  3218. memset(g_name, 'g', LFS_NAME_MAX);
  3219. g_name[LFS_NAME_MAX] = '\0';
  3220. char h_name[512];
  3221. memset(h_name, 'h', LFS_NAME_MAX);
  3222. h_name[LFS_NAME_MAX] = '\0';
  3223. char i_name[512];
  3224. memset(i_name, 'i', LFS_NAME_MAX);
  3225. i_name[LFS_NAME_MAX] = '\0';
  3226. char j_name[512];
  3227. memset(j_name, 'j', LFS_NAME_MAX);
  3228. j_name[LFS_NAME_MAX] = '\0';
  3229. char k_name[512];
  3230. memset(k_name, 'k', LFS_NAME_MAX);
  3231. k_name[LFS_NAME_MAX] = '\0';
  3232. char l_name[512];
  3233. memset(l_name, 'l', LFS_NAME_MAX);
  3234. l_name[LFS_NAME_MAX] = '\0';
  3235. // create names that aren't too long
  3236. lfs_mkdir(&lfs, c_name) => 0;
  3237. char path[1024];
  3238. if (DIR) {
  3239. sprintf(path, "%s/%s", c_name, a_name);
  3240. lfs_mkdir(&lfs, path) => 0;
  3241. sprintf(path, "%s/%s", c_name, b_name);
  3242. lfs_mkdir(&lfs, path) => 0;
  3243. sprintf(path, "%s/%s", c_name, c_name);
  3244. lfs_mkdir(&lfs, path) => 0;
  3245. sprintf(path, "%s/%s", c_name, d_name);
  3246. lfs_mkdir(&lfs, path) => 0;
  3247. sprintf(path, "%s/%s", c_name, e_name);
  3248. lfs_mkdir(&lfs, path) => 0;
  3249. sprintf(path, "%s/%s", c_name, f_name);
  3250. lfs_mkdir(&lfs, path) => 0;
  3251. } else {
  3252. lfs_file_t file;
  3253. sprintf(path, "%s/%s", c_name, a_name);
  3254. lfs_file_open(&lfs, &file, path,
  3255. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3256. lfs_file_close(&lfs, &file) => 0;
  3257. sprintf(path, "%s/%s", c_name, b_name);
  3258. lfs_file_open(&lfs, &file, path,
  3259. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3260. lfs_file_close(&lfs, &file) => 0;
  3261. sprintf(path, "%s/%s", c_name, c_name);
  3262. lfs_file_open(&lfs, &file, path,
  3263. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3264. lfs_file_close(&lfs, &file) => 0;
  3265. sprintf(path, "%s/%s", c_name, d_name);
  3266. lfs_file_open(&lfs, &file, path,
  3267. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3268. lfs_file_close(&lfs, &file) => 0;
  3269. sprintf(path, "%s/%s", c_name, e_name);
  3270. lfs_file_open(&lfs, &file, path,
  3271. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3272. lfs_file_close(&lfs, &file) => 0;
  3273. sprintf(path, "%s/%s", c_name, f_name);
  3274. lfs_file_open(&lfs, &file, path,
  3275. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3276. lfs_file_close(&lfs, &file) => 0;
  3277. }
  3278. // stat paths
  3279. struct lfs_info info;
  3280. sprintf(path, "%s/%s", c_name, a_name);
  3281. lfs_stat(&lfs, path, &info) => 0;
  3282. assert(strcmp(info.name, a_name) == 0);
  3283. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3284. sprintf(path, "%s/%s", c_name, b_name);
  3285. lfs_stat(&lfs, path, &info) => 0;
  3286. assert(strcmp(info.name, b_name) == 0);
  3287. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3288. sprintf(path, "%s/%s", c_name, c_name);
  3289. lfs_stat(&lfs, path, &info) => 0;
  3290. assert(strcmp(info.name, c_name) == 0);
  3291. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3292. sprintf(path, "%s/%s", c_name, d_name);
  3293. lfs_stat(&lfs, path, &info) => 0;
  3294. assert(strcmp(info.name, d_name) == 0);
  3295. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3296. sprintf(path, "%s/%s", c_name, e_name);
  3297. lfs_stat(&lfs, path, &info) => 0;
  3298. assert(strcmp(info.name, e_name) == 0);
  3299. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3300. sprintf(path, "%s/%s", c_name, f_name);
  3301. lfs_stat(&lfs, path, &info) => 0;
  3302. assert(strcmp(info.name, f_name) == 0);
  3303. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3304. // file open paths, only works on files!
  3305. if (DIR) {
  3306. lfs_file_t file;
  3307. sprintf(path, "%s/%s", c_name, a_name);
  3308. lfs_file_open(&lfs, &file, path,
  3309. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3310. sprintf(path, "%s/%s", c_name, b_name);
  3311. lfs_file_open(&lfs, &file, path,
  3312. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3313. sprintf(path, "%s/%s", c_name, c_name);
  3314. lfs_file_open(&lfs, &file, path,
  3315. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3316. sprintf(path, "%s/%s", c_name, d_name);
  3317. lfs_file_open(&lfs, &file, path,
  3318. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3319. sprintf(path, "%s/%s", c_name, e_name);
  3320. lfs_file_open(&lfs, &file, path,
  3321. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3322. sprintf(path, "%s/%s", c_name, f_name);
  3323. lfs_file_open(&lfs, &file, path,
  3324. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3325. } else {
  3326. lfs_file_t file;
  3327. sprintf(path, "%s/%s", c_name, a_name);
  3328. lfs_file_open(&lfs, &file, path,
  3329. LFS_O_RDONLY) => 0;
  3330. lfs_file_close(&lfs, &file) => 0;
  3331. sprintf(path, "%s/%s", c_name, b_name);
  3332. lfs_file_open(&lfs, &file, path,
  3333. LFS_O_RDONLY) => 0;
  3334. lfs_file_close(&lfs, &file) => 0;
  3335. sprintf(path, "%s/%s", c_name, c_name);
  3336. lfs_file_open(&lfs, &file, path,
  3337. LFS_O_RDONLY) => 0;
  3338. lfs_file_close(&lfs, &file) => 0;
  3339. sprintf(path, "%s/%s", c_name, d_name);
  3340. lfs_file_open(&lfs, &file, path,
  3341. LFS_O_RDONLY) => 0;
  3342. lfs_file_close(&lfs, &file) => 0;
  3343. sprintf(path, "%s/%s", c_name, e_name);
  3344. lfs_file_open(&lfs, &file, path,
  3345. LFS_O_RDONLY) => 0;
  3346. lfs_file_close(&lfs, &file) => 0;
  3347. sprintf(path, "%s/%s", c_name, f_name);
  3348. lfs_file_open(&lfs, &file, path,
  3349. LFS_O_RDONLY) => 0;
  3350. lfs_file_close(&lfs, &file) => 0;
  3351. }
  3352. // dir open paths, only works on dirs!
  3353. if (DIR) {
  3354. lfs_dir_t dir;
  3355. sprintf(path, "%s/%s", c_name, a_name);
  3356. lfs_dir_open(&lfs, &dir, path) => 0;
  3357. lfs_dir_close(&lfs, &dir) => 0;
  3358. sprintf(path, "%s/%s", c_name, b_name);
  3359. lfs_dir_open(&lfs, &dir, path) => 0;
  3360. lfs_dir_close(&lfs, &dir) => 0;
  3361. sprintf(path, "%s/%s", c_name, c_name);
  3362. lfs_dir_open(&lfs, &dir, path) => 0;
  3363. lfs_dir_close(&lfs, &dir) => 0;
  3364. sprintf(path, "%s/%s", c_name, d_name);
  3365. lfs_dir_open(&lfs, &dir, path) => 0;
  3366. lfs_dir_close(&lfs, &dir) => 0;
  3367. sprintf(path, "%s/%s", c_name, e_name);
  3368. lfs_dir_open(&lfs, &dir, path) => 0;
  3369. lfs_dir_close(&lfs, &dir) => 0;
  3370. sprintf(path, "%s/%s", c_name, f_name);
  3371. lfs_dir_open(&lfs, &dir, path) => 0;
  3372. lfs_dir_close(&lfs, &dir) => 0;
  3373. } else {
  3374. lfs_dir_t dir;
  3375. sprintf(path, "%s/%s", c_name, a_name);
  3376. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3377. sprintf(path, "%s/%s", c_name, b_name);
  3378. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3379. sprintf(path, "%s/%s", c_name, c_name);
  3380. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3381. sprintf(path, "%s/%s", c_name, d_name);
  3382. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3383. sprintf(path, "%s/%s", c_name, e_name);
  3384. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3385. sprintf(path, "%s/%s", c_name, f_name);
  3386. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3387. }
  3388. // rename paths
  3389. lfs_mkdir(&lfs, e_name) => 0;
  3390. char path_[1024];
  3391. sprintf(path, "%s/%s", c_name, a_name);
  3392. sprintf(path_, "%s/%s", e_name, g_name);
  3393. lfs_rename(&lfs, path, path_) => 0;
  3394. sprintf(path, "%s/%s", c_name, b_name);
  3395. sprintf(path_, "%s/%s", e_name, h_name);
  3396. lfs_rename(&lfs, path, path_) => 0;
  3397. sprintf(path, "%s/%s", c_name, c_name);
  3398. sprintf(path_, "%s/%s", e_name, i_name);
  3399. lfs_rename(&lfs, path, path_) => 0;
  3400. sprintf(path, "%s/%s", c_name, d_name);
  3401. sprintf(path_, "%s/%s", e_name, j_name);
  3402. lfs_rename(&lfs, path, path_) => 0;
  3403. sprintf(path, "%s/%s", c_name, e_name);
  3404. sprintf(path_, "%s/%s", e_name, k_name);
  3405. lfs_rename(&lfs, path, path_) => 0;
  3406. sprintf(path, "%s/%s", c_name, f_name);
  3407. sprintf(path_, "%s/%s", e_name, l_name);
  3408. lfs_rename(&lfs, path, path_) => 0;
  3409. // stat paths
  3410. sprintf(path, "%s/%s", e_name, g_name);
  3411. lfs_stat(&lfs, path, &info) => 0;
  3412. assert(strcmp(info.name, g_name) == 0);
  3413. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3414. sprintf(path, "%s/%s", e_name, h_name);
  3415. lfs_stat(&lfs, path, &info) => 0;
  3416. assert(strcmp(info.name, h_name) == 0);
  3417. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3418. sprintf(path, "%s/%s", e_name, i_name);
  3419. lfs_stat(&lfs, path, &info) => 0;
  3420. assert(strcmp(info.name, i_name) == 0);
  3421. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3422. sprintf(path, "%s/%s", e_name, j_name);
  3423. lfs_stat(&lfs, path, &info) => 0;
  3424. assert(strcmp(info.name, j_name) == 0);
  3425. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3426. sprintf(path, "%s/%s", e_name, k_name);
  3427. lfs_stat(&lfs, path, &info) => 0;
  3428. assert(strcmp(info.name, k_name) == 0);
  3429. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3430. sprintf(path, "%s/%s", e_name, l_name);
  3431. lfs_stat(&lfs, path, &info) => 0;
  3432. assert(strcmp(info.name, l_name) == 0);
  3433. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3434. sprintf(path, "%s/%s", c_name, a_name);
  3435. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3436. sprintf(path, "%s/%s", c_name, b_name);
  3437. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3438. sprintf(path, "%s/%s", c_name, c_name);
  3439. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3440. sprintf(path, "%s/%s", c_name, d_name);
  3441. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3442. sprintf(path, "%s/%s", c_name, e_name);
  3443. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3444. sprintf(path, "%s/%s", c_name, f_name);
  3445. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3446. // remove paths
  3447. sprintf(path, "%s/%s", e_name, g_name);
  3448. lfs_remove(&lfs, path) => 0;
  3449. sprintf(path, "%s/%s", e_name, h_name);
  3450. lfs_remove(&lfs, path) => 0;
  3451. sprintf(path, "%s/%s", e_name, i_name);
  3452. lfs_remove(&lfs, path) => 0;
  3453. sprintf(path, "%s/%s", e_name, j_name);
  3454. lfs_remove(&lfs, path) => 0;
  3455. sprintf(path, "%s/%s", e_name, k_name);
  3456. lfs_remove(&lfs, path) => 0;
  3457. sprintf(path, "%s/%s", e_name, l_name);
  3458. lfs_remove(&lfs, path) => 0;
  3459. // stat paths
  3460. sprintf(path, "%s/%s", e_name, g_name);
  3461. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3462. sprintf(path, "%s/%s", e_name, h_name);
  3463. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3464. sprintf(path, "%s/%s", e_name, i_name);
  3465. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3466. sprintf(path, "%s/%s", e_name, j_name);
  3467. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3468. sprintf(path, "%s/%s", e_name, k_name);
  3469. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3470. sprintf(path, "%s/%s", e_name, l_name);
  3471. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3472. lfs_unmount(&lfs) => 0;
  3473. '''
  3474. # a quick utf8 test, though utf8 is easy to support
  3475. [cases.test_paths_utf8]
  3476. defines.DIR = [false, true]
  3477. code = '''
  3478. lfs_t lfs;
  3479. lfs_format(&lfs, cfg) => 0;
  3480. lfs_mount(&lfs, cfg) => 0;
  3481. // create paths
  3482. lfs_mkdir(&lfs, "coffee") => 0;
  3483. if (DIR) {
  3484. lfs_mkdir(&lfs, "coffee/dripcoffee") => 0;
  3485. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  3486. lfs_mkdir(&lfs, "coffee/türkkahvesi") => 0;
  3487. lfs_mkdir(&lfs, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀") => 0;
  3488. lfs_mkdir(&lfs, "coffee/càphêđá") => 0;
  3489. lfs_mkdir(&lfs, "coffee/โอเลี้ยง") => 0;
  3490. } else {
  3491. lfs_file_t file;
  3492. lfs_file_open(&lfs, &file, "coffee/dripcoffee",
  3493. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3494. lfs_file_close(&lfs, &file) => 0;
  3495. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  3496. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3497. lfs_file_close(&lfs, &file) => 0;
  3498. lfs_file_open(&lfs, &file, "coffee/türkkahvesi",
  3499. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3500. lfs_file_close(&lfs, &file) => 0;
  3501. lfs_file_open(&lfs, &file, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀",
  3502. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3503. lfs_file_close(&lfs, &file) => 0;
  3504. lfs_file_open(&lfs, &file, "coffee/càphêđá",
  3505. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3506. lfs_file_close(&lfs, &file) => 0;
  3507. lfs_file_open(&lfs, &file, "coffee/โอเลี้ยง",
  3508. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3509. lfs_file_close(&lfs, &file) => 0;
  3510. }
  3511. // stat paths
  3512. struct lfs_info info;
  3513. lfs_stat(&lfs, "coffee/dripcoffee", &info) => 0;
  3514. assert(strcmp(info.name, "dripcoffee") == 0);
  3515. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3516. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  3517. assert(strcmp(info.name, "coldbrew") == 0);
  3518. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3519. lfs_stat(&lfs, "coffee/türkkahvesi", &info) => 0;
  3520. assert(strcmp(info.name, "türkkahvesi") == 0);
  3521. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3522. lfs_stat(&lfs, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀", &info) => 0;
  3523. assert(strcmp(info.name, "ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀") == 0);
  3524. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3525. lfs_stat(&lfs, "coffee/càphêđá", &info) => 0;
  3526. assert(strcmp(info.name, "càphêđá") == 0);
  3527. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3528. lfs_stat(&lfs, "coffee/โอเลี้ยง", &info) => 0;
  3529. assert(strcmp(info.name, "โอเลี้ยง") == 0);
  3530. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3531. // file open paths, only works on files!
  3532. if (DIR) {
  3533. lfs_file_t file;
  3534. lfs_file_open(&lfs, &file, "coffee/dripcoffee",
  3535. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3536. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  3537. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3538. lfs_file_open(&lfs, &file, "coffee/türkkahvesi",
  3539. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3540. lfs_file_open(&lfs, &file, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀",
  3541. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3542. lfs_file_open(&lfs, &file, "coffee/càphêđá",
  3543. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3544. lfs_file_open(&lfs, &file, "coffee/โอเลี้ยง",
  3545. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3546. } else {
  3547. lfs_file_t file;
  3548. lfs_file_open(&lfs, &file, "coffee/dripcoffee",
  3549. LFS_O_RDONLY) => 0;
  3550. lfs_file_close(&lfs, &file) => 0;
  3551. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  3552. LFS_O_RDONLY) => 0;
  3553. lfs_file_close(&lfs, &file) => 0;
  3554. lfs_file_open(&lfs, &file, "coffee/türkkahvesi",
  3555. LFS_O_RDONLY) => 0;
  3556. lfs_file_close(&lfs, &file) => 0;
  3557. lfs_file_open(&lfs, &file, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀",
  3558. LFS_O_RDONLY) => 0;
  3559. lfs_file_close(&lfs, &file) => 0;
  3560. lfs_file_open(&lfs, &file, "coffee/càphêđá",
  3561. LFS_O_RDONLY) => 0;
  3562. lfs_file_close(&lfs, &file) => 0;
  3563. lfs_file_open(&lfs, &file, "coffee/โอเลี้ยง",
  3564. LFS_O_RDONLY) => 0;
  3565. lfs_file_close(&lfs, &file) => 0;
  3566. }
  3567. // dir open paths, only works on dirs!
  3568. if (DIR) {
  3569. lfs_dir_t dir;
  3570. lfs_dir_open(&lfs, &dir, "coffee/dripcoffee") => 0;
  3571. lfs_dir_close(&lfs, &dir) => 0;
  3572. lfs_dir_open(&lfs, &dir, "coffee/coldbrew") => 0;
  3573. lfs_dir_close(&lfs, &dir) => 0;
  3574. lfs_dir_open(&lfs, &dir, "coffee/türkkahvesi") => 0;
  3575. lfs_dir_close(&lfs, &dir) => 0;
  3576. lfs_dir_open(&lfs, &dir, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀") => 0;
  3577. lfs_dir_close(&lfs, &dir) => 0;
  3578. lfs_dir_open(&lfs, &dir, "coffee/càphêđá") => 0;
  3579. lfs_dir_close(&lfs, &dir) => 0;
  3580. lfs_dir_open(&lfs, &dir, "coffee/โอเลี้ยง") => 0;
  3581. lfs_dir_close(&lfs, &dir) => 0;
  3582. } else {
  3583. lfs_dir_t dir;
  3584. lfs_dir_open(&lfs, &dir, "coffee/dripcoffee") => LFS_ERR_NOTDIR;
  3585. lfs_dir_open(&lfs, &dir, "coffee/coldbrew") => LFS_ERR_NOTDIR;
  3586. lfs_dir_open(&lfs, &dir, "coffee/türkkahvesi") => LFS_ERR_NOTDIR;
  3587. lfs_dir_open(&lfs, &dir, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀") => LFS_ERR_NOTDIR;
  3588. lfs_dir_open(&lfs, &dir, "coffee/càphêđá") => LFS_ERR_NOTDIR;
  3589. lfs_dir_open(&lfs, &dir, "coffee/โอเลี้ยง") => LFS_ERR_NOTDIR;
  3590. }
  3591. // rename paths
  3592. lfs_mkdir(&lfs, "caffè") => 0;
  3593. lfs_rename(&lfs,
  3594. "coffee/dripcoffee",
  3595. "caffè/espresso") => 0;
  3596. lfs_rename(&lfs,
  3597. "coffee/coldbrew",
  3598. "caffè/americano") => 0;
  3599. lfs_rename(&lfs,
  3600. "coffee/türkkahvesi",
  3601. "caffè/macchiato") => 0;
  3602. lfs_rename(&lfs,
  3603. "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀",
  3604. "caffè/latte") => 0;
  3605. lfs_rename(&lfs,
  3606. "coffee/càphêđá",
  3607. "caffè/cappuccino") => 0;
  3608. lfs_rename(&lfs,
  3609. "coffee/โอเลี้ยง",
  3610. "caffè/mocha") => 0;
  3611. // stat paths
  3612. lfs_stat(&lfs, "caffè/espresso", &info) => 0;
  3613. assert(strcmp(info.name, "espresso") == 0);
  3614. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3615. lfs_stat(&lfs, "caffè/americano", &info) => 0;
  3616. assert(strcmp(info.name, "americano") == 0);
  3617. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3618. lfs_stat(&lfs, "caffè/macchiato", &info) => 0;
  3619. assert(strcmp(info.name, "macchiato") == 0);
  3620. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3621. lfs_stat(&lfs, "caffè/latte", &info) => 0;
  3622. assert(strcmp(info.name, "latte") == 0);
  3623. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3624. lfs_stat(&lfs, "caffè/cappuccino", &info) => 0;
  3625. assert(strcmp(info.name, "cappuccino") == 0);
  3626. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3627. lfs_stat(&lfs, "caffè/mocha", &info) => 0;
  3628. assert(strcmp(info.name, "mocha") == 0);
  3629. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3630. lfs_stat(&lfs, "coffee/dripcoffee", &info) => LFS_ERR_NOENT;
  3631. lfs_stat(&lfs, "coffee/coldbrew", &info) => LFS_ERR_NOENT;
  3632. lfs_stat(&lfs, "coffee/türkkahvesi", &info) => LFS_ERR_NOENT;
  3633. lfs_stat(&lfs, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀", &info) => LFS_ERR_NOENT;
  3634. lfs_stat(&lfs, "coffee/càphêđá", &info) => LFS_ERR_NOENT;
  3635. lfs_stat(&lfs, "coffee/โอเลี้ยง", &info) => LFS_ERR_NOENT;
  3636. // remove paths
  3637. lfs_remove(&lfs, "caffè/espresso") => 0;
  3638. lfs_remove(&lfs, "caffè/americano") => 0;
  3639. lfs_remove(&lfs, "caffè/macchiato") => 0;
  3640. lfs_remove(&lfs, "caffè/latte") => 0;
  3641. lfs_remove(&lfs, "caffè/cappuccino") => 0;
  3642. lfs_remove(&lfs, "caffè/mocha") => 0;
  3643. // stat paths
  3644. lfs_stat(&lfs, "caffè/espresso", &info) => LFS_ERR_NOENT;
  3645. lfs_stat(&lfs, "caffè/americano", &info) => LFS_ERR_NOENT;
  3646. lfs_stat(&lfs, "caffè/macchiato", &info) => LFS_ERR_NOENT;
  3647. lfs_stat(&lfs, "caffè/latte", &info) => LFS_ERR_NOENT;
  3648. lfs_stat(&lfs, "caffè/cappuccino", &info) => LFS_ERR_NOENT;
  3649. lfs_stat(&lfs, "caffè/mocha", &info) => LFS_ERR_NOENT;
  3650. lfs_unmount(&lfs) => 0;
  3651. '''
  3652. # more utf8 tests
  3653. [cases.test_paths_utf8_ipa]
  3654. defines.DIR = [false, true]
  3655. code = '''
  3656. lfs_t lfs;
  3657. lfs_format(&lfs, cfg) => 0;
  3658. lfs_mount(&lfs, cfg) => 0;
  3659. // create paths
  3660. lfs_mkdir(&lfs, "ˈkɔ.fi") => 0;
  3661. if (DIR) {
  3662. lfs_mkdir(&lfs, "ˈkɔ.fi/dɹɪpˈkɔ.fi") => 0;
  3663. lfs_mkdir(&lfs, "ˈkɔ.fi/koʊldbɹuː") => 0;
  3664. lfs_mkdir(&lfs, "ˈkɔ.fi/tyɾckɑhvɛˈsi") => 0;
  3665. lfs_mkdir(&lfs, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚") => 0;
  3666. lfs_mkdir(&lfs, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥") => 0;
  3667. lfs_mkdir(&lfs, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥") => 0;
  3668. } else {
  3669. lfs_file_t file;
  3670. lfs_file_open(&lfs, &file, "ˈkɔ.fi/dɹɪpˈkɔ.fi",
  3671. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3672. lfs_file_close(&lfs, &file) => 0;
  3673. lfs_file_open(&lfs, &file, "ˈkɔ.fi/koʊldbɹuː",
  3674. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3675. lfs_file_close(&lfs, &file) => 0;
  3676. lfs_file_open(&lfs, &file, "ˈkɔ.fi/tyɾckɑhvɛˈsi",
  3677. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3678. lfs_file_close(&lfs, &file) => 0;
  3679. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚",
  3680. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3681. lfs_file_close(&lfs, &file) => 0;
  3682. lfs_file_open(&lfs, &file, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥",
  3683. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3684. lfs_file_close(&lfs, &file) => 0;
  3685. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥",
  3686. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3687. lfs_file_close(&lfs, &file) => 0;
  3688. }
  3689. // stat paths
  3690. struct lfs_info info;
  3691. lfs_stat(&lfs, "ˈkɔ.fi/dɹɪpˈkɔ.fi", &info) => 0;
  3692. assert(strcmp(info.name, "dɹɪpˈkɔ.fi") == 0);
  3693. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3694. lfs_stat(&lfs, "ˈkɔ.fi/koʊldbɹuː", &info) => 0;
  3695. assert(strcmp(info.name, "koʊldbɹuː") == 0);
  3696. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3697. lfs_stat(&lfs, "ˈkɔ.fi/tyɾckɑhvɛˈsi", &info) => 0;
  3698. assert(strcmp(info.name, "tyɾckɑhvɛˈsi") == 0);
  3699. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3700. lfs_stat(&lfs, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚", &info) => 0;
  3701. assert(strcmp(info.name, "ˈko.piˈt̪up̚.rʊk̚") == 0);
  3702. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3703. lfs_stat(&lfs, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥", &info) => 0;
  3704. assert(strcmp(info.name, "kaː˨˩fe˧˧ɗaː˧˥") == 0);
  3705. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3706. lfs_stat(&lfs, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥", &info) => 0;
  3707. assert(strcmp(info.name, "ʔoː˧.lia̯ŋ˦˥") == 0);
  3708. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3709. // file open paths, only works on files!
  3710. if (DIR) {
  3711. lfs_file_t file;
  3712. lfs_file_open(&lfs, &file, "ˈkɔ.fi/dɹɪpˈkɔ.fi",
  3713. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3714. lfs_file_open(&lfs, &file, "ˈkɔ.fi/koʊldbɹuː",
  3715. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3716. lfs_file_open(&lfs, &file, "ˈkɔ.fi/tyɾckɑhvɛˈsi",
  3717. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3718. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚",
  3719. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3720. lfs_file_open(&lfs, &file, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥",
  3721. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3722. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥",
  3723. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3724. } else {
  3725. lfs_file_t file;
  3726. lfs_file_open(&lfs, &file, "ˈkɔ.fi/dɹɪpˈkɔ.fi",
  3727. LFS_O_RDONLY) => 0;
  3728. lfs_file_close(&lfs, &file) => 0;
  3729. lfs_file_open(&lfs, &file, "ˈkɔ.fi/koʊldbɹuː",
  3730. LFS_O_RDONLY) => 0;
  3731. lfs_file_close(&lfs, &file) => 0;
  3732. lfs_file_open(&lfs, &file, "ˈkɔ.fi/tyɾckɑhvɛˈsi",
  3733. LFS_O_RDONLY) => 0;
  3734. lfs_file_close(&lfs, &file) => 0;
  3735. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚",
  3736. LFS_O_RDONLY) => 0;
  3737. lfs_file_close(&lfs, &file) => 0;
  3738. lfs_file_open(&lfs, &file, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥",
  3739. LFS_O_RDONLY) => 0;
  3740. lfs_file_close(&lfs, &file) => 0;
  3741. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥",
  3742. LFS_O_RDONLY) => 0;
  3743. lfs_file_close(&lfs, &file) => 0;
  3744. }
  3745. // dir open paths, only works on dirs!
  3746. if (DIR) {
  3747. lfs_dir_t dir;
  3748. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/dɹɪpˈkɔ.fi") => 0;
  3749. lfs_dir_close(&lfs, &dir) => 0;
  3750. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/koʊldbɹuː") => 0;
  3751. lfs_dir_close(&lfs, &dir) => 0;
  3752. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/tyɾckɑhvɛˈsi") => 0;
  3753. lfs_dir_close(&lfs, &dir) => 0;
  3754. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚") => 0;
  3755. lfs_dir_close(&lfs, &dir) => 0;
  3756. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥") => 0;
  3757. lfs_dir_close(&lfs, &dir) => 0;
  3758. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥") => 0;
  3759. lfs_dir_close(&lfs, &dir) => 0;
  3760. } else {
  3761. lfs_dir_t dir;
  3762. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/dɹɪpˈkɔ.fi") => LFS_ERR_NOTDIR;
  3763. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/koʊldbɹuː") => LFS_ERR_NOTDIR;
  3764. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/tyɾckɑhvɛˈsi") => LFS_ERR_NOTDIR;
  3765. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚") => LFS_ERR_NOTDIR;
  3766. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥") => LFS_ERR_NOTDIR;
  3767. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥") => LFS_ERR_NOTDIR;
  3768. }
  3769. // rename paths
  3770. lfs_mkdir(&lfs, "kafˈfɛ") => 0;
  3771. lfs_rename(&lfs,
  3772. "ˈkɔ.fi/dɹɪpˈkɔ.fi",
  3773. "kafˈfɛ/eˈsprɛsso") => 0;
  3774. lfs_rename(&lfs,
  3775. "ˈkɔ.fi/koʊldbɹuː",
  3776. "kafˈfɛ/ameriˈkano") => 0;
  3777. lfs_rename(&lfs,
  3778. "ˈkɔ.fi/tyɾckɑhvɛˈsi",
  3779. "kafˈfɛ/makˈkjato") => 0;
  3780. lfs_rename(&lfs,
  3781. "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚",
  3782. "kafˈfɛ/ˈlat.te") => 0;
  3783. lfs_rename(&lfs,
  3784. "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥",
  3785. "kafˈfɛ/kapputˈt͡ʃino") => 0;
  3786. lfs_rename(&lfs,
  3787. "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥",
  3788. "kafˈfɛ/ˈmoʊkə") => 0;
  3789. // stat paths
  3790. lfs_stat(&lfs, "kafˈfɛ/eˈsprɛsso", &info) => 0;
  3791. assert(strcmp(info.name, "eˈsprɛsso") == 0);
  3792. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3793. lfs_stat(&lfs, "kafˈfɛ/ameriˈkano", &info) => 0;
  3794. assert(strcmp(info.name, "ameriˈkano") == 0);
  3795. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3796. lfs_stat(&lfs, "kafˈfɛ/makˈkjato", &info) => 0;
  3797. assert(strcmp(info.name, "makˈkjato") == 0);
  3798. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3799. lfs_stat(&lfs, "kafˈfɛ/ˈlat.te", &info) => 0;
  3800. assert(strcmp(info.name, "ˈlat.te") == 0);
  3801. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3802. lfs_stat(&lfs, "kafˈfɛ/kapputˈt͡ʃino", &info) => 0;
  3803. assert(strcmp(info.name, "kapputˈt͡ʃino") == 0);
  3804. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3805. lfs_stat(&lfs, "kafˈfɛ/ˈmoʊkə", &info) => 0;
  3806. assert(strcmp(info.name, "ˈmoʊkə") == 0);
  3807. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3808. lfs_stat(&lfs, "ˈkɔ.fi/dɹɪpˈkɔ.fi", &info) => LFS_ERR_NOENT;
  3809. lfs_stat(&lfs, "ˈkɔ.fi/koʊldbɹuː", &info) => LFS_ERR_NOENT;
  3810. lfs_stat(&lfs, "ˈkɔ.fi/tyɾckɑhvɛˈsi", &info) => LFS_ERR_NOENT;
  3811. lfs_stat(&lfs, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚", &info) => LFS_ERR_NOENT;
  3812. lfs_stat(&lfs, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥", &info) => LFS_ERR_NOENT;
  3813. lfs_stat(&lfs, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥", &info) => LFS_ERR_NOENT;
  3814. // remove paths
  3815. lfs_remove(&lfs, "kafˈfɛ/eˈsprɛsso") => 0;
  3816. lfs_remove(&lfs, "kafˈfɛ/ameriˈkano") => 0;
  3817. lfs_remove(&lfs, "kafˈfɛ/makˈkjato") => 0;
  3818. lfs_remove(&lfs, "kafˈfɛ/ˈlat.te") => 0;
  3819. lfs_remove(&lfs, "kafˈfɛ/kapputˈt͡ʃino") => 0;
  3820. lfs_remove(&lfs, "kafˈfɛ/ˈmoʊkə") => 0;
  3821. // stat paths
  3822. lfs_stat(&lfs, "kafˈfɛ/eˈsprɛsso", &info) => LFS_ERR_NOENT;
  3823. lfs_stat(&lfs, "kafˈfɛ/ameriˈkano", &info) => LFS_ERR_NOENT;
  3824. lfs_stat(&lfs, "kafˈfɛ/makˈkjato", &info) => LFS_ERR_NOENT;
  3825. lfs_stat(&lfs, "kafˈfɛ/ˈlat.te", &info) => LFS_ERR_NOENT;
  3826. lfs_stat(&lfs, "kafˈfɛ/kapputˈt͡ʃino", &info) => LFS_ERR_NOENT;
  3827. lfs_stat(&lfs, "kafˈfɛ/ˈmoʊkə", &info) => LFS_ERR_NOENT;
  3828. lfs_unmount(&lfs) => 0;
  3829. '''
  3830. # test spaces have no problems
  3831. [cases.test_paths_spaces]
  3832. defines.DIR = [false, true]
  3833. code = '''
  3834. lfs_t lfs;
  3835. lfs_format(&lfs, cfg) => 0;
  3836. lfs_mount(&lfs, cfg) => 0;
  3837. // create paths
  3838. lfs_mkdir(&lfs, "c o f f e e") => 0;
  3839. if (DIR) {
  3840. lfs_mkdir(&lfs, "c o f f e e/d r i p") => 0;
  3841. lfs_mkdir(&lfs, "c o f f e e/c o l d b r e w") => 0;
  3842. lfs_mkdir(&lfs, "c o f f e e/t u r k i s h") => 0;
  3843. lfs_mkdir(&lfs, "c o f f e e/t u b r u k") => 0;
  3844. lfs_mkdir(&lfs, "c o f f e e/v i e t n a m e s e") => 0;
  3845. lfs_mkdir(&lfs, "c o f f e e/t h a i") => 0;
  3846. } else {
  3847. lfs_file_t file;
  3848. lfs_file_open(&lfs, &file, "c o f f e e/d r i p",
  3849. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3850. lfs_file_close(&lfs, &file) => 0;
  3851. lfs_file_open(&lfs, &file, "c o f f e e/c o l d b r e w",
  3852. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3853. lfs_file_close(&lfs, &file) => 0;
  3854. lfs_file_open(&lfs, &file, "c o f f e e/t u r k i s h",
  3855. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3856. lfs_file_close(&lfs, &file) => 0;
  3857. lfs_file_open(&lfs, &file, "c o f f e e/t u b r u k",
  3858. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3859. lfs_file_close(&lfs, &file) => 0;
  3860. lfs_file_open(&lfs, &file, "c o f f e e/v i e t n a m e s e",
  3861. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3862. lfs_file_close(&lfs, &file) => 0;
  3863. lfs_file_open(&lfs, &file, "c o f f e e/t h a i",
  3864. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3865. lfs_file_close(&lfs, &file) => 0;
  3866. }
  3867. // stat paths
  3868. struct lfs_info info;
  3869. lfs_stat(&lfs, "c o f f e e/d r i p", &info) => 0;
  3870. assert(strcmp(info.name, "d r i p") == 0);
  3871. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3872. lfs_stat(&lfs, "c o f f e e/c o l d b r e w", &info) => 0;
  3873. assert(strcmp(info.name, "c o l d b r e w") == 0);
  3874. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3875. lfs_stat(&lfs, "c o f f e e/t u r k i s h", &info) => 0;
  3876. assert(strcmp(info.name, "t u r k i s h") == 0);
  3877. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3878. lfs_stat(&lfs, "c o f f e e/t u b r u k", &info) => 0;
  3879. assert(strcmp(info.name, "t u b r u k") == 0);
  3880. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3881. lfs_stat(&lfs, "c o f f e e/v i e t n a m e s e", &info) => 0;
  3882. assert(strcmp(info.name, "v i e t n a m e s e") == 0);
  3883. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3884. lfs_stat(&lfs, "c o f f e e/t h a i", &info) => 0;
  3885. assert(strcmp(info.name, "t h a i") == 0);
  3886. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3887. // file open paths, only works on files!
  3888. if (DIR) {
  3889. lfs_file_t file;
  3890. lfs_file_open(&lfs, &file, "c o f f e e/d r i p",
  3891. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3892. lfs_file_open(&lfs, &file, "c o f f e e/c o l d b r e w",
  3893. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3894. lfs_file_open(&lfs, &file, "c o f f e e/t u r k i s h",
  3895. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3896. lfs_file_open(&lfs, &file, "c o f f e e/t u b r u k",
  3897. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3898. lfs_file_open(&lfs, &file, "c o f f e e/v i e t n a m e s e",
  3899. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3900. lfs_file_open(&lfs, &file, "c o f f e e/t h a i",
  3901. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3902. } else {
  3903. lfs_file_t file;
  3904. lfs_file_open(&lfs, &file, "c o f f e e/d r i p",
  3905. LFS_O_RDONLY) => 0;
  3906. lfs_file_close(&lfs, &file) => 0;
  3907. lfs_file_open(&lfs, &file, "c o f f e e/c o l d b r e w",
  3908. LFS_O_RDONLY) => 0;
  3909. lfs_file_close(&lfs, &file) => 0;
  3910. lfs_file_open(&lfs, &file, "c o f f e e/t u r k i s h",
  3911. LFS_O_RDONLY) => 0;
  3912. lfs_file_close(&lfs, &file) => 0;
  3913. lfs_file_open(&lfs, &file, "c o f f e e/t u b r u k",
  3914. LFS_O_RDONLY) => 0;
  3915. lfs_file_close(&lfs, &file) => 0;
  3916. lfs_file_open(&lfs, &file, "c o f f e e/v i e t n a m e s e",
  3917. LFS_O_RDONLY) => 0;
  3918. lfs_file_close(&lfs, &file) => 0;
  3919. lfs_file_open(&lfs, &file, "c o f f e e/t h a i",
  3920. LFS_O_RDONLY) => 0;
  3921. lfs_file_close(&lfs, &file) => 0;
  3922. }
  3923. // dir open paths, only works on dirs!
  3924. if (DIR) {
  3925. lfs_dir_t dir;
  3926. lfs_dir_open(&lfs, &dir, "c o f f e e/d r i p") => 0;
  3927. lfs_dir_close(&lfs, &dir) => 0;
  3928. lfs_dir_open(&lfs, &dir, "c o f f e e/c o l d b r e w") => 0;
  3929. lfs_dir_close(&lfs, &dir) => 0;
  3930. lfs_dir_open(&lfs, &dir, "c o f f e e/t u r k i s h") => 0;
  3931. lfs_dir_close(&lfs, &dir) => 0;
  3932. lfs_dir_open(&lfs, &dir, "c o f f e e/t u b r u k") => 0;
  3933. lfs_dir_close(&lfs, &dir) => 0;
  3934. lfs_dir_open(&lfs, &dir, "c o f f e e/v i e t n a m e s e") => 0;
  3935. lfs_dir_close(&lfs, &dir) => 0;
  3936. lfs_dir_open(&lfs, &dir, "c o f f e e/t h a i") => 0;
  3937. lfs_dir_close(&lfs, &dir) => 0;
  3938. } else {
  3939. lfs_dir_t dir;
  3940. lfs_dir_open(&lfs, &dir, "c o f f e e/d r i p") => LFS_ERR_NOTDIR;
  3941. lfs_dir_open(&lfs, &dir, "c o f f e e/c o l d b r e w") => LFS_ERR_NOTDIR;
  3942. lfs_dir_open(&lfs, &dir, "c o f f e e/t u r k i s h") => LFS_ERR_NOTDIR;
  3943. lfs_dir_open(&lfs, &dir, "c o f f e e/t u b r u k") => LFS_ERR_NOTDIR;
  3944. lfs_dir_open(&lfs, &dir, "c o f f e e/v i e t n a m e s e") => LFS_ERR_NOTDIR;
  3945. lfs_dir_open(&lfs, &dir, "c o f f e e/t h a i") => LFS_ERR_NOTDIR;
  3946. }
  3947. // rename paths
  3948. lfs_mkdir(&lfs, "e s p r e s s o") => 0;
  3949. lfs_rename(&lfs,
  3950. "c o f f e e/d r i p",
  3951. "e s p r e s s o/e s p r e s s o") => 0;
  3952. lfs_rename(&lfs,
  3953. "c o f f e e/c o l d b r e w",
  3954. "e s p r e s s o/a m e r i c a n o") => 0;
  3955. lfs_rename(&lfs,
  3956. "c o f f e e/t u r k i s h",
  3957. "e s p r e s s o/m a c c h i a t o") => 0;
  3958. lfs_rename(&lfs,
  3959. "c o f f e e/t u b r u k",
  3960. "e s p r e s s o/l a t t e") => 0;
  3961. lfs_rename(&lfs,
  3962. "c o f f e e/v i e t n a m e s e",
  3963. "e s p r e s s o/c a p p u c c i n o") => 0;
  3964. lfs_rename(&lfs,
  3965. "c o f f e e/t h a i",
  3966. "e s p r e s s o/m o c h a") => 0;
  3967. // stat paths
  3968. lfs_stat(&lfs, "e s p r e s s o/e s p r e s s o", &info) => 0;
  3969. assert(strcmp(info.name, "e s p r e s s o") == 0);
  3970. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3971. lfs_stat(&lfs, "e s p r e s s o/a m e r i c a n o", &info) => 0;
  3972. assert(strcmp(info.name, "a m e r i c a n o") == 0);
  3973. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3974. lfs_stat(&lfs, "e s p r e s s o/m a c c h i a t o", &info) => 0;
  3975. assert(strcmp(info.name, "m a c c h i a t o") == 0);
  3976. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3977. lfs_stat(&lfs, "e s p r e s s o/l a t t e", &info) => 0;
  3978. assert(strcmp(info.name, "l a t t e") == 0);
  3979. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3980. lfs_stat(&lfs, "e s p r e s s o/c a p p u c c i n o", &info) => 0;
  3981. assert(strcmp(info.name, "c a p p u c c i n o") == 0);
  3982. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3983. lfs_stat(&lfs, "e s p r e s s o/m o c h a", &info) => 0;
  3984. assert(strcmp(info.name, "m o c h a") == 0);
  3985. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3986. lfs_stat(&lfs, "c o f f e e/d r i p", &info) => LFS_ERR_NOENT;
  3987. lfs_stat(&lfs, "c o f f e e/c o l d b r e w", &info) => LFS_ERR_NOENT;
  3988. lfs_stat(&lfs, "c o f f e e/t u r k i s h", &info) => LFS_ERR_NOENT;
  3989. lfs_stat(&lfs, "c o f f e e/t u b r u k", &info) => LFS_ERR_NOENT;
  3990. lfs_stat(&lfs, "c o f f e e/v i e t n a m e s e", &info) => LFS_ERR_NOENT;
  3991. lfs_stat(&lfs, "c o f f e e/t h a i", &info) => LFS_ERR_NOENT;
  3992. // remove paths
  3993. lfs_remove(&lfs, "e s p r e s s o/e s p r e s s o") => 0;
  3994. lfs_remove(&lfs, "e s p r e s s o/a m e r i c a n o") => 0;
  3995. lfs_remove(&lfs, "e s p r e s s o/m a c c h i a t o") => 0;
  3996. lfs_remove(&lfs, "e s p r e s s o/l a t t e") => 0;
  3997. lfs_remove(&lfs, "e s p r e s s o/c a p p u c c i n o") => 0;
  3998. lfs_remove(&lfs, "e s p r e s s o/m o c h a") => 0;
  3999. // stat paths
  4000. lfs_stat(&lfs, "e s p r e s s o/e s p r e s s o", &info) => LFS_ERR_NOENT;
  4001. lfs_stat(&lfs, "e s p r e s s o/a m e r i c a n o", &info) => LFS_ERR_NOENT;
  4002. lfs_stat(&lfs, "e s p r e s s o/m a c c h i a t o", &info) => LFS_ERR_NOENT;
  4003. lfs_stat(&lfs, "e s p r e s s o/l a t t e", &info) => LFS_ERR_NOENT;
  4004. lfs_stat(&lfs, "e s p r e s s o/c a p p u c c i n o", &info) => LFS_ERR_NOENT;
  4005. lfs_stat(&lfs, "e s p r e s s o/m o c h a", &info) => LFS_ERR_NOENT;
  4006. lfs_unmount(&lfs) => 0;
  4007. '''
  4008. # test with only spaces
  4009. #
  4010. # please don't do this
  4011. [cases.test_paths_oopsallspaces]
  4012. defines.DIR = [false, true]
  4013. code = '''
  4014. lfs_t lfs;
  4015. lfs_format(&lfs, cfg) => 0;
  4016. lfs_mount(&lfs, cfg) => 0;
  4017. // create paths
  4018. lfs_mkdir(&lfs, " ") => 0;
  4019. if (DIR) {
  4020. lfs_mkdir(&lfs, " / ") => 0;
  4021. lfs_mkdir(&lfs, " / ") => 0;
  4022. lfs_mkdir(&lfs, " / ") => 0;
  4023. lfs_mkdir(&lfs, " / ") => 0;
  4024. lfs_mkdir(&lfs, " / ") => 0;
  4025. lfs_mkdir(&lfs, " / ") => 0;
  4026. } else {
  4027. lfs_file_t file;
  4028. lfs_file_open(&lfs, &file, " / ",
  4029. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4030. lfs_file_close(&lfs, &file) => 0;
  4031. lfs_file_open(&lfs, &file, " / ",
  4032. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4033. lfs_file_close(&lfs, &file) => 0;
  4034. lfs_file_open(&lfs, &file, " / ",
  4035. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4036. lfs_file_close(&lfs, &file) => 0;
  4037. lfs_file_open(&lfs, &file, " / ",
  4038. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4039. lfs_file_close(&lfs, &file) => 0;
  4040. lfs_file_open(&lfs, &file, " / ",
  4041. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4042. lfs_file_close(&lfs, &file) => 0;
  4043. lfs_file_open(&lfs, &file, " / ",
  4044. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4045. lfs_file_close(&lfs, &file) => 0;
  4046. }
  4047. // stat paths
  4048. struct lfs_info info;
  4049. lfs_stat(&lfs, " / ", &info) => 0;
  4050. assert(strcmp(info.name, " ") == 0);
  4051. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4052. lfs_stat(&lfs, " / ", &info) => 0;
  4053. assert(strcmp(info.name, " ") == 0);
  4054. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4055. lfs_stat(&lfs, " / ", &info) => 0;
  4056. assert(strcmp(info.name, " ") == 0);
  4057. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4058. lfs_stat(&lfs, " / ", &info) => 0;
  4059. assert(strcmp(info.name, " ") == 0);
  4060. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4061. lfs_stat(&lfs, " / ", &info) => 0;
  4062. assert(strcmp(info.name, " ") == 0);
  4063. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4064. lfs_stat(&lfs, " / ", &info) => 0;
  4065. assert(strcmp(info.name, " ") == 0);
  4066. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4067. // file open paths, only works on files!
  4068. if (DIR) {
  4069. lfs_file_t file;
  4070. lfs_file_open(&lfs, &file, " / ",
  4071. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4072. lfs_file_open(&lfs, &file, " / ",
  4073. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4074. lfs_file_open(&lfs, &file, " / ",
  4075. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4076. lfs_file_open(&lfs, &file, " / ",
  4077. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4078. lfs_file_open(&lfs, &file, " / ",
  4079. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4080. lfs_file_open(&lfs, &file, " / ",
  4081. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4082. } else {
  4083. lfs_file_t file;
  4084. lfs_file_open(&lfs, &file, " / ",
  4085. LFS_O_RDONLY) => 0;
  4086. lfs_file_close(&lfs, &file) => 0;
  4087. lfs_file_open(&lfs, &file, " / ",
  4088. LFS_O_RDONLY) => 0;
  4089. lfs_file_close(&lfs, &file) => 0;
  4090. lfs_file_open(&lfs, &file, " / ",
  4091. LFS_O_RDONLY) => 0;
  4092. lfs_file_close(&lfs, &file) => 0;
  4093. lfs_file_open(&lfs, &file, " / ",
  4094. LFS_O_RDONLY) => 0;
  4095. lfs_file_close(&lfs, &file) => 0;
  4096. lfs_file_open(&lfs, &file, " / ",
  4097. LFS_O_RDONLY) => 0;
  4098. lfs_file_close(&lfs, &file) => 0;
  4099. lfs_file_open(&lfs, &file, " / ",
  4100. LFS_O_RDONLY) => 0;
  4101. lfs_file_close(&lfs, &file) => 0;
  4102. }
  4103. // dir open paths, only works on dirs!
  4104. if (DIR) {
  4105. lfs_dir_t dir;
  4106. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4107. lfs_dir_close(&lfs, &dir) => 0;
  4108. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4109. lfs_dir_close(&lfs, &dir) => 0;
  4110. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4111. lfs_dir_close(&lfs, &dir) => 0;
  4112. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4113. lfs_dir_close(&lfs, &dir) => 0;
  4114. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4115. lfs_dir_close(&lfs, &dir) => 0;
  4116. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4117. lfs_dir_close(&lfs, &dir) => 0;
  4118. } else {
  4119. lfs_dir_t dir;
  4120. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4121. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4122. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4123. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4124. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4125. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4126. }
  4127. // rename paths
  4128. lfs_mkdir(&lfs, " ") => 0;
  4129. lfs_rename(&lfs,
  4130. " / ",
  4131. " / ") => 0;
  4132. lfs_rename(&lfs,
  4133. " / ",
  4134. " / ") => 0;
  4135. lfs_rename(&lfs,
  4136. " / ",
  4137. " / ") => 0;
  4138. lfs_rename(&lfs,
  4139. " / ",
  4140. " / ") => 0;
  4141. lfs_rename(&lfs,
  4142. " / ",
  4143. " / ") => 0;
  4144. lfs_rename(&lfs,
  4145. " / ",
  4146. " / ") => 0;
  4147. // stat paths
  4148. lfs_stat(&lfs, " / ", &info) => 0;
  4149. assert(strcmp(info.name, " ") == 0);
  4150. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4151. lfs_stat(&lfs, " / ", &info) => 0;
  4152. assert(strcmp(info.name, " ") == 0);
  4153. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4154. lfs_stat(&lfs, " / ", &info) => 0;
  4155. assert(strcmp(info.name, " ") == 0);
  4156. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4157. lfs_stat(&lfs, " / ", &info) => 0;
  4158. assert(strcmp(info.name, " ") == 0);
  4159. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4160. lfs_stat(&lfs, " / ", &info) => 0;
  4161. assert(strcmp(info.name, " ") == 0);
  4162. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4163. lfs_stat(&lfs, " / ", &info) => 0;
  4164. assert(strcmp(info.name, " ") == 0);
  4165. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4166. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4167. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4168. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4169. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4170. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4171. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4172. // remove paths
  4173. lfs_remove(&lfs, " / ") => 0;
  4174. lfs_remove(&lfs, " / ") => 0;
  4175. lfs_remove(&lfs, " / ") => 0;
  4176. lfs_remove(&lfs, " / ") => 0;
  4177. lfs_remove(&lfs, " / ") => 0;
  4178. lfs_remove(&lfs, " / ") => 0;
  4179. // stat paths
  4180. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4181. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4182. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4183. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4184. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4185. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4186. lfs_unmount(&lfs) => 0;
  4187. '''
  4188. # test with only ascii control characters
  4189. #
  4190. # littlefs only cares about "./" and NULL
  4191. [cases.test_paths_nonprintable]
  4192. defines.DIR = [false, true]
  4193. code = '''
  4194. lfs_t lfs;
  4195. lfs_format(&lfs, cfg) => 0;
  4196. lfs_mount(&lfs, cfg) => 0;
  4197. // create paths
  4198. lfs_mkdir(&lfs, "\x0c") => 0;
  4199. if (DIR) {
  4200. lfs_mkdir(&lfs, "\x0c/\x01") => 0;
  4201. lfs_mkdir(&lfs, "\x0c/\x02") => 0;
  4202. lfs_mkdir(&lfs, "\x0c/\x03") => 0;
  4203. lfs_mkdir(&lfs, "\x0c/\x04") => 0;
  4204. lfs_mkdir(&lfs, "\x0c/\x05") => 0;
  4205. lfs_mkdir(&lfs, "\x0c/\x06") => 0;
  4206. } else {
  4207. lfs_file_t file;
  4208. lfs_file_open(&lfs, &file, "\x0c/\x01",
  4209. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4210. lfs_file_close(&lfs, &file) => 0;
  4211. lfs_file_open(&lfs, &file, "\x0c/\x02",
  4212. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4213. lfs_file_close(&lfs, &file) => 0;
  4214. lfs_file_open(&lfs, &file, "\x0c/\x03",
  4215. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4216. lfs_file_close(&lfs, &file) => 0;
  4217. lfs_file_open(&lfs, &file, "\x0c/\x04",
  4218. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4219. lfs_file_close(&lfs, &file) => 0;
  4220. lfs_file_open(&lfs, &file, "\x0c/\x05",
  4221. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4222. lfs_file_close(&lfs, &file) => 0;
  4223. lfs_file_open(&lfs, &file, "\x0c/\x06",
  4224. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4225. lfs_file_close(&lfs, &file) => 0;
  4226. }
  4227. // stat paths
  4228. struct lfs_info info;
  4229. lfs_stat(&lfs, "\x0c/\x01", &info) => 0;
  4230. assert(strcmp(info.name, "\x01") == 0);
  4231. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4232. lfs_stat(&lfs, "\x0c/\x02", &info) => 0;
  4233. assert(strcmp(info.name, "\x02") == 0);
  4234. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4235. lfs_stat(&lfs, "\x0c/\x03", &info) => 0;
  4236. assert(strcmp(info.name, "\x03") == 0);
  4237. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4238. lfs_stat(&lfs, "\x0c/\x04", &info) => 0;
  4239. assert(strcmp(info.name, "\x04") == 0);
  4240. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4241. lfs_stat(&lfs, "\x0c/\x05", &info) => 0;
  4242. assert(strcmp(info.name, "\x05") == 0);
  4243. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4244. lfs_stat(&lfs, "\x0c/\x06", &info) => 0;
  4245. assert(strcmp(info.name, "\x06") == 0);
  4246. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4247. // file open paths, only works on files!
  4248. if (DIR) {
  4249. lfs_file_t file;
  4250. lfs_file_open(&lfs, &file, "\x0c/\x01",
  4251. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4252. lfs_file_open(&lfs, &file, "\x0c/\x02",
  4253. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4254. lfs_file_open(&lfs, &file, "\x0c/\x03",
  4255. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4256. lfs_file_open(&lfs, &file, "\x0c/\x04",
  4257. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4258. lfs_file_open(&lfs, &file, "\x0c/\x05",
  4259. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4260. lfs_file_open(&lfs, &file, "\x0c/\x06",
  4261. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4262. } else {
  4263. lfs_file_t file;
  4264. lfs_file_open(&lfs, &file, "\x0c/\x01",
  4265. LFS_O_RDONLY) => 0;
  4266. lfs_file_close(&lfs, &file) => 0;
  4267. lfs_file_open(&lfs, &file, "\x0c/\x02",
  4268. LFS_O_RDONLY) => 0;
  4269. lfs_file_close(&lfs, &file) => 0;
  4270. lfs_file_open(&lfs, &file, "\x0c/\x03",
  4271. LFS_O_RDONLY) => 0;
  4272. lfs_file_close(&lfs, &file) => 0;
  4273. lfs_file_open(&lfs, &file, "\x0c/\x04",
  4274. LFS_O_RDONLY) => 0;
  4275. lfs_file_close(&lfs, &file) => 0;
  4276. lfs_file_open(&lfs, &file, "\x0c/\x05",
  4277. LFS_O_RDONLY) => 0;
  4278. lfs_file_close(&lfs, &file) => 0;
  4279. lfs_file_open(&lfs, &file, "\x0c/\x06",
  4280. LFS_O_RDONLY) => 0;
  4281. lfs_file_close(&lfs, &file) => 0;
  4282. }
  4283. // dir open paths, only works on dirs!
  4284. if (DIR) {
  4285. lfs_dir_t dir;
  4286. lfs_dir_open(&lfs, &dir, "\x0c/\x01") => 0;
  4287. lfs_dir_close(&lfs, &dir) => 0;
  4288. lfs_dir_open(&lfs, &dir, "\x0c/\x02") => 0;
  4289. lfs_dir_close(&lfs, &dir) => 0;
  4290. lfs_dir_open(&lfs, &dir, "\x0c/\x03") => 0;
  4291. lfs_dir_close(&lfs, &dir) => 0;
  4292. lfs_dir_open(&lfs, &dir, "\x0c/\x04") => 0;
  4293. lfs_dir_close(&lfs, &dir) => 0;
  4294. lfs_dir_open(&lfs, &dir, "\x0c/\x05") => 0;
  4295. lfs_dir_close(&lfs, &dir) => 0;
  4296. lfs_dir_open(&lfs, &dir, "\x0c/\x06") => 0;
  4297. lfs_dir_close(&lfs, &dir) => 0;
  4298. } else {
  4299. lfs_dir_t dir;
  4300. lfs_dir_open(&lfs, &dir, "\x0c/\x01") => LFS_ERR_NOTDIR;
  4301. lfs_dir_open(&lfs, &dir, "\x0c/\x02") => LFS_ERR_NOTDIR;
  4302. lfs_dir_open(&lfs, &dir, "\x0c/\x03") => LFS_ERR_NOTDIR;
  4303. lfs_dir_open(&lfs, &dir, "\x0c/\x04") => LFS_ERR_NOTDIR;
  4304. lfs_dir_open(&lfs, &dir, "\x0c/\x05") => LFS_ERR_NOTDIR;
  4305. lfs_dir_open(&lfs, &dir, "\x0c/\x06") => LFS_ERR_NOTDIR;
  4306. }
  4307. // rename paths
  4308. lfs_mkdir(&lfs, "\x0e") => 0;
  4309. lfs_rename(&lfs,
  4310. "\x0c/\x01",
  4311. "\x0e/\x1a") => 0;
  4312. lfs_rename(&lfs,
  4313. "\x0c/\x02",
  4314. "\x0e/\x1b") => 0;
  4315. lfs_rename(&lfs,
  4316. "\x0c/\x03",
  4317. "\x0e/\x1c") => 0;
  4318. lfs_rename(&lfs,
  4319. "\x0c/\x04",
  4320. "\x0e/\x1d") => 0;
  4321. lfs_rename(&lfs,
  4322. "\x0c/\x05",
  4323. "\x0e/\x1e") => 0;
  4324. lfs_rename(&lfs,
  4325. "\x0c/\x06",
  4326. "\x0e/\x1f") => 0;
  4327. // stat paths
  4328. lfs_stat(&lfs, "\x0e/\x1a", &info) => 0;
  4329. assert(strcmp(info.name, "\x1a") == 0);
  4330. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4331. lfs_stat(&lfs, "\x0e/\x1b", &info) => 0;
  4332. assert(strcmp(info.name, "\x1b") == 0);
  4333. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4334. lfs_stat(&lfs, "\x0e/\x1c", &info) => 0;
  4335. assert(strcmp(info.name, "\x1c") == 0);
  4336. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4337. lfs_stat(&lfs, "\x0e/\x1d", &info) => 0;
  4338. assert(strcmp(info.name, "\x1d") == 0);
  4339. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4340. lfs_stat(&lfs, "\x0e/\x1e", &info) => 0;
  4341. assert(strcmp(info.name, "\x1e") == 0);
  4342. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4343. lfs_stat(&lfs, "\x0e/\x1f", &info) => 0;
  4344. assert(strcmp(info.name, "\x1f") == 0);
  4345. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4346. lfs_stat(&lfs, "\x0c/\x01", &info) => LFS_ERR_NOENT;
  4347. lfs_stat(&lfs, "\x0c/\x02", &info) => LFS_ERR_NOENT;
  4348. lfs_stat(&lfs, "\x0c/\x03", &info) => LFS_ERR_NOENT;
  4349. lfs_stat(&lfs, "\x0c/\x04", &info) => LFS_ERR_NOENT;
  4350. lfs_stat(&lfs, "\x0c/\x05", &info) => LFS_ERR_NOENT;
  4351. lfs_stat(&lfs, "\x0c/\x06", &info) => LFS_ERR_NOENT;
  4352. // remove paths
  4353. lfs_remove(&lfs, "\x0e/\x1a") => 0;
  4354. lfs_remove(&lfs, "\x0e/\x1b") => 0;
  4355. lfs_remove(&lfs, "\x0e/\x1c") => 0;
  4356. lfs_remove(&lfs, "\x0e/\x1d") => 0;
  4357. lfs_remove(&lfs, "\x0e/\x1e") => 0;
  4358. lfs_remove(&lfs, "\x0e/\x1f") => 0;
  4359. // stat paths
  4360. lfs_stat(&lfs, "\x0e/\x1a", &info) => LFS_ERR_NOENT;
  4361. lfs_stat(&lfs, "\x0e/\x1b", &info) => LFS_ERR_NOENT;
  4362. lfs_stat(&lfs, "\x0e/\x1c", &info) => LFS_ERR_NOENT;
  4363. lfs_stat(&lfs, "\x0e/\x1d", &info) => LFS_ERR_NOENT;
  4364. lfs_stat(&lfs, "\x0e/\x1e", &info) => LFS_ERR_NOENT;
  4365. lfs_stat(&lfs, "\x0e/\x1f", &info) => LFS_ERR_NOENT;
  4366. lfs_unmount(&lfs) => 0;
  4367. '''
  4368. # test with only ascii DELs
  4369. #
  4370. # I don't know why you'd do this
  4371. [cases.test_paths_oopsalldels]
  4372. defines.DIR = [false, true]
  4373. code = '''
  4374. lfs_t lfs;
  4375. lfs_format(&lfs, cfg) => 0;
  4376. lfs_mount(&lfs, cfg) => 0;
  4377. // create paths
  4378. lfs_mkdir(&lfs, "\x7f") => 0;
  4379. if (DIR) {
  4380. lfs_mkdir(&lfs, "\x7f/\x7f") => 0;
  4381. lfs_mkdir(&lfs, "\x7f/\x7f\x7f") => 0;
  4382. lfs_mkdir(&lfs, "\x7f/\x7f\x7f\x7f") => 0;
  4383. lfs_mkdir(&lfs, "\x7f/\x7f\x7f\x7f\x7f") => 0;
  4384. lfs_mkdir(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f") => 0;
  4385. lfs_mkdir(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4386. } else {
  4387. lfs_file_t file;
  4388. lfs_file_open(&lfs, &file, "\x7f/\x7f",
  4389. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4390. lfs_file_close(&lfs, &file) => 0;
  4391. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f",
  4392. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4393. lfs_file_close(&lfs, &file) => 0;
  4394. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f",
  4395. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4396. lfs_file_close(&lfs, &file) => 0;
  4397. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f",
  4398. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4399. lfs_file_close(&lfs, &file) => 0;
  4400. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f",
  4401. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4402. lfs_file_close(&lfs, &file) => 0;
  4403. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f",
  4404. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4405. lfs_file_close(&lfs, &file) => 0;
  4406. }
  4407. // stat paths
  4408. struct lfs_info info;
  4409. lfs_stat(&lfs, "\x7f/\x7f", &info) => 0;
  4410. assert(strcmp(info.name, "\x7f") == 0);
  4411. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4412. lfs_stat(&lfs, "\x7f/\x7f\x7f", &info) => 0;
  4413. assert(strcmp(info.name, "\x7f\x7f") == 0);
  4414. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4415. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f", &info) => 0;
  4416. assert(strcmp(info.name, "\x7f\x7f\x7f") == 0);
  4417. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4418. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f", &info) => 0;
  4419. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f") == 0);
  4420. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4421. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4422. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f") == 0);
  4423. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4424. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4425. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4426. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4427. // file open paths, only works on files!
  4428. if (DIR) {
  4429. lfs_file_t file;
  4430. lfs_file_open(&lfs, &file, "\x7f/\x7f",
  4431. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4432. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f",
  4433. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4434. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f",
  4435. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4436. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f",
  4437. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4438. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f",
  4439. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4440. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f",
  4441. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4442. } else {
  4443. lfs_file_t file;
  4444. lfs_file_open(&lfs, &file, "\x7f/\x7f",
  4445. LFS_O_RDONLY) => 0;
  4446. lfs_file_close(&lfs, &file) => 0;
  4447. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f",
  4448. LFS_O_RDONLY) => 0;
  4449. lfs_file_close(&lfs, &file) => 0;
  4450. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f",
  4451. LFS_O_RDONLY) => 0;
  4452. lfs_file_close(&lfs, &file) => 0;
  4453. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f",
  4454. LFS_O_RDONLY) => 0;
  4455. lfs_file_close(&lfs, &file) => 0;
  4456. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f",
  4457. LFS_O_RDONLY) => 0;
  4458. lfs_file_close(&lfs, &file) => 0;
  4459. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f",
  4460. LFS_O_RDONLY) => 0;
  4461. lfs_file_close(&lfs, &file) => 0;
  4462. }
  4463. // dir open paths, only works on dirs!
  4464. if (DIR) {
  4465. lfs_dir_t dir;
  4466. lfs_dir_open(&lfs, &dir, "\x7f/\x7f") => 0;
  4467. lfs_dir_close(&lfs, &dir) => 0;
  4468. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f") => 0;
  4469. lfs_dir_close(&lfs, &dir) => 0;
  4470. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f") => 0;
  4471. lfs_dir_close(&lfs, &dir) => 0;
  4472. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f") => 0;
  4473. lfs_dir_close(&lfs, &dir) => 0;
  4474. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f\x7f") => 0;
  4475. lfs_dir_close(&lfs, &dir) => 0;
  4476. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4477. lfs_dir_close(&lfs, &dir) => 0;
  4478. } else {
  4479. lfs_dir_t dir;
  4480. lfs_dir_open(&lfs, &dir, "\x7f/\x7f") => LFS_ERR_NOTDIR;
  4481. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f") => LFS_ERR_NOTDIR;
  4482. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f") => LFS_ERR_NOTDIR;
  4483. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f") => LFS_ERR_NOTDIR;
  4484. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f\x7f") => LFS_ERR_NOTDIR;
  4485. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f") => LFS_ERR_NOTDIR;
  4486. }
  4487. // rename paths
  4488. lfs_mkdir(&lfs, "\x7f\x7f") => 0;
  4489. lfs_rename(&lfs,
  4490. "\x7f/\x7f",
  4491. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4492. lfs_rename(&lfs,
  4493. "\x7f/\x7f\x7f",
  4494. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4495. lfs_rename(&lfs,
  4496. "\x7f/\x7f\x7f\x7f",
  4497. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4498. lfs_rename(&lfs,
  4499. "\x7f/\x7f\x7f\x7f\x7f",
  4500. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4501. lfs_rename(&lfs,
  4502. "\x7f/\x7f\x7f\x7f\x7f\x7f",
  4503. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4504. lfs_rename(&lfs,
  4505. "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f",
  4506. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4507. // stat paths
  4508. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4509. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4510. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4511. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4512. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4513. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4514. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4515. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4516. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4517. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4518. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4519. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4520. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4521. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4522. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4523. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4524. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4525. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4526. lfs_stat(&lfs, "\x7f/\x7f", &info) => LFS_ERR_NOENT;
  4527. lfs_stat(&lfs, "\x7f/\x7f\x7f", &info) => LFS_ERR_NOENT;
  4528. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4529. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4530. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4531. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4532. // remove paths
  4533. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4534. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4535. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4536. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4537. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4538. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4539. // stat paths
  4540. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4541. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4542. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4543. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4544. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4545. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4546. lfs_unmount(&lfs) => 0;
  4547. '''
  4548. # test with invalid utf8 sequences
  4549. #
  4550. # Don't do this! These filenames are not utf8 and will probably break
  4551. # external tools.
  4552. #
  4553. [cases.test_paths_nonutf8]
  4554. defines.DIR = [false, true]
  4555. code = '''
  4556. lfs_t lfs;
  4557. lfs_format(&lfs, cfg) => 0;
  4558. lfs_mount(&lfs, cfg) => 0;
  4559. // create paths
  4560. lfs_mkdir(&lfs, "\xc0") => 0;
  4561. if (DIR) {
  4562. lfs_mkdir(&lfs, "\xc0/\xa0") => 0;
  4563. lfs_mkdir(&lfs, "\xc0/\xb0") => 0;
  4564. lfs_mkdir(&lfs, "\xc0/\xc0") => 0;
  4565. lfs_mkdir(&lfs, "\xc0/\xd0") => 0;
  4566. lfs_mkdir(&lfs, "\xc0/\xe0") => 0;
  4567. lfs_mkdir(&lfs, "\xc0/\xf0") => 0;
  4568. } else {
  4569. lfs_file_t file;
  4570. lfs_file_open(&lfs, &file, "\xc0/\xa0",
  4571. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4572. lfs_file_close(&lfs, &file) => 0;
  4573. lfs_file_open(&lfs, &file, "\xc0/\xb0",
  4574. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4575. lfs_file_close(&lfs, &file) => 0;
  4576. lfs_file_open(&lfs, &file, "\xc0/\xc0",
  4577. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4578. lfs_file_close(&lfs, &file) => 0;
  4579. lfs_file_open(&lfs, &file, "\xc0/\xd0",
  4580. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4581. lfs_file_close(&lfs, &file) => 0;
  4582. lfs_file_open(&lfs, &file, "\xc0/\xe0",
  4583. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4584. lfs_file_close(&lfs, &file) => 0;
  4585. lfs_file_open(&lfs, &file, "\xc0/\xf0",
  4586. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4587. lfs_file_close(&lfs, &file) => 0;
  4588. }
  4589. // stat paths
  4590. struct lfs_info info;
  4591. lfs_stat(&lfs, "\xc0/\xa0", &info) => 0;
  4592. assert(strcmp(info.name, "\xa0") == 0);
  4593. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4594. lfs_stat(&lfs, "\xc0/\xb0", &info) => 0;
  4595. assert(strcmp(info.name, "\xb0") == 0);
  4596. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4597. lfs_stat(&lfs, "\xc0/\xc0", &info) => 0;
  4598. assert(strcmp(info.name, "\xc0") == 0);
  4599. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4600. lfs_stat(&lfs, "\xc0/\xd0", &info) => 0;
  4601. assert(strcmp(info.name, "\xd0") == 0);
  4602. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4603. lfs_stat(&lfs, "\xc0/\xe0", &info) => 0;
  4604. assert(strcmp(info.name, "\xe0") == 0);
  4605. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4606. lfs_stat(&lfs, "\xc0/\xf0", &info) => 0;
  4607. assert(strcmp(info.name, "\xf0") == 0);
  4608. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4609. // file open paths, only works on files!
  4610. if (DIR) {
  4611. lfs_file_t file;
  4612. lfs_file_open(&lfs, &file, "\xc0/\xa0",
  4613. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4614. lfs_file_open(&lfs, &file, "\xc0/\xb0",
  4615. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4616. lfs_file_open(&lfs, &file, "\xc0/\xc0",
  4617. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4618. lfs_file_open(&lfs, &file, "\xc0/\xd0",
  4619. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4620. lfs_file_open(&lfs, &file, "\xc0/\xe0",
  4621. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4622. lfs_file_open(&lfs, &file, "\xc0/\xf0",
  4623. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4624. } else {
  4625. lfs_file_t file;
  4626. lfs_file_open(&lfs, &file, "\xc0/\xa0",
  4627. LFS_O_RDONLY) => 0;
  4628. lfs_file_close(&lfs, &file) => 0;
  4629. lfs_file_open(&lfs, &file, "\xc0/\xb0",
  4630. LFS_O_RDONLY) => 0;
  4631. lfs_file_close(&lfs, &file) => 0;
  4632. lfs_file_open(&lfs, &file, "\xc0/\xc0",
  4633. LFS_O_RDONLY) => 0;
  4634. lfs_file_close(&lfs, &file) => 0;
  4635. lfs_file_open(&lfs, &file, "\xc0/\xd0",
  4636. LFS_O_RDONLY) => 0;
  4637. lfs_file_close(&lfs, &file) => 0;
  4638. lfs_file_open(&lfs, &file, "\xc0/\xe0",
  4639. LFS_O_RDONLY) => 0;
  4640. lfs_file_close(&lfs, &file) => 0;
  4641. lfs_file_open(&lfs, &file, "\xc0/\xf0",
  4642. LFS_O_RDONLY) => 0;
  4643. lfs_file_close(&lfs, &file) => 0;
  4644. }
  4645. // dir open paths, only works on dirs!
  4646. if (DIR) {
  4647. lfs_dir_t dir;
  4648. lfs_dir_open(&lfs, &dir, "\xc0/\xa0") => 0;
  4649. lfs_dir_close(&lfs, &dir) => 0;
  4650. lfs_dir_open(&lfs, &dir, "\xc0/\xb0") => 0;
  4651. lfs_dir_close(&lfs, &dir) => 0;
  4652. lfs_dir_open(&lfs, &dir, "\xc0/\xc0") => 0;
  4653. lfs_dir_close(&lfs, &dir) => 0;
  4654. lfs_dir_open(&lfs, &dir, "\xc0/\xd0") => 0;
  4655. lfs_dir_close(&lfs, &dir) => 0;
  4656. lfs_dir_open(&lfs, &dir, "\xc0/\xe0") => 0;
  4657. lfs_dir_close(&lfs, &dir) => 0;
  4658. lfs_dir_open(&lfs, &dir, "\xc0/\xf0") => 0;
  4659. lfs_dir_close(&lfs, &dir) => 0;
  4660. } else {
  4661. lfs_dir_t dir;
  4662. lfs_dir_open(&lfs, &dir, "\xc0/\xa0") => LFS_ERR_NOTDIR;
  4663. lfs_dir_open(&lfs, &dir, "\xc0/\xb0") => LFS_ERR_NOTDIR;
  4664. lfs_dir_open(&lfs, &dir, "\xc0/\xc0") => LFS_ERR_NOTDIR;
  4665. lfs_dir_open(&lfs, &dir, "\xc0/\xd0") => LFS_ERR_NOTDIR;
  4666. lfs_dir_open(&lfs, &dir, "\xc0/\xe0") => LFS_ERR_NOTDIR;
  4667. lfs_dir_open(&lfs, &dir, "\xc0/\xf0") => LFS_ERR_NOTDIR;
  4668. }
  4669. // rename paths
  4670. lfs_mkdir(&lfs, "\xe0") => 0;
  4671. lfs_rename(&lfs,
  4672. "\xc0/\xa0",
  4673. "\xe0/\xaf") => 0;
  4674. lfs_rename(&lfs,
  4675. "\xc0/\xb0",
  4676. "\xe0/\xbf") => 0;
  4677. lfs_rename(&lfs,
  4678. "\xc0/\xc0",
  4679. "\xe0/\xcf") => 0;
  4680. lfs_rename(&lfs,
  4681. "\xc0/\xd0",
  4682. "\xe0/\xdf") => 0;
  4683. lfs_rename(&lfs,
  4684. "\xc0/\xe0",
  4685. "\xe0/\xef") => 0;
  4686. lfs_rename(&lfs,
  4687. "\xc0/\xf0",
  4688. "\xe0/\xff") => 0;
  4689. // stat paths
  4690. lfs_stat(&lfs, "\xe0/\xaf", &info) => 0;
  4691. assert(strcmp(info.name, "\xaf") == 0);
  4692. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4693. lfs_stat(&lfs, "\xe0/\xbf", &info) => 0;
  4694. assert(strcmp(info.name, "\xbf") == 0);
  4695. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4696. lfs_stat(&lfs, "\xe0/\xcf", &info) => 0;
  4697. assert(strcmp(info.name, "\xcf") == 0);
  4698. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4699. lfs_stat(&lfs, "\xe0/\xdf", &info) => 0;
  4700. assert(strcmp(info.name, "\xdf") == 0);
  4701. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4702. lfs_stat(&lfs, "\xe0/\xef", &info) => 0;
  4703. assert(strcmp(info.name, "\xef") == 0);
  4704. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4705. lfs_stat(&lfs, "\xe0/\xff", &info) => 0;
  4706. assert(strcmp(info.name, "\xff") == 0);
  4707. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4708. lfs_stat(&lfs, "\xc0/\xa0", &info) => LFS_ERR_NOENT;
  4709. lfs_stat(&lfs, "\xc0/\xb0", &info) => LFS_ERR_NOENT;
  4710. lfs_stat(&lfs, "\xc0/\xc0", &info) => LFS_ERR_NOENT;
  4711. lfs_stat(&lfs, "\xc0/\xd0", &info) => LFS_ERR_NOENT;
  4712. lfs_stat(&lfs, "\xc0/\xe0", &info) => LFS_ERR_NOENT;
  4713. lfs_stat(&lfs, "\xc0/\xf0", &info) => LFS_ERR_NOENT;
  4714. // remove paths
  4715. lfs_remove(&lfs, "\xe0/\xaf") => 0;
  4716. lfs_remove(&lfs, "\xe0/\xbf") => 0;
  4717. lfs_remove(&lfs, "\xe0/\xcf") => 0;
  4718. lfs_remove(&lfs, "\xe0/\xdf") => 0;
  4719. lfs_remove(&lfs, "\xe0/\xef") => 0;
  4720. lfs_remove(&lfs, "\xe0/\xff") => 0;
  4721. // stat paths
  4722. lfs_stat(&lfs, "\xe0/\xaf", &info) => LFS_ERR_NOENT;
  4723. lfs_stat(&lfs, "\xe0/\xbf", &info) => LFS_ERR_NOENT;
  4724. lfs_stat(&lfs, "\xe0/\xcf", &info) => LFS_ERR_NOENT;
  4725. lfs_stat(&lfs, "\xe0/\xdf", &info) => LFS_ERR_NOENT;
  4726. lfs_stat(&lfs, "\xe0/\xef", &info) => LFS_ERR_NOENT;
  4727. lfs_stat(&lfs, "\xe0/\xff", &info) => LFS_ERR_NOENT;
  4728. lfs_unmount(&lfs) => 0;
  4729. '''
  4730. # test with only "\xff" characters
  4731. #
  4732. # Don't do this! These filenames are not utf8 and will probably break
  4733. # external tools.
  4734. #
  4735. [cases.test_paths_oopsallffs]
  4736. defines.DIR = [false, true]
  4737. code = '''
  4738. lfs_t lfs;
  4739. lfs_format(&lfs, cfg) => 0;
  4740. lfs_mount(&lfs, cfg) => 0;
  4741. // create paths
  4742. lfs_mkdir(&lfs, "\xff") => 0;
  4743. if (DIR) {
  4744. lfs_mkdir(&lfs, "\xff/\xff") => 0;
  4745. lfs_mkdir(&lfs, "\xff/\xff\xff") => 0;
  4746. lfs_mkdir(&lfs, "\xff/\xff\xff\xff") => 0;
  4747. lfs_mkdir(&lfs, "\xff/\xff\xff\xff\xff") => 0;
  4748. lfs_mkdir(&lfs, "\xff/\xff\xff\xff\xff\xff") => 0;
  4749. lfs_mkdir(&lfs, "\xff/\xff\xff\xff\xff\xff\xff") => 0;
  4750. } else {
  4751. lfs_file_t file;
  4752. lfs_file_open(&lfs, &file, "\xff/\xff",
  4753. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4754. lfs_file_close(&lfs, &file) => 0;
  4755. lfs_file_open(&lfs, &file, "\xff/\xff\xff",
  4756. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4757. lfs_file_close(&lfs, &file) => 0;
  4758. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff",
  4759. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4760. lfs_file_close(&lfs, &file) => 0;
  4761. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff",
  4762. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4763. lfs_file_close(&lfs, &file) => 0;
  4764. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff",
  4765. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4766. lfs_file_close(&lfs, &file) => 0;
  4767. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff\xff",
  4768. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4769. lfs_file_close(&lfs, &file) => 0;
  4770. }
  4771. // stat paths
  4772. struct lfs_info info;
  4773. lfs_stat(&lfs, "\xff/\xff", &info) => 0;
  4774. assert(strcmp(info.name, "\xff") == 0);
  4775. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4776. lfs_stat(&lfs, "\xff/\xff\xff", &info) => 0;
  4777. assert(strcmp(info.name, "\xff\xff") == 0);
  4778. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4779. lfs_stat(&lfs, "\xff/\xff\xff\xff", &info) => 0;
  4780. assert(strcmp(info.name, "\xff\xff\xff") == 0);
  4781. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4782. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff", &info) => 0;
  4783. assert(strcmp(info.name, "\xff\xff\xff\xff") == 0);
  4784. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4785. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff\xff", &info) => 0;
  4786. assert(strcmp(info.name, "\xff\xff\xff\xff\xff") == 0);
  4787. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4788. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff\xff\xff", &info) => 0;
  4789. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff") == 0);
  4790. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4791. // file open paths, only works on files!
  4792. if (DIR) {
  4793. lfs_file_t file;
  4794. lfs_file_open(&lfs, &file, "\xff/\xff",
  4795. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4796. lfs_file_open(&lfs, &file, "\xff/\xff\xff",
  4797. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4798. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff",
  4799. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4800. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff",
  4801. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4802. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff",
  4803. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4804. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff\xff",
  4805. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4806. } else {
  4807. lfs_file_t file;
  4808. lfs_file_open(&lfs, &file, "\xff/\xff",
  4809. LFS_O_RDONLY) => 0;
  4810. lfs_file_close(&lfs, &file) => 0;
  4811. lfs_file_open(&lfs, &file, "\xff/\xff\xff",
  4812. LFS_O_RDONLY) => 0;
  4813. lfs_file_close(&lfs, &file) => 0;
  4814. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff",
  4815. LFS_O_RDONLY) => 0;
  4816. lfs_file_close(&lfs, &file) => 0;
  4817. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff",
  4818. LFS_O_RDONLY) => 0;
  4819. lfs_file_close(&lfs, &file) => 0;
  4820. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff",
  4821. LFS_O_RDONLY) => 0;
  4822. lfs_file_close(&lfs, &file) => 0;
  4823. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff\xff",
  4824. LFS_O_RDONLY) => 0;
  4825. lfs_file_close(&lfs, &file) => 0;
  4826. }
  4827. // dir open paths, only works on dirs!
  4828. if (DIR) {
  4829. lfs_dir_t dir;
  4830. lfs_dir_open(&lfs, &dir, "\xff/\xff") => 0;
  4831. lfs_dir_close(&lfs, &dir) => 0;
  4832. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff") => 0;
  4833. lfs_dir_close(&lfs, &dir) => 0;
  4834. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff") => 0;
  4835. lfs_dir_close(&lfs, &dir) => 0;
  4836. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff") => 0;
  4837. lfs_dir_close(&lfs, &dir) => 0;
  4838. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff\xff") => 0;
  4839. lfs_dir_close(&lfs, &dir) => 0;
  4840. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff\xff\xff") => 0;
  4841. lfs_dir_close(&lfs, &dir) => 0;
  4842. } else {
  4843. lfs_dir_t dir;
  4844. lfs_dir_open(&lfs, &dir, "\xff/\xff") => LFS_ERR_NOTDIR;
  4845. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff") => LFS_ERR_NOTDIR;
  4846. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff") => LFS_ERR_NOTDIR;
  4847. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff") => LFS_ERR_NOTDIR;
  4848. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff\xff") => LFS_ERR_NOTDIR;
  4849. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff\xff\xff") => LFS_ERR_NOTDIR;
  4850. }
  4851. // rename paths
  4852. lfs_mkdir(&lfs, "\xff\xff") => 0;
  4853. lfs_rename(&lfs,
  4854. "\xff/\xff",
  4855. "\xff\xff/\xff\xff\xff\xff\xff\xff") => 0;
  4856. lfs_rename(&lfs,
  4857. "\xff/\xff\xff",
  4858. "\xff\xff/\xff\xff\xff\xff\xff\xff\xff") => 0;
  4859. lfs_rename(&lfs,
  4860. "\xff/\xff\xff\xff",
  4861. "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4862. lfs_rename(&lfs,
  4863. "\xff/\xff\xff\xff\xff",
  4864. "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4865. lfs_rename(&lfs,
  4866. "\xff/\xff\xff\xff\xff\xff",
  4867. "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4868. lfs_rename(&lfs,
  4869. "\xff/\xff\xff\xff\xff\xff\xff",
  4870. "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4871. // stat paths
  4872. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff", &info) => 0;
  4873. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff") == 0);
  4874. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4875. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff", &info) => 0;
  4876. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff\xff") == 0);
  4877. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4878. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff", &info) => 0;
  4879. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff\xff\xff") == 0);
  4880. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4881. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => 0;
  4882. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff\xff\xff\xff") == 0);
  4883. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4884. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => 0;
  4885. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") == 0);
  4886. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4887. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => 0;
  4888. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") == 0);
  4889. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4890. lfs_stat(&lfs, "\xff/\xff", &info) => LFS_ERR_NOENT;
  4891. lfs_stat(&lfs, "\xff/\xff\xff", &info) => LFS_ERR_NOENT;
  4892. lfs_stat(&lfs, "\xff/\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4893. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4894. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4895. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4896. // remove paths
  4897. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff") => 0;
  4898. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff") => 0;
  4899. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4900. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4901. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4902. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4903. // stat paths
  4904. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4905. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4906. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4907. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4908. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4909. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4910. lfs_unmount(&lfs) => 0;
  4911. '''