|
Packit Service |
360c39 |
#include "clusterautoconfig.h"
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
#include <stdio.h>
|
|
Packit Service |
360c39 |
#include <stdlib.h>
|
|
Packit Service |
360c39 |
#include <string.h>
|
|
Packit Service |
360c39 |
#include <stdint.h>
|
|
Packit Service |
360c39 |
#include <inttypes.h>
|
|
Packit Service |
360c39 |
#include <sys/types.h>
|
|
Packit Service |
360c39 |
#include <sys/stat.h>
|
|
Packit Service |
360c39 |
#include <fcntl.h>
|
|
Packit Service |
360c39 |
#include <unistd.h>
|
|
Packit Service |
360c39 |
#include <errno.h>
|
|
Packit Service |
360c39 |
#include <sys/ioctl.h>
|
|
Packit Service |
360c39 |
#include <linux/types.h>
|
|
Packit Service |
360c39 |
#include <linux/fs.h>
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
#include "libgfs2.h"
|
|
Packit Service |
360c39 |
#include "config.h"
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
#ifndef BLKSSZGET
|
|
Packit Service |
360c39 |
#define BLKSSZGET _IO(0x12,104) /* logical_block_size */
|
|
Packit Service |
360c39 |
#endif
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
#ifndef BLKIOMIN
|
|
Packit Service |
360c39 |
#define BLKIOMIN _IO(0x12,120) /* minimum_io_size */
|
|
Packit Service |
360c39 |
#endif
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
#ifndef BLKIOOPT
|
|
Packit Service |
360c39 |
#define BLKIOOPT _IO(0x12,121) /* optimal_io_size */
|
|
Packit Service |
360c39 |
#endif
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
#ifndef BLKALIGNOFF
|
|
Packit Service |
360c39 |
#define BLKALIGNOFF _IO(0x12,122) /* alignment_offset */
|
|
Packit Service |
360c39 |
#endif
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
#ifndef BLKPBSZGET
|
|
Packit Service |
360c39 |
#define BLKPBSZGET _IO(0x12,123) /* physical_block_size */
|
|
Packit Service |
360c39 |
#endif
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
int lgfs2_get_dev_info(int fd, struct lgfs2_dev_info *i)
|
|
Packit Service |
360c39 |
{
|
|
Packit Service |
360c39 |
int ret;
|
|
Packit Service |
360c39 |
int ro = 0;
|
|
Packit Service |
360c39 |
off_t off;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
memset(i, 0, sizeof(*i));
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
ret = fstat(fd, &i->stat);
|
|
Packit Service |
360c39 |
if (ret < 0)
|
|
Packit Service |
360c39 |
return ret;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
switch (i->stat.st_mode & S_IFMT) {
|
|
Packit Service |
360c39 |
case S_IFREG:
|
|
Packit Service |
360c39 |
i->size = i->stat.st_size;
|
|
Packit Service |
360c39 |
ret = fcntl(fd, F_GETFL, 0);
|
|
Packit Service |
360c39 |
if ((ret & O_ACCMODE) == O_RDONLY)
|
|
Packit Service |
360c39 |
i->readonly = 1;
|
|
Packit Service |
360c39 |
i->io_optimal_size = i->stat.st_blksize;
|
|
Packit Service |
360c39 |
goto size_check;
|
|
Packit Service |
360c39 |
case S_IFBLK:
|
|
Packit Service |
360c39 |
break;
|
|
Packit Service |
360c39 |
default:
|
|
Packit Service |
360c39 |
errno = ENOTBLK;
|
|
Packit Service |
360c39 |
return -1;
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
ioctl(fd, BLKRAGET, &i->ra_pages);
|
|
Packit Service |
360c39 |
ioctl(fd, BLKBSZGET, &i->soft_block_size);
|
|
Packit Service |
360c39 |
ioctl(fd, BLKSSZGET, &i->logical_block_size);
|
|
Packit Service |
360c39 |
ioctl(fd, BLKIOMIN, &i->io_min_size);
|
|
Packit Service |
360c39 |
ioctl(fd, BLKIOOPT, &i->io_optimal_size);
|
|
Packit Service |
360c39 |
ioctl(fd, BLKPBSZGET, &i->physical_block_size);
|
|
Packit Service |
360c39 |
ioctl(fd, BLKALIGNOFF, &i->io_align_offset);
|
|
Packit Service |
360c39 |
ioctl(fd, BLKROGET, &ro);
|
|
Packit Service |
360c39 |
if (ro)
|
|
Packit Service |
360c39 |
i->readonly = 1;
|
|
Packit Service |
360c39 |
off = lseek(fd, 0, SEEK_END);
|
|
Packit Service |
360c39 |
if (off < 0)
|
|
Packit Service |
360c39 |
return -1;
|
|
Packit Service |
360c39 |
i->size = off;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
size_check:
|
|
Packit Service |
360c39 |
if (i->size < (1 << 20)) {
|
|
Packit Service |
360c39 |
errno = ENOSPC;
|
|
Packit Service |
360c39 |
return -1;
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
return 0;
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
/**
|
|
Packit Service |
360c39 |
* fix_device_geometry - round off address and lengths and convert to FS blocks
|
|
Packit Service |
360c39 |
* @sdp: The super block
|
|
Packit Service |
360c39 |
*
|
|
Packit Service |
360c39 |
*/
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
void fix_device_geometry(struct gfs2_sbd *sdp)
|
|
Packit Service |
360c39 |
{
|
|
Packit Service |
360c39 |
struct device *device = &sdp->device;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
device->length = sdp->dinfo.size / sdp->bsize;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
if (cfg_debug) {
|
|
Packit Service |
360c39 |
printf("\nDevice Geometry: (in FS blocks)\n");
|
|
Packit Service |
360c39 |
printf(" length = %"PRIu64"\n", device->length);
|
|
Packit Service |
360c39 |
printf("\nDevice Size: %"PRIu64"\n", sdp->dinfo.size);
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
}
|