]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/9p/client.c
net/9p: Handle the server returned error properly
[net-next-2.6.git] / net / 9p / client.c
index 0aa79faa98509a1d91f71cec5c307f3522c2a58d..4ff068e98f76901eb3cce7c059859f1c1cd00d30 100644 (file)
@@ -460,7 +460,8 @@ static int p9_check_errors(struct p9_client *c, struct p9_req_t *req)
                        return err;
                }
 
-               if (p9_is_proto_dotu(c))
+               if (p9_is_proto_dotu(c) ||
+                       p9_is_proto_dotl(c))
                        err = -ecode;
 
                if (!err || !IS_ERR_VALUE(err))
@@ -1321,7 +1322,8 @@ static int p9_client_statsize(struct p9_wstat *wst, int proto_version)
        if (wst->muid)
                ret += strlen(wst->muid);
 
-       if (proto_version == p9_proto_2000u) {
+       if ((proto_version == p9_proto_2000u) ||
+               (proto_version == p9_proto_2000L)) {
                ret += 2+4+4+4; /* extension[s] n_uid[4] n_gid[4] n_muid[4] */
                if (wst->extension)
                        ret += strlen(wst->extension);
@@ -1364,3 +1366,117 @@ error:
        return err;
 }
 EXPORT_SYMBOL(p9_client_wstat);
+
+int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb)
+{
+       int err;
+       struct p9_req_t *req;
+       struct p9_client *clnt;
+
+       err = 0;
+       clnt = fid->clnt;
+
+       P9_DPRINTK(P9_DEBUG_9P, ">>> TSTATFS fid %d\n", fid->fid);
+
+       req = p9_client_rpc(clnt, P9_TSTATFS, "d", fid->fid);
+       if (IS_ERR(req)) {
+               err = PTR_ERR(req);
+               goto error;
+       }
+
+       err = p9pdu_readf(req->rc, clnt->proto_version, "ddqqqqqqd", &sb->type,
+               &sb->bsize, &sb->blocks, &sb->bfree, &sb->bavail,
+               &sb->files, &sb->ffree, &sb->fsid, &sb->namelen);
+       if (err) {
+               p9pdu_dump(1, req->rc);
+               p9_free_req(clnt, req);
+               goto error;
+       }
+
+       P9_DPRINTK(P9_DEBUG_9P, "<<< RSTATFS fid %d type 0x%lx bsize %ld "
+               "blocks %llu bfree %llu bavail %llu files %llu ffree %llu "
+               "fsid %llu namelen %ld\n",
+               fid->fid, (long unsigned int)sb->type, (long int)sb->bsize,
+               sb->blocks, sb->bfree, sb->bavail, sb->files,  sb->ffree,
+               sb->fsid, (long int)sb->namelen);
+
+       p9_free_req(clnt, req);
+error:
+       return err;
+}
+EXPORT_SYMBOL(p9_client_statfs);
+
+int p9_client_rename(struct p9_fid *fid, struct p9_fid *newdirfid, char *name)
+{
+       int err;
+       struct p9_req_t *req;
+       struct p9_client *clnt;
+
+       err = 0;
+       clnt = fid->clnt;
+
+       P9_DPRINTK(P9_DEBUG_9P, ">>> TRENAME fid %d newdirfid %d name %s\n",
+                       fid->fid, newdirfid->fid, name);
+
+       req = p9_client_rpc(clnt, P9_TRENAME, "dds", fid->fid,
+                       newdirfid->fid, name);
+       if (IS_ERR(req)) {
+               err = PTR_ERR(req);
+               goto error;
+       }
+
+       P9_DPRINTK(P9_DEBUG_9P, "<<< RRENAME fid %d\n", fid->fid);
+
+       p9_free_req(clnt, req);
+error:
+       return err;
+}
+EXPORT_SYMBOL(p9_client_rename);
+
+int p9_client_readdir(struct p9_fid *fid, char *data, u32 count, u64 offset)
+{
+       int err, rsize, total;
+       struct p9_client *clnt;
+       struct p9_req_t *req;
+       char *dataptr;
+
+       P9_DPRINTK(P9_DEBUG_9P, ">>> TREADDIR fid %d offset %llu count %d\n",
+                               fid->fid, (long long unsigned) offset, count);
+
+       err = 0;
+       clnt = fid->clnt;
+       total = 0;
+
+       rsize = fid->iounit;
+       if (!rsize || rsize > clnt->msize-P9_READDIRHDRSZ)
+               rsize = clnt->msize - P9_READDIRHDRSZ;
+
+       if (count < rsize)
+               rsize = count;
+
+       req = p9_client_rpc(clnt, P9_TREADDIR, "dqd", fid->fid, offset, rsize);
+       if (IS_ERR(req)) {
+               err = PTR_ERR(req);
+               goto error;
+       }
+
+       err = p9pdu_readf(req->rc, clnt->proto_version, "D", &count, &dataptr);
+       if (err) {
+               p9pdu_dump(1, req->rc);
+               goto free_and_error;
+       }
+
+       P9_DPRINTK(P9_DEBUG_9P, "<<< RREADDIR count %d\n", count);
+
+       if (data)
+               memmove(data, dataptr, count);
+
+       p9_free_req(clnt, req);
+       return count;
+
+free_and_error:
+       p9_free_req(clnt, req);
+error:
+       return err;
+}
+EXPORT_SYMBOL(p9_client_readdir);