コード例 #1
1
ファイル: mintopo.cpp プロジェクト: duncanthrax/scream
//=============================================================================
NTSTATUS CMiniportTopology::PropertyHandlerMute(IN PPCPROPERTY_REQUEST PropertyRequest)
/*++
Routine Description:
  Property handler for KSPROPERTY_AUDIO_MUTE

Arguments:
  PropertyRequest - property request structure

Return Value:
  NT status code.
--*/
{
    PAGED_CODE();

    DPF_ENTER(("[%s]",__FUNCTION__));

    NTSTATUS ntStatus;
    LONG     lChannel;
    PBOOL    pfMute;

    if (PropertyRequest->Verb & KSPROPERTY_TYPE_BASICSUPPORT) {
        ntStatus = PropertyHandler_BasicSupport(PropertyRequest, KSPROPERTY_TYPE_ALL, VT_BOOL);
    } else {
        ntStatus = ValidatePropertyParams(PropertyRequest, sizeof(BOOL), sizeof(LONG));
        if (NT_SUCCESS(ntStatus)) {
            lChannel = * PLONG (PropertyRequest->Instance);
            pfMute   = PBOOL (PropertyRequest->Value);

            if (PropertyRequest->Verb & KSPROPERTY_TYPE_GET) {
                *pfMute = m_AdapterCommon->MixerMuteRead(PropertyRequest->Node);
                PropertyRequest->ValueSize = sizeof(BOOL);
            } else if (PropertyRequest->Verb & KSPROPERTY_TYPE_SET) {
                m_AdapterCommon->MixerMuteWrite(PropertyRequest->Node, *pfMute);
            }
        } else {
            DPF(D_TERSE, ("[%s - ntStatus=0x%08x]", __FUNCTION__, ntStatus));
        }
    }

    return ntStatus;
} // PropertyHandlerMute
コード例 #2
0
ファイル: pcnfsd.c プロジェクト: 99years/plan9
static int
pcinfo(int n, Rpccall *cmd, Rpccall *reply)
{
	uchar *argptr = cmd->args;
	uchar *dataptr = reply->results;
	String vers, cm;
	int i;

	chat("host=%I, port=%ld: pcinfo...",
		cmd->host, cmd->port);
	if(n <= 16)
		return garbage(reply, "count too small");
	argptr += string2S(argptr, &vers);
	argptr += string2S(argptr, &cm);
	if(argptr != &((uchar *)cmd->args)[n])
		return garbage(reply, "bad count");
	chat("\"%.*s\",\"%.*s\"\n", utfnlen(vers.s, vers.n), vers.s, utfnlen(cm.s, cm.n), cm.s);
	PLONG(sizeof(pc_vers)-1);
	PPTR(pc_vers, sizeof(pc_vers)-1);
	PLONG(sizeof(no_comment)-1);
	PPTR(no_comment, sizeof(no_comment)-1);
	PLONG(nelem(pcfacilities));
	for(i=0; i<nelem(pcfacilities); i++)
		PLONG(pcfacilities[i]);
	return dataptr - (uchar *)reply->results;
}
コード例 #3
0
ファイル: pcnfsd.c プロジェクト: 99years/plan9
static int
pc1auth(int n, Rpccall *cmd, Rpccall *reply)
{
	uchar *argptr = cmd->args;
	uchar *dataptr = reply->results;
	String id, pw;
	Unixidmap *m;
	int uid;

	chat("host=%I, port=%ld: pcauth...",
		cmd->host, cmd->port);
	if(n <= 8)
		return garbage(reply, "count too small");
	argptr += string2S(argptr, &id);
	argptr += string2S(argptr, &pw);
	if(argptr != &((uchar*)cmd->args)[n])
		return garbage(reply, "bad count");
	scramble(&id);
	scramble(&pw);
	m = pair2idmap("pcnfsd", cmd->host);
	uid = -1;
	if(m)
		uid = name2id(&m->u.ids, id.s);
	if(uid < 0)
		uid = 1;
	chat("\"%.*s\",\"%.*s\" uid=%d\n", utfnlen(id.s, id.n), id.s, utfnlen(pw.s, pw.n), pw.s, uid);
	PLONG(0);	/* status */
	PLONG(uid);	/* uid */
	PLONG(uid);	/* gid */
	return dataptr - (uchar*)reply->results;
}
コード例 #4
0
ファイル: memoryMap.cpp プロジェクト: Eyescale/Lunchbox
    void* _mapFile(const size_t size_)
    {
        if (!_file)
            return nullptr;

        if (size_)
        {
            ::SetFilePointer(_file, LONG(size), PLONG(&size) + 1, FILE_BEGIN);
            ::SetEndOfFile(_file);
        }

        // create a file mapping
        const DWORD mode = size_ ? PAGE_READWRITE : PAGE_READONLY;
        _map = ::CreateFileMapping(_file, 0, mode, 0, 0, 0);
        if (!_map)
        {
            ::CloseHandle(_file);
            LBWARN << "File mapping failed: " << sysError << std::endl;
            return nullptr;
        }

        // get a view of the mapping
        ptr = ::MapViewOfFile(_map, size_ ? FILE_MAP_WRITE : FILE_MAP_READ, 0,
                              0, 0);

        // get size
        DWORD highSize;
        const DWORD lowSize = ::GetFileSize(_file, &highSize);
        size = lowSize | (static_cast<uint64_t>(highSize) << 32);
        return ptr;
    }
