コード例 #1
0
ファイル: fn_disk.c プロジェクト: mihaicarabas/dragonfly
void
fn_format_msdos_floppy(struct i_fn_args *a)
{
	struct commands *cmds;

	switch (dfui_be_present_dialog(a->c, _("Format MSDOS Floppy"),
	    _("Format Floppy|Return to Utilities Menu"),
	    _("Please insert the floppy to be formatted "
	    "in unit 0 (``drive A:'')."))) {
	case 1:
		cmds = commands_new();
		command_add(cmds, "%s%s -y -f 1440 /dev/fd0",
		    a->os_root, cmd_name(a, "FDFORMAT"));
		command_add(cmds, "%s%s -f 1440 fd0",
		    a->os_root, cmd_name(a, "NEWFS_MSDOS"));
		if (commands_execute(a, cmds))
			inform(a->c, _("Floppy successfully formatted!"));
		else
			inform(a->c, _("Floppy was not successfully formatted."));
		break;
	case 2:
		return;
	default:
		abort_backend();
	}
}
コード例 #2
0
ファイル: fn_diagnostic.c プロジェクト: Key4ce/bsdinstaller
void 
fn_show_dmesg(struct i_fn_args *a)
{
	struct aura_buffer *e;
	struct dfui_form *f;
	struct dfui_response *r;

	e = aura_buffer_new(1024);
	aura_buffer_cat_file(e, "%s%s", a->os_root, cmd_name(a, "DMESG_BOOT"));

	f = dfui_form_create(
	    "dmesg",
	    _("System Startup Messages (dmesg)"),
	    aura_buffer_buf(e),
	    "",

	    "p", "role", "informative",
	    "p", "minimum_width", "72",
	    "p", "monospaced", "true",

	    "a", "ok", _("OK"), "", "",
	    "p", "accelerator", "ESC",

	    NULL
	);

	if (!dfui_be_present(a->c, f, &r))
		abort_backend();

	dfui_form_free(f);
	dfui_response_free(r);

	aura_buffer_free(e);
}
コード例 #3
0
ファイル: mount.c プロジェクト: AhmadTux/DragonFlyBSD
/*
 * Unmount all mountpoints under a given mountpoint in order (e.g. /var/tmp is
 * unmounted before /var).
 */
void
unmount_all_under(struct i_fn_args *a, struct commands *cmds, const char *fmt, ...)
{
	struct statfs *mt_array;
	int count, i;
	char *mtpt;
	va_list args;

	va_start(args, fmt);
	vasprintf(&mtpt, fmt, args);
	va_end(args);

	count = getmntinfo(&mt_array, MNT_WAIT);

	/* Order mount points in reverse lexicographically order. */
	qsort((void*)mt_array, count, sizeof(struct statfs), compare);

	for (i = 0; i < count; i++) {
		if (strncmp(mtpt, mt_array[i].f_mntonname, strlen(mtpt)) != 0)
			continue;
		if (strlen(mtpt) > strlen(mt_array[i].f_mntonname))
			continue;

		command_add(cmds, "%s%s %s",
		    a->os_root, cmd_name(a, "UMOUNT"), mt_array[i].f_mntonname);
	}

	free(mtpt);
}
コード例 #4
0
ファイル: fn_disk.c プロジェクト: mihaicarabas/dragonfly
static void
ask_to_wipe_boot_sector(struct i_fn_args *a, struct commands *fcmds)
{
	struct commands *cmds;
	struct command *cmd;
	char *disk;

	for (cmd = command_get_first(fcmds); cmd != NULL;
	     cmd = command_get_next(cmd)) {
		disk = command_get_tag(cmd);
		if (disk != NULL &&
		    command_get_result(cmd) > 0 &&
		    command_get_result(cmd) < 256) {
			switch (dfui_be_present_dialog(a->c,
			    _("Bootblock Install Failed"),
			    _("Re-Initialize Bootblock|Cancel"),
			    _("Warning: bootblocks were not successfully "
			    "installed on the disk `%s'. This may be "
			    "because the disk is new and not yet "
			    "formatted. If this is the case, it might "
			    "help to re-initialize the boot sector, "
			    "then try installing the bootblock again. "
			    "Note that this should not affect the "
			    "partition table of the disk."),
			    disk)) {
			case 1:
				cmds = commands_new();
				command_add(cmds,
				    "%s%s | %s%s -B /dev/%s",
				    a->os_root, cmd_name(a, "YES"),
				    a->os_root, cmd_name(a, "FDISK"),
				    disk);
				if (commands_execute(a, cmds)) {
					inform(a->c, _("Boot sector successfully initialized."));
				} else {
					inform(a->c, _("Some errors occurred. "
					    "Boot sector was not successfully initialized."));
				}
				commands_free(cmds);
				break;
			default:
				break;
			}
		}
	}
}
コード例 #5
0
/*
 * state_create_subpartitions: let the user specify what subpartitions they
 * want on the disk, how large each should be, and where it should be mounted.
 */
void
state_create_subpartitions(struct i_fn_args *a)
{
	struct commands *cmds;

	if (measure_activated_swap_from_slice(a, storage_get_selected_disk(a->s),
	    storage_get_selected_slice(a->s)) > 0) {
		if (swapoff_all(a) == NULL) {
			inform(a->c, _("Warning: swap could not be turned off."));
			state = disk_get_formatted(storage_get_selected_disk(a->s)) ?
			    state_select_disk : state_select_slice;
			return;
		}
	}

	cmds = commands_new();

	/*
	 * Auto-disklabel the slice.
	 * NB: one cannot use "/dev/adXsY" here -
	 * it must be in the form "adXsY".
	 */
	command_add(cmds, "%s%s -W %s",
	    a->os_root, cmd_name(a, "DISKLABEL64"),
	    slice_get_device_name(storage_get_selected_slice(a->s)));
	command_add(cmds, "%s%s if=/dev/zero of=/dev/%s bs=32k count=16",
	    a->os_root, cmd_name(a, "DD"),
	    slice_get_device_name(storage_get_selected_slice(a->s)));
	command_add(cmds, "%s%s -B -r -w %s auto",
	    a->os_root, cmd_name(a, "DISKLABEL64"),
	    slice_get_device_name(storage_get_selected_slice(a->s)));
	commands_execute(a, cmds);
	commands_free(cmds);

	if (use_hammer)
		fn_create_subpartitions_hammer(a);
	else
		fn_create_subpartitions_ufs(a);

	if (a->result) {
		state = state_install_os;
	} else {
		state = disk_get_formatted(storage_get_selected_disk(a->s)) ?
		    state_select_disk : state_select_slice;
	}
}
コード例 #6
0
ファイル: lp_rast_debug.c プロジェクト: Distrotech/Mesa
static void
do_debug_bin( struct tile *tile,
              const struct cmd_bin *bin,
              int x, int y,
              boolean print_cmds)
{
   unsigned k, j = 0;
   const struct cmd_block *block;

   int tx = x * TILE_SIZE;
   int ty = y * TILE_SIZE;

   memset(tile->data, ' ', sizeof tile->data);
   tile->coverage = 0;
   tile->overdraw = 0;
   tile->state = NULL;

   for (block = bin->head; block; block = block->next) {
      for (k = 0; k < block->count; k++, j++) {
         boolean blend = is_blend(tile->state, block, k);
         char val = get_label(j);
         int count = 0;
            
         if (print_cmds)
            debug_printf("%c: %15s", val, cmd_name(block->cmd[k]));

         if (block->cmd[k] == LP_RAST_OP_SET_STATE)
            tile->state = block->arg[k].state;
         
         if (block->cmd[k] == LP_RAST_OP_CLEAR_COLOR ||
             block->cmd[k] == LP_RAST_OP_CLEAR_ZSTENCIL)
            count = debug_clear_tile(tx, ty, block->arg[k], tile, val);

         if (block->cmd[k] == LP_RAST_OP_SHADE_TILE ||
             block->cmd[k] == LP_RAST_OP_SHADE_TILE_OPAQUE)
            count = debug_shade_tile(tx, ty, block->arg[k], tile, val);

         if (block->cmd[k] == LP_RAST_OP_TRIANGLE_1 ||
             block->cmd[k] == LP_RAST_OP_TRIANGLE_2 ||
             block->cmd[k] == LP_RAST_OP_TRIANGLE_3 ||
             block->cmd[k] == LP_RAST_OP_TRIANGLE_4 ||
             block->cmd[k] == LP_RAST_OP_TRIANGLE_5 ||
             block->cmd[k] == LP_RAST_OP_TRIANGLE_6 ||
             block->cmd[k] == LP_RAST_OP_TRIANGLE_7)
            count = debug_triangle(tx, ty, block->arg[k], tile, val);

         if (print_cmds) {
            debug_printf(" % 5d", count);

            if (blend)
               debug_printf(" blended");
            
            debug_printf("\n");
         }
      }
   }
}
コード例 #7
0
ファイル: fn_disk.c プロジェクト: mihaicarabas/dragonfly
void
fn_create_cdboot_floppy(struct i_fn_args *a)
{
	struct commands *cmds;
	char msg_buf[1][1024];

	snprintf(msg_buf[0], sizeof(msg_buf[0]),
	    "%s cannot be installed from a floppy; "
	    "it must be installed from a booted CD-ROM. "
	    "However, many older systems do not support booting "
	    "from a CD-ROM. For these systems, a boot disk can be "
	    "created. This boot disk contains the Smart Boot "
	    "Manager program, which can boot a CD-ROM even "
	    "on systems with BIOSes which do not support booting "
	    "from the CD-ROM.\n\n"
	    "Smart Boot Manager is not a part of %s; "
	    "the Smart Boot Manager project can be found here:\n\n"
	    "http://btmgr.sourceforge.net/\n\n"
	    "To create a CDBoot floppy, insert a blank floppy "
	    "in unit 0 (``drive A:'') before proceeding."
	    "",
	    OPERATING_SYSTEM_NAME, OPERATING_SYSTEM_NAME);

	switch (dfui_be_present_dialog(a->c, _("Create CDBoot Floppy"),
	    _("Create CDBoot Floppy|Return to Utilities Menu"),
	    "%s", msg_buf[0])) {
	case 1:
		cmds = commands_new();
		command_add(cmds, "%s%s -c %sboot/cdboot.flp.bz2 | "
		    "%s%s of=/dev/fd0 bs=32k",
		    a->os_root, cmd_name(a, "BUNZIP2"),
		    a->os_root,
		    a->os_root, cmd_name(a, "DD"));
		if (commands_execute(a, cmds))
			inform(a->c, _("CDBoot floppy successfully created!"));
		else
			inform(a->c, _("CDBoot floppy was not successfully created."));
		break;
	case 2:
		return;
	default:
		abort_backend();
	}
}
コード例 #8
0
ファイル: binfs.c プロジェクト: AleksandraButrova/embox
static int binfs_mount(void *dev, void *dir) {
	struct node *dir_node = dir;
	const struct cmd *cmd;

	dir_node = dir;

	cmd_foreach(cmd) {
		vfs_subtree_create_child(dir_node, cmd_name(cmd),
				S_IFREG | S_IXUSR | S_IXGRP | S_IXOTH);
	}

	return 0;
}
コード例 #9
0
ファイル: client.c プロジェクト: amonmoce/network-programming
int prompt(int connfd) {

    int r = 0;

    memset(read_buff, 0, SIZE_READ_BUFF); 

    // r = read(connfd, read_buff, SIZE_READ_BUFF);
    r = read_helper(connfd, read_buff);
    if(r == 1)  return COMMAND_HANDLED;

    strcpy(original_read_buff, read_buff);

    argv = command_decode(read_buff);
    if(strcmp(argv[0], "exit") == 0)  return 0;   // same as end
    if(strcmp(argv[0], "setenv") == 0) {
        setenv_helper(connfd);
        return COMMAND_HANDLED;
    }
    if(strcmp(argv[0], "printenv") == 0) {
        printenv_helper(connfd);
        return COMMAND_HANDLED;
    }
    if(strcmp(argv[0], "who") == 0) {
        cmd_who(connfd);
        return COMMAND_HANDLED;
    }
    if(strcmp(argv[0], "name") == 0) {
        cmd_name(connfd, argv[1]);
        return COMMAND_HANDLED;
    }
    if(strcmp(argv[0], "yell") == 0) {
        cmd_yell(connfd, original_read_buff);
        return COMMAND_HANDLED;
    }
    if(strcmp(argv[0], "tell") == 0) {
        cmd_tell(connfd, atoi(argv[1])-1, original_read_buff);
        return COMMAND_HANDLED;
    }

    return r;

}
コード例 #10
0
ファイル: fn_install.c プロジェクト: AhmadTux/DragonFlyBSD
static void
handle_pfs(struct i_fn_args *a, struct commands *cmds)
{
	int j;

	/*
	 * Create PFS root directory.
	 */
	command_add(cmds, "%s%s -p %smnt/pfs",
	    a->os_root, cmd_name(a, "MKDIR"),
	    a->os_root);

	for (j = 0; pfs_mountpt[j] != NULL; j++) {
		/*
		 * We have a PFS for a subdirectory, e.g. /var/crash, so we
		 * need to create /pfs/var.crash
		 */
		if (rindex(pfs_mountpt[j]+1, '/') != NULL) {
			command_add(cmds, "%s%s pfs-master %smnt/pfs%s.%s",
			    a->os_root, cmd_name(a, "HAMMER"),
			    a->os_root, dirname(pfs_mountpt[j]),
			    basename(pfs_mountpt[j]));
			command_add(cmds, "%s%s -p %smnt%s",
			    a->os_root, cmd_name(a, "MKDIR"),
			    a->os_root, pfs_mountpt[j]);
			command_add(cmds, "%s%s %smnt/pfs%s.%s %smnt%s",
			    a->os_root, cmd_name(a, "MOUNT_NULL"),
			    a->os_root, dirname(pfs_mountpt[j]),
			    basename(pfs_mountpt[j]),
			    a->os_root, pfs_mountpt[j]);
		} else {
			command_add(cmds, "%s%s pfs-master %smnt/pfs%s",
			    a->os_root, cmd_name(a, "HAMMER"),
			    a->os_root, pfs_mountpt[j]);
			command_add(cmds, "%s%s -p %smnt%s",
			    a->os_root, cmd_name(a, "MKDIR"),
			    a->os_root, pfs_mountpt[j]);
			command_add(cmds, "%s%s %smnt/pfs%s %smnt%s",
			    a->os_root, cmd_name(a, "MOUNT_NULL"),
			    a->os_root, pfs_mountpt[j],
			    a->os_root, pfs_mountpt[j]);
		}
	}
}
コード例 #11
0
ファイル: lp_rast_debug.c プロジェクト: Distrotech/Mesa
static void
debug_bin( const struct cmd_bin *bin, int x, int y )
{
   const struct lp_rast_state *state = NULL;
   const struct cmd_block *head = bin->head;
   int i, j = 0;

   debug_printf("bin %d,%d:\n", x, y);
                
   while (head) {
      for (i = 0; i < head->count; i++, j++) {
         if (head->cmd[i] == LP_RAST_OP_SET_STATE)
            state = head->arg[i].state;

         debug_printf("%d: %s %s\n", j,
                      cmd_name(head->cmd[i]),
                      is_blend(state, head, i) ? "blended" : "");
      }
      head = head->next;
   }
}
コード例 #12
0
ファイル: fn_disk.c プロジェクト: mihaicarabas/dragonfly
/*
 * Wipes the start of the selected slice.
 */
