CDROM function - where does the function pointer go to? - linux

I am trying to debug an issue where the standard linux CDROMEJECT returns an error even though the disk ejected.
Standard eject command used.
ioctl(FP,CDROMEJECT)
When I look at the cdrom.c I can see the eject function and the errors (e.g: http://lxr.free-electrons.com/source/drivers/cdrom/cdrom.c#L2303). I am fine with where error codes are returned but you also have lines like this:
cdi->ops->lock_door(cdi, 0)
Now lock_door is a function pointer (see header file here). My issue is I cannot for the life-of-me figure out which function the lock_door pointer points to! I would expect this to point to a function that then sends a SCSI command to the CD/DVD drive.
I suspect I am missing some fundamental but really not sure what! Any idea where I find where the function pointers in struct cdrom_device_ops point to?

If you do an LXR "Freetext Search" for ".lock_door"
you can see
it being set for the scsi driver here
and if you click on sr_lock_door
you find it defined in sr_ioctl.c:
int sr_lock_door(struct cdrom_device_info *cdi, int lock) {
Scsi_CD *cd = cdi->handle;
return scsi_set_medium_removal(cd->device, lock ?
SCSI_REMOVAL_PREVENT : SCSI_REMOVAL_ALLOW);
}

Related

zbus connection not displayed in busctl list

I'm using the zbus crate to make a server able to get events from the dbus.
It works well my code (basically the same as the example from the documentation) is able to receive events so it's fine.
I use busctl to send an event like in the example:
busctl --user call org.zbus.MyGreeter /org/zbus/MyGreeter org.zbus.MyGreeter1 SayHello s "Maria"
And my code is able to receive the event with the parameter just fine.
The thing is I'm having some issues with udev and while I was trying to fix it I found some weird things:
If I send an event with another user it fails with Call failed: the name org.zbus.MyGreeter was not provided by any .service files while my program is running
When I do busctl list --acquired I don't see org.zbus.MyGreeter in the result
My question is: is it normal my program does not appear in the busctl list? Am I doing something wrong or do I use the wrong library to do what I want to do?
Ok it seems there are 2 busses and I was not using the system bus.
I had to replace the method session to system to indicates I want my program to run on the system bus.
Like this:
let _ = ConnectionBuilder::system()?
.name("org.zbus.MyGreeter")?
.serve_at("/org/zbus/MyGreeter", greeter)?
.build()
.await?;
Doing this is not enough because my program does not have to permission to create a service on the bus system. So I had to create a file in /usr/share/dbus-1/system.d where I did write the configuration needed.

Error while calling SetsockoptString with IP_ADD_SOURCE_MEMBERSHIP in golang

I need to call IP_ADD_SOURCE_MEMBERSHIP in golang with params. Here's my code
s := "239.195.140.6 0.0.0.0 91.203.255.242"
err = syscall.SetsockoptString(socket, syscall.IPPROTO_IP, syscall.IP_ADD_SOURCE_MEMBERSHIP, s)
But it throw invalid argument error
What's the right way to make it?
man 7 ip says IP_ADD_SOURCE_MEMBERSHIP is supposed to take an ip_mreq_source structure, but by using SetsockoptString, you're giving it a string instead. I don't see a variant of Setsockopt that passes the right kind of structure, so it looks like if you want to do this in Go, then you'll have to write some low-level glue code yourself.

How the function works cdev_add()?

Do I understand correctly that when the structure is initialized
struct dev_t dev;
dev = MKDEV(major,minor_first);
I create only the device file, it's right to say - to the node. Next, should I indicate how I will work with this device? To do this, you need the function
cdev_add(&my_ch_dev, dev, minor_count);
after
cdev_init(&my_ch_dev ,&dev_fops);
So, I mean that my driver will work with the created node as a character device? Thanks in advance!
Here is the details how it works
dev = MKDEV(major,minor_first);
Still kernel doesn't know whether we selected major/minor number or not, so for this you need to register he device by calling register_chrdev_region()
register_chrdev_region(dev,minor_count,"AYRAT_DEVICE"); so till now number(major/minor) has reserved the name(dev) so that other driver will not get the same name. Next you need to register your driver with kernel.
register with cdev by calling cdev_init(&my_ch_dev ,&dev_fops); Next you need to inform to kernel that we filled all member of struct cdev, so for this use cdev_add().
cdev_add(&my_ch_dev, dev, minor_count);

Arduino - How to read a string from the Serial Port

I just recently started working with Arduino. I just have a quick question, I tried searching for an answer but have failed for days. Basically what I wanna ask is if there is a way to read a whole line from the Serial Port. Like the line highlighted in the picture below.
What I'm trying to do is using a Bluesmirf Silver Rn-42 to search the area for a bluetooth device and trigger a signal if a matching address is found. I just cant figure out how to read messages that are already on the Serial port.
Use .readString()
Example code:
String myString;
void setup()
{
Serial.begin(9600);
}
void loop()
{
while (Serial.available())
{
myString = Serial.readString();
//do stuff with the string
}
}
If you want to read something that's already in the serial port from the Arduino end, then you need to rethink your code. Anything you produce within your code to print to the serial monitor will already be in your program ready to access if you make it available in the right way. The exemplar string you provided, is simply an array of characters that you can store in an element within an array, making it accessible whenever you need it.
Hints:
Never read back from the serial monitor, it's really slow -.-
Make all the resources you require accessible and available in memory at the time you need it to save hassel & processing power.
Never make the same mistake twice.
However, if you want to read from the COM port that the Arduino is connected to in Windows, then you'll need to work with Libusb libraries found here: http://www.libusb.org/ for C. Any other language will be library or import dependent.

Why the root of my stack in node.js + node-inspector is not the real root, I mean a function ran from an outrside source (like driver)

I have a a debugger point in my code and I look in the call stack, I see about 11 lines deep but I cannot dig more. In the last level, the deeper one, is not a response from an async call like a driver nor an entry program, it's just some function called by another. But I cannot see that another function...
Any help how to see the other function?
thanks
You could try out https://github.com/CrabDude/trycatch and wrap some of your initial code with it.
var trycatch = require('trycatch')
trycatch(yourOriginalFunction, exceptionHandlerCallback)
It should give you a long stacktrace with your original function in it.
There are other libraries trying to solving this problem too but I haven't used them:
https://github.com/tlrobinson/long-stack-traces
https://github.com/mattinsler/longjohn

Resources