correct return code of map_write
[emile:mainline.git] / libmap / map_write.c
1 /*
2  *
3  * (c) 2004-2007 Laurent Vivier <Laurent@Vivier.EU>
4  *
5  */
6
7 #include <sys/types.h>
8 #include <unistd.h>
9
10 #include "libmap.h"
11
12 int map_write(map_t *map, int part)
13 {
14         off_t offset;
15         int ret;
16         int blocksize = map->device->get_blocksize(map->device->data);
17
18         if (part > map->partition.MapBlkCnt)
19                 return -1;
20
21         offset = part * sizeof(struct Partition) + 
22                         sizeof(struct DriverDescriptor);
23
24         ret = map->device->write_sector(map->device->data, offset / blocksize,  &map->partition,
25                                         sizeof(struct Partition));
26         if (ret == -1)
27                 return -1;
28
29         map->current = part;
30
31         return part;
32 }