void
fn_wipe_start_of_slice(struct i_fn_args *a)
{
	struct commands *cmds;

	a->short_desc =
	  _("If you are having problems formatting a primary partition, "
	    "it may be because of junk that has accumulated in the "
	    "partition's `disklabel'. A cure for this is to wipe out "
	    "everything on the first few sectors of the primary partition. "
	    "However, this is a rather drastic action to take, so it is not "
	    "recommended unless you are otherwise encountering problems.");
	a->cancel_desc = _("Return to Utilities Menu");
	fn_select_slice(a);
	if (!a->result)
		return;

	if (confirm_dangerous_action(a->c,
	    _("WARNING!  ALL data in primary partition #%d,\n\n%s\n\non the "
	    "disk\n\n%s\n\n will be IRREVOCABLY ERASED!\n\nAre you "
	    "ABSOLUTELY SURE you wish to take this action?  This is "
	    "your LAST CHANCE to cancel!"),
	    slice_get_number(storage_get_selected_slice(a->s)),
	    slice_get_desc(storage_get_selected_slice(a->s)),
	    disk_get_desc(storage_get_selected_disk(a->s)))) {
		/* XXX check to make sure this slice is not mounted first */
		cmds = commands_new();
		command_add(cmds, "%s%s if=/dev/zero of=/dev/%s bs=32k count=16",
		    a->os_root, cmd_name(a, "DD"),
		    slice_get_device_name(storage_get_selected_slice(a->s)));
		if (commands_execute(a, cmds)) {
			inform(a->c, _("Start of primary partition was successfully wiped."));
		} else {
			inform(a->c, _("Some errors occurred. "
			    "Start of primary partition was not successfully wiped."));
		}
		commands_free(cmds);
	}
}
コード例 #13
0
ファイル: fn_disk.c プロジェクト: mihaicarabas/dragonfly
/*
 * Wipes the start of the selected disk.
 */
void
fn_wipe_start_of_disk(struct i_fn_args *a)
{
	struct commands *cmds;

	a->short_desc = _("If you are having problems formatting a disk, "
	    "it may be because of junk that has accumulated "
	    "in the boot block and the partition table. "
	    "A cure for this is to wipe out everything on "
	    "the first few sectors of the disk.  However, this "
	    "is a rather drastic action to take, so it is not "
	    "recommended unless you are otherwise "
	    "encountering problems.");
	a->cancel_desc = _("Return to Utilities Menu");
	fn_select_disk(a);
	if (!a->result)
		return;

	/* XXX check to make sure no slices on this disk are mounted first? */
	if (storage_get_selected_disk(a->s) != NULL && confirm_dangerous_action(a->c,
	    _("WARNING!  ALL data in ALL partitions on the disk\n\n"
	    "%s\n\nwill be IRREVOCABLY ERASED!\n\nAre you ABSOLUTELY "
	    "SURE you wish to take this action?  This is your "
	    "LAST CHANCE to cancel!"), disk_get_desc(storage_get_selected_disk(a->s)))) {
		cmds = commands_new();
		command_add(cmds,
		    "%s%s if=/dev/zero of=/dev/%s bs=32k count=16",
		    a->os_root, cmd_name(a, "DD"),
		    disk_get_device_name(storage_get_selected_disk(a->s)));
		if (commands_execute(a, cmds)) {
			inform(a->c, _("Start of disk was successfully wiped."));
		} else {
			inform(a->c, _("Some errors occurred. "
			    "Start of disk was not successfully wiped."));
		}
		commands_free(cmds);
	}
}
コード例 #14
0
ファイル: fn_install.c プロジェクト: AhmadTux/DragonFlyBSD
/*
 * fn_install_os: actually put DragonFly on a disk.
 */