コード例 #5
0
ファイル: mintopo.cpp プロジェクト: duncanthrax/scream
//=============================================================================
NTSTATUS CMiniportTopology::PropertyHandlerCpuResources(IN PPCPROPERTY_REQUEST PropertyRequest)
/*++
Routine Description:
  Processes KSPROPERTY_AUDIO_CPURESOURCES

Arguments:
  PropertyRequest - property request structure

Return Value:
  NT status code.
--*/
{
    PAGED_CODE();

    DPF_ENTER(("[%s]",__FUNCTION__));

    NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;

	if (PropertyRequest->Verb & KSPROPERTY_TYPE_BASICSUPPORT) {
        ntStatus = PropertyHandler_BasicSupport(PropertyRequest, KSPROPERTY_TYPE_GET | KSPROPERTY_TYPE_BASICSUPPORT, VT_ILLEGAL);
    } else if (PropertyRequest->Verb & KSPROPERTY_TYPE_GET) {
        ntStatus = ValidatePropertyParams(PropertyRequest, sizeof(ULONG));
        if (NT_SUCCESS(ntStatus)) {
            *(PLONG(PropertyRequest->Value)) = KSAUDIO_CPU_RESOURCES_HOST_CPU;
            PropertyRequest->ValueSize = sizeof(LONG);
        }
    }

    return ntStatus;
} // PropertyHandlerCpuResources
コード例 #6
0
ファイル: nfsserver.c プロジェクト: AustenConrad/plan-9
static int
nfsread(int n, Rpccall *cmd, Rpccall *reply)
{
	Session *s;
	Xfid *xf;
	Dir dir;
	int offset, count;
	uchar *argptr = cmd->args;
	uchar *dataptr = reply->results;
	uchar *readptr = dataptr + 4 + 17*4 + 4;

	chat("read...");
	if(n != FHSIZE+12)
		return garbage(reply, "bad count");
	xf = rpc2xfid(cmd, 0);
	argptr += FHSIZE;
	offset = GLONG();
	count = GLONG();
	if(xf == 0)
		return error(reply, NFSERR_STALE);
	chat("%s %d %d...", xf->xp->name, offset, count);
	if(xf->xp->s != xf->xp->parent->s){
		count = xfauthread(xf, offset, readptr, count);
	}else{
		if(xfopen(xf, Oread) < 0)
			return error(reply, NFSERR_PERM);
		if(count > 8192)
			count = 8192;
		s = xf->xp->s;
		setfid(s, xf->opfid);
		xf->opfid->tstale = nfstime + 60;
		s->f.offset = offset;
		s->f.count = count;
		if(xmesg(s, Tread) < 0)
			return error(reply, NFSERR_IO);
		count = s->f.count;
		memmove(readptr, s->f.data, count);
	}
	if(xfstat(xf, &dir) < 0)
		return error(reply, NFSERR_IO);
	PLONG(NFS_OK);
	dataptr += dir2fattr(cmd->up, &dir, dataptr);
	PLONG(count);
	dataptr += ROUNDUP(count);
	chat("%d OK\n", count);
	return dataptr - (uchar *)reply->results;
}
コード例 #7
0
ファイル: nfsserver.c プロジェクト: AustenConrad/plan-9
static int
creat(int n, Rpccall *cmd, Rpccall *reply, int chdir)
{
	Xfid *xf, *newxf;
	Xfile *xp;
	String elem;
	Dir dir; Sattr sattr;
	uchar *argptr = cmd->args;
	uchar *dataptr = reply->results;
	int trunced;

	if(n <= FHSIZE)
		return garbage(reply, "count too small");
	xf = rpc2xfid(cmd, 0);
	argptr += FHSIZE;
	argptr += string2S(argptr, &elem);
	argptr += convM2sattr(argptr, &sattr);
	if(argptr != &((uchar *)cmd->args)[n])
		return garbage(reply, "bad count");
	if(xf == 0)
		return error(reply, NFSERR_STALE);
	xp = xf->xp;
	if(!(xp->qid.type & QTDIR))
		return error(reply, NFSERR_NOTDIR);
	chat("%s/%.*s...", xp->name, utfnlen(elem.s, elem.n), elem.s);
	trunced = 0;
	if(xp->parent == xp && elem.s[0] == '#'){
		newxf = xfauth(xp, &elem);
		if(newxf == 0)
			return error(reply, NFSERR_PERM);
		if(xfauthremove(newxf, cmd->user) < 0)
			return error(reply, NFSERR_PERM);
		trunced = 1;
	}else
		newxf = xfwalkcr(Twalk, xf, &elem, 0);
	if(newxf == 0){
		newxf = xfwalkcr(Tcreate, xf, &elem, chdir|(sattr.mode&0777));
		if(newxf)
			trunced = 1;
		else
			newxf = xfwalkcr(Twalk, xf, &elem, 0);
	}
	if(newxf == 0)
		return error(reply, NFSERR_PERM);
	if(!trunced && chdir)
		return error(reply, NFSERR_EXIST);
	if(!trunced && xfopen(newxf, Trunc|Oread|Owrite) < 0)
		return error(reply, NFSERR_PERM);
	if(xfstat(newxf, &dir) < 0)
		return error(reply, NFSERR_IO);

	PLONG(NFS_OK);
	dataptr += xp2fhandle(newxf->xp, dataptr);
	dataptr += dir2fattr(cmd->up, &dir, dataptr);
	chat("OK\n");
	return dataptr - (uchar *)reply->results;
}
コード例 #8
0
ファイル: nfsserver.c プロジェクト: AustenConrad/plan-9
static int
nfssetattr(int n, Rpccall *cmd, Rpccall *reply)
{
	Xfid *xf;
	Dir dir, nd;
	Sattr sattr;
	int r;
	uchar *argptr = cmd->args;
	uchar *dataptr = reply->results;

	chat("setattr...");
	if(n <= FHSIZE)
		return garbage(reply, "count too small");
	xf = rpc2xfid(cmd, &dir);
	argptr += FHSIZE;
	argptr += convM2sattr(argptr, &sattr);
	if(argptr != &((uchar *)cmd->args)[n])
		return garbage(reply, "bad count");
	chat("mode=0%lo,u=%ld,g=%ld,size=%ld,atime=%ld,mtime=%ld...",
		sattr.mode, sattr.uid, sattr.gid, sattr.size,
		sattr.atime, sattr.mtime);
	if(xf == 0)
		return error(reply, NFSERR_STALE);
	if(sattr.uid != NOATTR || sattr.gid != NOATTR)
		return error(reply, NFSERR_PERM);
	if(sattr.size == 0){
		if(xf->xp->s != xf->xp->parent->s){
			if(xfauthremove(xf, cmd->user) < 0)
				return error(reply, NFSERR_PERM);
		}else if(dir.length && xfopen(xf, Trunc|Oread|Owrite) < 0)
			return error(reply, NFSERR_PERM);
	}else if(sattr.size != NOATTR)
		return error(reply, NFSERR_PERM);
	r = 0;
	nulldir(&nd);
	if(sattr.mode != NOATTR)
		++r, nd.mode = (dir.mode & ~0777) | (sattr.mode & 0777);
	if(sattr.atime != NOATTR)
		++r, nd.atime = sattr.atime;
	if(sattr.mtime != NOATTR)
		++r, nd.mtime = sattr.mtime;
	chat("sattr.mode=%luo dir.mode=%luo nd.mode=%luo...", sattr.mode, dir.mode, nd.mode);
	if(r){
		r = xfwstat(xf, &nd);
		if(r < 0)
			return error(reply, NFSERR_PERM);
	}
	if(xfstat(xf, &dir) < 0)
		return error(reply, NFSERR_STALE);
	PLONG(NFS_OK);
	dataptr += dir2fattr(cmd->up, &dir, dataptr);
	chat("OK\n");
	return dataptr - (uchar *)reply->results;
}
コード例 #9
0
ファイル: nfsserver.c プロジェクト: AustenConrad/plan-9
static int
nfsstatfs(int n, Rpccall *cmd, Rpccall *reply)
{
	uchar *dataptr = reply->results;
	enum {
		Xfersize = 2048,
		Maxlong = (long)((1ULL<<31) - 1),
		Maxfreeblks = Maxlong / Xfersize,
	};

	chat("statfs...");
	showauth(&cmd->cred);
	if(n != FHSIZE)
		return garbage(reply, "bad count");
	PLONG(NFS_OK);
	PLONG(4096);		/* tsize (fs block size) */
	PLONG(Xfersize);	/* bsize (optimal transfer size) */
	PLONG(Maxfreeblks);	/* blocks in fs */
	PLONG(Maxfreeblks);	/* bfree to root*/
	PLONG(Maxfreeblks);	/* bavail (free to mortals) */
	chat("OK\n");
	/*conftime = 0;
	readunixidmaps(config);*/
	return dataptr - (uchar *)reply->results;
}
コード例 #10
0
ファイル: nfsmount.c プロジェクト: 99years/plan9
static int
mntexport(int n, Rpccall *cmd, Rpccall *reply)
{
	uchar *dataptr = reply->results;
	Authunix au;
	int i;

	chat("mntexport...");
	if(n != 0)
		return garbage(reply, "mntexport");
	if(auth2unix(&cmd->cred, &au) != 0){
		chat("auth flavor=%ld, count=%ld\n",
			cmd->cred.flavor, cmd->cred.count);
		for(i=0; i<cmd->cred.count; i++)
			chat(" %.2ux", ((uchar *)cmd->cred.data)[i]);
		chat("...");
		au.mach.n = 0;
	}else
		chat("%ld@%.*s...", au.uid, utfnlen(au.mach.s, au.mach.n), au.mach.s);
	PLONG(TRUE);
	PLONG(1);
	PPTR("/", 1);
	if(au.mach.n > 0){
		PLONG(TRUE);
		PLONG(au.mach.n);
		PPTR(au.mach.s, au.mach.n);
	}
	PLONG(FALSE);
	PLONG(FALSE);
	chat("OK\n");
	return dataptr - (uchar *)reply->results;
}
コード例 #11
0
ファイル: nfsmount.c プロジェクト: 99years/plan9
static int
mntmnt(int n, Rpccall *cmd, Rpccall *reply)
{
	int i;
	char dom[64];
	uchar *argptr = cmd->args;
	uchar *dataptr = reply->results;
	Authunix au;
	Xfile *xp;
	String root;

	chat("mntmnt...\n");
	if(n < 8)
		return garbage(reply, "n too small");
	argptr += string2S(argptr, &root);
	if(argptr != &((uchar *)cmd->args)[n])
		return garbage(reply, "bad count");
	clog("host=%I, port=%ld, root=\"%.*s\"...",
		cmd->host, cmd->port, utfnlen(root.s, root.n), root.s);
	if(auth2unix(&cmd->cred, &au) != 0){
		chat("auth flavor=%ld, count=%ld\n",
			cmd->cred.flavor, cmd->cred.count);
		for(i=0; i<cmd->cred.count; i++)
			chat(" %.2ux", ((uchar *)cmd->cred.data)[i]);
		chat("\n");
		clog("auth: bad credentials");
		return error(reply, 1);
	}
	clog("auth: %ld %.*s u=%ld g=%ld",
		au.stamp, utfnlen(au.mach.s, au.mach.n), au.mach.s, au.uid, au.gid);
	for(i=0; i<au.gidlen; i++)
		chat(", %ld", au.gids[i]);
	chat("...");
	if(getdom(cmd->host, dom, sizeof(dom))<0){
		clog("auth: unknown ip address");
		return error(reply, 1);
	}
	chat("dom=%s...", dom);
	xp = xfroot(root.s, root.n);
	if(xp == 0){
		chat("xp=0...");
		clog("mntmnt: no fs");
		return error(reply, 3);
	}

	PLONG(0);
	dataptr += xp2fhandle(xp, dataptr);
	chat("OK\n");
	return dataptr - (uchar *)reply->results;
}
コード例 #12
0
ファイル: nfsserver.c プロジェクト: AustenConrad/plan-9
static int
remov(int n, Rpccall *cmd, Rpccall *reply)
{
	Session *s;
	Xfile *xp;
	Xfid *xf, *newxf;
	String elem;
	Fid *nfid;
	uchar *argptr = cmd->args;
	uchar *dataptr = reply->results;

	if(n <= FHSIZE)
		return garbage(reply, "count too small");
	xf = rpc2xfid(cmd, 0);
	argptr += FHSIZE;
	argptr += string2S(argptr, &elem);
	if(argptr != &((uchar *)cmd->args)[n])
		return garbage(reply, "bad count");
	if(xf == 0)
		return error(reply, NFSERR_STALE);
	xp = xf->xp;
	if(!(xp->qid.type & QTDIR))
		return error(reply, NFSERR_NOTDIR);
	chat("%s/%.*s...", xp->name, utfnlen(elem.s, elem.n), elem.s);
	if(xp->s->noauth == 0 && xp->parent == xp && elem.s[0] == '#')
		return error(reply, NFSERR_PERM);
	newxf = xfwalkcr(Twalk, xf, &elem, 0);
	if(newxf == 0)
		return error(reply, NFSERR_NOENT);
	s = xp->s;
	nfid = newfid(s);
	setfid(s, newxf->urfid);
	s->f.newfid = nfid - s->fids;
	s->f.nwname = 0;
	if(xmesg(s, Twalk) < 0){
		putfid(s, nfid);
		return error(reply, NFSERR_IO);
	}
	s->f.fid = nfid - s->fids;
	if(xmesg(s, Tremove) < 0){
		putfid(s, nfid);
		return error(reply, NFSERR_PERM);
	}
	putfid(s, nfid);
	xpclear(newxf->xp);
	PLONG(NFS_OK);
	chat("OK\n");
	return dataptr - (uchar *)reply->results;
}
コード例 #13
0
ファイル: nfsserver.c プロジェクト: AustenConrad/plan-9
static int
nfsrename(int n, Rpccall *cmd, Rpccall *reply)
{
	Xfid *xf, *newxf;
	Xfile *xp;
	uchar *fromdir, *todir;
	String fromelem, toelem;
	Dir dir;
	uchar *argptr = cmd->args;
	uchar *dataptr = reply->results;

	chat("rename...");
	if(n <= FHSIZE)
		return garbage(reply, "count too small");
	xf = rpc2xfid(cmd, 0);
	fromdir = argptr;
	argptr += FHSIZE;
	argptr += string2S(argptr, &fromelem);
	todir = argptr;
	argptr += FHSIZE;
	argptr += string2S(argptr, &toelem);
	if(argptr != &((uchar *)cmd->args)[n])
		return garbage(reply, "bad count");
	if(xf == 0)
		return error(reply, NFSERR_STALE);
	xp = xf->xp;
	if(!(xp->qid.type & QTDIR))
		return error(reply, NFSERR_NOTDIR);
	if(memcmp(fromdir, todir, FHSIZE) != 0)
		return error(reply, NFSERR_NXIO);
	newxf = xfwalkcr(Twalk, xf, &fromelem, 0);
	if(newxf == 0)
		return error(reply, NFSERR_NOENT);
	if(xfstat(newxf, &dir) < 0)
		return error(reply, NFSERR_IO);

	if(xp->parent == xp && toelem.s[0] == '#')
		return error(reply, NFSERR_PERM);
	nulldir(&dir);
	dir.name = toelem.s;
	if(xfwstat(newxf, &dir) < 0)
		return error(reply, NFSERR_PERM);
	PLONG(NFS_OK);
	chat("OK\n");
	return dataptr - (uchar *)reply->results;
}
コード例 #14
0
ファイル: nfsserver.c プロジェクト: AustenConrad/plan-9
static int
nfswrite(int n, Rpccall *cmd, Rpccall *reply)
{
	Session *s;
	Xfid *xf;
	Dir dir;
	int offset, count;
	uchar *argptr = cmd->args;
	uchar *dataptr = reply->results;

	chat("write...");
	if(n < FHSIZE+16)
		return garbage(reply, "count too small");
	xf = rpc2xfid(cmd, 0);
	argptr += FHSIZE + 4;
	offset = GLONG();
	argptr += 4;
	count = GLONG();
	if(xf == 0)
		return error(reply, NFSERR_STALE);
	chat("%s %d %d...", xf->xp->name, offset, count);
	if(xf->xp->s != xf->xp->parent->s){
		if(xfauthwrite(xf, offset, argptr, count) < 0)
			return error(reply, NFSERR_IO);
	}else{
		if(xfopen(xf, Owrite) < 0)
			return error(reply, NFSERR_PERM);
		s = xf->xp->s;
		setfid(s, xf->opfid);
		xf->opfid->tstale = nfstime + 60;
		s->f.offset = offset;
		s->f.count = count;
		s->f.data = (char *)argptr;
		if(xmesg(s, Twrite) < 0)
			return error(reply, NFSERR_IO);
	}
	if(xfstat(xf, &dir) < 0)
		return error(reply, NFSERR_IO);
	PLONG(NFS_OK);
	dataptr += dir2fattr(cmd->up, &dir, dataptr);
	chat("OK\n");
	return dataptr - (uchar *)reply->results;
}
コード例 #15
0
ファイル: nfsserver.c プロジェクト: AustenConrad/plan-9
static int
nfsgetattr(int n, Rpccall *cmd, Rpccall *reply)
{
	Xfid *xf;
	Dir dir;
	uchar *dataptr = reply->results;

	chat("getattr...");
	if(n != FHSIZE)
		return garbage(reply, "bad count");
	xf = rpc2xfid(cmd, &dir);
	if(xf == 0)
		return error(reply, NFSERR_STALE);
	chat("%s...", xf->xp->name);
	PLONG(NFS_OK);
	dataptr += dir2fattr(cmd->up, &dir, dataptr);
	chat("OK\n");
	return dataptr - (uchar *)reply->results;
}
コード例 #16
0
ファイル: mintopo.cpp プロジェクト: duncanthrax/scream
//=============================================================================
NTSTATUS CMiniportTopology::PropertyHandlerVolume(IN PPCPROPERTY_REQUEST PropertyRequest)
/*++
Routine Description:
  Property handler for KSPROPERTY_AUDIO_VOLUMELEVEL

Arguments:
  PropertyRequest - property request structure

Return Value:
  NT status code.
--*/
{
    PAGED_CODE();

    DPF_ENTER(("[%s]",__FUNCTION__));

    NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;
    LONG     lChannel;
    PULONG   pulVolume;

    if (PropertyRequest->Verb & KSPROPERTY_TYPE_BASICSUPPORT) {
        ntStatus = PropertyHandlerBasicSupportVolume(PropertyRequest);
    } else {
		// volume value is a ULONG, instance is the channel number
        ntStatus = ValidatePropertyParams(PropertyRequest, sizeof(ULONG), sizeof(LONG));
        if (NT_SUCCESS(ntStatus)) {
            lChannel  = * (PLONG (PropertyRequest->Instance));
            pulVolume = PULONG (PropertyRequest->Value);

            if (PropertyRequest->Verb & KSPROPERTY_TYPE_GET) {
                *pulVolume = m_AdapterCommon->MixerVolumeRead(PropertyRequest->Node, lChannel);
                PropertyRequest->ValueSize = sizeof(ULONG);                
            } else if (PropertyRequest->Verb & KSPROPERTY_TYPE_SET) {
                m_AdapterCommon->MixerVolumeWrite(PropertyRequest->Node, lChannel, *pulVolume);
            }
        } else {
            DPF(D_TERSE, ("[%s - ntStatus=0x%08x]",__FUNCTION__,ntStatus));
        }
    }

    return ntStatus;
} // PropertyHandlerVolume
コード例 #17
0
ファイル: memoryMap.cpp プロジェクト: biddisco/Lunchbox
    void init_( const std::string& filename, const size_t size_ )
    {
        // try to open binary file (and size it)
        const DWORD access = size_ ? GENERIC_READ | GENERIC_WRITE:GENERIC_READ;
        const DWORD create = size_ ? CREATE_ALWAYS : OPEN_EXISTING;
        HANDLE file = ::CreateFile( filename.c_str(), access, FILE_SHARE_READ,
                                    0, create, FILE_ATTRIBUTE_NORMAL, 0 );
        if( file == INVALID_HANDLE_VALUE )
        {
            LBWARN << "Can't open " << filename << ": " << sysError <<std::endl;
            return;
        }

        if( size_ )
        {
            ::SetFilePointer( file, LONG(size_), PLONG(&size_)+1, FILE_BEGIN );
            ::SetEndOfFile( file );
        }

        // create a file mapping
        const DWORD mode = size_ ? PAGE_READWRITE : PAGE_READONLY;
        map_ = ::CreateFileMapping( file, 0, mode, 0, 0, 0 );
        if( !map_ )
        {
            LBWARN << "File mapping failed: " << sysError << std::endl;
            return;
        }

        // get a view of the mapping
        ptr = ::MapViewOfFile( map_, FILE_MAP_READ, 0, 0, 0 );

        // get size
        DWORD highSize;
        const DWORD lowSize = ::GetFileSize( file, &highSize );
        size = lowSize | ( static_cast< uint64_t >( highSize ) << 32 );
        LBASSERT( size_ == 0 || size_ == size );

        ::CloseHandle( file );
    }
