Why does Linux only see 1GB of my 2GB SD Card?

August 31st, 2007

This mailing list post explains why.

A 2GB SD card reports a 1024 byte block size instead of the 512 byte block size that all smaller SD cards employ. However, I/O is performed in 512 byte blocks by the USB mass storage driver. The card reader is supposed to know about this and report a 512 byte block size, while multiplying the number of blocks reported by the card by 2, in order to report the correct card geometry to the operating system.

Older card readers do not know about this conversion, and may even assume that all SD cards have a 512 byte block size. Thus, a 512 byte block size is reported, along with the number of blocks reported by the card. This cuts the reported capacity of the card in half.

But the filesystem that exists on the card reports a 2GB size. On a system where the card physically only shows up as 1GB, this causes the FAT filesystem driver to read past the end of the card. This will produce read/write errors, and could even crash the filesystem driver if it is not equipped to deal with this case.

Windows reportedly employs one of two solutions to ensure that 2GB cards are correctly recognized.

The first solution is to assume that the card has a PC partition table on it (a mostly correct assumption for any card purchased retail). The Windows USB mass storage driver then examines the partition table to determine the number of blocks on the physical device, and ignores the number of blocks reported by the reader. A possible flaw with this scheme is that the Windows driver may not account for cases where a partition table has been erroneously or maliciously constructed, leading to an incorrect physical size being entered, and thus a device which cannot be correctly repartitioned or reformatted. It may also not account for the device being divided into several partitions. And of course this scheme won’t work for a card which is formatted without a partition table.

The other solution is to ignore the number of blocks reported by the reader, and to probe the size of the card by issuing test reads, probably in large increments at first and then smaller increments, until a read failure occurs. The read failure is assumed to occur because the read occurred past the end of the device. A possible flaw in this scheme is that a card with one or more defective sectors could cause the storage driver to believe it has found the end of the device, when in fact the read error occurs because of a bad sector.

At the moment, the solution for Linux and other operating systems which do not implement such hacks and which trust the card reader to report a useful block count and block size of the inserted card, is to buy a new card reader.

msmtp and Gmail

August 22nd, 2007

account gmail
host smtp.gmail.com
from username@gmail.com
auth on
user username@gmail.com
password mypass
tls on
tls_starttls off
tls_certcheck off
logfile /tmp/gmail.log

The synopsis: GMail doesn’t accept STARTTLS connections on port 25. The key is “tls_starttls off”, which causes the client to connect using SSL on port 465 instead…

Kerberos ticket forwarding and Reverse DNS

August 21st, 2007

You might get some confusing errors when attempting to login to your network from an outside network. The application reports “GSSAPI error: Miscellaneous failure” or “GSSAPI mech specific error: Server not found in Kerberos database”. Your Kerberos KDC log shows:

Aug 21 13:01:49 xanadu krb5kdc[30485]: TGS_REQ (3 etypes {16 1 3}) 66.9.16.190: UNKNOWN_SERVER: authtime 1187288
525,  nemesis@REALM.COM for krbtgt/ISP.COM@REALM.COM, Server not found in Kerberos database

What is important to note here is that the request is for a ticket for krbtgt/ISP.COM and not krbtgt/REALM.COM.

This happens because the client computer looks up the reverse DNS of the server computer, and attempts to get a ticket for the realm it appears to be a member of.

In this case, the server can be resolved to IP address by server.realm.com, but the Reverse DNS is controlled by the ISP, and so a reverse lookup on the server’s IP address gives a hostname that is on the ISP’s domain somewhere.

There are only a few ways to fix this:

  • Correct the public Reverse DNS for the remote server’s IP address (difficult to impossible depending on your ISP)
  • Add appropriate Reverse DNS entries for the remote server’s IP address to the client’s DNS server, and make the client’s DNS server authoritative for the remote server’s subnet
  • Add appropriate entries for the remote server to the client’s HOSTS file

The last option is probably the least painful if you are just trying to get seamless access from your work computer to home, for example.

A short howto for Linux volume labels

August 1st, 2007

You may have noticed from time to time as Linux evolves and device drivers change, the device nodes used to access your hard disks may sometimes change. Besides updating the root device on the kernel command line in your bootloader configuration, you also have to go through your /etc/fstab and make all the appropriate changes. That is assuming you still have a working kernel around…