void
fn_install_os(struct i_fn_args *a)
{
	struct subpartition *sp;
	struct commands *cmds;
	struct command *cmd;
	int i, seen_it, prefix, j, needcrypt;
	FILE *sources_conf;
	char line[256];
	char cp_src[64][256];
	char file_path[256];
	char *string;
	int lines = 0;

	/*
	 * Read SOURCES_CONF_FILE and populate our copy sources.
	 */
	snprintf(file_path, 256, "%s%s", a->os_root, SOURCES_CONF_FILE);
	sources_conf = fopen(file_path, "r");
	i_log(a, "Reading %s", file_path);
	while(fgets(line, 256, sources_conf) != NULL && lines < 63) {
		if(strlen(line)>0)
			line[strlen(line)-1] = '\0';
		strlcpy(cp_src[lines], line, 256);
		i_log(a,"Adding %s to copy source table.", cp_src[lines]);
		lines++;
	}
	i_log(a,"Added %i total items to copy source table.", lines);
	strcpy(cp_src[lines], "");
	fclose(sources_conf);

	cmds = commands_new();

	/*
	 * If swap isn't mounted yet, mount it.
	 */
	if (measure_activated_swap(a) == 0) {
		for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
		    sp != NULL; sp = subpartition_next(sp)) {
			if (!subpartition_is_swap(sp))
				continue;
			command_add(cmds, "%s%s %sdev/%s",
			    a->os_root,
			    cmd_name(a, "SWAPON"),
			    a->os_root,
			    subpartition_is_encrypted(sp) ?
			    "mapper/swap" : subpartition_get_device_name(sp));
		}
	}

	/*
	 * Unmount anything already mounted on /mnt.
	 */
	unmount_all_under(a, cmds, "%smnt", a->os_root);

	/* Check if crypto support is needed */
	needcrypt = 0;
	for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
	     sp != NULL; sp = subpartition_next(sp)) {
		if (subpartition_is_encrypted(sp)) {
			needcrypt = 1;
			break;
		}
	}

	for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
	     sp != NULL; sp = subpartition_next(sp)) {
		if (strcmp(subpartition_get_mountpoint(sp), "/") == 0) {
			if (use_hammer == 1) {
				command_add(cmds, "%s%s %sdev/%s %smnt%s",
				    a->os_root, cmd_name(a, "MOUNT_HAMMER"),
				    a->os_root,
				    subpartition_is_encrypted(sp) ?
				    "mapper/root" : subpartition_get_device_name(sp),
				    a->os_root,
				    subpartition_get_mountpoint(sp));
			} else {
				command_add(cmds, "%s%s %sdev/%s %smnt%s",
				    a->os_root, cmd_name(a, "MOUNT"),
				    a->os_root,
				    subpartition_get_device_name(sp),
				    a->os_root,
				    subpartition_get_mountpoint(sp));
			}
		}
	}

	/*
	 * Create mount points and mount subpartitions on them.
	 */
	for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
	     sp != NULL; sp = subpartition_next(sp)) {
		if (subpartition_is_swap(sp)) {
			/*
			 * Set this subpartition as the dump device.
			 */
			if (subpartition_get_capacity(sp) < storage_get_memsize(a->s))
				continue;

			command_add(cmds, "%s%s -v %sdev/%s",
			    a->os_root, cmd_name(a, "DUMPON"),
			    a->os_root,
			    subpartition_is_encrypted(sp) ?
			    "mapper/swap" : subpartition_get_device_name(sp));

			asprintf(&string, "/dev/%s",
			    subpartition_is_encrypted(sp) ?
			    "mapper/swap" : subpartition_get_device_name(sp));
			config_var_set(rc_conf, "dumpdev", string);
			free(string);
			continue;
		}

		if (use_hammer == 0) {
			/* / is already mounted */
			if (strcmp(subpartition_get_mountpoint(sp), "/") != 0) {
				command_add(cmds, "%s%s -p %smnt%s",
				    a->os_root, cmd_name(a, "MKDIR"),
				    a->os_root,
				    subpartition_get_mountpoint(sp));
				/* Don't mount it if it's TMPFS-backed. */
				if (subpartition_is_tmpfsbacked(sp))
					continue;
				if (subpartition_is_encrypted(sp)) {
					command_add(cmds, "%s%s %sdev/mapper/%s %smnt%s",
					    a->os_root, cmd_name(a, "MOUNT"),
					    a->os_root,
					    subpartition_get_mountpoint(sp) + 1,
					    a->os_root,
					    subpartition_get_mountpoint(sp));
				} else {
					command_add(cmds, "%s%s %sdev/%s %smnt%s",
					    a->os_root, cmd_name(a, "MOUNT"),
					    a->os_root,
					    subpartition_get_device_name(sp),
					    a->os_root,
					    subpartition_get_mountpoint(sp));
				}
			}
		} else if (strcmp(subpartition_get_mountpoint(sp), "/boot") == 0) {
			command_add(cmds, "%s%s -p %smnt%s",
			    a->os_root, cmd_name(a, "MKDIR"),
			    a->os_root,
			    subpartition_get_mountpoint(sp));
			command_add(cmds, "%s%s %sdev/%s %smnt%s",
			    a->os_root, cmd_name(a, "MOUNT"),
			    a->os_root,
			    subpartition_get_device_name(sp),
			    a->os_root,
			    subpartition_get_mountpoint(sp));
		}
	}

	/*
	 * Take care of HAMMER PFS.
	 */
	if (use_hammer == 1)
		handle_pfs(a, cmds);

	/*
	 * Actually copy files now.
	 */

	for (i = 0; cp_src[i] != NULL && cp_src[i][0] != '\0'; i++) {
		char *src, *dest, *dn, *tmp_dest;

		dest = cp_src[i];

		/*
		 * If dest would be on an TMPFS-backed
		 * mountpoint, don't bother copying it.
		 */
		sp = subpartition_of(storage_get_selected_slice(a->s),
				     "%s%s", a->os_root, &dest[1]);
		if (sp != NULL && subpartition_is_tmpfsbacked(sp)) {
			continue;
		}

		/*
		 * Create intermediate directories, if needed.
		 */
		tmp_dest = aura_strdup(dest);
		dn = dirname(tmp_dest);
		if (is_dir("%s%s", a->os_root, &dn[1]) &&
		    !is_dir("%smnt%s", a->os_root, dn)) {
			command_add(cmds, "%s%s -p %smnt%s",
			    a->os_root, cmd_name(a, "MKDIR"),
			    a->os_root, dn);
		}
		aura_free(tmp_dest, "directory name");

		/*
		 * If a directory by the same name but with the suffix
		 * ".hdd" exists on the installation media, cpdup that
		 * instead.  This is particularly useful with /etc, which
		 * may have significantly different behaviour on the
		 * live CD compared to a standard HDD boot.
		 */
		if (is_dir("%s%s.hdd", a->os_root, &dest[1]))
			asprintf(&src, "%s.hdd", &dest[1]);
		else
			asprintf(&src, "%s", &dest[1]);

		if (is_dir("%s%s", a->os_root, src) || is_file("%s%s", a->os_root, src)) {
			/*
			 * Cpdup the chosen file or directory onto the HDD.
			 * if it exists on the source.
			 */
			cmd = command_add(cmds, "%s%s %s%s %smnt%s",
			    a->os_root, cmd_name(a, "CPDUP"),
			    a->os_root, src,
			    a->os_root, dest);
			command_set_log_mode(cmd, COMMAND_LOG_QUIET);
		}
	}

	/*
	 * Now, because cpdup does not cross mount points,
	 * we must copy anything that the user might've made a
	 * seperate mount point for (e.g. /usr/libdata/lint.)
	 */
	for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
	     sp != NULL; sp = subpartition_next(sp)) {
		/*
		 * If the subpartition is a swap subpartition or an
		 * TMPFS-backed mountpoint, don't try to copy anything
		 * into it.
		 */
		if (subpartition_is_swap(sp) || subpartition_is_tmpfsbacked(sp))
			continue;

		/*
		 * If the mountpoint doesn't even exist on the installation
		 * medium, don't try to copy anything from it!  We assume
		 * it's an empty subpartition for the user's needs.
		 */
		if (!is_dir("%s%s", a->os_root, &subpartition_get_mountpoint(sp)[1]))
			continue;

		/*
		 * Don't bother copying the mountpoint IF:
		 * - we've already said to copy it, or something besides it
		 *   (it's a prefix of something in cp_src); or
		 * - we haven't said to copy it
		 *   (nothing in cp_src is a prefix of it.)
		 */
		seen_it = 0;
		prefix = 0;
		for (i = 0; cp_src[i] != NULL && cp_src[i][0] != '\0'; i++) {
			if (strncmp(subpartition_get_mountpoint(sp), cp_src[i],
			    strlen(subpartition_get_mountpoint(sp))) == 0) {
				seen_it = 1;
				break;
			}
			if (strncmp(cp_src[i], subpartition_get_mountpoint(sp),
			    strlen(cp_src[i])) == 0) {
				prefix = 1;
			}
		}
		if (seen_it || !prefix)
			continue;

		/*
		 * Otherwise, cpdup the subpartition.
		 *
		 * XXX check for .hdd-extended source dirs here, too,
		 * eventually - but for now, /etc.hdd will never be
		 * the kind of tricky sub-mount-within-a-mount-point
		 * that this part of the code is meant to handle.
		 */
		cmd = command_add(cmds, "%s%s %s%s %smnt%s",
		    a->os_root, cmd_name(a, "CPDUP"),
		    a->os_root, &subpartition_get_mountpoint(sp)[1],
		    a->os_root, subpartition_get_mountpoint(sp));
		command_set_log_mode(cmd, COMMAND_LOG_QUIET);
	}

	/*
	 * Create symlinks.
	 */

	/* Take care of /sys. */
	command_add(cmds, "%s%s -s usr/src/sys %smnt/sys",
	    a->os_root, cmd_name(a, "LN"), a->os_root);

	/*
	 * If the user has both /var and /tmp subpartitions,
	 * symlink /var/tmp to /tmp.
	 */
	if (subpartition_find(storage_get_selected_slice(a->s), "/tmp") != NULL &&
	    subpartition_find(storage_get_selected_slice(a->s), "/var") != NULL) {
		command_add(cmds, "%s%s 1777 %smnt/tmp",
		    a->os_root, cmd_name(a, "CHMOD"), a->os_root);
		command_add(cmds, "%s%s -rf %smnt/var/tmp",
		    a->os_root, cmd_name(a, "RM"), a->os_root);
		command_add(cmds, "%s%s -s /tmp %smnt/var/tmp",
		    a->os_root, cmd_name(a, "LN"), a->os_root);
	}

	/*
	 * If the user has /var, but no /tmp,
	 * symlink /tmp to /var/tmp.
	 */
	if (subpartition_find(storage_get_selected_slice(a->s), "/tmp") == NULL &&
	    subpartition_find(storage_get_selected_slice(a->s), "/var") != NULL) {
		command_add(cmds, "%s%s -rf %smnt/tmp",
		    a->os_root, cmd_name(a, "RM"), a->os_root);
		command_add(cmds, "%s%s -s /var/tmp %smnt/tmp",
		    a->os_root, cmd_name(a, "LN"), a->os_root);
	}

	/*
	 * If the user has /usr, but no /home,
	 * symlink /home to /usr/home.
	 */
	if (subpartition_find(storage_get_selected_slice(a->s), "/home") == NULL &&
	    subpartition_find(storage_get_selected_slice(a->s), "/usr") != NULL) {
		command_add(cmds, "%s%s -rf %smnt/home",
		    a->os_root, cmd_name(a, "RM"), a->os_root);
		command_add(cmds, "%s%s %smnt/usr/home",
		    a->os_root, cmd_name(a, "MKDIR"), a->os_root);
		command_add(cmds, "%s%s -s /usr/home %smnt/home",
		    a->os_root, cmd_name(a, "LN"), a->os_root);
	}

	/*
	 * XXX check for other possible combinations too?
	 */

	/*
	 * Clean up.  In case some file didn't make it, use rm -f
	 */
	command_add(cmds, "%s%s -f %smnt/boot/loader.conf",
	    a->os_root, cmd_name(a, "RM"), a->os_root);
	command_add(cmds, "%s%s -f %smnt/tmp/install.log",
	    a->os_root, cmd_name(a, "RM"), a->os_root);
	command_add(cmds, "%s%s -f %smnt/tmp/t[12]",
	    a->os_root, cmd_name(a, "RM"), a->os_root);
	command_add(cmds, "%s%s -f %smnt/tmp/test_in",
	    a->os_root, cmd_name(a, "RM"), a->os_root);
	command_add(cmds, "%s%s -f %smnt/tmp/test_out",
	    a->os_root, cmd_name(a, "RM"), a->os_root);

	/*
	 * Copy pristine versions over any files we might have installed.
	 * This allows the resulting file tree to be customized.
	 */
	for (i = 0; cp_src[i] != NULL && cp_src[i][0] != '\0'; i++) {
		char *src, *dest, *dn, *tmp_dest;

		src = cp_src[i];
		dest = cp_src[i];

		/*
		 * Get the directory that the desired thing to
		 * copy resides in.
		 */
		tmp_dest = aura_strdup(dest);
		dn = dirname(tmp_dest);

		/*
		 * If this dir doesn't exist in PRISTINE_DIR
		 * on the install media, just skip it.
		 */
		if (!is_dir("%s%s%s", a->os_root, PRISTINE_DIR, dn)) {
			aura_free(tmp_dest, _("directory name"));
			continue;
		}

		/*
		 * Create intermediate directories, if needed.
		 */
		if (!is_dir("%smnt%s", a->os_root, dn)) {
			command_add(cmds, "%s%s -p %smnt%s",
			    a->os_root, cmd_name(a, "MKDIR"),
			    a->os_root, dn);
		}
		aura_free(tmp_dest, "directory name");

		/*
		 * Cpdup the chosen file or directory onto the HDD.
		 */
		cmd = command_add(cmds, "%s%s %s%s %smnt%s",
		    a->os_root, cmd_name(a, "CPDUP"),
		    a->os_root, src,
		    a->os_root, dest);

		cmd = command_add(cmds,
		    "%s%s %s%s%s %smnt%s",
		    a->os_root, cmd_name(a, "CPDUP"),
		    a->os_root, PRISTINE_DIR, src,
		    a->os_root, dest);
		command_set_log_mode(cmd, COMMAND_LOG_QUIET);
	}

	/*
	 * Rebuild the user database, to get rid of any extra users
	 * from the LiveCD that aren't supposed to be installed
	 * (copying a pristine master.passwd isn't enough.)
	 */
	command_add(cmds, "%s%s -p -d %smnt/etc %smnt/etc/master.passwd",
	    a->os_root, cmd_name(a, "PWD_MKDB"), a->os_root, a->os_root);

	/* Create missing directories. */
	command_add(cmds, "%s%s %smnt/proc",
	    a->os_root, cmd_name(a, "MKDIR"), a->os_root);
	command_add(cmds, "%s%s %smnt/mnt",
	    a->os_root, cmd_name(a, "MKDIR"), a->os_root);

	/* Write new fstab. */
	command_add(cmds, "%s%s '%s' >%smnt/etc/fstab",
	    a->os_root, cmd_name(a, "ECHO"),
	    "# Device\t\tMountpoint\tFStype\tOptions\t\tDump\tPass#",
	    a->os_root);

	for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
	     sp != NULL; sp = subpartition_next(sp)) {
		if (strcmp(subpartition_get_mountpoint(sp), "swap") == 0) {
			command_add(cmds, "%s%s '/dev/%s\t\tnone\t\tswap\tsw\t\t0\t0' >>%smnt/etc/fstab",
			    a->os_root, cmd_name(a, "ECHO"),
			    subpartition_is_encrypted(sp) ?
			    "mapper/swap" : subpartition_get_device_name(sp),
			    a->os_root);
			if (subpartition_is_encrypted(sp)) {
				command_add(cmds,
				    "%s%s 'swap\t/dev/%s\tnone\tnone' >>%smnt/etc/crypttab",
				    a->os_root, cmd_name(a, "ECHO"),
				    subpartition_get_device_name(sp),
				    a->os_root);
			}
		} else if (use_hammer == 0) {
			if (strcmp(subpartition_get_mountpoint(sp), "/") == 0) {
				command_add(cmds, "%s%s '/dev/%s\t\t%s\t\tufs\trw\t\t1\t1' >>%smnt/etc/fstab",
				    a->os_root, cmd_name(a, "ECHO"),
				    subpartition_get_device_name(sp),
				    subpartition_get_mountpoint(sp),
				    a->os_root);
			} else if (subpartition_is_tmpfsbacked(sp)) {
				command_add(cmds, "%s%s 'tmpfs\t\t\t%s\t\ttmpfs\trw,-s%luM\t1\t1' >>%smnt/etc/fstab",
				    a->os_root, cmd_name(a, "ECHO"),
				    subpartition_get_mountpoint(sp),
				    subpartition_get_capacity(sp),
				    a->os_root);
			} else if (subpartition_is_encrypted(sp)) {
				command_add(cmds, "%s%s '%s\t/dev/%s\tnone\tnone' >>%smnt/etc/crypttab",
				    a->os_root, cmd_name(a, "ECHO"),
				    subpartition_get_mountpoint(sp) + 1,
				    subpartition_get_device_name(sp),
				    a->os_root);
				command_add(cmds, "%s%s '/dev/mapper/%s\t\t%s\t\tufs\trw\t\t2\t2' >>%smnt/etc/fstab",
				    a->os_root, cmd_name(a, "ECHO"),
				    subpartition_get_mountpoint(sp) + 1,
				    subpartition_get_mountpoint(sp),
				    a->os_root);
			} else {
				command_add(cmds, "%s%s '/dev/%s\t\t%s\t\tufs\trw\t\t2\t2' >>%smnt/etc/fstab",
				    a->os_root, cmd_name(a, "ECHO"),
				    subpartition_get_device_name(sp),
				    subpartition_get_mountpoint(sp),
				    a->os_root);
			}
		} else {
			if (strcmp(subpartition_get_mountpoint(sp), "/") == 0) {
				command_add(cmds, "%s%s '/dev/%s\t\t%s\t\thammer\trw\t\t1\t1' >>%smnt/etc/fstab",
				    a->os_root, cmd_name(a, "ECHO"),
				    subpartition_get_device_name(sp),
				    subpartition_get_mountpoint(sp),
				    a->os_root);
				if (subpartition_is_encrypted(sp)) {
					command_add(cmds,
					    "%s%s 'vfs.root.mountfrom=\"ufs:md0s0\"' >>%smnt/boot/loader.conf",
					    a->os_root, cmd_name(a, "ECHO"),
					    a->os_root);
					command_add(cmds,
					    "%s%s 'vfs.root.realroot=\"crypt:hammer:%s:root\"' >>%smnt/boot/loader.conf",
					    a->os_root, cmd_name(a, "ECHO"),
					    subpartition_get_device_name(sp),
					    a->os_root);
				} else {
					command_add(cmds,
					    "%s%s 'vfs.root.mountfrom=\"hammer:%s\"' >>%smnt/boot/loader.conf",
					    a->os_root, cmd_name(a, "ECHO"),
					    subpartition_get_device_name(sp),
					    a->os_root);
				}
			} else if (strcmp(subpartition_get_mountpoint(sp), "/boot") == 0) {
				command_add(cmds, "%s%s '/dev/%s\t\t%s\t\tufs\trw\t\t1\t1' >>%smnt/etc/fstab",
				    a->os_root, cmd_name(a, "ECHO"),
				    subpartition_get_device_name(sp),
				    subpartition_get_mountpoint(sp),
				    a->os_root);
			}
		}
	}

	/*
	 * Take care of HAMMER PFS null mounts.
	 */
	if (use_hammer == 1) {
		for (j = 0; pfs_mountpt[j] != NULL; j++) {
			if (rindex(pfs_mountpt[j]+1, '/') != NULL)
				command_add(cmds, "%s%s '/pfs%s.%s\t%s\t\tnull\trw\t\t0\t0' >>%smnt/etc/fstab",
				    a->os_root, cmd_name(a, "ECHO"),
				    dirname(pfs_mountpt[j]),
				    basename(pfs_mountpt[j]),
				    pfs_mountpt[j],
				    a->os_root);
			else
				command_add(cmds, "%s%s '/pfs%s\t\t%s\t\tnull\trw\t\t0\t0' >>%smnt/etc/fstab",
				    a->os_root, cmd_name(a, "ECHO"),
				    pfs_mountpt[j],
				    pfs_mountpt[j],
				    a->os_root);
		}
	}

	command_add(cmds, "%s%s '%s' >>%smnt/etc/fstab",
	    a->os_root, cmd_name(a, "ECHO"),
	    "proc\t\t\t/proc\t\tprocfs\trw\t\t0\t0",
	    a->os_root);

	/* Backup the disklabel and the log. */
	command_add(cmds, "%s%s %s > %smnt/etc/disklabel.%s",
	    a->os_root, cmd_name(a, "DISKLABEL64"),
	    slice_get_device_name(storage_get_selected_slice(a->s)),
	    a->os_root,
	    slice_get_device_name(storage_get_selected_slice(a->s)));

	/* 'chflags nohistory' as needed */
	for (j = 0; pfs_mountpt[j] != NULL; j++)
		if (pfs_nohistory[j] == 1)
			command_add(cmds, "%s%s -R nohistory %smnt%s",
			    a->os_root, cmd_name(a, "CHFLAGS"),
			    a->os_root, pfs_mountpt[j]);

	command_add(cmds, "%s%s %sinstall.log %smnt/var/log/install.log",
	    a->os_root, cmd_name(a, "CP"),
	    a->tmp, a->os_root);
	command_add(cmds, "%s%s 600 %smnt/var/log/install.log",
	    a->os_root, cmd_name(a, "CHMOD"), a->os_root);

	/* Do some preparation if encrypted partitions were configured */
	if (needcrypt) {
		command_add(cmds,
		    "%s%s 'dm_load=\"yes\"' >>%smnt/boot/loader.conf",
		    a->os_root, cmd_name(a, "ECHO"),
		    a->os_root);
		command_add(cmds,
		    "%s%s 'dm_target_crypt_load=\"yes\"' >>%smnt/boot/loader.conf",
		    a->os_root, cmd_name(a, "ECHO"),
		    a->os_root);
		if (use_hammer) {
			command_add(cmds, "%s%s -b %smnt/boot -t %smnt/tmp",
			    a->os_root, cmd_name(a, "MKINITRD"),
			    a->os_root, a->os_root);
			command_add(cmds, "%s%s -rf %smnt/tmp/initrd",
			    a->os_root, cmd_name(a, "RM"), a->os_root);
			command_add(cmds,
			    "%s%s 'initrd.img_load=\"YES\"' >>%smnt/boot/loader.conf",
			    a->os_root, cmd_name(a, "ECHO"),
			    a->os_root);
			command_add(cmds,
			    "%s%s 'initrd.img_type=\"md_image\"' >>%smnt/boot/loader.conf",
			    a->os_root, cmd_name(a, "ECHO"),
			    a->os_root);
		}
	}

	/* Customize stuff here */
	if(is_file("%susr/local/bin/after_installation_routines.sh", a->os_root)) {
		command_add(cmds, "%susr/local/bin/after_installation_routines.sh",
		    a->os_root);
	}

	/*
	 * Do it!
	 */
	/* commands_preview(a->c, cmds); */
	if (!commands_execute(a, cmds)) {
		inform(a->c, _("%s was not fully installed."), OPERATING_SYSTEM_NAME);
		a->result = 0;
	} else {
		a->result = 1;
	}
	commands_free(cmds);
	cmds = commands_new();

	if (a->result) {
		config_vars_write(rc_conf, CONFIG_TYPE_SH, "%smnt/etc/rc.conf",
		    a->os_root);
		config_vars_free(rc_conf);
		rc_conf = config_vars_new();
	}

	/*
	 * Unmount everything we mounted on /mnt.  This is done in a seperate
	 * command chain, so that partitions are unmounted, even if an error
	 * occurs in one of the preceding commands, or it is cancelled.
	 */
	unmount_all_under(a, cmds, "%smnt", a->os_root);

	/*
	 * Once everything is unmounted, if the install went successfully,
	 * make sure once and for all that the disklabel is bootable.
	 */
	if (a->result)
		command_add(cmds, "%s%s -B %s",
		    a->os_root, cmd_name(a, "DISKLABEL64"),
		    slice_get_device_name(storage_get_selected_slice(a->s)));

	if (!commands_execute(a, cmds))
		inform(a->c, _("Warning: subpartitions were not correctly unmounted."));

	commands_free(cmds);

	/*
	 * Finally, remove all swap and any mappings.
	 */
	if (swapoff_all(a) == NULL)
		inform(a->c, _("Warning: swap could not be turned off."));
	if (remove_all_mappings(a) == NULL)
		inform(a->c, _("Warning: mappings could not be removed."));
}
コード例 #15
0
ファイル: binder.c プロジェクト: longlinht/android_source
int binder_parse(struct binder_state *bs, struct binder_io *bio,
                 uint32_t *ptr, uint32_t size, binder_handler func)
{
    int r = 1;
    uint32_t *end = ptr + (size / 4);

    while (ptr < end) {
        uint32_t cmd = *ptr++;
#if TRACE
        fprintf(stderr,"%s:\n", cmd_name(cmd));
#endif
        switch(cmd) {
        case BR_NOOP:
            break;
        case BR_TRANSACTION_COMPLETE:
            break;
        case BR_INCREFS:
        case BR_ACQUIRE:
        case BR_RELEASE:
        case BR_DECREFS:
#if TRACE
            fprintf(stderr,"  %08x %08x\n", ptr[0], ptr[1]);
#endif
            ptr += 2;
            break;
        case BR_TRANSACTION: {
            struct binder_txn *txn = (void *) ptr;
            if ((end - ptr) * sizeof(uint32_t) < sizeof(struct binder_txn)) {
                LOGE("parse: txn too small!\n");
                return -1;
            }
            binder_dump_txn(txn);
            if (func) {
                unsigned rdata[256/4];
                struct binder_io msg;
                struct binder_io reply;
                int res;

                bio_init(&reply, rdata, sizeof(rdata), 4);
                bio_init_from_txn(&msg, txn);
                res = func(bs, txn, &msg, &reply);
                binder_send_reply(bs, &reply, txn->data, res);
            }
            ptr += sizeof(*txn) / sizeof(uint32_t);
            break;
        }
        case BR_REPLY: {
            struct binder_txn *txn = (void*) ptr;
            if ((end - ptr) * sizeof(uint32_t) < sizeof(struct binder_txn)) {
                LOGE("parse: reply too small!\n");
                return -1;
            }
            binder_dump_txn(txn);
            if (bio) {
                bio_init_from_txn(bio, txn);
                bio = 0;
            } else {
                    /* todo FREE BUFFER */
            }
            ptr += (sizeof(*txn) / sizeof(uint32_t));
            r = 0;
            break;
        }
        case BR_DEAD_BINDER: {
            struct binder_death *death = (void*) *ptr++;
            death->func(bs, death->ptr);
            break;
        }
        case BR_FAILED_REPLY:
            r = -1;
            break;
        case BR_DEAD_REPLY:
            r = -1;
            break;
        default:
            LOGE("parse: OOPS %d\n", cmd);
            return -1;
        }
    }

    return r;
}
コード例 #16
0
ファイル: functions.c プロジェクト: kusumi/DragonFlyBSD
struct i_fn_args *
i_fn_args_new(const char *os_root, const char *def_tmp_dir,
	      const char *def_cmds_file, int transport, const char *rendezvous)
{
	struct i_fn_args *a;
	char *filename;

	AURA_MALLOC(a, i_fn_args);

	a->c = NULL;
	a->os_root = aura_strdup(os_root);
	a->cfg_root = "";
	a->name = "";
	a->short_desc = "";
	a->long_desc = "";
	a->result = 0;
	a->log = NULL;
	a->s = NULL;
	a->tmp = NULL;
	a->temp_files = NULL;
	a->cmd_names = NULL;

	asprintf(&filename, "%sinstall.log", def_tmp_dir);
	a->log = fopen(filename, "w");
	free(filename);
	if (a->log == NULL) {
		i_fn_args_free(a);
		return(NULL);
	}

	i_log(a, "Installer started");
	i_log(a, "-----------------");

	i_log(a, "+ Creating DFUI connection on ``%s''\n", rendezvous);

	if ((a->c = dfui_connection_new(transport, rendezvous)) == NULL) {
		i_log(a, "! ERROR: Couldn't create connection on ``%s''\n", rendezvous);
		i_fn_args_free(a);
		return(NULL);
	}

	i_log(a, "+ Connecting on ``%s''\n", rendezvous);

	if (!dfui_be_start(a->c)) {
		i_log(a, "! ERROR: Couldn't connect to frontend on ``%s''\n", rendezvous);
		i_fn_args_free(a);
		return(NULL);
	}

	if ((a->s = storage_new()) == NULL) {
		i_log(a, "! ERROR: Couldn't create storage descriptor");
		i_fn_args_free(a);
		return(NULL);
	}

	a->tmp = def_tmp_dir;	/* XXX temporarily set to this */
	a->temp_files = aura_dict_new(23, AURA_DICT_HASH);
	a->cmd_names = config_vars_new();
	if (!config_vars_read(a, a->cmd_names, CONFIG_TYPE_SH, "%s",
		def_cmds_file)) {
		i_log(a, "! ERROR: Couldn't read cmdnames config file");
		i_fn_args_free(a);
		return(NULL);
	}

	a->tmp = cmd_name(a, "INSTALLER_TEMP");

	i_log(a, "+ Starting installer state machine");

	return(a);
}
コード例 #17
0
/*
 *
 *  state_setup_remote_installation_server:
 *  Setup a remote boot installation environment where a machine
 *  can boot via DHCP/TFTP/NFS and have a running environment
 *  where the installer can setup the machine.
 *
 */
