[iphonedisk] r100 committed - Add support to the rpc protocol for returning file attributes for a di...

3 views
Skip to first unread message

iphon...@googlecode.com

unread,
Oct 10, 2010, 1:36:44 AM10/10/10
to iphon...@googlegroups.com
Revision: 100
Author: allen.porter
Date: Sat Oct 9 22:35:38 2010
Log: Add support to the rpc protocol for returning file attributes for a
directory
listing.

http://code.google.com/p/iphonedisk/source/detail?r=100

Modified:
/trunk/fs/fs_fuse.cc
/trunk/mobilefs/mobile_fs_service.cc
/trunk/proto/fs.proto

=======================================
--- /trunk/fs/fs_fuse.cc Sun Apr 11 13:35:13 2010
+++ /trunk/fs/fs_fuse.cc Sat Oct 9 22:35:38 2010
@@ -36,6 +36,22 @@
struct Context* context = static_cast<struct Context*>(data);
syslog(LOG_DEBUG, "fs_destroy: %s", context->fs_id.c_str());
}
+
+void fill_stat(const proto::Stat& stat, struct stat* stbuf) {
+ stbuf->st_size = stat.size();
+ stbuf->st_blocks = stat.blocks();
+ stbuf->st_mode = stat.mode();
+ if (stat.has_nlink()) {
+ stbuf->st_nlink = stat.nlink();
+ }
+ if (stat.has_mtime()) {
+ stbuf->st_mtimespec.tv_sec = stat.mtime().tv_sec();
+ stbuf->st_mtimespec.tv_nsec = stat.mtime().tv_nsec();
+ }
+ stbuf->st_uid = getuid();
+ stbuf->st_gid = getgid();
+ stbuf->st_blksize = kBlockSize;
+}

int fs_getattr(const char* path, struct stat* stbuf) {
struct Context* context =
@@ -50,19 +66,7 @@
if (rpc.Failed()) {
return -ENOENT;
}
- stbuf->st_size = response.stat().size();
- stbuf->st_blocks = response.stat().blocks();
- stbuf->st_mode = response.stat().mode();
- if (response.stat().has_nlink()) {
- stbuf->st_nlink = response.stat().nlink();
- }
- if (response.stat().has_mtime()) {
- stbuf->st_mtimespec.tv_sec = response.stat().mtime().tv_sec();
- stbuf->st_mtimespec.tv_nsec = response.stat().mtime().tv_nsec();
- }
- stbuf->st_uid = getuid();
- stbuf->st_gid = getgid();
- stbuf->st_blksize = kBlockSize;
+ fill_stat(response.stat(), stbuf);
return 0;
}

@@ -80,7 +84,16 @@
return -ENOENT;
}
for (int i = 0; i < response.entry_size(); ++i) {
- filler(buf, response.entry(i).filename().c_str(), NULL, 0);
+ const proto::ReadDirResponse::Entry& entry = response.entry(i);
+ struct stat stbuf;
+ struct stat* stbuf_ptr = NULL;
+ if (entry.has_stat()) {
+ fill_stat(entry.stat(), &stbuf);
+ stbuf_ptr = &stbuf;
+ }
+ if (filler(buf, entry.filename().c_str(), stbuf_ptr, 0) != 0) {
+ return -ENOENT;
+ }
}
return 0;
}
=======================================
--- /trunk/mobilefs/mobile_fs_service.cc Sun Apr 11 13:35:13 2010
+++ /trunk/mobilefs/mobile_fs_service.cc Sat Oct 9 22:35:38 2010
@@ -38,7 +38,7 @@
!info_map.count("st_blocks")) {
rpc->SetFailed("AFCFileInfoOpen: Mising keys");
} else {
- proto::GetAttrResponse::Stat* stat = response->mutable_stat();
+ proto::Stat* stat = response->mutable_stat();
stat->set_size(atol(info_map["st_size"].c_str()));
stat->set_blocks(atol(info_map["st_blocks"].c_str()));
if (info_map.count("st_nlink")) {
@@ -258,9 +258,10 @@
info_map.find("Model") == info_map.end()) {
rpc->SetFailed("AFCDeviceInfoOpen: Mising keys");
} else {
- proto::StatFsResponse::Stat* stat = response->mutable_stat();
+ proto::StatFsResponse::StatFs* stat = response->mutable_stat();
int block_size = atoi(info_map["FSBlockSize"].c_str());
- unsigned long long total_bytes =
atoll(info_map["FSTotalBytes"].c_str());
+ unsigned long long total_bytes =
+ atoll(info_map["FSTotalBytes"].c_str());
unsigned long long free_bytes =
atoll(info_map["FSFreeBytes"].c_str());
stat->set_bsize(block_size);
stat->set_frsize(block_size);
=======================================
--- /trunk/proto/fs.proto Sat Oct 9 21:42:10 2010
+++ /trunk/proto/fs.proto Sat Oct 9 22:35:38 2010
@@ -5,6 +5,18 @@
message Header {
required string fs_id = 1;
}
+
+message Stat {
+ required int64 size = 1;
+ required int64 blocks = 2;
+ required int32 mode = 3;
+ optional int32 nlink = 4;
+ message Time {
+ required int32 tv_sec = 1;
+ required int32 tv_nsec = 2;
+ }
+ optional Time mtime = 5;
+}

message GetAttrRequest {
required Header header = 1;
@@ -12,17 +24,6 @@
}

message GetAttrResponse {
- message Stat {
- required int64 size = 1;
- required int64 blocks = 2;
- required int32 mode = 3;
- optional int32 nlink = 4;
- message Time {
- required int32 tv_sec = 1;
- required int32 tv_nsec = 2;
- }
- optional Time mtime = 5;
- }
optional Stat stat = 1;
}

@@ -34,6 +35,7 @@
message ReadDirResponse {
message Entry {
required string filename = 1;
+ optional Stat stat = 2;
}
repeated Entry entry = 1;
}
@@ -129,11 +131,11 @@
}

message StatFsResponse {
- message Stat {
+ message StatFs {
required int64 bsize = 1;
required int64 frsize = 2;
required int64 blocks = 3;
required int64 bfree = 4;
}
- optional Stat stat = 1;
-}
+ optional StatFs stat = 1;
+}

Reply all
Reply to author
Forward
0 new messages