Skip to contentSkip to conversation

struct char_device

PATCH [email protected] 2 participants 2 messages May 22, 2001 – May 23, 2001

lore
Share & tools
lore
#0 lore raw

From [email protected] Wed May 23 00:39:23 2001

On Tue, 22 May 2001 [email protected] wrote:
>
> The operations are different, but all bdev/cdev code is identical. >
> So the choice is between two uglies:
> (i) have some not entirely trivial amount of code twice in the kernel > (ii) have a union at the point where the struct operations > is assigned.
>
> I preferred the union.

I would much prefer a union of pointers over a pointer to a union.

Why? Because if you have a "struct inode", you also have enough information to decide _which_ of the two types of pointers you have, so you can do the proper dis-ambiguation of the union and properly select either 'inode->dev.char' or 'inode->dev.block' depending on other information in the inode.

I am not sure whether we agree or differ in opinion. I wouldn't mind

/* pairing for dev_t to bd_op/cd_op */

struct bc_device {
        struct list_head        bd_hash;
        atomic_t                bd_count;
        dev_t                   bd_dev;
        atomic_t                bd_openers;
        union {
		struct block_device_operations_and_data *bd_op;
		struct char_device_operations_and_data *cd_op;
	}
        struct semaphore        bd_sem;
};

typedef struct bc_device *kdev_t;

and in an inode

	kdev_t dev;
	dev_t rdev;

In reality we want the pair (dev_t, pointer to stuff), but then there is all this administrative nonsense needed to make sure that nobody uses the pointer after the module has been unloaded that makes the pointer a bit thicker.

And we should not depend on the "inode->dev.xxxx" pointer being valid all the time, as there is absolutely zero point in initializing the pointer every time somebody does a "ls -l /dev".

Yes, that is why I want to go back and have dev_t rdev, not kdev_t. The lookup is done when the device is opened.

Andries

#1 lore raw
Quoted 15 lines · On Wed, 23 May 2001 [email protected] wrote:

I am not sure whether we agree or differ in opinion. I wouldn't mind

/* pairing for dev_t to bd_op/cd_op */

struct bc_device {
        struct list_head        bd_hash;
        atomic_t                bd_count;
        dev_t                   bd_dev;
        atomic_t                bd_openers;
        union {
		struct block_device_operations_and_data *bd_op;
		struct char_device_operations_and_data *cd_op;
	}
        struct semaphore        bd_sem;
};
Quoted 1 line

typedef struct bc_device *kdev_t;

What for? What part of the kernel needs a device and doesn't know apriory whether it's block or character one?

Quoted 3 lines

and in an inode

	kdev_t dev;

Useless. If you hope that block_device will help to solve rmmod races - sorry, it won't. Wrong layer.

Quoted 1 line
	dev_t rdev;

Reasonable.