cleanup warnings found with -O2
[btrfs-progs-unstable.git] / btrfsctl.c
blob3710bc6a6dfb8fa5f8974e7b9dfb3ccc2a04179a
1 #ifndef __CHECKER__
2 #include <sys/ioctl.h>
3 #include <sys/mount.h>
4 #include "ioctl.h"
5 #endif
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <fcntl.h>
11 #include <unistd.h>
12 #include <dirent.h>
13 #include "kerncompat.h"
15 #ifdef __CHECKER__
16 #define BLKGETSIZE64 0
17 #define BTRFS_IOC_SNAP_CREATE 0
18 #define BTRFS_IOC_ADD_DISK 0
19 #define BTRFS_VOL_NAME_MAX 255
20 struct btrfs_ioctl_vol_args { char name[BTRFS_VOL_NAME_MAX]; };
21 static inline int ioctl(int fd, int define, void *arg) { return 0; }
22 #endif
24 void print_usage(void)
26 printf("usage: btrfsctl [ -s snapshot_name ] dir\n");
27 exit(1);
30 int main(int ac, char **av)
32 char *fname;
33 int fd;
34 int ret;
35 struct btrfs_ioctl_vol_args args;
36 char *name = NULL;
37 int i;
38 struct stat st;
39 DIR *dirstream;
40 unsigned long command = 0;
42 for (i = 1; i < ac - 1; i++) {
43 if (strcmp(av[i], "-s") == 0) {
44 if (i + 1 >= ac - 1) {
45 fprintf(stderr, "-s requires an arg");
46 print_usage();
48 name = av[i + 1];
49 if (strlen(name) >= BTRFS_VOL_NAME_MAX) {
50 fprintf(stderr, "snapshot name is too long\n");
51 exit(1);
53 command = BTRFS_IOC_SNAP_CREATE;
55 if (strcmp(av[i], "-a") == 0) {
56 if (i + 1 >= ac - 1) {
57 fprintf(stderr, "-a requires an arg");
58 print_usage();
60 name = av[i + 1];
61 if (strlen(name) >= BTRFS_VOL_NAME_MAX) {
62 fprintf(stderr, "device name is too long\n");
63 exit(1);
65 command = BTRFS_IOC_ADD_DISK;
68 if (command == 0) {
69 fprintf(stderr, "no valid commands given\n");
70 exit(1);
72 fname = av[ac - 1];
73 printf("fname is %s\n", fname);
74 ret = stat(fname, &st);
75 if (ret < 0) {
76 perror("stat:");
77 exit(1);
79 if (S_ISDIR(st.st_mode)) {
80 dirstream = opendir(fname);
81 if (!dirstream) {
82 perror("opendir");
83 exit(1);
85 fd = dirfd(dirstream);
86 } else {
87 fd = open(fname, O_RDWR);
88 } if (fd < 0) {
89 perror("open");
90 exit(1);
92 strcpy(args.name, name);
93 ret = ioctl(fd, command, &args);
94 printf("ioctl returns %d\n", ret);
95 return 0;