コード例 #18
0
ファイル: pcnfsd.c プロジェクト: 99years/plan9
static int
pcauth(int n, Rpccall *cmd, Rpccall *reply)
{
	uchar *argptr = cmd->args;
	uchar *dataptr = reply->results;
	String sys, id, pw, cm;
	Unixidmap *m;
	int uid;

	chat("host=%I, port=%ld: pcauth...",
		cmd->host, cmd->port);
	if(n <= 16)
		return garbage(reply, "count too small");
	argptr += string2S(argptr, &sys);
	argptr += string2S(argptr, &id);
	argptr += string2S(argptr, &pw);
	argptr += string2S(argptr, &cm);
	if(argptr != &((uchar *)cmd->args)[n])
		return garbage(reply, "bad count");
	scramble(&id);
	scramble(&pw);

	m = pair2idmap("pcnfsd", cmd->host);
	uid = -1;
	if(m)
		uid = name2id(&m->u.ids, id.s);
	if(uid < 0)
		uid = 1;
	chat("\"%.*s\",\"%.*s\",\"%.*s\",\"%.*s\"\n", utfnlen(sys.s, sys.n), sys.s,
		utfnlen(id.s, id.n), id.s, utfnlen(pw.s, pw.n), pw.s, utfnlen(cm.s, cm.n), cm.s);
	PLONG(0);	/* status - OK */
	PLONG(uid);
	PLONG(uid);	/* gid */
	PLONG(0);	/* ngids */
	PLONG(sizeof(pc_home)-1);
	PPTR(pc_home, sizeof(pc_home)-1);
	PLONG(0);	/* umask */
	PLONG(sizeof(no_comment)-1);
	PPTR(no_comment, sizeof(no_comment)-1);
	return dataptr - (uchar *)reply->results;
}
コード例 #19
0
ファイル: nfsserver.c プロジェクト: AustenConrad/plan-9
static int
nfslookup(int n, Rpccall *cmd, Rpccall *reply)
{
	Xfile *xp;
	Xfid *xf, *newxf;
	String elem;
	Dir dir;
	uchar *argptr = cmd->args;
	uchar *dataptr = reply->results;

	chat("lookup...");
	if(n <= FHSIZE)
		return garbage(reply, "count too small");
	xf = rpc2xfid(cmd, 0);
	argptr += FHSIZE;
	argptr += string2S(argptr, &elem);
	if(argptr != &((uchar *)cmd->args)[n])
		return garbage(reply, "bad count");
	if(xf == 0)
		return error(reply, NFSERR_STALE);
	xp = xf->xp;
	if(!(xp->qid.type & QTDIR))
		return error(reply, NFSERR_NOTDIR);
	chat("%s -> \"%.*s\"...", xp->name, utfnlen(elem.s, elem.n), elem.s);
	if(xp->s->noauth == 0 && xp->parent == xp && elem.s[0] == '#')
		newxf = xfauth(xp, &elem);
	else
		newxf = xfwalkcr(Twalk, xf, &elem, 0);
	if(newxf == 0)
		return error(reply, NFSERR_NOENT);
	if(xfstat(newxf, &dir) < 0)
		return error(reply, NFSERR_IO);
	PLONG(NFS_OK);
	dataptr += xp2fhandle(newxf->xp, dataptr);
	dataptr += dir2fattr(cmd->up, &dir, dataptr);
	chat("OK\n");
	return dataptr - (uchar *)reply->results;
}
コード例 #20
0
ファイル: nfsserver.c プロジェクト: AustenConrad/plan-9
static int
nfsreaddir(int n, Rpccall *cmd, Rpccall *reply)
{
	Session *s;
	Xfid *xf;
	Dir dir;
	char *rdata;
	int k, offset, count, sfcount, entries, dsize;
	uchar *argptr = cmd->args;
	uchar *dataptr = reply->results;

	chat("readdir...");
	if(n != FHSIZE+8)
		return garbage(reply, "bad count");
	xf = rpc2xfid(cmd, 0);
	argptr += FHSIZE;
	offset = GLONG();
	count = GLONG();
	if(xf == 0)
		return error(reply, NFSERR_STALE);
	chat("%s (%ld) %d %d...", xf->xp->name, xf->offset, offset, count);
	s = xf->xp->s;
	if((xf->mode & Open) && xf->offset > offset)
		xfclose(xf);
	if(xfopen(xf, Oread) < 0)
		return error(reply, NFSERR_PERM);
	while(xf->offset < offset){	/* if we reopened, xf->offset will be zero */
		sfcount = offset - xf->offset;
		if(sfcount > messagesize-IOHDRSZ)
			sfcount = messagesize-IOHDRSZ;
		setfid(s, xf->opfid);
		s->f.offset = xf->offset;
		s->f.count = sfcount;
		if(xmesg(s, Tread) < 0){
			xfclose(xf);
			return error(reply, NFSERR_IO);
		}
		if(s->f.count <= BIT16SZ)
			break;
		xf->offset += s->f.count;
	}
	if(count > messagesize-IOHDRSZ)
		count = messagesize-IOHDRSZ;
	PLONG(NFS_OK);
	entries = 0;
	while(count > 16){	/* at least 16 bytes required; we don't know size of name */
chat("top of loop\n");
		setfid(s, xf->opfid);
		s->f.offset = xf->offset;
		s->f.count = count;	/* as good a guess as any */
		if(xmesg(s, Tread) < 0){
			xfclose(xf);
			return error(reply, NFSERR_IO);
		}
		sfcount = s->f.count;
		if(sfcount <= BIT16SZ)
			break;
		xf->offset += sfcount;
chat("count %d data 0x%p\n", s->f.count, s->f.data);
		rdata = s->f.data;
		/* now have a buffer of Plan 9 directories; unpack into NFS thingies */
		while(sfcount >= 0){
			dsize = convM2D((uchar*)rdata, sfcount, &dir, (char*)s->statbuf);
			if(dsize <= BIT16SZ){
				count = 0;	/* force break from outer loop */
				break;
			}
			offset += dsize;
			k = strlen(dir.name);
			if(count < 16+ROUNDUP(k)){
				count = 0;	/* force break from outer loop */
				break;
			}
			PLONG(TRUE);
			PLONG(dir.qid.path);
			PLONG(k);
			PPTR(dir.name, k);
			PLONG(offset);
			count -= 16+ROUNDUP(k);
			rdata += dsize;
			sfcount -= dsize;
		}
	}
	PLONG(FALSE);
	if(s->f.count <= 0){
		xfclose(xf);
		chat("eof...");
		PLONG(TRUE);
	}else
		PLONG(FALSE);
	chat("%d OK\n", entries);
	return dataptr - (uchar *)reply->results;
}
コード例 #21
0
ファイル: kshelper.cpp プロジェクト: Realhram/wdk81
NTSTATUS
PropertyHandler_PeakMeter2
(
    _In_  PADAPTERCOMMON        AdapterCommon,
    _In_  PPCPROPERTY_REQUEST   PropertyRequest,
    _In_  ULONG                 MaxChannels
)
/*++

Routine Description:

  Property handler for KSPROPERTY_AUDIO_PEAKMETER2

Arguments:

  AdapterCommon - interface to the common adapter object.
  
  PropertyRequest - property request structure.

  MaxChannels - # of supported channels.

Return Value:

  NT status code.

--*/
{
    PAGED_CODE();

    DPF_ENTER(("[%s]",__FUNCTION__));

    NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;
    ULONG    ulChannel;
    PLONG    plSample;

    if (PropertyRequest->Verb & KSPROPERTY_TYPE_BASICSUPPORT)
    {
        ntStatus = PropertyHandler_BasicSupportPeakMeter2(
                            PropertyRequest,
                            MaxChannels);
    }
    else
    {
        ntStatus = 
            ValidatePropertyParams
            (
                PropertyRequest, 
                sizeof(LONG),    // sample value is a LONG
                sizeof(ULONG)    // instance is the channel number
            );
        if (NT_SUCCESS(ntStatus))
        {
            ulChannel = * (PULONG (PropertyRequest->Instance));
            plSample  = PLONG (PropertyRequest->Value);

            if (ulChannel >= MaxChannels &&
                ulChannel != ALL_CHANNELS_ID)
            {
               ntStatus = STATUS_INVALID_PARAMETER;
            }
            else if (PropertyRequest->Verb & KSPROPERTY_TYPE_GET)
            {
                *plSample = 
                    PEAKMETER_NORMALIZE_IN_RANGE(
                        AdapterCommon->MixerPeakMeterRead
                        (
                            PropertyRequest->Node, 
                            ulChannel == ALL_CHANNELS_ID ? 0 : ulChannel
                        ));
                
                PropertyRequest->ValueSize = sizeof(ULONG);                
            }
        }

        if (!NT_SUCCESS(ntStatus))
        {
            DPF(D_TERSE, ("[%s - ntStatus=0x%08x]",__FUNCTION__,ntStatus));
        }
    }

    return ntStatus;
} // PropertyHandlerVolume
コード例 #22
0
void
CHardwareSimulation::
FakeHardware (
)

