It sounds like you may be duplicating prior work, but do look at the Linux source code since that's what I would do.

Bob