~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/block/partitions/sun.c

Version: ~ [ linux-5.1-rc5 ] ~ [ linux-5.0.7 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.34 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.111 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.168 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.178 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.138 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.65 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  *  fs/partitions/sun.c
  4  *
  5  *  Code extracted from drivers/block/genhd.c
  6  *
  7  *  Copyright (C) 1991-1998  Linus Torvalds
  8  *  Re-organised Feb 1998 Russell King
  9  */
 10 
 11 #include "check.h"
 12 #include "sun.h"
 13 
 14 int sun_partition(struct parsed_partitions *state)
 15 {
 16         int i;
 17         __be16 csum;
 18         int slot = 1;
 19         __be16 *ush;
 20         Sector sect;
 21         struct sun_disklabel {
 22                 unsigned char info[128];   /* Informative text string */
 23                 struct sun_vtoc {
 24                     __be32 version;     /* Layout version */
 25                     char   volume[8];   /* Volume name */
 26                     __be16 nparts;      /* Number of partitions */
 27                     struct sun_info {           /* Partition hdrs, sec 2 */
 28                         __be16 id;
 29                         __be16 flags;
 30                     } infos[8];
 31                     __be16 padding;     /* Alignment padding */
 32                     __be32 bootinfo[3];  /* Info needed by mboot */
 33                     __be32 sanity;       /* To verify vtoc sanity */
 34                     __be32 reserved[10]; /* Free space */
 35                     __be32 timestamp[8]; /* Partition timestamp */
 36                 } vtoc;
 37                 __be32 write_reinstruct; /* sectors to skip, writes */
 38                 __be32 read_reinstruct;  /* sectors to skip, reads */
 39                 unsigned char spare[148]; /* Padding */
 40                 __be16 rspeed;     /* Disk rotational speed */
 41                 __be16 pcylcount;  /* Physical cylinder count */
 42                 __be16 sparecyl;   /* extra sects per cylinder */
 43                 __be16 obs1;       /* gap1 */
 44                 __be16 obs2;       /* gap2 */
 45                 __be16 ilfact;     /* Interleave factor */
 46                 __be16 ncyl;       /* Data cylinder count */
 47                 __be16 nacyl;      /* Alt. cylinder count */
 48                 __be16 ntrks;      /* Tracks per cylinder */
 49                 __be16 nsect;      /* Sectors per track */
 50                 __be16 obs3;       /* bhead - Label head offset */
 51                 __be16 obs4;       /* ppart - Physical Partition */
 52                 struct sun_partition {
 53                         __be32 start_cylinder;
 54                         __be32 num_sectors;
 55                 } partitions[8];
 56                 __be16 magic;      /* Magic number */
 57                 __be16 csum;       /* Label xor'd checksum */
 58         } * label;
 59         struct sun_partition *p;
 60         unsigned long spc;
 61         char b[BDEVNAME_SIZE];
 62         int use_vtoc;
 63         int nparts;
 64 
 65         label = read_part_sector(state, 0, &sect);
 66         if (!label)
 67                 return -1;
 68 
 69         p = label->partitions;
 70         if (be16_to_cpu(label->magic) != SUN_LABEL_MAGIC) {
 71 /*              printk(KERN_INFO "Dev %s Sun disklabel: bad magic %04x\n",
 72                        bdevname(bdev, b), be16_to_cpu(label->magic)); */
 73                 put_dev_sector(sect);
 74                 return 0;
 75         }
 76         /* Look at the checksum */
 77         ush = ((__be16 *) (label+1)) - 1;
 78         for (csum = 0; ush >= ((__be16 *) label);)
 79                 csum ^= *ush--;
 80         if (csum) {
 81                 printk("Dev %s Sun disklabel: Csum bad, label corrupted\n",
 82                        bdevname(state->bdev, b));
 83                 put_dev_sector(sect);
 84                 return 0;
 85         }
 86 
 87         /* Check to see if we can use the VTOC table */
 88         use_vtoc = ((be32_to_cpu(label->vtoc.sanity) == SUN_VTOC_SANITY) &&
 89                     (be32_to_cpu(label->vtoc.version) == 1) &&
 90                     (be16_to_cpu(label->vtoc.nparts) <= 8));
 91 
 92         /* Use 8 partition entries if not specified in validated VTOC */
 93         nparts = (use_vtoc) ? be16_to_cpu(label->vtoc.nparts) : 8;
 94 
 95         /*
 96          * So that old Linux-Sun partitions continue to work,
 97          * alow the VTOC to be used under the additional condition ...
 98          */
 99         use_vtoc = use_vtoc || !(label->vtoc.sanity ||
100                                  label->vtoc.version || label->vtoc.nparts);
101         spc = be16_to_cpu(label->ntrks) * be16_to_cpu(label->nsect);
102         for (i = 0; i < nparts; i++, p++) {
103                 unsigned long st_sector;
104                 unsigned int num_sectors;
105 
106                 st_sector = be32_to_cpu(p->start_cylinder) * spc;
107                 num_sectors = be32_to_cpu(p->num_sectors);
108                 if (num_sectors) {
109                         put_partition(state, slot, st_sector, num_sectors);
110                         state->parts[slot].flags = 0;
111                         if (use_vtoc) {
112                                 if (be16_to_cpu(label->vtoc.infos[i].id) == LINUX_RAID_PARTITION)
113                                         state->parts[slot].flags |= ADDPART_FLAG_RAID;
114                                 else if (be16_to_cpu(label->vtoc.infos[i].id) == SUN_WHOLE_DISK)
115                                         state->parts[slot].flags |= ADDPART_FLAG_WHOLEDISK;
116                         }
117                 }
118                 slot++;
119         }
120         strlcat(state->pp_buf, "\n", PAGE_SIZE);
121         put_dev_sector(sect);
122         return 1;
123 }
124 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp