]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: (sgi) cleanu sgi_info stuff
authorKarel Zak <kzak@redhat.com>
Wed, 29 May 2013 12:43:05 +0000 (14:43 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2013 14:46:57 +0000 (16:46 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk.c
fdisks/fdisksgilabel.c
fdisks/fdisksgilabel.h
include/pt-sgi.h

index 12700ee6e3c42a14ceb00ae5102168b2d4c5d1b8..b5dd7890d1c50dd173bf9c51c9673c5e56d42a21 100644 (file)
@@ -932,7 +932,7 @@ static void command_prompt(struct fdisk_context *cxt)
                        break;
                case 'i':
                        if (fdisk_is_disklabel(cxt, SGI))
-                               create_sgiinfo(cxt);
+                               sgi_create_info(cxt);
                        else
                                unknown_command(c);
                        break;
index 8dab615227202181a9bfabf08024ee780011242a..a9507a7accfea4aa64adb276cd70a67a367dfc7a 100644 (file)
@@ -24,8 +24,8 @@
 #include <sys/stat.h>           /* stat */
 #include <assert.h>             /* assert */
 
-#include <endian.h>
 #include "nls.h"
+#include "all-io.h"
 #include "xalloc.h"
 
 #include "blkdev.h"
@@ -43,7 +43,62 @@ struct fdisk_sgi_label {
        struct fdisk_label      head;           /* generic part */
 };
 
-static sgiinfo *fill_sgiinfo(void);
+/*
+ * Information within second on-disk block
+ */
+#define        SGI_INFO_MAGIC          0x00072959
+
+struct sgi_info {
+       unsigned int   magic;           /* looks like a magic number */
+       unsigned int   a2;
+       unsigned int   a3;
+       unsigned int   a4;
+       unsigned int   b1;
+       unsigned short b2;
+       unsigned short b3;
+       unsigned int   c[16];
+       unsigned short d[3];
+       unsigned char  scsi_string[50];
+       unsigned char  serial[137];
+       unsigned short check1816;
+       unsigned char  installer[225];
+};
+
+static struct sgi_info *sgi_new_info(void)
+{
+       struct sgi_info *info = calloc(1, sizeof(struct sgi_info));
+
+       if (!info)
+               return NULL;
+
+       info->magic = cpu_to_be32(SGI_INFO_MAGIC);
+       info->b1 = cpu_to_be32(-1);
+       info->b2 = cpu_to_be16(-1);
+       info->b3 = cpu_to_be16(1);
+
+       /* You may want to replace this string !!!!!!! */
+       strcpy((char *) info->scsi_string, "IBM OEM 0662S12         3 30");
+       strcpy((char *) info->serial, "0000");
+       info->check1816 = cpu_to_be16(18 * 256 + 16);
+       strcpy((char *) info->installer, "Sfx version 5.3, Oct 18, 1994");
+
+       return info;
+}
+
+static void sgi_free_info(struct sgi_info *info)
+{
+       free(info);
+}
+
+int sgi_create_info(struct fdisk_context *cxt)
+{
+       /* I keep SGI's habit to write the sgilabel to the second block */
+       sgilabel->volume[0].block_num = cpu_to_be32(2);
+       sgilabel->volume[0].num_bytes = cpu_to_be32(sizeof(struct sgi_info));
+       strncpy((char *) sgilabel->volume[0].name, "sgilabel", 8);
+       return 0;
+}
+
 
 /*
  * only dealing with free blocks here
@@ -311,19 +366,9 @@ sgi_set_bootfile(struct fdisk_context *cxt)
        }
 }
 
-void create_sgiinfo(struct fdisk_context *cxt)
-{
-       /* I keep SGI's habit to write the sgilabel to the second block */
-       sgilabel->volume[0].block_num = cpu_to_be32(2);
-       sgilabel->volume[0].num_bytes = cpu_to_be32(sizeof(sgiinfo));
-       strncpy((char *) sgilabel->volume[0].name, "sgilabel", 8);
-}
-
-
 static int sgi_write_disklabel(struct fdisk_context *cxt)
 {
-
-       sgiinfo *info = NULL;
+       struct sgi_info *info = NULL;
 
        assert(cxt);
        assert(cxt->label);
@@ -349,19 +394,17 @@ static int sgi_write_disklabel(struct fdisk_context *cxt)
                if (lseek(cxt->dev_fd, (off_t) infostartblock *
                                                SECTOR_SIZE, SEEK_SET) < 0)
                        goto err;
-
-               info = fill_sgiinfo();
+               info = sgi_new_info();
                if (!info)
                        goto err;
-
-               if (write(cxt->dev_fd, info, SECTOR_SIZE) != SECTOR_SIZE)
+               if (write_all(cxt->dev_fd, info, sizeof(*info)))
                        goto err;
        }
 
-       free(info);
+       sgi_free_info(info);
        return 0;
 err:
-       free(info);
+       sgi_free_info(info);
        return -errno;
 }
 
