| 1 | /* |
| 2 | * blank.c |
| 3 | * Detection of Blank Disk (Formatted) |
| 4 | * |
| 5 | * Written By Aaron Geyer of StorageQuest, Inc. |
| 6 | * |
| 7 | * Copyright (c) 2003 Aaron Geyer |
| 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person |
| 10 | * obtaining a copy of this software and associated documentation |
| 11 | * files (the "Software"), to deal in the Software without |
| 12 | * restriction, including without limitation the rights to use, copy, |
| 13 | * modify, merge, publish, distribute, sublicense, and/or sell copies |
| 14 | * of the Software, and to permit persons to whom the Software is |
| 15 | * furnished to do so, subject to the following conditions: |
| 16 | * |
| 17 | * The above copyright notice and this permission notice shall be |
| 18 | * included in all copies or substantial portions of the Software. |
| 19 | * |
| 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 24 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 25 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 26 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 27 | * SOFTWARE. |
| 28 | * |
| 29 | */ |
| 30 | |
| 31 | #include "global.h" |
| 32 | |
| 33 | /* The principle used to determine whether or not a disk |
| 34 | is blank is to search the disk for a byte code that |
| 35 | does not change over the disk. This module only scans the first |
| 36 | 2MB of the disk. This module will need more work. */ |
| 37 | |
| 38 | #define BLOCK_SIZE (512) |
| 39 | #define MAX_BLOCKS (2048*2) |
| 40 | #define MIN_BLOCKS (64*2) |
| 41 | |
| 42 | |
| 43 | void detect_blank(SECTION *section, int level) |
| 44 | { |
| 45 | unsigned char *buffer; |
| 46 | int i, j; |
| 47 | int block_size = BLOCK_SIZE; |
| 48 | int max_blocks = MAX_BLOCKS; |
| 49 | int blank_blocks = 0; |
| 50 | unsigned char code; |
| 51 | char s[256]; |
| 52 | |
| 53 | if (get_buffer(section, 0, 1, (void **)&buffer) < 1) |
| 54 | return; |
| 55 | code = buffer[0]; |
| 56 | |
| 57 | /* Limit to actual size of partition / disk */ |
| 58 | if (section->size && section->size < max_blocks * block_size) { |
| 59 | max_blocks = section->size / block_size; |
| 60 | } |
| 61 | |
| 62 | /* Determine number of blank blocks */ |
| 63 | for (i = 0; i < max_blocks; i++) { |
| 64 | if (get_buffer(section, i * block_size, block_size, (void **)&buffer) < block_size) |
| 65 | break; |
| 66 | |
| 67 | for (j = 0; j < block_size; j++) { |
| 68 | if (buffer[j] != code) |
| 69 | break; |
| 70 | } |
| 71 | if (j < block_size) |
| 72 | break; |
| 73 | |
| 74 | blank_blocks = i + 1; |
| 75 | } |
| 76 | |
| 77 | if (blank_blocks >= max_blocks) { |
| 78 | print_line(level, "Blank disk/medium"); |
| 79 | } else if (blank_blocks > MIN_BLOCKS) { |
| 80 | format_size(s, blank_blocks * block_size); |
| 81 | print_line(level, "First %s are blank", s); |
| 82 | } |
| 83 | } |