1*422f8ec3SStefano Ceccherini /* 2*422f8ec3SStefano Ceccherini * Copyright 2002-2006, Haiku Inc. All rights reserved. 3*422f8ec3SStefano Ceccherini * Distributed under the terms of the MIT License. 4*422f8ec3SStefano Ceccherini * 5*422f8ec3SStefano Ceccherini * Authors: 6*422f8ec3SStefano Ceccherini * Jonas Sundstrom, jonas.sundstrom@kirilla.com 7*422f8ec3SStefano Ceccherini */ 817049c45SAxel Dörfler 9*422f8ec3SStefano Ceccherini 10*422f8ec3SStefano Ceccherini #include <fs_info.h> 11*422f8ec3SStefano Ceccherini 1217049c45SAxel Dörfler #include <stdio.h> 1317049c45SAxel Dörfler #include <string.h> 1417049c45SAxel Dörfler 15*422f8ec3SStefano Ceccherini void Usage(); 1617049c45SAxel Dörfler 17*422f8ec3SStefano Ceccherini int 18*422f8ec3SStefano Ceccherini main(int32 argc, char** argv) 19*422f8ec3SStefano Ceccherini { 20*422f8ec3SStefano Ceccherini dev_t volumeDevice = dev_for_path("."); 21*422f8ec3SStefano Ceccherini uint32 isVolumeFlags = 0; 22*422f8ec3SStefano Ceccherini fs_info volumeInfo; 2317049c45SAxel Dörfler 24*422f8ec3SStefano Ceccherini for (int i = 1; i < argc; i++) { 25*422f8ec3SStefano Ceccherini if (!strcmp(argv[i], "--help")) { 26*422f8ec3SStefano Ceccherini Usage(); 27*422f8ec3SStefano Ceccherini return 0; 2817049c45SAxel Dörfler } 2917049c45SAxel Dörfler 30*422f8ec3SStefano Ceccherini if (argv[i][0] == '-') { 31*422f8ec3SStefano Ceccherini if (! strcmp(argv[i], "-readonly")) 32*422f8ec3SStefano Ceccherini isVolumeFlags |= B_FS_IS_READONLY; 33*422f8ec3SStefano Ceccherini else if (! strcmp(argv[i], "-query")) 34*422f8ec3SStefano Ceccherini isVolumeFlags |= B_FS_HAS_QUERY; 35*422f8ec3SStefano Ceccherini else if (! strcmp(argv[i], "-attribute")) 36*422f8ec3SStefano Ceccherini isVolumeFlags |= B_FS_HAS_ATTR; 37*422f8ec3SStefano Ceccherini else if (! strcmp(argv[i], "-mime")) 38*422f8ec3SStefano Ceccherini isVolumeFlags |= B_FS_HAS_MIME; 39*422f8ec3SStefano Ceccherini else if (! strcmp(argv[i], "-shared")) 40*422f8ec3SStefano Ceccherini isVolumeFlags |= B_FS_IS_SHARED; 41*422f8ec3SStefano Ceccherini else if (! strcmp(argv[i], "-persistent")) 42*422f8ec3SStefano Ceccherini isVolumeFlags |= B_FS_IS_PERSISTENT; 43*422f8ec3SStefano Ceccherini else if (! strcmp(argv[i], "-removable")) 44*422f8ec3SStefano Ceccherini isVolumeFlags |= B_FS_IS_REMOVABLE; 45*422f8ec3SStefano Ceccherini else { 46*422f8ec3SStefano Ceccherini fprintf(stderr, 47*422f8ec3SStefano Ceccherini "%s: option %s is not understood (use --help for help)\n", argv[0], argv[i]); 48*422f8ec3SStefano Ceccherini return -1; 4917049c45SAxel Dörfler } 50*422f8ec3SStefano Ceccherini } else { 51*422f8ec3SStefano Ceccherini volumeDevice = dev_for_path(argv[i]); 5217049c45SAxel Dörfler 53*422f8ec3SStefano Ceccherini if (volumeDevice < 0) { 5417049c45SAxel Dörfler fprintf(stderr, "%s: can't get information about volume: %s\n", argv[0], argv[i]); 55*422f8ec3SStefano Ceccherini return -1; 5617049c45SAxel Dörfler } 5717049c45SAxel Dörfler } 5817049c45SAxel Dörfler } 5917049c45SAxel Dörfler 60*422f8ec3SStefano Ceccherini if (fs_stat_dev(volumeDevice, &volumeInfo) == B_OK) { 61*422f8ec3SStefano Ceccherini if (volumeInfo.flags & isVolumeFlags) 6217049c45SAxel Dörfler printf("yes\n"); 6317049c45SAxel Dörfler else 6417049c45SAxel Dörfler printf("no\n"); 6517049c45SAxel Dörfler 66*422f8ec3SStefano Ceccherini return 0; 67*422f8ec3SStefano Ceccherini } else { 68*422f8ec3SStefano Ceccherini fprintf(stderr, "%s: can't get information about dev_t: %ld\n", argv[0], volumeDevice); 69*422f8ec3SStefano Ceccherini return -1; 7017049c45SAxel Dörfler } 7117049c45SAxel Dörfler } 7217049c45SAxel Dörfler 73*422f8ec3SStefano Ceccherini 74*422f8ec3SStefano Ceccherini void 75*422f8ec3SStefano Ceccherini Usage() 7617049c45SAxel Dörfler { 7717049c45SAxel Dörfler fprintf(stderr, 7817049c45SAxel Dörfler "Usage: isvolume {-OPTION} [volumename]\n" 7917049c45SAxel Dörfler " Where OPTION is one of:\n" 8017049c45SAxel Dörfler " -readonly - volume is read-only\n" 8117049c45SAxel Dörfler " -query - volume supports queries\n" 8217049c45SAxel Dörfler " -attribute - volume supports attributes\n" 8317049c45SAxel Dörfler " -mime - volume supports MIME information\n" 8417049c45SAxel Dörfler " -shared - volume is shared\n" 8517049c45SAxel Dörfler " -persistent - volume is backed on permanent storage\n" 8617049c45SAxel Dörfler " -removable - volume is on removable media\n" 8717049c45SAxel Dörfler " If the option is true for the named volume, 'yes' is printed\n" 8817049c45SAxel Dörfler " and if the option is false, 'no' is printed. Multiple options\n" 8917049c45SAxel Dörfler " can be specified in which case all of them must be true.\n\n" 9017049c45SAxel Dörfler " If no volume is specified, the volume of the current directory is assumed.\n"); 9117049c45SAxel Dörfler } 92