Attachment 'lfc-se-user.cc'
Download 1 #include <sys/types.h>
2 #include <iostream>
3 #include <iomanip>
4 #include <cstring>
5 #include <map>
6
7 #include "lfc_api.h"
8 #include "serrno.h"
9
10 int main(int argc, char *argv[])
11 {
12 const char *self = argv[0];
13 char *sename = 0;
14 uid_t uid = 0;
15 std::map<uid_t, int> userfiles;
16
17 switch (argc) {
18 case 3:
19 uid = strtol(argv[2], 0, 0);
20 /* no break */
21 case 2:
22 sename = argv[1];
23 break;
24 default:
25 std::cerr << "Usage: " << self << " SENAME [UID]" << std::endl;
26 return 1;
27 }
28
29 std::cerr << "Counting files on " << sename;
30 if (uid) std::cerr << " belonging to " << uid;
31 std::cerr << " ..." << std::endl;
32
33 int nfiles = 0;
34 lfc_list list;
35 int flags = CNS_LIST_BEGIN;
36 struct lfc_filereplica *replica;
37 struct lfc_filestatg statbuf;
38
39 if (lfc_startsess(getenv("LFC_HOST"), "Looking up files on a Storage Element")) {
40 std::cerr << self << ": " << sstrerror(serrno) << std::endl;
41 return 1;
42 }
43
44 while ((replica = lfc_listreplicax(0, sename, 0, flags, &list))) {
45 flags = CNS_LIST_CONTINUE;
46
47 if (lfc_statr(replica->sfn, &statbuf)) {
48 std::cerr << self << ": " << sstrerror(serrno) << std::endl;
49 continue;
50 }
51 if (uid) {
52 if (statbuf.uid == uid) {
53 std::cout << replica->sfn << std::endl;
54 ++nfiles;
55 }
56 } else {
57 ++userfiles[statbuf.uid];
58 }
59 }
60 if (serrno) std::cerr << self << ": " << sstrerror(serrno) << std::endl;
61 lfc_listreplicax(0, sename, 0, CNS_LIST_END, &list);
62
63 lfc_endsess();
64
65 if (uid) {
66 std::cerr << "Found " << nfiles << " file";
67 if (nfiles != 1) std::cerr << "s";
68 std::cerr << std::endl;
69 } else {
70 for (std::map<uid_t, int>::iterator user = userfiles.begin(); user != userfiles.end(); ++user) {
71 char username[256];
72 if (lfc_getusrbyuid(user->first, username)) {
73 std::cerr << self << ": " << sstrerror(serrno) << std::endl;
74 std::strcpy(username, "unknown");
75 }
76 std::cout << std::setw(6) << user->second << " files of " << std::setw(6) << user->first << " (" << username << ")" << std::endl;
77 }
78 }
79 }
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.