Rudiments
|
00001 // Copyright (c) 2002 David Muse 00002 // See the COPYING file for more information. 00003 00004 #ifndef RUDIMENTS_FILE_H 00005 #define RUDIMENTS_FILE_H 00006 00007 #include <rudiments/private/fileincludes.h> 00008 00009 #ifdef RUDIMENTS_NAMESPACE 00010 namespace rudiments { 00011 #endif 00012 00013 class fileprivate; 00014 00025 class RUDIMENTS_DLLSPEC file : public filedescriptor { 00026 public: 00027 00029 file(); 00030 00033 file(const file &f); 00034 00037 file &operator=(const file &f); 00038 00040 virtual ~file(); 00041 00044 bool open(const char *name, int32_t flags); 00045 00050 bool open(const char *name, int32_t flags, mode_t perms); 00051 00055 bool create(const char *name, mode_t perms); 00056 00061 ssize_t create(const char *name, mode_t perms, uint16_t number); 00062 00067 ssize_t create(const char *name, mode_t perms, 00068 unsigned long number); 00069 00074 ssize_t create(const char *name, mode_t perms, float number); 00075 00080 ssize_t create(const char *name, mode_t perms, double number); 00081 00086 ssize_t create(const char *name, mode_t perms, char number); 00087 00092 ssize_t create(const char *name, mode_t perms, 00093 const char *string); 00094 00100 ssize_t create(const char *name, mode_t perms, 00101 const char *string, size_t size); 00102 00108 ssize_t create(const char *name, mode_t perms, 00109 const void *data, size_t size); 00110 00111 00121 char *getContents(); 00122 00130 ssize_t getContents(unsigned char *buffer, size_t buffersize); 00131 00132 00136 bool truncate() const; 00137 00141 bool truncate(off64_t length) const; 00142 00143 00147 off64_t getCurrentPosition() const; 00148 00152 off64_t setPositionRelativeToBeginning(off64_t offset) const; 00153 00157 off64_t setPositionRelativeToCurrent(off64_t offset) const; 00158 00166 off64_t setPositionRelativeToEnd(off64_t offset) const; 00167 00171 bool tryLockFile(int16_t type) const; 00172 00177 bool lockFile(int16_t type) const; 00178 00193 bool checkLockFile(int16_t type, 00194 int16_t *conftype, 00195 int16_t *confwhence, 00196 off64_t *confstart, 00197 off64_t *conflen) const; 00198 00201 bool unlockFile() const; 00202 00208 bool tryLockRegion(int16_t type, off64_t start, 00209 off64_t len) const; 00210 00216 bool lockRegion(int16_t type, off64_t start, 00217 off64_t len) const; 00218 00234 bool checkLockRegion(int16_t type, 00235 off64_t start, 00236 off64_t len, 00237 int16_t *conftype, 00238 int16_t *confwhence, 00239 off64_t *confstart, 00240 off64_t *conflen) const; 00241 00246 bool unlockRegion(off64_t start, off64_t len) const; 00247 00252 bool tryLockFromCurrent(int16_t type, off64_t len) const; 00253 00259 bool tryLockFromCurrent(int16_t type, off64_t start, 00260 off64_t len) const; 00261 00267 bool lockFromCurrent(int16_t type, off64_t len) const; 00268 00274 bool lockFromCurrent(int16_t type, off64_t start, 00275 off64_t len) const; 00276 00291 bool checkLockFromCurrent(int16_t type, off64_t len, 00292 int16_t *conftype, 00293 int16_t *confwhence, 00294 off64_t *confstart, 00295 off64_t *conflen) const; 00296 00312 bool checkLockFromCurrent(int16_t type, off64_t start, 00313 off64_t len, 00314 int16_t *conftype, 00315 int16_t *confwhence, 00316 off64_t *confstart, 00317 off64_t *conflen) const; 00318 00322 bool unlockFromCurrent(off64_t len) const; 00323 00328 bool unlockFromCurrent(off64_t start, off64_t len) const; 00329 00334 bool tryLockFromEnd(int16_t type, off64_t len) const; 00335 00341 bool tryLockFromEnd(int16_t type, off64_t start, 00342 off64_t len) const; 00343 00349 bool lockFromEnd(int16_t type, off64_t len) const; 00350 00356 bool lockFromEnd(int16_t type, off64_t start, 00357 off64_t len) const; 00358 00373 bool checkLockFromEnd(int16_t type, off64_t len, 00374 int16_t *conftype, 00375 int16_t *confwhence, 00376 off64_t *confstart, 00377 off64_t *conflen) const; 00378 00394 bool checkLockFromEnd(int16_t type, off64_t start, 00395 off64_t len, 00396 int16_t *conftype, 00397 int16_t *confwhence, 00398 off64_t *confstart, 00399 off64_t *conflen) const; 00400 00404 bool unlockFromEnd(off64_t len) const; 00405 00410 bool unlockFromEnd(off64_t start, off64_t len) const; 00411 00417 bool tryLockRemainder(int16_t type, off64_t start) const; 00418 00424 bool lockRemainder(int16_t type, off64_t start) const; 00425 00441 bool checkLockRemainder(int16_t type, off64_t start, 00442 int16_t *conftype, 00443 int16_t *confwhence, 00444 off64_t *confstart, 00445 off64_t *conflen) const; 00446 00451 bool unlockRemainder(off64_t start) const; 00452 00457 bool tryLockRemainderFromCurrent(int16_t type) const; 00458 00463 bool tryLockRemainderFromCurrent(int16_t type, 00464 off64_t start) const; 00465 00470 bool lockRemainderFromCurrent(int16_t type) const; 00471 00477 bool lockRemainderFromCurrent(int16_t type, 00478 off64_t start) const; 00479 00494 bool checkLockRemainderFromCurrent(int16_t type, 00495 int16_t *conftype, 00496 int16_t *confwhence, 00497 off64_t *confstart, 00498 off64_t *conflen) const; 00499 00515 bool checkLockRemainderFromCurrent(int16_t type, 00516 off64_t start, 00517 int16_t *conftype, 00518 int16_t *confwhence, 00519 off64_t *confstart, 00520 off64_t *conflen) const; 00521 00525 bool unlockRemainderFromCurrent() const; 00526 00531 bool unlockRemainderFromCurrent(off64_t start) const; 00532 00537 bool tryLockRemainderFromEnd(int16_t type) const; 00538 00543 bool tryLockRemainderFromEnd(int16_t type, 00544 off64_t start) const; 00545 00550 bool lockRemainderFromEnd(int16_t type) const; 00551 00556 bool lockRemainderFromEnd(int16_t type, off64_t start) const; 00557 00572 bool checkLockRemainderFromEnd(int16_t type, 00573 int16_t *conftype, 00574 int16_t *confwhence, 00575 off64_t *confstart, 00576 off64_t *conflen) const; 00577 00592 bool checkLockRemainderFromEnd(int16_t type, 00593 off64_t start, 00594 int16_t *conftype, 00595 int16_t *confwhence, 00596 off64_t *confstart, 00597 off64_t *conflen) const; 00598 00602 bool unlockRemainderFromEnd() const; 00603 00607 bool unlockRemainderFromEnd(off64_t start) const; 00608 00609 00619 bool sequentialAccess(off64_t start, size_t len) const; 00620 00630 bool randomAccess(off64_t start, size_t len) const; 00631 00641 bool onlyOnce(off64_t start, size_t len) const; 00642 00652 bool willNeed(off64_t start, size_t len) const; 00653 00663 bool wontNeed(off64_t start, size_t len) const; 00664 00674 bool normalAccess(off64_t start, size_t len) const; 00675 00676 00684 bool reserve(off64_t start, size_t len) const; 00685 00686 00699 bool sync() const; 00700 00716 bool dataSync() const; 00717 00718 00723 void dontGetCurrentPropertiesOnOpen(); 00724 00734 void getCurrentPropertiesOnOpen(); 00735 00740 bool getCurrentProperties(); 00741 00743 mode_t getPermissions() const; 00744 00746 uid_t getOwnerUserId() const; 00747 00749 gid_t getOwnerGroupId() const; 00750 00752 off64_t getSize() const; 00753 00757 blksize_t getBlockSize() const; 00758 00761 blkcnt_t getBlockCount() const; 00762 00765 int32_t isSocket() const; 00766 00769 int32_t isSymbolicLink() const; 00770 00773 int32_t isRegularFile() const; 00774 00777 int32_t isBlockDevice() const; 00778 00781 int32_t isDirectory() const; 00784 int32_t isCharacterDevice() const; 00785 00788 int32_t isFifo() const; 00789 00791 time_t getLastAccessTime() const; 00792 00797 time_t getLastModificationTime() const; 00798 00803 time_t getLastChangeTime() const; 00804 00806 dev_t getDevice() const; 00807 00809 dev_t getDeviceType() const; 00810 00812 ino_t getInode() const; 00813 00815 nlink_t getNumberOfHardLinks() const; 00816 00817 00820 bool changeOwner(const char *newuser, 00821 const char *newgroup) const; 00822 00825 bool changeOwner(uid_t uid, gid_t gid) const; 00826 00829 bool changeOwnerUser(const char *newuser) const; 00830 00833 bool changeOwnerUser(uid_t uid) const; 00834 00837 bool changeOwnerGroup(const char *newgroup) const; 00838 00841 bool changeOwnerGroup(gid_t gid) const; 00842 00846 bool canChangeOwner() const; 00847 00850 long maxLinks() const; 00851 00852 00858 const char * const *listAttributes() const; 00859 00860 00863 bool getAttribute(const char *name, 00864 uint16_t *number) const; 00865 00868 bool getAttribute(const char *name, 00869 unsigned long *number) const; 00870 00873 bool getAttribute(const char *name, int16_t *number) const; 00874 00877 bool getAttribute(const char *name, long *number) const; 00878 00881 bool getAttribute(const char *name, float *number) const; 00882 00885 bool getAttribute(const char *name, double *number) const; 00886 00889 bool getAttribute(const char *name, 00890 unsigned char *character) const; 00891 00894 bool getAttribute(const char *name, char *character) const; 00895 00898 bool getAttribute(const char *name, bool *value) const; 00899 00904 bool getAttribute(const char *name, 00905 unsigned char **string) const; 00906 00911 bool getAttribute(const char *name, 00912 char **string) const; 00913 00919 bool getAttribute(const char *name, 00920 unsigned char **string, 00921 size_t *size) const; 00922 00928 bool getAttribute(const char *name, 00929 char **string, size_t *size) const; 00930 00936 bool getAttribute(const char *name, 00937 void **buffer, size_t *size) const; 00938 00939 00942 bool createAttribute(const char *name, 00943 uint16_t number) const; 00944 00947 bool createAttribute(const char *name, 00948 unsigned long number) const; 00949 00952 bool createAttribute(const char *name, int16_t number) const; 00953 00956 bool createAttribute(const char *name, long number) const; 00957 00960 bool createAttribute(const char *name, float number) const; 00961 00964 bool createAttribute(const char *name, double number) const; 00965 00968 bool createAttribute(const char *name, 00969 unsigned char character) const; 00970 00973 bool createAttribute(const char *name, char character) const; 00974 00977 bool createAttribute(const char *name, bool value) const; 00978 00981 bool createAttribute(const char *name, 00982 const unsigned char *string) const; 00983 00986 bool createAttribute(const char *name, 00987 const char *string) const; 00988 00992 bool createAttribute(const char *name, 00993 const unsigned char *string, 00994 size_t size) const; 00995 00999 bool createAttribute(const char *name, 01000 const char *string, size_t size) const; 01001 01005 bool createAttribute(const char *name, 01006 const void *buffer, size_t size) const; 01007 01008 01012 bool replaceAttribute(const char *name, 01013 uint16_t number) const; 01014 01018 bool replaceAttribute(const char *name, 01019 unsigned long number) const; 01020 01024 bool replaceAttribute(const char *name, 01025 int16_t number) const; 01026 01030 bool replaceAttribute(const char *name, long number) const; 01031 01035 bool replaceAttribute(const char *name, float number) const; 01036 01040 bool replaceAttribute(const char *name, double number) const; 01041 01045 bool replaceAttribute(const char *name, 01046 unsigned char character) const; 01047 01051 bool replaceAttribute(const char *name, 01052 char character) const; 01053 01057 bool replaceAttribute(const char *name, bool value) const; 01058 01062 bool replaceAttribute(const char *name, 01063 const unsigned char *string) const; 01064 01068 bool replaceAttribute(const char *name, 01069 const char *string) const; 01070 01074 bool replaceAttribute(const char *name, 01075 const unsigned char *string, 01076 size_t size) const; 01077 01081 bool replaceAttribute(const char *name, 01082 const char *string, 01083 size_t size) const; 01084 01088 bool replaceAttribute(const char *name, 01089 const void *buffer, 01090 size_t size) const; 01091 01092 01096 bool setAttribute(const char *name, 01097 uint16_t number) const; 01098 01102 bool setAttribute(const char *name, 01103 unsigned long number) const; 01104 01108 bool setAttribute(const char *name, int16_t number) const; 01109 01113 bool setAttribute(const char *name, long number) const; 01114 01118 bool setAttribute(const char *name, float number) const; 01119 01123 bool setAttribute(const char *name, double number) const; 01124 01128 bool setAttribute(const char *name, 01129 unsigned char character) const; 01130 01134 bool setAttribute(const char *name, char character) const; 01135 01139 bool setAttribute(const char *name, bool value) const; 01140 01144 bool setAttribute(const char *name, 01145 const unsigned char *string) const; 01146 01150 bool setAttribute(const char *name, 01151 const char *string) const; 01152 01157 bool setAttribute(const char *name, 01158 const unsigned char *string, 01159 size_t size) const; 01160 01165 bool setAttribute(const char *name, 01166 const char *string, 01167 size_t size) const; 01168 01173 bool setAttribute(const char *name, 01174 const void *buffer, 01175 size_t size) const; 01176 01177 01180 bool removeAttribute(const char *name) const; 01181 01184 void *getInternalFileStatisticsStructure(); 01185 01186 01190 static bool createFile(const char *name, mode_t perms); 01191 01197 static ssize_t createFile(const char *name, 01198 mode_t perms, 01199 uint16_t number); 01200 01206 static ssize_t createFile(const char *name, 01207 mode_t perms, 01208 unsigned long number); 01209 01215 static ssize_t createFile(const char *name, 01216 mode_t perms, 01217 float number); 01218 01224 static ssize_t createFile(const char *name, 01225 mode_t perms, 01226 double number); 01227 01233 static ssize_t createFile(const char *name, 01234 mode_t perms, 01235 char number); 01236 01242 static ssize_t createFile(const char *name, 01243 mode_t perms, 01244 const char *string); 01245 01251 static ssize_t createFile(const char *name, 01252 mode_t perms, 01253 const char *string, 01254 size_t size); 01255 01261 static ssize_t createFile(const char *name, 01262 mode_t perms, 01263 const void *data, 01264 size_t size); 01265 01266 01269 static bool createFifo(const char *filename, mode_t perms); 01270 01273 static bool createPipe(filedescriptor *readfd, 01274 filedescriptor *writefd); 01275 01284 static int32_t createTemporaryFile(char *templatefilename); 01285 01288 static bool createHardLink(const char *oldpath, 01289 const char *newpath); 01290 01294 static bool createSymbolicLink(const char *oldpath, 01295 const char *newpath); 01296 01303 static char *resolveSymbolicLink(const char *filename); 01304 01305 01308 static bool rename(const char *oldpath, 01309 const char *newpath); 01310 01313 static bool remove(const char *filename); 01314 01315 01318 static bool truncate(const char *filename); 01319 01322 static bool truncate(const char *filename, off64_t length); 01323 01324 01334 static char *getContents(const char *name); 01335 01343 static ssize_t getContents(const char *name, 01344 unsigned char *buffer, 01345 size_t buffersize); 01346 01347 01349 static bool exists(const char *filename); 01350 01353 static bool readable(const char *filename); 01354 01357 static bool writeable(const char *filename); 01358 01361 static bool executable(const char *filename); 01362 01371 static bool accessible(const char *filename, int32_t mode); 01372 01373 01376 static bool getPermissions(const char *filename, 01377 mode_t *perms); 01378 01381 static bool getOwnerUserId(const char *filename, 01382 uid_t *uid); 01383 01386 static bool getOwnerGroupId(const char *filename, 01387 gid_t *gid); 01388 01391 static bool getSize(const char *filename, 01392 off64_t *size); 01393 01397 static bool getBlockSize(const char *filename, 01398 blksize_t *size); 01399 01403 static bool getBlockCount(const char *filename, 01404 blkcnt_t *blocks); 01405 01408 static int32_t isSocket(const char *filename); 01409 01412 static int32_t isSymbolicLink(const char *filename); 01413 01416 static int32_t isRegularFile(const char *filename); 01417 01420 static int32_t isBlockDevice(const char *filename); 01421 01424 static int32_t isDirectory(const char *filename); 01425 01428 static int32_t isCharacterDevice(const char *filename); 01429 01432 static int32_t isFifo(const char *filename); 01433 01436 static bool getLastAccessTime(const char *filename, 01437 time_t *atime); 01438 01444 static bool getLastModificationTime(const char *filename, 01445 time_t *mtime); 01446 01452 static bool getLastChangeTime(const char *filename, 01453 time_t *ctime); 01454 01457 static bool getDevice(const char *filename, dev_t *dev); 01458 01461 static bool getDeviceType(const char *filename, 01462 dev_t *devtype); 01463 01466 static bool getInode(const char *filename, ino_t *inode); 01467 01470 static bool getNumberOfHardLinks(const char *filename, 01471 nlink_t *nlink); 01472 01475 static bool changeOwner(const char *filename, 01476 const char *newuser, 01477 const char *newgroup); 01478 01481 static bool changeOwner(const char *filename, 01482 uid_t uid, gid_t gid); 01483 01486 static bool changeOwnerUser(const char *filename, 01487 const char *newuser); 01488 01491 static bool changeOwnerUser(const char *filename, 01492 uid_t uid); 01493 01496 static bool changeOwnerGroup(const char *filename, 01497 const char *newgroup); 01498 01501 static bool changeOwnerGroup(const char *filename, 01502 gid_t gid); 01503 01506 static bool canChangeOwner(const char *filename); 01507 01508 01512 static bool setLastAccessTime(const char *filename, 01513 time_t lastaccesstime); 01514 01518 static bool setLastModificationTime(const char *filename, 01519 time_t lastmodtime); 01520 01525 static bool setLastAccessAndModificationTimes( 01526 const char *filename, 01527 time_t lastaccesstime, 01528 time_t lastmodtime); 01529 01533 static bool setLastAccessAndModificationTimes( 01534 const char *filename); 01535 01536 01541 static char *dirname(const char *filename); 01542 01546 static char *basename(const char *filename); 01547 01553 static char *basename(const char *filename, 01554 const char *suffix); 01555 01556 01562 static key_t generateKey(const char *filename, int32_t id); 01563 01566 static long maxLinks(const char *filename); 01567 01568 #include <rudiments/private/file.h> 01569 }; 01570 01571 #ifdef RUDIMENTS_NAMESPACE 01572 } 01573 #endif 01574 01575 #endif