/*++

Routine Description:

    Simulate an interrupt and what the hardware would have done in the
    time since the previous interrupt.

Arguments:

    None

Return Value:

    None

--*/

{
    PAGED_CODE();

    KScopedMutex Lock( m_ListLock );

    m_InterruptTime++;

    //
    // The hardware can be in a pause state in which case, it issues interrupts
    // but does not complete mappings.  In this case, don't bother synthesizing
    // a frame and doing the work of looking through the mappings table.
    //
    if (m_PinState == PinRunning)
    {
        //
        // Generate a "time stamp" just to overlay it onto the capture image.
        // It makes it more exciting than bars that do nothing.
        //
        ULONGLONG time = ConvertQPCtoTimeStamp(NULL);
        DBG_TRACE("QPC=0x%016llX", time);

        m_Synthesizer->SetFrameNumber( m_InterruptTime );
        m_Synthesizer->SetRelativePts( (m_InterruptTime + 1) * m_TimePerFrame );
        m_Synthesizer->SetQpcTime( time );

        m_Synthesizer->DoSynthesize();

        CHAR Text[64];

        CExtendedProperty   Control;
        m_Sensor->GetVideoStabilization( &Control );
        RtlStringCbPrintfA(Text, sizeof(Text), "DVS: %s", DVS_Text(Control.Flags));
        m_Synthesizer->OverlayText( 0, m_Height-38, 1, Text, BLACK, WHITE );

        m_Sensor->GetOpticalImageStabilization( &Control );
        RtlStringCbPrintfA(Text, sizeof(Text), "OIS: %s", OIS_Text(Control.Flags));
        m_Synthesizer->OverlayText( 0, m_Height-48, 1, Text, BLACK, WHITE );

        //
        // Fill scatter gather buffers
        //
        if (!NT_SUCCESS (FillScatterGatherBuffers ()))
        {
            InterlockedIncrement (PLONG (&m_NumFramesSkipped));
        }

    }

    //
    // Issue an interrupt to our hardware sink.  This is a "fake" interrupt.
    // It will occur at DISPATCH_LEVEL.
    //
    m_Sensor -> Interrupt (m_PinID);

    //
    //  Schedule the timer for the next interrupt time, if the pin is still running.
    //
    if( m_PinState == PinRunning )
    {
        LARGE_INTEGER NextTime;
        NextTime.QuadPart = m_StartTime.QuadPart +
                            (m_TimePerFrame * (m_InterruptTime + 1));

#ifdef ENABLE_TRACING  // To keep us from a tight spin when trying to debug this code...
        LARGE_INTEGER Now;
        KeQuerySystemTime(&Now);

        if( Now.QuadPart >= NextTime.QuadPart )
        {
            NextTime.QuadPart = 0LL - m_TimePerFrame ;
        }

#endif
        m_IsrTimer.Set( NextTime );
    }
}
コード例 #23
0
ファイル: hwsim.cpp プロジェクト: Juferr/avshws
void
CHardwareSimulation::
FakeHardware (
    )

