Home | History | Annotate | Download | only in fatblock
      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 #include <endian.h>
     20 
     21 #include "fat.h"
     22 
     23 const char FAT_BOOT_SIG[] = { 0x55, 0xAA };
     24 const char FAT_INFO_SIG1[4] = { 'R', 'R', 'a', 'A' };
     25 const char FAT_INFO_SIG2[4] = { 'r', 'r', 'A', 'a' };
     26 
     27 void fat_dirent_set_first_cluster(struct fat_dirent *de, cluster_t cluster)
     28 {
     29 	assert(de);
     30 
     31 	de->first_cluster_hi = htole16((cluster >> 16) & 0xffff);
     32 	de->first_cluster_lo = htole16((cluster >>  0) & 0xffff);
     33 }
     34 
     35 void fat_dirent_set(struct fat_dirent *de,
     36                     char *name, uint8_t attr,
     37                     cluster_t first_cluster, uint32_t size)
     38 {
     39 	assert(de);
     40 	assert(name);
     41 
     42 	memset(de, 0, sizeof(*de));
     43 
     44 	memcpy(de->name, name, 11);
     45 	de->attr = attr;
     46 	fat_dirent_set_first_cluster(de, first_cluster);
     47 	de->size = htole32(size);
     48 }
     49