hammer2_subr.c (731b2a84) | hammer2_subr.c (1a7cfe5a) |
---|---|
1/* 2 * Copyright (c) 2011-2013 The DragonFly Project. All rights reserved. 3 * 4 * This code is derived from software contributed to The DragonFly Project 5 * by Matthew Dillon <dillon@dragonflybsd.org> 6 * by Venkatesh Srinivas <vsrinivas@dragonflybsd.org> 7 * 8 * Redistribution and use in source and binary forms, with or without --- 270 unchanged lines hidden (view full) --- 279 * that the values 0x0000-0x7FFF are available for artificial entries. 280 * ('.' and '..'). 281 */ 282 key |= 0x8000U; 283 284 return (key); 285} 286 | 1/* 2 * Copyright (c) 2011-2013 The DragonFly Project. All rights reserved. 3 * 4 * This code is derived from software contributed to The DragonFly Project 5 * by Matthew Dillon <dillon@dragonflybsd.org> 6 * by Venkatesh Srinivas <vsrinivas@dragonflybsd.org> 7 * 8 * Redistribution and use in source and binary forms, with or without --- 270 unchanged lines hidden (view full) --- 279 * that the values 0x0000-0x7FFF are available for artificial entries. 280 * ('.' and '..'). 281 */ 282 key |= 0x8000U; 283 284 return (key); 285} 286 |
287#if 0 |
|
287/* 288 * Return the power-of-2 radix greater or equal to 289 * the specified number of bytes. 290 * 291 * Always returns at least the minimum media allocation 292 * size radix, HAMMER2_MIN_RADIX (10), which is 1KB. 293 */ 294int --- 12 unchanged lines hidden (view full) --- 307 else 308 radix = HAMMER2_MIN_RADIX; 309 310 while (((size_t)1 << radix) < bytes) 311 ++radix; 312 return (radix); 313} 314 | 288/* 289 * Return the power-of-2 radix greater or equal to 290 * the specified number of bytes. 291 * 292 * Always returns at least the minimum media allocation 293 * size radix, HAMMER2_MIN_RADIX (10), which is 1KB. 294 */ 295int --- 12 unchanged lines hidden (view full) --- 308 else 309 radix = HAMMER2_MIN_RADIX; 310 311 while (((size_t)1 << radix) < bytes) 312 ++radix; 313 return (radix); 314} 315 |
316#endif 317 |
|
315/* | 318/* |
319 * Convert bytes to radix with no limitations 320 */ 321int 322hammer2_getradix(size_t bytes) 323{ 324 int radix; 325 326 if (bytes == HAMMER2_PBUFSIZE) 327 radix = HAMMER2_PBUFRADIX; 328 else if (bytes >= 16384) 329 radix = 14; 330 else if (bytes >= 1024) 331 radix = 10; 332 else 333 radix = 0; 334 335 while (((size_t)1 << radix) < bytes) 336 ++radix; 337 return (radix); 338} 339 340/* |
|
316 * ip must be locked sh/ex 317 */ 318int 319hammer2_calc_logical(hammer2_inode_t *ip, hammer2_off_t uoff, 320 hammer2_key_t *lbasep, hammer2_key_t *leofp) 321{ 322 hammer2_inode_data_t *ipdata = &ip->chain->data->ipdata; 323 int radix; 324 325 *lbasep = uoff & ~HAMMER2_PBUFMASK64; 326 *leofp = ipdata->size & ~HAMMER2_PBUFMASK64; 327 KKASSERT(*lbasep <= *leofp); 328 if (*lbasep == *leofp /*&& *leofp < 1024 * 1024*/) { | 341 * ip must be locked sh/ex 342 */ 343int 344hammer2_calc_logical(hammer2_inode_t *ip, hammer2_off_t uoff, 345 hammer2_key_t *lbasep, hammer2_key_t *leofp) 346{ 347 hammer2_inode_data_t *ipdata = &ip->chain->data->ipdata; 348 int radix; 349 350 *lbasep = uoff & ~HAMMER2_PBUFMASK64; 351 *leofp = ipdata->size & ~HAMMER2_PBUFMASK64; 352 KKASSERT(*lbasep <= *leofp); 353 if (*lbasep == *leofp /*&& *leofp < 1024 * 1024*/) { |
329 radix = hammer2_allocsize((size_t)(ipdata->size - *leofp)); 330 if (radix < HAMMER2_MINALLOCRADIX) 331 radix = HAMMER2_MINALLOCRADIX; | 354 radix = hammer2_getradix((size_t)(ipdata->size - *leofp)); 355 if (radix < HAMMER2_MIN_RADIX) 356 radix = HAMMER2_MIN_RADIX; |
332 *leofp += 1U << radix; 333 return (1U << radix); 334 } else { 335 return (HAMMER2_PBUFSIZE); 336 } 337} 338 339void 340hammer2_update_time(uint64_t *timep) 341{ 342 struct timeval tv; 343 344 getmicrotime(&tv); 345 *timep = (unsigned long)tv.tv_sec * 1000000 + tv.tv_usec; 346} | 357 *leofp += 1U << radix; 358 return (1U << radix); 359 } else { 360 return (HAMMER2_PBUFSIZE); 361 } 362} 363 364void 365hammer2_update_time(uint64_t *timep) 366{ 367 struct timeval tv; 368 369 getmicrotime(&tv); 370 *timep = (unsigned long)tv.tv_sec * 1000000 + tv.tv_usec; 371} |