Revision 1de1ae0a

b/block/raw-posix.c
136 136
static int cdrom_reopen(BlockDriverState *bs);
137 137
#endif
138 138

  
139
#if defined(__NetBSD__)
140
static int raw_normalize_devicepath(const char **filename)
141
{
142
    static char namebuf[PATH_MAX];
143
    const char *dp, *fname;
144
    struct stat sb;
145

  
146
    fname = *filename;
147
    dp = strrchr(fname, '/');
148
    if (lstat(fname, &sb) < 0) {
149
        fprintf(stderr, "%s: stat failed: %s\n",
150
            fname, strerror(errno));
151
        return -errno;
152
    }
153

  
154
    if (!S_ISBLK(sb.st_mode)) {
155
        return 0;
156
    }
157

  
158
    if (dp == NULL) {
159
        snprintf(namebuf, PATH_MAX, "r%s", fname);
160
    } else {
161
        snprintf(namebuf, PATH_MAX, "%.*s/r%s",
162
            (int)(dp - fname), fname, dp + 1);
163
    }
164
    fprintf(stderr, "%s is a block device", fname);
165
    *filename = namebuf;
166
    fprintf(stderr, ", using %s\n", *filename);
167

  
168
    return 0;
169
}
170
#else
171
static int raw_normalize_devicepath(const char **filename)
172
{
173
    return 0;
174
}
175
#endif
176

  
139 177
static int raw_open_common(BlockDriverState *bs, const char *filename,
140 178
                           int bdrv_flags, int open_flags)
141 179
{
142 180
    BDRVRawState *s = bs->opaque;
143 181
    int fd, ret;
144 182

  
183
    ret = raw_normalize_devicepath(&filename);
184
    if (ret != 0) {
185
        return ret;
186
    }
187

  
145 188
    s->open_flags = open_flags | O_BINARY;
146 189
    s->open_flags &= ~O_ACCMODE;
147 190
    if (bdrv_flags & BDRV_O_RDWR) {

Also available in: Unified diff