michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_system_openfilefinder_h__ michael@0: #define mozilla_system_openfilefinder_h__ michael@0: michael@0: #include "nsString.h" michael@0: michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace system { michael@0: michael@0: class OpenFileFinder michael@0: { michael@0: public: michael@0: enum State michael@0: { michael@0: NEXT_PID, michael@0: CHECK_FDS, michael@0: DONE michael@0: }; michael@0: class Info michael@0: { michael@0: public: michael@0: nsCString mFileName; // name of the the open file michael@0: nsCString mAppName; // App which has the file open (if it's a b2g app) michael@0: pid_t mPid; // pid of the process which has the file open michael@0: nsCString mComm; // comm associated with pid michael@0: nsCString mExe; // executable name associated with pid michael@0: bool mIsB2gOrDescendant; // this is b2g/its descendant or not michael@0: }; michael@0: michael@0: OpenFileFinder(const nsACString& aPath, bool aCheckIsB2gOrDescendant = true); michael@0: ~OpenFileFinder(); michael@0: michael@0: bool First(Info* aInfo); // Return the first open file michael@0: bool Next(Info* aInfo); // Return the next open file michael@0: void Close(); michael@0: michael@0: private: michael@0: michael@0: void FillInfo(Info *aInfo, const nsACString& aPath); michael@0: bool ReadSymLink(const nsACString& aSymLink, nsACString& aOutPath); michael@0: bool PathMatches(const nsACString& aPath) michael@0: { michael@0: return Substring(aPath, 0, mPath.Length()).Equals(mPath); michael@0: } michael@0: michael@0: State mState; // Keeps track of what we're doing. michael@0: nsCString mPath; // Only report files contained within this directory tree michael@0: DIR* mProcDir; // Used for scanning /proc michael@0: DIR* mFdDir; // Used for scanning /proc/PID/fd michael@0: int mPid; // PID currently being processed michael@0: pid_t mMyPid; // PID of parent process, we assume we're running on it. michael@0: bool mCheckIsB2gOrDescendant; // Do we care about non-b2g process? michael@0: }; michael@0: michael@0: } // system michael@0: } // mozilla michael@0: michael@0: #endif // mozilla_system_nsvolume_h__