summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremie Koenig <jk@jk.fr.eu.org>2010-08-21 11:09:36 +0000
committerJeremie Koenig <jk@jk.fr.eu.org>2010-08-30 14:29:46 +0200
commita45606d0036565c468b462a207575bf2b4077fd8 (patch)
tree4e94b181b10c1232cd182e31981c1400e541f8c2
parent1f1661d6a5b6f22acb48460b5304e29af2a0a554 (diff)
Implement symlinks
* netfs.c (netfs_validate_stat): For symlinks, fetch the contents and propagate their length into the nn_stat.st_size field. (netfs_attempt_readlink): Implement using procfs_get_contents.
-rw-r--r--netfs.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/netfs.c b/netfs.c
index e98af75..a47861e 100644
--- a/netfs.c
+++ b/netfs.c
@@ -24,6 +24,28 @@ char *netfs_server_version = PROCFS_SERVER_VERSION;
/* Maximum number of symlinks to follow before returning ELOOP. */
int netfs_maxsymlinks = PROCFS_MAXSYMLINKS;
+/* The user must define this function. Make sure that NP->nn_stat is
+ filled with the most current information. CRED identifies the user
+ responsible for the operation. NP is locked. */
+error_t netfs_validate_stat (struct node *np, struct iouser *cred)
+{
+ void *contents;
+ size_t contents_len;
+ error_t err;
+
+ /* Only symlinks need to have their size filled, before a read is
+ attempted. */
+ if (! S_ISLNK (np->nn_stat.st_mode))
+ return 0;
+
+ err = procfs_get_contents (np, &contents, &contents_len);
+ if (err)
+ return err;
+
+ np->nn_stat.st_size = contents_len;
+ return 0;
+}
+
/* The user must define this function. Read from the locked file NP
for user CRED starting at OFFSET and continuing for up to *LEN
bytes. Put the data at DATA. Set *LEN to the amount successfully
@@ -56,7 +78,17 @@ error_t netfs_attempt_read (struct iouser *cred, struct node *np,
error_t netfs_attempt_readlink (struct iouser *user, struct node *np,
char *buf)
{
- return EIO;
+ char *contents;
+ size_t contents_len;
+ error_t err;
+
+ err = procfs_get_contents (np, (void **) &contents, &contents_len);
+ if (err)
+ return err;
+
+ assert (contents_len == np->nn_stat.st_size);
+ memcpy (buf, contents, contents_len);
+ return 0;
}
/* Helper function for netfs_get_dirents() below. CONTENTS is an argz
@@ -210,14 +242,6 @@ error_t netfs_report_access (struct iouser *cred, struct node *np,
/* Trivial or unsupported libnetfs callbacks. */
-/* The user must define this function. Make sure that NP->nn_stat is
- filled with the most current information. CRED identifies the user
- responsible for the operation. NP is locked. */
-error_t netfs_validate_stat (struct node *np, struct iouser *cred)
-{
- return 0;
-}
-
/* The user must define this function. This should attempt a chmod
call for the user specified by CRED on locked node NP, to change
the owner to UID and the group to GID. */