AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
attr.c File Reference

Changing a vnode's attributes: its mode (chmod()), its owner (chown()) and its times (utimensat()). More...

#include <core/system.h>
#include <core/time.h>
#include <fs/vfs.h>

Go to the source code of this file.

Functions

static int store (struct vnode *vnode, struct vnode *saved)
 Has the filesystem store a vnode's new attributes, and restores the old ones (saved) if it can't.
int vfs_chmod (struct vnode *vnode, mode_t mode, struct uio *uio)
 Changes a vnode's permission bits.
int vfs_chown (struct vnode *vnode, uid_t uid, gid_t gid, struct uio *uio)
 Changes a vnode's owner and group.
static void set_time (_time_t *time, const struct aquila_timespec *ts, struct timespec *now)
 Sets one time as utimensat() asks: to now for UTIME_NOW (or no time given), unchanged for UTIME_OMIT, to the time given otherwise.
int vfs_utimens (struct vnode *vnode, const struct aquila_timespec times[2], struct uio *uio)
 Changes a vnode's access and modification times, for utimensat().

Detailed Description

Changing a vnode's attributes: its mode (chmod()), its owner (chown()) and its times (utimensat()).

The vnode is changed in memory first, then the filesystem stores it (vops.setattr); if that fails, the vnode is restored as it was.

Definition in file attr.c.

Function Documentation

◆ set_time()

void set_time ( _time_t * time,
const struct aquila_timespec * ts,
struct timespec * now )
static

Sets one time as utimensat() asks: to now for UTIME_NOW (or no time given), unchanged for UTIME_OMIT, to the time given otherwise.

Definition at line 97 of file attr.c.

References set_time(), timespec::tv_nsec, and timespec::tv_sec.

Referenced by set_time(), and vfs_utimens().

◆ store()

int store ( struct vnode * vnode,
struct vnode * saved )
static

Has the filesystem store a vnode's new attributes, and restores the old ones (saved) if it can't.

Returns 0 or the filesystem's error.

Definition at line 14 of file attr.c.

References vnode::atime, vnode::ctime, vnode::gid, vnode::mode, vnode::mtime, store(), vnode::uid, and vfs_setattr().

Referenced by store(), vfs_chmod(), vfs_chown(), and vfs_utimens().

◆ vfs_chmod()

int vfs_chmod ( struct vnode * vnode,
mode_t mode,
struct uio * uio )

Changes a vnode's permission bits.

Only its owner, or root, may do it.

Parameters
vnodethe vnode
modethe new permissions (the file type is kept)
uiowho is asking
Returns
0, -EPERM, or the filesystem's error

Definition at line 38 of file attr.c.

References vnode::ctime, gettime(), uio::gid, vnode::gid, vnode::mode, store(), uio::uid, vnode::uid, and vfs_chmod().

Referenced by do_fchmodat(), sys_fchmod(), and vfs_chmod().

◆ vfs_chown()

int vfs_chown ( struct vnode * vnode,
uid_t uid,
gid_t gid,
struct uio * uio )

Changes a vnode's owner and group.

Root may change both; a file's owner may only change its group, to their own group.

Parameters
vnodethe vnode
uidthe new owner, or (uid_t) -1 to keep it
gidthe new group, or (gid_t) -1 to keep it
uiowho is asking
Returns
0, -EPERM, or the filesystem's error

Definition at line 68 of file attr.c.

References vnode::ctime, gettime(), uio::gid, vnode::gid, vnode::mode, store(), uio::uid, vnode::uid, and vfs_chown().

Referenced by do_fchownat(), sys_fchown(), and vfs_chown().

◆ vfs_utimens()

int vfs_utimens ( struct vnode * vnode,
const struct aquila_timespec times[2],
struct uio * uio )

Changes a vnode's access and modification times, for utimensat().

Setting them to the current time needs ownership or write permission; setting them to other times needs ownership.

Parameters
vnodethe vnode
timesthe access and modification times (each may be UTIME_NOW or UTIME_OMIT), or NULL for now
uiowho is asking
Returns
0, -EINVAL for a bad time, -EPERM, -EACCES, or the filesystem's error

Definition at line 124 of file attr.c.

References vnode::atime, vnode::ctime, gettime(), vnode::mtime, NULL, set_time(), store(), uio::uid, vnode::uid, vfs_access(), vfs_utimens(), and VFS_W.

Referenced by sys_utimensat(), and vfs_utimens().