Hardware Support in GNU/Linux

Well, really in just Linux, since drivers are mostly in the kernel. (For those who don’t know, “Linux” is the kernel, the central bits of the operating system that does the vast majority of the relations with the bare metal; “userland” is everything else, including most of the programs that we actively use on a daily basis, and is disproportionately GNU software). But for some reason people don’t think that Linux supports much hardware.

The reality, however, is that Linux has better hardware support than Windows. Indeed, Linux hardware support blows Mac and Windows completely out of the water. What’s more, Linux supports this hardware out of the box, with no need to install 250MB of drivers plus a helper program plus a load of adware and crapware off the CD that came with your device, which helpfully adds a desktop link, a “start menu” item (usually an entire directory!), and a little icon in your system tray on your menu bar (tried to install any printer on Windows lately?).

Why is that? Substantially, it’s the Linux Driver Project‘s doing. This massive project, utilizing some of the most competent programmers in the world and led by famous kernel hacker Greg Kroah-Hartman, offers free driver development for any device manufacturer that asks. This project has ensured that almost every single device on the planet can run on Linux. Kroah-Hartman (despite working for the execrable Novell) is a real hero in Linux, not only managing the USB kernel subsystem (being part of the first-ever implementation of USB 3.0, working in Linux before any other OS in the world), but also heading up this vital project. Kroah-Hartman explains it thus:

Part of the issue is that we support more devices than any other operating system ever has. That’s a fact that’s been verified by other companies. The problem is that people only care about the devices that they have. Therefore, if your device doesn’t work for some reason, you don’t care how many thousands of other devices out there work.

When I started the Linux driver project, I’d been hearing this from all the major companies that were shipping Linux and cared about Linux. So, I went around to them individually and said, “OK, what do you need me to do? What needs to be worked on?”

Every single major hardware company, said, “Hey, you’re right. Everything works on Linux. We’re fine.” That’s shown by these companies that ship Linux on their machines. Dell, HP, and all the big hardware companies and laptop manufacturers now ship Linux, and we’re working with them.

Compare that, now, with Windows. Every “upgrade” (e.g., XP to Vista, Vista to 7) breaks large numbers of drivers, which will need to be rewritten. Windows has comparatively few drivers built-in, necessitating downloads and CDs which consequently can, and usually do, contain vast quantities of adware and crapware that can only be removed with difficulty, if at all, without removing the driver itself. (Does your printer work in Windows without the nonsense software the printer company released? No? Mine does, in Linux.) And if you replace something really fundamental—say, put in a new motherboard—Windows will freak, gag, and probably break.

Forget about replacing your primary hard drive. Most likely, your copy of Windows came with your computer, so you don’t have an install disk; so if you replace that drive, your installation is all gone. You might be able to mirror your current drive onto the new one, then take out the old one—but not with out-of-the-box Windows software. Often, replacing fundamental bits of hardware will cause Windows to assume that it’s an illegal copy, requiring you to jump through ridiculous hoops to ensure Microsoft that you’re not cheating them. This last applies even if you do have an installation disk, not to mention the hundreds of dollars you probably had to drop to get it.

Incidentally, even on the software level Windows is gratuitously incompatible. It won’t read from any filesystem not produced by Microsoft at all. Really; it’ll gag, if it can even see the partition. Linux happily reads, and even writes, to filesystems as varied as NTFS and FAT32 (Microsoft’s own crappy filesystems), along with its native ext3 and friends. Windows just won’t. Nor will Windows easily network with non-Windows machines; to do that, non-Windows systems have to do all the work. Not to mention that Linux, upon installation, will tread very lightly, respecting everything else that’s on the computer, even Windows. When you install Linux on a computer that already has Windows on it, Linux is ready and willing to let Windows continue to exist; it will install a boot loader, allowing you to choose your operating system at boot time. Try it with Windows. On installation, Windows takes a big stinky dump on top of your boot sector, and adds insult to injury by not even bothering to wipe. Windows is here; all your box are belong to us. Surely you didn’t need to boot anything else? Microsoft will solve all your problems, whether you like it or not!

Mac? Forget about it. Mac works with Mac; Steve Jobs wants you to be entirely dependent on his little “walled garden,” so Apple doesn’t bother to even try putting in compatibility with a wide range of hardware. As Kroah-Hartman again points out, “Mac OS X does not support very many devices at all.”

