kernel/time/posix-clock.c
Source file repositories/reference/linux-study-clean/kernel/time/posix-clock.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/time/posix-clock.c- Extension
.c- Size
- 6049 bytes
- Lines
- 319
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/export.hlinux/file.hlinux/posix-clock.hlinux/slab.hlinux/syscalls.hlinux/uaccess.hposix-timers.h
Detected Declarations
struct posix_clock_descfunction Copyrightfunction put_posix_clockfunction posix_clock_readfunction posix_clock_pollfunction posix_clock_ioctlfunction posix_clock_openfunction posix_clock_releasefunction posix_clock_registerfunction posix_clock_unregisterfunction get_clock_descfunction put_clock_descfunction pc_clock_adjtimefunction pc_clock_gettimefunction pc_clock_getresfunction pc_clock_settimeexport posix_clock_registerexport posix_clock_unregister
Annotated Snippet
static const struct file_operations posix_clock_file_operations = {
.owner = THIS_MODULE,
.read = posix_clock_read,
.poll = posix_clock_poll,
.unlocked_ioctl = posix_clock_ioctl,
.compat_ioctl = posix_clock_ioctl,
.open = posix_clock_open,
.release = posix_clock_release,
};
int posix_clock_register(struct posix_clock *clk, struct device *dev)
{
int err;
init_rwsem(&clk->rwsem);
cdev_init(&clk->cdev, &posix_clock_file_operations);
err = cdev_device_add(&clk->cdev, dev);
if (err) {
pr_err("%s unable to add device %d:%d\n",
dev_name(dev), MAJOR(dev->devt), MINOR(dev->devt));
return err;
}
clk->cdev.owner = clk->ops.owner;
clk->dev = dev;
return 0;
}
EXPORT_SYMBOL_GPL(posix_clock_register);
void posix_clock_unregister(struct posix_clock *clk)
{
cdev_device_del(&clk->cdev, clk->dev);
down_write(&clk->rwsem);
clk->zombie = true;
up_write(&clk->rwsem);
put_device(clk->dev);
}
EXPORT_SYMBOL_GPL(posix_clock_unregister);
struct posix_clock_desc {
struct file *fp;
struct posix_clock *clk;
};
static int get_clock_desc(const clockid_t id, struct posix_clock_desc *cd)
{
struct file *fp = fget(clockid_to_fd(id));
int err = -EINVAL;
if (!fp)
return err;
if (fp->f_op->open != posix_clock_open || !fp->private_data)
goto out;
cd->fp = fp;
cd->clk = get_posix_clock(fp);
err = cd->clk ? 0 : -ENODEV;
out:
if (err)
fput(fp);
return err;
}
static void put_clock_desc(struct posix_clock_desc *cd)
{
put_posix_clock(cd->clk);
fput(cd->fp);
}
static int pc_clock_adjtime(clockid_t id, struct __kernel_timex *tx)
{
struct posix_clock_desc cd;
int err;
err = get_clock_desc(id, &cd);
if (err)
return err;
if (tx->modes && (cd.fp->f_mode & FMODE_WRITE) == 0) {
err = -EACCES;
goto out;
}
if (cd.clk->ops.clock_adjtime)
err = cd.clk->ops.clock_adjtime(cd.clk, tx);
Annotation
- Immediate include surface: `linux/device.h`, `linux/export.h`, `linux/file.h`, `linux/posix-clock.h`, `linux/slab.h`, `linux/syscalls.h`, `linux/uaccess.h`, `posix-timers.h`.
- Detected declarations: `struct posix_clock_desc`, `function Copyright`, `function put_posix_clock`, `function posix_clock_read`, `function posix_clock_poll`, `function posix_clock_ioctl`, `function posix_clock_open`, `function posix_clock_release`, `function posix_clock_register`, `function posix_clock_unregister`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: pattern implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.