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