So if you want hardware support, if you want compatibility with many other systems, GNU/Linux is your best choice. Saying otherwise is ignorance at best, FUD at worst.

Praise be to Christ the King!

Published in: on 30 November 2009 at 4:32 pm  Comments (2)  
Tags: , , , , ,

On C Programming and K & R’s Impossible Exercise 1-21

No, it’s not really impossible; it’s just extremely difficult until you make a certain, particular mental leap, one which was long in coming for my idiot little brain.

However, some brief background: K & R is Kernighan and Ritchie, authors of the monumental The C Programming Language. When I say “monumental,” I don’t mean “huge,” because it’s not; it’s actually remarkably short, given that it describes the programming language which underlies just about every significant systems program of the modern computing age. As K & R themselves state in said wise tome:

We have tried to retain the brevity of the first edition. C is not a big language, and it is not well served by a big book.

Such wisdom! Such restraint! If only more programming book authors could conduct themselves with such brevity! As a student of the Thomists, themselves dedicated studentes brevitatis, I can’t help but admire this kind of sensibility.

K & R have, rightly, exercised enormous influence in the world of computing, particular in that of GNU/Linux. Now, GNU has one coding style, while Linux has another; it’s the same language, but each uses different styles. The primary difference is that the Linux style is wonderful, while the GNU style is awful[1]; the reason for this is that the Linux style respects K & R, while the GNU style neglects them, thus consigning itself to the nether regions of illegibility. As Linus Torvalds himself has noted,

First off, I’d suggest printing out a copy of the GNU coding standards, and NOT read it. Burn them, it’s a great symbolic gesture. . . . the preferred way [of coding is] shown to us by the prophets Kernighan and Ritchie . . . Heretic people all over the world have claimed that this [style is] inconsistent, but all right-thinking people know that (a) K&R are _right_ and (b) K&R are right.[2]

So, in other words, K & R are right. Period. Moving on.

In any case, one thing that K & R absolutely love to do is throw into their text, as if it’s a minor practice step, programs that are incredibly difficult to execute correctly. These exercises are described in a way which implies mere employment of what has already been discussed, and that much is technically true; however, they often require cognitive leaps quite beyond the text to that point. Doubtlessly K & R’s immense brilliance render these cognitive leaps hardly worth mentioning, mere flickers of their intellectual thumbs; for puny mortals such as myself, however, they’re more equivalent to running the Boston marathon. There are many such exercises; however, without a doubt the worst example of this that I’ve encountered thus far is the dreaded Exercise 1-21, the entab program.

It sounds benign enough:

Write a program entab that replaces strings of blanks by the minimum number of tabs and blanks to achieve the same spacing. Use the same tab stops as for detab. [The program in Exercise 1-20; also difficult, but not murderously so.] When either a tab or a single blank would suffice to reach a tab stop, which should be given preference?

Hardly designing a rocket guidance system, is it? This one shouldn’t take more than half an hour.

Wrong. You couldn’t be more wrong. For hours I struggled, never successfully attaining this simple end. I’m even ashamed to say that I resorted to the answers site, just for ideas. But even those programs didn’t work. Seriously; I tried them. They don’t do what the exercise says they should do.

They do something, of course; they do what my initial attempt at the program did. They take any group of spaces equal to a tab and replace it with a tab. That’s great and all, but it’s not what the exercise requires.

Here’s an example. The programs at Heathfield’s are fine programs, but they don’t meet what the exercise requires. Here’s what they do; first line is the ruler, second the input, third the output:

             |________|________|________|________|
             |Now__________is____the______time
             |Now\t__is____the_____time

For those of you who don’t know, that ‘\t’ means “tab,” the pipes (“|”) represent tab stops, and the underscores are there because they’re easier to see than spaces. In other words, these programs simply find sequences of eight spaces and replaces them with tabs. It takes no notice of where the tab stops actually are. All well and good. But the exercise doesn’t just want sequences of eight blanks replaced by tabs; it wants some sequences of less than eight blanks replaced, if that would yield the same spacing as the original input.

This second solution is much harder than the first (which I was able to achieve quite quickly, even with my tiny brain and limited programming acumen). I beat my head against the wall for a long time—then finally had an epiphany. I can make the program work!

