Esempio n. 1
0
int
Xdisk(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
    int offset)
{
	int maxcyl  = 1024;
	int maxhead = 256;
	int maxsec  = 63;

	/* Print out disk info */
	DISK_printgeometry(disk, args);

#if defined (__powerpc__) || defined (__mips__)
	maxcyl  = 9999999;
	maxhead = 9999999;
	maxsec  = 9999999;
#endif

	/* Ask for new info */
	if (ask_yn("Change disk geometry?")) {
		disk->cylinders = ask_num("BIOS Cylinders",
		    disk->cylinders, 1, maxcyl);
		disk->heads = ask_num("BIOS Heads",
		    disk->heads, 1, maxhead);
		disk->sectors = ask_num("BIOS Sectors",
		    disk->sectors, 1, maxsec);

		disk->size = disk->cylinders * disk->heads * disk->sectors;
	}

	return (CMD_CONT);
}
Esempio n. 2
0
File: bxcommit.c Progetto: iver6/BA
int CDECL main()
{
  char filename[256];
  char tmplogname[256];
  char redologname[256];
  int  remove;

  print_banner();
  filename[0] = 0;
  redologname[0] = 0;

  if (ask_string("\nWhat is the flat image name?\n", "c.img", filename) < 0)
    fatal(EOF_ERR);

  snprintf(tmplogname,256,"%s%s", filename, UNDOABLE_REDOLOG_EXTENSION);

  if (ask_string("\nWhat is the redolog name?\n", tmplogname, redologname) < 0)
    fatal(EOF_ERR);

  if (ask_yn("\nShall I remove the redolog afterwards?\n", 1, &remove) < 0)
    fatal(EOF_ERR);

  commit_redolog(filename, redologname);

  if (remove) {
    if (unlink(redologname) != 0)
       fatal("ERROR: while removing the redolog !\n");
  }

  // make picky compilers (c++, gcc) happy,
  // even though we leave via 'myexit' just above
  return 0;
}
Esempio n. 3
0
int
Xwrite(char *args, struct disk *disk, struct mbr *mbr, struct mbr *tt,
    int offset)
{
	struct dos_mbr dos_mbr;
	int fd, i, n;

	for (i = 0, n = 0; i < NDOSPART; i++)
		if (mbr->part[i].id == 0xA6)
			n++;
	if (n >= 2) {
		warnx("MBR contains more than one OpenBSD partition!");
		if (!ask_yn("Write MBR anyway?"))
			return (CMD_CONT);
	}

	fd = DISK_open(disk->name, O_RDWR);
	MBR_make(mbr, &dos_mbr);

	printf("Writing MBR at offset %d.\n", offset);
	if (MBR_write(fd, offset, &dos_mbr) == -1) {
		int saved_errno = errno;
		warn("error writing MBR");
		close(fd);
		errno = saved_errno;
		return (CMD_CONT);
	}
	close(fd);

	/* Refresh in memory copy to reflect what was just written. */
	MBR_parse(disk, &dos_mbr, mbr->offset, mbr->reloffset, mbr);

	return (CMD_CLEAN);
}
Esempio n. 4
0
/* ARGSUSED */
int
Xedit(cmd_t *cmd, disk_t *disk, mbr_t *mbr, mbr_t *tt, int offset)
{
	const char *errstr;
	int pn, num, ret;
	prt_t *pp;

	pn = (int)strtonum(cmd->args, 0, 3, &errstr);
	if (errstr) {
		printf("partition number is %s: %s\n", errstr, cmd->args);
		return (CMD_CONT);
	}
	pp = &mbr->part[pn];

	/* Edit partition type */
	ret = Xsetpid(cmd, disk, mbr, tt, offset);

#define	EDIT(p, v, n, m)					\
	if ((num = ask_num(p, v, n, m)) != v)	\
		ret = CMD_DIRTY;				\
	v = num;

	/* Unused, so just zero out */
	if (pp->id == DOSPTYP_UNUSED) {
		memset(pp, 0, sizeof(*pp));
		printf("Partition %d is disabled.\n", pn);
		return (ret);
	}

	/* Change table entry */
	if (ask_yn("Do you wish to edit in CHS mode?")) {
		int maxcyl, maxhead, maxsect;

		/* Shorter */
		maxcyl = disk->real->cylinders - 1;
		maxhead = disk->real->heads - 1;
		maxsect = disk->real->sectors;

		/* Get data */
		EDIT("BIOS Starting cylinder", pp->scyl,  0, maxcyl);
		EDIT("BIOS Starting head",     pp->shead, 0, maxhead);
		EDIT("BIOS Starting sector",   pp->ssect, 1, maxsect);
		EDIT("BIOS Ending cylinder",   pp->ecyl,  0, maxcyl);
		EDIT("BIOS Ending head",       pp->ehead, 0, maxhead);
		EDIT("BIOS Ending sector",     pp->esect, 1, maxsect);
		/* Fix up off/size values */
		PRT_fix_BN(disk, pp, pn);
		/* Fix up CHS values for LBA */
		PRT_fix_CHS(disk, pp);
	} else {
		pp->bs = getuint(disk, "Partition offset", pp->bs,
		    disk->real->size);
		pp->ns = getuint(disk, "Partition size", pp->ns,
		    disk->real->size - pp->bs);
		/* Fix up CHS values */
		PRT_fix_CHS(disk, pp);
	}
#undef EDIT
	return (ret);
}
Esempio n. 5
0
int bx_write_rc(char *rc)
{
  char oldrc[CI_PATH_LENGTH], newrc[CI_PATH_LENGTH];
  if (rc == NULL) {
    if (SIM->get_default_rc(oldrc, CI_PATH_LENGTH) < 0)
      strcpy(oldrc, "none");
  } else {
    strncpy(oldrc, rc, CI_PATH_LENGTH);
  }
  while (1) {
    if (ask_string("Save configuration to what file?  To cancel, type 'none'.\n[%s] ", oldrc, newrc) < 0) return -1;
    if (!strcmp(newrc, "none")) return 0;
    // try with overwrite off first
    int status = SIM->write_rc(newrc, 0);
    if (status >= 0) {
      fprintf(stderr, "Wrote configuration to '%s'.\n", newrc);
      return 0;
    } else if (status == -2) {
      // return code -2 indicates the file already exists, and overwrite
      // confirmation is required.
      Bit32u overwrite = 0;
      char prompt[256];
      sprintf(prompt, "Configuration file '%s' already exists.  Overwrite it? [no] ", newrc);
      if (ask_yn(prompt, "", 0, &overwrite) < 0) return -1;
      if (!overwrite) continue;  // if "no", start loop over, asking for a different file
      // they confirmed, so try again with overwrite bit set
      if (SIM->write_rc(newrc, 1) >= 0) {
	fprintf(stderr, "Overwriting existing configuration '%s'.\n", newrc);
	return 0;
      } else {
	fprintf(stderr, "Write failed to '%s'.\n", newrc);
      }
    }
  }
}
Esempio n. 6
0
int
USER_init(disk_t *disk, gpt_t *tt)
{
	char *query;

	if (GPT_init(disk, tt) == -ENOMEM)
		return (-ENOMEM);

	if (ask_yn("Do you wish to write new GUID partition table?"))
		Xwrite(NULL, disk, tt, NULL, 0);

	return (0);
}
Esempio n. 7
0
File: 2048.c Progetto: theta43/2048
int
main (void)
{
	bool win_condition = false;
	int ret, ch;

	puts ("Playing 2048 " VERSION " in ASCII mode");

	init_tiles (&game);

	ch = ret = 0;
	do {
		draw_game ();
		printf ("move [wasd]: ");
		fflush (NULL);

		if (ch == 0)
			continue;

		enum tile_dir dir = -1;

		switch (ch) {
		case 'W': dir = UP;	break;
		case 'A': dir = LEFT;	break;
		case 'S': dir = DOWN;	break;
		case 'D': dir = RIGHT;	break;
		default: continue;
		}

		if (move_tiles (&game, dir) == -1)
			break;

		if (game.max_tile == 2048 && !win_condition) {
			win_condition = 1;
			if (!ask_yn ("You won! Do you wish to continue? [Y/n]"))
				break;
		}

	} while ((ch = toupper(getchar())) != EOF);

	destroy_tiles (&game);

	printf ("\nScore: %d\n", game.score);
	if (game.max_tile < 2048) {
		puts ("You lost. Better luck next time\n");
		return 1;
	}

	return 0;
}
Esempio n. 8
0
int ask (e2fsck_t ctx, const char * string, int def)
{
	if (ctx->options & E2F_OPT_NO) {
		log_out(ctx, _("%s? no\n\n"), string);
		return 0;
	}
	if (ctx->options & E2F_OPT_YES) {
		log_out(ctx, _("%s? yes\n\n"), string);
		return 1;
	}
	if (ctx->options & E2F_OPT_PREEN) {
		log_out(ctx, "%s? %s\n\n", string, def ? _("yes") : _("no"));
		return def;
	}
	return ask_yn(ctx, string, def);
}
static void check_mount(e2fsck_t ctx)
{
	errcode_t	retval;
	int		cont;

	retval = ext2fs_check_if_mounted(ctx->filesystem_name,
					 &ctx->mount_flags);
	if (retval) {
		com_err("ext2fs_check_if_mount", retval,
			_("while determining whether %s is mounted."),
			ctx->filesystem_name);
		return;
	}

	/*
	 * If the filesystem isn't mounted, or it's the root
	 * filesystem and it's mounted read-only, and we're not doing
	 * a read/write check, then everything's fine.
	 */
	if ((!(ctx->mount_flags & EXT2_MF_MOUNTED)) ||
	    ((ctx->mount_flags & EXT2_MF_ISROOT) &&
	     (ctx->mount_flags & EXT2_MF_READONLY) &&
	     !(ctx->options & E2F_OPT_WRITECHECK)))
		return;

	if ((ctx->options & E2F_OPT_READONLY) &&
	    !(ctx->options & E2F_OPT_WRITECHECK)) {
		printf(_("Warning!  %s is mounted.\n"), ctx->filesystem_name);
		return;
	}

	printf(_("%s is mounted.  "), ctx->filesystem_name);
	if (!ctx->interactive)
		fatal_error(ctx, _("Cannot continue, aborting.\n\n"));
	printf(_("\n\n\007\007\007\007WARNING!!!  "
	       "The filesystem is mounted.   If you continue you ***WILL***\n"
	       "cause ***SEVERE*** filesystem damage.\007\007\007\n\n"));
	cont = ask_yn(_("Do you really want to continue"), -1);
	if (!cont) {
		printf (_("check aborted.\n"));
		exit (0);
	}
	return;
}
Esempio n. 10
0
int bx_param_bool_c::text_ask(FILE *fpin, FILE *fpout)
{
  fprintf(fpout, "\n");
  int status;
  const char *prompt = get_ask_format();
  const char *help = get_description();
  char buffer[512];
  if (prompt == NULL) {
    if (get_label() != NULL) {
      sprintf(buffer, "%s? [%%s] ", get_label());
      prompt = buffer;
    } else {
      // default prompt, if they didn't set an ask format or label string
      sprintf(buffer, "%s? [%%s] ", get_name());
      prompt = buffer;
    }
  }
  Bit32u n = get();
  status = ask_yn(prompt, help, n, &n);
  if (status < 0) return status;
  set(n);
  return 0;
}
Esempio n. 11
0
int make_image (Bit64u sec, char *filename, WRITE_IMAGE write_image)
{
  FILE *fp;
  char buffer[1024];
 
  // check if it exists before trashing someone's disk image
  fp = fopen (filename, "r");
  if (fp) {
    int confirm;
    sprintf (buffer, "\nThe disk image '%s' already exists.  Are you sure you want to replace it?\nPlease type yes or no. ", filename);
    if (ask_yn (buffer, 0, &confirm) < 0)
      fatal (EOF_ERR);
    if (!confirm)
      fatal ("ERROR: Aborted");
    fclose (fp);
  }

  // okay, now open it for writing
  fp = fopen (filename, "w");
  if (fp == NULL) {
    // attempt to print an error
#ifdef HAVE_PERROR
    sprintf (buffer, "while opening '%s' for writing", filename);
    perror (buffer);
#endif
    fatal ("ERROR: Could not write disk image");
  }

  printf ("\nWriting: [");

  if( (*write_image)(fp, sec) != 0)
     fatal ("ERROR: while writing disk image!");

  printf ("] Done.\n");
  fclose (fp);
  return 0;
}
Esempio n. 12
0
int make_image_win32 (Bit64u sec, char *filename, WRITE_IMAGE_WIN32 write_image)
{
  HANDLE hFile;
  char buffer[1024];

  // check if it exists before trashing someone's disk image
  hFile = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL , NULL);
  if (hFile != INVALID_HANDLE_VALUE) {
    int confirm;
    sprintf (buffer, "\nThe disk image '%s' already exists.  Are you sure you want to replace it?\nPlease type yes or no. ", filename);
    if (ask_yn (buffer, 0, &confirm) < 0)
      fatal (EOF_ERR);
    if (!confirm)
      fatal ("ERROR: Aborted");
    CloseHandle(hFile);
  }

  // okay, now open it for writing
  hFile = CreateFile(filename, GENERIC_WRITE|GENERIC_READ, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  if (hFile == INVALID_HANDLE_VALUE) {
    // attempt to print an error
#ifdef HAVE_PERROR
    sprintf (buffer, "while opening '%s' for writing", filename);
    perror (buffer);
#endif
    fatal ("ERROR: Could not write disk image");
  }

  printf ("\nWriting: [");

  if( (*write_image)(hFile, sec) != 0)
     fatal ("ERROR: while writing disk image!");

  printf ("] Done.\n");
  CloseHandle(hFile);
  return 0;
}