Easier thing to do is refer to the volumes not by device node, but by LABEL or UUID. Every filesystem is assigned a UUID when it is created, and you can manually assign a human-readable LABEL by using the filesystem tuning tools. Once you have assigned a LABEL and/or UUID, then anywhere you would refer to a /dev/hdXX or /dev/sdXX device, use UUID=… or LABEL=… instead, where … is the actual UUID or LABEL that is assigned.

To set labels for a few filesystems:


ReiserFS: reiserfstune -l <label> /dev/XXXX
EXT2/3: tune2fs -L <label> /dev/XXXX
Swap: mkswap -L <label> /dev/XXXX

To retrieve labels and UUIDs for a few filesystems:


ReiserFS: reiserfstune /dev/XXXX (must be unmounted)
EXT2/3: tune2fs -l /dev/XXXX ("Filesystem volume name", "Filesystem UUID")
Swap: No way to retrieve, just relabel it with mkswap -L

After rebooting you will be able to see the volume labels in /proc/partitions.

Note: Only v1 (“new style”) swap devices can be labeled.

Error behavior

In ext2/ext3, you can also set the error behavior in the superblock so that when a filesystem error is encountered (due to corruption, CPU/memory failure or disk failure), the filesystem will be automatically remounted read-only or the kernel panicked. The default is to continue on errors. This is usually set in the fstab (errors=remount-ro or errors=panic), but it may be more convenient to have the default behavior set in the superblock. Simply issue tune2fs -e remount-ro /dev/hda1 for all your ext2/ext3 filesystems, and you will no longer have to have the verbosity in your /etc/fstab too…

PDC202xx_old driver is broken in Linux 2.6

August 1st, 2007

At some point, I started noticing my system (MSI BXMaster) would completely freeze under heavy disk load. After watching the logs, I would see something akin to the following:

Mar 11 17:27:19 dbz kernel: hdg: dma_timer_expiry: dma status == 0x60
Mar 11 17:27:19 dbz kernel: hdg: DMA timeout retry
Mar 11 17:27:19 dbz kernel: PDC202XX: Secondary channel reset.
Mar 11 17:27:19 dbz kernel: PDC202XX: Primary channel reset.
Mar 11 17:27:19 dbz kernel: hdg: timeout waiting for DMA
Mar 11 17:27:40 dbz kernel: hdg: dma_timer_expiry: dma status == 0x60
Mar 11 17:27:40 dbz kernel: hdg: DMA timeout retry
Mar 11 17:27:40 dbz kernel: PDC202XX: Secondary channel reset.
Mar 11 17:27:40 dbz kernel: PDC202XX: Primary channel reset.
Mar 11 17:27:40 dbz kernel: hdg: timeout waiting for DMA
Mar 11 17:28:02 dbz kernel: hdg: dma_timer_expiry: dma status == 0x60
Mar 11 17:28:02 dbz kernel: hdg: DMA timeout retry
Mar 11 17:28:02 dbz kernel: PDC202XX: Secondary channel reset.
Mar 11 17:28:02 dbz kernel: PDC202XX: Primary channel reset.
Mar 11 17:28:02 dbz kernel: hdg: timeout waiting for DMA
Mar 11 17:28:22 dbz kernel: hdg: dma_timer_expiry: dma status == 0x60
Mar 11 17:28:22 dbz kernel: hdg: DMA timeout retry
Mar 11 17:28:22 dbz kernel: PDC202XX: Secondary channel reset.
Mar 11 17:28:22 dbz kernel: PDC202XX: Primary channel reset.
Mar 11 17:28:22 dbz kernel: hdg: timeout waiting for DMA

Well, I was unable to find a 2.6 kernel that would work reliabily on my Promise chip (PDC20265), I went back several versions.

The fix is to NOT use the pdc202xx_old driver, but instead use the libata driver for old Promise chips (CONFIG_PATA_PDC_OLD=y). You will probably need to recompile your kernel for this because distribution kernels are not using libata yet.

Also, this will change your disk devices from /dev/hdX to /dev/sdX so be sure to update your /etc/fstab correspondingly.

