fsutils.c (e5d31070) | fsutils.c (422ee277) |
---|---|
1/*************************************************************************** 2 * 3 * fsutils.c : filesystem utilities 4 * | 1/*************************************************************************** 2 * 3 * fsutils.c : filesystem utilities 4 * |
5 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. | 5 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
6 * Use is subject to license terms. 7 * 8 * Licensed under the Academic Free License version 2.1 9 * 10 **************************************************************************/ 11 12#pragma ident "%Z%%M% %I% %E% SMI" 13 --- 93 unchanged lines hidden (view full) --- 107}; 108 109enum { WALK_CONTINUE, WALK_TERMINATE }; 110 111/* 112 * Walk partition tables and invoke a callback for each. 113 */ 114static void | 6 * Use is subject to license terms. 7 * 8 * Licensed under the Academic Free License version 2.1 9 * 10 **************************************************************************/ 11 12#pragma ident "%Z%%M% %I% %E% SMI" 13 --- 93 unchanged lines hidden (view full) --- 107}; 108 109enum { WALK_CONTINUE, WALK_TERMINATE }; 110 111/* 112 * Walk partition tables and invoke a callback for each. 113 */ 114static void |
115walk_partitions(int fd, int startsec, int (*f)(void *, int, int, int), 116 void *arg) | 115walk_partitions(int fd, int startsec, uint_t secsz, 116 int (*f)(void *, int, int, int), void *arg) |
117{ 118 uint32_t buf[1024/4]; 119 int bufsize = 1024; 120 struct mboot *mboot = (struct mboot *)&buf[0]; 121 struct ipart ipart[FD_NUMPART]; 122 int sec = startsec; 123 int lastsec = sec + 1; 124 int relsect; 125 int ext = 0; 126 int systid; 127 boolean_t valid; 128 int i; 129 130 while (sec != lastsec) { | 117{ 118 uint32_t buf[1024/4]; 119 int bufsize = 1024; 120 struct mboot *mboot = (struct mboot *)&buf[0]; 121 struct ipart ipart[FD_NUMPART]; 122 int sec = startsec; 123 int lastsec = sec + 1; 124 int relsect; 125 int ext = 0; 126 int systid; 127 boolean_t valid; 128 int i; 129 130 while (sec != lastsec) { |
131 if (pread(fd, buf, bufsize, (off_t)sec * 512) != bufsize) { | 131 if (pread(fd, buf, bufsize, (off_t)sec * secsz) != bufsize) { |
132 break; 133 } 134 lastsec = sec; 135 if (ltohs(mboot->signature) != MBB_MAGIC) { 136 break; 137 } 138 bcopy(mboot->parts, ipart, FD_NUMPART * sizeof (struct ipart)); 139 --- 37 unchanged lines hidden (view full) --- 177 return (WALK_CONTINUE); 178} 179 180/* 181 * Given a dos drive number, return its relative sector number, 182 * number of sectors in partition and the system id. 183 */ 184boolean_t | 132 break; 133 } 134 lastsec = sec; 135 if (ltohs(mboot->signature) != MBB_MAGIC) { 136 break; 137 } 138 bcopy(mboot->parts, ipart, FD_NUMPART * sizeof (struct ipart)); 139 --- 37 unchanged lines hidden (view full) --- 177 return (WALK_CONTINUE); 178} 179 180/* 181 * Given a dos drive number, return its relative sector number, 182 * number of sectors in partition and the system id. 183 */ 184boolean_t |
185find_dos_drive(int fd, int num, int *relsect, int *numsect, int *systid) | 185find_dos_drive(int fd, int num, uint_t secsz, off_t *offset) |
186{ 187 struct part_find_s p = { 0, 0, 0, 0, 0, 0 }; 188 189 p.num = num; 190 191 if (num > 0) { | 186{ 187 struct part_find_s p = { 0, 0, 0, 0, 0, 0 }; 188 189 p.num = num; 190 191 if (num > 0) { |
192 walk_partitions(fd, 0, find_dos_drive_cb, &p); | 192 walk_partitions(fd, 0, secsz, find_dos_drive_cb, &p); |
193 if (p.count == num) { | 193 if (p.count == num) { |
194 *relsect = p.r_relsect; 195 *numsect = p.r_numsect; 196 *systid = p.r_systid; | 194 *offset = (off_t)p.r_relsect * secsz; |
197 return (B_TRUE); 198 } 199 } 200 201 return (B_FALSE); 202} 203 204static int 205get_num_dos_drives_cb(void *arg, int systid, int relsect, int numsect) 206{ 207 if (is_dos_drive(systid)) { 208 (*(int *)arg)++; 209 } 210 return (WALK_CONTINUE); 211} 212 213int | 195 return (B_TRUE); 196 } 197 } 198 199 return (B_FALSE); 200} 201 202static int 203get_num_dos_drives_cb(void *arg, int systid, int relsect, int numsect) 204{ 205 if (is_dos_drive(systid)) { 206 (*(int *)arg)++; 207 } 208 return (WALK_CONTINUE); 209} 210 211int |
214get_num_dos_drives(int fd) | 212get_num_dos_drives(int fd, uint_t secsz) |
215{ 216 int count = 0; 217 | 213{ 214 int count = 0; 215 |
218 walk_partitions(fd, 0, get_num_dos_drives_cb, &count); | 216 walk_partitions(fd, 0, secsz, get_num_dos_drives_cb, &count); |
219 220 return (count); 221} 222 223/* 224 * Return true if all non-empty slices in vtoc have identical start/size and 225 * are tagged backup/entire disk. 226 */ --- 26 unchanged lines hidden --- | 217 218 return (count); 219} 220 221/* 222 * Return true if all non-empty slices in vtoc have identical start/size and 223 * are tagged backup/entire disk. 224 */ --- 26 unchanged lines hidden --- |