From owner-freebsd-hackers Sat Aug 29 15:47:52 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id PAA14557 for freebsd-hackers-outgoing; Sat, 29 Aug 1998 15:47:52 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from word.smith.net.au (castles153.castles.com [208.214.165.153]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id PAA14552 for ; Sat, 29 Aug 1998 15:47:49 -0700 (PDT) (envelope-from mike@word.smith.net.au) Received: from word.smith.net.au (localhost [127.0.0.1]) by word.smith.net.au (8.9.1/8.8.8) with ESMTP id PAA08998; Sat, 29 Aug 1998 15:45:03 GMT (envelope-from mike@word.smith.net.au) Message-Id: <199808291545.PAA08998@word.smith.net.au> X-Mailer: exmh version 2.0.2 2/24/98 To: zhihuizhang cc: hackers Subject: Re: Macro cbtorpos() in fs.h In-reply-to: Your message of "Sat, 29 Aug 1998 15:06:39 -0400." Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sat, 29 Aug 1998 15:45:02 +0000 From: Mike Smith Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > I am trying to understand the macro cbtorpos() defined below: > > #define cbtorpos(fs, bno) \ > (((bno) * NSPF(fs) % (fs)->fs_spc / (fs)->fs_nsect * (fs)->fs_trackskew + \ > (bno) * NSPF(fs) % (fs)->fs_spc % (fs)->fs_nsect * (fs)->fs_interleave) % \ > (fs)->fs_nsect * (fs)->fs_nrpos / (fs)->fs_npsect) > > > First I assume that the hard disk sectors are numbered from one cylinder > to another, moving from top track to the bottom track before moving to the > next cylinder. (This is the vertical mapping as described at the site > http:/www.tomshardware.com/hdd.html). Otherwise, the macro might not make > any sense. Yes. Logically block numbers are ordered in ascending order by track, head, cylinder. However it's worth considering, before you get too involved here, that most disks these days don't have the geometry that inspired these calculations, and when building filesystems we deliberately attempt to defeat these caclulations. > So bno * NSPF % fs_spc / fs_nsect will give us the track number and bno * > NSPF % fs_spc % fs_nsect will give us the sector count within that track. > However, the rest part of the macro is confusing to me. If I understand it correctly, the macro calculates the rotational position of the block number (bno) in the filesystem (fs). This is used for two things in ffs_alloc.c - When allocating a block, in the code which attempts to find the optimal block based on the filesystem's idea of the disk geometry. We defeat this code by setting fs_nrpos to 1 when building filesystems. - When accounting for block usage, it's used to generate an offset into the free block table for a given cylinder. Because we defeat much of the calculation with our filsystem layout, particularly by only distinguishing one rotational position per cylinder, I suspect that for FreeBSD filesystems the macro will normally return 0 (it might be a small optimisation to detect this case and avoid the calculations involved therin). In particular; fs_nsect will normally be == fs_npsect, and fs_rpos will be 1, so the entire macro reduces to (X) % ((z * 1) / z). You can see the fs_nsect and fs_npsect calculations in the newfs source, where fs_nsect is set from nsectors and fs_npsect is set from nphyssectors, and nphyssectors = nsectors + trackspares where trackspares is normally set to 0. For filesystems from other operating systems (eg. NetBSD), who don't optimise their filesystem layout for modern hardware, it will return an appropriate offset to suit the layout. Similarly if the optimised defaults used by FreeBSD's newfs are overridden when the filesystem is being generated. > I assume that fs_nsect + unused sectors = fs_npsect That would appear to be valid from the above. > and the C operators %, /, and * all > have same precedence. You can check /usr/share/misc/operator for that one. The policy implemented in ffs_alloc.c is discussed in "The Design and Implementation of the 4.4BSD Operating System", McKusic, Bostic, Karels and Quarterman, ISBN 0-201-54979-4 in section 8.2, subheading "Allocation Mechanisms" starting on page 277. Rotational positions are discussed on page 280. Our local policy changes are documented mostly in the CVS repository, and many are summarised in src/sbin/newfs/newfs.c. I hope this is at least a little helpful. -- \\ Sometimes you're ahead, \\ Mike Smith \\ sometimes you're behind. \\ mike@smith.net.au \\ The race is long, and in the \\ msmith@freebsd.org \\ end it's only with yourself. \\ msmith@cdrom.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message