MBR magic exists at the beginning of 'a' partition, BPB is cleared. Avoid to detect msdosfs incorrectly at boot time.diff -r1.10 -r1.11 src/distrib/utils/sysinst/arch/hpcarm/md.c
(nonaka)
--- src/distrib/utils/sysinst/arch/hpcarm/Attic/md.c 2011/04/04 08:30:29 1.10
+++ src/distrib/utils/sysinst/arch/hpcarm/Attic/md.c 2011/06/11 11:43:23 1.11
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: md.c,v 1.10 2011/04/04 08:30:29 mbalmer Exp $ */ | 1 | /* $NetBSD: md.c,v 1.11 2011/06/11 11:43:23 nonaka Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright 1997 Piermont Information Systems Inc. | 4 | * Copyright 1997 Piermont Information Systems Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Based on code written by Philip A. Nelson for Piermont Information | 7 | * Based on code written by Philip A. Nelson for Piermont Information | |
8 | * Systems Inc. | 8 | * Systems Inc. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -138,26 +138,58 @@ md_post_disklabel(void) | @@ -138,26 +138,58 @@ md_post_disklabel(void) | |||
138 | diskdev); | 138 | diskdev); | |
139 | } | 139 | } | |
140 | return 0; | 140 | return 0; | |
141 | } | 141 | } | |
142 | 142 | |||
143 | /* | 143 | /* | |
144 | * hook called after upgrade() or install() has finished setting | 144 | * hook called after upgrade() or install() has finished setting | |
145 | * up the target disk but immediately before the user is given the | 145 | * up the target disk but immediately before the user is given the | |
146 | * ``disks are now set up'' message. | 146 | * ``disks are now set up'' message. | |
147 | */ | 147 | */ | |
148 | int | 148 | int | |
149 | md_post_newfs(void) | 149 | md_post_newfs(void) | |
150 | { | 150 | { | |
151 | struct mbr_sector pbr; | |||
152 | char adevname[STRSIZE]; | |||
153 | ssize_t sz; | |||
154 | int fd = -1; | |||
155 | ||||
156 | snprintf(adevname, sizeof(adevname), "/dev/r%sa", diskdev); | |||
157 | fd = open(adevname, O_RDWR); | |||
158 | if (fd < 0) | |||
159 | goto out; | |||
160 | ||||
161 | /* Read partition boot record */ | |||
162 | sz = pread(fd, &pbr, sizeof(pbr), 0); | |||
163 | if (sz != sizeof(pbr)) | |||
164 | goto out; | |||
165 | ||||
166 | /* Check magic number */ | |||
167 | if (pbr.mbr_magic != le16toh(MBR_MAGIC)) | |||
168 | goto out; | |||
169 | ||||
170 | #define OSNAME "NetBSD60" | |||
171 | /* Update oemname */ | |||
172 | memcpy(&pbr.mbr_oemname, OSNAME, sizeof(OSNAME) - 1); | |||
173 | ||||
174 | /* Clear BPB */ | |||
175 | memset(&pbr.mbr_bpb, 0, sizeof(pbr.mbr_bpb)); | |||
176 | ||||
177 | /* write-backed new patition boot record */ | |||
178 | (void)pwrite(fd, &pbr, sizeof(pbr), 0); | |||
179 | ||||
180 | out: | |||
181 | if (fd >= 0) | |||
182 | close(fd); | |||
151 | return 0; | 183 | return 0; | |
152 | } | 184 | } | |
153 | 185 | |||
154 | int | 186 | int | |
155 | md_post_extract(void) | 187 | md_post_extract(void) | |
156 | { | 188 | { | |
157 | return 0; | 189 | return 0; | |
158 | } | 190 | } | |
159 | 191 | |||
160 | void | 192 | void | |
161 | md_cleanup_install(void) | 193 | md_cleanup_install(void) | |
162 | { | 194 | { | |
163 | #ifndef DEBUG | 195 | #ifndef DEBUG |
--- src/distrib/utils/sysinst/arch/zaurus/Attic/md.c 2011/04/04 08:30:46 1.7
+++ src/distrib/utils/sysinst/arch/zaurus/Attic/md.c 2011/06/11 11:43:23 1.8
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: md.c,v 1.7 2011/04/04 08:30:46 mbalmer Exp $ */ | 1 | /* $NetBSD: md.c,v 1.8 2011/06/11 11:43:23 nonaka Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright 1997 Piermont Information Systems Inc. | 4 | * Copyright 1997 Piermont Information Systems Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Based on code written by Philip A. Nelson for Piermont Information | 7 | * Based on code written by Philip A. Nelson for Piermont Information | |
8 | * Systems Inc. | 8 | * Systems Inc. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -101,26 +101,58 @@ int | @@ -101,26 +101,58 @@ int | |||
101 | md_post_disklabel(void) | 101 | md_post_disklabel(void) | |
102 | { | 102 | { | |
103 | return 0; | 103 | return 0; | |
104 | } | 104 | } | |
105 | 105 | |||
106 | /* | 106 | /* | |
107 | * hook called after upgrade() or install() has finished setting | 107 | * hook called after upgrade() or install() has finished setting | |
108 | * up the target disk but immediately before the user is given the | 108 | * up the target disk but immediately before the user is given the | |
109 | * ``disks are now set up'' message. | 109 | * ``disks are now set up'' message. | |
110 | */ | 110 | */ | |
111 | int | 111 | int | |
112 | md_post_newfs(void) | 112 | md_post_newfs(void) | |
113 | { | 113 | { | |
114 | struct mbr_sector pbr; | |||
115 | char adevname[STRSIZE]; | |||
116 | ssize_t sz; | |||
117 | int fd = -1; | |||
118 | ||||
119 | snprintf(adevname, sizeof(adevname), "/dev/r%sa", diskdev); | |||
120 | fd = open(adevname, O_RDWR); | |||
121 | if (fd < 0) | |||
122 | goto out; | |||
123 | ||||
124 | /* Read partition boot record */ | |||
125 | sz = pread(fd, &pbr, sizeof(pbr), 0); | |||
126 | if (sz != sizeof(pbr)) | |||
127 | goto out; | |||
128 | ||||
129 | /* Check magic number */ | |||
130 | if (pbr.mbr_magic != le16toh(MBR_MAGIC)) | |||
131 | goto out; | |||
132 | ||||
133 | #define OSNAME "NetBSD60" | |||
134 | /* Update oemname */ | |||
135 | memcpy(&pbr.mbr_oemname, OSNAME, sizeof(OSNAME) - 1); | |||
136 | ||||
137 | /* Clear BPB */ | |||
138 | memset(&pbr.mbr_bpb, 0, sizeof(pbr.mbr_bpb)); | |||
139 | ||||
140 | /* write-backed new patition boot record */ | |||
141 | (void)pwrite(fd, &pbr, sizeof(pbr), 0); | |||
142 | ||||
143 | out: | |||
144 | if (fd >= 0) | |||
145 | close(fd); | |||
114 | return 0; | 146 | return 0; | |
115 | } | 147 | } | |
116 | 148 | |||
117 | int | 149 | int | |
118 | md_post_extract(void) | 150 | md_post_extract(void) | |
119 | { | 151 | { | |
120 | return 0; | 152 | return 0; | |
121 | } | 153 | } | |
122 | 154 | |||
123 | void | 155 | void | |
124 | md_cleanup_install(void) | 156 | md_cleanup_install(void) | |
125 | { | 157 | { | |
126 | #ifndef DEBUG | 158 | #ifndef DEBUG |