/*++

Routine Description:

    Simulate an interrupt and what the hardware would have done in the
    time since the previous interrupt.

Arguments:

    None

Return Value:

    None

--*/

{

    m_InterruptTime++;

    //
    // The hardware can be in a pause state in which case, it issues interrupts
    // but does not complete mappings.  In this case, don't bother synthesizing
    // a frame and doing the work of looking through the mappings table.
    //
    if (m_HardwareState == HardwareRunning) {
    
        //
        // Generate a "time stamp" just to overlay it onto the capture image.
        // It makes it more exciting than bars that do nothing.
        //
        LONGLONG PtsRel = ((m_InterruptTime + 1) * m_TimePerFrame);
    
        ULONG Min = (ULONG)(PtsRel / 600000000);
        ULONG RemMin = (ULONG)(PtsRel % 600000000);
        ULONG Sec = (ULONG)(RemMin / 10000000);
        ULONG RemSec = (ULONG)(RemMin % 10000000);
        ULONG Hund = (ULONG)(RemSec / 100000);
    
        //
        // Synthesize a buffer in scratch space.
        //
        m_ImageSynth -> SynthesizeBars ();
    
        CHAR Text [256];
        Text[0] = '\0';
        (void) RtlStringCbPrintfA(Text, sizeof(Text), "%ld:%02ld.%02ld", Min, Sec, Hund);
    
        //
        // Overlay a clock onto the scratch space image.
        //
        m_ImageSynth -> OverlayText (
            POSITION_CENTER,
            (m_Height - 28),
            1,
            Text,
            BLACK,	
            WHITE
            );
    
        //
        // Overlay a counter of skipped frames onto the scratch image.
        //
        (void) RtlStringCbPrintfA(Text, sizeof(Text), "Skipped: %ld", m_NumFramesSkipped);
        m_ImageSynth -> OverlayText (
            10,
            10,
            1,
            Text,
            TRANSPARENT,
            BLUE
            );

        //
        // Fill scatter gather buffers
        //
        if (!NT_SUCCESS (FillScatterGatherBuffers ())) {
            InterlockedIncrement (PLONG (&m_NumFramesSkipped));
        }

    }
        
    //
    // Issue an interrupt to our hardware sink.  This is a "fake" interrupt.
    // It will occur at DISPATCH_LEVEL.
    //
    m_HardwareSink -> Interrupt ();

    //
    // Reschedule the timer if the hardware isn't being stopped.
    //
    if (!m_StopHardware) {

        //
        // Reschedule the timer for the next interrupt time.
        //
        LARGE_INTEGER NextTime;
        NextTime.QuadPart = m_StartTime.QuadPart + 
            (m_TimePerFrame * (m_InterruptTime + 1));

        KeSetTimer (&m_IsrTimer, NextTime, &m_IsrFakeDpc);
        
    } else {
        //
        // If someone is waiting on the hardware to stop, raise the stop
        // event and clear the flag.
        //
        m_StopHardware = FALSE;
        KeSetEvent (&m_HardwareEvent, IO_NO_INCREMENT, FALSE);
    }

}
コード例 #24
0
void
CImageHardwareSimulation::
FakeHardware()

