debugfs_create_file doesn't create file - linux

I am trying to create a debugfs file using the debugfs_create_file(...). I have written a sample code for this.
static int __init mmapexample_module_init(void)
{
file1 = debugfs_create_file("mmap_example", 0644, NULL, NULL, &my_fops)\
;
printk(KERN_ALERT "Hello, World\n");
if(file1==NULL)
{
printk(KERN_ALERT "Error occured\n");
}
if(file1==-ENODEV)
{
printk(KERN_ALERT "ENODEV occured\n");
}
return 0;
}
When i ran insmod i could get the Hello, World message but no the error message. So i think the debugfs_create_file worked fine. However i couldn't find any file in /sys/kernel/debug. The folder is there but it is empty. Can anyone help me with this? Thank you...
Thanks,
Bala

For debugfs to work, you actually have to have a debugfs mountpoint:
mount -t debugfs none /sys/kernel/debug
Not sure if that's what the problem is here, but may be you can check if you have a mounted debugfs
on /sys/kernel/debug

You might consider printk(KERN_ALERT "Something else happened\n") in the case that file1 is not equal to NULL or -ENODEV. That may provide some interesting results. Maybe:
if (file1 == NULL)
printk(KERN_ALERT "Error occurred\n");
else if (file1 == -ENODEV)
printk(KERN_ALERT "ENODEV occurred\n");
else
printk(KERN_ALERT "Something else occurred\n");
I'm not familiar with kernel programming libraries as much, but if there is a similar va_args interface to printk(), you could probably print the value of file1.
Now looking at this though, is there some kind of kernel errno? Or is that what debugfs_create_file() returns?
UPDATE:
The only help I can give now is to somehow discover what file1's value is and investigate what that means. You may want to do some poking around for an errno equivalent and see if its set. Equivalent to the perror() call in the kernel basically.

Related

ChucK - storing id values of sporked shreds

A little bit of a beginner so bear with me.
I was writing a bit of code to experiment with shred sporking and removing, but encountered a problem. Here is a portion of my code:
while(hid.recv(msg)) //Hid hid is above
{
if(msg.isButtonDown()) //HidMsg msg is above
{
spork ~ test() #=> Shred # s; //test is just an empty function
}
if(msg.isButtonUp())
{
Machine.remove(s.id());
}
}
With this, however, I get the error "undefined variable 's'...". I could tell that since defining 's' only happens after msg.isButtonDown() is true, so I tried a different method.
while(hid.recv(msg))
{
Shred s;
if(msg.isButtonDown()) //HidMsg msg is above
{
spork ~ test() #=> s; //test is just an empty function
}
if(msg.isButtonUp())
{
Machine.remove(s.id());
}
}
However, this results in the error "cannot remove: no shred with id 0...". I don't understand why s.id() would be 0? Shouldn't the chucking in the first if statement define s.id() as the sporked id? I can't seem to get past this.
Thanks,
Kevin Kim
Shred s is scoped to the body of the while loop. You're creating a new Shred variable on each iteration of the loop. They're different references. Put the variable declaration (Shred s in this case) outside of the while loop.

How to implement select function call

I have created a virtual node "/dev/abc" and there are 2 applications a.c and b.c
a.c will write data in to the node,
b.c will read data from the node
In b.c I am opening the node and using select function
to verify whether data is available in the node.
I am using below code for checking the data.
But with out writing data from a.c, b.c is reading the
data.
Code:
fd_set read set;
int result;
fd=open ("/dev/abc", O_RDWR);
FD_SET (fd, &readset);
result=select (fd+1,&readset, NULL, NULL, NULL);
if(result> 0)
{
if (FD_ISSET (fd, &readset))
{
read (fd, buffer, 100);
}
}
Please suggest me how to use select function call for
the above scenario.
Regards,
Ajith Kumsi
You should call FD_ZERO() before FD_SET() to clear your readset. That's probably the reason. There is a clear example near the bottom of select man page and you can just follow it.

IDWriteTextFormat::SetTextAlignment does not work for DWRITE_TEXT_ALIGNMENT_JUSTIFIED

