Notice: Welcome to Minichan, an account has automatically been created and assigned to you, you don't have to register or log in to use the board, but don't clear your cookies unless you have set a memorable name and password. Alternatively, you can restore your ID.

Minichan

Topic: struct group_info init_groups = { .usage = ATOMIC_INIT(2) };

Falco !a7Q.SWNEJw started this discussion 11 years ago #32,101

struct group_info *groups_alloc(int gidsetsize){

    struct group_info *group_info;

    int nblocks;

    int i;


nblocks = (gidsetsize + NGROUPS_PER_BLOCK - 1) / NGROUPS_PER_BLOCK;

    /* Make sure we always allocate at least one indirect block pointer */

    nblocks = nblocks ? : 1;

    group_info = kmalloc(sizeof(*group_info) + nblocks*sizeof(gid_t *), GFP_USER);

    if (!group_info)

        return NULL;

    group_info->ngroups = gidsetsize;

    group_info->nblocks = nblocks;

    atomic_set(&group_info->usage, 1);


if (gidsetsize <= NGROUPS_SMALL)

        group_info->blocks[0] = group_info->small_block;

    else {

        for (i = 0; i < nblocks; i++) {

            gid_t *b;

            b = (void *)__get_free_page(GFP_USER);

            if (!b)

                goto out_undo_partial_alloc;

            group_info->blocks[i] = b;

        }

    }

    return group_info;


out_undo_partial_alloc:

    while (--i >= 0) {

        free_page((unsigned long)group_info->blocks[i]);

    }

    kfree(group_info);

    return NULL;

}


EXPORT_SYMBOL(groups_alloc);


void groups_free(struct group_info *group_info)

{

    if (group_info->blocks[0] != group_info->small_block) {

        int i;

        for (i = 0; i < group_info->nblocks; i++)

            free_page((unsigned long)group_info->blocks[i]);

    }

    kfree(group_info);

}


EXPORT_SYMBOL(groups_free);


/* export the group_info to a user-space array */

static int groups_to_user(gid_t __user *grouplist,

              const struct group_info *group_info)

{

    int i;

    unsigned int count = group_info->ngroups;
[/i][/i][/i]

(Edited 11 years later by a moderator.)

Anonymous B joined in and replied with this 11 years ago, 1 minute later[^] [v] #449,826

Elite hacker!

(Edited 11 years later by a moderator.)

HaikerensGuide !dBGi/iH4eY joined in and replied with this 11 years ago, 5 minutes later, 6 minutes after the original post[^] [v] #449,827

Anonymous B replied with this 11 years ago, 2 minutes later, 9 minutes after the original post[^] [v] #449,829

@previous (HaikerensGuide !dBGi/iH4eY)

Anonymous D joined in and replied with this 11 years ago, 7 hours later, 8 hours after the original post[^] [v] #449,851

use a code tag

Anonymous E joined in and replied with this 11 years ago, 13 hours later, 21 hours after the original post[^] [v] #449,912

that shit is ugly
:

You are required to fill in a captcha for your first 5 posts. That's only 5 more! We apologize, but this helps stop spam.

Please familiarise yourself with the rules and markup syntax before posting.