* updated kollision (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / architecture / powerpc64 / package / linux / 0035-ps3-partition.patch
blobde19b83f90e379ba3042b0619d95436265feb8b9
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by scripts/Create-CopyPatch.
3 #
4 # T2 SDE: architecture/powerpc64/package/.../0035-ps3-partition.patch
5 # Copyright (C) 2019 - 2020 The T2 SDE Project
6 #
7 # More information can be found in the files COPYING and README.
8 #
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 # --- T2-COPYRIGHT-NOTE-END ---
17 --- a/block/partitions/Kconfig
18 +++ b/block/partitions/Kconfig
19 @@ -262,6 +262,12 @@ config SYSV68_PARTITION
20 sysv68).
21 Otherwise, say N.
23 +config PS3_PARTITION
24 + bool "PS3 Partition support"
25 + depends on PARTITION_ADVANCED
26 + help
27 + Say Y here if you would like to use PS3 hard disks under Linux.
29 config CMDLINE_PARTITION
30 bool "Command line partition support" if PARTITION_ADVANCED
31 select BLK_CMDLINE_PARSER
32 --- a/block/partitions/Makefile
33 +++ b/block/partitions/Makefile
34 @@ -21,3 +21,4 @@ obj-$(CONFIG_IBM_PARTITION) += ibm.o
35 obj-$(CONFIG_EFI_PARTITION) += efi.o
36 obj-$(CONFIG_KARMA_PARTITION) += karma.o
37 obj-$(CONFIG_SYSV68_PARTITION) += sysv68.o
38 +obj-$(CONFIG_PS3_PARTITION) += ps3.o
39 --- a/block/partitions/core.c
40 +++ b/block/partitions/core.c
41 @@ -11,6 +11,7 @@
42 #include <linux/blktrace_api.h>
43 #include <linux/raid/detect.h>
44 #include "check.h"
45 +#include "ps3.h"
47 static int (*check_part[])(struct parsed_partitions *) = {
49 @@ -81,6 +82,9 @@ static int (*check_part[])(struct parsed_partitions *) = {
50 #endif
51 #ifdef CONFIG_SYSV68_PARTITION
52 sysv68_partition,
53 +#endif
54 +#ifdef CONFIG_PS3_PARTITION
55 + ps3_partition,
56 #endif
57 NULL
59 --- /dev/null
60 +++ b/block/partitions/ps3.c
61 @@ -0,0 +1,98 @@
62 +/*
63 + * fs/partitions/ps3.c
64 + *
65 + * Copyright (C) 2012 glevand <geoffrey.levand@mail.ru>
66 + */
68 +#include "check.h"
69 +#include "ps3.h"
71 +#define SECTOR_SIZE 512
72 +#define MAX_ACL_ENTRIES 8
73 +#define MAX_PARTITIONS 8
75 +#define MAGIC1 0x0FACE0FFULL
76 +#define MAGIC2 0xDEADFACEULL
78 +struct p_acl_entry {
79 + __be64 laid;
80 + __be64 rights;
81 +};
83 +struct d_partition {
84 + __be64 p_start;
85 + __be64 p_size;
86 + struct p_acl_entry p_acl[MAX_ACL_ENTRIES];
87 +};
89 +struct disklabel {
90 + u8 d_res1[16];
91 + __be64 d_magic1;
92 + __be64 d_magic2;
93 + __be64 d_res2;
94 + __be64 d_res3;
95 + struct d_partition d_partitions[MAX_PARTITIONS];
96 + u8 d_pad[0x600 - MAX_PARTITIONS * sizeof(struct d_partition)- 0x30];
97 +};
99 +static bool ps3_read_disklabel(struct parsed_partitions *state, struct disklabel *label)
101 + Sector sect;
102 + unsigned char *data;
103 + int i;
105 + for (i = 0; i < sizeof(struct disklabel) / SECTOR_SIZE; i++) {
106 + data = read_part_sector(state, i, &sect);
107 + if (!data)
108 + return (false);
110 + memcpy((unsigned char *) label + i * SECTOR_SIZE, data, SECTOR_SIZE);
112 + put_dev_sector(sect);
115 + return (true);
118 +int ps3_partition(struct parsed_partitions *state)
120 + struct disklabel *label = NULL;
121 + int slot = 1;
122 + int result = -1;
123 + int i;
125 + label = kmalloc(sizeof(struct disklabel), GFP_KERNEL);
126 + if (!label)
127 + goto out;
129 + if (!ps3_read_disklabel(state, label))
130 + goto out;
132 + result = 0;
134 + if ((be64_to_cpu(label->d_magic1) != MAGIC1) ||
135 + (be64_to_cpu(label->d_magic2) != MAGIC2))
136 + goto out;
138 + for (i = 0; i < MAX_PARTITIONS; i++) {
139 + if (label->d_partitions[i].p_start && label->d_partitions[i].p_size) {
140 + put_partition(state, slot,
141 + be64_to_cpu(label->d_partitions[i].p_start),
142 + be64_to_cpu(label->d_partitions[i].p_size));
143 + slot++;
147 + strlcat(state->pp_buf, "\n", PAGE_SIZE);
149 + kfree(label);
151 + return (1);
153 +out:
155 + if (label)
156 + kfree(label);
158 + return (result);
160 --- /dev/null
161 +++ b/block/partitions/ps3.h
162 @@ -0,0 +1,5 @@
164 + * fs/partitions/ps3.h
165 + */
167 +int ps3_partition(struct parsed_partitions *state);