1 // isvolume - for OpenBeOS 2 // 3 // authors, in order of contribution: 4 // jonas.sundstrom@kirilla.com 5 // 6 7 // std C includes 8 #include <stdio.h> 9 #include <string.h> 10 11 // BeOS C includes 12 #include <fs_info.h> 13 14 void print_help (void); 15 16 int main (int32 argc, char **argv) 17 { 18 dev_t vol_device = dev_for_path("."); 19 uint32 is_volume_flags = 0; 20 fs_info volume_info; 21 22 for (int i = 1; i < argc; i++) 23 { 24 if (! strcmp(argv[i], "--help")) 25 { 26 print_help(); 27 return (0); 28 } 29 30 if (argv[i][0] == '-') 31 { 32 if (! strcmp(argv[i], "-readonly")) is_volume_flags |= B_FS_IS_READONLY; 33 else if (! strcmp(argv[i], "-query")) is_volume_flags |= B_FS_HAS_QUERY; 34 else if (! strcmp(argv[i], "-attribute")) is_volume_flags |= B_FS_HAS_ATTR; 35 else if (! strcmp(argv[i], "-mime")) is_volume_flags |= B_FS_HAS_MIME; 36 else if (! strcmp(argv[i], "-shared")) is_volume_flags |= B_FS_IS_SHARED; 37 else if (! strcmp(argv[i], "-persistent")) is_volume_flags |= B_FS_IS_PERSISTENT; 38 else if (! strcmp(argv[i], "-removable")) is_volume_flags |= B_FS_IS_REMOVABLE; 39 else 40 { 41 fprintf(stderr, "%s: option %s is not understood (use --help for help)\n", argv[0], argv[i]); 42 return (-1); 43 } 44 } 45 else 46 { 47 vol_device = dev_for_path(argv[i]); 48 49 if (vol_device < 0) 50 { 51 fprintf(stderr, "%s: can't get information about volume: %s\n", argv[0], argv[i]); 52 return (-1); 53 } 54 } 55 } 56 57 if(fs_stat_dev(vol_device, & volume_info) == B_OK) 58 { 59 if (volume_info.flags & is_volume_flags) 60 printf("yes\n"); 61 else 62 printf("no\n"); 63 64 return (0); 65 } 66 else 67 { 68 fprintf(stderr, "%s: can't get information about dev_t: %ld\n", argv[0], vol_device); 69 return (-1); 70 } 71 } 72 73 void print_help (void) 74 { 75 fprintf (stderr, 76 "Usage: isvolume {-OPTION} [volumename]\n" 77 " Where OPTION is one of:\n" 78 " -readonly - volume is read-only\n" 79 " -query - volume supports queries\n" 80 " -attribute - volume supports attributes\n" 81 " -mime - volume supports MIME information\n" 82 " -shared - volume is shared\n" 83 " -persistent - volume is backed on permanent storage\n" 84 " -removable - volume is on removable media\n" 85 " If the option is true for the named volume, 'yes' is printed\n" 86 " and if the option is false, 'no' is printed. Multiple options\n" 87 " can be specified in which case all of them must be true.\n\n" 88 " If no volume is specified, the volume of the current directory is assumed.\n"); 89 } 90 91