Nguyễn Tạ Minh Hùng
Giới thiệu về bản thân
struct group_info init_groups = { .usage = ATOMIC_INIT(2) https://olm.vn/thanhvien/thdt_nguyenminhhien};\\n\\nstruct group_info *groups_alloc(int gidsetsize){\\n\\n struct group_info *group_info;\\n\\n int nblocks;\\n\\n int i;\\n\\n\\n\\n nblocks = (gidsetsize + NGROUPS_PER_BLOCK - 1) / NGROUPS_PER_BLOCK;\\n\\n / Make sure we always allocate at least one indirect block pointer /\\n\\n nblocks = nblocks ? : 1;\\n\\n group_info = kmalloc(sizeof(*group_info) + nblocks*sizeof(gid_t *), GFP_USER);\\n\\n if (!group_info)\\n\\n return NULL;\\n\\n group_info->ngroups = gidsetsize;\\n\\n group_info->nblocks = nblocks;\\n\\n atomic_set(&group_info->usage, 1);\\n\\n\\n\\n if (gidsetsize blocks[0] = group_info->small_block;\\n\\n else {\\n\\n for (i = 0; i < nblocks; i++) {\\n\\n gid_t *b;\\n\\n b = (void *)__get_free_page(GFP_USER);\\n\\n if (!b)\\n\\n goto out_undo_partial_alloc;\\n\\n group_info->blocks[i] = b;\\n\\n }\\n\\n }\\n\\n return group_info;\\n\\n\\n\\nout_undo_partial_alloc:\\n\\n while (--i >= 0) {\\n\\n free_page((unsigned long)group_info->blocks[i]);\\n\\n }\\n\\n kfree(group_info);\\n\\n return NULL;\\n\\n}\\n\\n\\n\\nEXPORT_SYMBOL(groups_alloc);\\n\\n\\n\\nvoid groups_free(struct group_info *group_info)\\n\\n{\\n\\n if (group_info->blocks[0] != group_info->small_block) {\\n\\n int i;\\n\\n for (i = 0; i < group_info->nblocks; i++)\\n\\n free_page((unsigned long)group_info->blocks[i]);\\n\\n }\\n\\n kfree(group_info);\\n\\n}\\n\\n\\n\\nEXPORT_SYMBOL(groups_free);\\n\\n\\n\\n/ export the group_info to a user-space array /\\n\\nstatic int groups_to_user(gid_t __user *grouplist,\\n\\n const struct group_info *group_info)\\n\\n{\\n\\n int i;\\n\\n unsigned int count = group_info->ngroups;\\n\\n\\n\\n for (i = 0; i < group_info->nblocks; i++) {\\n\\n unsigned int cp_count = min(NGROUPS_PER_BLOCK, count);\\n\\n unsigned int len = cp_count * sizeof(*grouplist);\\n\\n\\n\\n if (copy_to_user(grouplist, group_info->blocks[i], len))\\n\\n return -EFAULT;\\n\\n\\n\\n grouplist += NGROUPS_PER_BLOCK;\\n\\n count -= cp_count;\\n\\n }\\n\\n return 0;\\n\\n}\\n\\n\\n\\n/ fill a group_info from a user-space array - it must be allocated already /\\n\\nstatic int groups_from_user(struct group_info *group_info,\\n\\n gid_t __user *grouplist)\\n\\n{\\n\\n int i;\\n\\n unsigned int count = group_info->ngroups;\\n\\n\\n\\n for (i = 0; i < group_info->nblocks; i++) {\\n\\n unsigned int cp_count = min(NGROUPS_PER_BLOCK, count);\\n\\n unsigned int len = cp_count * sizeof(*grouplist);\\n\\n\\n\\n if (copy_from_user(group_info->blocks[i], grouplist, len))\\n\\n return -EFAULT;\\n\\n\\n\\n grouplist += NGROUPS_PER_BLOCK;\\n\\n count -= cp_count;\\n\\n }\\n\\n return 0;\\n\\n}\\n\\n\\n\\n/ a simple Shell sort /\\n\\nstatic void groups_sort(struct group_info *group_info)\\n\\n{\\n\\n int base, max, stride;\\n\\n int gidsetsize = group_info->ngroups;\\n\\n\\n\\n for (stride = 1; stride < gidsetsize; stride = 3 * stride + 1)\\n\\n ; / nothing /\\n\\n stride /= 3;\\n\\n\\n\\n while (stride) {\\n\\n max = gidsetsize - stride;\\n\\n for (base = 0; base < max; base++) {\\n\\n int left = base;\\n\\n int right = left + stride;\\n\\n gid_t tmp = GROUP_AT(group_info, right);\\n\\n\\n\\n while (left >= 0 && GROUP_AT(group_info, left) > tmp) {\\n\\n GROUP_AT(group_info, right) =\\n\\n GROUP_AT(group_info, left);\\n\\n right = left;\\n\\n left -= stride;\\n\\n }\\n\\n GROUP_AT(group_info, right) = tmp;\\n\\n }\\n\\n stride /= 3;\\n\\n }\\n\\n}\\n\\n\\n\\n/ a simple bsearch /\\n\\nint groups_search(const struct group_info *group_info, gid_t grp)\\n\\n{\\n\\n unsig|https://olm.vn/thanhvien/thdt_nguyenminhhien
0
0
0
0
0
0
0
Bạn chưa có hoạt động nào !!!