|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef mozilla_system_openfilefinder_h__ |
|
6 #define mozilla_system_openfilefinder_h__ |
|
7 |
|
8 #include "nsString.h" |
|
9 |
|
10 #include <dirent.h> |
|
11 |
|
12 namespace mozilla { |
|
13 namespace system { |
|
14 |
|
15 class OpenFileFinder |
|
16 { |
|
17 public: |
|
18 enum State |
|
19 { |
|
20 NEXT_PID, |
|
21 CHECK_FDS, |
|
22 DONE |
|
23 }; |
|
24 class Info |
|
25 { |
|
26 public: |
|
27 nsCString mFileName; // name of the the open file |
|
28 nsCString mAppName; // App which has the file open (if it's a b2g app) |
|
29 pid_t mPid; // pid of the process which has the file open |
|
30 nsCString mComm; // comm associated with pid |
|
31 nsCString mExe; // executable name associated with pid |
|
32 bool mIsB2gOrDescendant; // this is b2g/its descendant or not |
|
33 }; |
|
34 |
|
35 OpenFileFinder(const nsACString& aPath, bool aCheckIsB2gOrDescendant = true); |
|
36 ~OpenFileFinder(); |
|
37 |
|
38 bool First(Info* aInfo); // Return the first open file |
|
39 bool Next(Info* aInfo); // Return the next open file |
|
40 void Close(); |
|
41 |
|
42 private: |
|
43 |
|
44 void FillInfo(Info *aInfo, const nsACString& aPath); |
|
45 bool ReadSymLink(const nsACString& aSymLink, nsACString& aOutPath); |
|
46 bool PathMatches(const nsACString& aPath) |
|
47 { |
|
48 return Substring(aPath, 0, mPath.Length()).Equals(mPath); |
|
49 } |
|
50 |
|
51 State mState; // Keeps track of what we're doing. |
|
52 nsCString mPath; // Only report files contained within this directory tree |
|
53 DIR* mProcDir; // Used for scanning /proc |
|
54 DIR* mFdDir; // Used for scanning /proc/PID/fd |
|
55 int mPid; // PID currently being processed |
|
56 pid_t mMyPid; // PID of parent process, we assume we're running on it. |
|
57 bool mCheckIsB2gOrDescendant; // Do we care about non-b2g process? |
|
58 }; |
|
59 |
|
60 } // system |
|
61 } // mozilla |
|
62 |
|
63 #endif // mozilla_system_nsvolume_h__ |