#define DEV_FD0 0x200 /* Device number of /dev/fd0 */
#define DEV_C0D0 0x300 /* Device number of /dev/c0d0 */
-#define MIN_REGION_MB 180
+#define MIN_REGION_MB 160
#define MIN_REGION_SECTORS (1024*1024*MIN_REGION_MB/SECTOR_SIZE)
#define MAX_REGION_MB 4095
}
}
-int probing = 0, autopartmode = 0;
+int open_ct_ok(int fd)
+{
+ int c = -1;
+ if(ioctl(fd, DIOCOPENCT, &c) < 0) {
+ printf("Warning: couldn't verify opencount, continuing\n");
+ return 1;
+ }
+
+ if(c == 1) return 1;
+ if(c < 1) { printf("Error: open count %d\n", c); }
+
+ return 0;
+}
void report(const char *label)
{
}
/* Sanity check. */
- if(autopartmode && si > 1) {
+ if(si > 1) {
if(table[i].lowsec < table[sort_order[si-1]].lowsec ||
table[i].lowsec < table[sort_order[si-1]].lowsec + table[sort_order[si-1]].size) {
printf("\nSanity check failed on %s - partitions overlap.\n"
fflush(stdout);
if ((device= open(curdev->name, mode= O_RDWR, 0666)) < 0) {
- stat_start(1);
- if(!probing)
- printf("%s: %s", curdev->name, strerror(errno));
- stat_end(5);
if (device >= 0) { close(device); device= -1; }
return;
}
- if(probing) {
- v = 2*HZ;
- ioctl(device, DIOCTIMEOUT, &v);
- }
+ v = 2*HZ;
+ ioctl(device, DIOCTIMEOUT, &v);
/* Assume up to five lines of kernel messages. */
statusrow+= 5-1;
if (n <= 0) stat_start(1);
if (n < 0) {
- if(!probing)
- printf("%s: %s", curdev->name, strerror(errno));
close(device);
device= -1;
} else
if (n < SECTOR_SIZE) {
- if(probing) {
- close(device);
- device= -1;
- return;
- }
- printf("%s: Unexpected EOF", curdev->subname);
+ close(device);
+ device= -1;
+ return;
}
if (n <= 0) stat_end(5);
if (n < SECTOR_SIZE) n= SECTOR_SIZE;
+ if(!open_ct_ok(device)) {
+ printf("\n%s: device in use! skipping it.", curdev->subname);
+ fflush(stdout);
+ close(device);
+ device= -1;
+ return;
+ }
+
memcpy(table+1, bootblock+PART_TABLE_OFF,
NR_PARTITIONS * sizeof(table[1]));
- for (i= 1; i <= NR_PARTITIONS; i++) {
- if ((table[i].bootind & ~ACTIVE_FLAG) != 0) break;
- }
- if (i <= NR_PARTITIONS || bootblock[510] != 0x55
- || bootblock[511] != 0xAA) {
+ if (bootblock[510] != 0x55 || bootblock[511] != 0xAA) {
/* Invalid boot block, install bootstrap, wipe partition table.
*/
memset(bootblock, 0, sizeof(bootblock));
installboot(bootblock, MASTERBOOT);
memset(table+1, 0, NR_PARTITIONS * sizeof(table[1]));
- stat_start(1);
- if(!probing)
- printf("%s: Invalid partition table (reset)", curdev->subname);
- stat_end(5);
}
/* Fix an extended partition table up to something mere mortals can
return;
}
- if (bootblock[510] != 0x55 || bootblock[511] != 0xAA) {
- /* Invalid boot block, warn user. */
- stat_start(1);
- if(!autopartmode) printf("Warning: About to write a new table on %s",
- curdev->subname);
- stat_end(5);
- }
if (extbase != 0) {
/* Will this stop him? Probably not... */
stat_start(1);
stat_end(5);
}
- if(!autopartmode) {
- stat_start(1);
- putstr("Save partition table? (y/n) ");
- fflush(stdout);
-
- while ((c= getchar()) != 'y' && c != 'n' && c != ctrl('?')) {}
-
- if (c == ctrl('?')) putstr("DEL"); else putchr(c);
- stat_end(5);
- if (c == 'n' && ev == E_WRITE) dirty= 0;
- if (c != 'y') return;
- }
-
memcpy(new_table, table+1, NR_PARTITIONS * sizeof(table[1]));
for (pe= new_table; pe < new_table + NR_PARTITIONS; pe++) {
if (pe->sysind == NO_PART) {
}
printf(" Probing done.\n");
- printf("The following disk%s were found on your system:\n\n", SORNOT(drives));
+ printf("The following disk%s %s found on your system:\n\n", SORNOT(drives),
+ drives == 1 ? "was" : "were");
for(i = 0; i < drives; i++) {
printf(" ");
return 1;
}
+ if(!open_ct_ok(fd)) {
+ printf("Autopart error: the disk is in use. This means that although a\n"
+ "new table has been written, it won't be in use by the system\n"
+ "until it's no longer in use (or a reboot is done). Just in case,\n"
+ "I'm not going to continue.\n\n");
+ return 1;
+ }
+
close(fd);
it_lowsec = div64u(part.base, SECTOR_SIZE);
int region, disk;
nordonly = 1;
- probing = 1;
- autopartmode = 1;
do {
curdev = select_disk();
{
int r, timeout, prev;
- if(m->m_type != DEV_IOCTL || m->REQUEST != DIOCTIMEOUT) {
+ if(m->m_type != DEV_IOCTL ) {
return EINVAL;
}
- if((r=sys_datacopy(m->PROC_NR, (vir_bytes)m->ADDRESS,
- SELF, (vir_bytes)&timeout, sizeof(timeout))) != OK)
- return r;
-
- if(timeout == 0) {
- /* Restore defaults. */
- timeout_ticks = DEF_TIMEOUT_TICKS;
- max_errors = MAX_ERRORS;
- wakeup_ticks = WAKEUP;
- w_silent = 0;
- } else if(timeout < 0) {
- return EINVAL;
- } else {
- prev = wakeup_ticks;
-
- if(!w_standard_timeouts) {
- /* Set (lower) timeout, lower error
- * tolerance and set silent mode.
- */
- wakeup_ticks = timeout;
- max_errors = 3;
- w_silent = 1;
-
- if(timeout_ticks > timeout)
- timeout_ticks = timeout;
+ if(m->REQUEST == DIOCTIMEOUT) {
+ if((r=sys_datacopy(m->PROC_NR, (vir_bytes)m->ADDRESS,
+ SELF, (vir_bytes)&timeout, sizeof(timeout))) != OK)
+ return r;
+
+ if(timeout == 0) {
+ /* Restore defaults. */
+ timeout_ticks = DEF_TIMEOUT_TICKS;
+ max_errors = MAX_ERRORS;
+ wakeup_ticks = WAKEUP;
+ w_silent = 0;
+ } else if(timeout < 0) {
+ return EINVAL;
+ } else {
+ prev = wakeup_ticks;
+
+ if(!w_standard_timeouts) {
+ /* Set (lower) timeout, lower error
+ * tolerance and set silent mode.
+ */
+ wakeup_ticks = timeout;
+ max_errors = 3;
+ w_silent = 1;
+
+ if(timeout_ticks > timeout)
+ timeout_ticks = timeout;
+ }
+
+ if((r=sys_datacopy(SELF, (vir_bytes)&prev,
+ m->PROC_NR, (vir_bytes)m->ADDRESS, sizeof(prev))) != OK)
+ return r;
}
-
- if((r=sys_datacopy(SELF, (vir_bytes)&prev,
- m->PROC_NR, (vir_bytes)m->ADDRESS, sizeof(prev))) != OK)
+
+ return OK;
+ } else if(m->REQUEST == DIOCOPENCT) {
+ int count;
+ if(w_prepare(m->DEVICE) == NIL_DEV) return ENXIO;
+ count = w_wn->open_ct;
+ if((r=sys_datacopy(SELF, (vir_bytes)&count,
+ m->PROC_NR, (vir_bytes)m->ADDRESS, sizeof(count))) != OK)
return r;
+ return OK;
}
-
- return OK;
+ return EINVAL;
}