|
1 // fuser.cpp |
|
2 // |
|
3 // Copyright (c) 2005 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include "fuser.h" |
|
14 #include <f32file.h> |
|
15 |
|
16 |
|
17 CCommandBase* CCmdFileUser::NewLC() |
|
18 { |
|
19 CCmdFileUser* self = new(ELeave) CCmdFileUser(); |
|
20 CleanupStack::PushL(self); |
|
21 self->BaseConstructL(); |
|
22 return self; |
|
23 } |
|
24 |
|
25 CCmdFileUser::~CCmdFileUser() |
|
26 { |
|
27 iFiles.Close(); |
|
28 } |
|
29 |
|
30 CCmdFileUser::CCmdFileUser() |
|
31 { |
|
32 } |
|
33 |
|
34 const TDesC& CCmdFileUser::Name() const |
|
35 { |
|
36 _LIT(KName, "fuser"); |
|
37 return KName; |
|
38 } |
|
39 |
|
40 void CCmdFileUser::DoRunL() |
|
41 { |
|
42 const TInt numFiles = iFiles.Count(); |
|
43 if (numFiles == 0) |
|
44 { |
|
45 PrintAllUsersL(); |
|
46 } |
|
47 else |
|
48 { |
|
49 for (TInt i = 0; i < numFiles; ++i) |
|
50 { |
|
51 PrintUsersL(iFiles[i]); |
|
52 } |
|
53 } |
|
54 } |
|
55 |
|
56 void CCmdFileUser::PrintAllUsersL() |
|
57 { |
|
58 TOpenFileScan openFileScanner(FsL()); |
|
59 CFileList* fileList = NULL; |
|
60 FOREVER |
|
61 { |
|
62 openFileScanner.NextL(fileList); |
|
63 if (fileList == NULL) |
|
64 { |
|
65 break; |
|
66 } |
|
67 CleanupStack::PushL(fileList); |
|
68 const TInt numOpenFiles = fileList->Count(); |
|
69 for (TInt i = 0; i < numOpenFiles; ++i) |
|
70 { |
|
71 const TEntry& entry = (*fileList)[i]; |
|
72 Printf(_L("%S: \r\n"), &entry.iName); |
|
73 TThreadId threadId(openFileScanner.ThreadId()); |
|
74 RThread thread; |
|
75 TInt err = thread.Open(threadId); |
|
76 if (err) |
|
77 { |
|
78 Printf(_L("\tError %d opening thread id %u\r\n"), err, (TUint)threadId); |
|
79 } |
|
80 else |
|
81 { |
|
82 TFullName name(thread.FullName()); |
|
83 thread.Close(); |
|
84 Printf(_L("\t%S (%u)\r\n"), &name, (TUint)threadId); |
|
85 } |
|
86 } |
|
87 CleanupStack::PopAndDestroy(fileList); |
|
88 } |
|
89 } |
|
90 |
|
91 void CCmdFileUser::PrintUsersL(const TDesC& aFileName) |
|
92 { |
|
93 Printf(_L("%S: \r\n"), &aFileName); |
|
94 TOpenFileScan openFileScanner(FsL()); |
|
95 CFileList* fileList = NULL; |
|
96 TBool userFound(EFalse); |
|
97 FOREVER |
|
98 { |
|
99 openFileScanner.NextL(fileList); |
|
100 if (fileList == NULL) |
|
101 { |
|
102 break; |
|
103 } |
|
104 CleanupStack::PushL(fileList); |
|
105 const TInt numOpenFiles = fileList->Count(); |
|
106 for (TInt i = 0; i < numOpenFiles; ++i) |
|
107 { |
|
108 const TEntry& entry = (*fileList)[i]; |
|
109 if (entry.iName.MatchF(aFileName.Mid(2)) != KErrNotFound) // Note entry.iName doesn't have a drive letter, hence the Mid(2). |
|
110 { |
|
111 userFound = ETrue; |
|
112 TThreadId threadId(openFileScanner.ThreadId()); |
|
113 RThread thread; |
|
114 TInt err = thread.Open(threadId); |
|
115 if (err) |
|
116 { |
|
117 Printf(_L("\tError %d opening thread id %u\r\n"), err, (TUint)threadId); |
|
118 } |
|
119 else |
|
120 { |
|
121 TFullName name(thread.FullName()); |
|
122 thread.Close(); |
|
123 Printf(_L("\t%S (%u)\r\n"), &name, (TUint)threadId); |
|
124 } |
|
125 break; |
|
126 } |
|
127 } |
|
128 CleanupStack::PopAndDestroy(fileList); |
|
129 } |
|
130 |
|
131 if (!userFound) |
|
132 { |
|
133 Write(_L("\tNo users")); |
|
134 } |
|
135 } |
|
136 |
|
137 void CCmdFileUser::ArgumentsL(RCommandArgumentList& aArguments) |
|
138 { |
|
139 _LIT(KArgFiles, "file_name"); |
|
140 aArguments.AppendFileNameL(iFiles, KArgFiles); |
|
141 } |
|
142 |
|
143 |
|
144 #ifdef EXE_BUILD |
|
145 EXE_BOILER_PLATE(CCmdFileUser) |
|
146 #endif |