void
state_setup_remote_installation_server(struct i_fn_args *a)
{
        FILE *p;
        struct commands *cmds;
        struct dfui_form *f;
	struct dfui_action *k;
        struct dfui_response *r;
        char *word;
        char interface[256];
        char line[256];

        switch (dfui_be_present_dialog(a->c, _("Enable Netboot Installation Services?"),
            _("Enable NetBoot Installation Services|No thanks"),
            _("NetBoot Installation Services allows this machine to become "
            "a Installation Server that will allow the clients to boot over the network "
	    "via PXE and start the Installation Environment."
	    "\n\n*NOTE!*  This will assign the IP Address of 10.1.0.1/24 to the selected interface."
            "\n\nWould you like to provision this machine to serve up the LiveCD/Installer?"))) {
		case 1:
			/*
			 * Get interface list.
			 */
			p = popen("/sbin/ifconfig -l", "r");
			/* XXX it's possible (though extremely unlikely) this will fail. */
			while (fgets(line, 255, p) != NULL)
				line[strlen(line) - 1] = '\0';
			pclose(p);

			f = dfui_form_create(
			    "assign_ip",
			    _("Setup NetBoot Installation Environment"),
			    _("Please select which interface you would like to configure:"),
			    "",
			    "p",        "role", "menu",
			    NULL
			);

			/* Loop through array. */
			word = strtok(line, " \t");
			while (word != NULL) {
				dfui_form_action_add(f, word,
				    dfui_info_new(word, "", ""));
				word = strtok(NULL, " ");
			}

			k = dfui_form_action_add(f, "cancel",
			    dfui_info_new("Cancel", "", ""));
			dfui_action_property_set(k, "accelerator", "ESC");

			if (!dfui_be_present(a->c, f, &r))
			abort_backend();

			strlcpy(interface, dfui_response_get_action_id(r), 256);

			if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
				dfui_form_free(f);
				dfui_response_free(r);
				return;
			}

			/*
			 *
			 * Issues the necessary commands to setup the remote boot environment
			 *
			 */
			cmds = commands_new();
			command_add(cmds, "%s%s %s 10.1.0.1 netmask 255.255.255.0",
			    a->os_root, cmd_name(a, "IFCONFIG"), interface);
			command_add(cmds, "%s%s -p %stftpdroot",
			    a->os_root, cmd_name(a, "MKDIR"), a->tmp);
			command_add(cmds, "%s%s %sboot/pxeboot %stftpdroot",
			    a->os_root, cmd_name(a, "CP"), a->os_root, a->tmp);
			command_add(cmds, "%s%s %s -ro -alldirs -maproot=root: -network 10.1.0.0 -mask 255.255.255.0 >> %setc/exports",
			    a->os_root, cmd_name(a, "ECHO"), a->os_root, a->os_root);
			command_add(cmds, "%s%s tftp dgram udp wait root %s%s tftpd -l -s %stftpdroot >> %setc/inetd.conf",
			    a->os_root, cmd_name(a, "ECHO"),
			    a->os_root, cmd_name(a, "TFTPD"),
			    a->tmp, a->os_root);
			command_add(cmds, "%s%s",
			    a->os_root, cmd_name(a, "INETD"));
			command_add(cmds, "%s%s %svar/db/dhcpd.leases",
			    a->os_root, cmd_name(a, "TOUCH"), a->os_root);
			command_add(cmds, "%s%s -cf /etc/dhcpd.conf >%sdev/null 2>&1",
			    a->os_root, cmd_name(a, "DHCPD"), a->os_root);
			command_add(cmds, "%s%s >%sdev/null 2>&1",
			    a->os_root, cmd_name(a, "RPCBIND"), a->os_root);
			command_add(cmds, "%s%s -ln >%sdev/null 2>&1",
			    a->os_root, cmd_name(a, "MOUNTD"), a->os_root);
			command_add(cmds, "%s%s -u -t -n 6 >%sdev/null 2>&1",
			    a->os_root, cmd_name(a, "NFSD"), a->os_root);

			if (commands_execute(a, cmds)) {
				inform(a->c, _("NetBoot installation services are now started."));
			} else {
				inform(a->c, _("A failure occurred while provisioning the NetBoot environment.  Please check the logs."));
			}

			commands_free(cmds);
			dfui_form_free(f);
			dfui_response_free(r);

			break;
		case 2:

			break;

	};

	state = state_welcome;

}
コード例 #18
0
/*
 * Given a set of subpartitions-to-be in the selected slice,
 * create them.
 */
