]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/linux.c
2 * Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
33 #define ustat __kernel_ustat
38 #include <sys/ustat.h>
39 #include <sys/mount.h>
40 #include <sys/ioctl.h>
42 extern char *progname
;
45 # define BLKGETSIZE64 _IOR(0x12,114,sizeof(__uint64_t))
48 # define BLKBSZSET _IOW(0x12,113,sizeof(int))
51 #define PROC_MOUNTED "/proc/mounts"
54 check_ismounted(char *name
, char *block
, struct stat64
*s
, int verbose
)
60 if (stat64(block
, &st
) < 0)
62 if ((st
.st_mode
& S_IFMT
) != S_IFBLK
)
67 if (ustat(s
->st_rdev
, &ust
) >= 0) {
70 _("%s: %s contains a mounted filesystem\n"),
78 check_iswritable(char *name
, char *block
, struct stat64
*s
, int fatal
)
84 char mounts
[MAXPATHLEN
];
86 strcpy(mounts
, access(PROC_MOUNTED
, R_OK
)? PROC_MOUNTED
: MOUNTED
);
87 if ((f
= setmntent(mounts
, "r")) == NULL
) {
88 fprintf(stderr
, _("%s: %s contains a possibly writable, "
89 "mounted filesystem\n"), progname
, name
);
92 while ((mnt
= getmntent(f
)) != NULL
) {
93 if (stat64(mnt
->mnt_fsname
, &mst
) < 0)
95 if ((mst
.st_mode
& S_IFMT
) != S_IFBLK
)
97 if (mst
.st_rdev
== s
->st_rdev
98 && hasmntopt(mnt
, MNTOPT_RO
) != NULL
)
102 fprintf(stderr
, _("%s: %s contains a mounted and writable "
103 "filesystem\n"), progname
, name
);
111 set_blocksize(int fd
, char *path
, int blocksize
)
113 if (ioctl(fd
, BLKBSZSET
, &blocksize
) < 0) {
114 fprintf(stderr
, _("%s: warning - cannot set blocksize "
115 "on block device %s: %s\n"),
116 progname
, path
, strerror(errno
));
123 ioctl(fd
, BLKFLSBUF
, 0);
135 if (stat64(path
, &st
) < 0) {
136 fprintf(stderr
, _("%s: "
137 "cannot stat the device file \"%s\": %s\n"),
138 progname
, path
, strerror(errno
));
141 if ((st
.st_mode
& S_IFMT
) == S_IFREG
)
142 return (__int64_t
)(st
.st_size
>> 9);
144 if ((fd
= open(path
, O_RDONLY
, 0)) < 0) {
145 fprintf(stderr
, _("%s: "
146 "error opening the device special file \"%s\": %s\n"),
147 progname
, path
, strerror(errno
));
151 error
= ioctl(fd
, BLKGETSIZE64
, &size
);
153 /* BLKGETSIZE64 returns size in bytes not 512-byte blocks */
156 /* If BLKGETSIZE64 fails, try BLKGETSIZE */
157 unsigned long tmpsize
;
158 error
= ioctl(fd
, BLKGETSIZE
, &tmpsize
);
160 fprintf(stderr
, _("%s: can't determine device size\n"),
164 ssize
= (__int64_t
)tmpsize
;