{
}
-int
-platform_get_blocksize(int fd, char *path)
-{
- return BBSIZE;
-}
-
void
platform_flush_device(int fd)
{
ioctl(fd, DKIOCSYNCHRONIZECACHE, NULL);
}
-__int64_t
-platform_findsize(char *path)
+void
+platform_findsizes(char *path, int fd, long long *sz, int *bsz)
{
- __int64_t ssize;
__uint64_t size;
struct stat64 st;
- int fd;
- if (stat64(path, &st) < 0) {
+ if (fstat64(fd, &st) < 0) {
fprintf(stderr,
_("%s: cannot stat the device file \"%s\": %s\n"),
progname, path, strerror(errno));
exit(1);
}
- if ((st.st_mode & S_IFMT) == S_IFREG)
- return (__int64_t)(st.st_size >> 9);
-
- if ((fd = open(path, O_RDONLY, 0)) < 0) {
- fprintf(stderr, _("%s: "
- "error opening the device special file \"%s\": %s\n"),
- progname, path, strerror(errno));
- exit(1);
+ if ((st.st_mode & S_IFMT) == S_IFREG) {
+ *sz = (long long)(st.st_size >> 9);
+ *bsz = BBSIZE;
+ return;
}
-
if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size) < 0) {
fprintf(stderr, _("%s: can't determine device size: %s\n"),
progname, strerror(errno));
exit(1);
}
- close(fd);
- ssize = (__int64_t)size;
- return ssize;
+ *sz = (long long)size;
+ *bsz = BBSIZE;
}
int
platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal)
{
- int sts = 0;
- return sts;
+ return 0;
}
void
{
}
-int
-platform_get_blocksize(int fd, char *path)
-{
- return BBSIZE;
-}
-
void
platform_flush_device(int fd)
{
return size;
}
-__int64_t
-platform_findsize(char *path)
+void
+platform_findsizes(char *path, int fd, long long *sz, int *bsz)
{
- int fd;
- struct stat st;
- __int64_t size;
+ struct stat st;
+ __int64_t size;
- /* Test to see if we are dealing with a regular file rather than a
- * block device, if we are just use the size returned by stat64
- */
- if (stat(path, &st) < 0) {
+ if (fstat(fd, &st) < 0) {
fprintf(stderr, _("%s: "
- "cannot stat the device special file \"%s\": %s\n"),
+ "cannot stat the device file \"%s\": %s\n"),
progname, path, strerror(errno));
exit(1);
}
if ((st.st_mode & S_IFMT) == S_IFREG) {
- return (__int64_t)(st.st_size >> 9);
+ *sz = (long long)(st.st_size >> 9);
+ *bsz = BBSIZE;
+ return;
}
- if ((fd = open(path, 0)) < 0) {
- fprintf(stderr, _("%s: "
- "error opening the device special file \"%s\": %s\n"),
- progname, path, strerror(errno));
- exit(1);
- }
-
- size = getdisksize(fd, path);
-
- close(fd);
-
- return size;
+ *sz = (long long) getdisksize(fd, path);
+ *bsz = BBSIZE;
}
a->setblksize);
a->dfd = libxfs_device_to_fd(a->ddev);
} else {
- if(!check_open(dname,flags,&rawfile,&blockfile))
+ if (!check_open(dname, flags, &rawfile, &blockfile))
goto done;
a->ddev = libxfs_device_open(rawfile,
a->dcreat, readonly, a->setblksize);
a->dfd = libxfs_device_to_fd(a->ddev);
- a->dsize = platform_findsize(rawfile);
- a->dbsize = platform_get_blocksize(a->dfd, rawfile);
+ platform_findsizes(rawfile, a->dfd,
+ &a->dsize, &a->dbsize);
}
needcd = 1;
} else
a->lcreat, readonly, a->setblksize);
a->logfd = libxfs_device_to_fd(a->logdev);
} else {
- if(!check_open(logname,flags,&rawfile,&blockfile))
+ if (!check_open(logname, flags, &rawfile, &blockfile))
goto done;
a->logdev = libxfs_device_open(rawfile,
a->lcreat, readonly, a->setblksize);
a->logfd = libxfs_device_to_fd(a->logdev);
- a->logBBsize = platform_findsize(rawfile);
- a->lbsize = platform_get_blocksize(a->logfd, rawfile);
+ platform_findsizes(rawfile, a->logfd,
+ &a->logBBsize, &a->lbsize);
}
needcd = 1;
} else
a->rcreat, readonly, a->setblksize);
a->rtfd = libxfs_device_to_fd(a->rtdev);
} else {
- if(!check_open(rtname,flags,&rawfile,&blockfile))
+ if (!check_open(rtname, flags, &rawfile, &blockfile))
goto done;
a->rtdev = libxfs_device_open(rawfile,
a->rcreat, readonly, a->setblksize);
a->rtfd = libxfs_device_to_fd(a->rtdev);
- a->rtsize = platform_findsize(rawfile);
- a->rtbsize = platform_get_blocksize(a->rtfd, rawfile);
+ platform_findsizes(rawfile, a->rtfd,
+ &a->rtsize, &a->rtbsize);
}
needcd = 1;
} else
struct stat64 *sptr, int verbose);
extern int platform_check_iswritable (char *path, char *block,
struct stat64 *sptr, int fatal);
-extern __int64_t platform_findsize (char *path);
+extern void platform_findsizes (char *path, int fd, long long *sz, int *bsz);
extern void platform_set_blocksize (int fd, char *path, int blocksize);
-extern int platform_get_blocksize (int fd, char *path);
extern void platform_flush_device (int fd);
#endif /* LIBXFS_INIT_H */
return;
}
-__int64_t
-platform_findsize(char *path)
+void
+platform_findsizes(char *path, int fd, long long *sz, int *bsz)
{
struct stat64 st;
- if (stat64(path, &st) < 0) {
+ if (fstat64(fd, &st) < 0) {
fprintf(stderr,
_("%s: cannot stat the device file \"%s\": %s\n"),
progname, path, strerror(errno));
exit(1);
}
- if ((st.st_mode & S_IFMT) == S_IFREG)
- return (__int64_t)(st.st_size >> 9);
-
- return findsize(path);
+ if ((st.st_mode & S_IFMT) == S_IFREG) {
+ *sz = (long long)(st.st_size >> 9);
+ } else {
+ *sz = findsize(path);
+ }
+ *bsz = BBSIZE;
}
}
}
-int
-platform_get_blocksize(int fd, char *path)
-{
- int blocksize;
-
- if (ioctl(fd, BLKSSZGET, &blocksize) < 0) {
- fprintf(stderr, _("%s: warning - cannot get sector size "
- "from block device %s: %s\n"),
- progname, path, strerror(errno));
- blocksize = BBSIZE;
- }
- return blocksize;
-}
-
void
platform_flush_device(int fd)
{
ioctl(fd, BLKFLSBUF, 0);
}
-__int64_t
-platform_findsize(char *path)
+void
+platform_findsizes(char *path, int fd, long long *sz, int *bsz)
{
- int fd;
- int error;
- __int64_t ssize;
- __uint64_t size;
struct stat64 st;
+ __uint64_t size;
+ int error;
- if (stat64(path, &st) < 0) {
+ if (fstat64(fd, &st) < 0) {
fprintf(stderr, _("%s: "
"cannot stat the device file \"%s\": %s\n"),
progname, path, strerror(errno));
exit(1);
}
- if ((st.st_mode & S_IFMT) == S_IFREG)
- return (__int64_t)(st.st_size >> 9);
-
- if ((fd = open(path, O_RDONLY, 0)) < 0) {
- fprintf(stderr, _("%s: "
- "error opening the device special file \"%s\": %s\n"),
- progname, path, strerror(errno));
- exit(1);
+ if ((st.st_mode & S_IFMT) == S_IFREG) {
+ *sz = (long long)(st.st_size >> 9);
+ *bsz = BBSIZE;
+ return;
}
error = ioctl(fd, BLKGETSIZE64, &size);
if (error >= 0) {
/* BLKGETSIZE64 returns size in bytes not 512-byte blocks */
- ssize = size >> 9;
+ *sz = (long long)(size >> 9);
} else {
/* If BLKGETSIZE64 fails, try BLKGETSIZE */
unsigned long tmpsize;
+
error = ioctl(fd, BLKGETSIZE, &tmpsize);
if (error < 0) {
fprintf(stderr, _("%s: can't determine device size\n"),
progname);
exit(1);
}
- ssize = (__int64_t)tmpsize;
+ *sz = (long long)tmpsize;
}
- close(fd);
- return ssize;
+ if (ioctl(fd, BLKSSZGET, bsz) < 0) {
+ fprintf(stderr, _("%s: warning - cannot get sector size "
+ "from block device %s: %s\n"),
+ progname, path, strerror(errno));
+ *bsz = BBSIZE;
+ }
}