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