9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Russ Cox" <rsc@swtch.com>
To: josh@utopian.net
Cc: 9fans@cse.psu.edu
Subject: Re: [9fans] p9p vbackup fs type endiannes
Date: Tue, 27 Nov 2007 10:28:56 -0500	[thread overview]
Message-ID: <20071127152858.80AC81E8C22@holo.morphisms.net> (raw)
In-Reply-To: <9C0A4F7F-8220-43AE-9538-1AB5F56A24A8@utopian.net>

>> I have never tried to run the ext2 reading code on a
>> little-endian machine.
> 
> I assumed above was a typo and that we're talking about
> big-endian powerpc.

Yes, sorry.

> I would too -- doesn't the filesystem's inode lookup method
> usually (on Unix) do any endianness swap for inode numbers
> and metadata? I guess I'd expect that to apply for superblock
> metadata as well.

Actually I thought that the file systems just stored in the
host byte order on disk, so that powerpc ext2 would be different
from 386 ext2.  But apparently that's not true and they're
all little-endian.

>> It's possible that the superblock magic code
>> is really two bytes and not a short,
> 
> I didn't intend to imply the magic was two bytes; the linux source
> seems to make it an unsigned short, yes. I must not follow you here;
> isn't a short in this context also 16 bits/2 bytes, and always at least
> that long, so still subject to endianness?

What I meant was that if you define

	struct Super {
		uchar magic1;
		uchar magic2;
	};

vs

	struct Super {
		ushort magic;
	}:

then in the first if you fill in the bytes magic1 = 0x53 and
magic2 = 0xEF, you are byte-order independent, but in the
second if you fill in magic = 0xEF53 then you're not.

If the magic was the only field on disk that ended up in the
wrong order, then I was suggesting that maybe it should
look like the former instead of the latter.

But it's all the fields that are screwed up.  The disk filled up
because vbackup thought the file system was some ridiculous
size because something like 0x12345 blocks
becomes 0x45230100 blocks if you read it backward.

I've changed libdiskfs to read the data in little-endian order
no matter what the underlying architecture.

Try running

	cd /usr/local/plan9/src/libdiskfs; cvs up
	mk
	cd ../cmd/vbackup
	mk clean
	mk all
	mk install
	mk clean

and then try again.

Russ


       reply	other threads:[~2007-11-27 15:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <9C0A4F7F-8220-43AE-9538-1AB5F56A24A8@utopian.net>
2007-11-27 15:28 ` Russ Cox [this message]
2007-11-22  9:01 Joshua Wood
2007-11-22 15:42 ` Russ Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071127152858.80AC81E8C22@holo.morphisms.net \
    --to=rsc@swtch.com \
    --cc=9fans@cse.psu.edu \
    --cc=josh@utopian.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).