示例#1
0
char *select_image(char *image)
/* Look image up on the filesystem, if it is a file then we're done, but
 * if its a directory then we want the newest file in that directory.  If
 * it doesn't exist at all, then see if it is 'number:number' and get the
 * image from that absolute offset off the disk.
 */
{
	ino_t image_ino;
	struct stat st;

	image= strcpy(malloc((strlen(image) + 1 + NAME_MAX + 1)
						 * sizeof(char)), image);

	fsok= r_super(&block_size) != 0;
	if (!fsok || (image_ino= r_lookup(ROOT_INO, image)) == 0) {
		char *size;

		if (numprefix(image, &size) && *size++ == ':'
						&& numeric(size)) {
			vir2sec= flat_vir2sec;
			image_off= a2l(image);
			image_sectors= a2l(size);
			strcpy(image, "Minix");
			return image;
		}
		if (!fsok)
			printf("No image selected\n");
		else
			printf("Can't load %s: %s\n", image, unix_err(errno));
		goto bail_out;
	}

	r_stat(image_ino, &st);
	image_bytes = st.st_size;

	if (!S_ISREG(st.st_mode)) {
		char *version= image + strlen(image);
		char dots[NAME_MAX + 1];

		if (!S_ISDIR(st.st_mode)) {
			printf("%s: %s\n", image, unix_err(ENOTDIR));
			goto bail_out;
		}
		(void) r_readdir(dots);
		(void) r_readdir(dots);	/* "." & ".." */
		*version++= '/';
		*version= 0;
		if ((image_ino= latest_version(version, &st)) == 0) {
			printf("There are no images in %s\n", image);
			goto bail_out;
		}
		r_stat(image_ino, &st);
	}
	vir2sec= file_vir2sec;
	image_sectors= (st.st_size + SECTOR_SIZE - 1) >> SECTOR_SHIFT;
	return image;
bail_out:
	free(image);
	return nil;
}
示例#2
0
static SInt32 _CFUserNotificationSendRequest(CFAllocatorRef allocator, CFStringRef sessionID, mach_port_t replyPort, SInt32 token, CFTimeInterval timeout, CFOptionFlags flags, CFDictionaryRef dictionary) {
    CFDictionaryRef modifiedDictionary = NULL;
    SInt32 retval = ERR_SUCCESS, itimeout = (timeout > 0.0 && timeout < INT_MAX) ? (SInt32)timeout : 0;
    CFDataRef data;
    mach_msg_base_t *msg = NULL;
    mach_port_t bootstrapPort = MACH_PORT_NULL, serverPort = MACH_PORT_NULL;
    CFIndex size;
    char namebuffer[MAX_PORT_NAME_LENGTH + 1];
    
    strlcpy(namebuffer, NOTIFICATION_PORT_NAME, sizeof(namebuffer));
    if (sessionID) {
        char sessionid[MAX_PORT_NAME_LENGTH + 1];
        CFIndex len = MAX_PORT_NAME_LENGTH - sizeof(NOTIFICATION_PORT_NAME) - sizeof(NOTIFICATION_PORT_NAME_SUFFIX);
        CFStringGetBytes(sessionID, CFRangeMake(0, CFStringGetLength(sessionID)), kCFStringEncodingUTF8, 0, false, (uint8_t *)sessionid, len, &size);
        sessionid[len - 1] = '\0';
        strlcat(namebuffer, NOTIFICATION_PORT_NAME_SUFFIX, sizeof(namebuffer));
        strlcat(namebuffer, sessionid, sizeof(namebuffer));
    }

    retval = task_get_bootstrap_port(mach_task_self(), &bootstrapPort);
    if (ERR_SUCCESS == retval && MACH_PORT_NULL != bootstrapPort) retval = bootstrap_look_up2(bootstrapPort, namebuffer, &serverPort, 0, 0);
    if (ERR_SUCCESS == retval && MACH_PORT_NULL != serverPort) {
        modifiedDictionary = _CFUserNotificationModifiedDictionary(allocator, dictionary, token, itimeout, _CFProcessNameString());
        if (modifiedDictionary) {
            data = CFPropertyListCreateXMLData(allocator, modifiedDictionary);
            if (data) {
                size = sizeof(mach_msg_base_t) + ((CFDataGetLength(data) + 3) & (~0x3));
                msg = (mach_msg_base_t *)CFAllocatorAllocate(kCFAllocatorSystemDefault, size, 0);
                if (__CFOASafe) __CFSetLastAllocationEventName(msg, "CFUserNotification (temp)");
                if (msg) {
                    memset(msg, 0, size);
                    msg->header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE);
                    msg->header.msgh_size = size;
                    msg->header.msgh_remote_port = serverPort;
                    msg->header.msgh_local_port = replyPort;
                    msg->header.msgh_id = flags;
                    msg->body.msgh_descriptor_count = 0;
                    CFDataGetBytes(data, CFRangeMake(0, CFDataGetLength(data)), (uint8_t *)msg + sizeof(mach_msg_base_t));
                    //CFShow(CFStringCreateWithBytes(kCFAllocatorSystemDefault, (UInt8 *)msg + sizeof(mach_msg_base_t), CFDataGetLength(data), kCFStringEncodingUTF8, false));
                    retval = mach_msg((mach_msg_header_t *)msg, MACH_SEND_MSG|MACH_SEND_TIMEOUT, size, 0, MACH_PORT_NULL, MESSAGE_TIMEOUT, MACH_PORT_NULL);
                    CFAllocatorDeallocate(kCFAllocatorSystemDefault, msg);
                } else {
                    retval = unix_err(ENOMEM);
                }
                CFRelease(data);
            } else {
                retval = unix_err(ENOMEM);
            }
            CFRelease(modifiedDictionary);
        } else {
            retval = unix_err(ENOMEM);
        }
    }
    return retval;
}
示例#3
0
CFUserNotificationRef CFUserNotificationCreate(CFAllocatorRef allocator, CFTimeInterval timeout, CFOptionFlags flags, SInt32 *error, CFDictionaryRef dictionary) {
    CHECK_FOR_FORK();
    CFUserNotificationRef userNotification = NULL;
    SInt32 retval = ERR_SUCCESS;
    static uint16_t tokenCounter = 0;
    SInt32 token = ((getpid() << 16) | (tokenCounter++));
    CFStringRef sessionID = (dictionary ? CFDictionaryGetValue(dictionary, kCFUserNotificationSessionIDKey) : NULL);
    mach_port_t replyPort = MACH_PORT_NULL;

    if (!allocator) allocator = __CFGetDefaultAllocator();
    retval = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &replyPort);
    if (ERR_SUCCESS == retval && MACH_PORT_NULL != replyPort) retval = _CFUserNotificationSendRequest(allocator, sessionID, replyPort, token, timeout, flags, dictionary);
    if (ERR_SUCCESS == retval) {
        userNotification = (CFUserNotificationRef)_CFRuntimeCreateInstance(allocator, CFUserNotificationGetTypeID(), sizeof(struct __CFUserNotification) - sizeof(CFRuntimeBase), NULL);
        if (userNotification) {
            userNotification->_replyPort = replyPort;
            userNotification->_token = token;
            userNotification->_timeout = timeout;
            userNotification->_requestFlags = flags;
            userNotification->_responseFlags = 0;
            userNotification->_sessionID = NULL;
            userNotification->_responseDictionary = NULL;
            userNotification->_machPort = NULL;
            userNotification->_callout = NULL;
            if (sessionID) userNotification->_sessionID = CFStringCreateCopy(allocator, sessionID);
        } else {
            retval = unix_err(ENOMEM);
        }
    } else {
        if (dictionary) CFUserNotificationLog(CFDictionaryGetValue(dictionary, kCFUserNotificationAlertHeaderKey), CFDictionaryGetValue(dictionary, kCFUserNotificationAlertMessageKey));
    }
    if (ERR_SUCCESS != retval && MACH_PORT_NULL != replyPort) mach_port_destroy(mach_task_self(), replyPort);
    if (error) *error = retval;
    return userNotification;
}
示例#4
0
文件: devmem.c 项目: braincat/uwin
static int devmem_map(HANDLE h, off64_t *addr, PDWORD len, PDWORD vaddr, int oflags)
{
	NTSTATUS	r;
	PHYSICAL_ADDRESS	base;
	unsigned long	am;

	switch(oflags & O_ACCMODE)
	{
	case O_RDONLY:
		am = PAGE_READONLY;
		break;
	case O_WRONLY:
	case O_RDWR:
		am = PAGE_READWRITE;
		break;
	}

	*vaddr = 0;
	base.QuadPart = (ULONGLONG) *addr;
	r = NtMapViewOfSection(h, (HANDLE) -1, (PVOID) vaddr, 0, *len, &base, len, ViewShare, 0, am);
	if(!NT_SUCCESS(r))
	{
		logerr(0, "NtMapViewOfSection failed");
		errno = unix_err(RtlNtStatusToDosError(r));
		return 0;
	}

	*addr = base.QuadPart;
	return 1;
}
示例#5
0
DAReturn _DADiskSetEncoding( DADiskRef disk, CFStringEncoding encoding )
{
    CFMutableArrayRef keys   = NULL;
    CFStringRef       name1  = NULL;
    CFStringRef       name2  = NULL;
    CFURLRef          path1  = NULL;
    CFURLRef          path2  = NULL;
    DAReturn          status = kDAReturnSuccess;

    path1 = DADiskGetDescription( disk, kDADiskDescriptionVolumePathKey );
    if ( path1 == NULL )  { status = kDAReturnBadArgument; goto _DADiskSetEncodingErr; }

    status = __DAFileSystemSetEncoding( DADiskGetFileSystem( disk ), path1, encoding );
    if ( status )  { status = unix_err( status ); goto _DADiskSetEncodingErr; }

    keys = CFArrayCreateMutable( kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks );
    if ( keys == NULL )  { status = kDAReturnNoResources; goto _DADiskSetEncodingErr; }

    name1 = DADiskGetDescription( disk, kDADiskDescriptionVolumeNameKey );
    if ( name1 == NULL )  { status = kDAReturnError; goto _DADiskSetEncodingErr; }

    name2 = _DAFileSystemCopyName( DADiskGetFileSystem( disk ), path1 );
    if ( name2 == NULL )  { status = kDAReturnError; goto _DADiskSetEncodingErr; }

    status = CFEqual( name1, name2 );
///w:start
//  if ( status )  { status = kDAReturnSuccess; goto _DADiskSetEncodingErr; }
///w:stop

    DADiskSetDescription( disk, kDADiskDescriptionVolumeNameKey, name2 );

    CFArrayAppendValue( keys, kDADiskDescriptionVolumeNameKey );

///w:start
    if ( status == FALSE )
///w:stop
    path2 = DAMountCreateMountPointWithAction( disk, kDAMountPointActionMove );
///w:start
    status = kDAReturnSuccess;
///w:stop

    if ( path2 )
    {
        DADiskSetBypath( disk, path2 );

        DADiskSetDescription( disk, kDADiskDescriptionVolumePathKey, path2 );

        CFArrayAppendValue( keys, kDADiskDescriptionVolumePathKey );
    }

    DADiskDescriptionChangedCallback( disk, keys );

_DADiskSetEncodingErr:

    if ( keys  )  CFRelease( keys  );
    if ( name2 )  CFRelease( name2 );
    if ( path2 )  CFRelease( path2 );

    return status;
}
示例#6
0
文件: eject.c 项目: braincat/uwin
int eject(const char* path)
{
	char	drive[2 * PATH_MAX];
	char	volume[sizeof(drive)];

	if (!ejectstate.initialized)
		ejectinit();
	if (ejectstate.initialized < 0)
	{
		errno = ENOSYS;
		return -1;
	}
	if (!ejectstate.GetVolumePathName(path, drive, sizeof(drive)))
	{
		logerr(2, "eject %s GetVolumePathName failed", path);
		goto bad;
	}
	if (!ejectstate.GetVolumeNameForVolumeMountPoint(drive, volume, sizeof(volume)))
	{
		logerr(2, "eject %s GetVolumeNameForVolumeMountPoint %s failed", path, drive);
		goto bad;
	}
	if (ejectvolume(volume))
		goto bad;
	logmsg(0, "eject %s volume %s", path, volume);
	return 0;
 bad:
	errno = unix_err(GetLastError());
	return -1;
}
示例#7
0
文件: devmem.c 项目: braincat/uwin
static void devmem_unmap(DWORD addr)
{
	NTSTATUS	r;

	r = NtUnmapViewOfSection((HANDLE) -1, (PVOID)addr);

	if(!NT_SUCCESS(r))
	{
		logerr(0, "NtUnmapViewOfSection failed");
		errno = unix_err(RtlNtStatusToDosError(r));
	}
}
示例#8
0
static int dump_file(struct tree_state *t, char *name, char *file)
{
	struct file_state f;
	int fd;
	Elf_Scn *scn;
	GElf_Shdr shdr;

	if ((dup_mode == HIDE_DUPS) && seen(t, name))
		return 0;

	indent(t); printf("%s", name);

	if ((dup_mode == PRUNE_DUPS) && seen(t, name)) {
		printf("...\n");
		return 0;
	} else {
		printf(":\n");
	}

	see(t, name);

	f.t = t;

	fd = open(file, O_RDONLY);
	if (fd < 0) {
		unix_err("open(%s) failed", file);
		return -1;
	}

	f.e = elf_begin(fd, ELF_C_READ, NULL);
	if (!f.e) {
		elf_err("elf_begin failed on %s", file);
		return -1;
	}

	scn = find_scn(&f, SHT_STRTAB, NULL, &shdr);
	f.strtab_data = elf_getdata(scn, NULL);
	if (!f.strtab_data) {
		app_err("%s has no strtab section", file);
		return -1;
	}

	scn = NULL;
	while ((scn = find_scn(&f, SHT_DYNAMIC, scn, &shdr))) {
		dump_dynamic(&f, scn, &shdr);
	}

	elf_end(f.e);
	close(fd);

	return 0;
}
示例#9
0
DAReturn _DADiskSetAdoption( DADiskRef disk, Boolean adoption )
{
    CFURLRef path;
    DAReturn status;

    path = DADiskGetDescription( disk, kDADiskDescriptionVolumePathKey );
    if ( path == NULL )  { status = kDAReturnBadArgument; goto _DADiskSetAdoptionErr; }

    status = __DAFileSystemSetAdoption( DADiskGetFileSystem( disk ), path, adoption );
    if ( status )  { status = unix_err( status ); goto _DADiskSetAdoptionErr; }

_DADiskSetAdoptionErr:

    return status;
}
SInt32 CFUserNotificationReceiveResponse(CFUserNotificationRef userNotification, CFTimeInterval timeout, CFOptionFlags *responseFlags) {
    CHECK_FOR_FORK();
    SInt32 retval = ERR_SUCCESS;
#if DEPLOYMENT_TARGET_MACOSX
    mach_msg_timeout_t msgtime = (timeout > 0.0 && 1000.0 * timeout < INT_MAX) ? (mach_msg_timeout_t)(1000.0 * timeout) : 0;
    mach_msg_base_t *msg = NULL;
    CFIndex size = MAX_STRING_COUNT * MAX_STRING_LENGTH;
    CFDataRef responseData;
    
    if (userNotification && MACH_PORT_NULL != userNotification->_replyPort) {
        msg = (mach_msg_base_t *)CFAllocatorAllocate(kCFAllocatorSystemDefault, size, 0);
	if (__CFOASafe) __CFSetLastAllocationEventName(msg, "CFUserNotification (temp)");
        if (msg) {
            memset(msg, 0, size);
            msg->header.msgh_size = size;
            if (msgtime > 0) {
                retval = mach_msg((mach_msg_header_t *)msg, MACH_RCV_MSG|MACH_RCV_TIMEOUT, 0, size, userNotification->_replyPort, msgtime, MACH_PORT_NULL);
            } else {
                retval = mach_msg((mach_msg_header_t *)msg, MACH_RCV_MSG, 0, size, userNotification->_replyPort, 0, MACH_PORT_NULL);
            }
            if (ERR_SUCCESS == retval) {
                if (responseFlags) *responseFlags = msg->header.msgh_id;
                if (msg->header.msgh_size > sizeof(mach_msg_base_t)) {
                    responseData = CFDataCreate(kCFAllocatorSystemDefault, (uint8_t *)msg + sizeof(mach_msg_base_t), msg->header.msgh_size - sizeof(mach_msg_base_t));
                    if (responseData) {
                        userNotification->_responseDictionary = CFPropertyListCreateFromXMLData(kCFAllocatorSystemDefault, responseData, kCFPropertyListImmutable, NULL);
                        CFRelease(responseData);
                    }
                }
                if (userNotification->_machPort) {
                    CFMachPortInvalidate(userNotification->_machPort);
                    CFRelease(userNotification->_machPort);
                    userNotification->_machPort = NULL;
                }
                mach_port_destroy(mach_task_self(), userNotification->_replyPort);
                userNotification->_replyPort = MACH_PORT_NULL;
            }
            CFAllocatorDeallocate(kCFAllocatorSystemDefault, msg);
        } else {
            retval = unix_err(ENOMEM);
        }
    }
#endif
    return retval;
}
示例#11
0
文件: devmem.c 项目: braincat/uwin
static HANDLE devmem_open(Devtab_t *pdevtab, Pfd_t *fpd, Path_t *ip, int oflags,
			  HANDLE *extra)
{
	HANDLE	hp;
	int	blkno, minor = ip->name[1];
	unsigned short *blocks = devtab_ptr(Share->chardev_index, DEVMEM_MAJOR);
	NTSTATUS	r;
	UNICODE_STRING	ucstr;
	OBJECT_ATTRIBUTES	attr;
	SYSTEM_BASIC_INFORMATION	sbi;
	Pdevmem_t	*pdm;
	ACCESS_MASK	am;

	if(Share->Platform != VER_PLATFORM_WIN32_NT)
	{
		logerr(0, "/dev/mem not supported on non NT systems");
		goto enodev;
	}
	if(!devmem_api())
	{
		logerr(0, "failed to get ntdll.dll API functions");
		goto enodev;
	}
	if(minor > DEVALLKMEM_MINOR)
	{
		logerr(0, "illegal minor device number");
		goto enodev;
	}
	if(minor > DEVPORT_MINOR)
	{
		logerr(0, "minor device not implemented yet");
		goto enodev;
	}
	if(blkno = blocks[minor])
	{	/* device already in use, increase device usage counter */
		pdm = (Pdevmem_t*)dev_ptr(blkno);
		InterlockedIncrement(&pdm->count);
	}
	else
	{	/* allocate new device block, fill in info */
		if((blkno = block_alloc(BLK_PDEV)) == 0)
			return(0);

		pdm = (Pdevmem_t*)dev_ptr(blkno);
		ZeroMemory((void *)pdm, BLOCK_SIZE-1);

		pdm->major = DEVMEM_MAJOR;
		pdm->minor = minor;

		blocks[minor] = blkno;

		/* get physical memory size */

		r = NtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), 0);

		if(!NT_SUCCESS(r))
		{
			logerr(0, "NtQuerySystemInformation failed");
			goto nterr;
		}

		switch(minor)
		{
		case DEVMEM_MINOR:
			pdm->min_addr = 0; // sbi.LowestPhysicalPage * sbi.PhysicalPageSize;
			pdm->max_addr = sbi.HighestPhysicalPage * sbi.PhysicalPageSize;
			break;
		case DEVPORT_MINOR:
			pdm->min_addr = 0;
			pdm->max_addr = 0x10000;
			break;
		default:
			pdm->min_addr = pdm->max_addr = 0;
			break;
		}
	}

	fpd->devno = blkno;
	fpd->extra64 = 0;

	RtlInitUnicodeString(&ucstr, L"\\Device\\PhysicalMemory");
	InitializeObjectAttributes(&attr, &ucstr, OBJ_CASE_INSENSITIVE | OBJ_INHERIT, 0, 0);

	switch(oflags & O_ACCMODE)
	{
	case O_RDONLY:
		am = SECTION_MAP_READ;
		break;
	case O_WRONLY:
	case O_RDWR:
		am = SECTION_MAP_READ | SECTION_MAP_WRITE;
		break;
	}

	r = NtOpenSection(&hp, am, &attr);

	if(!NT_SUCCESS(r))
	{
		logerr(0, "NtOpenSection failed");
		goto nterr;
	}

	return hp;

nterr:
	errno = unix_err(RtlNtStatusToDosError(r));
	return 0;

enodev:
	errno = ENODEV;
	return 0;
}