static int
create_subpartitions(struct i_fn_args *a)
{
	struct subpartition *sp;
	struct commands *cmds;
	int result = 0;
	int num_partitions;

	cmds = commands_new();
	if (!is_file("%sinstall.disklabel.%s",
	    a->tmp,
	    slice_get_device_name(storage_get_selected_slice(a->s)))) {
		/*
		 * Get a copy of the 'virgin' disklabel.
		 * XXX It might make more sense for this to
		 * happen right after format_slice() instead.
		 */
		command_add(cmds, "%s%s -r %s >%sinstall.disklabel.%s",
		    a->os_root, cmd_name(a, "DISKLABEL64"),
		    slice_get_device_name(storage_get_selected_slice(a->s)),
		    a->tmp,
		    slice_get_device_name(storage_get_selected_slice(a->s)));
	}

	/*
	 * Weave together a new disklabel out the of the 'virgin'
	 * disklabel, and the user's subpartition choices.
	 */

	/*
	 * Take everything from the 'virgin' disklabel up until the
	 * '16 partitions' line.
	 */
	num_partitions = 16;
	command_add(cmds, "%s%s '$2==\"partitions:\" || cut { cut = 1 } !cut { print $0 }' <%sinstall.disklabel.%s >%sinstall.disklabel",
	    a->os_root, cmd_name(a, "AWK"),
	    a->tmp,
	    slice_get_device_name(storage_get_selected_slice(a->s)),
	    a->tmp);

	/*
	 * 16 partitions:
	 * #          size     offset    fstype
	 *   c:   16383969          0    unused	#    7999.985MB
	 */

	command_add(cmds, "%s%s '%d partitions:' >>%sinstall.disklabel",
	    a->os_root, cmd_name(a, "ECHO"), num_partitions ,a->tmp);
	command_add(cmds, "%s%s '%s' >>%sinstall.disklabel",
	    a->os_root, cmd_name(a, "ECHO"),
	    "#          size     offset    fstype",
	    a->tmp);

#ifdef DEBUG
	for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
	     sp != NULL; sp = subpartition_next(sp)) {
		command_add(cmds, "%s%s 'mountpoint: %s device: %s'",
		     a->os_root, cmd_name(a, "ECHO"),
		     subpartition_get_mountpoint(sp),
		     subpartition_get_device_name(sp));
	}