If your distribution kernel includes CONFIG_PATA_PDC_OLD=m, you can use this by adding it to the initrd image. For initramfs-tools, the file /etc/initramfs-tools/modules should exist. Edit it, and add “pata_pdc202xx_old” without the quotes on a new line. Run update-initramfs -k all -u and you should be all set. This preloads the libata driver during the initrd, so that the faulty pdc202xx_old driver cannot be loaded later.

Tall people and success

July 26th, 2007

The secret to why tall people seem to be more successful and powerful?

It’s all related to the height of a standard cubicle.

Short people can’t monitor their employees as well because they can’t see over the cubicles as they walk past or stand nearby.

The obvious solution is to cut down the height of a standard cubicle, until it is comparable to the height of a standard picket fence.

Then short people will have true equal opportunity!

Idea for blog spam

July 18th, 2007

This only works if blog spamming is a compute and/or bandwidth intensive activity.

Publish a standard file or URL like robots.txt that blogs can provide in order to notify a robot that comments are moderated.

By market forces, robots should check this so they do not waste their computing time and bandwidth spamming moderated blogs.

Alternatively. Remember those copy protection things in computer games of the 80’s? “Please type in the third word of the second paragraph on the eighth page.”

This could be used in blog captchas too. Make the instructions of which word(s) to find just convoluted enough to avoid machine parsing, and you’re good to go. The instructions can then be generated on the fly.

Proof of concept to follow.

How to skin a banker

July 16th, 2007

Banks are offering incredible incentives for opening new checking/savings accounts and credit cards lately. Bank of America recently offered $100 to open a new checking account, US Bank $125, Citibank $200 or 20,000 reward points. Chase offered 200 reward points good for $250 cash on the Freedom credit card, BofA $250 cash on the Iowa Rewards credit card, American Express 25,000 reward points (good for $250 gift card), on and on.

How do you find out and pocket this awesome deals?

Maintain a good credit score and a clean history

There are too many factors to list here that goes into this, but assuming you always pay your bills on time, the most important thing to do here is to keep a long history, keep your overall debt to income ratio low, keep your credit balance to credit limit low (below 50% if possible), keep your credit limit to income ratio low, and keep your average credit limit on revolving accounts high (low credit limits on your existing accounts make new lenders suspicious). How do you do this?

  • Never close your oldest accounts, no matter how bad the terms are, and utilize the cards occasionally to keep the accounts active.
  • Close any new accounts after you have received the sign-up incentive
  • Ask for low credit limits on new cards, but close any accounts with a low credit limit as soon as possible.
  • On cards you are carrying a balance on (hopefully at 0%!), always maintain a balance less than half of the credit limit. A balance of between 15% and 50% will help your score. Note that many lenders will not report your credit limit, and as such the highest recorded balance on an account will be used as the limit for purposes of credit reporting… keep this in mind.

Closing any account can come with a hidden benefit — see Retention below.

Enroll in a credit monitor service with instant credit score pull

You should expect to pay around $10 a month for a full credit monitoring service with instant pull in the absence of a promotion. This will let you see which issuers are making hard credit inquiries (which temporarily hurt your score). Banks will often pull your credit report even if you are applying for an account (in addition to the usual CHEX Systems inquiry for bank accounts).

Find the best credit card deals

The Finance forum at Fatwallet.com and the forums at SlickDeals.net are awesome for keeping on top of these offers as they come out, and discussing how to perform social engineering on companies who don’t make good on the offers.

Make sure you followed the right link

The same credit card or bank account may be offered through several different links, some with the bonus and some without. Make sure you followed a link that included the bonus, or that you apply the correct promotional code while applying for the account.

Utilize CardSelection.com

CardSelection.com pays a cash rebate when you apply for a card through their website and are approved. Frequently, you can get the same card promotion that you would get externally, and then you get the CardSelection.com rebate on top of it.

Print a hard copy of the offers

Use a screen shot utility or a PDF printer to capture the offer details from your browser. This way, you have the ID/promo code as well as the terms for later reference, or when the company doesn’t make good on the offer.

Use a cell phone number for your work number, but always use your land line home phone number for the home phone number

