+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <lafs/lafs.h>
char path[60];
char buf[20];
fstat(fd, &stb);
+ if ((stb.st_mode & S_IFMT) != S_IFBLK)
+ return 512;
sprintf(path, "/sys/dev/block/%d:%d/queue/logical_block_size",
major(stb.st_rdev), minor(stb.st_rdev));
sfd = open(path, O_RDONLY);
* Device block needs 1K and goes once at start and once at end.
* Start location is 1K in unless basic block size is larger
*/
- ioctl(fd, BLKGETSIZE64, &size);
+ if (ioctl(fd, BLKGETSIZE64, &size) < 0)
+ size = lseek64(fd, 0, SEEK_END);
devblk = get_logical_block_size(fd);
if (devblk < LAFS_DEVBLK_SIZE)
devblk = LAFS_DEVBLK_SIZE;
opt_width,
opt_stride,
opt_noatime,
+ opt_regular,
};
char short_options[] = "-b:Vvh";
{"verbose", 0, 0, 'v'},
{"help", 0, 0, 'h'},
{"no-atime-file",0, 0, opt_noatime},
+ {"regular-file", 0, 0, opt_regular},
{0, 0, 0, 0}
};
}
}
-int open_device(char *devname, long long *device_bytes)
+int open_device(char *devname, long long *device_bytes, int regular_file)
{
/* must be able to get an exclusive open on the device and its size
* must be non-trivial
- *
+ * If 'regular_file', then expect a regular file to be used instead.
*/
int fd;
struct stat stb;
- unsigned long long size;
+ unsigned long long size = 0;
fd = open(devname, O_RDWR|O_EXCL);
- if (fd < 0)
+ if (fd < 0 || fstat(fd, &stb) < 0) {
fprintf(stderr, "mkfs.lafs: cannot open device %s: %s\n",
devname, strerror(errno));
- else if (fstat(fd, &stb) < 0 ||
- (stb.st_mode & S_IFMT) != S_IFBLK)
- fprintf(stderr, "mkfs.lafs: %s is not a block device\n",
- devname);
- else if (ioctl(fd, BLKGETSIZE64, &size) != 0)
- fprintf(stderr, "mkfs.lafs: Cannot get size of %s\n",
- devname);
+ exit(2);
+ }
+
+ if (regular_file) {
+ if ((stb.st_mode & S_IFMT) != S_IFREG)
+ fprintf(stderr, "mkfs.lafs: %s is not a regular file\n",
+ devname);
+ else
+ size = stb.st_size;
+ } else {
+ if ((stb.st_mode & S_IFMT) != S_IFBLK)
+ fprintf(stderr, "mkfs.lafs: %s is not a block device\n",
+ devname);
+ else if (ioctl(fd, BLKGETSIZE64, &size) != 0)
+ fprintf(stderr, "mkfs.lafs: Cannot get size of %s\n",
+ devname);
+ }
+ if (size == 0)
+ ;
else if (size < 64*1024)
fprintf(stderr, "mkfs.lafs: %s is too small for a LAFS filesystem\n",
devname);
long long device_bytes;
char *devname = NULL;
int create_atime = 1;
+ int regular_file = 0;
int opt;
int dev_fd;
struct lafs *lafs;
case opt_noatime:
create_atime = 0;
break;
+ case opt_regular:
+ regular_file = 1;
+ break;
case 1:
if (devname == NULL) {
}
/* Validate device */
- dev_fd = open_device(devname, &device_bytes);
+ dev_fd = open_device(devname, &device_bytes, regular_file);
/* Validate parameters */
validate_parameters(&block_bytes, &segment_bytes, &stride_bytes, &width,