#endif

	/*
	 * Write a line for each subpartition the user wants.
	 */
	for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
	     sp != NULL; sp = subpartition_next(sp)) {
		if (subpartition_is_tmpfsbacked(sp)) {
			continue;
		}
		if (subpartition_is_swap(sp)) {
			command_add(cmds, "%s%s '  %c:\t%s\t*\tswap' >>%sinstall.disklabel",
			    a->os_root, cmd_name(a, "ECHO"),
			    subpartition_get_letter(sp),
			    capacity_to_string(subpartition_get_capacity(sp)),
			    a->tmp);
		} else if (strcmp(subpartition_get_mountpoint(sp), "/boot") == 0) {
			command_add(cmds, "%s%s '  %c:\t%s\t0\t4.2BSD' >>%sinstall.disklabel",
			    a->os_root, cmd_name(a, "ECHO"),
			    subpartition_get_letter(sp),
			    capacity_to_string(subpartition_get_capacity(sp)),
			    a->tmp);
		} else {
			command_add(cmds, "%s%s '  %c:\t%s\t*\tHAMMER' >>%sinstall.disklabel",
			    a->os_root, cmd_name(a, "ECHO"),
			    subpartition_get_letter(sp),
			    capacity_to_string(subpartition_get_capacity(sp)),
			    a->tmp);
		}
	}
	temp_file_add(a, "install.disklabel");

	/*
	 * Label the slice from the disklabel we just wove together.
	 */
	command_add(cmds, "%s%s -R -B -r %s %sinstall.disklabel",
	    a->os_root, cmd_name(a, "DISKLABEL64"),
	    slice_get_device_name(storage_get_selected_slice(a->s)),
	    a->tmp);

	/*
	 * Create a snapshot of the disklabel we just created
	 * for debugging inspection in the log.
	 */
	command_add(cmds, "%s%s %s",
	    a->os_root, cmd_name(a, "DISKLABEL64"),
	    slice_get_device_name(storage_get_selected_slice(a->s)));

	/*
	 * If encryption was specified, load dm(4).
	 */
	for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
	     sp != NULL; sp = subpartition_next(sp)) {
		if (subpartition_is_encrypted(sp)) {
			fn_get_passphrase(a);
			break;
		}
	}

	/*
	 * Create filesystems on the newly-created subpartitions.
	 */
	for (sp = slice_subpartition_first(storage_get_selected_slice(a->s));
	     sp != NULL; sp = subpartition_next(sp)) {
		if (subpartition_is_swap(sp) || subpartition_is_tmpfsbacked(sp)) {
			if (subpartition_is_swap(sp) &&
			    subpartition_is_encrypted(sp)) {
				command_add(cmds,
				    "%s%s -d /tmp/t1 luksFormat /dev/%s",
				    a->os_root, cmd_name(a, "CRYPTSETUP"),
				    subpartition_get_device_name(sp));
				command_add(cmds,
				    "%s%s -d /tmp/t1 luksOpen /dev/%s swap",
				    a->os_root, cmd_name(a, "CRYPTSETUP"),
				    subpartition_get_device_name(sp));
			}
			continue;
		}

		if (strcmp(subpartition_get_mountpoint(sp), "/boot") == 0) {
			command_add(cmds, "%s%s /dev/%s",
			    a->os_root, cmd_name(a, "NEWFS"),
			    subpartition_get_device_name(sp));
		} else {
			if (subpartition_is_encrypted(sp)) {
				command_add(cmds,
				    "%s%s -d /tmp/t1 luksFormat /dev/%s",
				    a->os_root, cmd_name(a, "CRYPTSETUP"),
				    subpartition_get_device_name(sp));
				command_add(cmds,
				    "%s%s -d /tmp/t1 luksOpen /dev/%s root",
				    a->os_root, cmd_name(a, "CRYPTSETUP"),
				    subpartition_get_device_name(sp));
			}
			command_add(cmds, "%s%s -f -L ROOT /dev/%s",
			    a->os_root, cmd_name(a, "NEWFS_HAMMER"),
			    subpartition_is_encrypted(sp) ?
			    "mapper/root" : subpartition_get_device_name(sp));
		}
	}

	result = commands_execute(a, cmds);
	commands_free(cmds);
	return(result);
}
コード例 #19
0
ファイル: interact.c プロジェクト: ajinkya93/netbsd-src
static void
cmd_info(struct disklabel *lp, char *s, int fd)
{
	char	line[BUFSIZ];
	int	v, i;
	u_int32_t u;

	printf("# Current values:\n");
	showinfo(stdout, lp, specname);

	/* d_type */
	for (;;) {
		i = lp->d_type;
		if (i < 0 || i >= DKMAXTYPES)
			i = 0;
		i = getinput(line, "Disk type [%s]: ", dktypenames[i]);
		if (i == -1)
			return;
		else if (i == 0)
			break;
		if (!strcmp(line, "?")) {
			dumpnames("Supported disk types", dktypenames,
			    DKMAXTYPES);
			continue;
		}
		for (i = 0; i < DKMAXTYPES; i++) {
			if (!strcasecmp(dktypenames[i], line)) {
				lp->d_type = i;
				goto done_typename;
			}
		}
		v = atoi(line);
		if ((unsigned)v >= DKMAXTYPES) {
			warnx("Unknown disk type: %s", line);
			continue;
		}
		lp->d_type = v;
 done_typename:
		break;
	}

	/* d_typename */
	i = getinput(line, "Disk name [%.*s]: ", 
	    (int) sizeof(lp->d_typename), lp->d_typename);
	if (i == -1)
		return;
	else if (i == 1)
		(void) strncpy(lp->d_typename, line, sizeof(lp->d_typename));

	/* d_packname */
	cmd_name(lp, s, fd);

	/* d_npartitions */
	for (;;) {
		i = getinput(line, "Number of partitions [%" PRIu16 "]: ",
		    lp->d_npartitions);
		if (i == -1)
			return;
		else if (i == 0)
			break;
		if (sscanf(line, "%" SCNu32, &u) != 1) {
			printf("Invalid number of partitions `%s'\n", line);
			continue;
		}
		lp->d_npartitions = u;
		break;
	}

	/* d_secsize */
	for (;;) {
		i = getinput(line, "Sector size (bytes) [%" PRIu32 "]: ",
		    lp->d_secsize);
		if (i == -1)
			return;
		else if (i == 0)
			break;
		if (sscanf(line, "%" SCNu32, &u) != 1) {
			printf("Invalid sector size `%s'\n", line);
			continue;
		}
		lp->d_secsize = u;
		break;
	}

	/* d_nsectors */
	for (;;) {
		i = getinput(line, "Number of sectors per track [%" PRIu32
		    "]: ", lp->d_nsectors);
		if (i == -1)
			return;
		else if (i == 0)
			break;
		if (sscanf(line, "%" SCNu32, &u) != 1) {
			printf("Invalid number of sectors `%s'\n", line);
			continue;
		}
		lp->d_nsectors = u;
		break;
	}

	/* d_ntracks */
	for (;;) {
		i = getinput(line, "Number of tracks per cylinder [%" PRIu32
		    "]: ", lp->d_ntracks);
		if (i == -1)
			return;
		else if (i == 0)
			break;
		if (sscanf(line, "%" SCNu32, &u) != 1) {
			printf("Invalid number of tracks `%s'\n", line);
			continue;
		}
		lp->d_ntracks = u;
		break;
	}

	/* d_secpercyl */
	for (;;) {
		i = getinput(line, "Number of sectors/cylinder [%" PRIu32 "]: ",
		    lp->d_secpercyl);
		if (i == -1)
			return;
		else if (i == 0)
			break;
		if (sscanf(line, "%" SCNu32, &u) != 1) {
			printf("Invalid number of sector/cylinder `%s'\n",
			    line);
			continue;
		}
		lp->d_secpercyl = u;
		break;
	}

	/* d_ncylinders */
	for (;;) {
		i = getinput(line, "Total number of cylinders [%" PRIu32 "]: ",
		    lp->d_ncylinders);
		if (i == -1)
			return;
		else if (i == 0)
			break;
		if (sscanf(line, "%" SCNu32, &u) != 1) {
			printf("Invalid sector size `%s'\n", line);
			continue;
		}
		lp->d_ncylinders = u;
		break;
	}

	/* d_secperunit */
	for (;;) {
		i = getinput(line, "Total number of sectors [%" PRIu32 "]: ",
		    lp->d_secperunit);
		if (i == -1)
			return;
		else if (i == 0)
			break;
		if (sscanf(line, "%" SCNu32, &u) != 1) {
			printf("Invalid number of sectors `%s'\n", line);
			continue;
		}
		lp->d_secperunit = u;
		break;
	}

	/* d_rpm */

	/* d_interleave */
	for (;;) {
		i = getinput(line, "Hardware sectors interleave [%" PRIu16
		    "]: ", lp->d_interleave);
		if (i == -1)
			return;
		else if (i == 0)
			break;
		if (sscanf(line, "%" SCNu32, &u) != 1) {
			printf("Invalid sector interleave `%s'\n", line);
			continue;
		}
		lp->d_interleave = u;
		break;
	}

	/* d_trackskew */
	for (;;) {
		i = getinput(line, "Sector 0 skew, per track [%" PRIu16 "]: ",
		    lp->d_trackskew);
		if (i == -1)
			return;
		else if (i == 0)
			break;
		if (sscanf(line, "%" SCNu32, &u) != 1) {
			printf("Invalid track sector skew `%s'\n", line);
			continue;
		}
		lp->d_trackskew = u;
		break;
	}

	/* d_cylskew */
	for (;;) {
		i = getinput(line, "Sector 0 skew, per cylinder [%" PRIu16
		    "]: ", lp->d_cylskew);
		if (i == -1)
			return;
		else if (i == 0)
			break;
		if (sscanf(line, "%" SCNu32, &u) != 1) {
			printf("Invalid cylinder sector `%s'\n", line);
			continue;
		}
		lp->d_cylskew = u;
		break;
	}

	/* d_headswitch */
	for (;;) {
		i = getinput(line, "Head switch time (usec) [%" PRIu32 "]: ",
		    lp->d_headswitch);
		if (i == -1)
			return;
		else if (i == 0)
			break;
		if (sscanf(line, "%" SCNu32, &u) != 1) {
			printf("Invalid head switch time `%s'\n", line);
			continue;
		}
		lp->d_headswitch = u;
		break;
	}

	/* d_trkseek */
	for (;;) {
		i = getinput(line, "Track seek time (usec) [%" PRIu32 "]:",
		    lp->d_trkseek);
		if (i == -1)
			return;
		else if (i == 0)
			break;
		if (sscanf(line, "%" SCNu32, &u) != 1) {
			printf("Invalid track seek time `%s'\n", line);
			continue;
		}
		lp->d_trkseek = u;
		break;
	}
}
コード例 #20
0
ファイル: cmd.c プロジェクト: czarkoff/baresip
static int cmd_print_all(struct re_printf *pf,
			 const struct commands *commands,
			 bool print_long, bool print_short,
			 const char *match, size_t match_len)
{
	struct list sortedl = LIST_INIT;
	struct le *le;
	size_t width_long = 1;
	size_t width_short = 5;
	char fmt[64];
	char buf[16];
	int err = 0;

	if (!commands)
		return EINVAL;

	for (le = commands->cmdl.head; le; le = le->next) {

		struct cmds *cmds = le->data;
		size_t i;

		for (i=0; i<cmds->cmdc; i++) {

			const struct cmd *cmd = &cmds->cmdv[i];
			struct cmd_sort *cs;

			if (match && match_len) {

				if (str_len(cmd->name) >= match_len &&
				    0 == memcmp(cmd->name, match, match_len)) {
					/* Match */
				}
				else {
					continue;
				}
			}

			if (!str_isset(cmd->desc))
				continue;

			if (print_short && !print_long) {

				if (cmd->key == KEYCODE_NONE)
					continue;
			}

			cs = mem_zalloc(sizeof(*cs), NULL);
			if (!cs) {
				err = ENOMEM;
				goto out;
			}
			cs->cmd = cmd;

			list_append(&sortedl, &cs->le, cs);

			width_long = max(width_long, 1+str_len(cmd->name)+3);
		}
	}

	list_sort(&sortedl, sort_handler, &print_long);

	if (re_snprintf(fmt, sizeof(fmt),
			"  %%-%zus    %%-%zus    %%s\n",
			width_long, width_short) < 0) {
		err = ENOMEM;
		goto out;
	}

	for (le = sortedl.head; le; le = le->next) {
		struct cmd_sort *cs = le->data;
		const struct cmd *cmd = cs->cmd;
		char namep[64] = "";

		if (print_long && str_isset(cmd->name)) {
			re_snprintf(namep, sizeof(namep), "%c%s%s",
				    LONG_PREFIX, cmd->name,
				    (cmd->flags & CMD_PRM) ? " .." : "");
		}

		err |= re_hprintf(pf, fmt,
				  namep,
				  (print_short && cmd->key)
				    ? cmd_name(buf, sizeof(buf), cmd)
				    : "",
				  cmd->desc);
	}

	err |= re_hprintf(pf, "\n");

 out:
	list_flush(&sortedl);
	return err;
}
コード例 #21
0
ファイル: fn_diagnostic.c プロジェクト: Key4ce/bsdinstaller
void
fn_memtest(struct i_fn_args *a)
{
	struct dfui_form *f;
	struct dfui_response *r;
	struct dfui_dataset *ds, *new_ds;
	struct commands *cmds;
	struct command *cmd;
	const char *memtestsize;

	f = dfui_form_create(
	    "memtest",
	    _("Memory test"),
	    _("Memory test - Enter the size in values such as 400M, 1G."),
	    "",

	    "f", "memtestsize", _("Memory test size"),
	    _("Enter the amount of memory you would like to check:"), "",

	    "a", "ok", _("OK"), "", "",
	    "a", "cancel", _("Cancel Memory Test"), "", "",
	    "p", "accelerator", "ESC",

	    NULL
	);

	ds = dfui_dataset_new();
	dfui_dataset_celldata_add(ds, "memtestsize", "");
	dfui_form_dataset_add(f, ds);

	if (!dfui_be_present(a->c, f, &r))
		abort_backend();

	if (strcmp(dfui_response_get_action_id(r), "ok") == 0) {
		new_ds = dfui_response_dataset_get_first(r);
		memtestsize = dfui_dataset_get_value(new_ds, "memtestsize");
		cmds = commands_new();
		cmd = command_add(cmds,
		    "cd %s && %s%s %s 1 --log",
		    a->tmp,
		    a->os_root, cmd_name(a, "MEMTEST"),
		    memtestsize);
		command_set_log_mode(cmd, COMMAND_LOG_QUIET);
		cmd = command_add(cmds,
		    "%s%s -E -v '^Unable to malloc' %smemtest.log > %smemtest.log.new",
		    a->os_root, cmd_name(a, "GREP"),
		    a->tmp, a->tmp);
		cmd = command_add(cmds, "%s%s %smemtest.log.new %smemtest.log",
		    a->os_root, cmd_name(a, "MV"),
		    a->tmp, a->tmp);
		cmd = command_add(cmds,
		    "%s%s -E -v '^Allocated.*failed' %smemtest.log > %smemtest.log.new",
		    a->os_root, cmd_name(a, "GREP"),
		    a->tmp, a->tmp);
		cmd = command_add(cmds, "%s%s %smemtest.log.new %smemtest.log",
		    a->os_root, cmd_name(a, "MV"),
		    a->tmp, a->tmp);
 		if (commands_execute(a, cmds)) {
			commands_free(cmds);
			view_memtest_log(a);
			cmds = commands_new();
			cmd = command_add(cmds, "%s%s -f %smemtest.log",
			    a->os_root, cmd_name(a, "RM"),
			    a->tmp);
			commands_execute(a, cmds);
		} else {
			inform(a->c, _("Memory test could not be run."));
		}
		commands_free(cmds);
	}

	dfui_form_free(f);
	dfui_response_free(r);
}
コード例 #22
0
ファイル: fn_disk.c プロジェクト: mihaicarabas/dragonfly
/*
 * If ss->selected_disk == NULL, user will be asked for which disk.
 * Returns 1 if disk was formatted, 0 if it wasn't.
 * If it was, ss->selected_disk and ss->selected_slice are set to it.
 */
