~ubuntu-branches/ubuntu/lucid/loop-aes-utils/lucid-security

« back to all changes in this revision

Viewing changes to disk-utils/raw.c

  • Committer: Bazaar Package Importer
  • Author(s): Max Vozeler
  • Date: 2008-08-22 11:57:17 UTC
  • mfrom: (8.1.3 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080822115717-v8wfa8pxwlfvyje0
Tags: 2.13.1-4
* patches/losetup_add_option_f.dpatch: 
  - Added to support "find next free loop" in losetup.
    (closes: #495682)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#endif
32
32
#define DEVFS_RAWCTLDEV "/dev/raw/rawctl"
33
33
 
 
34
#define RAW_NR_MINORS 8192
34
35
 
35
36
char *  progname;
36
37
int     do_query = 0;
64
65
        char * block_name;
65
66
        int  err;
66
67
        int  block_major, block_minor;  
67
 
        int  i;
 
68
        int  i, rc;
68
69
 
69
70
        struct stat statbuf;
70
71
        
94
95
        if (do_query_all) {
95
96
                if (optind < argc)
96
97
                        usage(1);
97
 
                for (i=1; i<255; i++)
 
98
                for (i = 1; i < RAW_NR_MINORS; i++)
98
99
                        query(i, 1);
99
100
                exit(0);
100
101
        }
107
108
                usage(1);
108
109
        raw_name = argv[optind++];
109
110
 
 
111
        /*
 
112
         * try to check the device name before stat(), because on systems with
 
113
         * udev the raw0 causes a create udev event for char 162/0, which
 
114
         * causes udev to *remove* /dev/rawctl
 
115
         */
 
116
        rc = sscanf(raw_name, RAWDEVDIR "raw%d", &raw_minor);
 
117
        if (rc == 1 && raw_minor == 0) {
 
118
                fprintf (stderr,
 
119
                        "Device '%s' is control raw dev "
 
120
                        "(use raw<N> where <N> is greater than zero)\n",
 
121
                        raw_name);
 
122
                exit(2);
 
123
        }
 
124
 
110
125
        err = stat(raw_name, &statbuf);
111
126
        if (err) {
112
127
                fprintf (stderr, "Cannot locate raw device '%s' (%s)\n",
115
130
        }
116
131
        
117
132
        if (!S_ISCHR(statbuf.st_mode)) {
118
 
                fprintf (stderr, "raw device '%s' is not a character dev\n",
 
133
                fprintf (stderr, "Raw device '%s' is not a character dev\n",
119
134
                         raw_name);
120
135
                exit(2);
121
136
        }
129
144
 
130
145
        if (do_query)
131
146
                return query(raw_minor, 0);
132
 
        
 
147
 
133
148
        /* 
134
149
         * It's not a query, so we still have some parsing to do.  Have
135
150
         * we been given a block device filename or a major/minor pair? 
193
208
int query(int minor, int quiet)
194
209
{
195
210
        struct raw_config_request rq;
 
211
        static int has_worked = 0;
196
212
        int err;
197
 
        
 
213
 
198
214
        rq.raw_minor = minor;
199
215
        err = ioctl(master_fd, RAW_GETBIND, &rq);
200
216
        if (err < 0) {
201
217
                if (quiet && errno == ENODEV)
202
218
                        return 3;
203
 
                fprintf (stderr, 
 
219
                if (has_worked && errno == EINVAL)
 
220
                        return 0;
 
221
                fprintf (stderr,
204
222
                         "Error querying raw device (%s)\n",
205
223
                         strerror(errno));
206
224
                exit(3);
207
225
        }
 
226
        /* If one query has worked, mark that fact so that we don't
 
227
         * report spurious fatal errors if raw(8) has been built to
 
228
         * support more raw minor numbers than the kernel has. */
 
229
        has_worked = 1;
208
230
        if (quiet && !rq.block_major && !rq.block_minor)
209
231
                return 0;
210
232
        printf (RAWDEVDIR "raw%d:       bound to major %d, minor %d\n",