/* * Handle all mappings that got truncated by a "truncate()" * system call. * * NOTE! We have to be ready to update the memory sharing * between the file and the memory map for a potential last * incomplete page. Ugly, but necessary. */ void vmtruncate(struct inode * inode, unsigned long offset) { struct vm_area_struct * mpnt; truncate_inode_pages(inode, offset); if (!inode->i_mmap) return; mpnt = inode->i_mmap; do { unsigned long start = mpnt->vm_start; unsigned long len = mpnt->vm_end - start; unsigned long diff; /* mapping wholly truncated? */ if (mpnt->vm_offset >= offset) { zap_page_range(mpnt->vm_mm, start, len); continue; } /* mapping wholly unaffected? */ diff = offset - mpnt->vm_offset; if (diff >= len) continue; /* Ok, partially affected.. */ start += diff; len = (len - diff) & PAGE_MASK; if (start & ~PAGE_MASK) { partial_clear(mpnt, start); start = (start + ~PAGE_MASK) & PAGE_MASK; } zap_page_range(mpnt->vm_mm, start, len); } while ((mpnt = mpnt->vm_next_share) != inode->i_mmap); }
void TreeBase::clear() { if (!root_) return; partial_clear(root_); root_ = NULL; src_head_ = NULL; src_tail_ = NULL; }
void TreeBase::partial_clear(node_branch* parent) { auto it = parent->childs.begin(); auto end = parent->childs.end(); if (parent->bLeaf) for (; it != end; it++) delete (node_leaf*)*it; else for (; it != end; it++) partial_clear((node_branch*)*it); delete parent; }
void unShrink(void) { int stackp; int finchar; int code; int oldcode; int incode; /* decompress the file */ maxcodemax = 1 << max_bits; cbits = init_bits; maxcode = (1 << cbits) - 1; free_ent = first_ent; offset = 0; sizex = 0; for (code = maxcodemax; code > 255; code--) prefix_of[code] = -1; for (code = 255; code >= 0; code--) { prefix_of[code] = 0; suffix_of[code] = code; } ReadBits(cbits,&oldcode); if (zipeof) return; finchar = oldcode; OutByte(finchar); stackp = 0; while ((!zipeof)) { ReadBits(cbits,&code); if (zipeof) return; while (code == clear) { ReadBits(cbits,&code); switch (code) { case 1: { cbits++; if (cbits == max_bits) maxcode = maxcodemax; else maxcode = (1 << cbits) - 1; } break; case 2: partial_clear(); break; } ReadBits(cbits,&code); if (zipeof) return; } /* special case for KwKwK string */ incode = code; if (prefix_of[code] == -1) { stack[stackp] = finchar; stackp++; code = oldcode; } /* generate output characters in reverse order */ while (code >= first_ent) { stack[stackp] = suffix_of[code]; stackp++; code = prefix_of[code]; } finchar = suffix_of[code]; stack[stackp] = finchar; stackp++; /* and put them out in forward order */ while (stackp > 0) { stackp--; OutByte(stack[stackp]); } /* generate new entry */ code = free_ent; if (code < maxcodemax) { prefix_of[code] = oldcode; suffix_of[code] = finchar; while ((free_ent < maxcodemax) && (prefix_of[free_ent] != -1)) free_ent++; } /* remember previous code */ oldcode = incode; } }