Subject: libsa/ufs.c
To: None <port-mac68k@netbsd.org>
From: None <nigel@ind.tansu.com.au>
List: tech-kern
Date: 02/21/2002 13:32:10
(sorry for the cross-post, I am currently unsubscribed to tech-kern)


	I am trying to use libsa/ufs.c in a MacOS program
(the NetBSD/Mac68k Booter), and have struck a strange problem.

	ufs_open() works fine, but when either it, or ufs_read()
use buf_read_file() to read data, it is reading a block 2 times
what I expect. e.g.:

			  Old MacOS code    libsa code
Step:			   reads block:	   reads block:
-------------------------------------------------------
ufs_open()
 Read FS header			16		16
 Read diinode			56		56
 unknown			580		1160
 Parse inodes, discover
 file's first block is 1428
 unknown			18436
ufs_read()
 Read first block		1428		2856
-------------------------------------------------------

	Now, the problem seems to be here in buf_read_file():

        if (file_block != fp->f_buf_blkno) {
                rc = block_map(f, file_block, &disk_block);
                if (rc)
                        return (rc);

                if (fp->f_buf == (char *)0)
                        fp->f_buf = alloc(fs->fs_bsize);

                if (disk_block == 0) {
                        bzero(fp->f_buf, block_size);
                        fp->f_buf_size = block_size;
                } else {
#if !defined(LIBSA_NO_TWIDDLE)
                        twiddle();
#endif
                        rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
                                fsbtodb(fs, disk_block),
                                block_size, fp->f_buf, &fp->f_buf_size);



It calls block_map() which sets disk_block correctly, but then
the actual block read is determined by fsbtodb(fs, disk_block),
which in my case is doubling it.



	fsbtodb is the default one in ufs/ffs/fs.h:
#define fsbtodb(fs,b) ((b) << (fs)->fs_fsbtodb)
so does this mean:

1) My fs is incorrect? 
   (It was created by MacOS X's newfs -O)

2) My DEV_STRATEGY() is wrong,
   and needs to map between NetBSD and MacOS block sizes?
   (This seems unlikely, because the earlier blocks,
    like the header, are read in correctly)

3) I have included the wrong header files somewhere?
   (All seems OK - e.g. DEV_BSIZE is 512)

-- 
| Nigel Pearson, nigel@ind.tansu.com.au    |    "Things  you  own        |
| Telstra iDevelopments, Sydney, Australia |     end up owning you"      |
|   Office: 9206 3468    Fax:  9212 6329   | "not a beautiful snowflake" |
|   Mobile: 0408 664435  Home: 9792 6998   |     Tyler - Fight Club      |