If I’d sat down and planned out how to solve this problem, like a real programmer, instead of just started banging away at it the way I did, I would have solved this very quickly. But I didn’t, so I got started off on the wrong track, and because I already had a program in front of me, albeit one that didn’t work, I wasn’t able to see that I’d gone wrong from the very beginning.

The answer is that you need two variables, in addition to the string; one to keep the basic index on the line, and one that keeps track of the tab characters. If you know programming, look at the code and you’ll see what I mean. If you don’t, just take my word for it: two variables made all the difference.

And it works!

So, for your enlightenment (by “enlightenment,” I mean “amusement that it took someone so long to solve such a simple problem, and yet that someone is so excited about it”), here’s the code. I hope other anxious learners beating their heads against bricks with this problem will learn from my own egregious errors.

entab.odt. Note that this is suffixed “odt” because WordPress only accepts files in a limited number of formats (apparently it’s cool with plain text, but only plain text that’s been saved as odt). It’s actually a plain text file of C code.

It works! I’m really excited. Technology, though often abused, is incredibly powerful; learning more about it is more powerful still.

Praise be to Christ the King!

1. Don’t worry; both produce programs of equal usability, all other things being equal. It’s just that reading GNU-styled code is crazily impossible to me, while reading Linux-styled code, given that it’s directly from the immortal K & R, is pure pleasure.
2. I’m citing with legal standards here; that is, brackets indicate not only inserted material, but also possibly excluded material. This unencumbers selective quotations significantly, removing the need for braces and ellipses; I’ve provided a link to the full text. So many interpolations and exclusions were required because Torvalds is being much more specific than I am here; the spirit of his remarks is the same.

Published in: on 22 November 2009 at 8:57 pm  Comments (7)  
Tags: , , , , ,

Computers, Manuals, and the Command Line

Among Linux forums, Linux users are constantly being accused of elitism. They’re up on their high horses, secure in their comfort with Linux and other Unix-like operating systems, looking down their pointy noses on the hapless noobs who just want their computers to “just work.” Poor Joe Sixpack, trying to free himself from proprietary tyranny, is constantly being chased away from Linux by such superior elitists, who make him feel like an idiot just for asking an innocent question.

What yields such charges of elitism? More often than not, it’s the simple suggestion that the asker of a given question should resort to the documents which were written precisely for the purpose of answering such questions: the manuals. In other words, people who really cared about Joe Sixpack would spoon-feed him like a newborn baby; hateful people who point him to the answers to not only his specific question, but also to most other questions in the computerized universe, are elitists. To this, I can only respond with one short, trite phrase:

Read the f@#$ing manual.[1]

Seriously. Read it. That’ll probably answer your question. If it doesn’t, Google it. Google is your friend.[2] If you don’t know how to get to the manual, go to a command line and type “man command“. That’s it; your manual will come up. Read it. If it doesn’t work, as it very occasionally doesn’t, then once again, Google it. You’ll get a manual shortly. Once you’ve read it, and you actually understand the program you’re trying to use, you probably won’t have a question anymore. You’ll have educated yourself to know something, rather than simply doing something without knowing what or why. And isn’t that better? Isn’t it better to learn than simply to ape what some ubergeek tells you on a help forum?

If you’ve done all this, and you still can’t figure it out, please feel free to ask the question. Geeks and hackers throughout the world will be happy to help you find the solution. Remember that we hang around in help forums answering questions on our own time. Nobody’s paying us for it (most of the time); we’re doing it because we like the program and we like helping people. What we don’t like is people who demand we solve their every problem without them ever making any effort to solve it themselves, or even to understand what it is. That tends to make us a bit ornery. And with good reason.

You see, those of us who are called “geeks” or “hackers” didn’t become such by opening our heads up and letting people pour stuff into them. We got that way by study and effort. Some of us learned in college; some of us never went to college; some of us went to college, but learned little about computers there, gaining this knowledge on our own. But all of us value self-teaching and self-study, with deference to the masters when one cannot find the answers on one’s own. The deeper one gets into computers, the more one will require such consultation. As a corollary, however, the shallower one is in computers, the more rarely one will require it. If you’re just a hapless noob looking for help, then I can more or less guarantee that the answer to your question is easy, and that you’ll find it in the manual. But even if it winds up not being there, at least do us the courtesy of looking first, please.

