test_paths.toml 216 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246
  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_INVAL;
  1550. lfs_mkdir(&lfs, "coffee/tubruk/../../../..") => LFS_ERR_INVAL;
  1551. lfs_mkdir(&lfs, "coffee/vietnamese/../../../../..") => LFS_ERR_INVAL;
  1552. lfs_mkdir(&lfs, "coffee/thai/../../../../../..") => LFS_ERR_INVAL;
  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_INVAL;
  1568. lfs_file_open(&lfs, &file, "coffee/tubruk/../../../..",
  1569. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_INVAL;
  1570. lfs_file_open(&lfs, &file, "coffee/vietnamese/../../../../..",
  1571. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_INVAL;
  1572. lfs_file_open(&lfs, &file, "coffee/thai/../../../../../..",
  1573. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_INVAL;
  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) => LFS_ERR_INVAL;
  1597. lfs_stat(&lfs, "coffee/coldbrew/../../../../..", &info) => LFS_ERR_INVAL;
  1598. lfs_stat(&lfs, "coffee/turkish/../../../..", &info) => LFS_ERR_INVAL;
  1599. lfs_stat(&lfs, "coffee/tubruk/../../..", &info) => LFS_ERR_INVAL;
  1600. lfs_stat(&lfs, "coffee/vietnamese/../..", &info) => 0;
  1601. assert(strcmp(info.name, "/") == 0);
  1602. assert(info.type == LFS_TYPE_DIR);
  1603. lfs_stat(&lfs, "coffee/thai/..", &info) => 0;
  1604. assert(strcmp(info.name, "coffee") == 0);
  1605. assert(info.type == LFS_TYPE_DIR);
  1606. // file open paths, only works on files!
  1607. lfs_file_t file;
  1608. lfs_file_open(&lfs, &file, "coffee/drip/..",
  1609. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1610. lfs_file_open(&lfs, &file, "coffee/coldbrew/../..",
  1611. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1612. lfs_file_open(&lfs, &file, "coffee/turkish/../../..",
  1613. LFS_O_RDONLY) => LFS_ERR_INVAL;
  1614. lfs_file_open(&lfs, &file, "coffee/tubruk/../../../..",
  1615. LFS_O_RDONLY) => LFS_ERR_INVAL;
  1616. lfs_file_open(&lfs, &file, "coffee/vietnamese/../../../../..",
  1617. LFS_O_RDONLY) => LFS_ERR_INVAL;
  1618. lfs_file_open(&lfs, &file, "coffee/thai/../../../../../..",
  1619. LFS_O_RDONLY) => LFS_ERR_INVAL;
  1620. // dir open paths, only works on dirs!
  1621. lfs_dir_t dir;
  1622. lfs_dir_open(&lfs, &dir, "coffee/drip/..") => 0;
  1623. lfs_dir_close(&lfs, &dir) => 0;
  1624. lfs_dir_open(&lfs, &dir, "coffee/coldbrew/../..") => 0;
  1625. lfs_dir_close(&lfs, &dir) => 0;
  1626. lfs_dir_open(&lfs, &dir, "coffee/turkish/../../..") => LFS_ERR_INVAL;
  1627. lfs_dir_open(&lfs, &dir, "coffee/tubruk/../../../..") => LFS_ERR_INVAL;
  1628. lfs_dir_open(&lfs, &dir, "coffee/vietnamese/../../../../..") => LFS_ERR_INVAL;
  1629. lfs_dir_open(&lfs, &dir, "coffee/thai/../../../../../..") => LFS_ERR_INVAL;
  1630. // rename paths
  1631. lfs_mkdir(&lfs, "espresso") => 0;
  1632. // bad source
  1633. lfs_rename(&lfs,
  1634. "coffee/drip/../../../../../..",
  1635. "espresso/espresso") => LFS_ERR_INVAL;
  1636. lfs_rename(&lfs,
  1637. "coffee/coldbrew/../../../../..",
  1638. "espresso/americano") => LFS_ERR_INVAL;
  1639. lfs_rename(&lfs,
  1640. "coffee/turkish/../../../..",
  1641. "espresso/macchiato") => LFS_ERR_INVAL;
  1642. lfs_rename(&lfs,
  1643. "coffee/tubruk/../../..",
  1644. "espresso/latte") => LFS_ERR_INVAL;
  1645. lfs_rename(&lfs,
  1646. "coffee/vietnamese/../..",
  1647. "espresso/cappuccino") => LFS_ERR_INVAL;
  1648. // this one works
  1649. lfs_rename(&lfs,
  1650. "coffee/thai/..",
  1651. "espresso/mocha") => 0;
  1652. lfs_rename(&lfs,
  1653. "espresso/mocha",
  1654. "coffee") => 0;
  1655. // bad destination
  1656. if (DIR) {
  1657. // this one works
  1658. lfs_rename(&lfs,
  1659. "coffee/drip",
  1660. "espresso/espresso/..") => 0;
  1661. lfs_rename(&lfs,
  1662. "espresso",
  1663. "coffee/drip") => 0;
  1664. } else {
  1665. lfs_rename(&lfs,
  1666. "coffee/drip",
  1667. "espresso/espresso/..") => LFS_ERR_ISDIR;
  1668. }
  1669. lfs_rename(&lfs,
  1670. "coffee/coldbrew",
  1671. "espresso/americano/../..") => LFS_ERR_INVAL;
  1672. lfs_rename(&lfs,
  1673. "coffee/turkish",
  1674. "espresso/macchiato/../../..") => LFS_ERR_INVAL;
  1675. lfs_rename(&lfs,
  1676. "coffee/tubruk",
  1677. "espresso/latte/../../../..") => LFS_ERR_INVAL;
  1678. lfs_rename(&lfs,
  1679. "coffee/vietnamese",
  1680. "espresso/cappuccino/../../../../..") => LFS_ERR_INVAL;
  1681. lfs_rename(&lfs,
  1682. "coffee/thai",
  1683. "espresso/mocha/../../../../../..") => LFS_ERR_INVAL;
  1684. // bad source and bad destination
  1685. lfs_rename(&lfs,
  1686. "coffee/drip/../../../../../..",
  1687. "espresso/espresso/..") => LFS_ERR_INVAL;
  1688. lfs_rename(&lfs,
  1689. "coffee/coldbrew/../../../../..",
  1690. "espresso/americano/../..") => LFS_ERR_INVAL;
  1691. lfs_rename(&lfs,
  1692. "coffee/turkish/../../../..",
  1693. "espresso/macchiato/../../..") => LFS_ERR_INVAL;
  1694. lfs_rename(&lfs,
  1695. "coffee/tubruk/../../..",
  1696. "espresso/latte/../../../..") => LFS_ERR_INVAL;
  1697. lfs_rename(&lfs,
  1698. "coffee/vietnamese/../..",
  1699. "espresso/cappuccino/../../../../..") => LFS_ERR_INVAL;
  1700. lfs_rename(&lfs,
  1701. "coffee/thai/..",
  1702. "espresso/mocha/../../../../../..") => LFS_ERR_INVAL;
  1703. // remove paths
  1704. lfs_remove(&lfs, "coffee/drip/..") => LFS_ERR_NOTEMPTY;
  1705. lfs_remove(&lfs, "coffee/coldbrew/../..") => LFS_ERR_INVAL;
  1706. lfs_remove(&lfs, "coffee/turkish/../../..") => LFS_ERR_INVAL;
  1707. lfs_remove(&lfs, "coffee/tubruk/../../../..") => LFS_ERR_INVAL;
  1708. lfs_remove(&lfs, "coffee/vietnamese/../../../../..") => LFS_ERR_INVAL;
  1709. lfs_remove(&lfs, "coffee/thai/../../../../../..") => LFS_ERR_INVAL;
  1710. // stat paths
  1711. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  1712. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  1713. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  1714. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  1715. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  1716. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  1717. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  1718. assert(strcmp(info.name, "drip") == 0);
  1719. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1720. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  1721. assert(strcmp(info.name, "coldbrew") == 0);
  1722. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1723. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  1724. assert(strcmp(info.name, "turkish") == 0);
  1725. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1726. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  1727. assert(strcmp(info.name, "tubruk") == 0);
  1728. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1729. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  1730. assert(strcmp(info.name, "vietnamese") == 0);
  1731. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1732. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  1733. assert(strcmp(info.name, "thai") == 0);
  1734. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1735. lfs_unmount(&lfs) => 0;
  1736. '''
  1737. # dot dot dot path tests
  1738. [cases.test_paths_dotdotdots]
  1739. defines.DIR = [false, true]
  1740. code = '''
  1741. lfs_t lfs;
  1742. lfs_format(&lfs, cfg) => 0;
  1743. lfs_mount(&lfs, cfg) => 0;
  1744. // create paths
  1745. lfs_mkdir(&lfs, "coffee") => 0;
  1746. lfs_mkdir(&lfs, "coffee/...") => 0;
  1747. if (DIR) {
  1748. lfs_mkdir(&lfs, "/coffee/.../drip") => 0;
  1749. lfs_mkdir(&lfs, "/coffee/.../coldbrew") => 0;
  1750. lfs_mkdir(&lfs, "/coffee/.../turkish") => 0;
  1751. lfs_mkdir(&lfs, "/coffee/.../tubruk") => 0;
  1752. lfs_mkdir(&lfs, "/coffee/.../vietnamese") => 0;
  1753. lfs_mkdir(&lfs, "/coffee/.../thai") => 0;
  1754. } else {
  1755. lfs_file_t file;
  1756. lfs_file_open(&lfs, &file, "/coffee/.../drip",
  1757. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1758. lfs_file_close(&lfs, &file) => 0;
  1759. lfs_file_open(&lfs, &file, "/coffee/.../coldbrew",
  1760. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1761. lfs_file_close(&lfs, &file) => 0;
  1762. lfs_file_open(&lfs, &file, "/coffee/.../turkish",
  1763. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1764. lfs_file_close(&lfs, &file) => 0;
  1765. lfs_file_open(&lfs, &file, "/coffee/.../tubruk",
  1766. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1767. lfs_file_close(&lfs, &file) => 0;
  1768. lfs_file_open(&lfs, &file, "/coffee/.../vietnamese",
  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/.../thai",
  1772. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1773. lfs_file_close(&lfs, &file) => 0;
  1774. }
  1775. // stat paths
  1776. struct lfs_info info;
  1777. lfs_stat(&lfs, "/coffee/.../drip", &info) => 0;
  1778. assert(strcmp(info.name, "drip") == 0);
  1779. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1780. lfs_stat(&lfs, "/coffee/.../coldbrew", &info) => 0;
  1781. assert(strcmp(info.name, "coldbrew") == 0);
  1782. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1783. lfs_stat(&lfs, "/coffee/.../turkish", &info) => 0;
  1784. assert(strcmp(info.name, "turkish") == 0);
  1785. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1786. lfs_stat(&lfs, "/coffee/.../tubruk", &info) => 0;
  1787. assert(strcmp(info.name, "tubruk") == 0);
  1788. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1789. lfs_stat(&lfs, "/coffee/.../vietnamese", &info) => 0;
  1790. assert(strcmp(info.name, "vietnamese") == 0);
  1791. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1792. lfs_stat(&lfs, "/coffee/.../thai", &info) => 0;
  1793. assert(strcmp(info.name, "thai") == 0);
  1794. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1795. // file open paths, only works on files!
  1796. if (DIR) {
  1797. lfs_file_t file;
  1798. lfs_file_open(&lfs, &file, "/coffee/.../drip",
  1799. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1800. lfs_file_open(&lfs, &file, "/coffee/.../coldbrew",
  1801. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1802. lfs_file_open(&lfs, &file, "/coffee/.../turkish",
  1803. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1804. lfs_file_open(&lfs, &file, "/coffee/.../tubruk",
  1805. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1806. lfs_file_open(&lfs, &file, "/coffee/.../vietnamese",
  1807. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1808. lfs_file_open(&lfs, &file, "/coffee/.../thai",
  1809. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1810. } else {
  1811. lfs_file_t file;
  1812. lfs_file_open(&lfs, &file, "/coffee/.../drip",
  1813. LFS_O_RDONLY) => 0;
  1814. lfs_file_close(&lfs, &file) => 0;
  1815. lfs_file_open(&lfs, &file, "/coffee/.../coldbrew",
  1816. LFS_O_RDONLY) => 0;
  1817. lfs_file_close(&lfs, &file) => 0;
  1818. lfs_file_open(&lfs, &file, "/coffee/.../turkish",
  1819. LFS_O_RDONLY) => 0;
  1820. lfs_file_close(&lfs, &file) => 0;
  1821. lfs_file_open(&lfs, &file, "/coffee/.../tubruk",
  1822. LFS_O_RDONLY) => 0;
  1823. lfs_file_close(&lfs, &file) => 0;
  1824. lfs_file_open(&lfs, &file, "/coffee/.../vietnamese",
  1825. LFS_O_RDONLY) => 0;
  1826. lfs_file_close(&lfs, &file) => 0;
  1827. lfs_file_open(&lfs, &file, "/coffee/.../thai",
  1828. LFS_O_RDONLY) => 0;
  1829. lfs_file_close(&lfs, &file) => 0;
  1830. }
  1831. // dir open paths, only works on dirs!
  1832. if (DIR) {
  1833. lfs_dir_t dir;
  1834. lfs_dir_open(&lfs, &dir, "/coffee/.../drip") => 0;
  1835. lfs_dir_close(&lfs, &dir) => 0;
  1836. lfs_dir_open(&lfs, &dir, "/coffee/.../coldbrew") => 0;
  1837. lfs_dir_close(&lfs, &dir) => 0;
  1838. lfs_dir_open(&lfs, &dir, "/coffee/.../turkish") => 0;
  1839. lfs_dir_close(&lfs, &dir) => 0;
  1840. lfs_dir_open(&lfs, &dir, "/coffee/.../tubruk") => 0;
  1841. lfs_dir_close(&lfs, &dir) => 0;
  1842. lfs_dir_open(&lfs, &dir, "/coffee/.../vietnamese") => 0;
  1843. lfs_dir_close(&lfs, &dir) => 0;
  1844. lfs_dir_open(&lfs, &dir, "/coffee/.../thai") => 0;
  1845. lfs_dir_close(&lfs, &dir) => 0;
  1846. } else {
  1847. lfs_dir_t dir;
  1848. lfs_dir_open(&lfs, &dir, "/coffee/.../drip") => LFS_ERR_NOTDIR;
  1849. lfs_dir_open(&lfs, &dir, "/coffee/.../coldbrew") => LFS_ERR_NOTDIR;
  1850. lfs_dir_open(&lfs, &dir, "/coffee/.../turkish") => LFS_ERR_NOTDIR;
  1851. lfs_dir_open(&lfs, &dir, "/coffee/.../tubruk") => LFS_ERR_NOTDIR;
  1852. lfs_dir_open(&lfs, &dir, "/coffee/.../vietnamese") => LFS_ERR_NOTDIR;
  1853. lfs_dir_open(&lfs, &dir, "/coffee/.../thai") => LFS_ERR_NOTDIR;
  1854. }
  1855. // rename paths
  1856. lfs_mkdir(&lfs, "espresso") => 0;
  1857. lfs_mkdir(&lfs, "espresso/...") => 0;
  1858. lfs_rename(&lfs,
  1859. "/coffee/.../drip",
  1860. "/espresso/.../espresso") => 0;
  1861. lfs_rename(&lfs,
  1862. "/coffee/.../coldbrew",
  1863. "/espresso/.../americano") => 0;
  1864. lfs_rename(&lfs,
  1865. "/coffee/.../turkish",
  1866. "/espresso/.../macchiato") => 0;
  1867. lfs_rename(&lfs,
  1868. "/coffee/.../tubruk",
  1869. "/espresso/.../latte") => 0;
  1870. lfs_rename(&lfs,
  1871. "/coffee/.../vietnamese",
  1872. "/espresso/.../cappuccino") => 0;
  1873. lfs_rename(&lfs,
  1874. "/coffee/.../thai",
  1875. "/espresso/.../mocha") => 0;
  1876. // stat paths
  1877. lfs_stat(&lfs, "/espresso/.../espresso", &info) => 0;
  1878. assert(strcmp(info.name, "espresso") == 0);
  1879. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1880. lfs_stat(&lfs, "/espresso/.../americano", &info) => 0;
  1881. assert(strcmp(info.name, "americano") == 0);
  1882. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1883. lfs_stat(&lfs, "/espresso/.../macchiato", &info) => 0;
  1884. assert(strcmp(info.name, "macchiato") == 0);
  1885. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1886. lfs_stat(&lfs, "/espresso/.../latte", &info) => 0;
  1887. assert(strcmp(info.name, "latte") == 0);
  1888. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1889. lfs_stat(&lfs, "/espresso/.../cappuccino", &info) => 0;
  1890. assert(strcmp(info.name, "cappuccino") == 0);
  1891. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1892. lfs_stat(&lfs, "/espresso/.../mocha", &info) => 0;
  1893. assert(strcmp(info.name, "mocha") == 0);
  1894. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1895. lfs_stat(&lfs, "coffee/.../drip", &info) => LFS_ERR_NOENT;
  1896. lfs_stat(&lfs, "coffee/.../coldbrew", &info) => LFS_ERR_NOENT;
  1897. lfs_stat(&lfs, "coffee/.../turkish", &info) => LFS_ERR_NOENT;
  1898. lfs_stat(&lfs, "coffee/.../tubruk", &info) => LFS_ERR_NOENT;
  1899. lfs_stat(&lfs, "coffee/.../vietnamese", &info) => LFS_ERR_NOENT;
  1900. lfs_stat(&lfs, "coffee/.../thai", &info) => LFS_ERR_NOENT;
  1901. // remove paths
  1902. lfs_remove(&lfs, "/espresso/.../espresso") => 0;
  1903. lfs_remove(&lfs, "/espresso/.../americano") => 0;
  1904. lfs_remove(&lfs, "/espresso/.../macchiato") => 0;
  1905. lfs_remove(&lfs, "/espresso/.../latte") => 0;
  1906. lfs_remove(&lfs, "/espresso/.../cappuccino") => 0;
  1907. lfs_remove(&lfs, "/espresso/.../mocha") => 0;
  1908. // stat paths
  1909. lfs_stat(&lfs, "/espresso/.../espresso", &info) => LFS_ERR_NOENT;
  1910. lfs_stat(&lfs, "/espresso/.../americano", &info) => LFS_ERR_NOENT;
  1911. lfs_stat(&lfs, "/espresso/.../macchiato", &info) => LFS_ERR_NOENT;
  1912. lfs_stat(&lfs, "/espresso/.../latte", &info) => LFS_ERR_NOENT;
  1913. lfs_stat(&lfs, "/espresso/.../cappuccino", &info) => LFS_ERR_NOENT;
  1914. lfs_stat(&lfs, "/espresso/.../mocha", &info) => LFS_ERR_NOENT;
  1915. lfs_unmount(&lfs) => 0;
  1916. '''
  1917. # leading dot path test
  1918. [cases.test_paths_leading_dots]
  1919. defines.DIR = [false, true]
  1920. code = '''
  1921. lfs_t lfs;
  1922. lfs_format(&lfs, cfg) => 0;
  1923. lfs_mount(&lfs, cfg) => 0;
  1924. // create paths
  1925. lfs_mkdir(&lfs, "coffee") => 0;
  1926. if (DIR) {
  1927. lfs_mkdir(&lfs, "/coffee/.drip") => 0;
  1928. lfs_mkdir(&lfs, "/coffee/..coldbrew") => 0;
  1929. lfs_mkdir(&lfs, "/coffee/...turkish") => 0;
  1930. lfs_mkdir(&lfs, "/coffee/....tubruk") => 0;
  1931. lfs_mkdir(&lfs, "/coffee/.....vietnamese") => 0;
  1932. lfs_mkdir(&lfs, "/coffee/......thai") => 0;
  1933. } else {
  1934. lfs_file_t file;
  1935. lfs_file_open(&lfs, &file, "/coffee/.drip",
  1936. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1937. lfs_file_close(&lfs, &file) => 0;
  1938. lfs_file_open(&lfs, &file, "/coffee/..coldbrew",
  1939. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1940. lfs_file_close(&lfs, &file) => 0;
  1941. lfs_file_open(&lfs, &file, "/coffee/...turkish",
  1942. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1943. lfs_file_close(&lfs, &file) => 0;
  1944. lfs_file_open(&lfs, &file, "/coffee/....tubruk",
  1945. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1946. lfs_file_close(&lfs, &file) => 0;
  1947. lfs_file_open(&lfs, &file, "/coffee/.....vietnamese",
  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/......thai",
  1951. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1952. lfs_file_close(&lfs, &file) => 0;
  1953. }
  1954. // stat paths
  1955. struct lfs_info info;
  1956. lfs_stat(&lfs, "/coffee/.drip", &info) => 0;
  1957. assert(strcmp(info.name, ".drip") == 0);
  1958. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1959. lfs_stat(&lfs, "/coffee/..coldbrew", &info) => 0;
  1960. assert(strcmp(info.name, "..coldbrew") == 0);
  1961. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1962. lfs_stat(&lfs, "/coffee/...turkish", &info) => 0;
  1963. assert(strcmp(info.name, "...turkish") == 0);
  1964. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1965. lfs_stat(&lfs, "/coffee/....tubruk", &info) => 0;
  1966. assert(strcmp(info.name, "....tubruk") == 0);
  1967. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1968. lfs_stat(&lfs, "/coffee/.....vietnamese", &info) => 0;
  1969. assert(strcmp(info.name, ".....vietnamese") == 0);
  1970. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1971. lfs_stat(&lfs, "/coffee/......thai", &info) => 0;
  1972. assert(strcmp(info.name, "......thai") == 0);
  1973. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1974. // file open paths, only works on files!
  1975. if (DIR) {
  1976. lfs_file_t file;
  1977. lfs_file_open(&lfs, &file, "/coffee/.drip",
  1978. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1979. lfs_file_open(&lfs, &file, "/coffee/..coldbrew",
  1980. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1981. lfs_file_open(&lfs, &file, "/coffee/...turkish",
  1982. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1983. lfs_file_open(&lfs, &file, "/coffee/....tubruk",
  1984. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1985. lfs_file_open(&lfs, &file, "/coffee/.....vietnamese",
  1986. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1987. lfs_file_open(&lfs, &file, "/coffee/......thai",
  1988. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1989. } else {
  1990. lfs_file_t file;
  1991. lfs_file_open(&lfs, &file, "/coffee/.drip",
  1992. LFS_O_RDONLY) => 0;
  1993. lfs_file_close(&lfs, &file) => 0;
  1994. lfs_file_open(&lfs, &file, "/coffee/..coldbrew",
  1995. LFS_O_RDONLY) => 0;
  1996. lfs_file_close(&lfs, &file) => 0;
  1997. lfs_file_open(&lfs, &file, "/coffee/...turkish",
  1998. LFS_O_RDONLY) => 0;
  1999. lfs_file_close(&lfs, &file) => 0;
  2000. lfs_file_open(&lfs, &file, "/coffee/....tubruk",
  2001. LFS_O_RDONLY) => 0;
  2002. lfs_file_close(&lfs, &file) => 0;
  2003. lfs_file_open(&lfs, &file, "/coffee/.....vietnamese",
  2004. LFS_O_RDONLY) => 0;
  2005. lfs_file_close(&lfs, &file) => 0;
  2006. lfs_file_open(&lfs, &file, "/coffee/......thai",
  2007. LFS_O_RDONLY) => 0;
  2008. lfs_file_close(&lfs, &file) => 0;
  2009. }
  2010. // dir open paths, only works on dirs!
  2011. if (DIR) {
  2012. lfs_dir_t dir;
  2013. lfs_dir_open(&lfs, &dir, "/coffee/.drip") => 0;
  2014. lfs_dir_close(&lfs, &dir) => 0;
  2015. lfs_dir_open(&lfs, &dir, "/coffee/..coldbrew") => 0;
  2016. lfs_dir_close(&lfs, &dir) => 0;
  2017. lfs_dir_open(&lfs, &dir, "/coffee/...turkish") => 0;
  2018. lfs_dir_close(&lfs, &dir) => 0;
  2019. lfs_dir_open(&lfs, &dir, "/coffee/....tubruk") => 0;
  2020. lfs_dir_close(&lfs, &dir) => 0;
  2021. lfs_dir_open(&lfs, &dir, "/coffee/.....vietnamese") => 0;
  2022. lfs_dir_close(&lfs, &dir) => 0;
  2023. lfs_dir_open(&lfs, &dir, "/coffee/......thai") => 0;
  2024. lfs_dir_close(&lfs, &dir) => 0;
  2025. } else {
  2026. lfs_dir_t dir;
  2027. lfs_dir_open(&lfs, &dir, "/coffee/.drip") => LFS_ERR_NOTDIR;
  2028. lfs_dir_open(&lfs, &dir, "/coffee/..coldbrew") => LFS_ERR_NOTDIR;
  2029. lfs_dir_open(&lfs, &dir, "/coffee/...turkish") => LFS_ERR_NOTDIR;
  2030. lfs_dir_open(&lfs, &dir, "/coffee/....tubruk") => LFS_ERR_NOTDIR;
  2031. lfs_dir_open(&lfs, &dir, "/coffee/.....vietnamese") => LFS_ERR_NOTDIR;
  2032. lfs_dir_open(&lfs, &dir, "/coffee/......thai") => LFS_ERR_NOTDIR;
  2033. }
  2034. // rename paths
  2035. lfs_mkdir(&lfs, "espresso") => 0;
  2036. lfs_rename(&lfs,
  2037. "/coffee/.drip",
  2038. "/espresso/.espresso") => 0;
  2039. lfs_rename(&lfs,
  2040. "/coffee/..coldbrew",
  2041. "/espresso/..americano") => 0;
  2042. lfs_rename(&lfs,
  2043. "/coffee/...turkish",
  2044. "/espresso/...macchiato") => 0;
  2045. lfs_rename(&lfs,
  2046. "/coffee/....tubruk",
  2047. "/espresso/....latte") => 0;
  2048. lfs_rename(&lfs,
  2049. "/coffee/.....vietnamese",
  2050. "/espresso/.....cappuccino") => 0;
  2051. lfs_rename(&lfs,
  2052. "/coffee/......thai",
  2053. "/espresso/......mocha") => 0;
  2054. // stat paths
  2055. lfs_stat(&lfs, "/espresso/.espresso", &info) => 0;
  2056. assert(strcmp(info.name, ".espresso") == 0);
  2057. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2058. lfs_stat(&lfs, "/espresso/..americano", &info) => 0;
  2059. assert(strcmp(info.name, "..americano") == 0);
  2060. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2061. lfs_stat(&lfs, "/espresso/...macchiato", &info) => 0;
  2062. assert(strcmp(info.name, "...macchiato") == 0);
  2063. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2064. lfs_stat(&lfs, "/espresso/....latte", &info) => 0;
  2065. assert(strcmp(info.name, "....latte") == 0);
  2066. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2067. lfs_stat(&lfs, "/espresso/.....cappuccino", &info) => 0;
  2068. assert(strcmp(info.name, ".....cappuccino") == 0);
  2069. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2070. lfs_stat(&lfs, "/espresso/......mocha", &info) => 0;
  2071. assert(strcmp(info.name, "......mocha") == 0);
  2072. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2073. lfs_stat(&lfs, "coffee/.drip", &info) => LFS_ERR_NOENT;
  2074. lfs_stat(&lfs, "coffee/..coldbrew", &info) => LFS_ERR_NOENT;
  2075. lfs_stat(&lfs, "coffee/...turkish", &info) => LFS_ERR_NOENT;
  2076. lfs_stat(&lfs, "coffee/....tubruk", &info) => LFS_ERR_NOENT;
  2077. lfs_stat(&lfs, "coffee/.....vietnamese", &info) => LFS_ERR_NOENT;
  2078. lfs_stat(&lfs, "coffee/......thai", &info) => LFS_ERR_NOENT;
  2079. // remove paths
  2080. lfs_remove(&lfs, "/espresso/.espresso") => 0;
  2081. lfs_remove(&lfs, "/espresso/..americano") => 0;
  2082. lfs_remove(&lfs, "/espresso/...macchiato") => 0;
  2083. lfs_remove(&lfs, "/espresso/....latte") => 0;
  2084. lfs_remove(&lfs, "/espresso/.....cappuccino") => 0;
  2085. lfs_remove(&lfs, "/espresso/......mocha") => 0;
  2086. // stat paths
  2087. lfs_stat(&lfs, "/espresso/.espresso", &info) => LFS_ERR_NOENT;
  2088. lfs_stat(&lfs, "/espresso/..americano", &info) => LFS_ERR_NOENT;
  2089. lfs_stat(&lfs, "/espresso/...macchiato", &info) => LFS_ERR_NOENT;
  2090. lfs_stat(&lfs, "/espresso/....latte", &info) => LFS_ERR_NOENT;
  2091. lfs_stat(&lfs, "/espresso/.....cappuccino", &info) => LFS_ERR_NOENT;
  2092. lfs_stat(&lfs, "/espresso/......mocha", &info) => LFS_ERR_NOENT;
  2093. lfs_unmount(&lfs) => 0;
  2094. '''
  2095. # root dot dot path test
  2096. [cases.test_paths_root_dotdots]
  2097. defines.DIR = [false, true]
  2098. code = '''
  2099. lfs_t lfs;
  2100. lfs_format(&lfs, cfg) => 0;
  2101. lfs_mount(&lfs, cfg) => 0;
  2102. // create paths
  2103. lfs_mkdir(&lfs, "no") => 0;
  2104. lfs_mkdir(&lfs, "coffee") => 0;
  2105. if (DIR) {
  2106. lfs_mkdir(&lfs, "/../coffee/drip") => LFS_ERR_INVAL;
  2107. lfs_mkdir(&lfs, "/../../coffee/coldbrew") => LFS_ERR_INVAL;
  2108. lfs_mkdir(&lfs, "/../../../coffee/turkish") => LFS_ERR_INVAL;
  2109. lfs_mkdir(&lfs, "/no/../../coffee/tubruk") => LFS_ERR_INVAL;
  2110. lfs_mkdir(&lfs, "/no/../../../coffee/vietnamese") => LFS_ERR_INVAL;
  2111. lfs_mkdir(&lfs, "/no/../../../../coffee/thai") => LFS_ERR_INVAL;
  2112. } else {
  2113. lfs_file_t file;
  2114. lfs_file_open(&lfs, &file, "/../coffee/drip",
  2115. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_INVAL;
  2116. lfs_file_open(&lfs, &file, "/../../coffee/coldbrew",
  2117. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_INVAL;
  2118. lfs_file_open(&lfs, &file, "/../../../coffee/turkish",
  2119. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_INVAL;
  2120. lfs_file_open(&lfs, &file, "/no/../../coffee/tubruk",
  2121. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_INVAL;
  2122. lfs_file_open(&lfs, &file, "/no/../../../coffee/vietnamese",
  2123. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_INVAL;
  2124. lfs_file_open(&lfs, &file, "/no/../../../../coffee/thai",
  2125. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_INVAL;
  2126. }
  2127. // ok, actually create paths
  2128. if (DIR) {
  2129. lfs_mkdir(&lfs, "coffee/drip") => 0;
  2130. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  2131. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  2132. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  2133. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  2134. lfs_mkdir(&lfs, "coffee/thai") => 0;
  2135. } else {
  2136. lfs_file_t file;
  2137. lfs_file_open(&lfs, &file, "coffee/drip",
  2138. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2139. lfs_file_close(&lfs, &file) => 0;
  2140. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  2141. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2142. lfs_file_close(&lfs, &file) => 0;
  2143. lfs_file_open(&lfs, &file, "coffee/turkish",
  2144. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2145. lfs_file_close(&lfs, &file) => 0;
  2146. lfs_file_open(&lfs, &file, "coffee/tubruk",
  2147. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2148. lfs_file_close(&lfs, &file) => 0;
  2149. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  2150. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2151. lfs_file_close(&lfs, &file) => 0;
  2152. lfs_file_open(&lfs, &file, "coffee/thai",
  2153. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2154. lfs_file_close(&lfs, &file) => 0;
  2155. }
  2156. // stat paths
  2157. struct lfs_info info;
  2158. lfs_stat(&lfs, "/no/../../../../coffee/drip", &info) => LFS_ERR_INVAL;
  2159. lfs_stat(&lfs, "/no/../../../coffee/coldbrew", &info) => LFS_ERR_INVAL;
  2160. lfs_stat(&lfs, "/no/../../coffee/turkish", &info) => LFS_ERR_INVAL;
  2161. lfs_stat(&lfs, "/../../../coffee/tubruk", &info) => LFS_ERR_INVAL;
  2162. lfs_stat(&lfs, "/../../coffee/vietnamese", &info) => LFS_ERR_INVAL;
  2163. lfs_stat(&lfs, "/../coffee/thai", &info) => LFS_ERR_INVAL;
  2164. // file open paths, only works on files!
  2165. lfs_file_t file;
  2166. lfs_file_open(&lfs, &file, "/../coffee/drip",
  2167. LFS_O_RDONLY) => LFS_ERR_INVAL;
  2168. lfs_file_open(&lfs, &file, "/../../coffee/coldbrew",
  2169. LFS_O_RDONLY) => LFS_ERR_INVAL;
  2170. lfs_file_open(&lfs, &file, "/../../../coffee/turkish",
  2171. LFS_O_RDONLY) => LFS_ERR_INVAL;
  2172. lfs_file_open(&lfs, &file, "/no/../../coffee/tubruk",
  2173. LFS_O_RDONLY) => LFS_ERR_INVAL;
  2174. lfs_file_open(&lfs, &file, "/no/../../../coffee/vietnamese",
  2175. LFS_O_RDONLY) => LFS_ERR_INVAL;
  2176. lfs_file_open(&lfs, &file, "/no/../../../../coffee/thai",
  2177. LFS_O_RDONLY) => LFS_ERR_INVAL;
  2178. // dir open paths, only works on dirs!
  2179. lfs_dir_t dir;
  2180. lfs_dir_open(&lfs, &dir, "/../coffee/drip") => LFS_ERR_INVAL;
  2181. lfs_dir_open(&lfs, &dir, "/../../coffee/coldbrew") => LFS_ERR_INVAL;
  2182. lfs_dir_open(&lfs, &dir, "/../../../coffee/turkish") => LFS_ERR_INVAL;
  2183. lfs_dir_open(&lfs, &dir, "/no/../../coffee/tubruk") => LFS_ERR_INVAL;
  2184. lfs_dir_open(&lfs, &dir, "/no/../../../coffee/vietnamese") => LFS_ERR_INVAL;
  2185. lfs_dir_open(&lfs, &dir, "/no/../../../../coffee/thai") => LFS_ERR_INVAL;
  2186. // rename paths
  2187. lfs_mkdir(&lfs, "espresso") => 0;
  2188. // bad source
  2189. lfs_rename(&lfs,
  2190. "/no/../../../../coffee/drip",
  2191. "espresso/espresso") => LFS_ERR_INVAL;
  2192. lfs_rename(&lfs,
  2193. "/no/../../../coffee/coldbrew",
  2194. "espresso/americano") => LFS_ERR_INVAL;
  2195. lfs_rename(&lfs,
  2196. "/no/../../coffee/turkish",
  2197. "espresso/macchiato") => LFS_ERR_INVAL;
  2198. lfs_rename(&lfs,
  2199. "/../../../coffee/tubruk",
  2200. "espresso/latte") => LFS_ERR_INVAL;
  2201. lfs_rename(&lfs,
  2202. "/../../coffee/vietnamese",
  2203. "espresso/cappuccino") => LFS_ERR_INVAL;
  2204. lfs_rename(&lfs,
  2205. "/../coffee/thai",
  2206. "espresso/mocha") => LFS_ERR_INVAL;
  2207. // bad destination
  2208. lfs_rename(&lfs,
  2209. "coffee/drip",
  2210. "/../espresso/espresso") => LFS_ERR_INVAL;
  2211. lfs_rename(&lfs,
  2212. "coffee/coldbrew",
  2213. "/../../espresso/americano") => LFS_ERR_INVAL;
  2214. lfs_rename(&lfs,
  2215. "coffee/turkish",
  2216. "/../../../espresso/macchiato") => LFS_ERR_INVAL;
  2217. lfs_rename(&lfs,
  2218. "coffee/tubruk",
  2219. "/no/../../espresso/latte") => LFS_ERR_INVAL;
  2220. lfs_rename(&lfs,
  2221. "coffee/vietnamese",
  2222. "/no/../../../espresso/cappuccino") => LFS_ERR_INVAL;
  2223. lfs_rename(&lfs,
  2224. "coffee/thai",
  2225. "/no/../../../../espresso/mocha") => LFS_ERR_INVAL;
  2226. // bad source and bad destination
  2227. lfs_rename(&lfs,
  2228. "/no/../../../../coffee/drip",
  2229. "/../espresso/espresso") => LFS_ERR_INVAL;
  2230. lfs_rename(&lfs,
  2231. "/no/../../../coffee/coldbrew",
  2232. "/../../espresso/americano") => LFS_ERR_INVAL;
  2233. lfs_rename(&lfs,
  2234. "/no/../../coffee/turkish",
  2235. "/../../../espresso/macchiato") => LFS_ERR_INVAL;
  2236. lfs_rename(&lfs,
  2237. "/../../../coffee/tubruk",
  2238. "/no/../../espresso/latte") => LFS_ERR_INVAL;
  2239. lfs_rename(&lfs,
  2240. "/../../coffee/vietnamese",
  2241. "/no/../../../espresso/cappuccino") => LFS_ERR_INVAL;
  2242. lfs_rename(&lfs,
  2243. "/../coffee/thai",
  2244. "/no/../../../../espresso/mocha") => LFS_ERR_INVAL;
  2245. // here's a weird one, what happens if our rename is also a noop?
  2246. lfs_rename(&lfs,
  2247. "/../coffee/drip",
  2248. "/../espresso/espresso") => LFS_ERR_INVAL;
  2249. lfs_rename(&lfs,
  2250. "/../../coffee/coldbrew",
  2251. "/../../espresso/americano") => LFS_ERR_INVAL;
  2252. lfs_rename(&lfs,
  2253. "/../../../coffee/turkish",
  2254. "/../../../espresso/macchiato") => LFS_ERR_INVAL;
  2255. lfs_rename(&lfs,
  2256. "/no/../../coffee/tubruk",
  2257. "/no/../../espresso/latte") => LFS_ERR_INVAL;
  2258. lfs_rename(&lfs,
  2259. "/no/../../../coffee/vietnamese",
  2260. "/no/../../../espresso/cappuccino") => LFS_ERR_INVAL;
  2261. lfs_rename(&lfs,
  2262. "/no/../../../../coffee/thai",
  2263. "/no/../../../../espresso/mocha") => LFS_ERR_INVAL;
  2264. // remove paths
  2265. lfs_remove(&lfs, "/../espresso/espresso") => LFS_ERR_INVAL;
  2266. lfs_remove(&lfs, "/../../espresso/americano") => LFS_ERR_INVAL;
  2267. lfs_remove(&lfs, "/../../../espresso/macchiato") => LFS_ERR_INVAL;
  2268. lfs_remove(&lfs, "/no/../../espresso/latte") => LFS_ERR_INVAL;
  2269. lfs_remove(&lfs, "/no/../../../espresso/cappuccino") => LFS_ERR_INVAL;
  2270. lfs_remove(&lfs, "/no/../../../../espresso/mocha") => LFS_ERR_INVAL;
  2271. // stat paths
  2272. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  2273. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  2274. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  2275. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  2276. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  2277. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  2278. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  2279. assert(strcmp(info.name, "drip") == 0);
  2280. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2281. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  2282. assert(strcmp(info.name, "coldbrew") == 0);
  2283. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2284. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  2285. assert(strcmp(info.name, "turkish") == 0);
  2286. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2287. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  2288. assert(strcmp(info.name, "tubruk") == 0);
  2289. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2290. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  2291. assert(strcmp(info.name, "vietnamese") == 0);
  2292. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2293. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  2294. assert(strcmp(info.name, "thai") == 0);
  2295. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2296. lfs_unmount(&lfs) => 0;
  2297. '''
  2298. # trailing noent tests
  2299. [cases.test_paths_noent]
  2300. defines.DIR = [false, true]
  2301. code = '''
  2302. lfs_t lfs;
  2303. lfs_format(&lfs, cfg) => 0;
  2304. lfs_mount(&lfs, cfg) => 0;
  2305. // create paths
  2306. lfs_mkdir(&lfs, "coffee") => 0;
  2307. if (DIR) {
  2308. lfs_mkdir(&lfs, "coffee/drip") => 0;
  2309. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  2310. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  2311. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  2312. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  2313. lfs_mkdir(&lfs, "coffee/thai") => 0;
  2314. } else {
  2315. lfs_file_t file;
  2316. lfs_file_open(&lfs, &file, "coffee/drip",
  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/coldbrew",
  2320. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2321. lfs_file_close(&lfs, &file) => 0;
  2322. lfs_file_open(&lfs, &file, "coffee/turkish",
  2323. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2324. lfs_file_close(&lfs, &file) => 0;
  2325. lfs_file_open(&lfs, &file, "coffee/tubruk",
  2326. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2327. lfs_file_close(&lfs, &file) => 0;
  2328. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  2329. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2330. lfs_file_close(&lfs, &file) => 0;
  2331. lfs_file_open(&lfs, &file, "coffee/thai",
  2332. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2333. lfs_file_close(&lfs, &file) => 0;
  2334. }
  2335. // stat paths
  2336. struct lfs_info info;
  2337. lfs_stat(&lfs, "coffee/_rip", &info) => LFS_ERR_NOENT;
  2338. lfs_stat(&lfs, "coffee/c_ldbrew", &info) => LFS_ERR_NOENT;
  2339. lfs_stat(&lfs, "coffee/tu_kish", &info) => LFS_ERR_NOENT;
  2340. lfs_stat(&lfs, "coffee/tub_uk", &info) => LFS_ERR_NOENT;
  2341. lfs_stat(&lfs, "coffee/_vietnamese", &info) => LFS_ERR_NOENT;
  2342. lfs_stat(&lfs, "coffee/thai_", &info) => LFS_ERR_NOENT;
  2343. // file open paths, only works on files!
  2344. lfs_file_t file;
  2345. lfs_file_open(&lfs, &file, "coffee/_rip",
  2346. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2347. lfs_file_open(&lfs, &file, "coffee/c_ldbrew",
  2348. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2349. lfs_file_open(&lfs, &file, "coffee/tu_kish",
  2350. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2351. lfs_file_open(&lfs, &file, "coffee/tub_uk",
  2352. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2353. lfs_file_open(&lfs, &file, "coffee/_vietnamese",
  2354. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2355. lfs_file_open(&lfs, &file, "coffee/thai_",
  2356. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2357. // dir open paths, only works on dirs!
  2358. lfs_dir_t dir;
  2359. lfs_dir_open(&lfs, &dir, "coffee/_rip") => LFS_ERR_NOENT;
  2360. lfs_dir_open(&lfs, &dir, "coffee/c_ldbrew") => LFS_ERR_NOENT;
  2361. lfs_dir_open(&lfs, &dir, "coffee/tu_kish") => LFS_ERR_NOENT;
  2362. lfs_dir_open(&lfs, &dir, "coffee/tub_uk") => LFS_ERR_NOENT;
  2363. lfs_dir_open(&lfs, &dir, "coffee/_vietnamese") => LFS_ERR_NOENT;
  2364. lfs_dir_open(&lfs, &dir, "coffee/thai_") => LFS_ERR_NOENT;
  2365. // rename paths
  2366. lfs_mkdir(&lfs, "espresso") => 0;
  2367. lfs_rename(&lfs,
  2368. "coffee/_rip",
  2369. "espresso/espresso") => LFS_ERR_NOENT;
  2370. lfs_rename(&lfs,
  2371. "coffee/c_ldbrew",
  2372. "espresso/americano") => LFS_ERR_NOENT;
  2373. lfs_rename(&lfs,
  2374. "coffee/tu_kish",
  2375. "espresso/macchiato") => LFS_ERR_NOENT;
  2376. lfs_rename(&lfs,
  2377. "coffee/tub_uk",
  2378. "espresso/latte") => LFS_ERR_NOENT;
  2379. lfs_rename(&lfs,
  2380. "coffee/_vietnamese",
  2381. "espresso/cappuccino") => LFS_ERR_NOENT;
  2382. lfs_rename(&lfs,
  2383. "coffee/thai_",
  2384. "espresso/mocha") => LFS_ERR_NOENT;
  2385. // remove paths
  2386. lfs_remove(&lfs, "coffee/_rip") => LFS_ERR_NOENT;
  2387. lfs_remove(&lfs, "coffee/c_ldbrew") => LFS_ERR_NOENT;
  2388. lfs_remove(&lfs, "coffee/tu_kish") => LFS_ERR_NOENT;
  2389. lfs_remove(&lfs, "coffee/tub_uk") => LFS_ERR_NOENT;
  2390. lfs_remove(&lfs, "coffee/_vietnamese") => LFS_ERR_NOENT;
  2391. lfs_remove(&lfs, "coffee/thai_") => LFS_ERR_NOENT;
  2392. // stat paths
  2393. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  2394. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  2395. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  2396. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  2397. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  2398. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  2399. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  2400. assert(strcmp(info.name, "drip") == 0);
  2401. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2402. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  2403. assert(strcmp(info.name, "coldbrew") == 0);
  2404. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2405. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  2406. assert(strcmp(info.name, "turkish") == 0);
  2407. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2408. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  2409. assert(strcmp(info.name, "tubruk") == 0);
  2410. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2411. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  2412. assert(strcmp(info.name, "vietnamese") == 0);
  2413. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2414. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  2415. assert(strcmp(info.name, "thai") == 0);
  2416. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2417. lfs_unmount(&lfs) => 0;
  2418. '''
  2419. # parent noent tests
  2420. [cases.test_paths_noent_parent]
  2421. defines.DIR = [false, true]
  2422. code = '''
  2423. lfs_t lfs;
  2424. lfs_format(&lfs, cfg) => 0;
  2425. lfs_mount(&lfs, cfg) => 0;
  2426. // create paths
  2427. lfs_mkdir(&lfs, "coffee") => 0;
  2428. if (DIR) {
  2429. lfs_mkdir(&lfs, "_offee/drip") => LFS_ERR_NOENT;
  2430. lfs_mkdir(&lfs, "c_ffee/coldbrew") => LFS_ERR_NOENT;
  2431. lfs_mkdir(&lfs, "co_fee/turkish") => LFS_ERR_NOENT;
  2432. lfs_mkdir(&lfs, "cof_ee/tubruk") => LFS_ERR_NOENT;
  2433. lfs_mkdir(&lfs, "_coffee/vietnamese") => LFS_ERR_NOENT;
  2434. lfs_mkdir(&lfs, "coffee_/thai") => LFS_ERR_NOENT;
  2435. } else {
  2436. lfs_file_t file;
  2437. lfs_file_open(&lfs, &file, "_offee/drip",
  2438. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2439. lfs_file_open(&lfs, &file, "c_ffee/coldbrew",
  2440. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2441. lfs_file_open(&lfs, &file, "co_fee/turkish",
  2442. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2443. lfs_file_open(&lfs, &file, "cof_ee/tubruk",
  2444. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2445. lfs_file_open(&lfs, &file, "_coffee/vietnamese",
  2446. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2447. lfs_file_open(&lfs, &file, "coffee_/thai",
  2448. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2449. }
  2450. // ok, actually create paths
  2451. if (DIR) {
  2452. lfs_mkdir(&lfs, "coffee/drip") => 0;
  2453. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  2454. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  2455. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  2456. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  2457. lfs_mkdir(&lfs, "coffee/thai") => 0;
  2458. } else {
  2459. lfs_file_t file;
  2460. lfs_file_open(&lfs, &file, "coffee/drip",
  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/coldbrew",
  2464. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2465. lfs_file_close(&lfs, &file) => 0;
  2466. lfs_file_open(&lfs, &file, "coffee/turkish",
  2467. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2468. lfs_file_close(&lfs, &file) => 0;
  2469. lfs_file_open(&lfs, &file, "coffee/tubruk",
  2470. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2471. lfs_file_close(&lfs, &file) => 0;
  2472. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  2473. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2474. lfs_file_close(&lfs, &file) => 0;
  2475. lfs_file_open(&lfs, &file, "coffee/thai",
  2476. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2477. lfs_file_close(&lfs, &file) => 0;
  2478. }
  2479. // stat paths
  2480. struct lfs_info info;
  2481. lfs_stat(&lfs, "_offee/drip", &info) => LFS_ERR_NOENT;
  2482. lfs_stat(&lfs, "c_ffee/coldbrew", &info) => LFS_ERR_NOENT;
  2483. lfs_stat(&lfs, "co_fee/turkish", &info) => LFS_ERR_NOENT;
  2484. lfs_stat(&lfs, "cof_ee/tubruk", &info) => LFS_ERR_NOENT;
  2485. lfs_stat(&lfs, "_coffee/vietnamese", &info) => LFS_ERR_NOENT;
  2486. lfs_stat(&lfs, "coffee_/thai", &info) => LFS_ERR_NOENT;
  2487. // file open paths, only works on files!
  2488. lfs_file_t file;
  2489. lfs_file_open(&lfs, &file, "_offee/drip",
  2490. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2491. lfs_file_open(&lfs, &file, "c_ffee/coldbrew",
  2492. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2493. lfs_file_open(&lfs, &file, "co_fee/turkish",
  2494. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2495. lfs_file_open(&lfs, &file, "cof_ee/tubruk",
  2496. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2497. lfs_file_open(&lfs, &file, "_coffee/vietnamese",
  2498. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2499. lfs_file_open(&lfs, &file, "coffee_/thai",
  2500. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2501. // dir open paths, only works on dirs!
  2502. lfs_dir_t dir;
  2503. lfs_dir_open(&lfs, &dir, "_offee/drip") => LFS_ERR_NOENT;
  2504. lfs_dir_open(&lfs, &dir, "c_ffee/coldbrew") => LFS_ERR_NOENT;
  2505. lfs_dir_open(&lfs, &dir, "co_fee/turkish") => LFS_ERR_NOENT;
  2506. lfs_dir_open(&lfs, &dir, "cof_ee/tubruk") => LFS_ERR_NOENT;
  2507. lfs_dir_open(&lfs, &dir, "_coffee/vietnamese") => LFS_ERR_NOENT;
  2508. lfs_dir_open(&lfs, &dir, "coffee_/thai") => LFS_ERR_NOENT;
  2509. // rename paths
  2510. lfs_mkdir(&lfs, "espresso") => 0;
  2511. // bad source
  2512. lfs_rename(&lfs,
  2513. "_offee/drip",
  2514. "espresso/espresso") => LFS_ERR_NOENT;
  2515. lfs_rename(&lfs,
  2516. "c_ffee/coldbrew",
  2517. "espresso/americano") => LFS_ERR_NOENT;
  2518. lfs_rename(&lfs,
  2519. "co_fee/turkish",
  2520. "espresso/macchiato") => LFS_ERR_NOENT;
  2521. lfs_rename(&lfs,
  2522. "cof_ee/tubruk",
  2523. "espresso/latte") => LFS_ERR_NOENT;
  2524. lfs_rename(&lfs,
  2525. "_coffee/vietnamese",
  2526. "espresso/cappuccino") => LFS_ERR_NOENT;
  2527. lfs_rename(&lfs,
  2528. "coffee_/thai",
  2529. "espresso/mocha") => LFS_ERR_NOENT;
  2530. // bad destination
  2531. lfs_rename(&lfs,
  2532. "coffee/drip",
  2533. "_spresso/espresso") => LFS_ERR_NOENT;
  2534. lfs_rename(&lfs,
  2535. "coffee/coldbrew",
  2536. "e_presso/americano") => LFS_ERR_NOENT;
  2537. lfs_rename(&lfs,
  2538. "coffee/turkish",
  2539. "es_resso/macchiato") => LFS_ERR_NOENT;
  2540. lfs_rename(&lfs,
  2541. "coffee/tubruk",
  2542. "esp_esso/latte") => LFS_ERR_NOENT;
  2543. lfs_rename(&lfs,
  2544. "coffee/vietnamese",
  2545. "_espresso/cappuccino") => LFS_ERR_NOENT;
  2546. lfs_rename(&lfs,
  2547. "coffee/thai",
  2548. "espresso_/mocha") => LFS_ERR_NOENT;
  2549. // bad source and bad destination
  2550. lfs_rename(&lfs,
  2551. "_offee/drip",
  2552. "_spresso/espresso") => LFS_ERR_NOENT;
  2553. lfs_rename(&lfs,
  2554. "c_ffee/coldbrew",
  2555. "e_presso/americano") => LFS_ERR_NOENT;
  2556. lfs_rename(&lfs,
  2557. "co_fee/turkish",
  2558. "es_resso/macchiato") => LFS_ERR_NOENT;
  2559. lfs_rename(&lfs,
  2560. "cof_ee/tubruk",
  2561. "esp_esso/latte") => LFS_ERR_NOENT;
  2562. lfs_rename(&lfs,
  2563. "_coffee/vietnamese",
  2564. "_espresso/cappuccino") => LFS_ERR_NOENT;
  2565. lfs_rename(&lfs,
  2566. "coffee_/thai",
  2567. "espresso_/mocha") => LFS_ERR_NOENT;
  2568. // here's a weird one, what happens if our rename is also a noop?
  2569. lfs_rename(&lfs,
  2570. "_offee/drip",
  2571. "_offee/drip") => LFS_ERR_NOENT;
  2572. lfs_rename(&lfs,
  2573. "c_ffee/coldbrew",
  2574. "c_ffee/coldbrew") => LFS_ERR_NOENT;
  2575. lfs_rename(&lfs,
  2576. "co_fee/turkish",
  2577. "co_fee/turkish") => LFS_ERR_NOENT;
  2578. lfs_rename(&lfs,
  2579. "cof_ee/tubruk",
  2580. "cof_ee/tubruk") => LFS_ERR_NOENT;
  2581. lfs_rename(&lfs,
  2582. "_coffee/vietnamese",
  2583. "_coffee/vietnamese") => LFS_ERR_NOENT;
  2584. lfs_rename(&lfs,
  2585. "coffee_/thai",
  2586. "coffee_/thai") => LFS_ERR_NOENT;
  2587. // remove paths
  2588. lfs_remove(&lfs, "_offee/drip") => LFS_ERR_NOENT;
  2589. lfs_remove(&lfs, "c_ffee/coldbrew") => LFS_ERR_NOENT;
  2590. lfs_remove(&lfs, "co_fee/turkish") => LFS_ERR_NOENT;
  2591. lfs_remove(&lfs, "cof_ee/tubruk") => LFS_ERR_NOENT;
  2592. lfs_remove(&lfs, "_coffee/vietnamese") => LFS_ERR_NOENT;
  2593. lfs_remove(&lfs, "coffee_/thai") => LFS_ERR_NOENT;
  2594. // stat paths
  2595. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  2596. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  2597. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  2598. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  2599. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  2600. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  2601. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  2602. assert(strcmp(info.name, "drip") == 0);
  2603. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2604. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  2605. assert(strcmp(info.name, "coldbrew") == 0);
  2606. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2607. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  2608. assert(strcmp(info.name, "turkish") == 0);
  2609. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2610. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  2611. assert(strcmp(info.name, "tubruk") == 0);
  2612. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2613. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  2614. assert(strcmp(info.name, "vietnamese") == 0);
  2615. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2616. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  2617. assert(strcmp(info.name, "thai") == 0);
  2618. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2619. lfs_unmount(&lfs) => 0;
  2620. '''
  2621. # parent notdir tests
  2622. [cases.test_paths_notdir_parent]
  2623. defines.DIR = [false, true]
  2624. code = '''
  2625. lfs_t lfs;
  2626. lfs_format(&lfs, cfg) => 0;
  2627. lfs_mount(&lfs, cfg) => 0;
  2628. // create paths
  2629. lfs_file_t file;
  2630. lfs_file_open(&lfs, &file, "drip",
  2631. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2632. lfs_file_close(&lfs, &file) => 0;
  2633. lfs_file_open(&lfs, &file, "coldbrew",
  2634. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2635. lfs_file_close(&lfs, &file) => 0;
  2636. lfs_file_open(&lfs, &file, "turkish",
  2637. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2638. lfs_file_close(&lfs, &file) => 0;
  2639. lfs_file_open(&lfs, &file, "tubruk",
  2640. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2641. lfs_file_close(&lfs, &file) => 0;
  2642. lfs_file_open(&lfs, &file, "vietnamese",
  2643. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2644. lfs_file_close(&lfs, &file) => 0;
  2645. lfs_file_open(&lfs, &file, "thai",
  2646. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2647. lfs_file_close(&lfs, &file) => 0;
  2648. if (DIR) {
  2649. lfs_mkdir(&lfs, "drip/coffee") => LFS_ERR_NOTDIR;
  2650. lfs_mkdir(&lfs, "coldbrew/coffee") => LFS_ERR_NOTDIR;
  2651. lfs_mkdir(&lfs, "turkish/coffee") => LFS_ERR_NOTDIR;
  2652. lfs_mkdir(&lfs, "tubruk/coffee") => LFS_ERR_NOTDIR;
  2653. lfs_mkdir(&lfs, "vietnamese/coffee") => LFS_ERR_NOTDIR;
  2654. lfs_mkdir(&lfs, "thai/coffee") => LFS_ERR_NOTDIR;
  2655. } else {
  2656. lfs_file_t file;
  2657. lfs_file_open(&lfs, &file, "drip/coffee",
  2658. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2659. lfs_file_open(&lfs, &file, "coldbrew/coffee",
  2660. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2661. lfs_file_open(&lfs, &file, "turkish/coffee",
  2662. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2663. lfs_file_open(&lfs, &file, "tubruk/coffee",
  2664. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2665. lfs_file_open(&lfs, &file, "vietnamese/coffee",
  2666. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2667. lfs_file_open(&lfs, &file, "thai/coffee",
  2668. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2669. }
  2670. // stat paths
  2671. struct lfs_info info;
  2672. lfs_stat(&lfs, "drip/coffee", &info) => LFS_ERR_NOTDIR;
  2673. lfs_stat(&lfs, "coldbrew/coffee", &info) => LFS_ERR_NOTDIR;
  2674. lfs_stat(&lfs, "turkish/coffee", &info) => LFS_ERR_NOTDIR;
  2675. lfs_stat(&lfs, "tubruk/coffee", &info) => LFS_ERR_NOTDIR;
  2676. lfs_stat(&lfs, "vietnamese/coffee", &info) => LFS_ERR_NOTDIR;
  2677. lfs_stat(&lfs, "thai/coffee", &info) => LFS_ERR_NOTDIR;
  2678. // file open paths, only works on files!
  2679. lfs_file_open(&lfs, &file, "drip/coffee",
  2680. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2681. lfs_file_open(&lfs, &file, "coldbrew/coffee",
  2682. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2683. lfs_file_open(&lfs, &file, "turkish/coffee",
  2684. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2685. lfs_file_open(&lfs, &file, "tubruk/coffee",
  2686. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2687. lfs_file_open(&lfs, &file, "vietnamese/coffee",
  2688. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2689. lfs_file_open(&lfs, &file, "thai/coffee",
  2690. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2691. // dir open paths, only works on dirs!
  2692. lfs_dir_t dir;
  2693. lfs_dir_open(&lfs, &dir, "drip/coffee") => LFS_ERR_NOTDIR;
  2694. lfs_dir_open(&lfs, &dir, "coldbrew/coffee") => LFS_ERR_NOTDIR;
  2695. lfs_dir_open(&lfs, &dir, "turkish/coffee") => LFS_ERR_NOTDIR;
  2696. lfs_dir_open(&lfs, &dir, "tubruk/coffee") => LFS_ERR_NOTDIR;
  2697. lfs_dir_open(&lfs, &dir, "vietnamese/coffee") => LFS_ERR_NOTDIR;
  2698. lfs_dir_open(&lfs, &dir, "thai/coffee") => LFS_ERR_NOTDIR;
  2699. // make some normal paths so we have something to rename
  2700. lfs_mkdir(&lfs, "coffee") => 0;
  2701. if (DIR) {
  2702. lfs_mkdir(&lfs, "coffee/drip") => 0;
  2703. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  2704. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  2705. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  2706. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  2707. lfs_mkdir(&lfs, "coffee/thai") => 0;
  2708. } else {
  2709. lfs_file_t file;
  2710. lfs_file_open(&lfs, &file, "coffee/drip",
  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/coldbrew",
  2714. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2715. lfs_file_close(&lfs, &file) => 0;
  2716. lfs_file_open(&lfs, &file, "coffee/turkish",
  2717. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2718. lfs_file_close(&lfs, &file) => 0;
  2719. lfs_file_open(&lfs, &file, "coffee/tubruk",
  2720. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2721. lfs_file_close(&lfs, &file) => 0;
  2722. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  2723. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2724. lfs_file_close(&lfs, &file) => 0;
  2725. lfs_file_open(&lfs, &file, "coffee/thai",
  2726. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2727. lfs_file_close(&lfs, &file) => 0;
  2728. }
  2729. // rename paths
  2730. lfs_mkdir(&lfs, "espresso") => 0;
  2731. // bad source
  2732. lfs_rename(&lfs,
  2733. "drip/coffee",
  2734. "espresso/espresso") => LFS_ERR_NOTDIR;
  2735. lfs_rename(&lfs,
  2736. "coldbrew/coffee",
  2737. "espresso/americano") => LFS_ERR_NOTDIR;
  2738. lfs_rename(&lfs,
  2739. "turkish/coffee",
  2740. "espresso/macchiato") => LFS_ERR_NOTDIR;
  2741. lfs_rename(&lfs,
  2742. "tubruk/coffee",
  2743. "espresso/latte") => LFS_ERR_NOTDIR;
  2744. lfs_rename(&lfs,
  2745. "vietnamese/coffee",
  2746. "espresso/cappuccino") => LFS_ERR_NOTDIR;
  2747. lfs_rename(&lfs,
  2748. "thai/coffee",
  2749. "espresso/mocha") => LFS_ERR_NOTDIR;
  2750. // bad destination
  2751. lfs_rename(&lfs,
  2752. "coffee/drip",
  2753. "drip/espresso") => LFS_ERR_NOTDIR;
  2754. lfs_rename(&lfs,
  2755. "coffee/coldbrew",
  2756. "coldbrew/espresso") => LFS_ERR_NOTDIR;
  2757. lfs_rename(&lfs,
  2758. "coffee/turkish",
  2759. "turkish/espresso") => LFS_ERR_NOTDIR;
  2760. lfs_rename(&lfs,
  2761. "coffee/tubruk",
  2762. "tubruk/espresso") => LFS_ERR_NOTDIR;
  2763. lfs_rename(&lfs,
  2764. "coffee/vietnamese",
  2765. "vietnamese/espresso") => LFS_ERR_NOTDIR;
  2766. lfs_rename(&lfs,
  2767. "coffee/thai",
  2768. "thai/espresso") => LFS_ERR_NOTDIR;
  2769. // bad source and bad destination
  2770. lfs_rename(&lfs,
  2771. "drip/coffee",
  2772. "drip/espresso") => LFS_ERR_NOTDIR;
  2773. lfs_rename(&lfs,
  2774. "coldbrew/coffee",
  2775. "coldbrew/espresso") => LFS_ERR_NOTDIR;
  2776. lfs_rename(&lfs,
  2777. "turkish/coffee",
  2778. "turkish/espresso") => LFS_ERR_NOTDIR;
  2779. lfs_rename(&lfs,
  2780. "tubruk/coffee",
  2781. "tubruk/espresso") => LFS_ERR_NOTDIR;
  2782. lfs_rename(&lfs,
  2783. "vietnamese/coffee",
  2784. "vietnamese/espresso") => LFS_ERR_NOTDIR;
  2785. lfs_rename(&lfs,
  2786. "thai/coffee",
  2787. "thai/espresso") => LFS_ERR_NOTDIR;
  2788. // here's a weird one, what happens if our rename is also a noop?
  2789. lfs_rename(&lfs,
  2790. "drip/coffee",
  2791. "drip/coffee") => LFS_ERR_NOTDIR;
  2792. lfs_rename(&lfs,
  2793. "coldbrew/coffee",
  2794. "coldbrew/coffee") => LFS_ERR_NOTDIR;
  2795. lfs_rename(&lfs,
  2796. "turkish/coffee",
  2797. "turkish/coffee") => LFS_ERR_NOTDIR;
  2798. lfs_rename(&lfs,
  2799. "tubruk/coffee",
  2800. "tubruk/coffee") => LFS_ERR_NOTDIR;
  2801. lfs_rename(&lfs,
  2802. "vietnamese/coffee",
  2803. "vietnamese/coffee") => LFS_ERR_NOTDIR;
  2804. lfs_rename(&lfs,
  2805. "thai/coffee",
  2806. "thai/coffee") => LFS_ERR_NOTDIR;
  2807. // remove paths
  2808. lfs_stat(&lfs, "drip/espresso", &info) => LFS_ERR_NOTDIR;
  2809. lfs_stat(&lfs, "coldbrew/espresso", &info) => LFS_ERR_NOTDIR;
  2810. lfs_stat(&lfs, "turkish/espresso", &info) => LFS_ERR_NOTDIR;
  2811. lfs_stat(&lfs, "tubruk/espresso", &info) => LFS_ERR_NOTDIR;
  2812. lfs_stat(&lfs, "vietnamese/espresso", &info) => LFS_ERR_NOTDIR;
  2813. lfs_stat(&lfs, "thai/espresso", &info) => LFS_ERR_NOTDIR;
  2814. // stat paths
  2815. lfs_stat(&lfs, "drip/espresso", &info) => LFS_ERR_NOTDIR;
  2816. lfs_stat(&lfs, "coldbrew/espresso", &info) => LFS_ERR_NOTDIR;
  2817. lfs_stat(&lfs, "turkish/espresso", &info) => LFS_ERR_NOTDIR;
  2818. lfs_stat(&lfs, "tubruk/espresso", &info) => LFS_ERR_NOTDIR;
  2819. lfs_stat(&lfs, "vietnamese/espresso", &info) => LFS_ERR_NOTDIR;
  2820. lfs_stat(&lfs, "thai/espresso", &info) => LFS_ERR_NOTDIR;
  2821. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  2822. assert(strcmp(info.name, "drip") == 0);
  2823. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2824. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  2825. assert(strcmp(info.name, "coldbrew") == 0);
  2826. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2827. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  2828. assert(strcmp(info.name, "turkish") == 0);
  2829. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2830. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  2831. assert(strcmp(info.name, "tubruk") == 0);
  2832. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2833. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  2834. assert(strcmp(info.name, "vietnamese") == 0);
  2835. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2836. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  2837. assert(strcmp(info.name, "thai") == 0);
  2838. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2839. lfs_unmount(&lfs) => 0;
  2840. '''
  2841. # root operations
  2842. #
  2843. # POSIX deviations:
  2844. #
  2845. # - Root modifications return EINVAL instead of EBUSY:
  2846. # - littlefs: remove("/") => EINVAL
  2847. # - POSIX: remove("/") => EBUSY
  2848. # Reason: This would be the only use of EBUSY in the system.
  2849. #
  2850. [cases.test_paths_root]
  2851. defines.DIR = [false, true]
  2852. code = '''
  2853. lfs_t lfs;
  2854. lfs_format(&lfs, cfg) => 0;
  2855. lfs_mount(&lfs, cfg) => 0;
  2856. struct lfs_info info;
  2857. // create root, this should error
  2858. if (DIR) {
  2859. lfs_mkdir(&lfs, "/") => LFS_ERR_EXIST;
  2860. } else {
  2861. lfs_file_t file;
  2862. lfs_file_open(&lfs, &file, "/",
  2863. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2864. }
  2865. // stat root
  2866. lfs_stat(&lfs, "/", &info) => 0;
  2867. assert(strcmp(info.name, "/") == 0);
  2868. assert(info.type == LFS_TYPE_DIR);
  2869. // file open root, only works on files!
  2870. lfs_file_t file;
  2871. lfs_file_open(&lfs, &file, "/",
  2872. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2873. // dir open root, only works on dirs!
  2874. lfs_dir_t dir;
  2875. lfs_dir_open(&lfs, &dir, "/") => 0;
  2876. lfs_dir_close(&lfs, &dir) => 0;
  2877. // rename root, this should error
  2878. lfs_rename(&lfs, "/", "coffee") => LFS_ERR_INVAL;
  2879. lfs_mkdir(&lfs, "coffee") => 0;
  2880. lfs_rename(&lfs, "coffee", "/") => LFS_ERR_INVAL;
  2881. lfs_remove(&lfs, "coffee") => 0;
  2882. lfs_rename(&lfs, "/", "/") => LFS_ERR_INVAL;
  2883. // stat root
  2884. lfs_stat(&lfs, "/", &info) => 0;
  2885. assert(strcmp(info.name, "/") == 0);
  2886. assert(info.type == LFS_TYPE_DIR);
  2887. // remove root, this should error
  2888. lfs_remove(&lfs, "/") => LFS_ERR_INVAL;
  2889. // stat root
  2890. lfs_stat(&lfs, "/", &info) => 0;
  2891. assert(strcmp(info.name, "/") == 0);
  2892. assert(info.type == LFS_TYPE_DIR);
  2893. lfs_unmount(&lfs) => 0;
  2894. '''
  2895. # other root representations
  2896. [cases.test_paths_root_aliases]
  2897. defines.DIR = [false, true]
  2898. code = '''
  2899. lfs_t lfs;
  2900. lfs_format(&lfs, cfg) => 0;
  2901. lfs_mount(&lfs, cfg) => 0;
  2902. struct lfs_info info;
  2903. // create root, this should error
  2904. if (DIR) {
  2905. lfs_mkdir(&lfs, "/") => LFS_ERR_EXIST;
  2906. lfs_mkdir(&lfs, "") => LFS_ERR_EXIST;
  2907. lfs_mkdir(&lfs, ".") => LFS_ERR_EXIST;
  2908. lfs_mkdir(&lfs, "./") => LFS_ERR_EXIST;
  2909. lfs_mkdir(&lfs, "/.") => LFS_ERR_EXIST;
  2910. lfs_mkdir(&lfs, "//") => LFS_ERR_EXIST;
  2911. } else {
  2912. lfs_file_t file;
  2913. lfs_file_open(&lfs, &file, "/",
  2914. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2915. lfs_file_open(&lfs, &file, "",
  2916. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2917. lfs_file_open(&lfs, &file, ".",
  2918. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2919. lfs_file_open(&lfs, &file, "./",
  2920. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2921. lfs_file_open(&lfs, &file, "/.",
  2922. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2923. lfs_file_open(&lfs, &file, "//",
  2924. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2925. }
  2926. // stat root
  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. lfs_stat(&lfs, "/.", &info) => 0;
  2940. assert(strcmp(info.name, "/") == 0);
  2941. assert(info.type == LFS_TYPE_DIR);
  2942. lfs_stat(&lfs, "//", &info) => 0;
  2943. assert(strcmp(info.name, "/") == 0);
  2944. assert(info.type == LFS_TYPE_DIR);
  2945. // file open root, only works on files!
  2946. lfs_file_t file;
  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. lfs_file_open(&lfs, &file, "/.",
  2956. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2957. lfs_file_open(&lfs, &file, "//",
  2958. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2959. // dir open root, only works on dirs!
  2960. lfs_dir_t dir;
  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. lfs_dir_open(&lfs, &dir, "//") => 0;
  2972. lfs_dir_close(&lfs, &dir) => 0;
  2973. // rename root, this should error
  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_rename(&lfs, "//", "coffee") => LFS_ERR_INVAL;
  2980. lfs_mkdir(&lfs, "coffee") => 0;
  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. // remove root, this should error
  3015. lfs_remove(&lfs, "/") => LFS_ERR_INVAL;
  3016. lfs_remove(&lfs, "") => LFS_ERR_INVAL;
  3017. lfs_remove(&lfs, ".") => LFS_ERR_INVAL;
  3018. lfs_remove(&lfs, "./") => LFS_ERR_INVAL;
  3019. lfs_remove(&lfs, "/.") => LFS_ERR_INVAL;
  3020. lfs_remove(&lfs, "//") => LFS_ERR_INVAL;
  3021. // stat root
  3022. lfs_stat(&lfs, "/", &info) => 0;
  3023. assert(strcmp(info.name, "/") == 0);
  3024. assert(info.type == LFS_TYPE_DIR);
  3025. lfs_stat(&lfs, "", &info) => 0;
  3026. assert(strcmp(info.name, "/") == 0);
  3027. assert(info.type == LFS_TYPE_DIR);
  3028. lfs_stat(&lfs, ".", &info) => 0;
  3029. assert(strcmp(info.name, "/") == 0);
  3030. assert(info.type == LFS_TYPE_DIR);
  3031. lfs_stat(&lfs, "./", &info) => 0;
  3032. assert(strcmp(info.name, "/") == 0);
  3033. assert(info.type == LFS_TYPE_DIR);
  3034. lfs_stat(&lfs, "/.", &info) => 0;
  3035. assert(strcmp(info.name, "/") == 0);
  3036. assert(info.type == LFS_TYPE_DIR);
  3037. lfs_stat(&lfs, "//", &info) => 0;
  3038. assert(strcmp(info.name, "/") == 0);
  3039. assert(info.type == LFS_TYPE_DIR);
  3040. lfs_unmount(&lfs) => 0;
  3041. '''
  3042. # superblock magic shouldn't appear as a file
  3043. [cases.test_paths_magic_noent]
  3044. code = '''
  3045. lfs_t lfs;
  3046. lfs_format(&lfs, cfg) => 0;
  3047. lfs_mount(&lfs, cfg) => 0;
  3048. // stat littlefs, which shouldn't exist
  3049. struct lfs_info info;
  3050. lfs_stat(&lfs, "littlefs", &info) => LFS_ERR_NOENT;
  3051. // dir open littlefs, which shouldn't exist
  3052. lfs_dir_t dir;
  3053. lfs_dir_open(&lfs, &dir, "littlefs") => LFS_ERR_NOENT;
  3054. // rename littlefs, which shouldn't exist
  3055. lfs_rename(&lfs, "littlefs", "coffee") => LFS_ERR_NOENT;
  3056. // remove littlefs, which shouldn't exist
  3057. lfs_remove(&lfs, "littlefs") => LFS_ERR_NOENT;
  3058. // stat littlefs, which shouldn't exist
  3059. lfs_stat(&lfs, "coffee", &info) => LFS_ERR_NOENT;
  3060. lfs_stat(&lfs, "littlefs", &info) => LFS_ERR_NOENT;
  3061. lfs_unmount(&lfs) => 0;
  3062. '''
  3063. # superblock magic shouldn't conflict with files, that would be silly
  3064. [cases.test_paths_magic_conflict]
  3065. defines.DIR = [false, true]
  3066. code = '''
  3067. lfs_t lfs;
  3068. lfs_format(&lfs, cfg) => 0;
  3069. lfs_mount(&lfs, cfg) => 0;
  3070. // create littlefs
  3071. if (DIR) {
  3072. lfs_mkdir(&lfs, "littlefs") => 0;
  3073. } else {
  3074. lfs_file_t file;
  3075. lfs_file_open(&lfs, &file, "littlefs",
  3076. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3077. lfs_file_close(&lfs, &file) => 0;
  3078. }
  3079. // stat littlefs
  3080. struct lfs_info info;
  3081. lfs_stat(&lfs, "littlefs", &info) => 0;
  3082. assert(strcmp(info.name, "littlefs") == 0);
  3083. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3084. // file open littlefs, only works on files!
  3085. if (DIR) {
  3086. lfs_file_t file;
  3087. lfs_file_open(&lfs, &file, "littlefs",
  3088. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3089. } else {
  3090. lfs_file_t file;
  3091. lfs_file_open(&lfs, &file, "littlefs",
  3092. LFS_O_RDONLY) => 0;
  3093. lfs_file_close(&lfs, &file) => 0;
  3094. }
  3095. // dir open littlefs, only works on dirs!
  3096. if (DIR) {
  3097. lfs_dir_t dir;
  3098. lfs_dir_open(&lfs, &dir, "littlefs") => 0;
  3099. lfs_dir_close(&lfs, &dir) => 0;
  3100. } else {
  3101. lfs_dir_t dir;
  3102. lfs_dir_open(&lfs, &dir, "littlefs") => LFS_ERR_NOTDIR;
  3103. }
  3104. // rename littlefs
  3105. lfs_rename(&lfs, "littlefs", "coffee") => 0;
  3106. lfs_rename(&lfs, "coffee", "littlefs") => 0;
  3107. // stat littlefs
  3108. lfs_stat(&lfs, "littlefs", &info) => 0;
  3109. assert(strcmp(info.name, "littlefs") == 0);
  3110. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3111. lfs_stat(&lfs, "coffee", &info) => LFS_ERR_NOENT;
  3112. // remove littlefs
  3113. lfs_remove(&lfs, "littlefs") => 0;
  3114. // stat littlefs
  3115. lfs_stat(&lfs, "littlefs", &info) => LFS_ERR_NOENT;
  3116. lfs_unmount(&lfs) => 0;
  3117. '''
  3118. # test name too long
  3119. [cases.test_paths_nametoolong]
  3120. defines.DIR = [false, true]
  3121. code = '''
  3122. lfs_t lfs;
  3123. lfs_format(&lfs, cfg) => 0;
  3124. lfs_mount(&lfs, cfg) => 0;
  3125. char a_name[512];
  3126. memset(a_name, 'a', LFS_NAME_MAX+1);
  3127. a_name[LFS_NAME_MAX+1] = '\0';
  3128. // create names that are too long, should error
  3129. char path[1024];
  3130. lfs_mkdir(&lfs, "coffee") => 0;
  3131. if (DIR) {
  3132. sprintf(path, "coffee/%s", a_name);
  3133. lfs_mkdir(&lfs, path) => LFS_ERR_NAMETOOLONG;
  3134. } else {
  3135. lfs_file_t file;
  3136. sprintf(path, "coffee/%s", a_name);
  3137. lfs_file_open(&lfs, &file, path,
  3138. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NAMETOOLONG;
  3139. }
  3140. // stat paths
  3141. struct lfs_info info;
  3142. sprintf(path, "coffee/%s", a_name);
  3143. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3144. // file open paths, only works on files!
  3145. lfs_file_t file;
  3146. sprintf(path, "coffee/%s", a_name);
  3147. lfs_file_open(&lfs, &file, path,
  3148. LFS_O_RDONLY) => LFS_ERR_NOENT;
  3149. // dir open paths, only works on dirs!
  3150. lfs_dir_t dir;
  3151. sprintf(path, "coffee/%s", a_name);
  3152. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOENT;
  3153. // rename paths
  3154. lfs_mkdir(&lfs, "espresso") => 0;
  3155. sprintf(path, "coffee/%s", a_name);
  3156. lfs_rename(&lfs, path, "espresso/espresso") => LFS_ERR_NOENT;
  3157. // renaming with too long a destination is tricky!
  3158. if (DIR) {
  3159. lfs_mkdir(&lfs, "coffee/drip") => 0;
  3160. } else {
  3161. lfs_file_t file;
  3162. lfs_file_open(&lfs, &file, "coffee/drip",
  3163. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3164. lfs_file_close(&lfs, &file) => 0;
  3165. }
  3166. sprintf(path, "espresso/%s", a_name);
  3167. lfs_rename(&lfs, "coffee/drip", path) => LFS_ERR_NAMETOOLONG;
  3168. // stat paths
  3169. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  3170. assert(strcmp(info.name, "drip") == 0);
  3171. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3172. sprintf(path, "espresso/%s", a_name);
  3173. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3174. // remove paths
  3175. sprintf(path, "espresso/%s", a_name);
  3176. lfs_remove(&lfs, path) => LFS_ERR_NOENT;
  3177. // stat paths
  3178. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  3179. assert(strcmp(info.name, "drip") == 0);
  3180. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3181. sprintf(path, "espresso/%s", a_name);
  3182. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3183. lfs_unmount(&lfs) => 0;
  3184. '''
  3185. # test name really long but not too long
  3186. [cases.test_paths_namejustlongenough]
  3187. defines.DIR = [false, true]
  3188. code = '''
  3189. lfs_t lfs;
  3190. lfs_format(&lfs, cfg) => 0;
  3191. lfs_mount(&lfs, cfg) => 0;
  3192. char a_name[512];
  3193. memset(a_name, 'a', LFS_NAME_MAX);
  3194. a_name[LFS_NAME_MAX] = '\0';
  3195. char b_name[512];
  3196. memset(b_name, 'b', LFS_NAME_MAX);
  3197. b_name[LFS_NAME_MAX] = '\0';
  3198. char c_name[512];
  3199. memset(c_name, 'c', LFS_NAME_MAX);
  3200. c_name[LFS_NAME_MAX] = '\0';
  3201. char d_name[512];
  3202. memset(d_name, 'd', LFS_NAME_MAX);
  3203. d_name[LFS_NAME_MAX] = '\0';
  3204. char e_name[512];
  3205. memset(e_name, 'e', LFS_NAME_MAX);
  3206. e_name[LFS_NAME_MAX] = '\0';
  3207. char f_name[512];
  3208. memset(f_name, 'f', LFS_NAME_MAX);
  3209. f_name[LFS_NAME_MAX] = '\0';
  3210. char g_name[512];
  3211. memset(g_name, 'g', LFS_NAME_MAX);
  3212. g_name[LFS_NAME_MAX] = '\0';
  3213. char h_name[512];
  3214. memset(h_name, 'h', LFS_NAME_MAX);
  3215. h_name[LFS_NAME_MAX] = '\0';
  3216. char i_name[512];
  3217. memset(i_name, 'i', LFS_NAME_MAX);
  3218. i_name[LFS_NAME_MAX] = '\0';
  3219. char j_name[512];
  3220. memset(j_name, 'j', LFS_NAME_MAX);
  3221. j_name[LFS_NAME_MAX] = '\0';
  3222. char k_name[512];
  3223. memset(k_name, 'k', LFS_NAME_MAX);
  3224. k_name[LFS_NAME_MAX] = '\0';
  3225. char l_name[512];
  3226. memset(l_name, 'l', LFS_NAME_MAX);
  3227. l_name[LFS_NAME_MAX] = '\0';
  3228. // create names that aren't too long
  3229. lfs_mkdir(&lfs, c_name) => 0;
  3230. char path[1024];
  3231. if (DIR) {
  3232. sprintf(path, "%s/%s", c_name, a_name);
  3233. lfs_mkdir(&lfs, path) => 0;
  3234. sprintf(path, "%s/%s", c_name, b_name);
  3235. lfs_mkdir(&lfs, path) => 0;
  3236. sprintf(path, "%s/%s", c_name, c_name);
  3237. lfs_mkdir(&lfs, path) => 0;
  3238. sprintf(path, "%s/%s", c_name, d_name);
  3239. lfs_mkdir(&lfs, path) => 0;
  3240. sprintf(path, "%s/%s", c_name, e_name);
  3241. lfs_mkdir(&lfs, path) => 0;
  3242. sprintf(path, "%s/%s", c_name, f_name);
  3243. lfs_mkdir(&lfs, path) => 0;
  3244. } else {
  3245. lfs_file_t file;
  3246. sprintf(path, "%s/%s", c_name, a_name);
  3247. lfs_file_open(&lfs, &file, path,
  3248. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3249. lfs_file_close(&lfs, &file) => 0;
  3250. sprintf(path, "%s/%s", c_name, b_name);
  3251. lfs_file_open(&lfs, &file, path,
  3252. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3253. lfs_file_close(&lfs, &file) => 0;
  3254. sprintf(path, "%s/%s", c_name, c_name);
  3255. lfs_file_open(&lfs, &file, path,
  3256. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3257. lfs_file_close(&lfs, &file) => 0;
  3258. sprintf(path, "%s/%s", c_name, d_name);
  3259. lfs_file_open(&lfs, &file, path,
  3260. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3261. lfs_file_close(&lfs, &file) => 0;
  3262. sprintf(path, "%s/%s", c_name, e_name);
  3263. lfs_file_open(&lfs, &file, path,
  3264. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3265. lfs_file_close(&lfs, &file) => 0;
  3266. sprintf(path, "%s/%s", c_name, f_name);
  3267. lfs_file_open(&lfs, &file, path,
  3268. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3269. lfs_file_close(&lfs, &file) => 0;
  3270. }
  3271. // stat paths
  3272. struct lfs_info info;
  3273. sprintf(path, "%s/%s", c_name, a_name);
  3274. lfs_stat(&lfs, path, &info) => 0;
  3275. assert(strcmp(info.name, a_name) == 0);
  3276. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3277. sprintf(path, "%s/%s", c_name, b_name);
  3278. lfs_stat(&lfs, path, &info) => 0;
  3279. assert(strcmp(info.name, b_name) == 0);
  3280. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3281. sprintf(path, "%s/%s", c_name, c_name);
  3282. lfs_stat(&lfs, path, &info) => 0;
  3283. assert(strcmp(info.name, c_name) == 0);
  3284. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3285. sprintf(path, "%s/%s", c_name, d_name);
  3286. lfs_stat(&lfs, path, &info) => 0;
  3287. assert(strcmp(info.name, d_name) == 0);
  3288. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3289. sprintf(path, "%s/%s", c_name, e_name);
  3290. lfs_stat(&lfs, path, &info) => 0;
  3291. assert(strcmp(info.name, e_name) == 0);
  3292. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3293. sprintf(path, "%s/%s", c_name, f_name);
  3294. lfs_stat(&lfs, path, &info) => 0;
  3295. assert(strcmp(info.name, f_name) == 0);
  3296. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3297. // file open paths, only works on files!
  3298. if (DIR) {
  3299. lfs_file_t file;
  3300. sprintf(path, "%s/%s", c_name, a_name);
  3301. lfs_file_open(&lfs, &file, path,
  3302. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3303. sprintf(path, "%s/%s", c_name, b_name);
  3304. lfs_file_open(&lfs, &file, path,
  3305. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3306. sprintf(path, "%s/%s", c_name, c_name);
  3307. lfs_file_open(&lfs, &file, path,
  3308. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3309. sprintf(path, "%s/%s", c_name, d_name);
  3310. lfs_file_open(&lfs, &file, path,
  3311. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3312. sprintf(path, "%s/%s", c_name, e_name);
  3313. lfs_file_open(&lfs, &file, path,
  3314. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3315. sprintf(path, "%s/%s", c_name, f_name);
  3316. lfs_file_open(&lfs, &file, path,
  3317. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3318. } else {
  3319. lfs_file_t file;
  3320. sprintf(path, "%s/%s", c_name, a_name);
  3321. lfs_file_open(&lfs, &file, path,
  3322. LFS_O_RDONLY) => 0;
  3323. lfs_file_close(&lfs, &file) => 0;
  3324. sprintf(path, "%s/%s", c_name, b_name);
  3325. lfs_file_open(&lfs, &file, path,
  3326. LFS_O_RDONLY) => 0;
  3327. lfs_file_close(&lfs, &file) => 0;
  3328. sprintf(path, "%s/%s", c_name, c_name);
  3329. lfs_file_open(&lfs, &file, path,
  3330. LFS_O_RDONLY) => 0;
  3331. lfs_file_close(&lfs, &file) => 0;
  3332. sprintf(path, "%s/%s", c_name, d_name);
  3333. lfs_file_open(&lfs, &file, path,
  3334. LFS_O_RDONLY) => 0;
  3335. lfs_file_close(&lfs, &file) => 0;
  3336. sprintf(path, "%s/%s", c_name, e_name);
  3337. lfs_file_open(&lfs, &file, path,
  3338. LFS_O_RDONLY) => 0;
  3339. lfs_file_close(&lfs, &file) => 0;
  3340. sprintf(path, "%s/%s", c_name, f_name);
  3341. lfs_file_open(&lfs, &file, path,
  3342. LFS_O_RDONLY) => 0;
  3343. lfs_file_close(&lfs, &file) => 0;
  3344. }
  3345. // dir open paths, only works on dirs!
  3346. if (DIR) {
  3347. lfs_dir_t dir;
  3348. sprintf(path, "%s/%s", c_name, a_name);
  3349. lfs_dir_open(&lfs, &dir, path) => 0;
  3350. lfs_dir_close(&lfs, &dir) => 0;
  3351. sprintf(path, "%s/%s", c_name, b_name);
  3352. lfs_dir_open(&lfs, &dir, path) => 0;
  3353. lfs_dir_close(&lfs, &dir) => 0;
  3354. sprintf(path, "%s/%s", c_name, c_name);
  3355. lfs_dir_open(&lfs, &dir, path) => 0;
  3356. lfs_dir_close(&lfs, &dir) => 0;
  3357. sprintf(path, "%s/%s", c_name, d_name);
  3358. lfs_dir_open(&lfs, &dir, path) => 0;
  3359. lfs_dir_close(&lfs, &dir) => 0;
  3360. sprintf(path, "%s/%s", c_name, e_name);
  3361. lfs_dir_open(&lfs, &dir, path) => 0;
  3362. lfs_dir_close(&lfs, &dir) => 0;
  3363. sprintf(path, "%s/%s", c_name, f_name);
  3364. lfs_dir_open(&lfs, &dir, path) => 0;
  3365. lfs_dir_close(&lfs, &dir) => 0;
  3366. } else {
  3367. lfs_dir_t dir;
  3368. sprintf(path, "%s/%s", c_name, a_name);
  3369. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3370. sprintf(path, "%s/%s", c_name, b_name);
  3371. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3372. sprintf(path, "%s/%s", c_name, c_name);
  3373. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3374. sprintf(path, "%s/%s", c_name, d_name);
  3375. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3376. sprintf(path, "%s/%s", c_name, e_name);
  3377. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3378. sprintf(path, "%s/%s", c_name, f_name);
  3379. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3380. }
  3381. // rename paths
  3382. lfs_mkdir(&lfs, e_name) => 0;
  3383. char path_[1024];
  3384. sprintf(path, "%s/%s", c_name, a_name);
  3385. sprintf(path_, "%s/%s", e_name, g_name);
  3386. lfs_rename(&lfs, path, path_) => 0;
  3387. sprintf(path, "%s/%s", c_name, b_name);
  3388. sprintf(path_, "%s/%s", e_name, h_name);
  3389. lfs_rename(&lfs, path, path_) => 0;
  3390. sprintf(path, "%s/%s", c_name, c_name);
  3391. sprintf(path_, "%s/%s", e_name, i_name);
  3392. lfs_rename(&lfs, path, path_) => 0;
  3393. sprintf(path, "%s/%s", c_name, d_name);
  3394. sprintf(path_, "%s/%s", e_name, j_name);
  3395. lfs_rename(&lfs, path, path_) => 0;
  3396. sprintf(path, "%s/%s", c_name, e_name);
  3397. sprintf(path_, "%s/%s", e_name, k_name);
  3398. lfs_rename(&lfs, path, path_) => 0;
  3399. sprintf(path, "%s/%s", c_name, f_name);
  3400. sprintf(path_, "%s/%s", e_name, l_name);
  3401. lfs_rename(&lfs, path, path_) => 0;
  3402. // stat paths
  3403. sprintf(path, "%s/%s", e_name, g_name);
  3404. lfs_stat(&lfs, path, &info) => 0;
  3405. assert(strcmp(info.name, g_name) == 0);
  3406. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3407. sprintf(path, "%s/%s", e_name, h_name);
  3408. lfs_stat(&lfs, path, &info) => 0;
  3409. assert(strcmp(info.name, h_name) == 0);
  3410. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3411. sprintf(path, "%s/%s", e_name, i_name);
  3412. lfs_stat(&lfs, path, &info) => 0;
  3413. assert(strcmp(info.name, i_name) == 0);
  3414. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3415. sprintf(path, "%s/%s", e_name, j_name);
  3416. lfs_stat(&lfs, path, &info) => 0;
  3417. assert(strcmp(info.name, j_name) == 0);
  3418. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3419. sprintf(path, "%s/%s", e_name, k_name);
  3420. lfs_stat(&lfs, path, &info) => 0;
  3421. assert(strcmp(info.name, k_name) == 0);
  3422. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3423. sprintf(path, "%s/%s", e_name, l_name);
  3424. lfs_stat(&lfs, path, &info) => 0;
  3425. assert(strcmp(info.name, l_name) == 0);
  3426. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3427. sprintf(path, "%s/%s", c_name, a_name);
  3428. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3429. sprintf(path, "%s/%s", c_name, b_name);
  3430. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3431. sprintf(path, "%s/%s", c_name, c_name);
  3432. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3433. sprintf(path, "%s/%s", c_name, d_name);
  3434. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3435. sprintf(path, "%s/%s", c_name, e_name);
  3436. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3437. sprintf(path, "%s/%s", c_name, f_name);
  3438. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3439. // remove paths
  3440. sprintf(path, "%s/%s", e_name, g_name);
  3441. lfs_remove(&lfs, path) => 0;
  3442. sprintf(path, "%s/%s", e_name, h_name);
  3443. lfs_remove(&lfs, path) => 0;
  3444. sprintf(path, "%s/%s", e_name, i_name);
  3445. lfs_remove(&lfs, path) => 0;
  3446. sprintf(path, "%s/%s", e_name, j_name);
  3447. lfs_remove(&lfs, path) => 0;
  3448. sprintf(path, "%s/%s", e_name, k_name);
  3449. lfs_remove(&lfs, path) => 0;
  3450. sprintf(path, "%s/%s", e_name, l_name);
  3451. lfs_remove(&lfs, path) => 0;
  3452. // stat paths
  3453. sprintf(path, "%s/%s", e_name, g_name);
  3454. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3455. sprintf(path, "%s/%s", e_name, h_name);
  3456. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3457. sprintf(path, "%s/%s", e_name, i_name);
  3458. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3459. sprintf(path, "%s/%s", e_name, j_name);
  3460. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3461. sprintf(path, "%s/%s", e_name, k_name);
  3462. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3463. sprintf(path, "%s/%s", e_name, l_name);
  3464. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3465. lfs_unmount(&lfs) => 0;
  3466. '''
  3467. # a quick utf8 test, though utf8 is easy to support
  3468. [cases.test_paths_utf8]
  3469. defines.DIR = [false, true]
  3470. code = '''
  3471. lfs_t lfs;
  3472. lfs_format(&lfs, cfg) => 0;
  3473. lfs_mount(&lfs, cfg) => 0;
  3474. // create paths
  3475. lfs_mkdir(&lfs, "coffee") => 0;
  3476. if (DIR) {
  3477. lfs_mkdir(&lfs, "coffee/dripcoffee") => 0;
  3478. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  3479. lfs_mkdir(&lfs, "coffee/türkkahvesi") => 0;
  3480. lfs_mkdir(&lfs, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀") => 0;
  3481. lfs_mkdir(&lfs, "coffee/càphêđá") => 0;
  3482. lfs_mkdir(&lfs, "coffee/โอเลี้ยง") => 0;
  3483. } else {
  3484. lfs_file_t file;
  3485. lfs_file_open(&lfs, &file, "coffee/dripcoffee",
  3486. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3487. lfs_file_close(&lfs, &file) => 0;
  3488. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  3489. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3490. lfs_file_close(&lfs, &file) => 0;
  3491. lfs_file_open(&lfs, &file, "coffee/türkkahvesi",
  3492. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3493. lfs_file_close(&lfs, &file) => 0;
  3494. lfs_file_open(&lfs, &file, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀",
  3495. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3496. lfs_file_close(&lfs, &file) => 0;
  3497. lfs_file_open(&lfs, &file, "coffee/càphêđá",
  3498. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3499. lfs_file_close(&lfs, &file) => 0;
  3500. lfs_file_open(&lfs, &file, "coffee/โอเลี้ยง",
  3501. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3502. lfs_file_close(&lfs, &file) => 0;
  3503. }
  3504. // stat paths
  3505. struct lfs_info info;
  3506. lfs_stat(&lfs, "coffee/dripcoffee", &info) => 0;
  3507. assert(strcmp(info.name, "dripcoffee") == 0);
  3508. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3509. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  3510. assert(strcmp(info.name, "coldbrew") == 0);
  3511. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3512. lfs_stat(&lfs, "coffee/türkkahvesi", &info) => 0;
  3513. assert(strcmp(info.name, "türkkahvesi") == 0);
  3514. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3515. lfs_stat(&lfs, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀", &info) => 0;
  3516. assert(strcmp(info.name, "ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀") == 0);
  3517. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3518. lfs_stat(&lfs, "coffee/càphêđá", &info) => 0;
  3519. assert(strcmp(info.name, "càphêđá") == 0);
  3520. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3521. lfs_stat(&lfs, "coffee/โอเลี้ยง", &info) => 0;
  3522. assert(strcmp(info.name, "โอเลี้ยง") == 0);
  3523. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3524. // file open paths, only works on files!
  3525. if (DIR) {
  3526. lfs_file_t file;
  3527. lfs_file_open(&lfs, &file, "coffee/dripcoffee",
  3528. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3529. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  3530. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3531. lfs_file_open(&lfs, &file, "coffee/türkkahvesi",
  3532. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3533. lfs_file_open(&lfs, &file, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀",
  3534. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3535. lfs_file_open(&lfs, &file, "coffee/càphêđá",
  3536. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3537. lfs_file_open(&lfs, &file, "coffee/โอเลี้ยง",
  3538. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3539. } else {
  3540. lfs_file_t file;
  3541. lfs_file_open(&lfs, &file, "coffee/dripcoffee",
  3542. LFS_O_RDONLY) => 0;
  3543. lfs_file_close(&lfs, &file) => 0;
  3544. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  3545. LFS_O_RDONLY) => 0;
  3546. lfs_file_close(&lfs, &file) => 0;
  3547. lfs_file_open(&lfs, &file, "coffee/türkkahvesi",
  3548. LFS_O_RDONLY) => 0;
  3549. lfs_file_close(&lfs, &file) => 0;
  3550. lfs_file_open(&lfs, &file, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀",
  3551. LFS_O_RDONLY) => 0;
  3552. lfs_file_close(&lfs, &file) => 0;
  3553. lfs_file_open(&lfs, &file, "coffee/càphêđá",
  3554. LFS_O_RDONLY) => 0;
  3555. lfs_file_close(&lfs, &file) => 0;
  3556. lfs_file_open(&lfs, &file, "coffee/โอเลี้ยง",
  3557. LFS_O_RDONLY) => 0;
  3558. lfs_file_close(&lfs, &file) => 0;
  3559. }
  3560. // dir open paths, only works on dirs!
  3561. if (DIR) {
  3562. lfs_dir_t dir;
  3563. lfs_dir_open(&lfs, &dir, "coffee/dripcoffee") => 0;
  3564. lfs_dir_close(&lfs, &dir) => 0;
  3565. lfs_dir_open(&lfs, &dir, "coffee/coldbrew") => 0;
  3566. lfs_dir_close(&lfs, &dir) => 0;
  3567. lfs_dir_open(&lfs, &dir, "coffee/türkkahvesi") => 0;
  3568. lfs_dir_close(&lfs, &dir) => 0;
  3569. lfs_dir_open(&lfs, &dir, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀") => 0;
  3570. lfs_dir_close(&lfs, &dir) => 0;
  3571. lfs_dir_open(&lfs, &dir, "coffee/càphêđá") => 0;
  3572. lfs_dir_close(&lfs, &dir) => 0;
  3573. lfs_dir_open(&lfs, &dir, "coffee/โอเลี้ยง") => 0;
  3574. lfs_dir_close(&lfs, &dir) => 0;
  3575. } else {
  3576. lfs_dir_t dir;
  3577. lfs_dir_open(&lfs, &dir, "coffee/dripcoffee") => LFS_ERR_NOTDIR;
  3578. lfs_dir_open(&lfs, &dir, "coffee/coldbrew") => LFS_ERR_NOTDIR;
  3579. lfs_dir_open(&lfs, &dir, "coffee/türkkahvesi") => LFS_ERR_NOTDIR;
  3580. lfs_dir_open(&lfs, &dir, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀") => LFS_ERR_NOTDIR;
  3581. lfs_dir_open(&lfs, &dir, "coffee/càphêđá") => LFS_ERR_NOTDIR;
  3582. lfs_dir_open(&lfs, &dir, "coffee/โอเลี้ยง") => LFS_ERR_NOTDIR;
  3583. }
  3584. // rename paths
  3585. lfs_mkdir(&lfs, "caffè") => 0;
  3586. lfs_rename(&lfs,
  3587. "coffee/dripcoffee",
  3588. "caffè/espresso") => 0;
  3589. lfs_rename(&lfs,
  3590. "coffee/coldbrew",
  3591. "caffè/americano") => 0;
  3592. lfs_rename(&lfs,
  3593. "coffee/türkkahvesi",
  3594. "caffè/macchiato") => 0;
  3595. lfs_rename(&lfs,
  3596. "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀",
  3597. "caffè/latte") => 0;
  3598. lfs_rename(&lfs,
  3599. "coffee/càphêđá",
  3600. "caffè/cappuccino") => 0;
  3601. lfs_rename(&lfs,
  3602. "coffee/โอเลี้ยง",
  3603. "caffè/mocha") => 0;
  3604. // stat paths
  3605. lfs_stat(&lfs, "caffè/espresso", &info) => 0;
  3606. assert(strcmp(info.name, "espresso") == 0);
  3607. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3608. lfs_stat(&lfs, "caffè/americano", &info) => 0;
  3609. assert(strcmp(info.name, "americano") == 0);
  3610. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3611. lfs_stat(&lfs, "caffè/macchiato", &info) => 0;
  3612. assert(strcmp(info.name, "macchiato") == 0);
  3613. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3614. lfs_stat(&lfs, "caffè/latte", &info) => 0;
  3615. assert(strcmp(info.name, "latte") == 0);
  3616. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3617. lfs_stat(&lfs, "caffè/cappuccino", &info) => 0;
  3618. assert(strcmp(info.name, "cappuccino") == 0);
  3619. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3620. lfs_stat(&lfs, "caffè/mocha", &info) => 0;
  3621. assert(strcmp(info.name, "mocha") == 0);
  3622. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3623. lfs_stat(&lfs, "coffee/dripcoffee", &info) => LFS_ERR_NOENT;
  3624. lfs_stat(&lfs, "coffee/coldbrew", &info) => LFS_ERR_NOENT;
  3625. lfs_stat(&lfs, "coffee/türkkahvesi", &info) => LFS_ERR_NOENT;
  3626. lfs_stat(&lfs, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀", &info) => LFS_ERR_NOENT;
  3627. lfs_stat(&lfs, "coffee/càphêđá", &info) => LFS_ERR_NOENT;
  3628. lfs_stat(&lfs, "coffee/โอเลี้ยง", &info) => LFS_ERR_NOENT;
  3629. // remove paths
  3630. lfs_remove(&lfs, "caffè/espresso") => 0;
  3631. lfs_remove(&lfs, "caffè/americano") => 0;
  3632. lfs_remove(&lfs, "caffè/macchiato") => 0;
  3633. lfs_remove(&lfs, "caffè/latte") => 0;
  3634. lfs_remove(&lfs, "caffè/cappuccino") => 0;
  3635. lfs_remove(&lfs, "caffè/mocha") => 0;
  3636. // stat paths
  3637. lfs_stat(&lfs, "caffè/espresso", &info) => LFS_ERR_NOENT;
  3638. lfs_stat(&lfs, "caffè/americano", &info) => LFS_ERR_NOENT;
  3639. lfs_stat(&lfs, "caffè/macchiato", &info) => LFS_ERR_NOENT;
  3640. lfs_stat(&lfs, "caffè/latte", &info) => LFS_ERR_NOENT;
  3641. lfs_stat(&lfs, "caffè/cappuccino", &info) => LFS_ERR_NOENT;
  3642. lfs_stat(&lfs, "caffè/mocha", &info) => LFS_ERR_NOENT;
  3643. lfs_unmount(&lfs) => 0;
  3644. '''
  3645. # more utf8 tests
  3646. [cases.test_paths_utf8_ipa]
  3647. defines.DIR = [false, true]
  3648. code = '''
  3649. lfs_t lfs;
  3650. lfs_format(&lfs, cfg) => 0;
  3651. lfs_mount(&lfs, cfg) => 0;
  3652. // create paths
  3653. lfs_mkdir(&lfs, "ˈkɔ.fi") => 0;
  3654. if (DIR) {
  3655. lfs_mkdir(&lfs, "ˈkɔ.fi/dɹɪpˈkɔ.fi") => 0;
  3656. lfs_mkdir(&lfs, "ˈkɔ.fi/koʊldbɹuː") => 0;
  3657. lfs_mkdir(&lfs, "ˈkɔ.fi/tyɾckɑhvɛˈsi") => 0;
  3658. lfs_mkdir(&lfs, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚") => 0;
  3659. lfs_mkdir(&lfs, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥") => 0;
  3660. lfs_mkdir(&lfs, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥") => 0;
  3661. } else {
  3662. lfs_file_t file;
  3663. lfs_file_open(&lfs, &file, "ˈkɔ.fi/dɹɪpˈkɔ.fi",
  3664. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3665. lfs_file_close(&lfs, &file) => 0;
  3666. lfs_file_open(&lfs, &file, "ˈkɔ.fi/koʊldbɹuː",
  3667. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3668. lfs_file_close(&lfs, &file) => 0;
  3669. lfs_file_open(&lfs, &file, "ˈkɔ.fi/tyɾckɑhvɛˈsi",
  3670. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3671. lfs_file_close(&lfs, &file) => 0;
  3672. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚",
  3673. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3674. lfs_file_close(&lfs, &file) => 0;
  3675. lfs_file_open(&lfs, &file, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥",
  3676. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3677. lfs_file_close(&lfs, &file) => 0;
  3678. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥",
  3679. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3680. lfs_file_close(&lfs, &file) => 0;
  3681. }
  3682. // stat paths
  3683. struct lfs_info info;
  3684. lfs_stat(&lfs, "ˈkɔ.fi/dɹɪpˈkɔ.fi", &info) => 0;
  3685. assert(strcmp(info.name, "dɹɪpˈkɔ.fi") == 0);
  3686. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3687. lfs_stat(&lfs, "ˈkɔ.fi/koʊldbɹuː", &info) => 0;
  3688. assert(strcmp(info.name, "koʊldbɹuː") == 0);
  3689. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3690. lfs_stat(&lfs, "ˈkɔ.fi/tyɾckɑhvɛˈsi", &info) => 0;
  3691. assert(strcmp(info.name, "tyɾckɑhvɛˈsi") == 0);
  3692. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3693. lfs_stat(&lfs, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚", &info) => 0;
  3694. assert(strcmp(info.name, "ˈko.piˈt̪up̚.rʊk̚") == 0);
  3695. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3696. lfs_stat(&lfs, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥", &info) => 0;
  3697. assert(strcmp(info.name, "kaː˨˩fe˧˧ɗaː˧˥") == 0);
  3698. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3699. lfs_stat(&lfs, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥", &info) => 0;
  3700. assert(strcmp(info.name, "ʔoː˧.lia̯ŋ˦˥") == 0);
  3701. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3702. // file open paths, only works on files!
  3703. if (DIR) {
  3704. lfs_file_t file;
  3705. lfs_file_open(&lfs, &file, "ˈkɔ.fi/dɹɪpˈkɔ.fi",
  3706. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3707. lfs_file_open(&lfs, &file, "ˈkɔ.fi/koʊldbɹuː",
  3708. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3709. lfs_file_open(&lfs, &file, "ˈkɔ.fi/tyɾckɑhvɛˈsi",
  3710. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3711. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚",
  3712. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3713. lfs_file_open(&lfs, &file, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥",
  3714. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3715. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥",
  3716. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3717. } else {
  3718. lfs_file_t file;
  3719. lfs_file_open(&lfs, &file, "ˈkɔ.fi/dɹɪpˈkɔ.fi",
  3720. LFS_O_RDONLY) => 0;
  3721. lfs_file_close(&lfs, &file) => 0;
  3722. lfs_file_open(&lfs, &file, "ˈkɔ.fi/koʊldbɹuː",
  3723. LFS_O_RDONLY) => 0;
  3724. lfs_file_close(&lfs, &file) => 0;
  3725. lfs_file_open(&lfs, &file, "ˈkɔ.fi/tyɾckɑhvɛˈsi",
  3726. LFS_O_RDONLY) => 0;
  3727. lfs_file_close(&lfs, &file) => 0;
  3728. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚",
  3729. LFS_O_RDONLY) => 0;
  3730. lfs_file_close(&lfs, &file) => 0;
  3731. lfs_file_open(&lfs, &file, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥",
  3732. LFS_O_RDONLY) => 0;
  3733. lfs_file_close(&lfs, &file) => 0;
  3734. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥",
  3735. LFS_O_RDONLY) => 0;
  3736. lfs_file_close(&lfs, &file) => 0;
  3737. }
  3738. // dir open paths, only works on dirs!
  3739. if (DIR) {
  3740. lfs_dir_t dir;
  3741. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/dɹɪpˈkɔ.fi") => 0;
  3742. lfs_dir_close(&lfs, &dir) => 0;
  3743. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/koʊldbɹuː") => 0;
  3744. lfs_dir_close(&lfs, &dir) => 0;
  3745. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/tyɾckɑhvɛˈsi") => 0;
  3746. lfs_dir_close(&lfs, &dir) => 0;
  3747. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚") => 0;
  3748. lfs_dir_close(&lfs, &dir) => 0;
  3749. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥") => 0;
  3750. lfs_dir_close(&lfs, &dir) => 0;
  3751. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥") => 0;
  3752. lfs_dir_close(&lfs, &dir) => 0;
  3753. } else {
  3754. lfs_dir_t dir;
  3755. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/dɹɪpˈkɔ.fi") => LFS_ERR_NOTDIR;
  3756. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/koʊldbɹuː") => LFS_ERR_NOTDIR;
  3757. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/tyɾckɑhvɛˈsi") => LFS_ERR_NOTDIR;
  3758. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚") => LFS_ERR_NOTDIR;
  3759. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥") => LFS_ERR_NOTDIR;
  3760. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥") => LFS_ERR_NOTDIR;
  3761. }
  3762. // rename paths
  3763. lfs_mkdir(&lfs, "kafˈfɛ") => 0;
  3764. lfs_rename(&lfs,
  3765. "ˈkɔ.fi/dɹɪpˈkɔ.fi",
  3766. "kafˈfɛ/eˈsprɛsso") => 0;
  3767. lfs_rename(&lfs,
  3768. "ˈkɔ.fi/koʊldbɹuː",
  3769. "kafˈfɛ/ameriˈkano") => 0;
  3770. lfs_rename(&lfs,
  3771. "ˈkɔ.fi/tyɾckɑhvɛˈsi",
  3772. "kafˈfɛ/makˈkjato") => 0;
  3773. lfs_rename(&lfs,
  3774. "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚",
  3775. "kafˈfɛ/ˈlat.te") => 0;
  3776. lfs_rename(&lfs,
  3777. "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥",
  3778. "kafˈfɛ/kapputˈt͡ʃino") => 0;
  3779. lfs_rename(&lfs,
  3780. "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥",
  3781. "kafˈfɛ/ˈmoʊkə") => 0;
  3782. // stat paths
  3783. lfs_stat(&lfs, "kafˈfɛ/eˈsprɛsso", &info) => 0;
  3784. assert(strcmp(info.name, "eˈsprɛsso") == 0);
  3785. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3786. lfs_stat(&lfs, "kafˈfɛ/ameriˈkano", &info) => 0;
  3787. assert(strcmp(info.name, "ameriˈkano") == 0);
  3788. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3789. lfs_stat(&lfs, "kafˈfɛ/makˈkjato", &info) => 0;
  3790. assert(strcmp(info.name, "makˈkjato") == 0);
  3791. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3792. lfs_stat(&lfs, "kafˈfɛ/ˈlat.te", &info) => 0;
  3793. assert(strcmp(info.name, "ˈlat.te") == 0);
  3794. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3795. lfs_stat(&lfs, "kafˈfɛ/kapputˈt͡ʃino", &info) => 0;
  3796. assert(strcmp(info.name, "kapputˈt͡ʃino") == 0);
  3797. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3798. lfs_stat(&lfs, "kafˈfɛ/ˈmoʊkə", &info) => 0;
  3799. assert(strcmp(info.name, "ˈmoʊkə") == 0);
  3800. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3801. lfs_stat(&lfs, "ˈkɔ.fi/dɹɪpˈkɔ.fi", &info) => LFS_ERR_NOENT;
  3802. lfs_stat(&lfs, "ˈkɔ.fi/koʊldbɹuː", &info) => LFS_ERR_NOENT;
  3803. lfs_stat(&lfs, "ˈkɔ.fi/tyɾckɑhvɛˈsi", &info) => LFS_ERR_NOENT;
  3804. lfs_stat(&lfs, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚", &info) => LFS_ERR_NOENT;
  3805. lfs_stat(&lfs, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥", &info) => LFS_ERR_NOENT;
  3806. lfs_stat(&lfs, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥", &info) => LFS_ERR_NOENT;
  3807. // remove paths
  3808. lfs_remove(&lfs, "kafˈfɛ/eˈsprɛsso") => 0;
  3809. lfs_remove(&lfs, "kafˈfɛ/ameriˈkano") => 0;
  3810. lfs_remove(&lfs, "kafˈfɛ/makˈkjato") => 0;
  3811. lfs_remove(&lfs, "kafˈfɛ/ˈlat.te") => 0;
  3812. lfs_remove(&lfs, "kafˈfɛ/kapputˈt͡ʃino") => 0;
  3813. lfs_remove(&lfs, "kafˈfɛ/ˈmoʊkə") => 0;
  3814. // stat paths
  3815. lfs_stat(&lfs, "kafˈfɛ/eˈsprɛsso", &info) => LFS_ERR_NOENT;
  3816. lfs_stat(&lfs, "kafˈfɛ/ameriˈkano", &info) => LFS_ERR_NOENT;
  3817. lfs_stat(&lfs, "kafˈfɛ/makˈkjato", &info) => LFS_ERR_NOENT;
  3818. lfs_stat(&lfs, "kafˈfɛ/ˈlat.te", &info) => LFS_ERR_NOENT;
  3819. lfs_stat(&lfs, "kafˈfɛ/kapputˈt͡ʃino", &info) => LFS_ERR_NOENT;
  3820. lfs_stat(&lfs, "kafˈfɛ/ˈmoʊkə", &info) => LFS_ERR_NOENT;
  3821. lfs_unmount(&lfs) => 0;
  3822. '''
  3823. # test spaces have no problems
  3824. [cases.test_paths_spaces]
  3825. defines.DIR = [false, true]
  3826. code = '''
  3827. lfs_t lfs;
  3828. lfs_format(&lfs, cfg) => 0;
  3829. lfs_mount(&lfs, cfg) => 0;
  3830. // create paths
  3831. lfs_mkdir(&lfs, "c o f f e e") => 0;
  3832. if (DIR) {
  3833. lfs_mkdir(&lfs, "c o f f e e/d r i p") => 0;
  3834. lfs_mkdir(&lfs, "c o f f e e/c o l d b r e w") => 0;
  3835. lfs_mkdir(&lfs, "c o f f e e/t u r k i s h") => 0;
  3836. lfs_mkdir(&lfs, "c o f f e e/t u b r u k") => 0;
  3837. lfs_mkdir(&lfs, "c o f f e e/v i e t n a m e s e") => 0;
  3838. lfs_mkdir(&lfs, "c o f f e e/t h a i") => 0;
  3839. } else {
  3840. lfs_file_t file;
  3841. lfs_file_open(&lfs, &file, "c o f f e e/d r i p",
  3842. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3843. lfs_file_close(&lfs, &file) => 0;
  3844. lfs_file_open(&lfs, &file, "c o f f e e/c o l d b r e w",
  3845. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3846. lfs_file_close(&lfs, &file) => 0;
  3847. lfs_file_open(&lfs, &file, "c o f f e e/t u r k i s h",
  3848. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3849. lfs_file_close(&lfs, &file) => 0;
  3850. lfs_file_open(&lfs, &file, "c o f f e e/t u b r u k",
  3851. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3852. lfs_file_close(&lfs, &file) => 0;
  3853. lfs_file_open(&lfs, &file, "c o f f e e/v i e t n a m e s e",
  3854. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3855. lfs_file_close(&lfs, &file) => 0;
  3856. lfs_file_open(&lfs, &file, "c o f f e e/t h a i",
  3857. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3858. lfs_file_close(&lfs, &file) => 0;
  3859. }
  3860. // stat paths
  3861. struct lfs_info info;
  3862. lfs_stat(&lfs, "c o f f e e/d r i p", &info) => 0;
  3863. assert(strcmp(info.name, "d r i p") == 0);
  3864. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3865. lfs_stat(&lfs, "c o f f e e/c o l d b r e w", &info) => 0;
  3866. assert(strcmp(info.name, "c o l d b r e w") == 0);
  3867. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3868. lfs_stat(&lfs, "c o f f e e/t u r k i s h", &info) => 0;
  3869. assert(strcmp(info.name, "t u r k i s h") == 0);
  3870. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3871. lfs_stat(&lfs, "c o f f e e/t u b r u k", &info) => 0;
  3872. assert(strcmp(info.name, "t u b r u k") == 0);
  3873. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3874. lfs_stat(&lfs, "c o f f e e/v i e t n a m e s e", &info) => 0;
  3875. assert(strcmp(info.name, "v i e t n a m e s e") == 0);
  3876. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3877. lfs_stat(&lfs, "c o f f e e/t h a i", &info) => 0;
  3878. assert(strcmp(info.name, "t h a i") == 0);
  3879. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3880. // file open paths, only works on files!
  3881. if (DIR) {
  3882. lfs_file_t file;
  3883. lfs_file_open(&lfs, &file, "c o f f e e/d r i p",
  3884. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3885. lfs_file_open(&lfs, &file, "c o f f e e/c o l d b r e w",
  3886. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3887. lfs_file_open(&lfs, &file, "c o f f e e/t u r k i s h",
  3888. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3889. lfs_file_open(&lfs, &file, "c o f f e e/t u b r u k",
  3890. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3891. lfs_file_open(&lfs, &file, "c o f f e e/v i e t n a m e s e",
  3892. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3893. lfs_file_open(&lfs, &file, "c o f f e e/t h a i",
  3894. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3895. } else {
  3896. lfs_file_t file;
  3897. lfs_file_open(&lfs, &file, "c o f f e e/d r i p",
  3898. LFS_O_RDONLY) => 0;
  3899. lfs_file_close(&lfs, &file) => 0;
  3900. lfs_file_open(&lfs, &file, "c o f f e e/c o l d b r e w",
  3901. LFS_O_RDONLY) => 0;
  3902. lfs_file_close(&lfs, &file) => 0;
  3903. lfs_file_open(&lfs, &file, "c o f f e e/t u r k i s h",
  3904. LFS_O_RDONLY) => 0;
  3905. lfs_file_close(&lfs, &file) => 0;
  3906. lfs_file_open(&lfs, &file, "c o f f e e/t u b r u k",
  3907. LFS_O_RDONLY) => 0;
  3908. lfs_file_close(&lfs, &file) => 0;
  3909. lfs_file_open(&lfs, &file, "c o f f e e/v i e t n a m e s e",
  3910. LFS_O_RDONLY) => 0;
  3911. lfs_file_close(&lfs, &file) => 0;
  3912. lfs_file_open(&lfs, &file, "c o f f e e/t h a i",
  3913. LFS_O_RDONLY) => 0;
  3914. lfs_file_close(&lfs, &file) => 0;
  3915. }
  3916. // dir open paths, only works on dirs!
  3917. if (DIR) {
  3918. lfs_dir_t dir;
  3919. lfs_dir_open(&lfs, &dir, "c o f f e e/d r i p") => 0;
  3920. lfs_dir_close(&lfs, &dir) => 0;
  3921. lfs_dir_open(&lfs, &dir, "c o f f e e/c o l d b r e w") => 0;
  3922. lfs_dir_close(&lfs, &dir) => 0;
  3923. lfs_dir_open(&lfs, &dir, "c o f f e e/t u r k i s h") => 0;
  3924. lfs_dir_close(&lfs, &dir) => 0;
  3925. lfs_dir_open(&lfs, &dir, "c o f f e e/t u b r u k") => 0;
  3926. lfs_dir_close(&lfs, &dir) => 0;
  3927. lfs_dir_open(&lfs, &dir, "c o f f e e/v i e t n a m e s e") => 0;
  3928. lfs_dir_close(&lfs, &dir) => 0;
  3929. lfs_dir_open(&lfs, &dir, "c o f f e e/t h a i") => 0;
  3930. lfs_dir_close(&lfs, &dir) => 0;
  3931. } else {
  3932. lfs_dir_t dir;
  3933. lfs_dir_open(&lfs, &dir, "c o f f e e/d r i p") => LFS_ERR_NOTDIR;
  3934. lfs_dir_open(&lfs, &dir, "c o f f e e/c o l d b r e w") => LFS_ERR_NOTDIR;
  3935. lfs_dir_open(&lfs, &dir, "c o f f e e/t u r k i s h") => LFS_ERR_NOTDIR;
  3936. lfs_dir_open(&lfs, &dir, "c o f f e e/t u b r u k") => LFS_ERR_NOTDIR;
  3937. lfs_dir_open(&lfs, &dir, "c o f f e e/v i e t n a m e s e") => LFS_ERR_NOTDIR;
  3938. lfs_dir_open(&lfs, &dir, "c o f f e e/t h a i") => LFS_ERR_NOTDIR;
  3939. }
  3940. // rename paths
  3941. lfs_mkdir(&lfs, "e s p r e s s o") => 0;
  3942. lfs_rename(&lfs,
  3943. "c o f f e e/d r i p",
  3944. "e s p r e s s o/e s p r e s s o") => 0;
  3945. lfs_rename(&lfs,
  3946. "c o f f e e/c o l d b r e w",
  3947. "e s p r e s s o/a m e r i c a n o") => 0;
  3948. lfs_rename(&lfs,
  3949. "c o f f e e/t u r k i s h",
  3950. "e s p r e s s o/m a c c h i a t o") => 0;
  3951. lfs_rename(&lfs,
  3952. "c o f f e e/t u b r u k",
  3953. "e s p r e s s o/l a t t e") => 0;
  3954. lfs_rename(&lfs,
  3955. "c o f f e e/v i e t n a m e s e",
  3956. "e s p r e s s o/c a p p u c c i n o") => 0;
  3957. lfs_rename(&lfs,
  3958. "c o f f e e/t h a i",
  3959. "e s p r e s s o/m o c h a") => 0;
  3960. // stat paths
  3961. lfs_stat(&lfs, "e s p r e s s o/e s p r e s s o", &info) => 0;
  3962. assert(strcmp(info.name, "e s p r e s s o") == 0);
  3963. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3964. lfs_stat(&lfs, "e s p r e s s o/a m e r i c a n o", &info) => 0;
  3965. assert(strcmp(info.name, "a m e r i c a n o") == 0);
  3966. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3967. lfs_stat(&lfs, "e s p r e s s o/m a c c h i a t o", &info) => 0;
  3968. assert(strcmp(info.name, "m a c c h i a t o") == 0);
  3969. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3970. lfs_stat(&lfs, "e s p r e s s o/l a t t e", &info) => 0;
  3971. assert(strcmp(info.name, "l a t t e") == 0);
  3972. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3973. lfs_stat(&lfs, "e s p r e s s o/c a p p u c c i n o", &info) => 0;
  3974. assert(strcmp(info.name, "c a p p u c c i n o") == 0);
  3975. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3976. lfs_stat(&lfs, "e s p r e s s o/m o c h a", &info) => 0;
  3977. assert(strcmp(info.name, "m o c h a") == 0);
  3978. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3979. lfs_stat(&lfs, "c o f f e e/d r i p", &info) => LFS_ERR_NOENT;
  3980. lfs_stat(&lfs, "c o f f e e/c o l d b r e w", &info) => LFS_ERR_NOENT;
  3981. lfs_stat(&lfs, "c o f f e e/t u r k i s h", &info) => LFS_ERR_NOENT;
  3982. lfs_stat(&lfs, "c o f f e e/t u b r u k", &info) => LFS_ERR_NOENT;
  3983. lfs_stat(&lfs, "c o f f e e/v i e t n a m e s e", &info) => LFS_ERR_NOENT;
  3984. lfs_stat(&lfs, "c o f f e e/t h a i", &info) => LFS_ERR_NOENT;
  3985. // remove paths
  3986. lfs_remove(&lfs, "e s p r e s s o/e s p r e s s o") => 0;
  3987. lfs_remove(&lfs, "e s p r e s s o/a m e r i c a n o") => 0;
  3988. lfs_remove(&lfs, "e s p r e s s o/m a c c h i a t o") => 0;
  3989. lfs_remove(&lfs, "e s p r e s s o/l a t t e") => 0;
  3990. lfs_remove(&lfs, "e s p r e s s o/c a p p u c c i n o") => 0;
  3991. lfs_remove(&lfs, "e s p r e s s o/m o c h a") => 0;
  3992. // stat paths
  3993. lfs_stat(&lfs, "e s p r e s s o/e s p r e s s o", &info) => LFS_ERR_NOENT;
  3994. lfs_stat(&lfs, "e s p r e s s o/a m e r i c a n o", &info) => LFS_ERR_NOENT;
  3995. lfs_stat(&lfs, "e s p r e s s o/m a c c h i a t o", &info) => LFS_ERR_NOENT;
  3996. lfs_stat(&lfs, "e s p r e s s o/l a t t e", &info) => LFS_ERR_NOENT;
  3997. 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;
  3998. lfs_stat(&lfs, "e s p r e s s o/m o c h a", &info) => LFS_ERR_NOENT;
  3999. lfs_unmount(&lfs) => 0;
  4000. '''
  4001. # test with only spaces
  4002. #
  4003. # please don't do this
  4004. [cases.test_paths_oopsallspaces]
  4005. defines.DIR = [false, true]
  4006. code = '''
  4007. lfs_t lfs;
  4008. lfs_format(&lfs, cfg) => 0;
  4009. lfs_mount(&lfs, cfg) => 0;
  4010. // create paths
  4011. lfs_mkdir(&lfs, " ") => 0;
  4012. if (DIR) {
  4013. lfs_mkdir(&lfs, " / ") => 0;
  4014. lfs_mkdir(&lfs, " / ") => 0;
  4015. lfs_mkdir(&lfs, " / ") => 0;
  4016. lfs_mkdir(&lfs, " / ") => 0;
  4017. lfs_mkdir(&lfs, " / ") => 0;
  4018. lfs_mkdir(&lfs, " / ") => 0;
  4019. } else {
  4020. lfs_file_t file;
  4021. lfs_file_open(&lfs, &file, " / ",
  4022. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4023. lfs_file_close(&lfs, &file) => 0;
  4024. lfs_file_open(&lfs, &file, " / ",
  4025. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4026. lfs_file_close(&lfs, &file) => 0;
  4027. lfs_file_open(&lfs, &file, " / ",
  4028. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4029. lfs_file_close(&lfs, &file) => 0;
  4030. lfs_file_open(&lfs, &file, " / ",
  4031. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4032. lfs_file_close(&lfs, &file) => 0;
  4033. lfs_file_open(&lfs, &file, " / ",
  4034. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4035. lfs_file_close(&lfs, &file) => 0;
  4036. lfs_file_open(&lfs, &file, " / ",
  4037. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4038. lfs_file_close(&lfs, &file) => 0;
  4039. }
  4040. // stat paths
  4041. struct lfs_info info;
  4042. lfs_stat(&lfs, " / ", &info) => 0;
  4043. assert(strcmp(info.name, " ") == 0);
  4044. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4045. lfs_stat(&lfs, " / ", &info) => 0;
  4046. assert(strcmp(info.name, " ") == 0);
  4047. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4048. lfs_stat(&lfs, " / ", &info) => 0;
  4049. assert(strcmp(info.name, " ") == 0);
  4050. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4051. lfs_stat(&lfs, " / ", &info) => 0;
  4052. assert(strcmp(info.name, " ") == 0);
  4053. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4054. lfs_stat(&lfs, " / ", &info) => 0;
  4055. assert(strcmp(info.name, " ") == 0);
  4056. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4057. lfs_stat(&lfs, " / ", &info) => 0;
  4058. assert(strcmp(info.name, " ") == 0);
  4059. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4060. // file open paths, only works on files!
  4061. if (DIR) {
  4062. lfs_file_t file;
  4063. lfs_file_open(&lfs, &file, " / ",
  4064. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4065. lfs_file_open(&lfs, &file, " / ",
  4066. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4067. lfs_file_open(&lfs, &file, " / ",
  4068. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4069. lfs_file_open(&lfs, &file, " / ",
  4070. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4071. lfs_file_open(&lfs, &file, " / ",
  4072. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4073. lfs_file_open(&lfs, &file, " / ",
  4074. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4075. } else {
  4076. lfs_file_t file;
  4077. lfs_file_open(&lfs, &file, " / ",
  4078. LFS_O_RDONLY) => 0;
  4079. lfs_file_close(&lfs, &file) => 0;
  4080. lfs_file_open(&lfs, &file, " / ",
  4081. LFS_O_RDONLY) => 0;
  4082. lfs_file_close(&lfs, &file) => 0;
  4083. lfs_file_open(&lfs, &file, " / ",
  4084. LFS_O_RDONLY) => 0;
  4085. lfs_file_close(&lfs, &file) => 0;
  4086. lfs_file_open(&lfs, &file, " / ",
  4087. LFS_O_RDONLY) => 0;
  4088. lfs_file_close(&lfs, &file) => 0;
  4089. lfs_file_open(&lfs, &file, " / ",
  4090. LFS_O_RDONLY) => 0;
  4091. lfs_file_close(&lfs, &file) => 0;
  4092. lfs_file_open(&lfs, &file, " / ",
  4093. LFS_O_RDONLY) => 0;
  4094. lfs_file_close(&lfs, &file) => 0;
  4095. }
  4096. // dir open paths, only works on dirs!
  4097. if (DIR) {
  4098. lfs_dir_t dir;
  4099. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4100. lfs_dir_close(&lfs, &dir) => 0;
  4101. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4102. lfs_dir_close(&lfs, &dir) => 0;
  4103. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4104. lfs_dir_close(&lfs, &dir) => 0;
  4105. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4106. lfs_dir_close(&lfs, &dir) => 0;
  4107. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4108. lfs_dir_close(&lfs, &dir) => 0;
  4109. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4110. lfs_dir_close(&lfs, &dir) => 0;
  4111. } else {
  4112. lfs_dir_t dir;
  4113. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4114. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4115. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4116. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4117. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4118. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4119. }
  4120. // rename paths
  4121. lfs_mkdir(&lfs, " ") => 0;
  4122. lfs_rename(&lfs,
  4123. " / ",
  4124. " / ") => 0;
  4125. lfs_rename(&lfs,
  4126. " / ",
  4127. " / ") => 0;
  4128. lfs_rename(&lfs,
  4129. " / ",
  4130. " / ") => 0;
  4131. lfs_rename(&lfs,
  4132. " / ",
  4133. " / ") => 0;
  4134. lfs_rename(&lfs,
  4135. " / ",
  4136. " / ") => 0;
  4137. lfs_rename(&lfs,
  4138. " / ",
  4139. " / ") => 0;
  4140. // stat paths
  4141. lfs_stat(&lfs, " / ", &info) => 0;
  4142. assert(strcmp(info.name, " ") == 0);
  4143. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4144. lfs_stat(&lfs, " / ", &info) => 0;
  4145. assert(strcmp(info.name, " ") == 0);
  4146. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4147. lfs_stat(&lfs, " / ", &info) => 0;
  4148. assert(strcmp(info.name, " ") == 0);
  4149. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4150. lfs_stat(&lfs, " / ", &info) => 0;
  4151. assert(strcmp(info.name, " ") == 0);
  4152. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4153. lfs_stat(&lfs, " / ", &info) => 0;
  4154. assert(strcmp(info.name, " ") == 0);
  4155. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4156. lfs_stat(&lfs, " / ", &info) => 0;
  4157. assert(strcmp(info.name, " ") == 0);
  4158. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4159. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4160. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4161. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4162. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4163. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4164. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4165. // remove paths
  4166. lfs_remove(&lfs, " / ") => 0;
  4167. lfs_remove(&lfs, " / ") => 0;
  4168. lfs_remove(&lfs, " / ") => 0;
  4169. lfs_remove(&lfs, " / ") => 0;
  4170. lfs_remove(&lfs, " / ") => 0;
  4171. lfs_remove(&lfs, " / ") => 0;
  4172. // stat paths
  4173. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4174. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4175. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4176. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4177. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4178. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4179. lfs_unmount(&lfs) => 0;
  4180. '''
  4181. # test with only ascii control characters
  4182. #
  4183. # littlefs only cares about "./" and NULL
  4184. [cases.test_paths_nonprintable]
  4185. defines.DIR = [false, true]
  4186. code = '''
  4187. lfs_t lfs;
  4188. lfs_format(&lfs, cfg) => 0;
  4189. lfs_mount(&lfs, cfg) => 0;
  4190. // create paths
  4191. lfs_mkdir(&lfs, "\x0c") => 0;
  4192. if (DIR) {
  4193. lfs_mkdir(&lfs, "\x0c/\x01") => 0;
  4194. lfs_mkdir(&lfs, "\x0c/\x02") => 0;
  4195. lfs_mkdir(&lfs, "\x0c/\x03") => 0;
  4196. lfs_mkdir(&lfs, "\x0c/\x04") => 0;
  4197. lfs_mkdir(&lfs, "\x0c/\x05") => 0;
  4198. lfs_mkdir(&lfs, "\x0c/\x06") => 0;
  4199. } else {
  4200. lfs_file_t file;
  4201. lfs_file_open(&lfs, &file, "\x0c/\x01",
  4202. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4203. lfs_file_close(&lfs, &file) => 0;
  4204. lfs_file_open(&lfs, &file, "\x0c/\x02",
  4205. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4206. lfs_file_close(&lfs, &file) => 0;
  4207. lfs_file_open(&lfs, &file, "\x0c/\x03",
  4208. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4209. lfs_file_close(&lfs, &file) => 0;
  4210. lfs_file_open(&lfs, &file, "\x0c/\x04",
  4211. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4212. lfs_file_close(&lfs, &file) => 0;
  4213. lfs_file_open(&lfs, &file, "\x0c/\x05",
  4214. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4215. lfs_file_close(&lfs, &file) => 0;
  4216. lfs_file_open(&lfs, &file, "\x0c/\x06",
  4217. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4218. lfs_file_close(&lfs, &file) => 0;
  4219. }
  4220. // stat paths
  4221. struct lfs_info info;
  4222. lfs_stat(&lfs, "\x0c/\x01", &info) => 0;
  4223. assert(strcmp(info.name, "\x01") == 0);
  4224. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4225. lfs_stat(&lfs, "\x0c/\x02", &info) => 0;
  4226. assert(strcmp(info.name, "\x02") == 0);
  4227. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4228. lfs_stat(&lfs, "\x0c/\x03", &info) => 0;
  4229. assert(strcmp(info.name, "\x03") == 0);
  4230. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4231. lfs_stat(&lfs, "\x0c/\x04", &info) => 0;
  4232. assert(strcmp(info.name, "\x04") == 0);
  4233. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4234. lfs_stat(&lfs, "\x0c/\x05", &info) => 0;
  4235. assert(strcmp(info.name, "\x05") == 0);
  4236. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4237. lfs_stat(&lfs, "\x0c/\x06", &info) => 0;
  4238. assert(strcmp(info.name, "\x06") == 0);
  4239. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4240. // file open paths, only works on files!
  4241. if (DIR) {
  4242. lfs_file_t file;
  4243. lfs_file_open(&lfs, &file, "\x0c/\x01",
  4244. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4245. lfs_file_open(&lfs, &file, "\x0c/\x02",
  4246. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4247. lfs_file_open(&lfs, &file, "\x0c/\x03",
  4248. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4249. lfs_file_open(&lfs, &file, "\x0c/\x04",
  4250. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4251. lfs_file_open(&lfs, &file, "\x0c/\x05",
  4252. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4253. lfs_file_open(&lfs, &file, "\x0c/\x06",
  4254. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4255. } else {
  4256. lfs_file_t file;
  4257. lfs_file_open(&lfs, &file, "\x0c/\x01",
  4258. LFS_O_RDONLY) => 0;
  4259. lfs_file_close(&lfs, &file) => 0;
  4260. lfs_file_open(&lfs, &file, "\x0c/\x02",
  4261. LFS_O_RDONLY) => 0;
  4262. lfs_file_close(&lfs, &file) => 0;
  4263. lfs_file_open(&lfs, &file, "\x0c/\x03",
  4264. LFS_O_RDONLY) => 0;
  4265. lfs_file_close(&lfs, &file) => 0;
  4266. lfs_file_open(&lfs, &file, "\x0c/\x04",
  4267. LFS_O_RDONLY) => 0;
  4268. lfs_file_close(&lfs, &file) => 0;
  4269. lfs_file_open(&lfs, &file, "\x0c/\x05",
  4270. LFS_O_RDONLY) => 0;
  4271. lfs_file_close(&lfs, &file) => 0;
  4272. lfs_file_open(&lfs, &file, "\x0c/\x06",
  4273. LFS_O_RDONLY) => 0;
  4274. lfs_file_close(&lfs, &file) => 0;
  4275. }
  4276. // dir open paths, only works on dirs!
  4277. if (DIR) {
  4278. lfs_dir_t dir;
  4279. lfs_dir_open(&lfs, &dir, "\x0c/\x01") => 0;
  4280. lfs_dir_close(&lfs, &dir) => 0;
  4281. lfs_dir_open(&lfs, &dir, "\x0c/\x02") => 0;
  4282. lfs_dir_close(&lfs, &dir) => 0;
  4283. lfs_dir_open(&lfs, &dir, "\x0c/\x03") => 0;
  4284. lfs_dir_close(&lfs, &dir) => 0;
  4285. lfs_dir_open(&lfs, &dir, "\x0c/\x04") => 0;
  4286. lfs_dir_close(&lfs, &dir) => 0;
  4287. lfs_dir_open(&lfs, &dir, "\x0c/\x05") => 0;
  4288. lfs_dir_close(&lfs, &dir) => 0;
  4289. lfs_dir_open(&lfs, &dir, "\x0c/\x06") => 0;
  4290. lfs_dir_close(&lfs, &dir) => 0;
  4291. } else {
  4292. lfs_dir_t dir;
  4293. lfs_dir_open(&lfs, &dir, "\x0c/\x01") => LFS_ERR_NOTDIR;
  4294. lfs_dir_open(&lfs, &dir, "\x0c/\x02") => LFS_ERR_NOTDIR;
  4295. lfs_dir_open(&lfs, &dir, "\x0c/\x03") => LFS_ERR_NOTDIR;
  4296. lfs_dir_open(&lfs, &dir, "\x0c/\x04") => LFS_ERR_NOTDIR;
  4297. lfs_dir_open(&lfs, &dir, "\x0c/\x05") => LFS_ERR_NOTDIR;
  4298. lfs_dir_open(&lfs, &dir, "\x0c/\x06") => LFS_ERR_NOTDIR;
  4299. }
  4300. // rename paths
  4301. lfs_mkdir(&lfs, "\x0e") => 0;
  4302. lfs_rename(&lfs,
  4303. "\x0c/\x01",
  4304. "\x0e/\x1a") => 0;
  4305. lfs_rename(&lfs,
  4306. "\x0c/\x02",
  4307. "\x0e/\x1b") => 0;
  4308. lfs_rename(&lfs,
  4309. "\x0c/\x03",
  4310. "\x0e/\x1c") => 0;
  4311. lfs_rename(&lfs,
  4312. "\x0c/\x04",
  4313. "\x0e/\x1d") => 0;
  4314. lfs_rename(&lfs,
  4315. "\x0c/\x05",
  4316. "\x0e/\x1e") => 0;
  4317. lfs_rename(&lfs,
  4318. "\x0c/\x06",
  4319. "\x0e/\x1f") => 0;
  4320. // stat paths
  4321. lfs_stat(&lfs, "\x0e/\x1a", &info) => 0;
  4322. assert(strcmp(info.name, "\x1a") == 0);
  4323. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4324. lfs_stat(&lfs, "\x0e/\x1b", &info) => 0;
  4325. assert(strcmp(info.name, "\x1b") == 0);
  4326. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4327. lfs_stat(&lfs, "\x0e/\x1c", &info) => 0;
  4328. assert(strcmp(info.name, "\x1c") == 0);
  4329. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4330. lfs_stat(&lfs, "\x0e/\x1d", &info) => 0;
  4331. assert(strcmp(info.name, "\x1d") == 0);
  4332. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4333. lfs_stat(&lfs, "\x0e/\x1e", &info) => 0;
  4334. assert(strcmp(info.name, "\x1e") == 0);
  4335. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4336. lfs_stat(&lfs, "\x0e/\x1f", &info) => 0;
  4337. assert(strcmp(info.name, "\x1f") == 0);
  4338. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4339. lfs_stat(&lfs, "\x0c/\x01", &info) => LFS_ERR_NOENT;
  4340. lfs_stat(&lfs, "\x0c/\x02", &info) => LFS_ERR_NOENT;
  4341. lfs_stat(&lfs, "\x0c/\x03", &info) => LFS_ERR_NOENT;
  4342. lfs_stat(&lfs, "\x0c/\x04", &info) => LFS_ERR_NOENT;
  4343. lfs_stat(&lfs, "\x0c/\x05", &info) => LFS_ERR_NOENT;
  4344. lfs_stat(&lfs, "\x0c/\x06", &info) => LFS_ERR_NOENT;
  4345. // remove paths
  4346. lfs_remove(&lfs, "\x0e/\x1a") => 0;
  4347. lfs_remove(&lfs, "\x0e/\x1b") => 0;
  4348. lfs_remove(&lfs, "\x0e/\x1c") => 0;
  4349. lfs_remove(&lfs, "\x0e/\x1d") => 0;
  4350. lfs_remove(&lfs, "\x0e/\x1e") => 0;
  4351. lfs_remove(&lfs, "\x0e/\x1f") => 0;
  4352. // stat paths
  4353. lfs_stat(&lfs, "\x0e/\x1a", &info) => LFS_ERR_NOENT;
  4354. lfs_stat(&lfs, "\x0e/\x1b", &info) => LFS_ERR_NOENT;
  4355. lfs_stat(&lfs, "\x0e/\x1c", &info) => LFS_ERR_NOENT;
  4356. lfs_stat(&lfs, "\x0e/\x1d", &info) => LFS_ERR_NOENT;
  4357. lfs_stat(&lfs, "\x0e/\x1e", &info) => LFS_ERR_NOENT;
  4358. lfs_stat(&lfs, "\x0e/\x1f", &info) => LFS_ERR_NOENT;
  4359. lfs_unmount(&lfs) => 0;
  4360. '''
  4361. # test with only ascii DELs
  4362. #
  4363. # I don't know why you'd do this
  4364. [cases.test_paths_oopsalldels]
  4365. defines.DIR = [false, true]
  4366. code = '''
  4367. lfs_t lfs;
  4368. lfs_format(&lfs, cfg) => 0;
  4369. lfs_mount(&lfs, cfg) => 0;
  4370. // create paths
  4371. lfs_mkdir(&lfs, "\x7f") => 0;
  4372. if (DIR) {
  4373. lfs_mkdir(&lfs, "\x7f/\x7f") => 0;
  4374. lfs_mkdir(&lfs, "\x7f/\x7f\x7f") => 0;
  4375. lfs_mkdir(&lfs, "\x7f/\x7f\x7f\x7f") => 0;
  4376. lfs_mkdir(&lfs, "\x7f/\x7f\x7f\x7f\x7f") => 0;
  4377. lfs_mkdir(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f") => 0;
  4378. lfs_mkdir(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4379. } else {
  4380. lfs_file_t file;
  4381. lfs_file_open(&lfs, &file, "\x7f/\x7f",
  4382. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4383. lfs_file_close(&lfs, &file) => 0;
  4384. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f",
  4385. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4386. lfs_file_close(&lfs, &file) => 0;
  4387. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f",
  4388. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4389. lfs_file_close(&lfs, &file) => 0;
  4390. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f",
  4391. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4392. lfs_file_close(&lfs, &file) => 0;
  4393. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f",
  4394. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4395. lfs_file_close(&lfs, &file) => 0;
  4396. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f",
  4397. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4398. lfs_file_close(&lfs, &file) => 0;
  4399. }
  4400. // stat paths
  4401. struct lfs_info info;
  4402. lfs_stat(&lfs, "\x7f/\x7f", &info) => 0;
  4403. assert(strcmp(info.name, "\x7f") == 0);
  4404. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4405. lfs_stat(&lfs, "\x7f/\x7f\x7f", &info) => 0;
  4406. assert(strcmp(info.name, "\x7f\x7f") == 0);
  4407. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4408. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f", &info) => 0;
  4409. assert(strcmp(info.name, "\x7f\x7f\x7f") == 0);
  4410. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4411. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f", &info) => 0;
  4412. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f") == 0);
  4413. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4414. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4415. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f") == 0);
  4416. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4417. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4418. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4419. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4420. // file open paths, only works on files!
  4421. if (DIR) {
  4422. lfs_file_t file;
  4423. lfs_file_open(&lfs, &file, "\x7f/\x7f",
  4424. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4425. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f",
  4426. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4427. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f",
  4428. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4429. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f",
  4430. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4431. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f",
  4432. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4433. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f",
  4434. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4435. } else {
  4436. lfs_file_t file;
  4437. lfs_file_open(&lfs, &file, "\x7f/\x7f",
  4438. LFS_O_RDONLY) => 0;
  4439. lfs_file_close(&lfs, &file) => 0;
  4440. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f",
  4441. LFS_O_RDONLY) => 0;
  4442. lfs_file_close(&lfs, &file) => 0;
  4443. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f",
  4444. LFS_O_RDONLY) => 0;
  4445. lfs_file_close(&lfs, &file) => 0;
  4446. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f",
  4447. LFS_O_RDONLY) => 0;
  4448. lfs_file_close(&lfs, &file) => 0;
  4449. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f",
  4450. LFS_O_RDONLY) => 0;
  4451. lfs_file_close(&lfs, &file) => 0;
  4452. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f",
  4453. LFS_O_RDONLY) => 0;
  4454. lfs_file_close(&lfs, &file) => 0;
  4455. }
  4456. // dir open paths, only works on dirs!
  4457. if (DIR) {
  4458. lfs_dir_t dir;
  4459. lfs_dir_open(&lfs, &dir, "\x7f/\x7f") => 0;
  4460. lfs_dir_close(&lfs, &dir) => 0;
  4461. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f") => 0;
  4462. lfs_dir_close(&lfs, &dir) => 0;
  4463. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f") => 0;
  4464. lfs_dir_close(&lfs, &dir) => 0;
  4465. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f") => 0;
  4466. lfs_dir_close(&lfs, &dir) => 0;
  4467. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f\x7f") => 0;
  4468. lfs_dir_close(&lfs, &dir) => 0;
  4469. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4470. lfs_dir_close(&lfs, &dir) => 0;
  4471. } else {
  4472. lfs_dir_t dir;
  4473. lfs_dir_open(&lfs, &dir, "\x7f/\x7f") => LFS_ERR_NOTDIR;
  4474. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f") => LFS_ERR_NOTDIR;
  4475. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f") => LFS_ERR_NOTDIR;
  4476. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f") => LFS_ERR_NOTDIR;
  4477. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f\x7f") => LFS_ERR_NOTDIR;
  4478. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f") => LFS_ERR_NOTDIR;
  4479. }
  4480. // rename paths
  4481. lfs_mkdir(&lfs, "\x7f\x7f") => 0;
  4482. lfs_rename(&lfs,
  4483. "\x7f/\x7f",
  4484. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4485. lfs_rename(&lfs,
  4486. "\x7f/\x7f\x7f",
  4487. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4488. lfs_rename(&lfs,
  4489. "\x7f/\x7f\x7f\x7f",
  4490. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4491. lfs_rename(&lfs,
  4492. "\x7f/\x7f\x7f\x7f\x7f",
  4493. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4494. lfs_rename(&lfs,
  4495. "\x7f/\x7f\x7f\x7f\x7f\x7f",
  4496. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4497. lfs_rename(&lfs,
  4498. "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f",
  4499. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4500. // stat paths
  4501. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4502. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4503. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4504. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4505. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4506. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4507. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4508. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4509. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4510. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4511. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4512. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4513. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4514. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4515. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4516. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4517. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4518. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4519. lfs_stat(&lfs, "\x7f/\x7f", &info) => LFS_ERR_NOENT;
  4520. lfs_stat(&lfs, "\x7f/\x7f\x7f", &info) => LFS_ERR_NOENT;
  4521. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4522. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4523. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4524. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4525. // remove paths
  4526. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4527. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4528. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4529. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4530. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4531. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4532. // stat paths
  4533. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4534. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4535. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4536. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4537. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4538. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4539. lfs_unmount(&lfs) => 0;
  4540. '''
  4541. # test with invalid utf8 sequences
  4542. #
  4543. # Don't do this! These filenames are not utf8 and will probably break
  4544. # external tools.
  4545. #
  4546. [cases.test_paths_nonutf8]
  4547. defines.DIR = [false, true]
  4548. code = '''
  4549. lfs_t lfs;
  4550. lfs_format(&lfs, cfg) => 0;
  4551. lfs_mount(&lfs, cfg) => 0;
  4552. // create paths
  4553. lfs_mkdir(&lfs, "\xc0") => 0;
  4554. if (DIR) {
  4555. lfs_mkdir(&lfs, "\xc0/\xa0") => 0;
  4556. lfs_mkdir(&lfs, "\xc0/\xb0") => 0;
  4557. lfs_mkdir(&lfs, "\xc0/\xc0") => 0;
  4558. lfs_mkdir(&lfs, "\xc0/\xd0") => 0;
  4559. lfs_mkdir(&lfs, "\xc0/\xe0") => 0;
  4560. lfs_mkdir(&lfs, "\xc0/\xf0") => 0;
  4561. } else {
  4562. lfs_file_t file;
  4563. lfs_file_open(&lfs, &file, "\xc0/\xa0",
  4564. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4565. lfs_file_close(&lfs, &file) => 0;
  4566. lfs_file_open(&lfs, &file, "\xc0/\xb0",
  4567. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4568. lfs_file_close(&lfs, &file) => 0;
  4569. lfs_file_open(&lfs, &file, "\xc0/\xc0",
  4570. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4571. lfs_file_close(&lfs, &file) => 0;
  4572. lfs_file_open(&lfs, &file, "\xc0/\xd0",
  4573. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4574. lfs_file_close(&lfs, &file) => 0;
  4575. lfs_file_open(&lfs, &file, "\xc0/\xe0",
  4576. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4577. lfs_file_close(&lfs, &file) => 0;
  4578. lfs_file_open(&lfs, &file, "\xc0/\xf0",
  4579. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4580. lfs_file_close(&lfs, &file) => 0;
  4581. }
  4582. // stat paths
  4583. struct lfs_info info;
  4584. lfs_stat(&lfs, "\xc0/\xa0", &info) => 0;
  4585. assert(strcmp(info.name, "\xa0") == 0);
  4586. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4587. lfs_stat(&lfs, "\xc0/\xb0", &info) => 0;
  4588. assert(strcmp(info.name, "\xb0") == 0);
  4589. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4590. lfs_stat(&lfs, "\xc0/\xc0", &info) => 0;
  4591. assert(strcmp(info.name, "\xc0") == 0);
  4592. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4593. lfs_stat(&lfs, "\xc0/\xd0", &info) => 0;
  4594. assert(strcmp(info.name, "\xd0") == 0);
  4595. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4596. lfs_stat(&lfs, "\xc0/\xe0", &info) => 0;
  4597. assert(strcmp(info.name, "\xe0") == 0);
  4598. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4599. lfs_stat(&lfs, "\xc0/\xf0", &info) => 0;
  4600. assert(strcmp(info.name, "\xf0") == 0);
  4601. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4602. // file open paths, only works on files!
  4603. if (DIR) {
  4604. lfs_file_t file;
  4605. lfs_file_open(&lfs, &file, "\xc0/\xa0",
  4606. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4607. lfs_file_open(&lfs, &file, "\xc0/\xb0",
  4608. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4609. lfs_file_open(&lfs, &file, "\xc0/\xc0",
  4610. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4611. lfs_file_open(&lfs, &file, "\xc0/\xd0",
  4612. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4613. lfs_file_open(&lfs, &file, "\xc0/\xe0",
  4614. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4615. lfs_file_open(&lfs, &file, "\xc0/\xf0",
  4616. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4617. } else {
  4618. lfs_file_t file;
  4619. lfs_file_open(&lfs, &file, "\xc0/\xa0",
  4620. LFS_O_RDONLY) => 0;
  4621. lfs_file_close(&lfs, &file) => 0;
  4622. lfs_file_open(&lfs, &file, "\xc0/\xb0",
  4623. LFS_O_RDONLY) => 0;
  4624. lfs_file_close(&lfs, &file) => 0;
  4625. lfs_file_open(&lfs, &file, "\xc0/\xc0",
  4626. LFS_O_RDONLY) => 0;
  4627. lfs_file_close(&lfs, &file) => 0;
  4628. lfs_file_open(&lfs, &file, "\xc0/\xd0",
  4629. LFS_O_RDONLY) => 0;
  4630. lfs_file_close(&lfs, &file) => 0;
  4631. lfs_file_open(&lfs, &file, "\xc0/\xe0",
  4632. LFS_O_RDONLY) => 0;
  4633. lfs_file_close(&lfs, &file) => 0;
  4634. lfs_file_open(&lfs, &file, "\xc0/\xf0",
  4635. LFS_O_RDONLY) => 0;
  4636. lfs_file_close(&lfs, &file) => 0;
  4637. }
  4638. // dir open paths, only works on dirs!
  4639. if (DIR) {
  4640. lfs_dir_t dir;
  4641. lfs_dir_open(&lfs, &dir, "\xc0/\xa0") => 0;
  4642. lfs_dir_close(&lfs, &dir) => 0;
  4643. lfs_dir_open(&lfs, &dir, "\xc0/\xb0") => 0;
  4644. lfs_dir_close(&lfs, &dir) => 0;
  4645. lfs_dir_open(&lfs, &dir, "\xc0/\xc0") => 0;
  4646. lfs_dir_close(&lfs, &dir) => 0;
  4647. lfs_dir_open(&lfs, &dir, "\xc0/\xd0") => 0;
  4648. lfs_dir_close(&lfs, &dir) => 0;
  4649. lfs_dir_open(&lfs, &dir, "\xc0/\xe0") => 0;
  4650. lfs_dir_close(&lfs, &dir) => 0;
  4651. lfs_dir_open(&lfs, &dir, "\xc0/\xf0") => 0;
  4652. lfs_dir_close(&lfs, &dir) => 0;
  4653. } else {
  4654. lfs_dir_t dir;
  4655. lfs_dir_open(&lfs, &dir, "\xc0/\xa0") => LFS_ERR_NOTDIR;
  4656. lfs_dir_open(&lfs, &dir, "\xc0/\xb0") => LFS_ERR_NOTDIR;
  4657. lfs_dir_open(&lfs, &dir, "\xc0/\xc0") => LFS_ERR_NOTDIR;
  4658. lfs_dir_open(&lfs, &dir, "\xc0/\xd0") => LFS_ERR_NOTDIR;
  4659. lfs_dir_open(&lfs, &dir, "\xc0/\xe0") => LFS_ERR_NOTDIR;
  4660. lfs_dir_open(&lfs, &dir, "\xc0/\xf0") => LFS_ERR_NOTDIR;
  4661. }
  4662. // rename paths
  4663. lfs_mkdir(&lfs, "\xe0") => 0;
  4664. lfs_rename(&lfs,
  4665. "\xc0/\xa0",
  4666. "\xe0/\xaf") => 0;
  4667. lfs_rename(&lfs,
  4668. "\xc0/\xb0",
  4669. "\xe0/\xbf") => 0;
  4670. lfs_rename(&lfs,
  4671. "\xc0/\xc0",
  4672. "\xe0/\xcf") => 0;
  4673. lfs_rename(&lfs,
  4674. "\xc0/\xd0",
  4675. "\xe0/\xdf") => 0;
  4676. lfs_rename(&lfs,
  4677. "\xc0/\xe0",
  4678. "\xe0/\xef") => 0;
  4679. lfs_rename(&lfs,
  4680. "\xc0/\xf0",
  4681. "\xe0/\xff") => 0;
  4682. // stat paths
  4683. lfs_stat(&lfs, "\xe0/\xaf", &info) => 0;
  4684. assert(strcmp(info.name, "\xaf") == 0);
  4685. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4686. lfs_stat(&lfs, "\xe0/\xbf", &info) => 0;
  4687. assert(strcmp(info.name, "\xbf") == 0);
  4688. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4689. lfs_stat(&lfs, "\xe0/\xcf", &info) => 0;
  4690. assert(strcmp(info.name, "\xcf") == 0);
  4691. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4692. lfs_stat(&lfs, "\xe0/\xdf", &info) => 0;
  4693. assert(strcmp(info.name, "\xdf") == 0);
  4694. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4695. lfs_stat(&lfs, "\xe0/\xef", &info) => 0;
  4696. assert(strcmp(info.name, "\xef") == 0);
  4697. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4698. lfs_stat(&lfs, "\xe0/\xff", &info) => 0;
  4699. assert(strcmp(info.name, "\xff") == 0);
  4700. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4701. lfs_stat(&lfs, "\xc0/\xa0", &info) => LFS_ERR_NOENT;
  4702. lfs_stat(&lfs, "\xc0/\xb0", &info) => LFS_ERR_NOENT;
  4703. lfs_stat(&lfs, "\xc0/\xc0", &info) => LFS_ERR_NOENT;
  4704. lfs_stat(&lfs, "\xc0/\xd0", &info) => LFS_ERR_NOENT;
  4705. lfs_stat(&lfs, "\xc0/\xe0", &info) => LFS_ERR_NOENT;
  4706. lfs_stat(&lfs, "\xc0/\xf0", &info) => LFS_ERR_NOENT;
  4707. // remove paths
  4708. lfs_remove(&lfs, "\xe0/\xaf") => 0;
  4709. lfs_remove(&lfs, "\xe0/\xbf") => 0;
  4710. lfs_remove(&lfs, "\xe0/\xcf") => 0;
  4711. lfs_remove(&lfs, "\xe0/\xdf") => 0;
  4712. lfs_remove(&lfs, "\xe0/\xef") => 0;
  4713. lfs_remove(&lfs, "\xe0/\xff") => 0;
  4714. // stat paths
  4715. lfs_stat(&lfs, "\xe0/\xaf", &info) => LFS_ERR_NOENT;
  4716. lfs_stat(&lfs, "\xe0/\xbf", &info) => LFS_ERR_NOENT;
  4717. lfs_stat(&lfs, "\xe0/\xcf", &info) => LFS_ERR_NOENT;
  4718. lfs_stat(&lfs, "\xe0/\xdf", &info) => LFS_ERR_NOENT;
  4719. lfs_stat(&lfs, "\xe0/\xef", &info) => LFS_ERR_NOENT;
  4720. lfs_stat(&lfs, "\xe0/\xff", &info) => LFS_ERR_NOENT;
  4721. lfs_unmount(&lfs) => 0;
  4722. '''
  4723. # test with only "\xff" characters
  4724. #
  4725. # Don't do this! These filenames are not utf8 and will probably break
  4726. # external tools.
  4727. #
  4728. [cases.test_paths_oopsallffs]
  4729. defines.DIR = [false, true]
  4730. code = '''
  4731. lfs_t lfs;
  4732. lfs_format(&lfs, cfg) => 0;
  4733. lfs_mount(&lfs, cfg) => 0;
  4734. // create paths
  4735. lfs_mkdir(&lfs, "\xff") => 0;
  4736. if (DIR) {
  4737. lfs_mkdir(&lfs, "\xff/\xff") => 0;
  4738. lfs_mkdir(&lfs, "\xff/\xff\xff") => 0;
  4739. lfs_mkdir(&lfs, "\xff/\xff\xff\xff") => 0;
  4740. lfs_mkdir(&lfs, "\xff/\xff\xff\xff\xff") => 0;
  4741. lfs_mkdir(&lfs, "\xff/\xff\xff\xff\xff\xff") => 0;
  4742. lfs_mkdir(&lfs, "\xff/\xff\xff\xff\xff\xff\xff") => 0;
  4743. } else {
  4744. lfs_file_t file;
  4745. lfs_file_open(&lfs, &file, "\xff/\xff",
  4746. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4747. lfs_file_close(&lfs, &file) => 0;
  4748. lfs_file_open(&lfs, &file, "\xff/\xff\xff",
  4749. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4750. lfs_file_close(&lfs, &file) => 0;
  4751. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff",
  4752. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4753. lfs_file_close(&lfs, &file) => 0;
  4754. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff",
  4755. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4756. lfs_file_close(&lfs, &file) => 0;
  4757. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff",
  4758. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4759. lfs_file_close(&lfs, &file) => 0;
  4760. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff\xff",
  4761. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4762. lfs_file_close(&lfs, &file) => 0;
  4763. }
  4764. // stat paths
  4765. struct lfs_info info;
  4766. lfs_stat(&lfs, "\xff/\xff", &info) => 0;
  4767. assert(strcmp(info.name, "\xff") == 0);
  4768. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4769. lfs_stat(&lfs, "\xff/\xff\xff", &info) => 0;
  4770. assert(strcmp(info.name, "\xff\xff") == 0);
  4771. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4772. lfs_stat(&lfs, "\xff/\xff\xff\xff", &info) => 0;
  4773. assert(strcmp(info.name, "\xff\xff\xff") == 0);
  4774. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4775. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff", &info) => 0;
  4776. assert(strcmp(info.name, "\xff\xff\xff\xff") == 0);
  4777. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4778. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff\xff", &info) => 0;
  4779. assert(strcmp(info.name, "\xff\xff\xff\xff\xff") == 0);
  4780. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4781. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff\xff\xff", &info) => 0;
  4782. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff") == 0);
  4783. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4784. // file open paths, only works on files!
  4785. if (DIR) {
  4786. lfs_file_t file;
  4787. lfs_file_open(&lfs, &file, "\xff/\xff",
  4788. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4789. lfs_file_open(&lfs, &file, "\xff/\xff\xff",
  4790. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4791. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff",
  4792. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4793. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff",
  4794. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4795. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff",
  4796. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4797. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff\xff",
  4798. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4799. } else {
  4800. lfs_file_t file;
  4801. lfs_file_open(&lfs, &file, "\xff/\xff",
  4802. LFS_O_RDONLY) => 0;
  4803. lfs_file_close(&lfs, &file) => 0;
  4804. lfs_file_open(&lfs, &file, "\xff/\xff\xff",
  4805. LFS_O_RDONLY) => 0;
  4806. lfs_file_close(&lfs, &file) => 0;
  4807. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff",
  4808. LFS_O_RDONLY) => 0;
  4809. lfs_file_close(&lfs, &file) => 0;
  4810. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff",
  4811. LFS_O_RDONLY) => 0;
  4812. lfs_file_close(&lfs, &file) => 0;
  4813. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff",
  4814. LFS_O_RDONLY) => 0;
  4815. lfs_file_close(&lfs, &file) => 0;
  4816. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff\xff",
  4817. LFS_O_RDONLY) => 0;
  4818. lfs_file_close(&lfs, &file) => 0;
  4819. }
  4820. // dir open paths, only works on dirs!
  4821. if (DIR) {
  4822. lfs_dir_t dir;
  4823. lfs_dir_open(&lfs, &dir, "\xff/\xff") => 0;
  4824. lfs_dir_close(&lfs, &dir) => 0;
  4825. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff") => 0;
  4826. lfs_dir_close(&lfs, &dir) => 0;
  4827. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff") => 0;
  4828. lfs_dir_close(&lfs, &dir) => 0;
  4829. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff") => 0;
  4830. lfs_dir_close(&lfs, &dir) => 0;
  4831. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff\xff") => 0;
  4832. lfs_dir_close(&lfs, &dir) => 0;
  4833. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff\xff\xff") => 0;
  4834. lfs_dir_close(&lfs, &dir) => 0;
  4835. } else {
  4836. lfs_dir_t dir;
  4837. lfs_dir_open(&lfs, &dir, "\xff/\xff") => LFS_ERR_NOTDIR;
  4838. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff") => LFS_ERR_NOTDIR;
  4839. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff") => LFS_ERR_NOTDIR;
  4840. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff") => LFS_ERR_NOTDIR;
  4841. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff\xff") => LFS_ERR_NOTDIR;
  4842. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff\xff\xff") => LFS_ERR_NOTDIR;
  4843. }
  4844. // rename paths
  4845. lfs_mkdir(&lfs, "\xff\xff") => 0;
  4846. lfs_rename(&lfs,
  4847. "\xff/\xff",
  4848. "\xff\xff/\xff\xff\xff\xff\xff\xff") => 0;
  4849. lfs_rename(&lfs,
  4850. "\xff/\xff\xff",
  4851. "\xff\xff/\xff\xff\xff\xff\xff\xff\xff") => 0;
  4852. lfs_rename(&lfs,
  4853. "\xff/\xff\xff\xff",
  4854. "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4855. lfs_rename(&lfs,
  4856. "\xff/\xff\xff\xff\xff",
  4857. "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4858. lfs_rename(&lfs,
  4859. "\xff/\xff\xff\xff\xff\xff",
  4860. "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4861. lfs_rename(&lfs,
  4862. "\xff/\xff\xff\xff\xff\xff\xff",
  4863. "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4864. // stat paths
  4865. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff", &info) => 0;
  4866. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff") == 0);
  4867. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4868. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff", &info) => 0;
  4869. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff\xff") == 0);
  4870. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4871. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff", &info) => 0;
  4872. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff\xff\xff") == 0);
  4873. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4874. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => 0;
  4875. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff\xff\xff\xff") == 0);
  4876. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4877. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => 0;
  4878. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") == 0);
  4879. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4880. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => 0;
  4881. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") == 0);
  4882. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4883. lfs_stat(&lfs, "\xff/\xff", &info) => LFS_ERR_NOENT;
  4884. lfs_stat(&lfs, "\xff/\xff\xff", &info) => LFS_ERR_NOENT;
  4885. lfs_stat(&lfs, "\xff/\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4886. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4887. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4888. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4889. // remove paths
  4890. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff") => 0;
  4891. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff") => 0;
  4892. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4893. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4894. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4895. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4896. // stat paths
  4897. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4898. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4899. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4900. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4901. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4902. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4903. lfs_unmount(&lfs) => 0;
  4904. '''