From: <ow...@us...> - 2008-05-22 14:45:11
|
Revision: 1386 http://ipcop.svn.sourceforge.net/ipcop/?rev=1386&view=rev Author: owes Date: 2008-05-22 07:45:17 -0700 (Thu, 22 May 2008) Log Message: ----------- Use LABEL instead of UUID, no problem since we have fixed partitioning and it is much more user-friendly. Added functions to make make_partitions much easier readable. Modified Paths: -------------- ipcop/trunk/src/installer/arch_defs.h ipcop/trunk/src/installer/installer.c ipcop/trunk/src/installer/partition.c Modified: ipcop/trunk/src/installer/arch_defs.h =================================================================== --- ipcop/trunk/src/installer/arch_defs.h 2008-05-22 14:22:38 UTC (rev 1385) +++ ipcop/trunk/src/installer/arch_defs.h 2008-05-22 14:45:17 UTC (rev 1386) @@ -115,18 +115,10 @@ extern unsigned int memtotal; /* Total memory in MB */ /* - Various function implemented in hardware.c and partition.c + Functions implemented in hardware.c and partition.c */ void scan_hardware(int installer_setup, int nopcmcia, int nousb, int noscsi); -int make_partitions(char *device, long int disk_size, int parted, long int *swap_size); -int make_disk(char *device, long int swap_size); -void create_initramfs(void); -void make_bootable(char *device, long int ramdisk_size); -/* - List of partitions. - Can be /boot, /, /var/log but also skip and swap. -*/ -extern char partition_label[NR_PARTITIONS][STRING_SIZE]; +int make_ipcop_disk(char *device, long int disk_size, int parted); /* Some global variables used when installing Modified: ipcop/trunk/src/installer/installer.c =================================================================== --- ipcop/trunk/src/installer/installer.c 2008-05-22 14:22:38 UTC (rev 1385) +++ ipcop/trunk/src/installer/installer.c 2008-05-22 14:45:17 UTC (rev 1386) @@ -559,7 +559,6 @@ int selected_hd = 0; long int disk_size = 0; long int ramdisk_size = 0; - long int swap_size = 0; if ( selectdestination(&selected_hd, &disk_size, &ramdisk_size) ) { @@ -567,32 +566,16 @@ goto EXIT; } - /* Partition the 'device', manual partitioning if parted != 0 */ - if ( make_partitions(hardwares[selected_hd].device, disk_size, parted, &swap_size) ) + /* Partition, format, mount, initramfs and make bootable + manual partitioning if parted != 0 */ + if ( make_ipcop_disk(hardwares[selected_hd].device, disk_size, parted) ) goto EXIT; - /* Format partitions and fill them with files */ - if ( make_disk(hardwares[selected_hd].device, swap_size) ) - goto EXIT; + // Now, /harddisk is mounted // /harddisk/boot is mounted // /harddisk/var/log is mounted - /* Mount filesystems necessary??? */ - mysystem("/bin/mount -n -t sysfs none /harddisk/sys"); - mysystem("/bin/mount -n -t tmpfs none /harddisk/tmp"); - mysystem("/bin/mount -n -t ramfs none /harddisk/root"); - mysystem("/bin/mount -n -t proc none /harddisk/proc"); - - /* We've already discovered all the devices on the host, so use that information */ - mysystem("/bin/mount -n -o bind /dev /harddisk/dev"); - - // InitRD - create_initramfs(); - - /* Make the new installation bootable */ - make_bootable(hardwares[selected_hd].device, ramdisk_size); - if ( medium_target == flash ) { /* Specials for flash disk */ @@ -647,28 +630,18 @@ mysystem("/bin/umount -n /harddisk/tmp"); mysystem("/bin/umount -n /harddisk/sys"); - for (i = 0; i < NR_PARTITIONS ; i++) + /* No need to make this complicated, we know what we've mounted */ + mysystem("/bin/umount -n /harddisk/boot"); + if ( medium_target == flash ) { - 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(command, STRING_SIZE, "/bin/umount /harddisk%s", partition_label[i]); - mysystem(command); - } + mysystem("/bin/umount -n /harddisk/var/log_compressed"); } - - // And last /hardisk and swaps - mysystem("/bin/umount /harddisk/"); // migh be done in the loop - //mysystem("/bin/swapoff /harddisk/swapfile"); + else + { + mysystem("/bin/umount -n /harddisk/var/log"); + } mysystem("/bin/swapoff -a"); + mysystem("/bin/umount /harddisk/"); /* And very very last, unmount /cdrom */ if ( medium_sources == cdrom ) Modified: ipcop/trunk/src/installer/partition.c =================================================================== --- ipcop/trunk/src/installer/partition.c 2008-05-22 14:22:38 UTC (rev 1385) +++ ipcop/trunk/src/installer/partition.c 2008-05-22 14:45:17 UTC (rev 1386) @@ -68,27 +68,111 @@ #define BLKGETSIZE64 _IOR(0x12,114,size_t) +/* Make these module globals. + Since we are not multi-tasking, multi-threaded, multi-anything that is OK + and avoids passing pointers to pointers, addresses of pointers, etc. between functions. +*/ 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 -char uuid_enc[NR_PARTITIONS][STRING_SIZE]; // UUIDs +static char partitions[NR_PARTITIONS][STRING_SIZE]; // something like /dev/hda1, /dev/hda2 +static char partition_label[NR_PARTITIONS][STRING_SIZE]; // add 1 string for terminator mark +static char partition_mount[NR_PARTITIONS][STRING_SIZE]; // mountpoints for partitions +static char partition_uuidenc[NR_PARTITIONS][STRING_SIZE]; // UUIDs +static PedDevice *ped_dev; +static PedDisk *ped_disk; +static PedPartition *ped_part; +static PedConstraint *ped_constraint; -/* - Calculate for the user a useable disk schema partition + +/* Since we do this only slightly different for every architecture, + bundle it in 1 function. + Parameter is partition table labeltype, can be something like bsd, mac, msdos, sun. + Returns 0 if OK. +*/ +static int my_partition_table(const char *disk_type) +{ + if ( (ped_disk = ped_disk_new_fresh(ped_dev, ped_disk_type_get(disk_type))) == NULL ) + { + fprintf(flog, "Error in ped_disk_new_fresh\n"); + return 1; + } + if ( !ped_disk_commit_to_dev(ped_disk) ) + { + fprintf(flog, "Error in ped_disk_commit disktype\n"); + return 2; + } + + fprintf(flog, "Table of type %s created\n", disk_type); + return 0; +} + + +/* Create an additional partition, label it and flag as bootable if wanted. + Parameters: start and end sector, filesystemtype (ext2, hfs), label and boot flag. + Returns 0 if OK. +*/ +static int my_partition_create(PedSector start, PedSector end, const char *fstype, const char *label, int boot) +{ + PedFileSystemType *ped_fstype; + + if ( (ped_fstype = ped_file_system_type_get(fstype)) == NULL ) + { + fprintf(flog, "Error in ped_file_system_type_get (%s)\n", fstype); + return 1; + } + + if ( (ped_part = ped_partition_new(ped_disk, PED_PARTITION_NORMAL, ped_fstype, start, end)) == NULL ) + { + fprintf(flog, "Error in ped_partition_new (%s)\n", fstype); + return 1; + } + + /* If labels are supported, make it so */ + if ( ped_disk_type_check_feature (ped_disk->type, PED_DISK_TYPE_PARTITION_NAME) ) + { + ped_partition_set_name(ped_part, label); + } + /* Set the boot flag */ + if ( boot ) + { + ped_partition_set_flag(ped_part, PED_PARTITION_BOOT, 1); + } + + if ( (ped_constraint = ped_constraint_new_from_max(&ped_part->geom)) == NULL ) + { + fprintf(flog, "Error in ped_constraint_new_from_max (%s)\n", label); + return 1; + } + + if ( ped_disk_add_partition(ped_disk, ped_part, ped_constraint) == 0 ) + { + fprintf(flog, "Error in ped_disk_add_partition (%s)\n", label); + return 1; + } + + if ( !ped_disk_commit_to_dev(ped_disk) ) + { + fprintf(flog, "Error in ped_disk_commit (%s)\n", label); + return 1; + } + fprintf(flog, "Partition added %s (%s)\n", label, fstype); + + return 0; +} + + +/* Calculate for the user a useable disk schema partition and make it so. */ int make_partitions(char *dev, long int disk_size, int parted, long int *swap_file) { + int i; int retcode = 1; /* ERROR */ + int part_varlog; /* /var/log partition number */ long boot_partition, log_partition; long int start_partition, current_free, root_partition; char command[STRING_SIZE]; char device[STRING_SIZE]; - PedDevice *ped_dev; - PedDisk *ped_disk; - PedPartition *ped_part; - PedFileSystemType *ped_fstype; PedSector pedsector_start; PedSector pedsector_boot; PedSector pedsector_root; @@ -147,40 +231,66 @@ boot_p + root_p disk_size */ - /* misuse command for /var/log vs. /var/log_compressed */ - if ( medium_target == flash ) + for (i = 0; i < NR_PARTITIONS; i++) { - strcpy(command, "/var/log_compressed"); + /* zap label and mountpoint strings */ + partition_label[i][0] = 0; + partition_mount[i][0] = 0; } - else - { - strcpy(command, "/var/log"); - } + /* define all label and mountpoints for the architectures we support */ + part_varlog = 0; #if defined(__i386__) || defined(__x86_64__) - strcpy(partition_label[0], "/boot"); - strcpy(partition_label[1], "/"); - strcpy(partition_label[2], command); + strcpy(partition_label[0], "boot"); + strcpy(partition_label[1], "root"); + strcpy(partition_mount[0], "/boot"); + strcpy(partition_mount[1], "/"); + part_varlog = 2; #endif #if defined(__powerpc__) || defined(__powerpc64__) strcpy(partition_label[0], "skip"); strcpy(partition_label[1], "skip"); - strcpy(partition_label[2], "/boot"); - strcpy(partition_label[3], "/"); - strcpy(partition_label[4], command); + strcpy(partition_label[2], "boot"); + strcpy(partition_label[3], "root"); + strcpy(partition_mount[2], "/boot"); + strcpy(partition_mount[3], "/"); + part_varlog = 4; #endif #if defined(__sparc__) || defined(__sparc64__) - strcpy(partition_label[0], "/boot"); - strcpy(partition_label[1], "/"); + strcpy(partition_label[0], "boot"); + strcpy(partition_label[1], "root"); strcpy(partition_label[2], "skip"); - strcpy(partition_label[3], command); + strcpy(partition_mount[0], "/boot"); + strcpy(partition_mount[1], "/"); + part_varlog = 3; #endif #if defined(__alpha__) - strcpy(partition_label[0], "/boot"); - strcpy(partition_label[1], "/"); - strcpy(partition_label[2], command); + strcpy(partition_label[0], "boot"); + strcpy(partition_label[1], "root"); + strcpy(partition_mount[0], "/boot"); + strcpy(partition_mount[1], "/"); + part_varlog = 2; #endif + if ( part_varlog == 0 ) + { + /* Can't be, probably because of non-supported arch. */ + fprintf(flog, "Partition# for /var/log is 0, non-supported arch?\n"); + goto PARTITION_EXIT; + } + + if ( medium_target == flash ) + { + strcpy(partition_label[part_varlog], "varlog_comp"); + strcpy(partition_mount[part_varlog], "/var/log_compressed"); + } + else + { + strcpy(partition_label[part_varlog], "varlog"); + strcpy(partition_mount[part_varlog], "/var/log"); + } + + if ( parted && (access("/usr/bin/parted", 0) == 0) ) { /* @@ -207,11 +317,11 @@ fprintf(f, "/usr/bin/parted -s %s name 2 bootstrap\n", device); fprintf(f, "/usr/bin/parted -s %s set 2 boot on\n", device); fprintf(f, "/usr/bin/parted -s %s mkpart primary ext2 %ld %ld\n", device, start_partition, boot_partition); - fprintf(f, "/usr/bin/parted -s %s name 3 /boot\n", device); + fprintf(f, "/usr/bin/parted -s %s name 3 %s\n", device, "boot"); fprintf(f, "/usr/bin/parted -s %s mkpart primary ext2 %ld %ld\n", device, boot_partition, boot_partition+root_partition); - fprintf(f, "/usr/bin/parted -s %s name 4 /\n", device); + fprintf(f, "/usr/bin/parted -s %s name 4 %s\n", device, "root"); fprintf(f, "/usr/bin/parted -s %s mkpart primary ext2 %ld %ld\n", device, boot_partition+root_partition, disk_size); - fprintf(f, "/usr/bin/parted -s %s name 5 /var/log\n", device); + fprintf(f, "/usr/bin/parted -s %s name 5 %s\n", device, partition_label[part_varlog]); #endif #if defined(__sparc__) || defined(__sparc64__) fprintf(f, "/usr/bin/parted -s %s mklabel sun\n", device); @@ -252,11 +362,6 @@ fprintf(flog, "error in ped_device_get\n"); goto PARTITION_EXIT; } - if ( (ped_fstype = ped_file_system_type_get("ext2")) == NULL ) - { - fprintf(flog, "error in ped_file_system_type_get\n"); - goto PARTITION_EXIT; - } /* convert MByte to PedSector */ pedsector_start = ((PedSector)1*1024*1024 / ped_dev->sector_size); @@ -265,243 +370,78 @@ #if defined(__i386__) || defined(__x86_64__) /* create a new partition table */ - if ( (ped_disk = ped_disk_new_fresh(ped_dev, ped_disk_type_get("msdos"))) == NULL ) - { - fprintf(flog, "error in ped_disk_new_fresh\n"); + if ( my_partition_table("msdos") ) goto PARTITION_EXIT; - } - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit disktype\n"); - goto PARTITION_EXIT; - } /* boot partition */ - ped_part = ped_partition_new(ped_disk, PED_PARTITION_NORMAL, ped_fstype, 1, pedsector_boot); - if ( ped_disk_type_check_feature (ped_disk->type, PED_DISK_TYPE_PARTITION_NAME) ) - { - ped_partition_set_name(ped_part, "/boot"); - } - ped_partition_set_flag(ped_part, PED_PARTITION_BOOT, 1); - ped_disk_add_partition(ped_disk, ped_part, ped_constraint_exact(&ped_part->geom)); - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit /boot\n"); + if ( my_partition_create(1, pedsector_boot, "ext2", "boot", 1) ) goto PARTITION_EXIT; - } - fprintf(flog, "Partition added /boot\n"); /* / partition */ - ped_part = ped_partition_new(ped_disk, PED_PARTITION_NORMAL, ped_fstype, ped_part->geom.end+1, ped_part->geom.end+1+pedsector_root); - if ( ped_disk_type_check_feature (ped_disk->type, PED_DISK_TYPE_PARTITION_NAME) ) - { - ped_partition_set_name(ped_part, "/"); - } - ped_disk_add_partition(ped_disk, ped_part, ped_constraint_exact(&ped_part->geom)); - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit /\n"); + if ( my_partition_create(ped_part->geom.end+1, ped_part->geom.end+1+pedsector_root, "ext2", "root", 0) ) goto PARTITION_EXIT; - } - fprintf(flog, "Partition added /\n"); /* /var/log partition */ - ped_part = ped_partition_new(ped_disk, PED_PARTITION_NORMAL, ped_fstype, ped_part->geom.end+1, ped_dev->length - 1); - if ( ped_disk_type_check_feature (ped_disk->type, PED_DISK_TYPE_PARTITION_NAME) ) - { - ped_partition_set_name(ped_part, "/var/log"); - } - ped_disk_add_partition(ped_disk, ped_part, ped_constraint_exact(&ped_part->geom)); - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit /var/log\n"); + if ( my_partition_create(ped_part->geom.end+1, ped_dev->length - 1, "ext2", partition_label[part_varlog], 0) ) goto PARTITION_EXIT; - } - fprintf(flog, "Partition added /var/log\n"); #endif /* End of i386/x86_64 partitioning block */ #if defined(__powerpc__) || defined(__powerpc64__) /* create a new partition table */ - if ( (ped_disk = ped_disk_new_fresh(ped_dev, ped_disk_type_get("mac"))) == NULL ) - { - fprintf(flog, "error in ped_disk_new_fresh\n"); + if ( my_partition_table("mac") ) goto PARTITION_EXIT; - } - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit disktype\n"); - goto PARTITION_EXIT; - } /* hfs bootstrap partition */ - ped_part = ped_partition_new(ped_disk, PED_PARTITION_NORMAL, ped_file_system_type_get("hfs"), 1, pedsector_start); - if ( ped_disk_type_check_feature (ped_disk->type, PED_DISK_TYPE_PARTITION_NAME) ) - { - ped_partition_set_name(ped_part, "bootstrap"); - } - ped_partition_set_flag(ped_part, PED_PARTITION_BOOT, 1); - ped_disk_add_partition(ped_disk, ped_part, ped_constraint_exact(&ped_part->geom)); - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit bootstrap\n"); + if ( my_partition_create(1, pedsector_start, "hfs", "bootstrap", 1) ) goto PARTITION_EXIT; - } /* boot partition */ - ped_part = ped_partition_new(ped_disk, PED_PARTITION_NORMAL, ped_fstype, ped_part->geom.end+1, ped_part->geom.end+1+pedsector_boot); - if ( ped_disk_type_check_feature (ped_disk->type, PED_DISK_TYPE_PARTITION_NAME) ) - { - ped_partition_set_name(ped_part, "/boot"); - } - ped_disk_add_partition(ped_disk, ped_part, ped_constraint_exact(&ped_part->geom)); - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit /boot\n"); + if ( my_partition_create(ped_part->geom.end+1, ped_part->geom.end+1+pedsector_boot, "ext2", "boot", 0) ) goto PARTITION_EXIT; - } - fprintf(flog, "Partition added /boot\n"); /* / partition */ - ped_part = ped_partition_new(ped_disk, PED_PARTITION_NORMAL, ped_fstype, ped_part->geom.end+1, ped_part->geom.end+1+pedsector_root); - if ( ped_disk_type_check_feature (ped_disk->type, PED_DISK_TYPE_PARTITION_NAME) ) - { - ped_partition_set_name(ped_part, "/"); - } - ped_disk_add_partition(ped_disk, ped_part, ped_constraint_exact(&ped_part->geom)); - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit /\n"); + if ( my_partition_create(ped_part->geom.end+1, ped_part->geom.end+1+pedsector_root, "ext2", "root", 0) ) goto PARTITION_EXIT; - } - fprintf(flog, "Partition added /\n"); /* /var/log partition */ - ped_part = ped_partition_new(ped_disk, PED_PARTITION_NORMAL, ped_fstype, ped_part->geom.end+1, ped_dev->length - 1); - if ( ped_disk_type_check_feature (ped_disk->type, PED_DISK_TYPE_PARTITION_NAME) ) - { - ped_partition_set_name(ped_part, "/var/log"); - } - ped_disk_add_partition(ped_disk, ped_part, ped_constraint_exact(&ped_part->geom)); - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit /var/log\n"); + if ( my_partition_create(ped_part->geom.end+1, ped_dev->length - 1, "ext2", partition_label[part_varlog], 0) ) goto PARTITION_EXIT; - } - fprintf(flog, "Partition added /var/log\n"); #endif /* End of ppc/ppc64 partitioning block */ #if defined(__sparc__) || defined(__sparc64__) /* create a new partition table */ - if ( (ped_disk = ped_disk_new_fresh(ped_dev, ped_disk_type_get("sun"))) == NULL ) - { - fprintf(flog, "error in ped_disk_new_fresh\n"); + if ( my_partition_table("sun") ) goto PARTITION_EXIT; - } - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit disktype\n"); - goto PARTITION_EXIT; - } /* boot partition */ - ped_part = ped_partition_new(ped_disk, PED_PARTITION_NORMAL, ped_fstype, 1, pedsector_boot); - if ( ped_disk_type_check_feature (ped_disk->type, PED_DISK_TYPE_PARTITION_NAME) ) - { - ped_partition_set_name(ped_part, "/boot"); - } - ped_partition_set_flag(ped_part, PED_PARTITION_BOOT, 1); - ped_disk_add_partition(ped_disk, ped_part, ped_constraint_exact(&ped_part->geom)); - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit /boot\n"); + if ( my_partition_create(1, pedsector_boot, "ext2", "boot", 1) ) goto PARTITION_EXIT; - } - fprintf(flog, "Partition added /boot\n"); /* / partition */ - ped_part = ped_partition_new(ped_disk, PED_PARTITION_NORMAL, ped_fstype, ped_part->geom.end+1, ped_part->geom.end+1+pedsector_root); - if ( ped_disk_type_check_feature (ped_disk->type, PED_DISK_TYPE_PARTITION_NAME) ) - { - ped_partition_set_name(ped_part, "/"); - } - ped_disk_add_partition(ped_disk, ped_part, ped_constraint_exact(&ped_part->geom)); - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit /\n"); + if ( my_partition_create(ped_part->geom.end+1, ped_part->geom.end+1+pedsector_root, "ext2", "root", 0) ) goto PARTITION_EXIT; - } - fprintf(flog, "Partition added /\n"); /* /var/log partition */ - ped_part = ped_partition_new(ped_disk, PED_PARTITION_NORMAL, ped_fstype, ped_part->geom.end+1, ped_dev->length - 1); - if ( ped_disk_type_check_feature (ped_disk->type, PED_DISK_TYPE_PARTITION_NAME) ) - { - ped_partition_set_name(ped_part, "/var/log"); - } - ped_disk_add_partition(ped_disk, ped_part, ped_constraint_exact(&ped_part->geom)); - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit /var/log\n"); + if ( my_partition_create(ped_part->geom.end+1, ped_dev->length - 1, "ext2", partition_label[part_varlog], 0) ) goto PARTITION_EXIT; - } - fprintf(flog, "Partition added /var/log\n"); #endif /* End of sparc/sparc64 partitioning block */ #if defined(__alpha__) /* create a new partition table */ - if ( (ped_disk = ped_disk_new_fresh(ped_dev, ped_disk_type_get("bsd"))) == NULL ) - { - fprintf(flog, "error in ped_disk_new_fresh\n"); + if ( my_partition_table("bsd") ) goto PARTITION_EXIT; - } - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit disktype\n"); - goto PARTITION_EXIT; - } /* boot partition */ - ped_part = ped_partition_new(ped_disk, PED_PARTITION_NORMAL, ped_fstype, 1, pedsector_boot); - if ( ped_disk_type_check_feature (ped_disk->type, PED_DISK_TYPE_PARTITION_NAME) ) - { - ped_partition_set_name(ped_part, "/boot"); - } - ped_partition_set_flag(ped_part, PED_PARTITION_BOOT, 1); - ped_disk_add_partition(ped_disk, ped_part, ped_constraint_exact(&ped_part->geom)); - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit /boot\n"); + if ( my_partition_create(1, pedsector_boot, "ext2", "boot", 1) ) goto PARTITION_EXIT; - } - fprintf(flog, "Partition added /boot\n"); /* / partition */ - ped_part = ped_partition_new(ped_disk, PED_PARTITION_NORMAL, ped_fstype, ped_part->geom.end+1, ped_part->geom.end+1+pedsector_root); - if ( ped_disk_type_check_feature (ped_disk->type, PED_DISK_TYPE_PARTITION_NAME) ) - { - ped_partition_set_name(ped_part, "/"); - } - ped_disk_add_partition(ped_disk, ped_part, ped_constraint_exact(&ped_part->geom)); - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit /\n"); + if ( my_partition_create(ped_part->geom.end+1, ped_part->geom.end+1+pedsector_root, "ext2", "root", 0) ) goto PARTITION_EXIT; - } - fprintf(flog, "Partition added /\n"); /* /var/log partition */ - ped_part = ped_partition_new(ped_disk, PED_PARTITION_NORMAL, ped_fstype, ped_part->geom.end+1, ped_dev->length - 1); - if ( ped_disk_type_check_feature (ped_disk->type, PED_DISK_TYPE_PARTITION_NAME) ) - { - ped_partition_set_name(ped_part, "/var/log"); - } - ped_disk_add_partition(ped_disk, ped_part, ped_constraint_exact(&ped_part->geom)); - if ( !ped_disk_commit_to_dev(ped_disk) ) - { - fprintf(flog, "error in ped_disk_commit /var/log\n"); + if ( my_partition_create(ped_part->geom.end+1, ped_dev->length - 1, "ext2", partition_label[part_varlog], 0) ) goto PARTITION_EXIT; - } - fprintf(flog, "Partition added /var/log\n"); #endif /* End of alpha partitioning block */ ped_disk_commit(ped_disk); @@ -509,6 +449,10 @@ retcode = 0; /* SUCCESS */ PARTITION_EXIT: + if ( retcode ) + { + fprintf(flog, "Make partitions failed ...\n"); + } sleep(1); mysystem("/bin/sync"); @@ -550,10 +494,9 @@ We assume the disk is partitioned. No manual labelling. - Return value: - index of boot partition (zero if not) + Return 0 if OK */ -int make_disk(char *dev, long int swap_file) +static int make_disk(char *dev, long int swap_file) { char command[STRING_SIZE]; char string[STRING_SIZE]; @@ -604,7 +547,7 @@ const char *uuid; snprintf(string, STRING_SIZE, "/dev/%s", partitions[i]); - uuid_enc[i][0] = 0; + partition_uuidenc[i][0] = 0; snprintf(command, STRING_SIZE, "/usr/bin/mke2fs -L %s -q -j %s", partition_label[i], string); mysystem(command); @@ -626,13 +569,13 @@ ioctl(fd, BLKGETSIZE64, &size); volume_id_probe_filesystem(vid, 0, size); volume_id_get_uuid(vid, &uuid); - volume_id_encode_string(uuid, uuid_enc[i], STRING_SIZE); - fprintf(flog, " %s UUID %s\n", string, uuid_enc[i]); + volume_id_encode_string(uuid, partition_uuidenc[i], STRING_SIZE); + fprintf(flog, " %s UUID %s\n", string, partition_uuidenc[i]); } close(fd); } - fprintf(handle, "%s\t/harddisk%s\text3\n", string, partition_label[i]); + fprintf(handle, "%s\t/harddisk%s\text3\n", string, partition_mount[i]); } } fclose(handle); @@ -640,11 +583,6 @@ newtPopWindow(); - /* Update device files after partitioning -- DISABLED, we use udevd */ - /* - mysystem("/sbin/udevstart"); - */ - statuswindow(72, 5, ipcop_gettext("TR_TITLE_DISK"), ipcop_gettext("TR_MOUTING_FILESYSTEMS")); /* load ext3 now */ @@ -653,12 +591,21 @@ for (i = 0; i < numpartitions; i++) { - if ( !strcmp(partition_label[i], "skip") ) + if ( partition_label[i][0] == 0 ) { } + else if ( !strcmp(partition_label[i], "skip") ) + { + /* The label says it all */ + } + else if ( partition_mount[i][0] == 0 ) + { + /* This one does not have a mount point? */ + fprintf(flog, "Don't know what mountpoint to make for: %s\n", partition_label[i]); + } else { - sprintf(command, "/bin/mkdir -p /harddisk%s", partition_label[i]); + snprintf(command, STRING_SIZE, "/bin/mkdir -p /harddisk%s", partition_mount[i]); mysystem(command); } } @@ -778,16 +725,23 @@ } else { - /* either use UUID (when available) or device for /etc/fstab */ - if ( uuid_enc[1][0] ) + /* either use UUID,LABEL (when available) or device for /etc/fstab */ + #ifdef FSTAB_USE_UUID + if ( partition_uuidenc[1][0] ) { - snprintf(devname, STRING_SIZE, "UUID=%s", uuid_enc[i]); + snprintf(devname, STRING_SIZE, "UUID=%s", partition_uuidenc[i]); } + #else + if ( partition_label[1][0] ) + { + snprintf(devname, STRING_SIZE, "LABEL=%s", partition_label[i]); + } + #endif else { snprintf(devname, STRING_SIZE, "/dev/%s", partitions[i]); } - fprintf(handle, FORMAT_FSTAB, devname, partition_label[i], "ext3", "noatime", "1", "1"); + fprintf(handle, FORMAT_FSTAB, devname, partition_mount[i], "ext3", "noatime", "1", "1"); } } @@ -808,7 +762,7 @@ } -void create_initramfs(void) +static void create_initramfs(void) { char bigstring[STRING_SIZE_LARGE]; // many modules maybe! int i; @@ -864,10 +818,10 @@ } -/* - Make the new installation bootable, add ramdisksize +/* Make the new installation bootable, add ramdisksize. + Note that there are few similarities between the architectures here. */ -void make_bootable(char *dev, long int ramdisk_size) +static void make_bootable(char *dev) { char command[STRING_SIZE]; char device[STRING_SIZE]; @@ -881,12 +835,21 @@ snprintf(command, STRING_SIZE, "/bin/sed -i -e 's+DEVICE+%s+g' /harddisk/tmp/grubbatch", device); mysystem(command); - if ( uuid_enc[1][0] ) + #ifdef GRUB_USE_UUID + if ( partition_uuidenc[1][0] ) { /* replace the ROOT_DEV with UUID partition 2 */ - snprintf(command, STRING_SIZE, "/bin/sed -i -e 's+ROOT_DEV+UUID=%s+g' /harddisk/boot/grub/menu.lst", uuid_enc[1]); + snprintf(command, STRING_SIZE, "/bin/sed -i -e 's+ROOT_DEV+UUID=%s+g' /harddisk/boot/grub/menu.lst", partition_uuidenc[1]); mysystem(command); } + #else + if ( partition_label[1][0] ) + { + /* replace the ROOT_DEV with LABEL partition 2 */ + snprintf(command, STRING_SIZE, "/bin/sed -i -e 's+ROOT_DEV+LABEL=%s+g' /harddisk/boot/grub/menu.lst", "root"); + mysystem(command); + } + #endif else { /* fallback: replace the ROOT_DEV with the real device, partition 2 */ @@ -894,7 +857,6 @@ mysystem(command); } - /* apply ramdisk_size (if any) */ if ( medium_target == flash ) { /* Add ide=nodma, maybe others. */ @@ -990,3 +952,36 @@ newtPopWindow(); } + + +/* The big one. Cleaning, cooking, laundring, the whole enchilada. +*/ +int make_ipcop_disk(char *dev, long int disk_size, int parted) +{ + long int swap_file; + + /* Make partition table and partitions */ + if ( make_partitions(dev, disk_size, parted, &swap_file) ) + return 1; + + /* Format the fresh partitions */ + if ( make_disk(dev, swap_file) ) + return 1; + + /* Mount filesystems necessary??? */ + mysystem("/bin/mount -n -t sysfs none /harddisk/sys"); + mysystem("/bin/mount -n -t tmpfs none /harddisk/tmp"); + mysystem("/bin/mount -n -t ramfs none /harddisk/root"); + mysystem("/bin/mount -n -t proc none /harddisk/proc"); + + /* We've already discovered all the devices on the host, so use that information */ + mysystem("/bin/mount -n -o bind /dev /harddisk/dev"); + + // InitRD + create_initramfs(); + + /* Make the new installation bootable */ + make_bootable(dev); + + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |