]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
Enable use of O_EXCL in mkfs, for exclusive 2.6 blockdev access.
authorNathan Scott <nathans@sgi.com>
Fri, 5 Mar 2004 04:26:40 +0000 (04:26 +0000)
committerNathan Scott <nathans@sgi.com>
Fri, 5 Mar 2004 04:26:40 +0000 (04:26 +0000)
include/libxfs.h
libxfs/init.c
mkfs/xfs_mkfs.c

index 641b08e4c406e6c4be0a4e2606167c11f5f14d63..0e5ef4d31f9ee50b383047846e947e07e47bb28e 100644 (file)
@@ -117,7 +117,8 @@ typedef struct {
 #define LIBXFS_EXIT_ON_FAILURE 0x0001  /* exit the program if a call fails */
 #define LIBXFS_ISREADONLY      0x0002  /* disallow all mounted filesystems */
 #define LIBXFS_ISINACTIVE      0x0004  /* allow mounted only if mounted ro */
-#define LIBXFS_DANGEROUSLY     0x0008  /* repair is mounted ro */
+#define LIBXFS_DANGEROUSLY     0x0008  /* repairing a device mounted ro    */
+#define LIBXFS_EXCLUSIVELY     0x0010  /* disallow other accesses (O_EXCL) */
 
 extern char    *progname;
 extern int     libxfs_init (libxfs_init_t *);
index 075775f58167465d988d61204e71068e87c685ab..d8fad03bae41ee0e25a38b46e71fe03120ed675c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of version 2 of the GNU General Public License as
@@ -93,23 +93,26 @@ libxfs_device_to_fd(dev_t device)
  *     open a device and return its device number
  */
 dev_t
-libxfs_device_open(char *path, int creat, int readonly, int setblksize)
+libxfs_device_open(char *path, int creat, int xflags, int setblksize)
 {
-       int             fd;
        dev_t           dev;
-       int             d;
-       struct stat     statb;
+       int             fd, d, flags;
+       int             readonly, excl;
+       struct stat64   statb;
+
+       readonly = (xflags & LIBXFS_ISREADONLY);
+       excl = (xflags & LIBXFS_EXCLUSIVELY) && !creat;
 
-       if ((fd = open(path,
-                       (readonly ? O_RDONLY : O_RDWR) |
-                       (creat ? O_CREAT|O_TRUNC : 0),
-                       0666)) < 0) {
+       flags = (readonly ? O_RDONLY : O_RDWR) | \
+               (creat ? (O_CREAT|O_TRUNC) : 0) | \
+               (excl ? O_EXCL : 0);
+       if ((fd = open(path, flags, 0666)) < 0) {
                fprintf(stderr, _("%s: cannot open %s: %s\n"),
                        progname, path, strerror(errno));
                exit(1);
        }
 
-       if (stat(path, &statb)<0) {
+       if (fstat64(fd, &statb) < 0) {
                fprintf(stderr, _("%s: cannot stat %s: %s\n"),
                        progname, path, strerror(errno));
                exit(1);
@@ -222,8 +225,6 @@ libxfs_init(libxfs_init_t *a)
        char            *rtname;
        char            rtpath[25];
        int             rval = 0;
-       int             readonly;
-       int             inactive;
        int             flags;
 
        dpath[0] = logpath[0] = rtpath[0] = '\0';
@@ -238,8 +239,6 @@ libxfs_init(libxfs_init_t *a)
        (void)getcwd(curdir,MAXPATHLEN);
        needcd = 0;
        fd = -1;
-       readonly = (a->isreadonly & LIBXFS_ISREADONLY);
-       inactive = (a->isreadonly & LIBXFS_ISINACTIVE);
        flags = a->isreadonly;
 
        if (a->volname) {
@@ -325,14 +324,14 @@ voldone:
                if (dname[0] != '/' && needcd)
                        chdir(curdir);
                if (a->disfile) {
-                       a->ddev= libxfs_device_open(dname, a->dcreat, readonly,
+                       a->ddev= libxfs_device_open(dname, a->dcreat, flags,
                                                    a->setblksize);
                        a->dfd = libxfs_device_to_fd(a->ddev);
                } else {
                        if (!check_open(dname, flags, &rawfile, &blockfile))
                                goto done;
                        a->ddev = libxfs_device_open(rawfile,
-                                       a->dcreat, readonly, a->setblksize);
+                                       a->dcreat, flags, a->setblksize);
                        a->dfd = libxfs_device_to_fd(a->ddev);
                        platform_findsizes(rawfile, a->dfd,
                                                &a->dsize, &a->dbsize);
@@ -345,13 +344,13 @@ voldone:
                        chdir(curdir);
                if (a->lisfile) {
                        a->logdev = libxfs_device_open(logname,
-                                       a->lcreat, readonly, a->setblksize);
+                                       a->lcreat, flags, a->setblksize);
                        a->logfd = libxfs_device_to_fd(a->logdev);
                } else {
                        if (!check_open(logname, flags, &rawfile, &blockfile))
                                goto done;
                        a->logdev = libxfs_device_open(rawfile,
-                                       a->lcreat, readonly, a->setblksize);
+                                       a->lcreat, flags, a->setblksize);
                        a->logfd = libxfs_device_to_fd(a->logdev);
                        platform_findsizes(rawfile, a->logfd,
                                                &a->logBBsize, &a->lbsize);
@@ -364,13 +363,13 @@ voldone:
                        chdir(curdir);
                if (a->risfile) {
                        a->rtdev = libxfs_device_open(rtname,
-                                       a->rcreat, readonly, a->setblksize);
+                                       a->rcreat, flags, a->setblksize);
                        a->rtfd = libxfs_device_to_fd(a->rtdev);
                } else {
                        if (!check_open(rtname, flags, &rawfile, &blockfile))
                                goto done;
                        a->rtdev = libxfs_device_open(rawfile,
-                                       a->rcreat, readonly, a->setblksize);
+                                       a->rcreat, flags, a->setblksize);
                        a->rtfd = libxfs_device_to_fd(a->rtdev);
                        platform_findsizes(rawfile, a->rtfd,
                                                &a->rtsize, &a->rtbsize);
index 4f9f13ba48258f783f5ae1695cbfba60e795c288..dcf26e4b533fdba45012b3daa0b886abebbac4b5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
  * 
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of version 2 of the GNU General Public License as
@@ -600,6 +600,7 @@ main(
        bzero(&xi, sizeof(xi));
        xi.notvolok = 1;
        xi.setblksize = 1;
+       xi.isreadonly = LIBXFS_EXCLUSIVELY;
 
        while ((c = getopt(argc, argv, "b:d:i:l:L:n:Np:qr:s:CfV")) != EOF) {
                switch (c) {