Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Aug 1998 12:38:37 +0200
From:      Stefan Eggers <seggers@semyam.dinoco.de>
To:        zhihuizhang <bf20761@binghamton.edu>
Cc:        hackers <freebsd-hackers@FreeBSD.ORG>, seggers@semyam.dinoco.de
Subject:   Re: fs_cs() macro in FFS 
Message-ID:  <199808261038.MAA04028@semyam.dinoco.de>
In-Reply-To: Your message of "Tue, 25 Aug 1998 11:33:33 EDT." <Pine.SOL.L3.93.980825112655.12734A-100000@bingsun2> 

next in thread | previous in thread | raw e-mail | index | archive | help
> #define fs_cs(fs, indx) \
>         fs_csp[(indx) >> (fs)->fs_csshift] [(indx) & ~(fs)->fs_csmask]
> 
> Since fs_csp is defined as an array of pointers to csum structure, I can
> not see why it is accessed as a two-dimension array (I just write a small

Just the usual trick in C of making a dynamically sized two dimen-
sional array.  One makes a pointer to a pointer and allocates it in
the right way.  Here the first index is limited to MAXCSBUFS (a small
integer) and thus can be made a real C array of pointers.  The second
one depends on the filesystem and can't be treated this way.

If you look at the code which allocates it (in ffs_mountfs in the file
ffs_vfsops.c) you'll notice it gets allocated as a huge array and then
every fs_csp[i] gets a pointer into this huge array makeing up in
effect a two dimensional array.

It would surely be easier to understand and produce less complex code
in some places to make it just one array.  Doing it the way it is
requires fewer operations for getting a superblock from disk to memory
as the array fs_csp is already in the structure - one just has to
initialize it.

Why it is there I don't know.  It is already in the CSRG labelled
sources in the repository.  If I had to guess mine would be that once
the pointers were also used to hold the block numbers of the blocks
containing these information.

Stefan.
-- 
Stefan Eggers                 Lu4 yao2 zhi1 ma3 li4,
Max-Slevogt-Str. 1            ri4 jiu3 jian4 ren2 xin1.
51109 Koeln
Federal Republic of Germany

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199808261038.MAA04028>