The home phone number is what is verified during the application process, but the work phone number is what is called later to reference the application. So using your cell phone number as your work number makes it easier to contact you, but using anything other than your land line number as your home phone number is virtually guaranteed to hold up your application. If you are concerned about commercial calls on your cell or work phone, simply place them on the Do Not Call registry.

Credit limits are mostly per-bank

There is an overall credit limit to income ratio that is considered as part of your credit score, but when a particular bank is weighing whether to issue you a new card or not, the most important factor is the ratio of your credit limit with THEM to your income. It makes sense, because they really don’t care if you default with another bank — especially in this age of universal default. All they really care about is the level of risk you pose to them.

One way you can get approved for more cards is by making an online application with the offer you want, and then following up with a phone call to the bank’s credit card application center. The CSA will be able to get your new account opened by reallocating credit lines from another account. They will ask how much of a credit limit you want on the new card, and what other cards you would like them to reduce the credit limit on. (To maximize your chances of success, ask for a low limit and allow them to source the credit limit from any other card.) It is important to call if your application is at all in question (for example, if it is the third, fourth, or more card from the same issuer). If you do not call and you are at or near the limit of credit that bank is willing to extend to you, your application will simply be declined.

If the CSA is curious why you want more new cards, tell them that you like having separate cards for separate categories of purchases (such as online purchases, utility bills, rent, etc), either because it keeps you more organized or because it lets you take care of fraud more easily. Or you could say that you want more accounts because you are trying to build up your credit score. Or you simply like the design offered on the new card. Don’t mention that you are trying to get extra signup bonuses!

Sign up for snail mail offers and maybe email offers

It doesn’t hurt to get promotions in the mail. Just recycle them if you’re not interested. You can usually opt out of phone and email communication without opting out of snail mail. You may want to consider setting up a special e-mail account for bank related stuff, because they do send very nice reward offers through email from time to time (along with spam from companies they sell your info to…) For example, US Bank and Chase are known to send bonus promotions via e-mail, and many rewards credit cards will send special time-limited promotions where you can spend a certain amount of money before a deadline and receive a bonus.

Comply with the terms of the offer

If you don’t think you can comply with the terms of the offer, don’t bother. Noncompliance with the terms of the offer on bank accounts usually is associated with account maintenance fees, to add insult to injury. Noncompliance with the terms of the offer on a credit card with an annual fee that is not waived with the offer is similarly injurious.

Credit card offers are also usually easier to take advantage of (bonus posts after first purchase or after certain amount purchased, while bank offers require so many months of direct deposit, etc). Bank accounts typically have account maintenance fees associated with non-compliance, where credit cards do not. Opening a bank account with a new bank (many bank promotions are for new customers only) is typically quite annoying, because many things can go wrong with getting the opening deposit credited, several forms of ID sent, and getting online access to the account.

Bank accounts frequently require a huge opening deposit to qualify for the bonus, even if there is no minimum balance on the account. To put this into action, if you have a 0%/no-fee cash advance and 0%/no-fee balance transfer combo, use it. Otherwise, utilize an offer at another bank that allows you to open an account and initially fund it with a credit card as a purchase, not a cash advance. Once the ‘bounce’ account is open, transfer the funds to your main account at that bank, and then either withdraw the cash and deposit it at the other bank or initiate a ACH transfer from the other bank’s end. Once the opening deposit has been received at the other bank, simply use their online bill pay to pay off the credit card balance that you sourced the funds from once the credit card statement posts, and continue to comply with the remaining terms of the bank’s offer.

For a nice one-two punch, use a credit card which requires a large purchase requirement to qualify for its opening bonus as the source of the initial funding. Turn it into money by opening a bank account that will perform the initial funding as a credit card purchase. Transfer that money to the bank with the promotion to satisfy the opening deposit requirement, and finally pay the credit card off from that bank after the statement posts. Then you will receive the credit card bonus for nothing more than “purchasing” your own money! And, you will receive reward points or cashback as if you had made a normal credit card purchase. You’ve foiled both a huge opening deposit and a huge purchase requirement at once, by playing them against each other, and come out on top in every way… THAT is how to skin a banker, folks!

Taxes

Most bank account offers will be reported as interest income to the IRS. Credit card offers come in the form of rewards and statement credits, so they are exempt.

