xpcom/io/nsLocalFileUnix.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /*
     7  * Implementation of nsIFile for ``Unixy'' systems.
     8  */
    10 #ifndef _nsLocalFileUNIX_H_
    11 #define _nsLocalFileUNIX_H_
    13 #include <sys/stat.h>
    14 #include <sys/types.h>
    15 #include <unistd.h>
    17 #include "nscore.h"
    18 #include "nsString.h"
    19 #include "nsReadableUtils.h"
    20 #include "nsIHashable.h"
    21 #include "nsIClassInfoImpl.h"
    22 #include "mozilla/Attributes.h"
    23 #ifdef MOZ_WIDGET_COCOA
    24 #include "nsILocalFileMac.h"
    25 #endif
    27 /** 
    28  *  we need these for statfs()
    29  */
    30 #ifdef HAVE_SYS_STATVFS_H
    31     #if defined(__osf__) && defined(__DECCXX)
    32         extern "C" int statvfs(const char *, struct statvfs *);
    33     #endif
    34     #include <sys/statvfs.h>
    35 #endif
    37 #ifdef HAVE_SYS_STATFS_H
    38     #include <sys/statfs.h>
    39 #endif
    41 #ifdef HAVE_SYS_VFS_H
    42     #include <sys/vfs.h>
    43 #endif
    45 #ifdef HAVE_SYS_MOUNT_H
    46     #include <sys/param.h>
    47     #include <sys/mount.h>
    48 #endif
    50 #if defined(HAVE_STATVFS64) && (!defined(LINUX) && !defined(__osf__))
    51     #define STATFS statvfs64
    52     #define F_BSIZE f_frsize
    53 #elif defined(HAVE_STATVFS) && (!defined(LINUX) && !defined(__osf__))
    54     #define STATFS statvfs
    55     #define F_BSIZE f_frsize
    56 #elif defined(HAVE_STATFS64)
    57     #define STATFS statfs64
    58     #define F_BSIZE f_bsize
    59 #elif defined(HAVE_STATFS)
    60     #define STATFS statfs
    61     #define F_BSIZE f_bsize
    62 #endif
    64 // stat64 and lstat64 are deprecated on OS X. Normal stat and lstat are
    65 // 64-bit by default on OS X 10.6+.
    66 #if defined(HAVE_STAT64) && defined(HAVE_LSTAT64) && !defined(XP_MACOSX)
    67     #if defined (AIX)
    68         #if defined STAT
    69             #undef STAT
    70         #endif
    71     #endif
    72     #define STAT stat64
    73     #define LSTAT lstat64
    74     #define HAVE_STATS64 1
    75 #else
    76     #define STAT stat
    77     #define LSTAT lstat
    78 #endif
    81 class nsLocalFile MOZ_FINAL :
    82 #ifdef MOZ_WIDGET_COCOA
    83                            public nsILocalFileMac,
    84 #else
    85                            public nsILocalFile,
    86 #endif
    87                            public nsIHashable
    88 {
    89 public:
    90     NS_DEFINE_STATIC_CID_ACCESSOR(NS_LOCAL_FILE_CID)
    92     nsLocalFile();
    94     static nsresult nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
    96     NS_DECL_THREADSAFE_ISUPPORTS
    97     NS_DECL_NSIFILE
    98     NS_DECL_NSILOCALFILE
    99 #ifdef MOZ_WIDGET_COCOA
   100     NS_DECL_NSILOCALFILEMAC
   101 #endif
   102     NS_DECL_NSIHASHABLE
   104 public:
   105     static void GlobalInit();
   106     static void GlobalShutdown();
   108 private:
   109     nsLocalFile(const nsLocalFile& other);
   110     ~nsLocalFile() {}
   112 protected:
   113     // This stat cache holds the *last stat* - it does not invalidate.
   114     // Call "FillStatCache" whenever you want to stat our file.
   115     struct STAT  mCachedStat;
   116     nsCString    mPath;
   118     void LocateNativeLeafName(nsACString::const_iterator &,
   119                               nsACString::const_iterator &);
   121     nsresult CopyDirectoryTo(nsIFile *newParent);
   122     nsresult CreateAllAncestors(uint32_t permissions);
   123     nsresult GetNativeTargetPathName(nsIFile *newParent,
   124                                      const nsACString &newName,
   125                                      nsACString &_retval);
   127     bool FillStatCache();
   129     nsresult CreateAndKeepOpen(uint32_t type, int flags,
   130                                uint32_t permissions, PRFileDesc **_retval);
   131 };
   133 #endif /* _nsLocalFileUNIX_H_ */

mercurial