?

Log in

No account? Create an account
All of us together/in the same device - Lindsey Kuper [entries|archive|friends|userinfo]
Lindsey Kuper

[ website | composition.al ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

All of us together/in the same device [Jun. 27th, 2010|07:41 pm]
Lindsey Kuper
[Tags|, ]

I'm working on the last homework assignment (which doubles as the final) for the OS course I'm taking, which is to write a toy filesystem. It's not a kernel module or anything, just a user-space thing, so I suppose it's less a filesystem than a database, really. Running the provided test program creates a big1 ol' monolithic fs.dat within which one's "files" live.

$ file fs.dat
fs.dat: data

"data". Damn straight. It is not XML. It is not JSON. Regarding its endianness no information is to be had. It is not UTF-anything. There is no name for what it is! But there's stuff in there that can be thought of as representing files, and it's possible to read them and write them and create and delete and all of that. Or it will be, notionally, as soon as I implement the ability to do that stuff. So far, all you can really do is "format" the thing, which sets up a superblock, an inode for the root directory, and a list of free blocks. That part works. I think. If you've ever formatted a floppy disk, I fancy this process as being a lot like that. Except, uh, less sophisticated. And on a smaller scale.

The assignments that we turn in have to compile and run on Linux, and using my Mac to test my code has gotten a little bit less feasible with each one. At first, my code ran on both without issue. Later, things started to get #ifdeffy, or sometimes the code would run on both but produce different results. With the filesystem assignment, I'm officially giving up on trying to make it portable.2 On my Mac, the test program promptly segfaults, and I'm not going to worry about figuring out why.

On Linux, though! I just tried it out and it's awesome. The formatting seems to work, and then the test program continues running, thinking it's creating files and writing to them and so forth. Except! None of the functions that do those things have been implemented yet; they're there, but they don't do anything at all, except sometimes creating some dummy objects on the stack and returning them, to make the types -- such as they are -- work out. So, the program runs, and some bytes get copied around, and when the test program eventually prints out what it thinks it has "read" from what it thinks was a "file", it prints this:

?Y?h8???????????9??h@@0?h8/??h8Linux?@@{?h8ui csug.1?h8??h8?)?h8XkU?*?kU?*?????@??w?@?\?h80?????????w?@?}?h8?kU?*x86_64?kU?*?\?h8X????Y?h8(none)@ PP@ P?????g?h8?ıh8?@????? @@L?h8?@????????ıh8? @P@?@?@??????????????????????????:???U???h???t???7???C???_???????????????????!???J???R???d???s??????????????????d@@8 ?@ f? bb????x86_64./fsHOSTNAME=csug01.csuglab.cornell.eduTERM=xterm-colorSHELL=/bin/bashHISTSIZE=1000SSH_CLIENT=::ffff:67.255.17.76 54565 22OLDPWD=/home/lak223/cs4410SSH_TTY=/dev/pts/7USER=lak223LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:KDEDIR=/usrMAIL=/var/spool/mail/lak223PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/binINPUTRC=/etc/inputrcPWD=/home/lak223/cs4410/assignments/4LANG=en_US.UTF-8SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpassKRB5CCNAME=FILE:/tmp/krb5cc_49766_UKYjQrSHLVL=1HOME=/home/lak223LOGNAME=lak223SSH_CONNECTION=::ffff:67.255.17.76 54565 ::ffff:132.236.227.41 22LESSOPEN=|/usr/bin/lesspipe.sh %sG_BROKEN_FILENAMES=1_=./

which is...some interesting-looking garbage, followed by what appear to be my bash environment variables. How did that get there?! Dude! Also, now you know my Cornell username.

I suppose I should do the rest of the assignment now or something, and fix this bug. But -- isn't it fun, having something break in a weird and interesting way? Don't get me wrong -- I don't think I would want to try to build large, portable, reliable, secure systems like this. But for hacking on your own, which bug would would you rather have -- this, or some boring-ass CantDoThatException? Right now my vote's for this.


  1. Where by "big" I mean "256 K".
  2. Between this and running Ubuntu at work and loving it, I'm starting to feel just a little disillusioned with OS X. I have an Ubuntu box at home that I've been neglecting because it's easier to just use my Mac, where things Just Work. But I think that when I get back home in the fall I'll upgrade to Limpid Lemur or whatever they're on now and start using it more regularly. These days, things actually Just Work on Ubuntu, too -- and Ubuntu doesn't have several competing package management systems, all of which are mediocre.
LinkReply

Comments:
(Deleted comment)
[User Picture]From: oniugnip
2010-06-28 01:37 am (UTC)

Re: So I made some lies so they'd fit real nice

Valgrind helps C programmers be happy instead of tense :)
(Reply) (Parent) (Thread)
(Deleted comment)
(Deleted comment)
[User Picture]From: oniugnip
2010-06-28 01:36 am (UTC)
So cool :)

So those bytes -- did they originate in your fs.dat file, or were they just randomly sitting around in memory?