/*++

Routine Description:

    Simulate an interrupt and what the hardware would have done in the
    time since the previous interrupt.

Arguments:

    None

Return Value:

    None

--*/

{
    PAGED_CODE();

    //  Prevent state-changes during this call.
    KScopedMutex    Lock(m_ListLock);

    m_InterruptTime++;

    //
    // The hardware can be in a pause state in which case, it issues interrupts
    // but does not complete mappings.  In this case, don't bother synthesizing
    // a frame and doing the work of looking through the mappings table.
    //
    if( m_PinState == PinRunning )
    {
        if(m_PinMode == PinBurstMode && m_bTriggered && m_bPastBufferTrigger)
        {
            CompletePastBuffers();
        }

        m_Synthesizer->DoSynthesize();

        CHAR Text[64];

        CExtendedProperty   Control;
        m_Sensor->GetAdvancedPhoto(&Control);
        RtlStringCbPrintfA(Text, sizeof(Text), "Adv: %s", AdvancedPhoto_Text(Control.Flags));
        m_Synthesizer->OverlayText( 0, m_Height-38, 1, Text, TRANSPARENT, WHITE );
        
        //
        // Fill scatter gather buffers
        //
        if (!NT_SUCCESS (FillScatterGatherBuffers ()))
        {
            InterlockedIncrement (PLONG (&m_NumFramesSkipped));
        }
    }

    //
    // Issue an interrupt to our hardware sink.  This is a "fake" interrupt.
    // It will occur at DISPATCH_LEVEL.
    //
    m_Sensor -> Interrupt (m_PinID);

    //
    //  Schedule the timer for the next interrupt time, if the pin is still running.
    //
    if( m_PinState == PinRunning )
    {
        LARGE_INTEGER NextTime;
        NextTime.QuadPart = m_StartTime.QuadPart +
                            (m_TimePerFrame * (m_InterruptTime + 1));

#ifdef ENABLE_TRACING  // To keep us from a tight spin when trying to debug this code...
        LARGE_INTEGER Now;
        KeQuerySystemTime(&Now);

        if( Now.QuadPart >= NextTime.QuadPart )
        {
            NextTime.QuadPart = 0LL - m_TimePerFrame ;
        }

#endif
        m_IsrTimer.Set( NextTime );
    }
}