1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/system/gonk/OpenFileFinder.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,63 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef mozilla_system_openfilefinder_h__ 1.9 +#define mozilla_system_openfilefinder_h__ 1.10 + 1.11 +#include "nsString.h" 1.12 + 1.13 +#include <dirent.h> 1.14 + 1.15 +namespace mozilla { 1.16 +namespace system { 1.17 + 1.18 +class OpenFileFinder 1.19 +{ 1.20 +public: 1.21 + enum State 1.22 + { 1.23 + NEXT_PID, 1.24 + CHECK_FDS, 1.25 + DONE 1.26 + }; 1.27 + class Info 1.28 + { 1.29 + public: 1.30 + nsCString mFileName; // name of the the open file 1.31 + nsCString mAppName; // App which has the file open (if it's a b2g app) 1.32 + pid_t mPid; // pid of the process which has the file open 1.33 + nsCString mComm; // comm associated with pid 1.34 + nsCString mExe; // executable name associated with pid 1.35 + bool mIsB2gOrDescendant; // this is b2g/its descendant or not 1.36 + }; 1.37 + 1.38 + OpenFileFinder(const nsACString& aPath, bool aCheckIsB2gOrDescendant = true); 1.39 + ~OpenFileFinder(); 1.40 + 1.41 + bool First(Info* aInfo); // Return the first open file 1.42 + bool Next(Info* aInfo); // Return the next open file 1.43 + void Close(); 1.44 + 1.45 +private: 1.46 + 1.47 + void FillInfo(Info *aInfo, const nsACString& aPath); 1.48 + bool ReadSymLink(const nsACString& aSymLink, nsACString& aOutPath); 1.49 + bool PathMatches(const nsACString& aPath) 1.50 + { 1.51 + return Substring(aPath, 0, mPath.Length()).Equals(mPath); 1.52 + } 1.53 + 1.54 + State mState; // Keeps track of what we're doing. 1.55 + nsCString mPath; // Only report files contained within this directory tree 1.56 + DIR* mProcDir; // Used for scanning /proc 1.57 + DIR* mFdDir; // Used for scanning /proc/PID/fd 1.58 + int mPid; // PID currently being processed 1.59 + pid_t mMyPid; // PID of parent process, we assume we're running on it. 1.60 + bool mCheckIsB2gOrDescendant; // Do we care about non-b2g process? 1.61 +}; 1.62 + 1.63 +} // system 1.64 +} // mozilla 1.65 + 1.66 +#endif // mozilla_system_nsvolume_h__