fat.c revision f79b2dff1024db4f6326f3422236bed169dd902f
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include <assert.h> 18#include <string.h> 19 20#include <sys/endian.h> 21 22#include "fat.h" 23 24const char FAT_BOOT_SIG[] = { 0x55, 0xAA }; 25const char FAT_INFO_SIG1[4] = { 'R', 'R', 'a', 'A' }; 26const char FAT_INFO_SIG2[4] = { 'r', 'r', 'A', 'a' }; 27 28void fat_dirent_set_first_cluster(struct fat_dirent *de, cluster_t cluster) { 29 assert(de); 30 31 de->first_cluster_hi = htole16((cluster >> 16) & 0xffff); 32 de->first_cluster_lo = htole16((cluster >> 0) & 0xffff); 33} 34 35void fat_dirent_set(struct fat_dirent *de, 36 char *name, uint8_t attr, 37 cluster_t first_cluster, uint32_t size) { 38 assert(de); 39 assert(name); 40 41 memset(de, 0, sizeof(*de)); 42 43 memcpy(de->name, name, 11); 44 de->attr = attr; 45 fat_dirent_set_first_cluster(de, first_cluster); 46 de->size = htole32(size); 47} 48