program to know list of attached devices to my linux laptop - linux-kernel

I am writing a small apllication that will tell list of attached devices to my linux laptop.There is one utility that is udev that can be used for hot plugging but is their some other way where i can write simple c program where it will tell that these devices are attached to your laptop.or it will pop up message when new devices will be attached and removed.please provide some basic stuff so that i can start my project.thanx in advance.

As far as I can see, there are two parts to your question. I will answer them separately.
Get a list of current devices
Your source of information would be /sys/ and proc and their sub directories. You can get most information by simply reading the appropriate file from here. For example, trying running utilities such as lsusb using strace and see what files they access - you will see it reads /sys/devices. Also look at lshw and it's source code.
Notification of hardware events
This is where udev comes in. Here are couple of articles I came across they may be helpful:
http://www.signal11.us/oss/udev/
http://www.reactivated.net/writing_udev_rules.html

Related

How to filter read calls using minifilter driver?

I'm completely new to minifilter drivers. In fact new to windows development as such. I want to create a minifilter driver, attach it to one of my local disk( say D drive) and filter the READ calls coming from the files in that drive.
After so much effort, I somehow installed Visual Studio 2013 and then installed WDK 8. Then I took the minispy example. After changing some settings for that project, I was able to successfully build the project.
The problem is, whenever I run minispy.exe, it is filtering only the IRP_MJ_CREATE calls and logging it either on the terminal or in a file. I couldn't find any place in the code where it is mentioned to filter only the IRP_MJ_CREATE calls.
It will be really useful if someone can help in coming up with a minifilter for filtering out the IRP_MJ_CREATE calls from one particular drive.
Thanks in advance !
In the minispy sample code, the file Registration Data.c defines a callback structure that tells filter manager what to call for what operations. For minispy, this is set to call SpyPreOperationCallback for every pre-operation, including IRP_MJ_CREATE.
It should be logging much more than just the create operations. Perhaps it's not attached to the volume you're interested in?
If you want to filter only calls from one drive, there are a few ways you can do that. You can only attach your filter to the drives you are interested in (see fltmc attach command-line options. You can also code your filter to attach automatically to certain volumes, and you could also do the filtering yourself by getting the file name with FltGetFileNameInformation and deciding whether or not to log it.
Which is right for you will very much depend on how you want to use it.

How does Mac OS X know what programs are using a mounted filesystem?

This may sound like a silly question but up until recently if you tried to unmount a volume that was in use the Finder reported that it was in use, but not by whom. This is simple Unix functionality, if a file is open on a mount point, do not allow it to eject. But now they seem to have added functionality that lets the user know what programs are currently using a mounted system, and I have been looking through man pages of fopen,stat, etc. for Unix like operating systems(distros of linux) and I can't seem to find similar functionality.
Is this functionality specialized, or am I just looking in the wrong place?
There are BSD-level calls (mainly lsof, whose source is at http://www.opensource.apple.com/source/lsof/) that let you examine the list of files open in a process. Activity Monitor, for example, uses them.
Using lsof as a starting point, you can iterate through processes and see if any of them are using a file under the mount point you're examining. There may be more efficient ways to do it though, of which I'm not aware. :)
It's somewhat specialized. Check out the lsof utility.
Check the man page for fuser, and run fuser -c /mountpoint

Making a soft copy(file) of everything printed to any printer from a Windows workstation?

I have been looking into the possibility of creating a soft copy(image/EMF file) of everything printed from Windows - for archival purposes. Does anyone know if it is possible to create a hooking DLL that can grab the printed data in such a general way?
A low tech way of solving it might be to install pdf printer driver as the default printer and remove all others and set it up to automatically write all the files to certain directory on the network and then write a tiny app on another computer to monitor that folder for changes and if any new pdfs appear just print them out to a real printer.
Edit: Otherwise there's apparently something called the Print Monitor API. Here's an article that describes using that from VC++ 6 and seems to be pretty much what you want (assuming it's still supported by the OS you use).
Having looked at this problem in more detail the best solution seems to handle it through Spooler notifications in the Win32.

SMS war continues, ideas welcome

I am trying to make U9 telit modem send SMS messages. I think I handle protocol correctly, at least, I manage to send them, but only under these circumstances: the native application was executed beforehand, and killed by task manager (without giving it a chance to initialize things).
It looks like the supplied application is good at doing certain initialization/deinitialization which is critical. I also see the difference between the two states in output of AT+CIND command. When I am trying to do things on my own, it returns zeroes (including signal quality), but when I run the same command after killing the native application, the output looks reasonable.
I am out nearly of ideas. I have tried many things, including attempts to spy at modem's COM ports (didn't work). Haven't tried setting windows hooks to see what the application is trying to get thru.
Perhaps you have encountered a similar situation?
Agg's "Advanced Serial Port Monitor" actually helped a lot. Sometimes it caused blue screen, but it helped uncover secret commands which seem to help. AT+PCFULL is not described anywhere on the net, for example. The real trigger of non-operatio was AT+CFUN, the power disable/standby feature.
Also, it appeared that we have more issues. At first, the modem appears on the bus only as disk drive. It doesn't want to appear as any other devices before the drivers are installed. So, the U9 Telit software sends an IOCTL to disk driver to tell the modem to reappear as more devices (modem, 3 serial ports, another disk drive).

Sample a process on Mac OS X from a C/C++ program

The Sample Process feature in Activity Monitor is quite a useful thing. However, I need to do the same thing (take samples) of a certain process from another running process (C/C++) or a command line.
Is there any way to do this? I have been googling for this since a few days without any luck.
There is a command-line utility sample.
Example:
sample Safari -file /dev/stdout
It will get exactly the same output with Activity Monitor.
There are some few commandsline application that come in handy: sample and top.
If you want to write your own program, you can use the sysctl system call to get such information. However, it's quite tedious.
I would recommend installing procfs file system (built with MacFUSE). This would create a new "directory" at /proc that contains a lot of useful information for each application (e.g. memory usage, cpu usage, locks, opened files, sockets, threads, etc). The site gives a sample of how it can be accessed. Then you can simply script your access to those files.

Resources