summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1995-09-17 22:06:56 +0000
committerRoland McGrath <roland@gnu.org>1995-09-17 22:06:56 +0000
commita8b71d587f3a3ff6b0f15e38a332987aa77bdb03 (patch)
tree31e82884f4f0bc74b8fcaf53412a9ae3ff329545
parent5c141b1658fb39b940ba50859baab26219d79009 (diff)
Renamed from file-trunate.c.
(diskfs_S_file_set_size): Renamed from diskfs_s_file_truncate. If SIZE exceeds the file size, extend the file.
-rw-r--r--libdiskfs/file-set-size.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/libdiskfs/file-set-size.c b/libdiskfs/file-set-size.c
index 06fc4671..f4d3f110 100644
--- a/libdiskfs/file-set-size.c
+++ b/libdiskfs/file-set-size.c
@@ -1,4 +1,4 @@
-/* libdiskfs implementation of fs.defs: file_truncate
+/* libdiskfs implementation of fs.defs: file_set_size
Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation
This program is free software; you can redistribute it and/or
@@ -19,16 +19,27 @@
#include "fs_S.h"
#include <fcntl.h>
-/* Implement file_truncate as described in <hurd/fs.defs>. */
+/* Implement file_set_size as described in <hurd/fs.defs>. */
kern_return_t
-diskfs_S_file_truncate (struct protid *cred,
+diskfs_S_file_set_size (struct protid *cred,
off_t size)
{
CHANGE_NODE_FIELD (cred,
- ({
- if (!(cred->po->openstat & O_WRITE))
- err = EINVAL;
- else
- err = diskfs_truncate (np, size);
- }));
+ ({
+ if (!(cred->po->openstat & O_WRITE))
+ err = EINVAL;
+ else if (size < np->dn_stat.st_size)
+ err = diskfs_truncate (np, size);
+ else if (size > np->dn_stat.st_size)
+ {
+ err = diskfs_grow (np, size, cred);
+ if (! err)
+ {
+ np->dn_stat.st_size = size;
+ np->dn_set_ctime = np->dn_set_mtime = 1;
+ }
+ }
+ else
+ err = 0; /* Setting to same size. */
+ }));
}