355a6cb933c1a09bf3bd1b2b6e6aad0440b6beaf
[platform/upstream/multipath-tools.git] / kpartx / solaris.c
1 #include "kpartx.h"
2 #include <stdio.h>
3 #include <sys/types.h>
4 #include <time.h>               /* time_t */
5
6 #define SOLARIS_X86_NUMSLICE    8
7 #define SOLARIS_X86_VTOC_SANE   (0x600DDEEEUL)
8
9 //typedef int daddr_t;          /* or long - check */
10
11 struct solaris_x86_slice {
12         unsigned short  s_tag;          /* ID tag of partition */
13         unsigned short  s_flag;         /* permision flags */
14         daddr_t         s_start;        /* start sector no of partition */
15         long            s_size;         /* # of blocks in partition */
16 };
17
18 struct solaris_x86_vtoc {
19         unsigned long v_bootinfo[3];    /* info for mboot */
20         unsigned long v_sanity;         /* to verify vtoc sanity */
21         unsigned long v_version;        /* layout version */
22         char    v_volume[8];            /* volume name */
23         unsigned short  v_sectorsz;     /* sector size in bytes */
24         unsigned short  v_nparts;       /* number of partitions */
25         unsigned long v_reserved[10];   /* free space */
26         struct solaris_x86_slice
27                 v_slice[SOLARIS_X86_NUMSLICE];   /* slice headers */
28         time_t  timestamp[SOLARIS_X86_NUMSLICE]; /* timestamp */
29         char    v_asciilabel[128];      /* for compatibility */
30 };
31
32 int
33 read_solaris_pt(int fd, struct slice all, struct slice *sp, int ns) {
34         struct solaris_x86_vtoc *v;
35         struct solaris_x86_slice *s;
36         unsigned int offset = all.start;
37         int i, n;
38         char *bp;
39
40         bp = getblock(fd, offset+1);    /* 1 sector suffices */
41         if (bp == NULL)
42                 return -1;
43
44         v = (struct solaris_x86_vtoc *) bp;
45         if(v->v_sanity != SOLARIS_X86_VTOC_SANE)
46                 return -1;
47
48         if(v->v_version != 1) {
49                 fprintf(stderr, "Cannot handle solaris version %ld vtoc\n",
50                        v->v_version);
51                 return 0;
52         }
53
54         for(i=0, n=0; i<SOLARIS_X86_NUMSLICE; i++) {
55                 s = &v->v_slice[i];
56
57                 if (s->s_size == 0)
58                         continue;
59                 if (n < ns) {
60                         sp[n].start = offset + s->s_start;
61                         sp[n].size = s->s_size;
62                         n++;
63                 } else {
64                         fprintf(stderr,
65                                 "solaris_x86_partition: too many slices\n");
66                         break;
67                 }
68         }
69         return n;
70 }