PERFORCE change 165323 for review
Aditya Sarawgi
truncs at FreeBSD.org
Sat Jun 27 17:09:18 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=165323
Change 165323 by truncs at aditya on 2009/06/27 17:09:04
Fixed lot of errors
1) In the current implementation the in-memory superblock has a *pointer* to on-core superblock.
2) The in-memory superblock has buffer to store group descriptors and it's not stored directly as in NetBSD
3) Other Typos
4) Some functions that are not implemented are guarded by #ifdef notyet
Affected files ...
.. //depot/projects/soc2009/soc_ext2fs/src/sys/gnu/fs/ext2fs/ext2_alloc.c#19 edit
Differences ...
==== //depot/projects/soc2009/soc_ext2fs/src/sys/gnu/fs/ext2fs/ext2_alloc.c#19 (text+ko) ====
@@ -43,6 +43,7 @@
#include <sys/stat.h>
#include <sys/mount.h>
#include <sys/syslog.h>
+#include <sys/buf.h>
#include <gnu/fs/ext2fs/inode.h>
#include <gnu/fs/ext2fs/ext2_mount.h>
@@ -50,14 +51,19 @@
#include <gnu/fs/ext2fs/fs.h>
#include <gnu/fs/ext2fs/ext2_extern.h>
+#ifdef notyet
static daddr_t ext2_alloccg(struct inode *, int, daddr_t, int);
+#endif
static u_long ext2_dirpref(struct m_ext2fs *);
static void ext2_fserr(struct m_ext2fs *, u_int, char *);
static ino_t ext2_hashalloc(struct inode *, int, long, int,
daddr_t (*)(struct inode *, int, daddr_t,
int));
-static daddr_t ext2_nodealloccg(struct inode *, int, daddr_t. int);
+static daddr_t ext2_nodealloccg(struct inode *, int, daddr_t, int);
+#ifdef notyet
static daddr_t ext2_mapsearch(struct m_ext2fs *, char *, daddr_t);
+#endif
+static void mark_buffer_dirty2(struct buf *);
/*
* Linux calls this functions at the following locations:
@@ -386,7 +392,7 @@
cg = ext2_dirpref(fs);
else
cg = ino_to_cg(fs, pip->i_number);
- ipref = cg * fs->e2fs.e2fs_ipg + 1;
+ ipref = cg * fs->e2fs->e2fs_ipg + 1;
ino = ext2_hashalloc(pip, cg, (long)ipref, mode, ext2_nodealloccg);
if (ino == 0)
@@ -559,17 +565,19 @@
ext2_dirpref(struct m_ext2fs *fs)
{
int cg, maxspace, mincg, avgifree;
-
- avgifree = fs->e2fs.e2fs_ficount / fs->e2fs_ncg;
+ struct ext2_gd *gdp = NULL;
+ avgifree = fs->e2fs->e2fs_ficount / fs->e2fs_gcount;
maxspace = 0;
mincg = -1;
- for (cg = 0; cg < fs->e2fs_ncg; cg++)
- if ( fs->e2fs_gd[cg].ext2bgd_nifree >= avgifree) {
- if (mincg == -1 || fs->e2fs_gd[cg].ext2bgd_nbfree > maxspace) {
+ for (cg = 0; cg < fs->e2fs_gcount; cg++) {
+ gdp = (struct ext2_gd *) fs->e2fs_group_desc[cg]->b_data;
+ if ( gdp->ext2bgd_nifree >= avgifree) {
+ if (mincg == -1 || gdp->ext2bgd_nbfree > maxspace) {
mincg = cg;
- maxspace = fs->e2fs_gd[cg].ext2bgd_nbfree;
+ maxspace = gdp->ext2bgd_nbfree;
}
}
+ }
return mincg;
}
@@ -599,10 +607,10 @@
/*
* 2: quadratic rehash
*/
- for (i = 1; i < fs->e2fs_ncg; i *= 2) {
+ for (i = 1; i < fs->e2fs_gcount; i *= 2) {
cg += i;
- if (cg >= fs->e2fs_ncg)
- cg -= fs->e2fs_ncg;
+ if (cg >= fs->e2fs_gcount)
+ cg -= fs->e2fs_gcount;
result = (*allocator)(ip, cg, 0, size);
if (result)
return (result);
@@ -612,13 +620,13 @@
* Note that we start at i == 2, since 0 was checked initially,
* and 1 is always checked in the quadratic rehash.
*/
- cg = (icg + 2) % fs->e2fs_ncg;
- for (i = 2; i < fs->e2fs_ncg; i++) {
+ cg = (icg + 2) % fs->e2fs_gcount;
+ for (i = 2; i < fs->e2fs_gcount; i++) {
result = (*allocator)(ip, cg, 0, size);
if (result)
return (result);
cg++;
- if (cg == fs->e2fs_ncg)
+ if (cg == fs->e2fs_gcount)
cg = 0;
}
return (0);
@@ -630,22 +638,24 @@
* Check to see if a block of the appropriate size is available,
* and if it is, allocate it.
*/
-
+#ifdef notyet
static daddr_t
ext2_alloccg(struct inode *ip, int cg, daddr_t bpref, int size)
{
struct m_ext2fs *fs;
char *bbp;
struct buf *bp;
+ struct ext2_gd *gdp = NULL;
/* XXX ondisk32 */
int error, bno, start, end, loc;
-
+
fs = ip->i_e2fs;
- if (fs->e2fs_gd[cg].ext2bgd_nbfree == 0)
+ gdp = (struct ext2_gd *) fs->e2fs_group_desc[cg]->b_data;
+ if (gdp->ext2bgd_nbfree == 0)
return (0);
lock_super(DEVVP(ip));
error = bread(ip->i_devvp, fsbtodb(fs,
- fs->e2fs_gd[cg].ext2bgd_b_bitmap),
+ gdp->ext2bgd_b_bitmap),
(int)fs->e2fs_bsize, NOCRED, &bp);
if (error) {
brelse(bp);
@@ -676,7 +686,7 @@
start = dtogd(fs, bpref) / NBBY;
else
start = 0;
- end = howmany(fs->e2fs.e2fs_fpg, NBBY) - start;
+ end = howmany(fs->e2fs->e2fs_fpg, NBBY) - start;
for (loc = start; loc < end; loc++) {
if (bbp[loc] == 0) {
bno = loc * NBBY;
@@ -690,7 +700,7 @@
}
}
- bno = ext2fs_mapsearch(fs, bbp, bpref);
+ bno = ext2_mapsearch(fs, bbp, bpref);
if (bno < 0){
unlock_super(DEVVP(ip));
return (0);
@@ -704,14 +714,14 @@
}
#endif
setbit(bbp, (daddr_t)bno);
- fs->e2fs.e2fs_fbcount--;
- fs->e2fs_gd[cg].ext2bgd_nbfree--;
- mark_buffer_dirty(bp);
+ fs->e2fs->e2fs_fbcount--;
+ gdp->ext2bgd_nbfree--;
+ mark_buffer_dirty2(bp);
fs->e2fs_fmod = 1;
unlock_super(DEVVP(ip));
- return (cg * fs->e2fs.e2fs_fpg + fs->e2fs.e2fs_first_dblock + bno);
+ return (cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + bno);
}
-
+#endif
/*
* Determine whether an inode can be allocated.
*
@@ -724,17 +734,19 @@
struct m_ext2fs *fs;
char *ibp;
struct buf *bp;
+ struct ext2_gd *gdp = NULL;
int error, start, len, loc, map, i;
ipref--; /* to avoid a lot of (ipref -1) */
if (ipref == -1)
ipref = 0;
fs = ip->i_e2fs;
- if (fs->e2fs_gd[cg].ext2bgd_nifree == 0)
+ gdp = (struct ext2_gd *) fs->e2fs_group_desc[cg]->b_data;
+ if (gdp->ext2bgd_nifree == 0)
return (0);
lock_super(DEVVP(ip));
error = bread(ip->i_devvp, fsbtodb(fs,
- fs->e2fs_gd[cg].ext2bgd_i_bitmap),
+ gdp->ext2bgd_i_bitmap),
(int)fs->e2fs_bsize, NOCRED, &bp);
if (error) {
brelse(bp);
@@ -743,14 +755,24 @@
}
ibp = (char *)bp->b_data;
if (ipref) {
- ipref %= fs->e2fs.e2fs_ipg;
+ ipref %= fs->e2fs->e2fs_ipg;
if (isclr(ibp, ipref))
goto gotit;
}
start = ipref / NBBY;
- len = howmany(fs->e2fs.e2fs_ipg - ipref, NBBY);
+ len = howmany(fs->e2fs->e2fs_ipg - ipref, NBBY);
loc = skpc(0xff, len, &ibp[start]);
- if (l}
+ if (loc == 0) {
+ len = start + 1;
+ start = 0;
+ loc = skpc(0xff, len, &ibp[0]);
+ if (loc == 0) {
+ printf("cg = %d, ipref = %lld, fs = %s\n",
+ cg, (long long)ipref, fs->e2fs_fsmnt);
+ panic("ext2fs_nodealloccg: map corrupted");
+ /* NOTREACHED */
+ }
+ }
i = start + len - loc;
map = ibp[i];
ipref = i * NBBY;
@@ -764,15 +786,15 @@
/* NOTREACHED */
gotit:
setbit(ibp, ipref);
- fs->e2fs.e2fs_ficount--;
- fs->e2fs_gd[cg].ext2bgd_nifree--;
+ fs->e2fs->e2fs_ficount--;
+ gdp->ext2bgd_nifree--;
fs->e2fs_fmod = 1;
if ((mode & IFMT) == IFDIR) {
- fs->e2fs_gd[cg].ext2bgd_ndirs++;
+ gdp->ext2bgd_ndirs++;
}
- mark_buffer_dirty(bp);
+ mark_buffer_dirty2(bp);
unlock_super(DEVVP(ip));
- return (cg * fs->e2fs.e2fs_ipg + ipref +1);
+ return (cg * fs->e2fs->e2fs_ipg + ipref +1);
}
/*
@@ -781,7 +803,7 @@
* It is a panic if a request is made to find a block if none are
* available.
*/
-
+#ifdef notyet
static daddr_t
ext2_mapsearch(struct m_ext2fs *fs, char *bbp, daddr_t bpref)
{
@@ -796,7 +818,7 @@
start = dtogd(fs, bpref) / NBBY;
else
start = 0;
- len = howmany(fs->e2fs.e2fs_fpg, NBBY) - start;
+ len = howmany(fs->e2fs->e2fs_fpg, NBBY) - start;
loc = skpc(0xff, len, &bbp[start]);
if (loc == 0) {
len = start + 1;
@@ -820,8 +842,8 @@
panic("ext2fs_mapsearch: block not in map");
/* NOTREACHED */
}
-
-void mark_buffer_dirty(struct buf *bh)
+#endif
+void mark_buffer_dirty2(struct buf *bh)
{
int s;
More information about the p4-projects
mailing list