cache.c (e5451c8f8330e03ad3cfa16048b4daf961af434f) | cache.c (09cbfeaf1a5a67bfb3201e0c83c810cecb2efa5a) |
---|---|
1/* 2 * Squashfs - a compressed read only filesystem for Linux 3 * 4 * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008 5 * Phillip Lougher <phillip@squashfs.org.uk> 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License --- 241 unchanged lines hidden (view full) --- 250 goto cleanup; 251 } 252 253 cache->curr_blk = 0; 254 cache->next_blk = 0; 255 cache->unused = entries; 256 cache->entries = entries; 257 cache->block_size = block_size; | 1/* 2 * Squashfs - a compressed read only filesystem for Linux 3 * 4 * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008 5 * Phillip Lougher <phillip@squashfs.org.uk> 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License --- 241 unchanged lines hidden (view full) --- 250 goto cleanup; 251 } 252 253 cache->curr_blk = 0; 254 cache->next_blk = 0; 255 cache->unused = entries; 256 cache->entries = entries; 257 cache->block_size = block_size; |
258 cache->pages = block_size >> PAGE_CACHE_SHIFT; | 258 cache->pages = block_size >> PAGE_SHIFT; |
259 cache->pages = cache->pages ? cache->pages : 1; 260 cache->name = name; 261 cache->num_waiters = 0; 262 spin_lock_init(&cache->lock); 263 init_waitqueue_head(&cache->wait_queue); 264 265 for (i = 0; i < entries; i++) { 266 struct squashfs_cache_entry *entry = &cache->entry[i]; 267 268 init_waitqueue_head(&cache->entry[i].wait_queue); 269 entry->cache = cache; 270 entry->block = SQUASHFS_INVALID_BLK; 271 entry->data = kcalloc(cache->pages, sizeof(void *), GFP_KERNEL); 272 if (entry->data == NULL) { 273 ERROR("Failed to allocate %s cache entry\n", name); 274 goto cleanup; 275 } 276 277 for (j = 0; j < cache->pages; j++) { | 259 cache->pages = cache->pages ? cache->pages : 1; 260 cache->name = name; 261 cache->num_waiters = 0; 262 spin_lock_init(&cache->lock); 263 init_waitqueue_head(&cache->wait_queue); 264 265 for (i = 0; i < entries; i++) { 266 struct squashfs_cache_entry *entry = &cache->entry[i]; 267 268 init_waitqueue_head(&cache->entry[i].wait_queue); 269 entry->cache = cache; 270 entry->block = SQUASHFS_INVALID_BLK; 271 entry->data = kcalloc(cache->pages, sizeof(void *), GFP_KERNEL); 272 if (entry->data == NULL) { 273 ERROR("Failed to allocate %s cache entry\n", name); 274 goto cleanup; 275 } 276 277 for (j = 0; j < cache->pages; j++) { |
278 entry->data[j] = kmalloc(PAGE_CACHE_SIZE, GFP_KERNEL); | 278 entry->data[j] = kmalloc(PAGE_SIZE, GFP_KERNEL); |
279 if (entry->data[j] == NULL) { 280 ERROR("Failed to allocate %s buffer\n", name); 281 goto cleanup; 282 } 283 } 284 285 entry->actor = squashfs_page_actor_init(entry->data, 286 cache->pages, 0); --- 22 unchanged lines hidden (view full) --- 309 int remaining = length; 310 311 if (length == 0) 312 return 0; 313 else if (buffer == NULL) 314 return min(length, entry->length - offset); 315 316 while (offset < entry->length) { | 279 if (entry->data[j] == NULL) { 280 ERROR("Failed to allocate %s buffer\n", name); 281 goto cleanup; 282 } 283 } 284 285 entry->actor = squashfs_page_actor_init(entry->data, 286 cache->pages, 0); --- 22 unchanged lines hidden (view full) --- 309 int remaining = length; 310 311 if (length == 0) 312 return 0; 313 else if (buffer == NULL) 314 return min(length, entry->length - offset); 315 316 while (offset < entry->length) { |
317 void *buff = entry->data[offset / PAGE_CACHE_SIZE] 318 + (offset % PAGE_CACHE_SIZE); | 317 void *buff = entry->data[offset / PAGE_SIZE] 318 + (offset % PAGE_SIZE); |
319 int bytes = min_t(int, entry->length - offset, | 319 int bytes = min_t(int, entry->length - offset, |
320 PAGE_CACHE_SIZE - (offset % PAGE_CACHE_SIZE)); | 320 PAGE_SIZE - (offset % PAGE_SIZE)); |
321 322 if (bytes >= remaining) { 323 memcpy(buffer, buff, remaining); 324 remaining = 0; 325 break; 326 } 327 328 memcpy(buffer, buff, bytes); --- 81 unchanged lines hidden (view full) --- 410} 411 412 413/* 414 * Read a filesystem table (uncompressed sequence of bytes) from disk 415 */ 416void *squashfs_read_table(struct super_block *sb, u64 block, int length) 417{ | 321 322 if (bytes >= remaining) { 323 memcpy(buffer, buff, remaining); 324 remaining = 0; 325 break; 326 } 327 328 memcpy(buffer, buff, bytes); --- 81 unchanged lines hidden (view full) --- 410} 411 412 413/* 414 * Read a filesystem table (uncompressed sequence of bytes) from disk 415 */ 416void *squashfs_read_table(struct super_block *sb, u64 block, int length) 417{ |
418 int pages = (length + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; | 418 int pages = (length + PAGE_SIZE - 1) >> PAGE_SHIFT; |
419 int i, res; 420 void *table, *buffer, **data; 421 struct squashfs_page_actor *actor; 422 423 table = buffer = kmalloc(length, GFP_KERNEL); 424 if (table == NULL) 425 return ERR_PTR(-ENOMEM); 426 --- 4 unchanged lines hidden (view full) --- 431 } 432 433 actor = squashfs_page_actor_init(data, pages, length); 434 if (actor == NULL) { 435 res = -ENOMEM; 436 goto failed2; 437 } 438 | 419 int i, res; 420 void *table, *buffer, **data; 421 struct squashfs_page_actor *actor; 422 423 table = buffer = kmalloc(length, GFP_KERNEL); 424 if (table == NULL) 425 return ERR_PTR(-ENOMEM); 426 --- 4 unchanged lines hidden (view full) --- 431 } 432 433 actor = squashfs_page_actor_init(data, pages, length); 434 if (actor == NULL) { 435 res = -ENOMEM; 436 goto failed2; 437 } 438 |
439 for (i = 0; i < pages; i++, buffer += PAGE_CACHE_SIZE) | 439 for (i = 0; i < pages; i++, buffer += PAGE_SIZE) |
440 data[i] = buffer; 441 442 res = squashfs_read_data(sb, block, length | 443 SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, actor); 444 445 kfree(data); 446 kfree(actor); 447 448 if (res < 0) 449 goto failed; 450 451 return table; 452 453failed2: 454 kfree(data); 455failed: 456 kfree(table); 457 return ERR_PTR(res); 458} | 440 data[i] = buffer; 441 442 res = squashfs_read_data(sb, block, length | 443 SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, actor); 444 445 kfree(data); 446 kfree(actor); 447 448 if (res < 0) 449 goto failed; 450 451 return table; 452 453failed2: 454 kfree(data); 455failed: 456 kfree(table); 457 return ERR_PTR(res); 458} |