xref: /haiku/src/system/boot/loader/file_systems/fat/File.cpp (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
1 /*
2 ** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the OpenBeOS License.
4 */
5 
6 
7 #include "File.h"
8 
9 #include <util/kernel_cpp.h>
10 
11 #include <sys/stat.h>
12 #include <unistd.h>
13 
14 
15 //#define TRACE(x) dprintf x
16 #define TRACE(x) do {} while (0)
17 
18 
19 namespace FATFS {
20 
21 
22 File::File(Volume &volume, uint32 cluster, off_t size, const char *name)
23 	:
24 	fVolume(volume),
25 	fStream(volume, cluster, size, name)
26 {
27 	TRACE(("FATFS::File::()\n"));
28 }
29 
30 
31 File::~File()
32 {
33 	TRACE(("FATFS::File::~()\n"));
34 }
35 
36 
37 status_t
38 File::InitCheck()
39 {
40 	if (!fStream.InitCheck() < B_OK)
41 		return fStream.InitCheck();
42 
43 	return B_OK;
44 }
45 
46 
47 status_t
48 File::Open(void **_cookie, int mode)
49 {
50 	TRACE(("FATFS::File::%s(, %d)\n", __FUNCTION__, mode));
51 	if (fStream.InitCheck() < B_OK)
52 		return fStream.InitCheck();
53 
54 	return B_OK;
55 }
56 
57 
58 status_t
59 File::Close(void *cookie)
60 {
61 	return B_OK;
62 }
63 
64 
65 ssize_t
66 File::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize)
67 {
68 	TRACE(("FATFS::File::%s(, %Ld,, %d)\n", __FUNCTION__, pos, bufferSize));
69 	status_t err;
70 	err = fStream.ReadAt(pos, (uint8 *)buffer, &bufferSize);
71 	if (err < B_OK)
72 		return err;
73 	return bufferSize;
74 }
75 
76 
77 ssize_t
78 File::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize)
79 {
80 	return EROFS;
81 }
82 
83 
84 status_t
85 File::GetName(char *nameBuffer, size_t bufferSize) const
86 {
87 	return fStream.GetName(nameBuffer, bufferSize);
88 }
89 
90 
91 status_t
92 File::GetFileMap(struct file_map_run *runs, int32 *count)
93 {
94 	return fStream.GetFileMap(runs, count);
95 }
96 
97 
98 int32
99 File::Type() const
100 {
101 	return S_IFREG;
102 }
103 
104 
105 off_t
106 File::Size() const
107 {
108 	return fStream.Size();
109 }
110 
111 
112 ino_t
113 File::Inode() const
114 {
115 	return fStream.FirstCluster() << 16;
116 }
117 
118 }	// namespace FATFS
119