File: overlap.c

package info (click to toggle)
acorn-fdisk 3.0.6-13
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,068 kB
  • sloc: ansic: 5,422; makefile: 99
file content (39 lines) | stat: -rw-r--r-- 1,247 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * lib/scheme/overlap.c
 *
 * Copyright (C) 1998 Russell King
 */
#include <assert.h>
#include <stdlib.h>

#include "util/debug.h"
#include "part/utils.h"

static u_int test_overlap(const partinfo_t *p1, const partinfo_t *p2)
{
  dbg_printf("checking [0x%X-0x%X] with [0x%X-0x%X]",
             p2->blk_start, p2->blk_end,
             p1->blk_start, p1->blk_end);
  return !(p2->blk_end < p1->blk_start || p2->blk_start > p1->blk_end);
}

/* Function: u_int check_overlap(part_t *part, u_int exclude_parn, partinfo_t *pinfo)
 * Purpose : check that the new partition information `pinfo' for `exclude_parn' entry
 *           does not overlap physically on the disk with the existing partitions.
 * Params  : part         - partitionable device
 *         : exclude_parn - partition entry to exclude from check
 *         : pinfo        - new partition information to check against
 * Returns : TRUE if new information overlaps existing
 */
u_int check_overlap(part_t *part, u_int exclude_parn, const partinfo_t *pinfo)
{
  u_int i, ret = 0;

  for (i = 1; i < part->nr_partitions; i++)
    if (i != exclude_parn && part->partinfo[i] &&
        test_overlap(&part->partinfo[i]->info, pinfo)) {
      ret = 1;
      break;
    }
  return ret;
}