@@ -908,25 +951,6 @@ sgi_set_ncyl(void)
 /* _____________________________________________________________
  */
 
-static sgiinfo *fill_sgiinfo(void)
-{
-       sgiinfo *info = xcalloc(1, sizeof(sgiinfo));
-
-       if (!info)
-               return NULL;
-
-       info->magic = cpu_to_be32(SGI_INFO_MAGIC);
-       info->b1 = cpu_to_be32(-1);
-       info->b2 = cpu_to_be16(-1);
-       info->b3 = cpu_to_be16(1);
-       /* You may want to replace this string !!!!!!! */
-       strcpy((char *) info->scsi_string, "IBM OEM 0662S12         3 30");
-       strcpy((char *) info->serial, "0000");
-       info->check1816 = cpu_to_be16(18 * 256 + 16);
-       strcpy((char *) info->installer, "Sfx version 5.3, Oct 18, 1994");
-       return info;
-}
-
 static struct fdisk_parttype *sgi_get_parttype(struct fdisk_context *cxt, size_t n)
 {
        struct fdisk_parttype *t;
index 0ba4cfcc0a8f4f1574cd0a966cfe520e29e6f794..cca694f36e32940b9b02816070b5e604f91a3a3d 100644 (file)
 #define        RESEEK          0x20
 #define        CMDTAGQ_ENABLE  0x40
 
-typedef struct {
-       unsigned int   magic;           /* looks like a magic number */
-       unsigned int   a2;
-       unsigned int   a3;
-       unsigned int   a4;
-       unsigned int   b1;
-       unsigned short b2;
-       unsigned short b3;
-       unsigned int   c[16];
-       unsigned short d[3];
-       unsigned char  scsi_string[50];
-       unsigned char  serial[137];
-       unsigned short check1816;
-       unsigned char  installer[225];
-} sgiinfo;
-
-#define        SGI_LABEL_MAGIC         0x0be5a941
-#define        SGI_LABEL_MAGIC_SWAPPED 0x41a9e50b
-#define        SGI_INFO_MAGIC          0x00072959
-#define        SGI_INFO_MAGIC_SWAPPED  0x59290700
-
+#
 /* toggle flags */
 #define SGI_FLAG_BOOT  1
 #define SGI_FLAG_SWAP  2
@@ -49,7 +29,6 @@ extern void   sgi_list_table( struct fdisk_context *cxt, int xtra );
 extern int  sgi_change_sysid(struct fdisk_context *cxt, int i, int sys);
 extern unsigned int    sgi_get_start_sector(struct fdisk_context *cxt, int i );
 extern unsigned int    sgi_get_num_sectors(struct fdisk_context *cxt, int i );
-extern void    create_sgiinfo(struct fdisk_context *cxt);
 extern void    sgi_set_ilfact( void );
 extern void    sgi_set_rspeed( void );
 extern void    sgi_set_pcylcount( void );
@@ -61,4 +40,6 @@ extern int    sgi_get_bootpartition(struct fdisk_context *cxt);
 extern int     sgi_get_swappartition(struct fdisk_context *cxt);
 extern void    sgi_set_bootfile(struct fdisk_context *cxt);
 
+extern int sgi_create_info(struct fdisk_context *cxt);
+
 #endif /* FDISK_SGI_LABEL_H */
index aef33859ee1484db7d5654cf22f79f473fad0c28..ff482babdd3a5f0eeff91a9e8db5ce32f0b3015c 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <stdint.h>
 
+#define        SGI_LABEL_MAGIC         0x0be5a941
+
 #define SGI_MAXPARTITIONS      16
 #define SGI_MAXVOLUMES         15