dosfslabel.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* dosfslabel.c - User interface */
  2. /* Copyright 2007 Red Hat, Inc.
  3. * Portions copyright 1998 Roman Hodek.
  4. * Portions copyright 1993 Werner Almesberger.
  5. */
  6. #include "version.h"
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <unistd.h>
  12. #include <getopt.h>
  13. #include "common.h"
  14. #include "dosfsck.h"
  15. #include "io.h"
  16. #include "boot.h"
  17. #include "fat.h"
  18. #include "file.h"
  19. #include "check.h"
  20. int interactive = 0,list = 0,test = 0,verbose = 0,write_immed = 0;
  21. int atari_format = 0;
  22. unsigned n_files = 0;
  23. void *mem_queue = NULL;
  24. static void usage(int error)
  25. {
  26. FILE *f = error ? stderr : stdout;
  27. int status = error ? 1 : 0;
  28. fprintf(f,"usage: dosfslabel device [label]\n");
  29. exit(status);
  30. }
  31. /*
  32. * ++roman: On m68k, check if this is an Atari; if yes, turn on Atari variant
  33. * of MS-DOS filesystem by default.
  34. */
  35. static void check_atari( void )
  36. {
  37. #ifdef __mc68000__
  38. FILE *f;
  39. char line[128], *p;
  40. if (!(f = fopen( "/proc/hardware", "r" ))) {
  41. perror( "/proc/hardware" );
  42. return;
  43. }
  44. while( fgets( line, sizeof(line), f ) ) {
  45. if (strncmp( line, "Model:", 6 ) == 0) {
  46. p = line + 6;
  47. p += strspn( p, " \t" );
  48. if (strncmp( p, "Atari ", 6 ) == 0)
  49. atari_format = 1;
  50. break;
  51. }
  52. }
  53. fclose( f );
  54. #endif
  55. }
  56. int main(int argc, char *argv[])
  57. {
  58. DOS_FS fs;
  59. int rw = 0;
  60. char *device = NULL;
  61. char *label = NULL;
  62. check_atari();
  63. if (argc < 2 || argc > 3)
  64. usage(1);
  65. if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
  66. usage(0);
  67. else if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) {
  68. printf( "dosfslabel " VERSION ", " VERSION_DATE ", FAT32, LFN\n" );
  69. exit(0);
  70. }
  71. device = argv[1];
  72. if (argc == 3) {
  73. label = argv[2];
  74. if (strlen(label) > 11) {
  75. fprintf(stderr,
  76. "dosfslabel: labels can be no longer than 11 characters\n");
  77. exit(1);
  78. }
  79. rw = 1;
  80. }
  81. fs_open(device, rw);
  82. read_boot(&fs);
  83. if (!rw) {
  84. fprintf(stdout, "%s\n", fs.label);
  85. exit(0);
  86. }
  87. write_label(&fs, label);
  88. return fs_close(rw) ? 1 : 0;
  89. }