Think about how to use reward points

If you can get cash for points at or near 1:1, that’s a no-brainer, take the cash and either take a bite out of any debt you have, or drop it into a high yield CD. If you can only take the reward in the form of gifts, some good investments for rewards for would be home improvement gift cards (increase your home equity) or student loan repayment vouchers. And of course you can redeem your rewards for gift cards for other people for weddings, birthdays, and other special events (upon which you would be buying them gifts anyway).

Don’t go out and buy disposable junk from China, or unnecessary household or entertainment items, just because you feel that the bonus is ‘free’ or that you don’t have a choice how to utilize it. For example, if your only choice is to receive some gift card or voucher that is useless in terms of increasing your equity or happiness, then sell it on EBay. Invest wisely end-to-end on the deal and you come out even further ahead!

Apply multiple times

If there aren’t any better opportunities, it doesn’t hurt to go for the same offer multiple times. The worst that will happen is that your application is declined, or that you fail to receive the offer. Having numerous bank accounts and credit card accounts, even with the same product from the same bank, is common now.

Retention offers

When you call to cancel your credit card or close your bank account after you received the signup bonus, you will occasionally be given a special offer to retain your business. This is especially prevalent on credit cards with annual fees. With credit cards, you can usually just ask straight away if your account qualifies for retention. Take the offer if you want it, then call again after you receive the bonus and attempt to cancel/close again. If they don’t offer retention when you ask specifically for it, don’t then close the account. Call back later and close it. Sometimes they won’t offer retention if you ask straightaway with awareness of it, but if you call and pretend to aloofly ask to close the account, they may counter with an offer.

Arbitrage

While applying for all these bonuses, you might accidentally fall into another good deal. Keep your eye out specifically for:

  • Credit cards with 0% cash advances, bank accounts that can be initially funded from a credit card as a purchase, or credit cards with balance transfer checks and a 0% interest offer
  • In combination with a 0% cash advance card, credit cards with capped balance transfer fees (i.e., 3% up to $75 or similar) and with a 0% interest rate for some period of time

The goal is to obtain money that you can place into a high yield savings account to make back any fees you paid, and then earn interest free and clear. The 0% cash advance card, initial account funding via credit card, or balance transfer check can be used to take a cash advance which you then transfer to a high yield savings account (earning 5-6%). If you took a cash advance, then use a capped balance transfer card to transfer the balance off that card, avoiding the cash advance interest rate. When the 0% deal is over, use another balance transfer or pay off the card from savings.

Some cards have 0% offers that can be extended as long as the card has regular monthly purchase activity. These are awesome for this scheme.

This scheme will hurt your credit score in the short term, because of the high debt to income and debt to credit limit ratios, but in the end as long as you don’t screw up, your credit score will come out even higher. Don’t do this if you anticipate needing to apply for a loan in the near future, because getting a crappy rate on a long-term loan due to a banged up credit score isn’t worth the few hundred bucks (after income tax) in interest you earn from this scheme.

How to do an end run around the GPL with retail software

June 26th, 2007

1. Include a GPL-based program in your retail software version 1.0.
2. 3 months after 1.0 is released, release version 1.1 and cease distributing 1.0.
3. Delete the sources to 1.0.
4. Repeat ad infinitum.
5. ???
6. Profit!

This way you only have to satisfy source requests from customers who request it up front immediately after their purchase. Immediately after a direct purchase from you, that is — if the boxed software is sold by a distribution house after you have moved to a new version, well that’s no longer your problem, is it? And those pesky customers who have to maintain your software in the field will just have to do without the sources to any prior versions that you no longer distribute. Bonus points if they purchase upgrades to the new version because of this scheme.

For extra evil, you can refer customers who ask for source to a generic upstream mirror for the “sources”, as long as they don’t make enough noise about your violation of the GPL.

Bank of America “security”

June 26th, 2007

When you’re in a Bank of America online banking session, if your session goes idle for too long, the site pops up an alert box letting you know that your session has timed out due to inactivity. The alert box then redirects to a page which destroys your session and presents a login. This scheme can be easily defeated by immediately refreshing the page after dismissing the alert box, before the redirect occurs… thanks, BOA.