We’re the ones who wrote those manuals, see. We don’t just write software; we write documentation for it. We work hard at it, and try to include all the normal situations as well as any unusual ones that have been reported to us. As such, your problem is probably in there; in the unlikely event that you’ve found an edge case that nobody else has noticed yet, then we want to know about it. But we don’t want to answer the same question thousands of times when we’ve already answered it in a thorough and complete way by putting it in the manual.

Nobody expects to drive a car without taking a driving class. Nobody expects to wire a house without studying up on electronics. Nobody expects to fix their dishwasher without learning a little plumbing. Yet for some reason everybody expects their computer to sit up and beg whenever they point at it and tell it what they want it to do. The computer is an immensely powerful machine that will do many wonderful things, but one must first learn how to tell it what to do. Sometimes that’s pretty easy; sometimes it takes significant study; sometimes it’s deep magic that only the very greatest masters can manage. In no case, however, can it be done without learning something, and the place to learn that something is, more often than not, the manual.

People who call us elitists for saying things like this are completely missing the point. We’re not elitists. Elitists would want to maintain their superior knowledge and keep everyone else dependent upon them. We’re doing precisely the opposite; we’re helping other people obtain the same knowledge we have, from the same sources that we have it. A truer egalitarianism is difficult to imagine.

It’s the difference between giving a man a fish and teaching him to fish. Is it elitist to teach a man how to provide for himself, or to perpetually infantilize him by giving him everything he needs and pretending that it takes no effort for somebody else to get it?

The computer is a tool, and like all tools it takes knowledge, study, and experience to use it effectively. When we refer you to a manual or to a search engine for an answer, we’re not doing it because we think you’re stupid, or because we think we’re better than you. We’re doing it to teach you how to find the answers yourself. That’s not elitism; it’s humanitarianism, pure and simple.

Praise be to Christ the King!

1. This saying is frequently abbreviated to “RTFM,” which is variably rendered as “read the f@#$ing manual,” “read the fun manual,” “read the fine manual,” or something similar, depending on the speaker.
2. This saying is frequently abbreviated “GIYF.” Truer words in the computer world could hardly be imagined.
3. Please, also, learn how to ask a question correctly should the manual or the Internet fail to yield a helpful solution. This will go a long way to showing that you’ve filled your end of the computer help bargain; people will respect you, and thus be more interested in helping you.

Published in: on 13 November 2009 at 9:41 pm  Comments (2)  
Tags: , , , , ,

The Reality of Localism

As distributists, we’re all strongly committed to localism; that is, to making our society, particularly our production, less remote and more local. Indeed, distributism is a name for that economic system in which more, rather than less, of the population is the owner of productive property; such a system necessarily entails more local production. Many distributists, however, forget that this economic localism corresponds to a very real cultural localism, one which is part of the universal experience of mankind.

Culturally, we are all localists, even our so-called cosmopolitans. (Indeed, the problem with our modern cosmopolitans is that they are too local, not that they are not local enough.) The “it takes a village” mantra that the modern nation-state constantly uses as an excuse to preempt the just powers of parents is often grotesquely overextended, but nevertheless there is real and substantial truth in it. We are raised by our parents, but we inevitably have substantial contact with others around us, and others around us are inevitably those who come from the same locality as we do. They, in turn, were raised by parents, but also had substantial contact primarily with other locals. As a result, whole cultural systems rise up which are confined primarily to a given, localized area, distinguished from all others throughout the world.

Localities are distinguished from others in countless ways. Those in a given area sing songs that are unlike those sung in other places; they eat food that is not eaten elsewhere; they adopt curious hairstyles and clothing; they play games that others find odd. Men tend to share things with other men with whom they have more in common, rather than with those with whom they have less, and they have more in common with those who live near them than with those who live far away.

It’s sometimes hard to recognize this in our age of distributed computing, but look at the question from a natural point of view. If a hurricane knocks my neighbor’s tree down into my yard, who will help me clean up the flotsam? When my lawnmower breaks down, to whom do I turn to borrow one? When the city garbage collectors are careless with their task, with whom will I join my voice to obtain redress? When my house is on fire, who will call the firemen for me? When I lock my keys in my home, whose phone do I use to call for help? When the grocery store runs out of bread and milk before a snowstorm, who can I rely on to share?

