* Made the internal file systems correctly handle the timespec struct stat

times.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31059 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2009-06-15 14:03:24 +00:00
parent 348ad702b6
commit fa00207c50
5 changed files with 74 additions and 41 deletions

View File

@ -84,8 +84,8 @@ struct devfs_vnode {
struct devfs_vnode* all_next;
ino_t id;
char* name;
time_t modification_time;
time_t creation_time;
timespec modification_time;
timespec creation_time;
uid_t uid;
gid_t gid;
struct devfs_vnode* parent;
@ -151,6 +151,18 @@ static struct devfs* sDeviceFileSystem = NULL;
// #pragma mark - devfs private
static timespec
current_timespec()
{
bigtime_t time = real_time_clock_usecs();
timespec tv;
tv.tv_sec = time / 1000000;
tv.tv_nsec = (time % 1000000) * 1000;
return tv;
}
static int32
scan_mode(void)
{
@ -228,7 +240,7 @@ devfs_create_vnode(struct devfs* fs, devfs_vnode* parent, const char* name)
return NULL;
}
vnode->creation_time = vnode->modification_time = time(NULL);
vnode->creation_time = vnode->modification_time = current_timespec();
vnode->uid = geteuid();
vnode->gid = parent ? parent->gid : getegid();
// inherit group from parent if possible
@ -333,7 +345,7 @@ devfs_insert_in_dir(struct devfs_vnode* dir, struct devfs_vnode* vnode)
}
vnode->parent = dir;
dir->modification_time = time(NULL);
dir->modification_time = current_timespec();
notify_entry_created(sDeviceFileSystem->id, dir->id, vnode->name,
vnode->id);
@ -360,7 +372,7 @@ devfs_remove_from_dir(struct devfs_vnode* dir, struct devfs_vnode* removeNode)
else
dir->stream.u.dir.dir_head = vnode->dir_next;
vnode->dir_next = NULL;
dir->modification_time = time(NULL);
dir->modification_time = current_timespec();
notify_entry_removed(sDeviceFileSystem->id, dir->id, vnode->name,
vnode->id);
@ -1796,11 +1808,11 @@ devfs_read_stat(fs_volume* _volume, fs_vnode* _vnode, struct stat* stat)
stat->st_uid = vnode->uid;
stat->st_gid = vnode->gid;
stat->st_atime = time(NULL);
stat->st_mtime = stat->st_ctime = vnode->modification_time;
stat->st_crtime = vnode->creation_time;
stat->st_atim = current_timespec();
stat->st_mtim = stat->st_ctim = vnode->modification_time;
stat->st_crtim = vnode->creation_time;
// ToDo: this only works for partitions right now - if we should decide
// TODO: this only works for partitions right now - if we should decide
// to keep this feature, we should have a better solution
if (S_ISCHR(vnode->stream.type)) {
//device_geometry geometry;
@ -1854,9 +1866,9 @@ devfs_write_stat(fs_volume* _volume, fs_vnode* _vnode, const struct stat* stat,
vnode->gid = stat->st_gid;
if (statMask & B_STAT_MODIFICATION_TIME)
vnode->modification_time = stat->st_mtime;
vnode->modification_time = stat->st_mtim;
if (statMask & B_STAT_CREATION_TIME)
vnode->creation_time = stat->st_crtime;
vnode->creation_time = stat->st_crtim;
notify_stat_changed(fs->id, vnode->id, statMask);
return B_OK;

View File

@ -89,7 +89,7 @@ struct legacy_driver {
const char* name;
dev_t device;
ino_t node;
time_t last_modified;
timespec last_modified;
image_id image;
uint32 devices_used;
bool binary_updated;
@ -567,7 +567,7 @@ add_driver(const char *path, image_id image)
driver->device = stat.st_dev;
driver->node = stat.st_ino;
driver->image = image;
driver->last_modified = stat.st_mtime;
driver->last_modified = stat.st_mtim;
driver->devices_used = 0;
driver->binary_updated = false;
driver->priority = priority;
@ -756,7 +756,8 @@ dump_driver(int argc, char** argv)
kprintf(" image: %ld\n", driver->image);
kprintf(" device: %ld\n", driver->device);
kprintf(" node: %Ld\n", driver->node);
kprintf(" last modified: %ld\n", driver->last_modified);
kprintf(" last modified: %ld.%lu\n", driver->last_modified.tv_sec,
driver->last_modified.tv_nsec);
kprintf(" devs used: %ld\n", driver->devices_used);
kprintf(" devs published: %ld\n", driver->devices.Count());
kprintf(" binary updated: %d\n", driver->binary_updated);

View File

@ -1,6 +1,6 @@
/*
* Copyright 2007-2008, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2003-2007, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2003-2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
@ -137,11 +137,11 @@ class Inode {
status_t InitCheck();
bool IsActive() const { return fActive; }
time_t CreationTime() const { return fCreationTime; }
void SetCreationTime(time_t creationTime)
timespec CreationTime() const { return fCreationTime; }
void SetCreationTime(timespec creationTime)
{ fCreationTime = creationTime; }
time_t ModificationTime() const { return fModificationTime; }
void SetModificationTime(time_t modificationTime)
timespec ModificationTime() const { return fModificationTime; }
void SetModificationTime(timespec modificationTime)
{ fModificationTime = modificationTime; }
mutex *RequestLock() { return &fRequestLock; }
@ -171,8 +171,8 @@ class Inode {
status_t Deselect(uint8 event, selectsync *sync, int openMode);
private:
time_t fCreationTime;
time_t fModificationTime;
timespec fCreationTime;
timespec fModificationTime;
RingBuffer fBuffer;
@ -319,7 +319,10 @@ Inode::Inode()
fWriteCondition.Publish(this, "pipe");
mutex_init(&fRequestLock, "pipe request");
fCreationTime = fModificationTime = time(NULL);
bigtime_t time = real_time_clock();
fModificationTime.tv_sec = time / 1000000;
fModificationTime.tv_nsec = (time % 1000000) * 1000;
fCreationTime = fModificationTime;
}
@ -855,10 +858,10 @@ fifo_read_stat(fs_volume *volume, fs_vnode *vnode, struct ::stat *st)
st->st_blksize = 4096;
// TODO: Just pass the changes to our modification time on to the super node.
st->st_atime = time(NULL);
st->st_mtime = st->st_ctime = fifo->ModificationTime();
// st->st_crtime = inode->CreationTime();
// TODO: Just pass the changes to our modification time on to the super node.
st->st_atim.tv_sec = time(NULL);
st->st_atim.tv_nsec = 0;
st->st_mtim = st->st_ctim = fifo->ModificationTime();
return B_OK;
}

View File

@ -60,8 +60,8 @@ struct rootfs_vnode {
struct rootfs_vnode* all_next;
ino_t id;
char* name;
time_t modification_time;
time_t creation_time;
timespec modification_time;
timespec creation_time;
uid_t uid;
gid_t gid;
struct rootfs_vnode* parent;
@ -102,6 +102,18 @@ namespace {
#define ROOTFS_HASH_SIZE 16
static timespec
current_timespec()
{
bigtime_t time = real_time_clock_usecs();
timespec tv;
tv.tv_sec = time / 1000000;
tv.tv_nsec = (time % 1000000) * 1000;
return tv;
}
static uint32
rootfs_vnode_hash_func(void* _v, const void* _key, uint32 range)
{
@ -150,7 +162,7 @@ rootfs_create_vnode(struct rootfs* fs, struct rootfs_vnode* parent,
vnode->id = fs->next_vnode_id++;
vnode->stream.type = type;
vnode->creation_time = vnode->modification_time = time(NULL);
vnode->creation_time = vnode->modification_time = current_timespec();
vnode->uid = geteuid();
vnode->gid = parent ? parent->gid : getegid();
// inherit group from parent if possible
@ -235,7 +247,7 @@ rootfs_insert_in_dir(struct rootfs* fs, struct rootfs_vnode* dir,
}
vnode->parent = dir;
dir->modification_time = time(NULL);
dir->modification_time = current_timespec();
notify_stat_changed(fs->id, dir->id, B_STAT_MODIFICATION_TIME);
return B_OK;
@ -261,7 +273,7 @@ rootfs_remove_from_dir(struct rootfs* fs, struct rootfs_vnode* dir,
dir->stream.dir.dir_head = vnode->dir_next;
vnode->dir_next = NULL;
dir->modification_time = time(NULL);
dir->modification_time = current_timespec();
notify_stat_changed(fs->id, dir->id, B_STAT_MODIFICATION_TIME);
return B_OK;
}
@ -1002,9 +1014,10 @@ rootfs_read_stat(fs_volume* _volume, fs_vnode* _v, struct stat* stat)
stat->st_uid = vnode->uid;
stat->st_gid = vnode->gid;
stat->st_atime = time(NULL);
stat->st_mtime = stat->st_ctime = vnode->modification_time;
stat->st_crtime = vnode->creation_time;
stat->st_atim.tv_sec = real_time_clock();
stat->st_atim.tv_nsec = 0;
stat->st_mtim = stat->st_ctim = vnode->modification_time;
stat->st_crtim = vnode->creation_time;
return B_OK;
}
@ -1037,9 +1050,9 @@ rootfs_write_stat(fs_volume* _volume, fs_vnode* _vnode, const struct stat* stat,
vnode->gid = stat->st_gid;
if ((statMask & B_STAT_MODIFICATION_TIME) != 0)
vnode->modification_time = stat->st_mtime;
vnode->modification_time = stat->st_mtim;
if ((statMask & B_STAT_CREATION_TIME) != 0)
vnode->creation_time = stat->st_crtime;
vnode->creation_time = stat->st_crtim;
mutex_unlock(&fs->lock);

View File

@ -288,13 +288,17 @@ socket_read_stat(struct file_descriptor *descriptor, struct stat *st)
st->st_size = 0;
st->st_rdev = 0;
st->st_blksize = 1024; // use MTU for datagram sockets?
time_t now = time(NULL);
st->st_atime = now;
st->st_mtime = now;
st->st_ctime = now;
st->st_crtime = now;
st->st_type = 0;
timespec now;
now.tv_sec = time(NULL);
now.tv_nsec = 0;
st->st_atim = now;
st->st_mtim = now;
st->st_ctim = now;
st->st_crtim = now;
return B_OK;
}