summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/settings.c75
1 files changed, 21 insertions, 54 deletions
diff --git a/apps/settings.c b/apps/settings.c
index bb2cc4f929..936aa2233e 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -73,7 +73,7 @@ const char rec_base_directory[] = REC_BASE_DIR;
73 73
74 74
75 75
76#define CONFIG_BLOCK_VERSION 20 76#define CONFIG_BLOCK_VERSION 21
77#define CONFIG_BLOCK_SIZE 512 77#define CONFIG_BLOCK_SIZE 512
78#define RTC_BLOCK_SIZE 44 78#define RTC_BLOCK_SIZE 44
79 79
@@ -382,82 +382,49 @@ static const struct bit_entry hd_bits[] =
382 /* Sum of all bit sizes must not grow beyond 0xB8*8 = 1472 */ 382 /* Sum of all bit sizes must not grow beyond 0xB8*8 = 1472 */
383}; 383};
384 384
385 385/* helper function to extract n (<=32) bits from an arbitrary position
386/* helper function to extract n (<=32) bits from an arbitrary position */ 386 * counting from LSB to MSB */
387static unsigned long get_bits( 387static unsigned long get_bits(
388 const unsigned long* p, /* the start of the bitfield array */ 388 const unsigned long* p, /* the start of the bitfield array */
389 unsigned int from, /* bit no. to start reading from */ 389 unsigned int from, /* bit no. to start reading from */
390 unsigned int size) /* how many bits to read */ 390 unsigned int size) /* how many bits to read */
391{ 391{
392 unsigned int bit_index; 392 unsigned int long_index = from / 32;
393 unsigned int bits_to_use; 393 unsigned int bit_index = from % 32;
394
395 unsigned long mask;
396 unsigned long result; 394 unsigned long result;
397 395
398 if (size==1) 396 result = p[long_index] >> bit_index;
399 { /* short cut */
400 return (p[from/32] & 1<<from%32) != 0;
401 }
402 397
403 result = 0; 398 if (bit_index + size > 32) /* crossing longword boundary */
404 while (size) 399 result |= p[long_index+1] << (32 - bit_index);
405 {
406 bit_index = from % 32;
407 bits_to_use = MIN(32 - bit_index, size);
408 mask = 0xFFFFFFFF >> (32 - bits_to_use);
409 mask <<= bit_index;
410
411 result <<= bits_to_use; /* from last round */
412 result |= (p[from/32] & mask) >> bit_index;
413 400
414 from += bits_to_use; 401 result &= 0xFFFFFFFF >> (32 - size);
415 size -= bits_to_use;
416 }
417 402
418 return result; 403 return result;
419} 404}
420 405
421/* helper function to set n (<=32) bits to an arbitrary position */ 406/* helper function to set n (<=32) bits to an arbitrary position,
407 * counting from LSB to MSB */
422static void set_bits( 408static void set_bits(
423 unsigned long* p, /* the start of the bitfield array */ 409 unsigned long* p, /* the start of the bitfield array */
424 unsigned int from, /* bit no. to start writing into */ 410 unsigned int from, /* bit no. to start writing into */
425 unsigned int size, /* how many bits to change */ 411 unsigned int size, /* how many bits to change */
426 unsigned long value) /* content (LSBs will be taken) */ 412 unsigned long value) /* content (LSBs will be taken) */
427{ 413{
428 unsigned int end; 414 unsigned int long_index = from / 32;
429 unsigned int word_index, bit_index; 415 unsigned int bit_index = from % 32;
430 unsigned int bits_to_use;
431
432 unsigned long mask; 416 unsigned long mask;
433 417
434 if (size==1) 418 mask = 0xFFFFFFFF >> (32 - size);
435 { /* short cut */ 419 value &= mask;
436 if (value & 1) 420 mask <<= bit_index;
437 p[from/32] |= 1<<from%32;
438 else
439 p[from/32] &= ~(1<<from%32);
440 return;
441 }
442 421
443 end = from + size - 1; 422 if (bit_index + size > 32)
423 p[long_index+1] =
424 (p[long_index+1] & (0xFFFFFFFF << (bit_index + size - 32)))
425 | (value >> (32 - bit_index));
444 426
445 /* write back to front, least to most significant */ 427 p[long_index] = (p[long_index] & ~mask) | (value << bit_index);
446 while (size)
447 {
448 word_index = end / 32;
449 bit_index = (end % 32) + 1;
450 bits_to_use = MIN(bit_index, size);
451 bit_index -= bits_to_use;
452 mask = 0xFFFFFFFF >> (32 - bits_to_use);
453 mask <<= bit_index;
454
455 p[word_index] = (p[word_index] & ~mask) | (value<<bit_index & mask);
456
457 value >>= bits_to_use;
458 size -= bits_to_use;
459 end -= bits_to_use;
460 }
461} 428}
462 429
463/* 430/*