From: <ow...@us...> - 2007-11-01 08:21:27
|
Revision: 621 http://ipcop.svn.sourceforge.net/ipcop/?rev=621&view=rev Author: owes Date: 2007-11-01 01:21:30 -0700 (Thu, 01 Nov 2007) Log Message: ----------- Add new header for architecture specifics. Redone partitioning, to better cover powerpc and sparc schemes. Modified Paths: -------------- ipcop/trunk/src/installer/common.h ipcop/trunk/src/installer/hardware.c ipcop/trunk/src/installer/installer.c ipcop/trunk/src/installer/partition.c Added Paths: ----------- ipcop/trunk/src/installer/arch_defs.h Added: ipcop/trunk/src/installer/arch_defs.h =================================================================== --- ipcop/trunk/src/installer/arch_defs.h (rev 0) +++ ipcop/trunk/src/installer/arch_defs.h 2007-11-01 08:21:30 UTC (rev 621) @@ -0,0 +1,95 @@ +/* + * arch_defs.h: Global defines, function definitions etc. concerning portabilty + * Probably only necessary for installer. + * + * This program is distributed under the terms of the GNU General Public + * Licence. See the file COPYING for details. + * + * (c) 2007, the IPCop team + * + * $Id$ + * + */ + + +/* + Test which arch is used for building. + We currently support i386, alpha, powerpc and sparc. + + If you want to compile on a different architecture look in this file for modifications. +*/ +#if defined (__i386__) +#elif defined (__alpha__) +#elif defined (__powerpc__) || defined (__powerpc64__) +#elif defined (__sparc__) || defined (__sparc64__) +#else + #error "We currently do not support your hardware architecture" +#endif + + +#include <hd.h> + + +/* + Number of partitions +*/ +#if defined (__i386__) + #define NR_PARTITIONS 3 +#elif defined (__alpha__) + #define NR_PARTITIONS 3 +#elif defined (__powerpc__) || defined (__powerpc64__) + #define NR_PARTITIONS 5 +#elif defined (__sparc__) || defined (__sparc64__) + #define NR_PARTITIONS 4 +#endif + +/* + Partioning settings (all in MByte) +*/ +#define DISK_MINIMUM 256 +#define ROOT_MINIMUM 128 +#define SWAP_MINIMUM 32 +#define SWAP_MAXIMUM 256 + + +/* + Size for boot partition, this must be at least 2x size of kernel and initrd + so we can manage kernel updates. Also allow some margin, in case kernel size + increases. +*/ +#if defined (__powerpc__) +#define BOOT_PARTITION 32 +#else +#define BOOT_PARTITION 16 +#endif + + +/* + Various function implemented in hardware.c and partition.c +*/ +void scanhardware(int nopcmcia, int nousb); +int autopart( int selected_hd, long int disk_size); +int makedisk( int selected_hd, int *bootpartexist); +void createinitrd(void); +void make_bootable(int selected_hd, int bootpartexist); +/* + List of partitions. + Can be /boot, /, /var/log but also skip and swap. +*/ +extern char partition_label[NR_PARTITIONS][STRING_SIZE]; +/* + Helper, returns the name of the device without '/dev/' + Implemented in hardware.c +*/ +char *short_ddev(int disk); + +/* + Some global variables used when installing +*/ +extern char **harddisklist; +extern char **cdromlist; +extern char **floppylist; +extern unsigned int nummodules; +extern char **modules; +extern hd_hw_item_t *module_type; + Property changes on: ipcop/trunk/src/installer/arch_defs.h ___________________________________________________________________ Name: svn:keywords + Id Modified: ipcop/trunk/src/installer/common.h =================================================================== --- ipcop/trunk/src/installer/common.h 2007-11-01 05:53:54 UTC (rev 620) +++ ipcop/trunk/src/installer/common.h 2007-11-01 08:21:30 UTC (rev 621) @@ -13,7 +13,6 @@ #ifndef __COMMON_H #define __COMMON_H -#include <hd.h> #include <stdio.h> #define TRUE 1 @@ -25,22 +24,6 @@ /* - Partioning settings (all in MByte) -*/ -#define DISK_MINIMUM 256 -#define ROOT_MINIMUM 128 -#define SWAP_MINIMUM 32 -#define SWAP_MAXIMUM 256 - - -#if defined(__powerpc__) -#define BOOT_PARTITION 32 -#else -#define BOOT_PARTITION 16 -#endif - - -/* Log and error handles are needed for mysystem helper function. */ extern FILE *flog; @@ -55,11 +38,6 @@ int mysystem(char *command); int mysystemhidden(char *command); /* - Helper, returns the name of the device without '/dev/' - Implemented in hardware.c -*/ -char *short_ddev(int disk); -/* Implemented in helper_newt.c */ void statuswindow(int width, int height, char *title, char *text, ...); @@ -97,36 +75,9 @@ /* - + All kinds of functions used by setup */ -extern char **harddisklist; -extern char **cdromlist; -extern char **floppylist; -extern unsigned int nummodules; -extern char **modules; -extern hd_hw_item_t *module_type; - -void scanhardware(int nopcmcia, int nousb); - - -/* - -*/ void setlanguage (NODEKV *kv); - - -/* - -*/ -extern char **partition_label; - -int autopart( int selected_hd, long int disk_size); -int makedisk( int selected_hd, int *bootpartexist, int autolabel); -void createinitrd(void); -void make_bootable(int selected_hd, int bootpartexist); - - - int handlekeymap(void); int handletimezone(void); int handlehostname(void); @@ -134,9 +85,8 @@ int handleisdn(void); int handlenetworking(void); int handlepasswords(void); - /* - Dialogs for changing passwords. Possible user: "root", "admin", "backup" + Dialogs for changing passwords. Possible user: "root", "admin", "backup" */ int password(char *user); Modified: ipcop/trunk/src/installer/hardware.c =================================================================== --- ipcop/trunk/src/installer/hardware.c 2007-11-01 05:53:54 UTC (rev 620) +++ ipcop/trunk/src/installer/hardware.c 2007-11-01 08:21:30 UTC (rev 621) @@ -16,6 +16,7 @@ #include <string.h> #include <unistd.h> #include "common.h" +#include "arch_defs.h" // Build a list of specified items and load corresponding driver Modified: ipcop/trunk/src/installer/installer.c =================================================================== --- ipcop/trunk/src/installer/installer.c 2007-11-01 05:53:54 UTC (rev 620) +++ ipcop/trunk/src/installer/installer.c 2007-11-01 08:21:30 UTC (rev 621) @@ -31,6 +31,7 @@ #include <stdlib.h> #include <string.h> #include "common.h" +#include "arch_defs.h" NODEKV *kv = NULL; // contains a list key=value pairs @@ -232,12 +233,10 @@ 50, 5, 5, 8, harddisklist, ddisk, - gettext("TR_OK"), - "fdisk", - gettext("TR_CANCEL"), NULL); + gettext("TR_OK"), gettext("TR_CANCEL"), NULL); - if (rc == 3) // cancel choosed! - return 3; + if (rc == 2) // cancel choosed! + return 2; sprintf(string, "/sys/block/%s/size", short_ddev(*ddisk)); @@ -251,7 +250,7 @@ { fprintf(flog, "HARDDISK %s: really to small.\n", harddisklist[*ddisk]); newtWinMessage(get_title(), gettext("TR_OK"), gettext("TR_DISK_TO_SMALL")); - return 3; // force cancel + return 2; // force cancel } fclose(handle); fprintf(flog, "Hard disk selected %s. Size:%ld MByte\n", @@ -263,8 +262,7 @@ fprintf(flog, "Hard disk set to:%ld MByte\n", *disk_size); } - - return rc; //(OK or fdisk) + return rc; //(OK) } @@ -364,9 +362,9 @@ switch (selectdestination (&selected_hd, &disk_size)) { - case 3: //CANCEL + case 2: //CANCEL goto EXIT; - case 2: // call manual fdisk + case 3: // call manual fdisk #if 0 // skip for now if (!(bigdisk = (disk_size >= SMALL_DISK))) { @@ -389,8 +387,7 @@ if (autopart(selected_hd, disk_size)) goto EXIT; if (makedisk( selected_hd, - &bootpartindex, // return index id '/boot' - TRUE // autolabel=yes + &bootpartindex // return index id '/boot' )) goto EXIT; } @@ -446,11 +443,22 @@ mysystem("/bin/umount -n /harddisk/tmp"); mysystem("/bin/umount -n /harddisk/sys"); - for (i = 0; partition_label[i] ; i++) + for (i = 0; i < NR_PARTITIONS ; i++) { - char string[STRING_SIZE]; - snprintf(string, STRING_SIZE, "/bin/umount /harddisk%s", partition_label[i]); - mysystem(string); + if ( !strcmp(partition_label[i], "skip") ) + { + } + else if ( !strcmp(partition_label[i], "swap") ) + { + } + else if ( !strcmp(partition_label[i], "/") ) + { /* /var/log comes after /, so we cannot umount /harddisk/ */ + } + else + { + snprintf(line, STRING_SIZE, "/bin/umount /harddisk%s", partition_label[i]); + mysystem(line); + } } // And last /hardisk /mnt and swaps Modified: ipcop/trunk/src/installer/partition.c =================================================================== --- ipcop/trunk/src/installer/partition.c 2007-11-01 05:53:54 UTC (rev 620) +++ ipcop/trunk/src/installer/partition.c 2007-11-01 08:21:30 UTC (rev 621) @@ -6,6 +6,28 @@ * * (c) 2007, the IPCop team * + * + * + * Partition scheme is: + * i386 partition1 /boot + * partition2 / + * partition3 /var/log + * + * alpha partition1 /boot + * partition2 / + * partition3 /var/log + * + * powerpc partition1 -- reserved, absolutely can't be used + * partition2 -- reserved, absolutely can't be used + * partition3 /boot + * partition4 / + * partition5 /var/log + * + * sparc partition1 /boot + * partition2 / + * partition3 -- reserved, absolutely can't be used + * partition4 /var/log + * * $Id$ * */ @@ -18,536 +40,479 @@ #include <string.h> #include <sys/stat.h> #include "common.h" +#include "arch_defs.h" + +static int numpartitions = 0; +static char partitions [NR_PARTITIONS][STRING_SIZE]; // something like /dev/hda1, /dev/hda2 +char partition_label [NR_PARTITIONS][STRING_SIZE]; // add 1 string for terminator mark + + /* Calculate for the user a useable disk schema partition and make it so. */ -int -autopart( int selected_hd, long int disk_size) +int autopart( int selected_hd, long int disk_size) { + long int swap_file, boot_partition, log_partition; + long int start_partition, current_free, root_partition; + char string[STRING_SIZE]; + char *device = harddisklist[selected_hd]; - long int swap_file, boot_partition, log_partition; - long int start_partition, current_free, root_partition; - char string[STRING_SIZE]; + /* set all the minimum sizes */ + boot_partition = BOOT_PARTITION; + root_partition = ROOT_MINIMUM; + swap_file = SWAP_MINIMUM; + log_partition = DISK_MINIMUM - BOOT_PARTITION - ROOT_MINIMUM - SWAP_MINIMUM; - /* set all the minimum sizes */ - boot_partition = BOOT_PARTITION; - root_partition = ROOT_MINIMUM; - swap_file = SWAP_MINIMUM; - log_partition = DISK_MINIMUM - BOOT_PARTITION - ROOT_MINIMUM - SWAP_MINIMUM; + current_free = disk_size - boot_partition - root_partition - log_partition - swap_file; - current_free = disk_size - boot_partition - root_partition - log_partition - swap_file; + /* 25% of remaining space goes to swap and maximize swap */ + swap_file += current_free / 4; + if ( swap_file > SWAP_MAXIMUM ) + { + swap_file = SWAP_MAXIMUM; + } - /* 25% of remaining space goes to swap and maximize swap */ - swap_file += current_free / 4; - if ( swap_file > SWAP_MAXIMUM ) - { - swap_file = SWAP_MAXIMUM; - } + /* 25% of remaining space goes to root partition */ + root_partition += current_free / 4; + /* swap is just a file in root partition */ + root_partition = root_partition + swap_file; + /* now that we have boot and root, recalc log */ + log_partition = disk_size - boot_partition - root_partition; - /* 25% of remaining space goes to root partition */ - root_partition += current_free / 4; - /* swap is just a file in root partition */ - root_partition = root_partition + swap_file; - /* now that we have boot and root, recalc log */ - log_partition = disk_size - boot_partition - root_partition; + start_partition = 1; /* in MB */ - start_partition = 1; /* in MB */ + /* stupid parted is unable to batch correctly. */ + snprintf(string, STRING_SIZE, "dd if=/dev/zero of=%s bs=512 count=1", device ); + mysystem(string); + mysystem("sync"); - /* stupid parted is unable to batch correctly. */ - snprintf(string, STRING_SIZE, "dd if=/dev/zero of=%s bs=512 count=1", harddisklist[selected_hd] ); - mysystem(string); - mysystem("sync"); - #if defined(__i386__) || defined(__x86_64__) - snprintf(string, STRING_SIZE, "/bin/parted -s %s mklabel msdos", harddisklist[selected_hd]); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create msdos disk label (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + strcpy(partition_label[0], "/boot"); + strcpy(partition_label[1], "/"); + strcpy(partition_label[2], "/var/log"); + strcpy(partition_label[3], ""); - snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", - harddisklist[selected_hd], - start_partition, - boot_partition); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create /boot partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mklabel msdos", device); + if (mysystem(string) != 0) + { + fprintf(flog, "Unable to create msdos disk label (fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", - harddisklist[selected_hd], - boot_partition, - boot_partition+root_partition); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create / partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", + device, + start_partition, + boot_partition); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create /boot partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", - harddisklist[selected_hd], - boot_partition+root_partition, - disk_size); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create /var/log partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", + device, + boot_partition, + boot_partition+root_partition); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create / partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s set 1 boot on", - harddisklist[selected_hd]); - if (mysystem(string)) - { - fprintf(flog, "Unable to set the boot flag on the /boot partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", + device, + boot_partition+root_partition, + disk_size); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create /var/log partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } + + snprintf(string, STRING_SIZE, "/bin/parted -s %s set 1 boot on", + device); + if ( mysystem(string) ) + { + fprintf(flog, "Unable to set the boot flag on the /boot partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } #endif /* End of i386/x86_64 partitioning block */ #if defined(__powerpc__) || defined(__powerpc64__) - snprintf(string, STRING_SIZE, "/bin/parted -s %s mklabel mac", - harddisklist[selected_hd]); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create mac disk label (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + strcpy(partition_label[0], "skip"); + strcpy(partition_label[1], "skip"); + strcpy(partition_label[2], "/boot"); + strcpy(partition_label[3], "/"); + strcpy(partition_label[4], "/var/log"); + strcpy(partition_label[5], ""); - snprintf(string, STRING_SIZE, - "/bin/parted -s %s mkpart primary hfs 33k %ld", - harddisklist[selected_hd], - start_partition); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create hfs bootstrap partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mklabel mac", device); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create mac disk label (fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s name 2 bootstrap", - harddisklist[selected_hd]); - if (mysystem(string)) - { - fprintf(flog, "Unable to name bootstrap partition (non-fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary hfs 33k %ld", + device, + start_partition); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create hfs bootstrap partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s set 2 boot on", - harddisklist[selected_hd]); - if (mysystem(string)) - { - fprintf(flog, "Unable to set the boot flag on the hfs bootstrap partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s name 2 bootstrap", + device); + if ( mysystem(string) ) + { + fprintf(flog, "Unable to name bootstrap partition (non-fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", - harddisklist[selected_hd], - start_partition, - boot_partition); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create /boot partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s set 2 boot on", + device); + if ( mysystem(string) ) + { + fprintf(flog, "Unable to set the boot flag on the hfs bootstrap partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s name 3 /boot", harddisklist[selected_hd]); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to name /boot partition (non-fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", + device, + start_partition, + boot_partition); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create /boot partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", - harddisklist[selected_hd], - boot_partition, - root_partition); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create / partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s name 3 /boot", device); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to name /boot partition (non-fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s name 4 /", harddisklist[selected_hd]); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to name / partition (non-fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", + device, + boot_partition, + root_partition); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create / partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", - harddisklist[selected_hd], - root_partition, - log_partition); + snprintf(string, STRING_SIZE, "/bin/parted -s %s name 4 /", device); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to name / partition (non-fatal error)\n"); + /* return 1; */ /* ERROR */ + } - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create /var/log partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", + device, + root_partition, + log_partition); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create /var/log partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s name 5 /var/log", - harddisklist[selected_hd]); - if (mysystem(string)) - { - fprintf(flog, "Unable to name /var/log partition (non-fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s name 5 /var/log", device); + if ( mysystem(string) ) + { + fprintf(flog, "Unable to name /var/log partition (non-fatal error)\n"); + /* return 1; */ /* ERROR */ + } #endif /* End of ppc/ppc64 partitioning block */ #if defined(__sparc__) || defined(__sparc64__) - snprintf(string, STRING_SIZE, "/bin/parted -s %s mklabel sun", - harddisklist[selected_hd]); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create sun disk label (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + strcpy(partition_label[0], "/boot"); + strcpy(partition_label[1], "/"); + strcpy(partition_label[2], "skip"); + strcpy(partition_label[3], "/var/log"); + strcpy(partition_label[4], ""); - snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", - harddisklist[selected_hd], - start_partition, - boot_partition); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create /boot partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mklabel sun", device); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create sun disk label (fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", - harddisklist[selected_hd], - boot_partition, - root_partition); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create / partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", + device, + start_partition, + boot_partition); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create /boot partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", - harddisklist[selected_hd], - root_partition, - log_partition); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create /var/log partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", + device, + boot_partition, + root_partition); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create / partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s set 1 boot on", - harddisklist[selected_hd]); - if (mysystem(string)) - { - fprintf(flog, "Unable to set the boot flag on the /boot partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } -#endif /* End of sparc/sparc64 partitioning block */ + snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", + device, + root_partition, + log_partition); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create /var/log partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } + snprintf(string, STRING_SIZE, "/bin/parted -s %s set 1 boot on", device); + if ( mysystem(string) ) + { + fprintf(flog, "Unable to set the boot flag on the /boot partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } + #endif /* End of sparc/sparc64 partitioning block */ + #if defined(__alpha__) - snprintf(string, STRING_SIZE, "/bin/parted -s %s mklabel bsd", - harddisklist[selected_hd]); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create bsd disk label (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + strcpy(partition_label[0], "/boot"); + strcpy(partition_label[1], "/"); + strcpy(partition_label[2], "/var/log"); + strcpy(partition_label[3], ""); - snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", - harddisklist[selected_hd], - start_partition, - boot_partition); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create /boot partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mklabel bsd", device); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create bsd disk label (fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", - harddisklist[selected_hd], - boot_partition, - root_partition); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create / partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", + device, + start_partition, + boot_partition); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create /boot partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", - harddisklist[selected_hd], - root_partition, - log_partition); - if (mysystem(string) != 0) - { - fprintf(flog, "Unable to create /var/log partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", + device, + boot_partition, + root_partition); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create / partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } - snprintf(string, STRING_SIZE, "/bin/parted -s %s set 1 boot on", - harddisklist[selected_hd]); - if (mysystem(string)) - { - fprintf(flog, "Unable to set the boot flag on the /boot partition (fatal error)\n"); - /* return 1; */ /* ERROR */ - } + snprintf(string, STRING_SIZE, "/bin/parted -s %s mkpart primary %ld %ld", + device, + root_partition, + log_partition); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to create /var/log partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } + + snprintf(string, STRING_SIZE, "/bin/parted -s %s set 1 boot on", device); + if ( mysystem(string) != 0 ) + { + fprintf(flog, "Unable to set the boot flag on the /boot partition (fatal error)\n"); + /* return 1; */ /* ERROR */ + } #endif /* End of alpha partitioning block */ - return 0; /* SUCCESS */ + return 0; /* SUCCESS */ } /* End of int autopart() */ -int -manualpart( int selected_hd) +/* + Manual partition. Not correctly implemented, not tested. + Do not use. +*/ +int manualpart( int selected_hd) { - /* Would like to write a frontend based on libparted and get - * rid of cfdisk, as it doesn't understand other partitioning - * software. - */ - char string[STRING_SIZE]; - newtFinished(); - snprintf(string, STRING_SIZE, "cfdisk %s", harddisklist[selected_hd]); - /* dont redirect */ - system(string); - newtInit(); - newtCls(); - return 0; + /* Would like to write a frontend based on libparted and get + * rid of cfdisk, as it doesn't understand other partitioning + * software. + */ + char string[STRING_SIZE]; + newtFinished(); + snprintf(string, STRING_SIZE, "cfdisk %s", harddisklist[selected_hd]); + /* dont redirect */ + system(string); + newtInit(); + newtCls(); + return 0; } -// -// After sourcefile are decompressed on harddisk, make room on /tmp -// +/* + After sourcefile are decompressed on harddisk, make room on /tmp +*/ void deletetarballs() { - mysystem("rm -f /tmp/" SNAME "-" VERSION "-varlog.tar.gz"); - mysystem("rm -f /tmp/" SNAME "-" VERSION "-config.tar.gz"); - mysystem("rm -f /tmp/" SNAME "-" VERSION ".tar.gz"); + mysystem("rm -f /tmp/" SNAME "-" VERSION "-varlog.tar.gz"); + mysystem("rm -f /tmp/" SNAME "-" VERSION "-config.tar.gz"); + mysystem("rm -f /tmp/" SNAME "-" VERSION ".tar.gz"); } -// Format and copy ipcop files. -// Input : autolabel flag -// Return value : indexe of boot partition (zero if not) -// use two global var to unmount properly partition at end. -char **partition_label = NULL; //callback helper funct, select something int special_filter_helper; -int -filter (const struct dirent *b) +int filter (const struct dirent *b) { - return (strstr(b->d_name, short_ddev(special_filter_helper))) ? 1 : 0; + return (strstr(b->d_name, short_ddev(special_filter_helper))) ? 1 : 0; } -int -makedisk( int selected_hd, - int *bootpartexist, - int autolabel) -{ - char string[STRING_SIZE]; - char message[STRING_SIZE]; - FILE *handle; - struct dirent **names; - int i; - int alllabelled = 0; - int found = 0; - int numpartitions = 0; - char **partitions = NULL; - char **partitionslist = NULL; - int choice=0, rc; - char *values[] = { NULL, NULL }; /* pointers for the values. */ - struct newtWinEntry entries[] = { {"", &values[0], 0,}, {NULL, NULL, 0} }; - // Get existing partitions names - sprintf(string, "/sys/block/%s", short_ddev(selected_hd)); - special_filter_helper = selected_hd; // call back needs global var. - numpartitions = scandir(string, &names, &filter, alphasort); - fprintf(flog, "Number of Partitions: %d\n", numpartitions); +/* + Format and copy ipcop files. + We assume the disk is partitioned. + No manual labelling. - if (numpartitions == 0) - { - newtWinMessage(get_title(), gettext("TR_OK"), gettext("TR_UNABLE_TO_PARTITION")); - return 1; // cancel - } - partitions = calloc(1, sizeof(char *) * (numpartitions + 1)); - partition_label = calloc(1, sizeof(char *) * (numpartitions + 1)); - for (i = 0; i < numpartitions; i++) - { - partitions[i] = calloc(1, strlen(names[i]->d_name) + 1); - strcpy(partitions[i], names[i]->d_name); - partition_label[i] = ""; - free(names[i]); - } - free(names); + Return value: + index of boot partition (zero if not) +*/ - /* end with a null pointer */ - partitions[numpartitions] = NULL; +int makedisk( int selected_hd, + int *bootpartexist) +{ + char string[STRING_SIZE]; + char message[STRING_SIZE]; + FILE *handle; + struct dirent **names; + int i; + int found = 0; + int choice=0, rc; + char *values[] = { NULL, NULL }; /* pointers for the values. */ + struct newtWinEntry entries[] = { {"", &values[0], 0,}, {NULL, NULL, 0} }; - for (i = 0; i < numpartitions; i++) - fprintf(flog, "PARTITIONS ARE : %s\n", partitions[i]); + // Get existing partitions names + sprintf(string, "/sys/block/%s", short_ddev(selected_hd)); + special_filter_helper = selected_hd; // call back needs global var. + numpartitions = scandir(string, &names, &filter, alphasort); - /* auto partitioned, so auto label */ - if (autolabel == 1) - { - alllabelled = TRUE; - } - partition_label[0] = "/boot"; - partition_label[1] = "/"; - partition_label[2] = "/var/log"; + fprintf(flog, "Number of Partitions: %d\n", numpartitions); - while (!alllabelled) - { - //reconstruct part + label in a string... - partitionslist = calloc(1, sizeof(char *) * (numpartitions + 1)); - for (i = 0; i < numpartitions; i++) - { - partitionslist[i] = calloc(1, strlen(partitions[i]) - + strlen(partition_label[i]) + 10); - sprintf(partitionslist[i],"%s => %s", partitions[i],partition_label[i]); - } - partitionslist[i] = NULL; - -/*TR*/ rc = newtWinMenu(gettext("Label Partitions"), -/*TR*/ gettext("Select the partition to label."), 50, - 5, 5, 8, partitionslist, &choice, - gettext("TR_EDIT"), - gettext("TR_DONE"), - gettext("TR_CANCEL"), NULL); + if ( (numpartitions == 0) || (numpartitions > NR_PARTITIONS) ) + { + newtWinMessage(get_title(), gettext("TR_OK"), gettext("TR_UNABLE_TO_PARTITION")); + return 1; // cancel + } + for (i = 0; i < numpartitions; i++) + { + strncpy(partitions[i], names[i]->d_name, STRING_SIZE); + partitions[i][STRING_SIZE-1] = 0; + fprintf(flog, "PARTITIONS ARE : %s %s\n", partitions[i], partition_label[i]); + free(names[i]); + } + free(names); - for (i = 0; i < numpartitions; i++) - { - free (partitionslist[i]); - } - free (partitionslist); - - if (rc == 3) - return 1; // cancel + statuswindow(60, 4, get_title(), gettext("TR_MAKING_FILESYSTEMS")); - if ((rc == 1) || (rc == 0)) { - char *v = strdup (partition_label[choice]); - free (values[0]); - values[0] = v; -/*TR*/ sprintf(message, gettext("Enter Label")); - sprintf(string, "%s %s", -/*TR*/ gettext("Enter the mount point for the partition"), - partitions[choice]); -/*TR*/ if( 2 == newtWinEntries(gettext("Label Partition"), - string, 50, 5, 5, 18, - entries, - gettext("TR_OK"), - gettext("TR_CANCEL"), NULL)) - continue; - - fprintf(flog, "CHOICE %d VALUE %s\n", choice, values[0]); - - /* Ensure first char is / */ - if (values[0][0] == '/') - strcpy(string,""); - else - strcpy(string,"/"); - strcat (string,values[0]); - partition_label[choice] = calloc(1, strlen(string) + 1); - strcpy(partition_label[choice], string); - fprintf(flog, "MOUNT POINT FOR %s is %s\n", - partitions[choice], partition_label[choice]); - } - - /* test for all labelled up */ - if (rc == 2) - { - alllabelled = 1; - found = 0; - for (i = 0; i < numpartitions; i++) - { - if (partition_label[i] == NULL) - alllabelled = 0; - /* make sure we've found the root partition */ - else if (strlen(partition_label[i]) == 1) - found = 1; - } - if (!found) - alllabelled = 0; - } - } - - statuswindow(60, 4, get_title(), gettext("TR_MAKING_FILESYSTEMS")); - - if ((handle=fopen("/etc/fstab", "w"))) + if ( (handle = fopen("/etc/fstab", "w")) ) + { + for (i = 0; i < numpartitions; i++) { - for (i = 0; i < numpartitions; i++) + if ( !strcmp(partition_label[i], "skip") ) { - if (!strcmp(partition_label[i], "swap")) - { - sprintf(string, "/sbin/mkswap /dev/%s", partitions[i]); - mysystem(string); - fprintf(handle, "/dev/%s\tnone%s\tswap\n", - partitions[i], partition_label[i]); - mysystem("/bin/swapon -a"); - } else { - sprintf(string, "/sbin/mke2fs -L %s -q -j /dev/%s", - partition_label[i], - partitions[i]); - mysystem(string); + } + else if ( !strcmp(partition_label[i], "swap") ) + { + sprintf(string, "/sbin/mkswap /dev/%s", partitions[i]); + mysystem(string); + fprintf(handle, "/dev/%s\tnone%s\tswap\n", partitions[i], partition_label[i]); + mysystem("/bin/swapon -a"); + } else { + sprintf(string, "/sbin/mke2fs -L %s -q -j /dev/%s", partition_label[i], partitions[i]); + mysystem(string); // sprintf(string, "/sbin/tune2fs -L %s /dev/%s", // partition_label[i], partitions[i]); // mysystem(string); - fprintf(handle, "/dev/%s\t/harddisk%s\text3\n", - partitions[i], partition_label[i]); - } + fprintf(handle, "/dev/%s\t/harddisk%s\text3\n", partitions[i], partition_label[i]); } - fclose(handle); } - newtPopWindow(); + fclose(handle); + } + newtPopWindow(); - /* Update device files after partitioning */ - mysystem("/sbin/udevstart"); - statuswindow(60, 4, get_title(), gettext("TR_MOUTING_FILESYSTEMS")); + /* Update device files after partitioning */ + mysystem("/sbin/udevstart"); - /* load ext3 now */ - mysystem("/bin/modprobe ext3"); - mysystem("/bin/mount /harddisk/"); + statuswindow(60, 4, get_title(), gettext("TR_MOUTING_FILESYSTEMS")); - *bootpartexist = 0; - for (i = 0; i < numpartitions; i++) + /* load ext3 now */ + mysystem("/bin/modprobe ext3"); + mysystem("/bin/mount /harddisk/"); + + *bootpartexist = 0; + for (i = 0; i < numpartitions; i++) + { + if ( !strcmp(partition_label[i], "skip") ) { + } + else if ( !strcmp(partition_label[i], "swap") ) + { + } + else + { sprintf(string, "/bin/mkdir -p /harddisk%s", partition_label[i]); mysystem(string); - if (!strcmp(partition_label[i], "/boot")) + if ( !strcmp(partition_label[i], "/boot") ) { *bootpartexist = i + 1; } } - /* this can fail */ - mysystem("/bin/mount -a"); - newtPopWindow(); + } + /* this can fail */ + mysystem("/bin/mount -a"); + newtPopWindow(); - /* populate files on the partitions */ - statuswindow(60, 4, get_title(), gettext("TR_INSTALLING_FILES")); - mysystem("/bin/tar -C /harddisk -xpzf /tmp/" SNAME "-" VERSION "-varlog.tar.gz"); - mysystem("/bin/tar -C /harddisk -xpzf /tmp/" SNAME "-" VERSION "-config.tar.gz"); - mysystem("/bin/tar -C /harddisk -xpzf /tmp/" SNAME "-" VERSION ".tar.gz"); + /* populate files on the partitions */ + statuswindow(60, 4, get_title(), gettext("TR_INSTALLING_FILES")); + mysystem("/bin/tar -C /harddisk -xpzf /tmp/" SNAME "-" VERSION "-varlog.tar.gz"); + mysystem("/bin/tar -C /harddisk -xpzf /tmp/" SNAME "-" VERSION "-config.tar.gz"); + mysystem("/bin/tar -C /harddisk -xpzf /tmp/" SNAME "-" VERSION ".tar.gz"); - /* complete fstab */ - if ((handle = fopen("/harddisk/etc/fstab", "a"))) + /* complete fstab */ + if ( (handle = fopen("/harddisk/etc/fstab", "a")) ) + { + for (i = 0; i < numpartitions; i++) { - for (i = 0; i < numpartitions; i++) + if ( !strcmp(partition_label[i], "skip") ) { - if (!strcmp(partition_label[i], "swap")) - fprintf(handle, "/dev/%s\t\t%s\t\tswap\tdefaults\t0 0\n", - partitions[i], partition_label[i]); - else - fprintf(handle, "/dev/%s\t\t%s\t\text3\tnoatime\t1 1\n", - partitions[i], partition_label[i]); } - fclose(handle); + else if (!strcmp(partition_label[i], "swap")) + { + fprintf(handle, "/dev/%s\t\t%s\t\tswap\tdefaults\t0 0\n", partitions[i], partition_label[i]); + } + else + { + fprintf(handle, "/dev/%s\t\t%s\t\text3\tnoatime\t1 1\n", partitions[i], partition_label[i]); + } } - newtPopWindow(); + fclose(handle); + } + newtPopWindow(); - for (i = 0; i < numpartitions; i++) - free(partitions[numpartitions]); - free(partitions); - return 0; // success + for (i = 0; i < numpartitions; i++) + return 0; // success } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |