/* * Mausezahn - A fast versatile traffic generator * Copyright (C) 2010 Herbert Haas * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 2 as published by the * Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html * */ #include "mz.h" #include "cli.h" #include "mops.h" #include "llist.h" /* PURPOSE: * General doubly linked list with management functions. * * NOTE: * There is no dummy head element. Every element may contain data! * Therefore there is only one general "create_new_element" function. * * You cannot delete the head element except you want to delete the whole list. * Usually you delete the head element at last. * * head->refcount always contains the number of elements. * * Each element has a unique index number. * * The user must assign her/his data to (void*) elem->data. * */ // Create new list element - may be the first one (list==NULL) // struct mz_ll * mz_ll_create_new_element(struct mz_ll *list) { struct mz_ll *new_element; new_element = (struct mz_ll*) malloc (sizeof(struct mz_ll)); if (new_element==NULL) return NULL; _mz_ll_set_default(new_element); if (list==NULL) { new_element->next=new_element; new_element->prev=new_element; new_element->head=new_element; new_element->refcount=1; new_element->index=0; new_element->index_last=0; } else { new_element->prev=list->prev; new_element->next=list; new_element->prev->next=new_element; list->prev = new_element; new_element->head=list; list->refcount++; list->index_last++; new_element->index=list->index_last; } return new_element; } // Delete ONE list element. int mz_ll_delete_element (struct mz_ll *cur) { if ((cur==NULL)||(cur==cur->head)) return -1; // don't delete head! if (cur->data!=NULL) { free(cur->data); cur->data=NULL; } if ((cur->next!=cur)&&(cur->prev!=cur)) { cur->prev->next=cur->next; cur->next->prev=cur->prev; } cur->head->refcount--; if (cur!=NULL) { free(cur); cur=NULL; } return 0; } int mz_ll_delete_list (struct mz_ll *list) { struct mz_ll *cur=list, *tmp; if (cur==NULL) return 1; while (cur!=cur->next) { tmp=cur->next; mz_ll_delete_element(cur); cur=tmp; } // Finally free list head: if (list->data!=NULL) { free(list->data); list->data=NULL; } free(list); list=NULL; return 0; } struct mz_ll * mz_ll_search_name (struct mz_ll *list, char *str) { struct mz_ll *cur=list; do { if (strncmp(cur->name, str, MZ_LL_NAME_LEN)==0) return cur; cur=cur->next; } while (cur!=list); return NULL; } struct mz_ll * mz_ll_search_index (struct mz_ll *list, int i) { struct mz_ll *cur=list; do { if (cur->index==i) return cur; cur=cur->next; } while (cur!=list); return NULL; } int mz_ll_size(struct mz_ll *list) { int i=0; struct mz_ll *cur=list; if (list==NULL) return 0; do { i++; cur=cur->next; } while (cur!=list); if (i!=list->refcount) fprintf(stderr, "MZ_LL_SIZE: Anomalous situation. Report this.\n"); return i; } int mz_ll_dump_all(struct mz_ll *list) { int i=0; struct mz_ll *cur=list; if (list==NULL) return 0; do { i++; fprintf(stdout, "Element %i: '%s', index=%i\n",i,cur->name, cur->index); cur=cur->next; } while (cur!=list); return i; } // ------ PRIVATE: initialize list-element void _mz_ll_set_default (struct mz_ll *cur) { cur->refcount = 0; cur->data = NULL; cur->name[0]='\0'; cur->index=0; cur->state=0; } on value='0' selected='selected'>unified
authorPascal Eberhard <pascal.eberhard@gmail.com>2016-09-21 23:57:30 +0200
committerRichard Weinberger <richard@nod.at>2016-10-02 22:55:02 +0200
commit74e9c700bcb7529a0ab3f57d1125f4494ec97b3c (patch)
tree16320c195fbaa8b970962cfccbf287da94530a80
parent1e039533886765f50b4e58e7c337c84523ebf7b2 (diff)
ubifs: fix host xattr_len when changing xattr
When an extended attribute is changed, xattr_len of host inode is recalculated. ui->data_len is updated before computation and result is wrong. This patch adds a temporary variable to fix computation. To reproduce the issue: ~# > a.txt ~# attr -s an-attr -V a-value a.txt ~# attr -s an-attr -V a-bit-bigger-value a.txt Now host inode xattr_len is wrong. Forcing dbg_check_filesystem() generates the following error: [ 130.620140] UBIFS (ubi0:2): background thread "ubifs_bgt0_2" started, PID 565 [ 131.470790] UBIFS error (ubi0:2 pid 564): check_inodes: inode 646 has xattr size 240, but calculated size is 256 [ 131.481697] UBIFS (ubi0:2): dump of the inode 646 sitting in LEB 29:114688 [ 131.488953] magic 0x6101831 [ 131.492876] crc 0x9fce9091 [ 131.496836] node_type 0 (inode node) [ 131.501193] group_type 1 (in node group) [ 131.505788] sqnum 9278 [ 131.509191] len 160 [ 131.512549] key (646, inode) [ 131.516688] creat_sqnum 9270 [ 131.520133] size 0 [ 131.523264] nlink 1 [ 131.526398] atime 1053025857.0 [ 131.530574] mtime 1053025857.0 [ 131.534714] ctime 1053025906.0 [ 131.538849] uid 0 [ 131.542009] gid 0 [ 131.545140] mode 33188 [ 131.548636] flags 0x1 [ 131.551977] xattr_cnt 1 [ 131.555108] xattr_size 240 [ 131.558420] xattr_names 12 [ 131.561670] compr_type 0x1 [ 131.564983] data len 0 [ 131.568125] UBIFS error (ubi0:2 pid 564): dbg_check_filesystem: file-system check failed with error -22 [ 131.578074] CPU: 0 PID: 564 Comm: mount Not tainted 4.4.12-g3639bea54a #24 [ 131.585352] Hardware name: Generic AM33XX (Flattened Device Tree) [ 131.591918] [<c00151c0>] (unwind_backtrace) from [<c0012acc>] (show_stack+0x10/0x14) [ 131.600177] [<c0012acc>] (show_stack) from [<c01c950c>] (dbg_check_filesystem+0x464/0x4d0) [ 131.608934] [<c01c950c>] (dbg_check_filesystem) from [<c019f36c>] (ubifs_mount+0x14f8/0x2130) [ 131.617991] [<c019f36c>] (ubifs_mount) from [<c00d7088>] (mount_fs+0x14/0x98) [ 131.625572] [<c00d7088>] (mount_fs) from [<c00ed674>] (vfs_kern_mount+0x4c/0xd4) [ 131.633435] [<c00ed674>] (vfs_kern_mount) from [<c00efb5c>] (do_mount+0x988/0xb50) [ 131.641471] [<c00efb5c>] (do_mount) from [<c00f004c>] (SyS_mount+0x74/0xa0) [ 131.648837] [<c00f004c>] (SyS_mount) from [<c000fe20>] (ret_fast_syscall+0x0/0x3c) [ 131.665315] UBIFS (ubi0:2): background thread "ubifs_bgt0_2" stops Signed-off-by: Pascal Eberhard <pascal.eberhard@gmail.com> Signed-off-by: Richard Weinberger <richard@nod.at>
Diffstat