static status_t
vmi_init_private(
vmi_instance_t *vmi,
uint32_t flags,
uint64_t id,
const char *name,
vmi_config_t config)
{
uint32_t access_mode = flags & 0x0000FFFF;
uint32_t init_mode = flags & 0x00FF0000;
uint32_t config_mode = flags & 0xFF000000;
status_t status = VMI_FAILURE;
/* allocate memory for instance structure */
*vmi = (vmi_instance_t) safe_malloc(sizeof(struct vmi_instance));
memset(*vmi, 0, sizeof(struct vmi_instance));
/* initialize instance struct to default values */
dbprint(VMI_DEBUG_CORE, "LibVMI Version 0.11.0\n"); //TODO change this with each release
/* save the flags and init mode */
(*vmi)->flags = flags;
(*vmi)->init_mode = init_mode;
(*vmi)->config_mode = config_mode;
/* the config hash table is set up later based on mode */
(*vmi)->config = NULL;
/* set page mode to unknown */
(*vmi)->page_mode = VMI_PM_UNKNOWN;
/* setup the caches */
pid_cache_init(*vmi);
sym_cache_init(*vmi);
rva_cache_init(*vmi);
v2p_cache_init(*vmi);
if ( init_mode & VMI_INIT_SHM_SNAPSHOT ) {
#if ENABLE_SHM_SNAPSHOT == 1
v2m_cache_init(*vmi);
#else
errprint("LibVMI wasn't compiled with SHM support!\n");
status = VMI_FAILURE;
goto error_exit;
#endif
}
/* connecting to xen, kvm, file, etc */
if (VMI_FAILURE == set_driver_type(*vmi, access_mode, id, name)) {
goto error_exit;
}
/* driver-specific initilization */
if (VMI_FAILURE == driver_init(*vmi)) {
goto error_exit;
}
dbprint(VMI_DEBUG_CORE, "--completed driver init.\n");
/* resolve the id and name */
if (VMI_FAILURE == set_id_and_name(*vmi, access_mode, id, name)) {
goto error_exit;
}
/* init vmi for specific file/domain through the driver */
if (VMI_FAILURE == driver_init_vmi(*vmi)) {
goto error_exit;
}
/* setup the page offset size */
if (VMI_FAILURE == init_page_offset(*vmi)) {
goto error_exit;
}
/* get the memory size */
if (driver_get_memsize(*vmi, &(*vmi)->allocated_ram_size, &(*vmi)->max_physical_address) == VMI_FAILURE) {
errprint("Failed to get memory size.\n");
goto error_exit;
}
dbprint(VMI_DEBUG_CORE, "**set size = %"PRIu64" [0x%"PRIx64"]\n", (*vmi)->size,
(*vmi)->size);
// for file mode we need os-specific heuristics to deduce the architecture
// for live mode, having arch_interface set even in VMI_PARTIAL mode
// allows use of dtb-based translation methods.
if (VMI_FILE != (*vmi)->mode) {
if(VMI_FAILURE == arch_init(*vmi)) {
if (init_mode & VMI_INIT_COMPLETE) {
dbprint(VMI_DEBUG_CORE, "--failed to determine architecture of live vm and INIT_COMPLETE.\n");
goto error_exit;
} else {
dbprint(VMI_DEBUG_CORE, "--failed to determine architecture of live vm and INIT_PARTIAL, continuing.\n");
}
} else {
dbprint(VMI_DEBUG_CORE, "--succesfully completed architecture init.\n");
}
}
/* we check VMI_INIT_COMPLETE first as
VMI_INIT_PARTIAL is not exclusive */
//.........这里部分代码省略.........
开发者ID:LoongWin,项目名称:libvmi,代码行数:101,代码来源:core.c
示例5: guestfs_int_send
int
guestfs_int_send (guestfs_h *g, int proc_nr,
uint64_t progress_hint, uint64_t optargs_bitmask,
xdrproc_t xdrp, char *args)
{
struct guestfs_message_header hdr;
XDR xdr;
uint32_t len;
int serial = g->msg_next_serial++;
ssize_t r;
CLEANUP_FREE char *msg_out = NULL;
size_t msg_out_size;
if (!g->conn) {
guestfs_int_unexpected_close_error (g);
return -1;
}
/* We have to allocate this message buffer on the heap because
* it is quite large (although will be mostly unused). We
* can't allocate it on the stack because in some environments
* we have quite limited stack space available, notably when
* running in the JVM.
*/
msg_out = safe_malloc (g, GUESTFS_MESSAGE_MAX + 4);
xdrmem_create (&xdr, msg_out + 4, GUESTFS_MESSAGE_MAX, XDR_ENCODE);
/* Serialize the header. */
hdr.prog = GUESTFS_PROGRAM;
hdr.vers = GUESTFS_PROTOCOL_VERSION;
hdr.proc = proc_nr;
hdr.direction = GUESTFS_DIRECTION_CALL;
hdr.serial = serial;
hdr.status = GUESTFS_STATUS_OK;
hdr.progress_hint = progress_hint;
hdr.optargs_bitmask = optargs_bitmask;
if (!xdr_guestfs_message_header (&xdr, &hdr)) {
error (g, _("xdr_guestfs_message_header failed"));
return -1;
}
/* Serialize the args. If any, because some message types
* have no parameters.
*/
if (xdrp) {
if (!(*xdrp) (&xdr, args, 0)) {
error (g, _("dispatch failed to marshal args"));
return -1;
}
}
/* Get the actual length of the message, resize the buffer to match
* the actual length, and write the length word at the beginning.
*/
len = xdr_getpos (&xdr);
xdr_destroy (&xdr);
msg_out = safe_realloc (g, msg_out, len + 4);
msg_out_size = len + 4;
xdrmem_create (&xdr, msg_out, 4, XDR_ENCODE);
xdr_uint32_t (&xdr, &len);
/* Look for stray daemon cancellation messages from earlier calls
* and ignore them.
*/
r = check_daemon_socket (g);
/* r == -2 (cancellation) is ignored */
if (r == -1)
return -1;
if (r == 0) {
guestfs_int_unexpected_close_error (g);
child_cleanup (g);
return -1;
}
/* Send the message. */
r = g->conn->ops->write_data (g, g->conn, msg_out, msg_out_size);
if (r == -1)
return -1;
if (r == 0) {
guestfs_int_unexpected_close_error (g);
child_cleanup (g);
return -1;
}
return serial;
}
int ea_setxattr_rcs(const char *path, const char *name, const char *value, size_t size)
{
metadata_t *metadata;
version_t *version;
rcs_ignore_deleted = 1;
metadata = rcs_translate_to_metadata(path, rcs_version_path);
rcs_ignore_deleted = 0;
if (!metadata)
return -ENOENT;
if (!strcmp(name,"rcs.purge"))
{
/* Copy the value to NUL-terminate it */
char *local;
local = safe_malloc(size + 1);
local[size] = '\0';
memcpy(local, value, size);
// Get the full path to the metadatafile
char *mdfile=helper_build_meta_name(path, METADATA_PREFIX);
if (!mdfile)
return -ENOENT;
int c=1; // how many versions to delete
int vnum=1; // number of versions
if(!strcmp(local,"A")) {
// Delete them all
// we don't have to count the versions
// we just leave c and vnum at 1
} else {
// we have a number, so set c to it
c=atoi(local);
// Count the number of versions there are
version = metadata->md_versions;
while(version->v_next) {
version=version->v_next;
vnum++;
}
}
/* Let's do this... Crawl through the list, nulling
* next's and unlinking files
*/
version_t *next;
version = metadata->md_versions;
if(c >= vnum) {
// we're toasting them all...
while(version) {
//unlink file.. scary!
unlink(version->v_rfile);
/* No need to clean up version data.
* This is done later by rcs_free_metadata */
version=version->v_next;
}
// Free the metadata from cache
cache_drop_metadata(metadata);
rcs_free_metadata(metadata);
// kill the metadata file too.. SCARY!!!
unlink(mdfile);
} else {
// cull
vnum-=c; // number of versions we want to _keep_.
while(version) {
if(vnum > 1) {
// we want to keep this version
vnum--;
version=version->v_next;
}
else if (vnum == 1) {
// this is the last version to keep
vnum--;
next=version->v_next;
version->v_next = NULL;
version=next;
}
else {
//delete this version
//unlink file.. scary!
unlink(version->v_rfile);
next=version->v_next;
free(version->v_rfile);
free(version);
version=next;
}
}
// We've made changes to the metadata, and got at least one
// version left.. need to update it
if (write_metadata_file(mdfile, metadata) == -1) {
free(mdfile);
return -errno;
}
}
//.........这里部分代码省略.........
开发者ID:butesa,项目名称:fuse-copyfs,代码行数:101,代码来源:ea.c
示例8: mutt_parse_hook
//.........这里部分代码省略.........
/* At this stage remain only message-hooks, reply-hooks, send-hooks,
* send2-hooks, save-hooks, and fcc-hooks: All those allowing full
* patterns. If given a simple regexp, we expand $default_hook.
*/
strfcpy (tmp, pattern.data, sizeof (tmp));
mutt_check_simple (tmp, sizeof (tmp), DefaultHook);
FREE (&pattern.data);
memset (&pattern, 0, sizeof (pattern));
pattern.data = safe_strdup (tmp);
}
if (data & (MUTT_MBOXHOOK | MUTT_SAVEHOOK | MUTT_FCCHOOK))
{
strfcpy (path, command.data, sizeof (path));
mutt_expand_path (path, sizeof (path));
FREE (&command.data);
memset (&command, 0, sizeof (command));
command.data = safe_strdup (path);
}
/* check to make sure that a matching hook doesn't already exist */
for (ptr = Hooks; ptr; ptr = ptr->next)
{
if (ptr->type == data &&
ptr->rx.not == not &&
!mutt_strcmp (pattern.data, ptr->rx.pattern))
{
if (data & (MUTT_FOLDERHOOK | MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_MESSAGEHOOK | MUTT_ACCOUNTHOOK | MUTT_REPLYHOOK | MUTT_CRYPTHOOK))
{
/* these hooks allow multiple commands with the same
* pattern, so if we've already seen this pattern/command pair, just
* ignore it instead of creating a duplicate */
if (!mutt_strcmp (ptr->command, command.data))
{
FREE (&command.data);
FREE (&pattern.data);
return 0;
}
}
else
{
/* other hooks only allow one command per pattern, so update the
* entry with the new command. this currently does not change the
* order of execution of the hooks, which i think is desirable since
* a common action to perform is to change the default (.) entry
* based upon some other information. */
FREE (&ptr->command);
ptr->command = command.data;
FREE (&pattern.data);
return 0;
}
}
if (!ptr->next)
break;
}
if (data & (MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_SAVEHOOK | MUTT_FCCHOOK | MUTT_MESSAGEHOOK | MUTT_REPLYHOOK))
{
if ((pat = mutt_pattern_comp (pattern.data,
(data & (MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_FCCHOOK)) ? 0 : MUTT_FULL_MSG,
err)) == NULL)
goto error;
}
else
{
/* Hooks not allowing full patterns: Check syntax of regexp */
rx = safe_malloc (sizeof (regex_t));
#ifdef MUTT_CRYPTHOOK
if ((rc = REGCOMP (rx, NONULL(pattern.data), ((data & (MUTT_CRYPTHOOK|MUTT_CHARSETHOOK|MUTT_ICONVHOOK)) ? REG_ICASE : 0))) != 0)
#else
if ((rc = REGCOMP (rx, NONULL(pattern.data), (data & (MUTT_CHARSETHOOK|MUTT_ICONVHOOK)) ? REG_ICASE : 0)) != 0)
#endif /* MUTT_CRYPTHOOK */
{
regerror (rc, rx, err->data, err->dsize);
FREE (&rx);
goto error;
}
}
if (ptr)
{
ptr->next = safe_calloc (1, sizeof (HOOK));
ptr = ptr->next;
}
else
Hooks = ptr = safe_calloc (1, sizeof (HOOK));
ptr->type = data;
ptr->command = command.data;
ptr->pattern = pat;
ptr->rx.pattern = pattern.data;
ptr->rx.rx = rx;
ptr->rx.not = not;
return 0;
error:
FREE (&pattern.data);
FREE (&command.data);
return (-1);
}
请发表评论