[Ocfs2-tools-devel] [PATCH 13/19] Ocfs2-tools: Add running codes for '--file-statistics' in operation.c
Tristan Ye
tristan.ye at oracle.com
Tue Apr 13 19:50:13 PDT 2010
Task of file statistics will be partly implemented by fiemap, and partly
from standard stat().
Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
o2info/operations.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 109 insertions(+), 0 deletions(-)
diff --git a/o2info/operations.c b/o2info/operations.c
index c4fa7fc..21504d6 100644
--- a/o2info/operations.c
+++ b/o2info/operations.c
@@ -553,3 +553,112 @@ static int usage_run(struct o2info_operation *op,
DEFINE_O2INFO_OP(usage,
usage_run,
NULL);
+
+static int filestat_run(struct o2info_operation *op,
+ struct o2info_method *om,
+ void *arg)
+{
+ int rc = 0;
+ uint16_t perm;
+ struct stat st;
+
+ char *path = NULL;
+ char *filetype = NULL, *h_perm = NULL;
+ char *uname = NULL, *gname = NULL;
+ char *ah_time = NULL, *ch_time = NULL, *mh_time = NULL;
+
+ static struct o2info_fiemap_stats ofs;
+
+ rc = lstat(om->om_path, &st);
+ if (rc < 0) {
+ rc = errno;
+ o2i_error(op, "stat error: %s\n", strerror(rc));
+ goto out;
+ }
+
+ rc = o2info_get_human_path(st.st_mode, om->om_path, &path);
+ if (rc)
+ goto out;
+
+ rc = o2info_get_filetype(st, &filetype);
+ if (rc)
+ goto out;
+
+ rc = o2info_uid2name(st.st_uid, &uname);
+ if (rc)
+ goto out;
+
+ rc = o2info_gid2name(st.st_gid, &gname);
+ if (rc)
+ goto out;
+
+ rc = o2info_get_human_permission(st.st_mode, &perm, &h_perm);
+ if (rc)
+ goto out;
+
+ rc = get_fiemap_stats(op, om, &ofs);
+ if (rc)
+ goto out;
+
+ if (!ofs.blocksize)
+ ofs.blocksize = st.st_blksize;
+
+ fprintf(stdout, " File: %s\n", path);
+ fprintf(stdout, " Size: %-10lu\tBlocks: %-10u IO Block: %-6u %s\n",
+ st.st_size, st.st_blocks, ofs.blocksize, filetype);
+ if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))
+ fprintf(stdout, "Device: %xh/%dd\tInode: %-10i Links: %-5u"
+ " Device type: %u,%u\n", st.st_dev, st.st_dev,
+ st.st_ino, st.st_nlink,
+ st.st_dev >> 16UL, st.st_dev & 0x0000FFFF);
+ else
+ fprintf(stdout, "Device: %xh/%dd\tInode: %-10i Links: %u\n",
+ st.st_dev, st.st_dev, st.st_ino, st.st_nlink);
+ fprintf(stdout, " Frag%: %-10.2f\tClusters: %-8u Extents: "
+ "%-6lu Score: %.0f\n", ofs.frag, ofs.clusters,
+ ofs.num_extents, ofs.score);
+ fprintf(stdout, "Shared: %-10u\tUnwritten: %-7u Holes: %-8u "
+ "Xattr: %u\n", ofs.shared, ofs.unwrittens,
+ ofs.holes, ofs.xattr);
+ fprintf(stdout, "Access: (%04o/%10s) Uid: (%5u/%8s) "
+ "Gid: (%5u/%8s)\n", perm, h_perm, st.st_uid,
+ uname, st.st_gid, gname);
+
+ rc = o2info_get_human_time(&ah_time, o2info_get_stat_atime(&st));
+ if (rc)
+ goto out;
+ rc = o2info_get_human_time(&mh_time, o2info_get_stat_mtime(&st));
+ if (rc)
+ goto out;
+ rc = o2info_get_human_time(&ch_time, o2info_get_stat_ctime(&st));
+ if (rc)
+ goto out;
+
+ fprintf(stdout, "Access: %s\n", ah_time);
+ fprintf(stdout, "Modify: %s\n", mh_time);
+ fprintf(stdout, "Change: %s\n", ch_time);
+
+out:
+ if (path)
+ ocfs2_free(&path);
+ if (filetype)
+ ocfs2_free(&filetype);
+ if (uname)
+ ocfs2_free(&uname);
+ if (gname)
+ ocfs2_free(&gname);
+ if (h_perm)
+ ocfs2_free(&h_perm);
+ if (ah_time)
+ ocfs2_free(&ah_time);
+ if (mh_time)
+ ocfs2_free(&mh_time);
+ if (ch_time)
+ ocfs2_free(&ch_time);
+
+ return rc;
+}
+
+DEFINE_O2INFO_OP(filestat,
+ filestat_run,
+ NULL);
--
1.5.5
More information about the Ocfs2-tools-devel
mailing list