vfs: check userland buffers before reading them.
[haiku.git] / src / system / boot / loader / file_systems / fat / fatfs.cpp
blob2a989109f8fbef80ae84be87ff84b31aaf0a3b9b
1 /*
2 * Copyright 2008, François Revol <revol@free.fr>
3 * Distributed under the terms of the MIT License.
4 */
7 #include "fatfs.h"
9 #include <boot/partitions.h>
10 #include <boot/platform.h>
12 #include <string.h>
13 #include <unistd.h>
14 #include <fcntl.h>
15 #include <stdio.h>
16 #include <stdlib.h>
19 using namespace FATFS;
21 #if 0
22 status_t
23 FATFS::get_root_block(int fDevice, char *buffer, int32 blockSize, off_t partitionSize)
25 // calculate root block position (it depends on the block size)
27 // ToDo: get the number of reserved blocks out of the disk_environment structure??
28 // (from the amiga_rdb module)
29 int32 reservedBlocks = 2;
30 off_t offset = (((partitionSize / blockSize) - 1 - reservedBlocks) / 2) + reservedBlocks;
31 // ToDo: this calculation might be incorrect for certain cases.
33 if (read_pos(fDevice, offset * blockSize, buffer, blockSize) < B_OK)
34 return B_ERROR;
36 RootBlock root(buffer, blockSize);
37 if (root.ValidateCheckSum() < B_OK)
38 return B_BAD_DATA;
40 //printf("primary = %ld, secondary = %ld\n", root.PrimaryType(), root.SecondaryType());
41 if (!root.IsRootBlock())
42 return B_BAD_TYPE;
44 return B_OK;
47 #endif