IDWriteTextFormat::SetTextAlignment was used to alignment text in DirectWrite, it takes a parameter of DWRITE_TEXT_ALIGNMENT type
enum DWRITE_TEXT_ALIGNMENT {
DWRITE_TEXT_ALIGNMENT_LEADING,
DWRITE_TEXT_ALIGNMENT_TRAILING,
DWRITE_TEXT_ALIGNMENT_CENTER,
DWRITE_TEXT_ALIGNMENT_JUSTIFIED
};
the first 3 type all work well, but the last one DWRITE_TEXT_ALIGNMENT_JUSTIFIED does not work, when I try to set it, I got an invalid argument error
HRESULT hr = g_pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_JUSTIFIED);
if(FAILED(hr))
{
MessageBox(NULL, L"Center text failed!", L"Error", 0);
return;
}
It seems this is not a valid argument, why? does anyone encountered the same issue?
Got the answer from Microsoft DirectX forum, it is because, this flag does not support Win7, but the SDK document does not point it out.
http://xboxforums.create.msdn.com/forums/p/108456/640004.aspx#640004

How to read a custom path of a file in c++?

My file is located in C:\\Input\\pStep.p21 . i want to open that file in my cpp program. How can i do it? I am using char* inputPath="C:\\Input\\pStep.p21"; but its not finding my file in program. How to get current working directory in VC++?. Its working if try to save p21 file but failing if i read it.
my code in CAA:
#include<CATSDM_Services>
#include<SdaiModel.h>
#include<CATIUniCodeString>
---
---
main()
{
CATIUniCodeString inputPath("C:\\Input\\pStep.p21");
HRESULT hr=S_OK;
SdaiModel edxModel=Null;
//this method reads express schema name, input p21 file and sdaimodel
hr=CreateModelFromFile(inputPath,"parts",edxModel);
if(FAILED(hr))
{
cout<<"Model created succesfully";
}
else
{
cout<<"Failed";
}
}
Sorry for not seeing the question earlier.
From what I am seeing in your code, the test is wrong. The FAILED() macro denotes incorrect execution. Thus from you code, if you see "Failed" on the console, it actually means the execution of the method ran OK.
Change your code to something like:
if ( SUCCEEDED(hr) )
{
cout<<"Model created succesfully";
}
else
{
cout<<"Failed";
}

RBuf8 to char* in Symbian C++

I am downloading a text string from a web service into an RBuf8 using this kind of code (it works..)
void CMyApp::BodyReceivedL( const TDesC8& data ) {
int newLength = iTextBuffer.Length() + data.Length();
if (iTextBuffer.MaxLength() < newLength)
{
iTextBuffer.ReAllocL(newLength);
}
iTextBuffer.Append(data);
}
I want to then convert the RBuf8 into a char* string I can display in a label or whatever.. or for the purposes of debug, display in
RDebug::Printf("downloading text %S", charstring);
edit for clarity..
My conversion function looks like this..
void CMyApp::DownloadCompleteL() {
{
RBuf16 buf;
buf.CreateL(iTextBuffer.Length());
buf.Copy(iTextBuffer);
RDebug::Printf("downloaded text %S", buf);
iTextBuffer.SetLength(0);
iTextBuffer.ReAlloc(0);
}
But this still causes a crash. I am using S60 3rd Edition FP2 v1.1
What you may need is something to the effect of:
RDebug::Print( _L( "downloaded text %S" ), &buf );
This tutorial may help you.
void RBuf16::Copy(const TDesC8&) will take an 8bit descriptor and convert it into a 16bit descriptor.
You should be able to display any 16bit descriptor on the screen. If it doesn't seem to work, post the specific API you're using.
When an API can be used with an undefined number of parameters (like void RDebug::Printf(const char*, ...) ), %S is used for "pointer to 16bit descriptor". Note the uppercase %S.
Thanks, the %S is a helpful reminder.
However, this doesn't seem to work.. my conversion function looks like this..
void CMyApp::DownloadCompleteL() {
{
RBuf16 buf;
buf.CreateL(iTextBuffer.Length());
buf.Copy(iTextBuffer);
RDebug::Printf("downloaded text %S", buf);
iTextBuffer.SetLength(0);
iTextBuffer.ReAlloc(0);
}
But this still causes a crash. I am using S60 3rd Edition FP2 v1.1
You have to supply a pointer to the descriptor in RDebuf::Printf so it should be
RDebug::Print(_L("downloaded text %S"), &buf);
Although use of _L is discouraged. _LIT macro is preferred.
As stated by quickrecipesonsymbainosblogspotcom, you need to pass a pointer to the descriptor.
RDebug::Printf("downloaded text %S", &buf); //note the address-of operator
This works because RBuf8 is derived from TDes8 (and the same with the 16-bit versions).

Resources