Yet even in light of all this, many claim that localism is outdated, that we now live in a “global society.” Now, after all, we have Twitter; many of us have more in common with individuals we’ve never even met than with our neighbors. But this overlooks the vast majority of our daily and necessary lives. While I’m sure many people find it wonderful that another person halfway around the world can know exactly what I’m having for lunch today, it hardly compares with the localism we’re discussing here. These globalists, these cosmopolitans too good for the universal localism may have global news sites and global networking, and these things are all fine and good. But the things of the earth, the things that are closest to who we are and what we need to maintain our safety and even our existence, are and must be local. And these things, by necessity, we have in common with our neighbors, with those who live in real, physical proximity to us. We have more in common with these fine people than we do with anyone else in the world, no matter how closely we follow someone’s Facebook feed.

My neighbors are really my best friends; I have more in common with them than I do with anyone. And there is absolutely nothing in the world that can change that. No matter how cosmopolitan our society becomes; even if we begin a national policy of moving to another state at least twice a year; for as long as we live in a place, we are dependent upon that place and the people who share it with us. For anyone who doubts it, let him wait for his Myspace fans to call the fire department when they see smoke coming out of his windows while he sleeps. For the rest of us, we will rely on what men throughout the world have always relied on—the people who live next door. We can try to ignore it, but we cannot change it. Man is an inherently local creature.

Yet modernity has long been on a mission not only to ignore it, but to positively oppose it, like Harold the Usurper commanding the waves to cease. Our modern economy, in particular, has been a great force attempting to undermine this unavoidable localism. There are great incentives for leaving localities, particularly smaller ones, to gravitate toward great centers where, we are told, people aren’t so “provincial” and “small-minded.” Economic production is increasingly centralized; even that most quintessentially local activity, agriculture, has been warped into an industry, producing corn and hogs as though they were parts in a great machine. Television, radio, and other modern media have rendered the culture of our locality less and less important, as people increasingly follow whatever culture they see emanating from New York and San Francisco. Consequently, we are told, localities are irrelevant; only the “global society” is important.

One might as well say that men are irrelevant, and only the commune matters; yet without the parts, the whole will inevitably collapse. And that’s precisely what’s happening. As our localities weaken, as everything from our culture to our economy centralizes and our people increasingly ignore their roots, our larger societies become increasingly untenable. With nothing to anchor it, the ship continually blows further adrift, and our deracinated citizens continually invent newer and more disgusting debaucheries for the public approval, which is never long in coming. A people which forgets its roots will die as surely as will the branches of a rootless tree; and our people’s roots, like all peoples’, are in localities.

For how can we contribute to or benefit from our new global society if we’re not even really part of our local one? The leaf can gather all the sunlight it can, but if the roots aren’t in the ground the tree will die. The West is like a man so busy pressing his suits and gelling his hair that he forgets he still needs to eat. We are physical beings, necessarily tied to a particular place at a particular time; when our culture and our economy no longer reflects this reality, we know that the corruption of our society has reached a critical stage.

For the distributist, dedicated to men living as men and not as disembodied brains (for what else is the man without a place?), the solution is obvious: become more local. There is no need for me to rehash the many economic means of doing so, but think of the cultural means. These are simple; the most basic is, the next time you see your neighbor out mowing his lawn or washing his car, do the most revolutionary and countercultural thing you can imagine: walk up to him and say hello. Really; it’s that simple. Once upon a time, people used to have block parties; when the weather gets nice in the spring again, throw one. Invite not your friends from work, but your neighbors. Help organize a neighborhood watch to protect your community from becoming crime-ridden and keep your children safe.

You may even go the extra mile. Learn about your place’s history and culture. Learn local songs, tell local stories. Go to local festivals and cultural events. Join local organizations, like museums or community centers. Get involved in local politics. Simply be local; really live in your place, rather than just store your earthly flesh there for a while. Plant your roots, or your branches will inevitably die.

Praise be to Christ the King!

The Glories of the Command Line

Let’s say you have a middling to lousy Internet connection, but you still want to take advantage of an online video language course. What’s the solution? Download the videos, obviously; my processor is much faster than streaming them over my middling to lousy connection.

