iso9660: new license LGPL
[meinos.git] / apps / iso9660 / sector.c
blob3c8e7e282637f28f848e8fd6d2e7a3e78c98778c
1 /*
2 iso9660 - An iso9660 CDI driver with Rockridge support
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <stdint.h>
21 #include "cdi/fs.h"
22 #include "cdi/cache.h"
24 #include "iso9660def.h"
26 #include "iso9660_cdi.h"
28 /**
29 * Reads data from device for cache
30 * @param cache CDI cache
31 * @param block Block to read
32 * @param count How many blocks to read
33 * @param dest Buffer to store data in
34 * @param prv Private data (CDI filesystem)
36 int iso9660_sector_read_cache(struct cdi_cache *cache,uint64_t block,size_t count,void *dest,void *prv) {
37 debug("iso9660_sector_read_cache(0x%x,0x%x,0x%x,0x%x,0x%x,0x%x)\n",cache,block,count,dest,prv);
38 uint64_t start = ((uint64_t)block)*ISO9660_DEFAULT_SECTOR_SIZE;
39 size_t size = count*ISO9660_DEFAULT_SECTOR_SIZE;
40 return iso9660_sector_read(prv,start,size,dest)/ISO9660_DEFAULT_SECTOR_SIZE;
43 /**
44 * Read data from resource
45 * @param res Resource to read data from
46 * @param pos Position in resource
47 * @param size How many bytes to read
48 * @param Buffer Buffer to store data in
49 * @return How many bytes read
51 size_t iso9660_read(struct iso9660_fs_res *res,size_t pos,size_t size,void *buffer) {
52 size_t block = pos/res->voldesc->sector_size;
53 size_t offset = pos%res->voldesc->sector_size;
54 size_t rem_size = size;
56 while (rem_size>0) {
57 //debug("Block: 0x%x\n",res->data_sector+block++);
58 struct cdi_cache_block *cache_block = cdi_cache_block_get(res->cache,res->data_sector+block++);
59 size_t cur_size = rem_size>res->voldesc->sector_size?res->voldesc->sector_size:rem_size;
60 memcpy(buffer,cache_block->data+offset,cur_size);
61 cdi_cache_block_release(res->cache,cache_block);
62 buffer += cur_size;
63 rem_size -= cur_size;
64 offset = 0;
67 return size;