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