Giant hacks! <3
(Reply) (Thread)
[User Picture]From: lindseykuper
2010-06-28 03:32 am (UTC)
fs.dat comes about because the test program opens it like it would any other file, with open(). I don't know why they would be there.
(Reply) (Parent) (Thread)
[User Picture]From: perligata
2010-06-28 03:11 am (UTC)
Whoa, you do development on OS X? I'm from a pretty purely Linux background and have been trying to navigate my way around OS X for some work stuff and it's killing me. I guess it's good to know people do actually use it for development though. (Development that is not just web apps.)
(Reply) (Thread)
[User Picture]From: lindseykuper
2010-06-28 04:35 am (UTC)
A lot of people do, but personally, these last few weeks have been the first time I've tried writing C on anything that wasn't Linux.

I've been writing Scheme and Python on OS X for the last two years. Before that, I wrote Perl on OS X for two years. I haven't had to think about cross-platform issues with any of these languages. None of it has been code that runs on a web server or in a browser, but I suppose that if you're equating "interpreted languages" with "web apps", it doesn't count.

Edited at 2010-06-28 04:46 am (UTC)
(Reply) (Parent) (Thread)
[User Picture]From: aleffert
2010-06-28 05:58 am (UTC)
What problems are you having? I've written a lot of code on OSX over the past decade in a variety of different languages from the mainstream to the fairly obscure, basically none of which was web stuff, and I haven't noticed myself having tools issues that I didn't also have in my time with linux, but it could just be I don't know what I'm missing.

The package management situation is pretty dire though.
(Reply) (Parent) (Thread)
[User Picture]From: perligata
2010-06-28 06:32 am (UTC)
I'm mostly desperately missing strace. I work on something called the Tor Browser Bundle so what I'm making is an .app bundle which launches some GUI software (Vidalia) which then launches Tor and once connected launches Firefox. It's not easy to connect to any of this with gdb at the right moment, and gdb doesn't exactly do what I want anyway. Or maybe it does and I just suck at debugging.

I've been trying to diagnose some issues through Console.app and debug logs provided by Vidalia, but I need to find a way to trace all of the opens/closes/etc like I normally would with strace. I've heard tell that dtrace is the thing, but it looks a lot more complicated than anything I need. Maybe you have some pointers? I'd be very appreciative if so. :)

(And apologies, Lindsey, for opportunistically seeking debugging help in your comments!)
(Reply) (Parent) (Thread) (Expand)
[User Picture]From: lindseykuper
2010-06-28 02:49 pm (UTC)

re the package management situation

Fight the evil from the inside!
(Reply) (Parent) (Thread) (Expand)
(Deleted comment)
[User Picture]From: royhuggins
2010-06-28 03:12 am (UTC)
I love that your environment variables got randomly thrown in there. It makes it look like your output was written for a Hollywood movie.
(Reply) (Thread)
[User Picture]From: lindseykuper
2010-06-28 02:55 pm (UTC)
I know, right? I stared at it for a while before posting it here to make sure it didn't reveal any Top Sekrit Information about me.

Anyway, I figured out that it was a buffer overflow thing. I can't believe that I'm arguing that buffer overflows are interesting and fun. My advisor should fire me. (Arguably the whole point of PL research is to develop languages that prevent such "interesting" and "fun" anomalies from ever happening.)
(Reply) (Parent) (Thread)
[User Picture]From: jes5199
2010-06-28 06:17 am (UTC)
my Labs computer is a relatively new MacBook Pro, you know one of the ones with the pixels so small that 12pt fonts are unreadable
I find the thing extremely frustrating, I keep making the windows accidentally dance around, I get beachballs that stall out the machine for 15 seconds every 4 minutes (this only happens when I'm running firefox, so, you know...)
the keyboard just has too few keys! With pageup/pagedown mapped to arrow keys, just a bizarre number of my normal activities are mapped to some combination of FN/CTRL/SHIFT + Arrow. I feel like I'm using Emacs.

Currently, I do all of my development in a VMWare running Ubuntu.

anyway. I'm probably going to buy myself a new thinkpad. I could almost justify switching back to my old one, but not quite.
(Reply) (Thread)
[User Picture]From: lindseykuper
2010-06-29 01:01 am (UTC)
Did you have any say in the matter of what laptop they got you?

Huh -- I have a MacBook Pro and I've never once thought that the keyboard had too few keys. But, then, I use Emacs.

Edited at 2010-06-29 01:02 am (UTC)
(Reply) (Parent) (Thread) (Expand)
(Deleted comment)
[User Picture]From: lindseykuper
2010-06-29 12:55 am (UTC)
Man, everyone keeps telling me to talk to this or that awesome person while I'm around Cornell, but I'm only on campus from 8:30 to 9:45 every morning, and I have to leave right after that to be at work for a daily 10 a.m. meeting, and I'm at work every day until after professors have gone home. In principle, I could go back to campus during the work day, but you gotta understand, there's a really big hill separating me from it. So for now I think I'll have to content myself with Tim Teitelbaum telling anecdotes about Coq.

(Reply) (Parent) (Thread) (Expand)