diff options
author | San Mehat | 2010-03-10 14:46:00 -0600 |
---|---|---|
committer | San Mehat | 2010-03-10 17:19:06 -0600 |
commit | a6391f1006b961ca89d1c79a826375380684a4de (patch) | |
tree | 50f5a2b2179d52cf24cb6ad09c4842d0404610e2 /libdiskconfig/write_lst.c | |
parent | 732799eca9f2767996bc423503937c4c935bb630 (diff) | |
download | platform-system-core-a6391f1006b961ca89d1c79a826375380684a4de.tar.gz platform-system-core-a6391f1006b961ca89d1c79a826375380684a4de.tar.xz platform-system-core-a6391f1006b961ca89d1c79a826375380684a4de.zip |
system: libdiskconfig: Add libdiskconfig
Change-Id: Ie7a7b5d8016dec60cdfb17228c3f519789c98564
Signed-off-by: San Mehat <san@google.com>
Diffstat (limited to 'libdiskconfig/write_lst.c')
-rw-r--r-- | libdiskconfig/write_lst.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/libdiskconfig/write_lst.c b/libdiskconfig/write_lst.c new file mode 100644 index 000000000..12b7cd775 --- /dev/null +++ b/libdiskconfig/write_lst.c | |||
@@ -0,0 +1,92 @@ | |||
1 | /* libs/diskconfig/write_lst.c | ||
2 | * | ||
3 | * Copyright 2008, The Android Open Source Project | ||
4 | * | ||
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | * you may not use this file except in compliance with the License. | ||
7 | * You may obtain a copy of the License at | ||
8 | * | ||
9 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | * | ||
11 | * Unless required by applicable law or agreed to in writing, software | ||
12 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | * See the License for the specific language governing permissions and | ||
15 | * limitations under the License. | ||
16 | */ | ||
17 | |||
18 | #define LOG_TAG "write_lst" | ||
19 | #include <sys/types.h> | ||
20 | #include <stdint.h> | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <unistd.h> | ||
24 | |||
25 | #include <cutils/log.h> | ||
26 | |||
27 | #include <diskconfig/diskconfig.h> | ||
28 | |||
29 | struct write_list * | ||
30 | alloc_wl(uint32_t data_len) | ||
31 | { | ||
32 | struct write_list *item; | ||
33 | |||
34 | if (!(item = malloc(sizeof(struct write_list) + data_len))) { | ||
35 | LOGE("Unable to allocate memory."); | ||
36 | return NULL; | ||
37 | } | ||
38 | |||
39 | item->len = data_len; | ||
40 | return item; | ||
41 | } | ||
42 | |||
43 | void | ||
44 | free_wl(struct write_list *item) | ||
45 | { | ||
46 | if (item) | ||
47 | free(item); | ||
48 | } | ||
49 | |||
50 | struct write_list * | ||
51 | wlist_add(struct write_list **lst, struct write_list *item) | ||
52 | { | ||
53 | item->next = (*lst); | ||
54 | *lst = item; | ||
55 | return item; | ||
56 | } | ||
57 | |||
58 | void | ||
59 | wlist_free(struct write_list *lst) | ||
60 | { | ||
61 | struct write_list *temp_wr; | ||
62 | while (lst) { | ||
63 | temp_wr = lst->next; | ||
64 | free_wl(lst); | ||
65 | lst = temp_wr; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | int | ||
70 | wlist_commit(int fd, struct write_list *lst, int test) | ||
71 | { | ||
72 | for(; lst; lst = lst->next) { | ||
73 | if (lseek64(fd, lst->offset, SEEK_SET) != (loff_t)lst->offset) { | ||
74 | LOGE("Cannot seek to the specified position (%lld).", lst->offset); | ||
75 | goto fail; | ||
76 | } | ||
77 | |||
78 | if (!test) { | ||
79 | if (write(fd, lst->data, lst->len) != (int)lst->len) { | ||
80 | LOGE("Failed writing %u bytes at position %lld.", lst->len, | ||
81 | lst->offset); | ||
82 | goto fail; | ||
83 | } | ||
84 | } else | ||
85 | LOGI("Would write %d bytes @ offset %lld.", lst->len, lst->offset); | ||
86 | } | ||
87 | |||
88 | return 0; | ||
89 | |||
90 | fail: | ||
91 | return -1; | ||
92 | } | ||