177 |
if (! fd) |
if (! fd) |
178 |
return pupa_error (PUPA_ERR_BAD_DEVICE, "cannot open `%s'", map[drive]); |
return pupa_error (PUPA_ERR_BAD_DEVICE, "cannot open `%s'", map[drive]); |
179 |
|
|
180 |
|
if (fstat (fd, &st) < 0 || ! S_ISBLK (st.st_mode)) |
181 |
|
{ |
182 |
|
close (fd); |
183 |
|
goto fail; |
184 |
|
} |
185 |
|
|
186 |
if (ioctl (fd, BLKGETSIZE, &nr)) |
if (ioctl (fd, BLKGETSIZE, &nr)) |
187 |
{ |
{ |
188 |
close (fd); |
close (fd); |
204 |
if (stat (map[drive], &st) < 0) |
if (stat (map[drive], &st) < 0) |
205 |
return pupa_error (PUPA_ERR_BAD_DEVICE, "cannot stat `%s'", map[drive]); |
return pupa_error (PUPA_ERR_BAD_DEVICE, "cannot stat `%s'", map[drive]); |
206 |
|
|
207 |
if (st.st_blocks) |
disk->total_sectors = st.st_size >> PUPA_DISK_SECTOR_BITS; |
|
disk->total_sectors = st.st_blocks; |
|
|
else |
|
|
/* Hmm... Use st_size instead. */ |
|
|
disk->total_sectors = st.st_size >> PUPA_DISK_SECTOR_BITS; |
|
208 |
|
|
209 |
pupa_util_info ("the size of %s is %lu", name, disk->total_sectors); |
pupa_util_info ("the size of %s is %lu", name, disk->total_sectors); |
210 |
|
|