void init_swapping(void)有问题

来源:互联网 发布:魔兽大脚插件for mac 编辑:程序博客网 时间:2024/05/16 11:46


void init_swapping(void)
{
 extern int *blk_size[];
 int swap_size,i,j;

 if (!SWAP_DEV)
  return;
 if (!blk_size[MAJOR(SWAP_DEV)]) {
  printk("Unable to get size of swap device\n\r");
  return;
 }
 swap_size = blk_size[MAJOR(SWAP_DEV)][MINOR(SWAP_DEV)];
 if (!swap_size)
  return;
 if (swap_size < 100) {
  printk("Swap device too small (%d blocks)\n\r",swap_size);
  return;
 }
 swap_size >>= 2;
 if (swap_size > SWAP_BITS)
  swap_size = SWAP_BITS;
 swap_bitmap = (char *) get_free_page();
 if (!swap_bitmap) {
  printk("Unable to start swapping: out of memory :-)\n\r");
  return;
 }
 read_swap_page(0,swap_bitmap);
 if (strncmp("SWAP-SPACE",swap_bitmap+4086,10)) {
  printk("Unable to find swap-space signature\n\r");
  free_page((long) swap_bitmap);
  swap_bitmap = NULL;
  return;
 }
 memset(swap_bitmap+4086,0,10);
 for (i = 0 ; i < SWAP_BITS ; i++) {
  if (i == 1)
   i = swap_size;
  if (bit(swap_bitmap,i)) {
   printk("Bad swap-space bit-map\n\r");
   free_page((long) swap_bitmap);
   swap_bitmap = NULL;
   return;
  }
 }
 j = 0;
 for (i = 1 ; i < swap_size ; i++)
  if (bit(swap_bitmap,i))
   j++;
 if (!j) {
  free_page((long) swap_bitmap);
  swap_bitmap = NULL;
  return;
 }
 printk("Swap device ok: %d pages (%d bytes) swap-space\n\r",j,j*4096);

这段代码应该是有问题的应该if(j){...............}才对

原创粉丝点击