xref: /haiku/headers/os/storage/File.h (revision 3e216965baa8d58a67bf7372e2bfa13d999f5a9d)
1 /*
2  * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _FILE_H
6 #define _FILE_H
7 
8 
9 #include <DataIO.h>
10 #include <Node.h>
11 
12 
13 class BFile : public BNode, public BPositionIO {
14 	public:
15 		BFile();
16 		BFile(const BFile &file);
17 		BFile(const entry_ref *ref, uint32 openMode);
18 		BFile(const BEntry *entry, uint32 openMode);
19 		BFile(const char *path, uint32 openMode);
20 		BFile(const BDirectory *dir, const char *path, uint32 openMode);
21 		virtual ~BFile();
22 
23 		status_t SetTo(const entry_ref *ref, uint32 openMode);
24 		status_t SetTo(const BEntry *entry, uint32 openMode);
25 		status_t SetTo(const char *path, uint32 openMode);
26 		status_t SetTo(const BDirectory *dir, const char *path, uint32 openMode);
27 
28 		bool IsReadable() const;
29 		bool IsWritable() const;
30 
31 		virtual ssize_t Read(void *buffer, size_t size);
32 		virtual ssize_t ReadAt(off_t location, void *buffer, size_t size);
33 		virtual ssize_t Write(const void *buffer, size_t size);
34 		virtual ssize_t WriteAt(off_t location, const void *buffer, size_t size);
35 
36 		virtual off_t Seek(off_t offset, uint32 seekMode);
37 		virtual off_t Position() const;
38 
39 		virtual status_t SetSize(off_t size);
40 		virtual	status_t GetSize(off_t* size) const;
41 
42 		BFile &operator=(const BFile &file);
43 
44 	private:
45 		virtual void _PhiloFile1();
46 		virtual void _PhiloFile2();
47 		virtual void _PhiloFile3();
48 		virtual void _PhiloFile4();
49 		virtual void _PhiloFile5();
50 		virtual void _PhiloFile6();
51 
52 		uint32 _reservedData[8];
53 
54 	private:
55 		int get_fd() const;
56 		virtual void close_fd();
57 
58 	private:
59 		//! The file's open mode.
60 		uint32 fMode;
61 };
62 
63 #endif	// _FILE_H
64