xref: /haiku/headers/build/os/storage/File.h (revision 3cb015b1ee509d69c643506e8ff573808c86dcfc)
1 //----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //---------------------------------------------------------------------
5 /*!
6 	\file File.h
7 	BFile interface declaration.
8 */
9 #ifndef _FILE_H
10 #define _FILE_H
11 
12 #include <DataIO.h>
13 #include <Node.h>
14 #include <StorageDefs.Private.h>
15 
16 #ifdef USE_OPENBEOS_NAMESPACE
17 namespace OpenBeOS {
18 #endif
19 
20 /*!
21 	\class BFile
22 	\brief BFile is a wrapper class for common operations on files providing
23 	access to the file's content data and its attributes.
24 
25 	A BFile represents a file in some file system. It implements the
26 	BPositionIO interface and thus the methods to read from and write to the
27 	file, and is derived of BNode to provide access to the file's attributes.
28 
29 	\author <a href='mailto:bonefish@users.sf.net'>Ingo Weinhold</a>
30 
31 	\version 0.0.0
32 */
33 class BFile : public BNode, public BPositionIO {
34 public:
35 	BFile();
36 	BFile(const BFile &file);
37 	BFile(const entry_ref *ref, uint32 openMode);
38 	BFile(const BEntry *entry, uint32 openMode);
39 	BFile(const char *path, uint32 openMode);
40 	BFile(const BDirectory *dir, const char *path, uint32 openMode);
41 	virtual ~BFile();
42 
43 	status_t SetTo(const entry_ref *ref, uint32 openMode);
44 	status_t SetTo(const BEntry *entry, uint32 openMode);
45 	status_t SetTo(const char *path, uint32 openMode);
46 	status_t SetTo(const BDirectory *dir, const char *path, uint32 openMode);
47 
48 	bool IsReadable() const;
49 	bool IsWritable() const;
50 
51 	virtual ssize_t Read(void *buffer, size_t size);
52 	virtual ssize_t ReadAt(off_t location, void *buffer, size_t size);
53 	virtual ssize_t Write(const void *buffer, size_t size);
54 	virtual ssize_t WriteAt(off_t location, const void *buffer, size_t size);
55 
56 	virtual off_t Seek(off_t offset, uint32 seekMode);
57 	virtual off_t Position() const;
58 
59 	virtual status_t SetSize(off_t size);
60 
61 	BFile &operator=(const BFile &file);
62 
63 private:
64 	virtual void _PhiloFile1();
65 	virtual void _PhiloFile2();
66 	virtual void _PhiloFile3();
67 	virtual void _PhiloFile4();
68 	virtual void _PhiloFile5();
69 	virtual void _PhiloFile6();
70 
71 	uint32 _reservedData[8];
72 
73 private:
74 	int get_fd() const;
75 	virtual void close_fd();
76 
77 private:
78 	//! The file's open mode.
79 	uint32 fMode;
80 };
81 
82 #ifdef USE_OPENBEOS_NAMESPACE
83 };		// namespace OpenBeOS
84 #endif
85 
86 #endif	// _FILE_H
87 
88 
89