void
fn_format_disk(struct i_fn_args *a)
{
	struct commands *cmds;
	char *selected_disk_string;

	if (storage_get_selected_disk(a->s) == NULL) {
		a->short_desc = _("Select a disk to format.");
		a->cancel_desc = _("Return to Utilities Menu");
		fn_select_disk(a);
		if (!a->result || storage_get_selected_disk(a->s) == NULL) {
			a->result = 0;
			return;
		}
	}

	if (confirm_dangerous_action(a->c,
	    _("WARNING!  ALL data in ALL partitions on the disk\n\n"
	    "%s\n\nwill be IRREVOCABLY ERASED!\n\nAre you ABSOLUTELY "
	    "SURE you wish to take this action?  This is your "
	    "LAST CHANCE to cancel!"), disk_get_desc(storage_get_selected_disk(a->s)))) {
		cmds = commands_new();

		command_add(cmds, "%s%s -BI %s",
		    a->os_root, cmd_name(a, "FDISK"),
		    disk_get_device_name(storage_get_selected_disk(a->s)));

		if (!commands_execute(a, cmds)) {
			inform(a->c, _("The disk\n\n%s\n\nwas "
			    "not correctly formatted, and may "
			    "now be in an inconsistent state. "
			    "We recommend re-formatting it "
			    "before attempting to install "
			    "%s on it."),
			    disk_get_desc(storage_get_selected_disk(a->s)),
			    OPERATING_SYSTEM_NAME);
			commands_free(cmds);
			a->result = 0;
			return;
		}
		commands_free(cmds);

		/*
		 * Since one of the disks has now changed, we must
		 * refresh our view of them and re-select the disk
		 * since the selected_disk pointer will be invalidated.
		 */
		selected_disk_string = aura_strdup(
		    disk_get_device_name(storage_get_selected_disk(a->s)));
		if (!survey_storage(a)) {
			inform(a->c, _("Errors occurred while probing "
			    "the system for its storage capabilities."));
		}
		storage_set_selected_disk(a->s, disk_find(a->s, selected_disk_string));
		free(selected_disk_string);

		/*
		 * Note that we formatted this disk and that we want
		 * to use the first (and only) slice of it.
		 */
		disk_set_formatted(storage_get_selected_disk(a->s), 1);
		storage_set_selected_slice(a->s, disk_slice_first(storage_get_selected_disk(a->s)));

		if (!format_slice(a)) {
			inform(a->c, _("The sole primary partition of "
			    "the disk\n\n%s\n\nwas "
			    "not correctly formatted, and may "
			    "now be in an inconsistent state. "
			    "We recommend re-formatting the "
			    "disk before attempting to install "
			    "%s on it."),
			    disk_get_desc(storage_get_selected_disk(a->s)),
			    OPERATING_SYSTEM_NAME);
			a->result = 0;
			return;
		}

		inform(a->c, _("The disk\n\n%s\n\nwas formatted."),
		    disk_get_desc(storage_get_selected_disk(a->s)));
		a->result = 1;
	} else {
		inform(a->c, _("Action cancelled - no disks were formatted."));
		a->result = 0;
	}
}
コード例 #23
0
ファイル: main.c プロジェクト: GrayTShirt/bolo
int main(int argc, char **argv)
{
	int run_help = 0;
	int run_version = 0;

	char proc[256];
	char path[256];
	pid_t pid = getpid();
	sprintf(proc, "/proc/%d/exe", pid);
	if (readlink(proc, path, 256) == -1) {
		fprintf(stderr, "failed to read execution path from /proc\n");
		return 1;
	}

	if (strcmp(path, "/usr/sbin/bolo") == 0)
		return cmd_aggregator(argc, argc, argv);

	int i;
	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "-h") == 0
		 || strcmp(argv[i], "-?") == 0
		 || strcmp(argv[i], "--help") == 0) {
			run_help = 1;
			continue;
		}
		if (strcmp(argv[i], "-V") == 0
		 || strcmp(argv[i], "--version") == 0) {
			run_version = 1;
			continue;
		}
		if (argv[i][0] == '-') {
			fprintf(stderr, "Invalid option `%s'\n", argv[i]);
			return 1;
		}
		break;
	}

	if (run_help)    return cmd_help(i, argc, argv);
	if (run_version) return cmd_version(i, argc, argv);
	if (i == argc)   return cmd_help(i, argc, argv);

	if (strcmp(argv[i], "help") == 0)
		return cmd_help(i, argc, argv);

	if (strcmp(argv[i], "version") == 0)
		return cmd_version(i, argc, argv);

	if (strcmp(argv[i], "aggr") == 0
	 || strcmp(argv[i], "aggregator") == 0)
		return cmd_aggregator(i, argc, argv);

	if (strcmp(argv[i], "cache") == 0)
		return cmd_cache(i, argc, argv);

	if (strcmp(argv[i], "forget") == 0)
		return cmd_forget(i, argc, argv);

	if (strcmp(argv[i], "name") == 0)
		return cmd_name(i, argc, argv);

	if (strcmp(argv[i], "query") == 0)
		return cmd_query(i, argc, argv);

	if (strcmp(argv[i], "send") == 0)
		return cmd_send(i, argc, argv);

	if (strcmp(argv[i], "spy") == 0)
		return cmd_spy(i, argc, argv);

	if (strcmp(argv[i], "tail") == 0)
		return cmd_tail(i, argc, argv);

	fprintf(stderr, "Unrecognized command `%s'.  See bolo --help.\n", argv[i]);
	return 1;
}
コード例 #24
0
ファイル: cmd_line_parser.cpp プロジェクト: hwanju/spiceplay
int CmdLineParser::get_option(char** val)
{
    CmdLineParser::Option* opt_obj;

    if (!_argv) {
        THROW("unexpected");
    }

    if (_multi_args) {
        THROW("in multi args mode");
    }

    if (_done) {
        THROW("is done");
    }

    int long_index;

    int opt = getopt_long(_argc, _argv, _short_options.c_str(), &_long_options[0], &long_index);

    switch (opt) {
    case 0: {
        if (!(opt_obj = find(_long_options[long_index].val))) {
            THROW("long option no found");
        }

#ifdef DISABLE_ABBREVIATE
        int name_pos =
            (opt_obj->type == REQUIRED_ARGUMENT && optarg[-1] != '=')
            ? optind - 2
            : optind - 1;
        std::string cmd_name(_argv[name_pos] + 2);
        if (cmd_name.find(opt_obj->name) != 0) {
            Platform::term_printf("%s: invalid abbreviated option '--%s'\n", _argv[0], cmd_name.c_str());
            return OPTION_ERROR;
        }
#endif

        if (opt_obj->seperator) {
            *val = start_multi(optarg, opt_obj->seperator);
        } else {
            *val = optarg;
        }
        opt_obj->is_set = true;
        return opt_obj->id;
    }
    case -1: {
        *val = NULL;
        if (!_positional_args && optind != _argc) {
            Platform::term_printf("%s: unexpected positional arguments\n", _argv[0]);
            return OPTION_ERROR;
        }
        if ((opt_obj = find_missing_opt())) {
            Platform::term_printf("%s: option --%s is required\n", _argv[0], opt_obj->name.c_str());
            return OPTION_ERROR;
        }
        _done = true;
        return OPTION_DONE;
    }
    case '?':
        if (optopt >= 255) {
            opt_obj = find(optopt);
            ASSERT(opt_obj);

#ifdef DISABLE_ABBREVIATE
            std::string cmd_name(_argv[optind - 1] + 2);
            if (cmd_name.find(opt_obj->name) != 0) {
                Platform::term_printf("%s: invalid option '--%s'\n", _argv[0], cmd_name.c_str());
                return OPTION_ERROR;
            }
#endif
            Platform::term_printf("%s: option --%s requires an argument\n",
                                  _argv[0], opt_obj->name.c_str());
        } else if (optopt == 0) {
            Platform::term_printf("%s: invalid option '%s'\n", _argv[0], _argv[optind - 1]);
        } else if ((opt_obj = find((char)optopt))) {
            Platform::term_printf("%s: option '-%c' requires an argument\n",
                                  _argv[0], opt_obj->short_name);
        } else {
            Platform::term_printf("%s: invalid option '-%c'\n", _argv[0], char(optopt));
        }
        return OPTION_ERROR;
    default:
        if (opt > 255 || !(opt_obj = find((char)opt))) {
            *val = NULL;
            return OPTION_ERROR;
        }
        if (opt_obj->seperator) {
            *val = start_multi(optarg, opt_obj->seperator);
        } else {
            *val = optarg;
        }
        opt_obj->is_set = true;
        return opt_obj->id;
    }
}
コード例 #25
0
ファイル: fn_disk.c プロジェクト: mihaicarabas/dragonfly
int
format_slice(struct i_fn_args *a)
{
	struct commands *cmds;
	struct command *cmd;
	int result;
	int cyl, hd, sec;

	cmds = commands_new();

	/*
	 * The information in a->s NEEDS to be accurate here!
	 * Presumably we just did a survey_storage() recently.
	 * XXX should we do another one here anyway just to be paranoid?
	 */

	/*
	 * Set the slice's sysid to 165.
	 */
	disk_get_geometry(storage_get_selected_disk(a->s), &cyl, &hd, &sec);
	command_add(cmds, "%s%s 'g c%d h%d s%d' >%snew.fdisk",
	    a->os_root, cmd_name(a, "ECHO"),
	    cyl, hd, sec,
	    a->tmp);
	command_add(cmds, "%s%s 'p %d %d %lu %lu' >>%snew.fdisk",
	    a->os_root, cmd_name(a, "ECHO"),
	    slice_get_number(storage_get_selected_slice(a->s)),
	    165,
	    slice_get_start(storage_get_selected_slice(a->s)),
	    slice_get_size(storage_get_selected_slice(a->s)),
	    a->tmp);
	if (slice_get_flags(storage_get_selected_slice(a->s)) & 0x80) {
		command_add(cmds, "%s%s 'a %d' >>%snew.fdisk",
		    a->os_root, cmd_name(a, "ECHO"),
		    slice_get_number(storage_get_selected_slice(a->s)),
		    a->tmp);
	}

	command_add(cmds, "%s%s %snew.fdisk",
	    a->os_root, cmd_name(a, "CAT"), a->tmp);
	temp_file_add(a, "new.fdisk");

	/*
	 * Execute the fdisk script.
	 */
	cmd = command_add(cmds, "%s%s -v -f %snew.fdisk %s",
	    a->os_root, cmd_name(a, "FDISK"), a->tmp,
	    disk_get_device_name(storage_get_selected_disk(a->s)));
	if (slice_get_size(storage_get_selected_slice(a->s)) == 0xFFFFFFFFU)
		command_set_failure_mode(cmd, COMMAND_FAILURE_IGNORE);

	/*
	 * If there is an old 'virgin' disklabel hanging around
	 * in the temp dir, get rid of it.  This won't happen
	 * from a real CD, but might happen with '-o' installs.
	 */
	command_add(cmds, "%s%s -f %sinstall.disklabel.%s",
	    a->os_root, cmd_name(a, "RM"),
	    a->tmp,
	    slice_get_device_name(storage_get_selected_slice(a->s)));

	result = commands_execute(a, cmds);

	commands_free(cmds);

	return(result);
}
コード例 #26
0
ファイル: fn_disk.c プロジェクト: mihaicarabas/dragonfly
void
fn_install_bootblocks(struct i_fn_args *a, const char *device)
{
	struct dfui_form *f;
	struct dfui_response *r;
	struct dfui_dataset *ds;
	struct disk *d;
	struct commands *cmds;
	struct command *cmd;
	char disk[64], boot0cfg[32], packet[32];
	char msg_buf[1][1024];

	snprintf(msg_buf[0], sizeof(msg_buf[0]),
	    "'Packet Mode' refers to using newer BIOS calls to boot "
	    "from a partition of the disk.  It is generally not "
	    "required unless:\n\n"
	    "- your BIOS does not support legacy mode; or\n"
	    "- your %s primary partition resides on a "
	    "cylinder of the disk beyond cylinder 1024; or\n"
	    "- you just can't get it to boot without it.",
	    OPERATING_SYSTEM_NAME);

	f = dfui_form_create(
	    "install_bootstrap",
	    _("Install Bootblock(s)"),
	    a->short_desc,

	    msg_buf[0],

	    "p", "special", "dfinstaller_install_bootstrap",

	    "f", "disk", _("Disk Drive"),
	    _("The disk on which you wish to install a bootblock"), "",
	    "p", "editable", "false",
	    "f", "boot0cfg", _("Install Bootblock?"),
	    _("Install a bootblock on this disk"), "",
	    "p", "control", "checkbox",
	    "f", "packet", _("Packet Mode?"),
	    _("Select this to use 'packet mode' to boot the disk"), "",
	    "p", "control", "checkbox",

	    "a", "ok", _("Accept and Install Bootblocks"), "", "",
	    "a", "cancel", a->cancel_desc, "", "",
	    "p", "accelerator", "ESC",

	    NULL
	);

	dfui_form_set_multiple(f, 1);

	if (device != NULL) {
		ds = dfui_dataset_new();
		dfui_dataset_celldata_add(ds, "disk", device);
		dfui_dataset_celldata_add(ds, "boot0cfg", "Y");
		dfui_dataset_celldata_add(ds, "packet", "Y");
		dfui_form_dataset_add(f, ds);
	} else {
		for (d = storage_disk_first(a->s); d != NULL; d = disk_next(d)) {
			ds = dfui_dataset_new();
			dfui_dataset_celldata_add(ds, "disk",
			    disk_get_device_name(d));
			dfui_dataset_celldata_add(ds, "boot0cfg", "Y");
			dfui_dataset_celldata_add(ds, "packet", "Y");
			dfui_form_dataset_add(f, ds);
		}
	}

	if (!dfui_be_present(a->c, f, &r))
		abort_backend();

	a->result = 0;
	if (strcmp(dfui_response_get_action_id(r), "ok") == 0) {
		cmds = commands_new();

		for (ds = dfui_response_dataset_get_first(r); ds != NULL;
		     ds = dfui_dataset_get_next(ds)) {
			strlcpy(disk, dfui_dataset_get_value(ds, "disk"), 64);
			strlcpy(boot0cfg, dfui_dataset_get_value(ds, "boot0cfg"), 32);
			strlcpy(packet, dfui_dataset_get_value(ds, "packet"), 32);

			if (strcasecmp(boot0cfg, "Y") == 0) {
				cmd = command_add(cmds, "%s%s -B -o %spacket %s",
				    a->os_root, cmd_name(a, "BOOT0CFG"),
				    strcasecmp(packet, "Y") == 0 ? "" : "no",
				    disk);
				command_set_failure_mode(cmd, COMMAND_FAILURE_WARN);
				command_set_tag(cmd, "%s", disk);
				cmd = command_add(cmds, "%s%s -v %s",
				    a->os_root, cmd_name(a, "BOOT0CFG"),
				    disk);
				command_set_failure_mode(cmd, COMMAND_FAILURE_WARN);
				command_set_tag(cmd, "%s", disk);
			}
		}

		if (!commands_execute(a, cmds)) {
			ask_to_wipe_boot_sector(a, cmds);
		} else {
			inform(a->c, _("Bootblocks were successfully installed!"));
			a->result = 1;
		}
		commands_free(cmds);
	}

	dfui_form_free(f);
	dfui_response_free(r);
}
コード例 #27
0
ファイル: binder_impl.c プロジェクト: mrunix/gobinder
int binder_parse(struct binder_state* bs, struct binder_io* bio,
                 uintptr_t ptr, size_t size, binder_handler func) {
  int r = 1;
  uintptr_t end = ptr + (uintptr_t) size;

  while (ptr < end) {
    uint32_t cmd = *(uint32_t*) ptr;
    ptr += sizeof(uint32_t);
#if TRACE
    fprintf(stderr, "%s:\n", cmd_name(cmd));
#endif
    switch (cmd) {
    case BR_NOOP:
      break;
    case BR_TRANSACTION_COMPLETE:
      break;
    case BR_INCREFS:
    case BR_ACQUIRE:
    case BR_RELEASE:
    case BR_DECREFS:
#if TRACE
      fprintf(stderr, "  %p, %p\n", (void*)ptr, (void*)(ptr + sizeof(void*)));
#endif
      ptr += sizeof(struct binder_ptr_cookie);
      break;
    case BR_TRANSACTION: {
      struct binder_transaction_data* txn = (struct binder_transaction_data*) ptr;
      if ((end - ptr) < sizeof(*txn)) {
        fprintf(stderr, "parse: txn too small!\n");
        return -1;
      }
      binder_dump_txn(txn);
      if (func) {
        unsigned rdata[256 / 4];
        struct binder_io msg;
        struct binder_io reply;
        int res;

        bio_init(&reply, rdata, sizeof(rdata), 4);
        bio_init_from_txn(&msg, txn);
        res = func(bs, txn, &msg, &reply);
        binder_send_reply(bs, &reply, txn->data.ptr.buffer, res);
      }
      ptr += sizeof(*txn);
      break;
    }
    case BR_REPLY: {
      struct binder_transaction_data* txn = (struct binder_transaction_data*) ptr;
      if ((end - ptr) < sizeof(*txn)) {
        fprintf(stderr, "parse: reply too small!\n");
        return -1;
      }
      binder_dump_txn(txn);
      if (bio) {
        bio_init_from_txn(bio, txn);
        bio = 0;
      } else {
        /* todo FREE BUFFER */
      }
      ptr += sizeof(*txn);
      r = 0;
      break;
    }
    case BR_DEAD_BINDER: {
      struct binder_death* death = (struct binder_death*)(uintptr_t) * (binder_uintptr_t*)ptr;
      ptr += sizeof(binder_uintptr_t);
      death->func(bs, death->ptr);
      break;
    }
    case BR_FAILED_REPLY:
      r = -1;
      break;
    case BR_DEAD_REPLY:
      r = -1;
      break;
    default:
      fprintf(stderr, "parse: OOPS %d\n", cmd);
      return -1;
    }
  }

  return r;
}
コード例 #28
0
ファイル: binder.c プロジェクト: ybin/android-binder-ipc
/*
 * 解析从驱动读取上来的数据,如果bio != NULL,则同时将数据保存到bio中
 */
