2 * Copyright 2003-2013, Axel Dörfler, axeld@pinc-software.de.
3 * Copyright 2008, François Revol <revol@free.fr>
4 * Distributed under the terms of the MIT License.
13 #include "Directory.h"
16 //#define TRACE(x) dprintf x
17 #define TRACE(x) do {} while (0)
23 File::File(Volume
&volume
, off_t dirEntryOffset
, uint32 cluster
, off_t size
,
27 fStream(volume
, cluster
, size
, name
),
28 fDirEntryOffset(dirEntryOffset
)
30 TRACE(("FATFS::File::()\n"));
36 TRACE(("FATFS::File::~()\n"));
43 if (fStream
.InitCheck() != B_OK
)
44 return fStream
.InitCheck();
51 File::Open(void **_cookie
, int mode
)
53 TRACE(("FATFS::File::%s(, %d)\n", __FUNCTION__
, mode
));
54 if (fStream
.InitCheck() < B_OK
)
55 return fStream
.InitCheck();
57 return Node::Open(_cookie
, mode
);
62 File::Close(void *cookie
)
64 return Node::Close(cookie
);
69 File::ReadAt(void *cookie
, off_t pos
, void *buffer
, size_t bufferSize
)
71 TRACE(("FATFS::File::%s(, %Ld,, %d)\n", __FUNCTION__
, pos
, bufferSize
));
73 err
= fStream
.ReadAt(pos
, buffer
, &bufferSize
);
81 File::WriteAt(void *cookie
, off_t pos
, const void *buffer
, size_t bufferSize
)
83 off_t streamSize
= fStream
.Size();
84 uint32 firstCluster
= fStream
.FirstCluster();
87 size_t written
= bufferSize
;
88 status_t error
= fStream
.WriteAt(pos
, buffer
, &written
);
92 // If the file size has changed, we need to adjust the directory entry.
93 if (fStream
.Size() > streamSize
|| fStream
.FirstCluster() != firstCluster
) {
94 error
= Directory::UpdateDirEntry(fVolume
, fDirEntryOffset
,
95 fStream
.FirstCluster(), fStream
.Size());
98 // TODO: Undo the changes!
106 File::GetName(char *nameBuffer
, size_t bufferSize
) const
108 return fStream
.GetName(nameBuffer
, bufferSize
);
113 File::GetFileMap(struct file_map_run
*runs
, int32
*count
)
115 return fStream
.GetFileMap(runs
, count
);
129 return fStream
.Size();
136 return fStream
.FirstCluster() << 16;