summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.org>2005-03-09 14:49:35 +0000
committerOlivier Blin <oblin@mandriva.org>2005-03-09 14:49:35 +0000
commit38a2c24e6e576edb089ae74e48529015260e4dd8 (patch)
treea86513865493ca80b1f4b8b8c3788fd2bd6ea655
parent4ab4217cad713d92578079af72594d8f1876bf0a (diff)
downloaddrakx-backup-do-not-use-38a2c24e6e576edb089ae74e48529015260e4dd8.tar
drakx-backup-do-not-use-38a2c24e6e576edb089ae74e48529015260e4dd8.tar.gz
drakx-backup-do-not-use-38a2c24e6e576edb089ae74e48529015260e4dd8.tar.bz2
drakx-backup-do-not-use-38a2c24e6e576edb089ae74e48529015260e4dd8.tar.xz
drakx-backup-do-not-use-38a2c24e6e576edb089ae74e48529015260e4dd8.zip
move partition stuff in partition.c and common disk stuff in tools.c
-rw-r--r--mdk-stage1/Makefile2
-rw-r--r--mdk-stage1/disk.c167
-rw-r--r--mdk-stage1/partition.c171
-rw-r--r--mdk-stage1/partition.h28
-rw-r--r--mdk-stage1/tools.c34
-rw-r--r--mdk-stage1/tools.h2
6 files changed, 238 insertions, 166 deletions
diff --git a/mdk-stage1/Makefile b/mdk-stage1/Makefile
index 9fd254c8b..0baa93765 100644
--- a/mdk-stage1/Makefile
+++ b/mdk-stage1/Makefile
@@ -110,7 +110,7 @@ STAGE1_NETWORK_LIBS = /usr/$(LIB)/libresolv.a
endif
#- stage1 itself
-STAGE1SRC = stage1.c log.c tools.c modules.c probing.c mount.c automatic.c frontend-common.c lomount.c
+STAGE1SRC = stage1.c log.c tools.c modules.c probing.c mount.c automatic.c frontend-common.c lomount.c partition.c
CDROMSRC = cdrom.c
DISKSRC = disk.c directory.c
NETWORKSRC = network.c nfsmount.c dhcp.c url.c dns.c adsl.c directory.c
diff --git a/mdk-stage1/disk.c b/mdk-stage1/disk.c
index ca3e02526..678484c5e 100644
--- a/mdk-stage1/disk.c
+++ b/mdk-stage1/disk.c
@@ -36,155 +36,10 @@
#include "mount.h"
#include "lomount.h"
#include "automatic.h"
-
-#include "disk.h"
#include "directory.h"
+#include "partition.h"
-struct partition_detection_anchor {
- off_t offset;
- const char * anchor;
-};
-
-static int seek_and_compare(int fd, struct partition_detection_anchor anch)
-{
- char buf[500];
- size_t count;
- if (lseek(fd, anch.offset, SEEK_SET) == (off_t)-1) {
- log_perror("seek failed");
- return -1;
- }
- count = read(fd, buf, strlen(anch.anchor));
- if (count != strlen(anch.anchor)) {
- log_perror("read failed");
- return -1;
- }
- buf[count] = '\0';
- if (strcmp(anch.anchor, buf))
- return 1;
- return 0;
-}
-
-static const char * detect_partition_type(char * dev)
-{
- struct partition_detection_info {
- const char * name;
- struct partition_detection_anchor anchor0;
- struct partition_detection_anchor anchor1;
- struct partition_detection_anchor anchor2;
- };
- struct partition_detection_info partitions_signatures[] = {
- { "Linux Swap", { 4086, "SWAP-SPACE" }, { 0, NULL }, { 0, NULL } },
- { "Linux Swap", { 4086, "SWAPSPACE2" }, { 0, NULL }, { 0, NULL } },
- { "Ext2", { 0x438, "\x53\xEF" }, { 0, NULL }, { 0, NULL } },
- { "ReiserFS", { 0x10034, "ReIsErFs" }, { 0, NULL }, { 0, NULL } },
- { "ReiserFS", { 0x10034, "ReIsEr2Fs" }, { 0, NULL }, { 0, NULL } },
- { "XFS", { 0, "XFSB" }, { 0x200, "XAGF" }, { 0x400, "XAGI" } },
- { "JFS", { 0x8000, "JFS1" }, { 0, NULL }, { 0, NULL } },
- { "NTFS", { 0x1FE, "\x55\xAA" }, { 0x3, "NTFS" }, { 0, NULL } },
- { "FAT32", { 0x1FE, "\x55\xAA" }, { 0x52, "FAT32" }, { 0, NULL } },
- { "FAT", { 0x1FE, "\x55\xAA" }, { 0x36, "FAT" }, { 0, NULL } },
- { "Linux LVM", { 0, "HM\1\0" }, { 0, NULL }, { 0, NULL } }
- };
- int partitions_signatures_nb = sizeof(partitions_signatures) / sizeof(struct partition_detection_info);
- int i;
- int fd;
- const char *part_type = NULL;
-
- char device_fullname[50];
- strcpy(device_fullname, "/dev/");
- strcat(device_fullname, dev);
-
- if (ensure_dev_exists(device_fullname))
- return NULL;
- log_message("guessing type of %s", device_fullname);
-
- if ((fd = open(device_fullname, O_RDONLY, 0)) < 0) {
- log_perror("open");
- return NULL;
- }
-
- for (i=0; i<partitions_signatures_nb; i++) {
- int results = seek_and_compare(fd, partitions_signatures[i].anchor0);
- if (results == -1)
- goto detect_partition_type_end;
- if (results == 1)
- continue;
- if (!partitions_signatures[i].anchor1.anchor)
- goto detect_partition_found_it;
-
- results = seek_and_compare(fd, partitions_signatures[i].anchor1);
- if (results == -1)
- goto detect_partition_type_end;
- if (results == 1)
- continue;
- if (!partitions_signatures[i].anchor2.anchor)
- goto detect_partition_found_it;
-
- results = seek_and_compare(fd, partitions_signatures[i].anchor2);
- if (results == -1)
- goto detect_partition_type_end;
- if (results == 1)
- continue;
-
- detect_partition_found_it:
- part_type = partitions_signatures[i].name;
- break;
- }
-
- detect_partition_type_end:
- close(fd);
- return part_type;
-}
-
-static int list_partitions(char * dev_name, char ** parts, char ** comments)
-{
- int major, minor, blocks;
- char name[100];
- FILE * f;
- int i = 0;
- char buf[512];
-
- if (!(f = fopen("/proc/partitions", "rb")) || !fgets(buf, sizeof(buf), f) || !fgets(buf, sizeof(buf), f)) {
- log_perror(dev_name);
- return 1;
- }
-
- while (fgets(buf, sizeof(buf), f)) {
- memset(name, 0, sizeof(name));
- sscanf(buf, " %d %d %d %s", &major, &minor, &blocks, name);
- if ((strstr(name, dev_name) == name) && (blocks > 1) && (name[strlen(dev_name)] != '\0')) {
- const char * partition_type = detect_partition_type(name);
- parts[i] = strdup(name);
- comments[i] = (char *) malloc(sizeof(char) * 100);
- sprintf(comments[i], "size: %d Mbytes", blocks >> 10);
- if (partition_type) {
- strcat(comments[i], ", type: ");
- strcat(comments[i], partition_type);
- }
- i++;
- }
- }
- parts[i] = NULL;
- fclose(f);
-
- return 0;
-}
-
-static int try_mount(char * dev, char * location)
-{
- char device_fullname[50];
- strcpy(device_fullname, "/dev/");
- strcat(device_fullname, dev);
-
- if (my_mount(device_fullname, location, "ext2", 0) == -1 &&
- my_mount(device_fullname, location, "vfat", 0) == -1 &&
- my_mount(device_fullname, location, "ntfs", 0) == -1 &&
- my_mount(device_fullname, location, "reiserfs", 0) == -1) {
- return 1;
- }
-
- return 0;
-}
+#include "disk.h"
static enum return_type try_with_device(char *dev_name)
{
@@ -255,24 +110,6 @@ static enum return_type try_with_device(char *dev_name)
return RETURN_OK;
}
-static int get_disks(char *** names, char *** models)
-{
- char ** ptr;
- int count = 0;
-
- my_insmod("sd_mod", ANY_DRIVER_TYPE, NULL, 0);
-
- get_medias(DISK, names, models, BUS_ANY);
-
- ptr = *names;
- while (ptr && *ptr) {
- count++;
- ptr++;
- }
-
- return count;
-}
-
enum return_type disk_prepare(void)
{
char ** medias, ** medias_models;
diff --git a/mdk-stage1/partition.c b/mdk-stage1/partition.c
new file mode 100644
index 000000000..8fd581017
--- /dev/null
+++ b/mdk-stage1/partition.c
@@ -0,0 +1,171 @@
+/*
+ * Guillaume Cottenceau (gc@mandrakesoft.com)
+ *
+ * Copyright 2000 Mandrakesoft
+ *
+ * This software may be freely redistributed under the terms of the GNU
+ * public license.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/*
+ * Portions from Erik Troan (ewt@redhat.com)
+ *
+ * Copyright 1996 Red Hat Software
+ *
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <libgen.h>
+#include "stage1.h"
+#include "frontend.h"
+#include "modules.h"
+#include "probing.h"
+#include "log.h"
+#include "mount.h"
+#include "lomount.h"
+#include "automatic.h"
+
+#include "disk.h"
+#include "partition.h"
+
+struct partition_detection_anchor {
+ off_t offset;
+ const char * anchor;
+};
+
+static int seek_and_compare(int fd, struct partition_detection_anchor anch)
+{
+ char buf[500];
+ size_t count;
+ if (lseek(fd, anch.offset, SEEK_SET) == (off_t)-1) {
+ log_perror("seek failed");
+ return -1;
+ }
+ count = read(fd, buf, strlen(anch.anchor));
+ if (count != strlen(anch.anchor)) {
+ log_perror("read failed");
+ return -1;
+ }
+ buf[count] = '\0';
+ if (strcmp(anch.anchor, buf))
+ return 1;
+ return 0;
+}
+
+static const char * detect_partition_type(char * dev)
+{
+ struct partition_detection_info {
+ const char * name;
+ struct partition_detection_anchor anchor0;
+ struct partition_detection_anchor anchor1;
+ struct partition_detection_anchor anchor2;
+ };
+ struct partition_detection_info partitions_signatures[] = {
+ { "Linux Swap", { 4086, "SWAP-SPACE" }, { 0, NULL }, { 0, NULL } },
+ { "Linux Swap", { 4086, "SWAPSPACE2" }, { 0, NULL }, { 0, NULL } },
+ { "Ext2", { 0x438, "\x53\xEF" }, { 0, NULL }, { 0, NULL } },
+ { "ReiserFS", { 0x10034, "ReIsErFs" }, { 0, NULL }, { 0, NULL } },
+ { "ReiserFS", { 0x10034, "ReIsEr2Fs" }, { 0, NULL }, { 0, NULL } },
+ { "XFS", { 0, "XFSB" }, { 0x200, "XAGF" }, { 0x400, "XAGI" } },
+ { "JFS", { 0x8000, "JFS1" }, { 0, NULL }, { 0, NULL } },
+ { "NTFS", { 0x1FE, "\x55\xAA" }, { 0x3, "NTFS" }, { 0, NULL } },
+ { "FAT32", { 0x1FE, "\x55\xAA" }, { 0x52, "FAT32" }, { 0, NULL } },
+ { "FAT", { 0x1FE, "\x55\xAA" }, { 0x36, "FAT" }, { 0, NULL } },
+ { "Linux LVM", { 0, "HM\1\0" }, { 0, NULL }, { 0, NULL } }
+ };
+ int partitions_signatures_nb = sizeof(partitions_signatures) / sizeof(struct partition_detection_info);
+ int i;
+ int fd;
+ const char *part_type = NULL;
+
+ char device_fullname[50];
+ strcpy(device_fullname, "/dev/");
+ strcat(device_fullname, dev);
+
+ if (ensure_dev_exists(device_fullname))
+ return NULL;
+ log_message("guessing type of %s", device_fullname);
+
+ if ((fd = open(device_fullname, O_RDONLY, 0)) < 0) {
+ log_perror("open");
+ return NULL;
+ }
+
+ for (i=0; i<partitions_signatures_nb; i++) {
+ int results = seek_and_compare(fd, partitions_signatures[i].anchor0);
+ if (results == -1)
+ goto detect_partition_type_end;
+ if (results == 1)
+ continue;
+ if (!partitions_signatures[i].anchor1.anchor)
+ goto detect_partition_found_it;
+
+ results = seek_and_compare(fd, partitions_signatures[i].anchor1);
+ if (results == -1)
+ goto detect_partition_type_end;
+ if (results == 1)
+ continue;
+ if (!partitions_signatures[i].anchor2.anchor)
+ goto detect_partition_found_it;
+
+ results = seek_and_compare(fd, partitions_signatures[i].anchor2);
+ if (results == -1)
+ goto detect_partition_type_end;
+ if (results == 1)
+ continue;
+
+ detect_partition_found_it:
+ part_type = partitions_signatures[i].name;
+ break;
+ }
+
+ detect_partition_type_end:
+ close(fd);
+ return part_type;
+}
+
+int list_partitions(char * dev_name, char ** parts, char ** comments)
+{
+ int major, minor, blocks;
+ char name[100];
+ FILE * f;
+ int i = 0;
+ char buf[512];
+
+ if (!(f = fopen("/proc/partitions", "rb")) || !fgets(buf, sizeof(buf), f) || !fgets(buf, sizeof(buf), f)) {
+ log_perror(dev_name);
+ return 1;
+ }
+
+ while (fgets(buf, sizeof(buf), f)) {
+ memset(name, 0, sizeof(name));
+ sscanf(buf, " %d %d %d %s", &major, &minor, &blocks, name);
+ if ((strstr(name, dev_name) == name) && (blocks > 1) && (name[strlen(dev_name)] != '\0')) {
+ const char * partition_type = detect_partition_type(name);
+ parts[i] = strdup(name);
+ comments[i] = (char *) malloc(sizeof(char) * 100);
+ sprintf(comments[i], "size: %d Mbytes", blocks >> 10);
+ if (partition_type) {
+ strcat(comments[i], ", type: ");
+ strcat(comments[i], partition_type);
+ }
+ i++;
+ }
+ }
+ parts[i] = NULL;
+ fclose(f);
+
+ return 0;
+}
diff --git a/mdk-stage1/partition.h b/mdk-stage1/partition.h
new file mode 100644
index 000000000..e901662df
--- /dev/null
+++ b/mdk-stage1/partition.h
@@ -0,0 +1,28 @@
+/*
+ * Olivier Blin (oblin@mandrakesoft.com)
+ *
+ * Copyright 2005 Mandrakesoft
+ *
+ * This software may be freely redistributed under the terms of the GNU
+ * public license.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/*
+ * Portions from Erik Troan (ewt@redhat.com)
+ *
+ * Copyright 1996 Red Hat Software
+ *
+ */
+
+#ifndef _PARTITION_H_
+#define _PARTITION_H_
+
+int list_partitions(char * dev_name, char ** parts, char ** comments);
+
+#endif
+
diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c
index be050376b..8798b48ac 100644
--- a/mdk-stage1/tools.c
+++ b/mdk-stage1/tools.c
@@ -446,6 +446,40 @@ int kernel_version(void)
return charstar_to_int(val.release + 2);
}
+int try_mount(char * dev, char * location)
+{
+ char device_fullname[50];
+ strcpy(device_fullname, "/dev/");
+ strcat(device_fullname, dev);
+
+ if (my_mount(device_fullname, location, "ext2", 0) == -1 &&
+ my_mount(device_fullname, location, "vfat", 0) == -1 &&
+ my_mount(device_fullname, location, "ntfs", 0) == -1 &&
+ my_mount(device_fullname, location, "reiserfs", 0) == -1) {
+ return 1;
+ }
+
+ return 0;
+}
+
+int get_disks(char *** names, char *** models)
+{
+ char ** ptr;
+ int count = 0;
+
+ my_insmod("sd_mod", ANY_DRIVER_TYPE, NULL, 0);
+
+ get_medias(DISK, names, models, BUS_ANY);
+
+ ptr = *names;
+ while (ptr && *ptr) {
+ count++;
+ ptr++;
+ }
+
+ return count;
+}
+
char * floppy_device(void)
{
char ** names, ** models;
diff --git a/mdk-stage1/tools.h b/mdk-stage1/tools.h
index 737b323c9..a4aedfea1 100644
--- a/mdk-stage1/tools.h
+++ b/mdk-stage1/tools.h
@@ -48,6 +48,8 @@ void add_to_env(char * name, char * value);
char ** list_directory(char * direct);
int string_array_length(char ** a);
int kernel_version(void);
+int try_mount(char * dev, char * location);
+int get_disks(char *** names, char *** models);
char * floppy_device(void);
char * asprintf_(const char *msg, ...);
int scall_(int retval, char * msg, char * file, int line);