kernel-programming

Collaborative kernel development

Hi, I have to develop a patch for the linux kernel (2.6) for an university course I'm attending. I have to develop this patch with a friend of mine and we need to edit the same files on our computers (2-3 PCs). So, we want to use something like a collaborative editor and/or a version control system. The problem is that we never used some...

Linux Kernel - Socket file descriptor close location

Where in the linux kernel does the closing of a socket's file descriptor occur? I know for a file, the file's file descriptor is closed in fs/open.cs function sys_close(). However, for a socket file descriptor, is this the same location or somewhere else? Also, do sockets utilize the file.c alloc_fd to allocate the file descriptor or do...

Linux Kernel - Check if a file descriptor is taken

In linux kernel programming, is there a way to check if a particular file descriptor is in use for a given process or if it's available? ...

Do mini-filter functions need APCs enabled?

Hello, Many Zw* functions that work with files (such as ZwCreateFile) need to be called at PASSIVE_LEVEL with APCs enabled: http://msdn.microsoft.com/en-us/library/ff566424%28VS.85%29.aspx. This is because, internally, I/O operations are asynchronously and the completion of an operation is delivered through an APC (correct me if I'm wro...

Kernel module for /proc

How to write a kernel module that creates a directory in /proc named mymod and a file in it name is mymodfile. This file should accept a number ranged from 1 to 3 when written into it and return the following messages when read based on the number already written into it: • 1: Current system time (in microseconds precision) • 2: System ...

First Come, First Served process scheduling

i have 4 processes: p1 - bursts 5, priority: 3 p2 - bursts 8, priority: 2 p3 - bursts 12, priority: 2 p4 - bursts 6, priority: 1 Assuming that all processes arrive at the scheduler at the same time what is the average response time and average turnaround time? For FCFS is it ok to have them in the order p1, p2, p3, p4 in the executi...

inode_operations , warning: initialization from incompatible pointer type

Hi everyone, I'm trying to compile a simple Kernel program that read and write from a proc file. I'm trying to set permission to that file by overriding the permission fp in inode_operations struct (.permission) static int module_permission(struct inode *inode, int op, struct nameidata *foo) { . . . } static struct inode_opera...

Is it easier to write filesystem drivers in userspace than in kernel space?

I will use the Linux NTFS driver as an example. The Linux kernel NTFS driver only has very limited write support in the kernel, and after 5 years it is still considered experimental. The same development team creates the ntfsmount userspace driver, which has almost perfect write support. Likewise, the NTFS-3G project which is written ...

file_operations Question, how do i know if a process that opened a file for writing has decided to close it ?

Hi Kernel Gurus, I'm currently writing a simple "multicaster" module. Only one process can open a proc filesystem file for writing, and the rest can open it for reading. To do so i use the inode_operation .permission callback, I check the operation and when i detect someone open a file for writing I set a flag ON. i need a way to det...

task_current redundant field

Hi, I'm writing a kernel module that reads from a /proc file. When someone writes into the /proc file the reader will read it, but if it reads again while there is no "new" write, it should be blocked. In order to remember if we already read, i need to keep a map of the latest buffer that process read. To avoid that, I was told that th...

Saving information in the IO System

Hi Kernel Gurus, I need to write a kernel module that simulate a "multicaster" Using the /proc file system. Basically it need to support the following scenarios: 1) allow one write access to the /proc file and many read accesses to the /proc file. 2) The module should have a buffer of the contents last successful write. Each write sh...

Writing an OS kernel in assembly with NASM

I want to know what is the standard way for writing a -simple- kernel to be compiled on NASM? To get it clearer: I was able to define the code block with all the following ways: [segment code] [segment .code] segment code segment .code [section code] [section .code] section code section .code I need to know what is the standard way ...

Mini-filters callbacks and APCs (Windows)

Hello, in many cases callbacks registered by a mini-filter (pre/post operations) are called at PASSIVE_LEVEL. In case the pre-callback decides that it needs to do some work after the completion of some operation, it will ask the filter-manager to call the post-callback for that operation. The documentation states that if the pre-callba...

Problem with .release behavior in file_operations

Hello, I'm dealing with a problem in a kernel module that get data from userspace using a /proc entry. I set open/write/release entries for my own defined /proc entry, and manage well to use it to get data from userspace. I handle errors in open/write functions well, and they are visible to user as open/fopen or write/fwrite/fprintf err...

How can I uniquely identify users trying to open() a kernel module?

I'm working on a kernel module and I'm trying to uniquely identify each one of the users trying to open() the module (can be either processes or threads). What is the best way to identify them? Is there an ID I can get from a system call? I wish to get all users in a list that specifies whether they're trying to open the module for rea...

What is the sequence followed by the Linux kernel to configure a device?

As I understood after reading the chapter related to The Linux Device Model in the Linux Device Drivers 3rd Edition, when a new device is configured, the kernel (2.6) follows more or less this sequence: The Device is registered in the driver core (device_register(), what includes device initialization) A kobject is registered in the de...

What does a linux device need to be seen by Hal?

I'm trying to learn about device drivers on Linux Kernel, for that I've created three modules with: A bus type A device driver A fake device that does nothing now, only is registered Everything works fine, I can load the bus, the driver and the module that creates the device. Everything appears on sysfs, including the link between th...

how can i make IOCTL calls in kernel mode (windows)

In user mode IOCTL calls can be made via DeviceIoControl function. What can I use in kernel mode to issue IOCTL calls? I must use this inside a filesystem minifilter driver. BACKGROUND I am writing a filesystem minifilter driver, and I must issue IOCTL calls to storage devices to find out their serial number and capabilities (removable ...

What is the recommended set of tools required for writing an OS kernel from scratch?

Do they use Windows to write Windows? I don't know, but if they did and suddenly there was no more Windows, what would they use to re-write Windows? ...

Need complete picture of virtual adress space

Hello, This image gives a good picture about Virtual Adress space. But it only says half of the story. It only gives complete picture of User Adress space ie.. lower 50% (or 75% in some cases). What about the rest 50% (or 25%) which is occupied by the kernel. I know kernel also has so many different things like kernel modules , devic...