Changeset f4ae95a in mainline
- Timestamp:
- 2017-07-02T16:22:09Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a927398
- Parents:
- ee50130
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mkfat/mkfat.c
ree50130 rf4ae95a 38 38 */ 39 39 40 #include <ctype.h> 40 41 #include <stdio.h> 41 42 #include <stdlib.h> … … 48 49 #include <errno.h> 49 50 #include "fat.h" 51 #include "fat_dentry.h" 50 52 51 53 #define NAME "mkfat" 54 55 #define LABEL_NONAME "NO NAME" 52 56 53 57 /** Divide and round up. */ … … 77 81 uint32_t total_clusters; 78 82 uint8_t fat_count; 83 const char *label; 79 84 } fat_cfg_t; 80 85 … … 102 107 cfg.root_ent_max = 128; 103 108 cfg.fat_type = FATAUTO; 109 cfg.label = NULL; 104 110 105 111 if (argc < 2) { … … 142 148 return 1; 143 149 } 150 151 --argc; ++argv; 152 } 153 154 if (str_cmp(*argv, "--label") == 0) { 155 --argc; ++argv; 156 if (*argv == NULL) { 157 printf(NAME ": Error, argument missing.\n"); 158 syntax_print(); 159 return 1; 160 } 161 162 cfg.label = *argv; 144 163 145 164 --argc; ++argv; … … 216 235 static void syntax_print(void) 217 236 { 218 printf("syntax: mkfat [--size <sectors>] [--type 12|16|32] <device_name>\n"); 237 printf("syntax: mkfat [--size <sectors>] [--type 12|16|32] " 238 "[--label <label>] <device_name>\n"); 239 } 240 241 static int fat_label_encode(void *dest, const char *src) 242 { 243 int i; 244 const char *sp; 245 uint8_t *dp; 246 247 i = 0; 248 sp = src; 249 dp = (uint8_t *)dest; 250 251 while (*sp != '\0' && i < FAT_VOLLABEL_LEN) { 252 if (!ascii_check(*sp)) 253 return EINVAL; 254 if (dp != NULL) 255 dp[i] = toupper(*sp); 256 ++i; ++sp; 257 } 258 259 while (i < FAT_VOLLABEL_LEN) { 260 if (dp != NULL) 261 dp[i] = FAT_PAD; 262 ++i; 263 } 264 265 return EOK; 219 266 } 220 267 … … 241 288 cfg->sector_size); 242 289 } else 243 cfg->rootdir_sectors = 0;290 cfg->rootdir_sectors = cfg->sectors_per_cluster; 244 291 non_data_sectors_lb = cfg->reserved_sectors + cfg->rootdir_sectors; 245 292 … … 268 315 cfg->fat_sectors = div_round_up(fat_bytes, cfg->sector_size); 269 316 317 if (cfg->label != NULL && fat_label_encode(NULL, cfg->label) != EOK) 318 return EINVAL; 319 270 320 return EOK; 271 321 } … … 280 330 int rc; 281 331 struct fat_bs bs; 332 fat_dentry_t *de; 282 333 283 334 fat_bootsec_create(cfg, &bs); … … 339 390 printf("Writing root directory.\n"); 340 391 memset(buffer, 0, cfg->sector_size); 341 if (cfg->fat_type != FAT32) { 342 size_t idx; 343 for (idx = 0; idx < cfg->rootdir_sectors; ++idx) { 344 rc = block_write_direct(service_id, addr, 1, buffer); 345 if (rc != EOK) 346 return EIO; 347 348 ++addr; 349 } 350 } else { 351 for (i = 0; i < cfg->sectors_per_cluster; i++) { 352 rc = block_write_direct(service_id, addr, 1, buffer); 353 if (rc != EOK) 354 return EIO; 355 356 ++addr; 357 } 392 de = (fat_dentry_t *)buffer; 393 size_t idx; 394 for (idx = 0; idx < cfg->rootdir_sectors; ++idx) { 395 396 if (idx == 0 && cfg->label != NULL) { 397 /* Set up volume label entry */ 398 (void) fat_label_encode(&de->name, cfg->label); 399 de->attr = FAT_ATTR_VOLLABEL; 400 de->mtime = 0x1234; 401 de->mdate = 0x1234; 402 } else if (idx == 1) { 403 /* Clear volume label entry */ 404 memset(buffer, 0, cfg->sector_size); 405 } 406 407 rc = block_write_direct(service_id, addr, 1, buffer); 408 if (rc != EOK) 409 return EIO; 410 411 ++addr; 358 412 } 359 413 … … 366 420 static void fat_bootsec_create(struct fat_cfg const *cfg, struct fat_bs *bs) 367 421 { 422 const char *bs_label; 423 424 /* 425 * The boot sector must always contain a valid label. If there 426 * is no label, there should be 'NO NAME' 427 */ 428 if (cfg->label != NULL) 429 bs_label = cfg->label; 430 else 431 bs_label = LABEL_NONAME; 368 432 memset(bs, 0, sizeof(*bs)); 369 433 … … 404 468 bs->fat32.root_cluster = 2; 405 469 406 memcpy(bs->fat32.label, "HELENOS_NEW", 11);470 (void) fat_label_encode(&bs->fat32.label, bs_label); 407 471 memcpy(bs->fat32.type, "FAT32 ", 8); 408 472 } else { … … 412 476 bs->id = host2uint32_t_be(0x12345678); 413 477 414 memcpy(bs->label, "HELENOS_NEW", 11);478 (void) fat_label_encode(&bs->label, bs_label); 415 479 memcpy(bs->type, "FAT ", 8); 416 480 } -
uspace/srv/fs/fat/fat_dentry.h
ree50130 rf4ae95a 35 35 #define FAT_FAT_DENTRY_H_ 36 36 37 #include <ctype.h> 37 38 #include <stdint.h> 38 39 #include <stdbool.h> -
uspace/srv/fs/fat/fat_ops.c
ree50130 rf4ae95a 1039 1039 static int fat_fsprobe(service_id_t service_id, vfs_fs_probe_info_t *info) 1040 1040 { 1041 fat_bs_t *bs;1042 1041 fat_idx_t *ridxp; 1043 1042 fs_node_t *rfn; … … 1045 1044 fat_directory_t di; 1046 1045 char label[FAT_VOLLABEL_LEN + 1]; 1047 int i;1048 1046 int rc; 1049 1047 … … 1060 1058 rc = fat_directory_vollabel_get(&di, label); 1061 1059 if (rc != EOK) { 1062 /* No label in root directory. Read label from the BS */ 1063 bs = block_bb_get(service_id); 1064 i = FAT_VOLLABEL_LEN; 1065 while (i > 0 && bs->label[i - 1] == FAT_PAD) 1066 --i; 1067 1068 /* XXX Deal with non-ASCII characters */ 1069 memcpy(label, bs->label, i); 1070 label[i] = '\0'; 1060 if (rc != ENOENT) 1061 return rc; 1062 1063 label[0] = '\0'; 1071 1064 } 1072 1065
Note:
See TracChangeset
for help on using the changeset viewer.