#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 32 del file sfat_create.c.
00032 { 00033 FILE *fs = NULL; 00034 char *endptr; 00035 int block_size=0; 00036 unsigned int num_block=0; 00037 struct stat buf; 00038 00039 /* Argomenti da riga di comando */ 00040 if (argc<2){ 00041 fprintf(stderr,"sfat_create: Errore nome filesystem mancante\n"); 00042 exit(EXIT_FAILURE); 00043 } 00044 else if (argc<3){ 00045 fprintf(stderr,"sfat_create: Errore numero di blocchi mancante\n"); 00046 exit(EXIT_FAILURE); 00047 } 00048 else if (argc<4){ 00049 fprintf(stderr,"sfat_create: Errore dimensione dei blocchi mancante\n"); 00050 exit(EXIT_FAILURE); 00051 } 00052 else if (lstat(argv[1], &buf) == 0){ 00053 fprintf(stderr,"sfat_create: Errore file gia' esistente\n"); 00054 exit(EXIT_FAILURE); 00055 } 00056 00057 num_block = strtoul(argv[2], &endptr, 10); /* unsigned */ 00058 if ((errno == ERANGE) || (errno != 0 && num_block == 0)) { 00059 perror("Strtoul"); 00060 exit(EXIT_FAILURE); 00061 } 00062 if (endptr == argv[2]) { 00063 fprintf(stderr, "sfat_create: No digits were found\n"); 00064 exit(EXIT_FAILURE); 00065 } 00066 if (num_block <= 0){ 00067 fprintf(stderr, "sfat_create: error number blocks\n"); 00068 exit(EXIT_FAILURE); 00069 } 00070 00071 block_size = strtol(argv[3], &endptr, 10); 00072 if (!((block_size==128) || (block_size==1024) || (block_size==2048) || (block_size==4096))){ 00073 fprintf(stderr, "sfat_create: bad size block\n"); 00074 return EWFCD; /* bad size block */ 00075 } 00076 00077 if (!(fs = fopen(argv[1],"w"))){ 00078 perror(NULL); 00079 exit(EXIT_FAILURE); 00080 } 00081 00082 if (EWFCD == fat_format(fs, block_size, num_block)){ 00083 sfaterror (EWFCD); 00084 if (fclose(fs)) perror(NULL); 00085 exit(EXIT_FAILURE); 00086 } 00087 printf("sfat_create: Sto creando %s di %d blocchi size %d\n", argv[1], num_block, block_size); 00088 00089 if (fclose(fs)){ 00090 perror(NULL); 00091 exit(EXIT_FAILURE); 00092 } 00093 exit(EXIT_SUCCESS); 00094 return 0; 00095 }