Exemplo n.º 1
0
// Ls lists a directory in the guest operating system.
//
// Parameters:
//
//   dir: The path name of a directory to be listed.
//
// Remarks:
//
//   * Only absolute paths should be used for files in the guest; the resolution
//     of relative paths is not specified.
//
// Since VMware Workstation 6.0
// Minimum Supported Guest OS: Microsoft Windows NT Series, Linux
func (g *Guest) Ls(dir string) ([]*GuestFile, error) {
	var jobHandle C.VixHandle = C.VIX_INVALID_HANDLE
	var err C.VixError = C.VIX_OK
	var files []*GuestFile

	guestdir := C.CString(dir)
	defer C.free(unsafe.Pointer(guestdir))

	jobHandle = C.VixVM_ListDirectoryInGuest(g.handle, guestdir, 0, nil, nil)
	defer C.Vix_ReleaseHandle(jobHandle)

	err = C.vix_job_wait(jobHandle)
	if C.VIX_OK != err {
		return nil, &Error{
			Operation: "guest.Ls.ListDirectoryInGuest",
			Code:      int(err & 0xFFFF),
			Text:      C.GoString(C.Vix_GetErrorText(err, nil)),
		}
	}

	num := C.VixJob_GetNumProperties(jobHandle, C.VIX_PROPERTY_JOB_RESULT_ITEM_NAME)
	for i := 0; i < int(num); i++ {
		var name *C.char
		var size *C.int64
		var modtime *C.int64
		var attrs *C.int

		gfile := &GuestFile{}

		err = C.get_guest_file(jobHandle, C.int(i), name, size, modtime, attrs)
		if C.VIX_OK != err {
			return nil, &Error{
				Operation: "guest.Ls.get_guest_file",
				Code:      int(err & 0xFFFF),
				Text:      C.GoString(C.Vix_GetErrorText(err, nil)),
			}
		}

		gfile.Path = C.GoString(name)
		C.Vix_FreeBuffer(unsafe.Pointer(name))

		gfile.Size = int64(*size)
		gfile.Modtime = int64(*modtime)
		gfile.Attrs = FileAttr(*attrs)

		files = append(files, gfile)
	}

	return files, nil
}
Exemplo n.º 2
0
// Ps lists the running processes in the guest operating system.
//
// Since Workstation 6.0
// Minimum Supported Guest OS: Microsoft Windows NT Series, Linux
func (g *Guest) Ps() ([]*GuestProcess, error) {
	var jobHandle C.VixHandle = C.VIX_INVALID_HANDLE
	var err C.VixError = C.VIX_OK
	var processes []*GuestProcess

	jobHandle = C.VixVM_ListProcessesInGuest(g.handle, 0, nil, nil)
	defer C.Vix_ReleaseHandle(jobHandle)

	err = C.vix_job_wait(jobHandle)
	if C.VIX_OK != err {
		return nil, &Error{
			Operation: "guest.Ps",
			Code:      int(err & 0xFFFF),
			Text:      C.GoString(C.Vix_GetErrorText(err, nil)),
		}
	}

	num := C.VixJob_GetNumProperties(jobHandle, C.VIX_PROPERTY_JOB_RESULT_ITEM_NAME)
	for i := 0; i < int(num); i++ {
		var name *C.char
		var pid *C.uint64
		var owner *C.char
		var cmdline *C.char
		var isDebugged *C.Bool
		var startTime *C.int

		gprocess := &GuestProcess{}

		err = C.get_guest_process(jobHandle, C.int(i),
			name,
			pid,
			owner,
			cmdline,
			isDebugged,
			startTime)

		if C.VIX_OK != err {
			return nil, &Error{
				Operation: "guest.Ps.get_guest_process",
				Code:      int(err & 0xFFFF),
				Text:      C.GoString(C.Vix_GetErrorText(err, nil)),
			}
		}

		gprocess.Name = C.GoString(name)
		C.Vix_FreeBuffer(unsafe.Pointer(name))

		gprocess.Pid = uint64(*pid)

		gprocess.Owner = C.GoString(owner)
		C.Vix_FreeBuffer(unsafe.Pointer(owner))

		gprocess.Cmdline = C.GoString(cmdline)
		C.Vix_FreeBuffer(unsafe.Pointer(cmdline))

		if *isDebugged == 1 {
			gprocess.IsDebugged = true
		} else {
			gprocess.IsDebugged = false
		}

		gprocess.StartTime = int(*startTime)

		processes = append(processes, gprocess)
	}

	return processes, nil
}