static void fd_set_properties(struct fd_softc *fd) { prop_dictionary_t disk_info, odisk_info, geom; const struct fd_type *fdt; int secsize; fdt = fd->sc_type; if (fdt == NULL) { fdt = fd->sc_deftype; if (fdt == NULL) return; } disk_info = prop_dictionary_create(); geom = prop_dictionary_create(); prop_dictionary_set_uint64(geom, "sectors-per-unit", fdt->size); switch (fdt->secsize) { case 2: secsize = 512; break; case 3: secsize = 1024; break; default: secsize = 0; } prop_dictionary_set_uint32(geom, "sector-size", secsize); prop_dictionary_set_uint16(geom, "sectors-per-track", fdt->sectrac); prop_dictionary_set_uint16(geom, "tracks-per-cylinder", fdt->heads); prop_dictionary_set_uint64(geom, "cylinders-per-unit", fdt->cyls); prop_dictionary_set(disk_info, "geometry", geom); prop_object_release(geom); prop_dictionary_set(device_properties(fd->sc_dev), "disk-info", disk_info); /* * Don't release disk_info here; we keep a reference to it. * disk_detach() will release it when we go away. */ odisk_info = fd->sc_dk.dk_info; fd->sc_dk.dk_info = disk_info; if (odisk_info) prop_object_release(odisk_info); }
/* * npfctl_sessions_save: construct a list of sessions and export for saving. */ int npfctl_sessions_save(u_long cmd, void *data) { struct plistref *pref = data; prop_dictionary_t sesdict; prop_array_t selist, nplist; int error; /* Create a dictionary and two lists. */ sesdict = prop_dictionary_create(); selist = prop_array_create(); nplist = prop_array_create(); /* Save the sessions. */ error = npf_session_save(selist, nplist); if (error) { goto fail; } /* Set the session list, NAT policy list and export the dictionary. */ prop_dictionary_set(sesdict, "session-list", selist); prop_dictionary_set(sesdict, "nat-policy-list", nplist); error = prop_dictionary_copyout_ioctl(pref, cmd, sesdict); fail: prop_object_release(sesdict); return error; }
int _npf_ruleset_list(int fd, const char *rname, nl_config_t *ncf) { prop_dictionary_t rldict, ret; int error; rldict = prop_dictionary_create(); if (rldict == NULL) { return ENOMEM; } prop_dictionary_set_cstring(rldict, "ruleset-name", rname); prop_dictionary_set_uint32(rldict, "command", NPF_CMD_RULE_LIST); error = prop_dictionary_sendrecv_ioctl(rldict, fd, IOC_NPF_RULE, &ret); if (!error) { prop_array_t rules; rules = prop_dictionary_get(ret, "rules"); if (rules == NULL) { return EINVAL; } prop_object_release(ncf->ncf_rules_list); ncf->ncf_rules_list = rules; } return error; }
prop_dictionary_t cfg_query(bdaddr_t *laddr, bdaddr_t *raddr, const char *service) { prop_dictionary_t dict; sdp_session_t ss; size_t i; dict = prop_dictionary_create(); if (dict == NULL) err(EXIT_FAILURE, "prop_dictionary_create()"); for (i = 0; i < __arraycount(cfgtype); i++) { if (strcasecmp(service, cfgtype[i].name) == 0) { ss = sdp_open(laddr, raddr); if (ss == NULL) err(EXIT_FAILURE, "SDP connection failed"); if (!cfg_search(ss, i, dict)) errx(EXIT_FAILURE, "service %s not found", service); sdp_close(ss); return dict; } } printf("Known config types:\n"); for (i = 0; i < __arraycount(cfgtype); i++) printf("\t%s\t%s\n", cfgtype[i].name, cfgtype[i].description); exit(EXIT_FAILURE); }
nl_rproc_t * npf_rproc_create(const char *name) { prop_dictionary_t rpdict; prop_array_t extcalls; nl_rproc_t *nrp; nrp = malloc(sizeof(nl_rproc_t)); if (nrp == NULL) { return NULL; } rpdict = prop_dictionary_create(); if (rpdict == NULL) { free(nrp); return NULL; } prop_dictionary_set_cstring(rpdict, "name", name); extcalls = prop_array_create(); if (extcalls == NULL) { prop_object_release(rpdict); free(nrp); return NULL; } prop_dictionary_set(rpdict, "extcalls", extcalls); prop_object_release(extcalls); nrp->nrp_dict = rpdict; return nrp; }
int npfctl_remove_rule(u_long cmd, void *data) { struct plistref *pref = data; prop_dictionary_t dict, errdict; prop_object_t obj; const char *name; int error, numrules; /* Retrieve and construct the rule. */ error = prop_dictionary_copyin_ioctl(pref, cmd, &dict); if (error) { return error; } /* Dictionary for error reporting. */ errdict = prop_dictionary_create(); obj = prop_dictionary_get(dict, "name"); name = prop_string_cstring_nocopy(obj); npf_rule_t *rl; error = npf_mk_singlerule(dict, prop_array_create(), &rl, errdict); npf_core_enter(); numrules = npf_named_ruleset_remove(name, npf_core_ruleset(), rl); npf_core_exit(); prop_object_release(dict); /* Error report. */ prop_dictionary_set_int32(errdict, "errno", error); prop_dictionary_set_int32(errdict, "numrules", numrules); prop_dictionary_copyout_ioctl(pref, cmd, errdict); prop_object_release(errdict); return error; }
int main(int argc, char *argv[]) { int fd; int err; prop_dictionary_t dict_in, dict_out; struct plistref prefp; char *xml; err = rump_init(); if (err != 0) printf("rump_init failed with %s\n", strerror(err)); fd = rump_sys_open("/dev/mapper/control", O_RDWR, 0); if (fd == -1) printf("Cannot open control device.\n"); dict_in = prop_dictionary_internalize_from_file("prop2.plist"); dict_out = prop_dictionary_create(); prop_dictionary_externalize_to_pref(dict_in, &prefp); err = rump_sys_ioctl(fd, NETBSD_DM_IOCTL, &prefp); if ( err < 0) printf("ioctl failed %d\n", err); dict_out = prop_dictionary_internalize(prefp.pref_plist); xml = prop_dictionary_externalize(dict_out); printf("%s\n",xml); rump_sys_close(fd); }
nl_rule_t * npf_rule_create(const char *name, uint32_t attr, const char *ifname) { prop_dictionary_t rldict; nl_rule_t *rl; rl = malloc(sizeof(*rl)); if (rl == NULL) { return NULL; } rldict = prop_dictionary_create(); if (rldict == NULL) { free(rl); return NULL; } if (name) { prop_dictionary_set_cstring(rldict, "name", name); } prop_dictionary_set_uint32(rldict, "attributes", attr); if (ifname) { prop_dictionary_set_cstring(rldict, "interface", ifname); } rl->nrl_dict = rldict; return rl; }
nl_table_t * npf_table_create(const char *name, u_int id, int type) { prop_dictionary_t tldict; prop_array_t tblents; nl_table_t *tl; tl = malloc(sizeof(*tl)); if (tl == NULL) { return NULL; } tldict = prop_dictionary_create(); if (tldict == NULL) { free(tl); return NULL; } prop_dictionary_set_cstring(tldict, "name", name); prop_dictionary_set_uint32(tldict, "id", id); prop_dictionary_set_int32(tldict, "type", type); tblents = prop_array_create(); if (tblents == NULL) { prop_object_release(tldict); free(tl); return NULL; } prop_dictionary_set(tldict, "entries", tblents); prop_object_release(tblents); tl->ntl_dict = tldict; return tl; }
int main(int argc, char **argv) { modctl_load_t cmdargs; prop_dictionary_t props; char *propsstr; int ch; int flags; flags = 0; props = prop_dictionary_create(); while ((ch = getopt(argc, argv, "b:fi:s:")) != -1) { switch (ch) { case 'b': parse_param(props, optarg, parse_bool_param); break; case 'f': flags |= MODCTL_LOAD_FORCE; break; case 'i': parse_param(props, optarg, parse_int_param); break; case 's': parse_param(props, optarg, parse_string_param); break; default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; if (argc != 1) usage(); propsstr = prop_dictionary_externalize(props); if (propsstr == NULL) errx(EXIT_FAILURE, "Failed to process properties"); cmdargs.ml_filename = argv[0]; cmdargs.ml_flags = flags; cmdargs.ml_props = propsstr; cmdargs.ml_propslen = strlen(propsstr); if (modctl(MODCTL_LOAD, &cmdargs)) { err(EXIT_FAILURE, NULL); } free(propsstr); prop_object_release(props); exit(EXIT_SUCCESS); }
static prop_dictionary_t _npf_debug_initonce(nl_config_t *ncf) { if (!ncf->ncf_debug) { prop_array_t iflist = prop_array_create(); ncf->ncf_debug = prop_dictionary_create(); prop_dictionary_set(ncf->ncf_debug, "interfaces", iflist); prop_object_release(iflist); } return ncf->ncf_debug; }
void board_info_init(void) { /* * Set up the board properties dictionary. */ if (board_properties != NULL) return; board_properties = prop_dictionary_create(); KASSERT(board_properties != NULL); }
int npf_config_submit(nl_config_t *ncf, int fd) { const char *plist = ncf->ncf_plist; prop_dictionary_t npf_dict; prop_array_t rlset; int error = 0; npf_dict = prop_dictionary_create(); if (npf_dict == NULL) { return ENOMEM; } prop_dictionary_set_uint32(npf_dict, "version", NPF_VERSION); rlset = _npf_ruleset_transform(ncf->ncf_rules_list); if (rlset == NULL) { prop_object_release(npf_dict); return ENOMEM; } prop_object_release(ncf->ncf_rules_list); ncf->ncf_rules_list = rlset; prop_dictionary_set(npf_dict, "rules", ncf->ncf_rules_list); prop_dictionary_set(npf_dict, "algs", ncf->ncf_alg_list); prop_dictionary_set(npf_dict, "rprocs", ncf->ncf_rproc_list); prop_dictionary_set(npf_dict, "tables", ncf->ncf_table_list); prop_dictionary_set(npf_dict, "translation", ncf->ncf_nat_list); prop_dictionary_set_bool(npf_dict, "flush", ncf->ncf_flush); if (ncf->ncf_debug) { prop_dictionary_set(npf_dict, "debug", ncf->ncf_debug); } if (plist) { if (!prop_dictionary_externalize_to_file(npf_dict, plist)) { error = errno; } prop_object_release(npf_dict); return error; } if (fd) { error = prop_dictionary_sendrecv_ioctl(npf_dict, fd, IOC_NPF_RELOAD, &ncf->ncf_err); if (error) { prop_object_release(npf_dict); assert(ncf->ncf_err == NULL); return error; } prop_dictionary_get_int32(ncf->ncf_err, "errno", &error); } prop_object_release(npf_dict); return error; }
int npf_ruleset_flush(int fd, const char *rname) { prop_dictionary_t rldict; rldict = prop_dictionary_create(); if (rldict == NULL) { return ENOMEM; } prop_dictionary_set_cstring(rldict, "ruleset-name", rname); prop_dictionary_set_uint32(rldict, "command", NPF_CMD_RULE_FLUSH); return prop_dictionary_send_ioctl(rldict, fd, IOC_NPF_RULE); }
static int hdaudioctl_list(int fd) { prop_dictionary_t request, response; prop_dictionary_t dict; prop_object_iterator_t iter; prop_object_t obj; prop_array_t array; uint16_t nid, codecid; uint16_t vendor, product; uint32_t subsystem; const char *device = NULL; int error; request = prop_dictionary_create(); if (request == NULL) { fprintf(stderr, "out of memory\n"); return ENOMEM; } error = prop_dictionary_sendrecv_ioctl(request, fd, HDAUDIO_FGRP_INFO, &response); if (error != 0) { perror("HDAUDIO_FGRP_INFO failed"); return error; } array = prop_dictionary_get(response, "function-group-info"); iter = prop_array_iterator(array); prop_object_iterator_reset(iter); while ((obj = prop_object_iterator_next(iter)) != NULL) { dict = (prop_dictionary_t)obj; prop_dictionary_get_uint16(dict, "codecid", &codecid); prop_dictionary_get_uint16(dict, "nid", &nid); prop_dictionary_get_uint16(dict, "vendor-id", &vendor); prop_dictionary_get_uint16(dict, "product-id", &product); prop_dictionary_get_uint32(dict, "subsystem-id", &subsystem); prop_dictionary_get_cstring_nocopy(dict, "device", &device); printf("codecid 0x%02X nid 0x%02X vendor 0x%04X " "product 0x%04X subsystem 0x%08X device %s\n", codecid, nid, vendor, product, subsystem, device ? device : "<none>"); } prop_object_release(array); prop_object_release(response); prop_object_release(request); return 0; }
gboolean drvctl_find_device(const gchar *devnode, prop_dictionary_t *properties) { prop_dictionary_t command_dict; prop_dictionary_t args_dict; prop_dictionary_t results_dict; int err; command_dict = prop_dictionary_create (); args_dict = prop_dictionary_create (); prop_dictionary_set_cstring_nocopy (command_dict, "drvctl-command", "get-properties"); prop_dictionary_set_cstring_nocopy (args_dict, "device-name", devnode); prop_dictionary_set (command_dict, "drvctl-arguments", args_dict); prop_object_release (args_dict); err = prop_dictionary_sendrecv_ioctl (command_dict, drvctl_fd, DRVCTLCOMMAND, &results_dict); prop_object_release (command_dict); if (err) return FALSE; if (prop_dictionary_get_int8 (results_dict, "drvctl-error", &err) == false || err != 0) { prop_object_release (results_dict); return FALSE; } if (properties) { prop_dictionary_t result_data; result_data = prop_dictionary_get (results_dict, "drvctl-result-data"); if (result_data) *properties = prop_dictionary_copy (result_data); } prop_object_release (results_dict); return TRUE; }
static prop_dictionary_t pkgdict_init(void) { prop_array_t a; prop_dictionary_t d; d = prop_dictionary_create(); ATF_REQUIRE(d != NULL); a = provides_init(); ATF_REQUIRE_EQ(prop_dictionary_set(d, "provides", a), true); return d; }
int npf_ruleset_remove(int fd, const char *rname, uint64_t id) { prop_dictionary_t rldict; rldict = prop_dictionary_create(); if (rldict == NULL) { return ENOMEM; } prop_dictionary_set_cstring(rldict, "ruleset-name", rname); prop_dictionary_set_uint32(rldict, "command", NPF_CMD_RULE_REMOVE); prop_dictionary_set_uint64(rldict, "id", id); return prop_dictionary_send_ioctl(rldict, fd, IOC_NPF_RULE); }
int _npf_alg_load(nl_config_t *ncf, const char *name) { prop_dictionary_t al_dict; if (_npf_prop_array_lookup(ncf->ncf_alg_list, "name", name)) return EEXIST; al_dict = prop_dictionary_create(); prop_dictionary_set_cstring(al_dict, "name", name); prop_array_add(ncf->ncf_alg_list, al_dict); prop_object_release(al_dict); return 0; }
void wsdv_keymap_save_default(void) { int32_t v; char key[MAX_KEY_SIZE]; char val[MAX_VAL_SIZE]; pd = prop_dictionary_create(); snprintf(key, MAX_KEY_SIZE-1, "%d", 0x29); //snprintf(val, MAX_VAL_SIZE-1, "%d", 0x29); prop_dictionary_set_int32(pd, key, 0x29); prop_dictionary_externalize_to_file(pd, "map1.plist"); }
void _npf_debug_addif(nl_config_t *ncf, const char *ifname) { prop_dictionary_t ifdict, dbg = _npf_debug_initonce(ncf); prop_array_t iflist = prop_dictionary_get(dbg, "interfaces"); u_int if_idx = if_nametoindex(ifname); if (_npf_prop_array_lookup(iflist, "name", ifname)) { return; } ifdict = prop_dictionary_create(); prop_dictionary_set_cstring(ifdict, "name", ifname); prop_dictionary_set_uint32(ifdict, "index", if_idx); prop_array_add(iflist, ifdict); prop_object_release(ifdict); }
static int quota_handle_cmd_get_version(struct mount *mp, struct lwp *l, prop_dictionary_t cmddict, prop_array_t datas) { struct ufsmount *ump = VFSTOUFS(mp); prop_array_t replies; prop_dictionary_t data; int error = 0; if ((ump->um_flags & (UFS_QUOTA|UFS_QUOTA2)) == 0) return EOPNOTSUPP; replies = prop_array_create(); if (replies == NULL) return ENOMEM; data = prop_dictionary_create(); if (data == NULL) { prop_object_release(replies); return ENOMEM; } #ifdef QUOTA if (ump->um_flags & UFS_QUOTA) { if (!prop_dictionary_set_int8(data, "version", 1)) error = ENOMEM; } else #endif #ifdef QUOTA2 if (ump->um_flags & UFS_QUOTA2) { if (!prop_dictionary_set_int8(data, "version", 2)) error = ENOMEM; } else #endif error = 0; if (error) prop_object_release(data); else if (!prop_array_add_and_rel(replies, data)) error = ENOMEM; if (error) prop_object_release(replies); else if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) error = ENOMEM; return error; }
/* * npfctl_update_rule: reload a specific rule identified by the name. */ int npfctl_update_rule(u_long cmd, void *data) { struct plistref *pref = data; prop_dictionary_t dict, errdict; prop_array_t subrules; prop_object_t obj; npf_ruleset_t *rlset; const char *name; int error; /* Retrieve and construct the rule. */ error = prop_dictionary_copyin_ioctl(pref, cmd, &dict); if (error) { return error; } /* Dictionary for error reporting. */ errdict = prop_dictionary_create(); /* Create the ruleset and construct sub-rules. */ rlset = npf_ruleset_create(); subrules = prop_dictionary_get(dict, "subrules"); error = npf_mk_subrules(rlset, subrules, NULL, errdict); if (error) { goto out; } /* Lookup the rule by name, and replace its subset (sub-rules). */ obj = prop_dictionary_get(dict, "name"); name = prop_string_cstring_nocopy(obj); if (npf_ruleset_replace(name, rlset) == NULL) { /* Not found. */ error = ENOENT; out: /* Error path. */ npf_ruleset_destroy(rlset); } prop_object_release(dict); /* Error report. */ prop_dictionary_set_int32(errdict, "errno", error); prop_dictionary_copyout_ioctl(pref, cmd, errdict); prop_object_release(errdict); return error; }
static int hdaudioctl_set(int fd, int argc, char *argv[]) { prop_dictionary_t request, response; prop_array_t config = NULL; uint16_t nid, codecid; int error; if (argc < 2 || argc > 3) usage(); codecid = strtol(argv[0], NULL, 0); nid = strtol(argv[1], NULL, 0); if (argc == 3) { config = prop_array_internalize_from_file(argv[2]); if (config == NULL) { fprintf(stderr, "couldn't load configuration from %s\n", argv[2]); return EIO; } } request = prop_dictionary_create(); if (request == NULL) { fprintf(stderr, "out of memory\n"); return ENOMEM; } prop_dictionary_set_uint16(request, "codecid", codecid); prop_dictionary_set_uint16(request, "nid", nid); if (config) prop_dictionary_set(request, "pin-config", config); error = prop_dictionary_sendrecv_ioctl(request, fd, HDAUDIO_FGRP_SETCONFIG, &response); if (error != 0) { perror("HDAUDIO_FGRP_SETCONFIG failed"); return error; } prop_object_release(response); prop_object_release(request); return 0; }
nl_ext_t * npf_ext_construct(const char *name) { nl_ext_t *ext; ext = malloc(sizeof(*ext)); if (ext == NULL) { return NULL; } ext->nxt_name = strdup(name); if (ext->nxt_name == NULL) { free(ext); return NULL; } ext->nxt_dict = prop_dictionary_create(); return ext; }
prop_dictionary_t testcase_get_result_dict(prop_dictionary_t testcase) { prop_dictionary_t result_dict; int r; result_dict = prop_dictionary_get(testcase, "result"); if (result_dict == NULL) { result_dict = prop_dictionary_create(); if (result_dict == NULL) err(1, "could not allocate new result dict"); r = prop_dictionary_set(testcase, "result", result_dict); if (r == 0) err(1, "prop_dictionary operation failed"); } return result_dict; }
static void _dm_rename_kern(struct dm_task *dmt) { prop_dictionary_t dm_dict_in, dm_dict_out; dm_dict_in = prop_dictionary_create(); /* Dictionary send to kernel */ /* Set command name to dictionary */ prop_dictionary_set_cstring(dm_dict_in, DM_IOCTL_COMMAND, "nrename"); prop_dictionary_set_cstring(dm_dict_in, "dev_name", dmt->dev_name); prop_dictionary_set_cstring(dm_dict_in, "new_name", dmt->newname); /* Set flags to dictionary. */ prop_dictionary_set_uint32(dm_dict_in,DM_IOCTL_FLAGS,0); if (prop_dictionary_sendrecv_ioctl(dm_dict_in,_control_fd, NETBSD_DM_IOCTL,&dm_dict_out) != 0) { log_error("rename failed"); } }
prop_array_t udev_getdevs(int devfd) { prop_dictionary_t pd, rpd; prop_string_t ps; prop_array_t pa; pd = prop_dictionary_create(); if (pd == NULL) { err(1, "prop_dictionary_create()"); } ps = prop_string_create_cstring("getdevs"); if (ps == NULL) { prop_object_release(pd); err(1, "prop_string_create_cstring()"); } if (prop_dictionary_set(pd, "command", ps) == false) { prop_object_release(ps); prop_object_release(pd); err(1, "prop_dictionary_set()"); } prop_object_release(ps); /* Send dictionary to kernel space */ if (prop_dictionary_sendrecv_ioctl(pd, devfd, UDEVPROP, &rpd) != 0) err(1, "prop_array_recv_ioctl()"); prop_object_release(pd); pa = prop_dictionary_get(rpd, "array"); if (pa == NULL) goto out; prop_object_retain(pa); out: prop_object_release(rpd); return pa; }
static int hdaudioctl_get(int fd, int argc, char *argv[]) { prop_dictionary_t request, response; prop_array_t config; uint16_t nid, codecid; const char *xml; int error; if (argc != 2) usage(); codecid = strtol(argv[0], NULL, 0); nid = strtol(argv[1], NULL, 0); request = prop_dictionary_create(); if (request == NULL) { fprintf(stderr, "out of memory\n"); return ENOMEM; } prop_dictionary_set_uint16(request, "codecid", codecid); prop_dictionary_set_uint16(request, "nid", nid); error = prop_dictionary_sendrecv_ioctl(request, fd, HDAUDIO_FGRP_GETCONFIG, &response); if (error != 0) { perror("HDAUDIO_FGRP_GETCONFIG failed"); return error; } config = prop_dictionary_get(response, "pin-config"); xml = prop_array_externalize(config); printf("%s\n", xml); prop_object_release(response); prop_object_release(request); return 0; }
int npf_sessions_send(int fd, const char *fpath) { prop_dictionary_t sdict; int error; if (fpath) { sdict = prop_dictionary_internalize_from_file(fpath); if (sdict == NULL) { return errno; } } else { /* Empty: will flush the sessions. */ prop_array_t selist = prop_array_create(); sdict = prop_dictionary_create(); prop_dictionary_set(sdict, "session-list", selist); prop_object_release(selist); } error = prop_dictionary_send_ioctl(sdict, fd, IOC_NPF_SESSIONS_LOAD); prop_object_release(sdict); return error; }