* as the offsets are usually PAGE_SIZE aligned due to pin-Bcb expectations.
*/
guint64 FileSize; /* ==CC_FILE_SIZES.FileSize.QuadPart */
- /* We use 'FileSize' instead of 'ValidDataLength' as I assume W32
+ /* We use do not use 'ValidDataLength' as I assume W32
* automatically increases 'ValidDataLength' during Cache Manager write operations.
* We do not increase it and therefore it is mostly useless for us.
*/
guint64 ValidDataLength; /* ==CC_FILE_SIZES.ValidDataLength.QuadPart */
+ /* The real allocation size of 'buffer' and 'pages'.
+ * Maintained by captive_shared_cache_map_object_FileSizes_changed()
+ * to prevent continous reallocation to (n+1) size.
+ * We use (n*2) sizes for logaritmic time complexity.
+ */
+ guint64 alloc_length;
CACHE_MANAGER_CALLBACKS CallBacks;
VOID *LazyWriterContext;
gboolean PinAccess;
}
if (size_old!=size_new) {
-gpointer buffer_new;
-
/* ntfs.sys of NT-5.1sp1 may extend StreamFileObject while dirty pins exist.
* How to extend SharedCacheMap size without changing the memory location?
* I hope ntfs.sys does not expect long-term absolute position of its
g_assert(!captive_shared_cache_map_object->map);
g_assert(!g_hash_table_size(captive_shared_cache_map_object->pin_hash));
}
+ }
+
+ if (size_new > captive_shared_cache_map_object->alloc_length) {
+gpointer buffer_new;
+
+ size_new*=2;
+ size64_new*=2;
+ if (size_new!=size64_new)
+ goto size_new_big;
- if (AllocationSize) {
+ if (size_new) {
gpointer base;
int errint;
memcpy(buffer_new,captive_shared_cache_map_object->buffer,
MIN(AllocationSize,captive_shared_cache_map_object->AllocationSize));
- if (captive_shared_cache_map_object->AllocationSize) {
+ if (captive_shared_cache_map_object->alloc_length) {
int errint;
- errint=munmap(captive_shared_cache_map_object->buffer,size_old);
+ errint=munmap(captive_shared_cache_map_object->buffer,captive_shared_cache_map_object->alloc_length);
g_assert(errint==0);
}
}
}
#endif
+
captive_shared_cache_map_object->pages=g_realloc(captive_shared_cache_map_object->pages,
size_new/PAGE_SIZE*sizeof(*captive_shared_cache_map_object->pages));
if (size_new>size_old) /* prevent 'size_new-size_old' as it is unsigned! */
memset(captive_shared_cache_map_object->pages+(size_old/PAGE_SIZE),0,
(size_new-size_old)/PAGE_SIZE*sizeof(*captive_shared_cache_map_object->pages));
+
+ captive_shared_cache_map_object->alloc_length=size_new;
}
captive_shared_cache_map_object->AllocationSize=AllocationSize;