1*5a1d355fSStephan Aßmus // Permissions.h 2*5a1d355fSStephan Aßmus 3*5a1d355fSStephan Aßmus #ifndef NET_FS_PERMISSIONS_H 4*5a1d355fSStephan Aßmus #define NET_FS_PERMISSIONS_H 5*5a1d355fSStephan Aßmus 6*5a1d355fSStephan Aßmus #include <SupportDefs.h> 7*5a1d355fSStephan Aßmus 8*5a1d355fSStephan Aßmus enum { 9*5a1d355fSStephan Aßmus // file permissions 10*5a1d355fSStephan Aßmus READ_PERMISSION = 0x01, 11*5a1d355fSStephan Aßmus WRITE_PERMISSION = 0x02, 12*5a1d355fSStephan Aßmus 13*5a1d355fSStephan Aßmus // directory permissions 14*5a1d355fSStephan Aßmus READ_DIR_PERMISSION = 0x04, 15*5a1d355fSStephan Aßmus WRITE_DIR_PERMISSION = 0x08, 16*5a1d355fSStephan Aßmus RESOLVE_DIR_ENTRY_PERMISSION = 0x10, 17*5a1d355fSStephan Aßmus 18*5a1d355fSStephan Aßmus // share permissions 19*5a1d355fSStephan Aßmus MOUNT_SHARE_PERMISSION = 0x20, 20*5a1d355fSStephan Aßmus QUERY_SHARE_PERMISSION = 0x40, 21*5a1d355fSStephan Aßmus 22*5a1d355fSStephan Aßmus // all permissions 23*5a1d355fSStephan Aßmus ALL_PERMISSIONS = 0x7f, 24*5a1d355fSStephan Aßmus }; 25*5a1d355fSStephan Aßmus 26*5a1d355fSStephan Aßmus class Permissions { 27*5a1d355fSStephan Aßmus public: 28*5a1d355fSStephan Aßmus inline Permissions(); 29*5a1d355fSStephan Aßmus inline Permissions(uint32 permissions); 30*5a1d355fSStephan Aßmus inline Permissions(const Permissions& other); 31*5a1d355fSStephan Aßmus 32*5a1d355fSStephan Aßmus inline uint32 GetPermissions() const; 33*5a1d355fSStephan Aßmus 34*5a1d355fSStephan Aßmus inline Permissions& AddPermissions(uint32 permissions); 35*5a1d355fSStephan Aßmus inline Permissions& AddPermissions(Permissions permissions); 36*5a1d355fSStephan Aßmus 37*5a1d355fSStephan Aßmus inline bool Implies(uint32 permissions) const; 38*5a1d355fSStephan Aßmus 39*5a1d355fSStephan Aßmus inline bool ImpliesReadPermission() const; 40*5a1d355fSStephan Aßmus inline bool ImpliesWritePermission() const; 41*5a1d355fSStephan Aßmus inline bool ImpliesReadDirPermission() const; 42*5a1d355fSStephan Aßmus inline bool ImpliesWriteDirPermission() const; 43*5a1d355fSStephan Aßmus inline bool ImpliesResolveDirEntryPermission() const; 44*5a1d355fSStephan Aßmus inline bool ImpliesMountSharePermission() const; 45*5a1d355fSStephan Aßmus inline bool ImpliesQuerySharePermission() const; 46*5a1d355fSStephan Aßmus 47*5a1d355fSStephan Aßmus inline Permissions& operator=(const Permissions& other); 48*5a1d355fSStephan Aßmus inline bool operator==(const Permissions& other) const; 49*5a1d355fSStephan Aßmus inline bool operator!=(const Permissions& other) const; 50*5a1d355fSStephan Aßmus 51*5a1d355fSStephan Aßmus private: 52*5a1d355fSStephan Aßmus uint32 fPermissions; 53*5a1d355fSStephan Aßmus }; 54*5a1d355fSStephan Aßmus 55*5a1d355fSStephan Aßmus // inline implementation 56*5a1d355fSStephan Aßmus 57*5a1d355fSStephan Aßmus // constructor 58*5a1d355fSStephan Aßmus inline Permissions()59*5a1d355fSStephan AßmusPermissions::Permissions() 60*5a1d355fSStephan Aßmus : fPermissions(0) 61*5a1d355fSStephan Aßmus { 62*5a1d355fSStephan Aßmus } 63*5a1d355fSStephan Aßmus 64*5a1d355fSStephan Aßmus // constructor 65*5a1d355fSStephan Aßmus inline Permissions(uint32 permissions)66*5a1d355fSStephan AßmusPermissions::Permissions(uint32 permissions) 67*5a1d355fSStephan Aßmus : fPermissions(permissions) 68*5a1d355fSStephan Aßmus { 69*5a1d355fSStephan Aßmus } 70*5a1d355fSStephan Aßmus 71*5a1d355fSStephan Aßmus // copy constructor 72*5a1d355fSStephan Aßmus inline Permissions(const Permissions & other)73*5a1d355fSStephan AßmusPermissions::Permissions(const Permissions& other) 74*5a1d355fSStephan Aßmus : fPermissions(other.fPermissions) 75*5a1d355fSStephan Aßmus { 76*5a1d355fSStephan Aßmus } 77*5a1d355fSStephan Aßmus 78*5a1d355fSStephan Aßmus // GetPermissions 79*5a1d355fSStephan Aßmus inline 80*5a1d355fSStephan Aßmus uint32 GetPermissions()81*5a1d355fSStephan AßmusPermissions::GetPermissions() const 82*5a1d355fSStephan Aßmus { 83*5a1d355fSStephan Aßmus return fPermissions; 84*5a1d355fSStephan Aßmus } 85*5a1d355fSStephan Aßmus 86*5a1d355fSStephan Aßmus // AddPermissions 87*5a1d355fSStephan Aßmus inline 88*5a1d355fSStephan Aßmus Permissions& AddPermissions(uint32 permissions)89*5a1d355fSStephan AßmusPermissions::AddPermissions(uint32 permissions) 90*5a1d355fSStephan Aßmus { 91*5a1d355fSStephan Aßmus fPermissions |= permissions; 92*5a1d355fSStephan Aßmus return *this; 93*5a1d355fSStephan Aßmus } 94*5a1d355fSStephan Aßmus 95*5a1d355fSStephan Aßmus // AddPermissions 96*5a1d355fSStephan Aßmus inline 97*5a1d355fSStephan Aßmus Permissions& AddPermissions(Permissions permissions)98*5a1d355fSStephan AßmusPermissions::AddPermissions(Permissions permissions) 99*5a1d355fSStephan Aßmus { 100*5a1d355fSStephan Aßmus fPermissions |= permissions.fPermissions; 101*5a1d355fSStephan Aßmus return *this; 102*5a1d355fSStephan Aßmus } 103*5a1d355fSStephan Aßmus 104*5a1d355fSStephan Aßmus // Implies 105*5a1d355fSStephan Aßmus inline 106*5a1d355fSStephan Aßmus bool Implies(uint32 permissions)107*5a1d355fSStephan AßmusPermissions::Implies(uint32 permissions) const 108*5a1d355fSStephan Aßmus { 109*5a1d355fSStephan Aßmus return ((fPermissions & permissions) == permissions); 110*5a1d355fSStephan Aßmus } 111*5a1d355fSStephan Aßmus 112*5a1d355fSStephan Aßmus // ImpliesReadPermission 113*5a1d355fSStephan Aßmus inline 114*5a1d355fSStephan Aßmus bool ImpliesReadPermission()115*5a1d355fSStephan AßmusPermissions::ImpliesReadPermission() const 116*5a1d355fSStephan Aßmus { 117*5a1d355fSStephan Aßmus return Implies(READ_PERMISSION); 118*5a1d355fSStephan Aßmus } 119*5a1d355fSStephan Aßmus 120*5a1d355fSStephan Aßmus // ImpliesWritePermission 121*5a1d355fSStephan Aßmus inline 122*5a1d355fSStephan Aßmus bool ImpliesWritePermission()123*5a1d355fSStephan AßmusPermissions::ImpliesWritePermission() const 124*5a1d355fSStephan Aßmus { 125*5a1d355fSStephan Aßmus return Implies(WRITE_PERMISSION); 126*5a1d355fSStephan Aßmus } 127*5a1d355fSStephan Aßmus 128*5a1d355fSStephan Aßmus // ImpliesReadDirPermission 129*5a1d355fSStephan Aßmus inline 130*5a1d355fSStephan Aßmus bool ImpliesReadDirPermission()131*5a1d355fSStephan AßmusPermissions::ImpliesReadDirPermission() const 132*5a1d355fSStephan Aßmus { 133*5a1d355fSStephan Aßmus return Implies(READ_DIR_PERMISSION); 134*5a1d355fSStephan Aßmus } 135*5a1d355fSStephan Aßmus 136*5a1d355fSStephan Aßmus // ImpliesWriteDirPermission 137*5a1d355fSStephan Aßmus inline 138*5a1d355fSStephan Aßmus bool ImpliesWriteDirPermission()139*5a1d355fSStephan AßmusPermissions::ImpliesWriteDirPermission() const 140*5a1d355fSStephan Aßmus { 141*5a1d355fSStephan Aßmus return Implies(WRITE_DIR_PERMISSION); 142*5a1d355fSStephan Aßmus } 143*5a1d355fSStephan Aßmus 144*5a1d355fSStephan Aßmus // ImpliesResolveDirEntryPermission 145*5a1d355fSStephan Aßmus inline 146*5a1d355fSStephan Aßmus bool ImpliesResolveDirEntryPermission()147*5a1d355fSStephan AßmusPermissions::ImpliesResolveDirEntryPermission() const 148*5a1d355fSStephan Aßmus { 149*5a1d355fSStephan Aßmus return Implies(RESOLVE_DIR_ENTRY_PERMISSION); 150*5a1d355fSStephan Aßmus } 151*5a1d355fSStephan Aßmus 152*5a1d355fSStephan Aßmus // ImpliesMountSharePermission 153*5a1d355fSStephan Aßmus inline 154*5a1d355fSStephan Aßmus bool ImpliesMountSharePermission()155*5a1d355fSStephan AßmusPermissions::ImpliesMountSharePermission() const 156*5a1d355fSStephan Aßmus { 157*5a1d355fSStephan Aßmus return Implies(MOUNT_SHARE_PERMISSION); 158*5a1d355fSStephan Aßmus } 159*5a1d355fSStephan Aßmus 160*5a1d355fSStephan Aßmus // ImpliesQuerySharePermission 161*5a1d355fSStephan Aßmus inline 162*5a1d355fSStephan Aßmus bool ImpliesQuerySharePermission()163*5a1d355fSStephan AßmusPermissions::ImpliesQuerySharePermission() const 164*5a1d355fSStephan Aßmus { 165*5a1d355fSStephan Aßmus return Implies(QUERY_SHARE_PERMISSION); 166*5a1d355fSStephan Aßmus } 167*5a1d355fSStephan Aßmus 168*5a1d355fSStephan Aßmus // = 169*5a1d355fSStephan Aßmus inline 170*5a1d355fSStephan Aßmus Permissions& 171*5a1d355fSStephan Aßmus Permissions::operator=(const Permissions& other) 172*5a1d355fSStephan Aßmus { 173*5a1d355fSStephan Aßmus fPermissions = other.fPermissions; 174*5a1d355fSStephan Aßmus return *this; 175*5a1d355fSStephan Aßmus } 176*5a1d355fSStephan Aßmus 177*5a1d355fSStephan Aßmus // == 178*5a1d355fSStephan Aßmus inline 179*5a1d355fSStephan Aßmus bool 180*5a1d355fSStephan Aßmus Permissions::operator==(const Permissions& other) const 181*5a1d355fSStephan Aßmus { 182*5a1d355fSStephan Aßmus return (fPermissions == other.fPermissions); 183*5a1d355fSStephan Aßmus } 184*5a1d355fSStephan Aßmus 185*5a1d355fSStephan Aßmus // != 186*5a1d355fSStephan Aßmus inline 187*5a1d355fSStephan Aßmus bool 188*5a1d355fSStephan Aßmus Permissions::operator!=(const Permissions& other) const 189*5a1d355fSStephan Aßmus { 190*5a1d355fSStephan Aßmus return (fPermissions != other.fPermissions); 191*5a1d355fSStephan Aßmus } 192*5a1d355fSStephan Aßmus 193*5a1d355fSStephan Aßmus #endif // NET_FS_PERMISSIONS_H 194