The videos, however, are streamed under the “mms” protocol. This doesn’t mean that they can’t be downloaded (they are free to view, by the way); it just means that you can’t download them directly, you have to stream them and save them as they’re streamed. (Essentially, this is downloading them in real time; so saving the thirty-two minute video takes thirty-two minutes.) While I’m at it, I want to convert them from the execrable Windows Media format they’re provided in to a different, free, and good format; namely, Ogg Theora. What to do?

Well, Video LAN Client, or VLC, provides the answer. This cross-platform media player can handle playlists and deals with just about every media format known to man. ffmpeg, on the other hand, will be used for converting the video to Ogg Theora. There are plenty of tutorials online explaining how to use VLC to save a streaming mms video to disk, and plenty explaining how to use ffmpeg to convert a video to Theora. (I’ll show you all in a minute, only I’ll do it in a better way.) It involves navigating lots of menus; it takes several seconds per video, which is fine when you’re only doing a video or two.

Thing is, this is a multi-part language course. With fifty-two parts. Downloading them all individually, one by one, when it takes half an hour to do each, and then converting them all manually with ffmpeg, would be a hideous nightmare. However, VLC is a Unix application by birth and by choice, and consequently it has a fully developed command-line interface. This means that it can be scripted. Which means that I can get all this done without a fuss or a bother; in the time it takes to download one video manually, or even less, I can write a script which will handle each and every one for me, and convert them all to Theora while it’s at it. But how, you ask?

RTFM! I went into the documentation and learned how to tell VLC to save a streaming video while it streams when invoking it on the command line, and how to tell vlc to exit when it’s done. (Check the script below!) This took about ten minutes. I then hammered out the script; I had to look up the syntax for while loops in a bash script, which took another ten minutes or so. I then ran it, corrected a couple of errors, and ran it again. About a half hour of work, and I was able to download and convert all fifty-two videos without a lick of trouble, while not even looking at the computer the entire time unless I wanted to. Without the scriptability of the command line, I would have had to nurse the whole process for well over twenty-four hours to get it done.

Yes, the command line is superior, if you read the documentation and take a few minutes to do it right instead of doing it easy. That’s the way with all fields; why should computers be any different? An automatic transmission is easy as pie; but a standard gets better gas mileage and provides better control.

It’s the same way with computers. A graphical interface is shiny and lets you pointy-clicky and probably after a few minutes accidentally stumble on whatever you need to do, then immediately forget how you did it until you pointy-clicky your way back to it again the next time. But the command line gets you more control, more facility, once you’ve learned how to use it. Learning how to use it requires work; there’s no two ways about it. But that work will pay off once you do it.

So here’s the script. Enjoy it in all its ugly wonder.

#!/bin/bash
# +AMDG

i="0"

while [ $i -lt 53 ]
do
     i=$[$i+1];
     if [ $i -lt 10 ]; then
	vlc --sout videos_{$i}of52.wmv mms://video_path_0$i.wmv vlc://quit;
	ffmpeg -i videos_{$i}of52.wmv -sameq -acodec libvorbis videos_{$i}of52.ogg;
     fi
     if [ $i -ge 10 ]; then
	vlc --sout videos_{$i}of52.wmv mms://video_path_$i.wmv vlc://quit;
	ffmpeg -i videos_{$i}of52.wmv -sameq -acodec libvorbis videos_{$i}of52.ogg;
     fi
done
exit;

Of course, this puts actual curly braces in the final file name, something I didn’t intend. But a quick line of bash, using the rename Perl script (standard on every Linux distribution I’ve used), took care of all that; another half-minute. Big whoop.

The condition is necessary because the videos are named in the form “video_$number.wmv”, where $number is always two-digit, even when it’s less than ten. They do this simply by adding a leading zero (as in “03″). That makes it show up in numerical order in file listings (instead of that annoying “video29, video3, video 30″ listing you’d get otherwise), but it did necessitate two different statements, one if there was a leading zero and one if not. I could have made this just one, but it was more work than it was worth, as this worked splendidly.

Learn the command line! It’s better!

Praise be to Christ the King!

Published in: on 3 November 2009 at 2:31 pm  Comments (6)  
Tags: , , , ,
Follow

Get every new post delivered to your Inbox.