epepep

The archived blog history of Per Liedman.

© 2013. All rights reserved.

Built on @mdo's Hyde.

DNS-323 filename encoding problems

This entry will be in english, since it's more likely to be helpful to others googling for solutions to the same problem.

A colleague of mine has used a D-Link DNS-323 as his RAID/backup solution at home. Apparently it's been working great for ages, until he recently updated its firmware, which also caused all files and directories containing non-ASCII characters (mostly å, ä and ö for us swedes) to be completely inaccessible; the windows sharing (Samba/SMB) wouldn't show the directories at all, and although they showed up in FTP, you couldn't really access them. Downgrading the firmware did not help.

The fun thing about the DNS-323, and the reason the colleague asked me for help, is that it runs Linux internally. Although it looks like a USB disk with a web interface, it actually has a full-featured operating system underneath. Well, close to full featured.

Googling for solutions, I found another swede, Martin Bergek, who had at least similar problems (by chance, I also happen to know who Martin is). It seems that older firmwares used CP850 for filename encoding, while newer versions use UTF-8. Probably some upgrade didn't go as planned, leaving the filenames in CP850, while interpreting them as UTF-8. Decoding swedish CP850 characters as UTF-8 results in invalid multibyte characters, causing the programs to refuse to handle files and directories containing them.

Now for the fun part. There seems to be quite a community developing hacks for the DNS-323. Using the so called fun_plug, you can very easily enable an SSH server, and get access to lots of useful commands. In my case, SSH access in combination with the rsync command turned out to be the key.

My solution was to get a backup disk large enough to copy all the material from the DNS-323 (actually, my colleague had already thought of this and provided me with a disk for this purpose). Once all the files where copied from the DNS-323, it could be wiped and the files copied back, but this time with the correct filename encoding.

As mentioned above, most of the problem results from applications interpreting the characters as invalid UTF-8 codes, refusing to work with them altogether. Even basic stuff, like doing recursive file lists with rsync, fails if a directory contains the invalid characters, probably since the runtime's string library can't work with the resulting strings. Shell commands like cd handle the directories, though, even if the characters are displayed as garbage.

Fortunately, rsync includes a command line parameter called --iconv, which lets you override which encoding is used when interpreting the filenames. This way, you can interpret the names correctly, and they can be converted into proper UTF-8. The trick is that you have to do this on the DNS-323 side, otherwise the conversion will be done on the backup unit's side, still causing errors attempting to do recursive file lists. (In case you connect the USB disk directly to the DNS-323, you won't have to think about this - in my case, the backup disk was connected to my Ubuntu desktop.)

So, to sum things up, this was the killer command line that made it possible to copy all the files out of the DNS-323:

rsync -azv --iconv=cp850,utf8 /mnt/HD_a2/ per@asta:/media/usbdrive/dns323

(Obviously, you'll have to replace the paths to whatever directories you're using on the DNS-323 as well as for the backup disk.)

Grotesque

Som jag skrivit i en tidigare post har jag skrivit ett program för katalogisering av IF-spel. För att göra det hela lite mer officiellt har jag nu registrerat projektet på SourceForge, som nu tar hand om Grotesques hemsida samt tar hand om projektets programkod.

Spielen!

Stora nyheter. Jag har lyckats sätta ihop mitt första GTK+-program och skapat mitt första Ubuntu-paket (som innehåller programmet i fråga). Men låt oss börja från början.

De senaste månaderna har jag fastnat i textäventyr - den uråldriga eller kanske urmodiga typ av datorspel där man spelar genom att läsa text och sedan skriva kommandon för att berätta för datorn vad man vill göra; interactive fiction (IF) är den engelska termen, som jag gillar bättre, då det inte nödvändigtvis rör sig om äventyr av drakar och demoner-karaktär.

I detta äventyrande började mina problem. Annars förträffliga Ubuntu har inte några program för att spela IF på något bekvämt sätt; några program finns (frotz, tads och qtads), men de täcker inte alla olika spelformat som finns, och även om jag gillar terminalfönster så är det inte optimalt för IF. Min favorit blev istället snart Gargoyle, som stöder alla format jag är intresserad av, samt ser synnerligen elegant ut.

Vad Gargoyle saknar är dock ett bibliotek, eller smidigt sätt att hålla reda på de olika spel man samlar på sig. Det är här mitt program kommer in. Ett slags katalogiseringsprogram för IF-spel med utseende som ett budget-iTunes. Arbetsnamnet är Grotesque (eftersom en gargoyle är en form av groteskornamentik - ja, jag fick slå upp det sistnämnda ordet).

Jag ämnar nog göra något lite mer seriöst av detta längre fram, men tills vidare lägger jag upp en screenshot, källkoden samt slutligen Ubuntu-paketet för Grotesque-0.1 (Uppdaterat 2008-07-03: se Grotesques hemsida för senaste versionen av dessa filer). Eftersom jag bara byggt på min egen maskin och det är första gången jag paketerar för Ubuntu så har jag säkert gjort något fel, men pröva gärna.

Min plan härnäst är att paketera även Gargoyle som Ubuntu-paket, eftersom det är lite väl stökigt att bygga för hand nu, lägga på lite puts och glans på Grotesque, samt kanske hitta på ett ordentligt namn. Vi får se. Under tiden borde du pröva att spela lite IF - några bra förslag på spel att pröva hittar du t.ex. här.

Kvitter

Här verkar det inte hända mycket, men om ni är väldigt intresserad av vad jag håller på med kan ni numera försöka följa mig på Twitter.

Dagens Ubuntu-tips

Jag är en stor vän av tangenbordsgenvägar. Tydligen till den grad att jag inte ens märker att jag använder dem. Däremot blir det problem när de plötsligt slutar fungera. Därför är en av de få irritationsmoment jag haft sen jag konverterade till Ubuntu varit att en så enkel sak som att flytta markören i URL:er i Firefox inte längre fungerar som jag är van vid.

I Windows kan man förflytta markören snabbt genom en URL till nästa "logiska stopp" (punkt, snedstreck, &-tecken, etc.) genom att hålla inne Ctrl samtidigt som en av piltangenterna. I Ubuntu leder (med default-inställningarna) tyvärr detta till att man hoppar direkt till slutet respektive början av hela URL:en, till föga nytta.

Efter att äntligen orkat upparbeta en tillräcklig irritation över detta, Googlade jag och fann lösningen: ändra inställningen layout.word_select.stop_at_punctuation till true i Firefox (genom att gå till about:config). Underbart lätt. Varför detta inte är grundinställningen är ett mysterium.