#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <sys/stat.h>#include <limits.h>#include "../../Fat/Src/Include/format.h"#include "../../Fat/Src/Include/sfaterror.h"Vai al codice sorgente di questo file.
Funzioni | |
| int | main (int argc, char **argv) |
This program is free software; you can redistribuite it and/or modify it under the terms of the GNU/General Pubblic License as published the Free software Foundation; either version 2 of the License, or (at your opinion) any later version.
Definizione nel file sfat_create.c.
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Comando: sfat_create device_name nblock size
Crea un file di nome device_name da usare come device per un filesystem sfat e lo formatta in modo che la data region contenga nblocks blocchi di ampiezza size. Ricordando che size puo' assumere uno dei 4 valori: 128, 1K, 2K, 4K.
Se il file esiste la funzione termina con errore.
Definizione alla linea 33 del file sfat_create.c.
00033 { 00034 FILE *fs = NULL; 00035 char *endptr; 00036 int block_size=0; 00037 unsigned int num_block=0; 00038 struct stat buf; 00039 00040 /* Argomenti da riga di comando */ 00041 if (argc<2){ 00042 fprintf(stderr,"sfat_create: Errore nome filesystem mancante\n"); 00043 exit(EXIT_FAILURE); 00044 } 00045 else if (argc<3){ 00046 fprintf(stderr,"sfat_create: Errore numero di blocchi mancante\n"); 00047 exit(EXIT_FAILURE); 00048 } 00049 else if (argc<4){ 00050 fprintf(stderr,"sfat_create: Errore dimensione dei blocchi mancante\n"); 00051 exit(EXIT_FAILURE); 00052 } 00053 else if (lstat(argv[1], &buf) == 0){ 00054 fprintf(stderr,"sfat_create: Errore file gia' esistente\n"); 00055 exit(EXIT_FAILURE); 00056 } 00057 00058 num_block = strtoul(argv[2], &endptr, 10); /* unsigned */ 00059 if ((errno == ERANGE) || (errno != 0 && num_block == 0)) { 00060 perror("Strtoul"); 00061 exit(EXIT_FAILURE); 00062 } 00063 if (endptr == argv[2]) { 00064 fprintf(stderr, "sfat_create: No digits were found\n"); 00065 exit(EXIT_FAILURE); 00066 } 00067 if (num_block <= 0){ 00068 fprintf(stderr, "sfat_create: error number blocks\n"); 00069 exit(EXIT_FAILURE); 00070 } 00071 00072 block_size = strtol(argv[3], &endptr, 10); 00073 if (!((block_size==128) || (block_size==1024) || (block_size==2048) || (block_size==4096))){ 00074 fprintf(stderr, "sfat_create: bad size block\n"); 00075 return EWFCD; /* bad size block */ 00076 } 00077 00078 if (!(fs = fopen(argv[1],"w"))){ 00079 perror(NULL); 00080 exit(EXIT_FAILURE); 00081 } 00082 00083 if (EWFCD == fat_format(fs, block_size, num_block)){ 00084 sfaterror (EWFCD); 00085 if (fclose(fs)) perror(NULL); 00086 exit(EXIT_FAILURE); 00087 } 00088 printf("sfat_create: Sto creando %s di %d blocchi size %d\n", argv[1], num_block, block_size); 00089 00090 if (fclose(fs)){ 00091 perror(NULL); 00092 exit(EXIT_FAILURE); 00093 } 00094 exit(EXIT_SUCCESS); 00095 return 0; 00096 }
1.6.3