int binder_parse(struct binder_state *bs, struct binder_io *bio,
                 uint32_t *ptr, uint32_t size, binder_handler func)
{
    int r = 1;
    uint32_t *end = ptr + (size / 4);

    while (ptr < end) {
        uint32_t cmd = *ptr++;
#if TRACE
        fprintf(stderr,"%s:\n", cmd_name(cmd));
#endif
        switch(cmd) {
        case BR_NOOP:
            break;
        case BR_TRANSACTION_COMPLETE:
            break;
        case BR_INCREFS:
        case BR_ACQUIRE:
        case BR_RELEASE:
        case BR_DECREFS:
#if TRACE
            fprintf(stderr,"  %08x %08x\n", ptr[0], ptr[1]);
#endif
            ptr += 2;
            break;
        case BR_TRANSACTION: {
			// binder_txn结构跟binder_transaction_data结构是一样的,直接拿来用即可
            struct binder_txn *txn = (void *) ptr;
            if ((end - ptr) * sizeof(uint32_t) < sizeof(struct binder_txn)) {
                ALOGE("parse: txn too small!\n");
                return -1;
            }
            binder_dump_txn(txn);
            if (func) {
                unsigned rdata[256/4];
                struct binder_io msg;
                struct binder_io reply;
                int res;

				// 初始化reply对象内存为binder_io结构
                bio_init(&reply, rdata, sizeof(rdata), 4);
				// 将binder_transaction_data结构转换为binder_io结构
                bio_init_from_txn(&msg, txn);
				// 调用回调函数处理msg对象,并将结果保存到reply对象中
                res = func(bs, txn, &msg, &reply);
				// 释放txn->data缓存; 给驱动发送reply数据,这些数据
				// 根据res的不同会有所不同(res==0表示回调函数执行成功)
                binder_send_reply(bs, &reply, txn->data, res);
            }
            ptr += sizeof(*txn) / sizeof(uint32_t);
            break;
        }
        case BR_REPLY: {
            struct binder_txn *txn = (void*) ptr;
            if ((end - ptr) * sizeof(uint32_t) < sizeof(struct binder_txn)) {
                ALOGE("parse: reply too small!\n");
                return -1;
            }
            binder_dump_txn(txn);
            if (bio) {
				// 如果调用者希望拿到数据,就把数据写入bio对象
                bio_init_from_txn(bio, txn);
                bio = 0;
            } else {
                    /* todo FREE BUFFER */
            }
            ptr += (sizeof(*txn) / sizeof(uint32_t));
            r = 0;
            break;
        }
        case BR_DEAD_BINDER: {
            struct binder_death *death = (void*) *ptr++;
            death->func(bs, death->ptr);
            break;
        }
        case BR_FAILED_REPLY:
            r = -1;
            break;
        case BR_DEAD_REPLY:
            r = -1;
            break;
        default:
            ALOGE("parse: OOPS %d\n", cmd);
            return -1;
        }
    }

    return r;
}