DragonFly BSD
DragonFly kernel List (threaded) for 2004-11
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

learning dragonfly or C...


From: "George Georgalis" <george@xxxxxxxxx>
Date: Thu, 11 Nov 2004 01:58:20 -0500

A couple days ago some code in a patch caught my eye and I decided
to take a closer look. The patch itself might be more interesting
than the result because it simplifies a function.

Let me set the context a bit, I know very little C but most of Bash,
my second language after BASIC was Pascal. I didn't do anything
major in Pascal but it left me with an impression of a 'right' way
to do things and what advanced concepts looked like.

Now it seems if I don't jump into C quickly, the separation between
my understanding of dragonfly applications and the underlying code
will only grow. So here goes, incomplete answers are better than no
answers so if you can point me in the right direction, that would be
appreciated.


When jumping into a block of code that has functions and
declarations, what is an efficient way to to find those definition
amidst all the includes, paths and Makefiles of the whole tree,
without completely losing your place? (eg I'd like to reference
O_RDONLY and fp_close)


The code that caught my eye is the in the top of the first diff in
http://leaf.dragonflybsd.org/~dillon/vfsx22.patch

In checkpt.c, this:

static int
mmap_vp(struct vn_hdr *vnh)
{
        struct vnode **vpp, *vp;
        Elf_Phdr *phdr;
        struct file *fp;
        int error;
        TRACE_ENTER;
        vpp = &vp;

        phdr = &vnh->vnh_phdr;

        if ((error = ckpt_fhtovp(&vnh->vnh_fh, vpp)) != 0)
                return error;
        /*
         * XXX O_RDONLY -> or O_RDWR if file is PROT_WRITE, MAP_SHARED
         */
        if ((error = fp_vpopen(*vpp, O_RDONLY, &fp)) != 0)
                return error;
        error = mmap_phdr(fp, phdr);
        fp_close(fp);
        TRACE_EXIT;
        return error;
}



becomes



static int
mmap_vp(struct vn_hdr *vnh)
{
        struct vnode *vp;
        Elf_Phdr *phdr;
        struct file *fp;
        int error;
        TRACE_ENTER;

        phdr = &vnh->vnh_phdr;

        if ((error = ckpt_fhtovp(&vnh->vnh_fh, &vp)) != 0)
                return error;
        /*
         * XXX O_RDONLY -> or O_RDWR if file is PROT_WRITE, MAP_SHARED
         */
        if ((error = fp_vpopen(vp, O_RDONLY, &fp)) != 0) {
                vput(vp);
                return error;
        }
        error = mmap_phdr(fp, phdr);
        fp_close(fp);
        TRACE_EXIT;
        return error;
}



This is the part of the diff that interests me:

-	struct vnode **vpp, *vp;
+	struct vnode *vp;
 	Elf_Phdr *phdr;
 	struct file *fp;
 	int error;
 	TRACE_ENTER;
-	vpp = &vp;


I have a general idea about the use of pointers, but don't really
understand how they are used. What exactly does this syntax mean?

        struct vnode **vpp, *vp;
        vpp = &vp;

The other changes explain it a little to me: a degree of pointer
reference has been removed and the function is basicly a derivative
of the former. Is that what's happening?  Any other comments on what
that block of code does, or tries to do, are more than welcome.

// George


-- 
George Georgalis, systems architect, administrator Linux BSD IXOYE
http://galis.org/george/ cell:646-331-2027 mailto:george@xxxxxxxxx



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]