Print this page
PSARC 2008/290 lofi mount
6384817 Need persistent lofi based mounts and direct mount(1m) support for lofi


   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  * lofiadm - administer lofi(7d). Very simple, add and remove file<->device
  28  * associations, and display status. All the ioctls are private between
  29  * lofi and lofiadm, and so are very simple - device information is
  30  * communicated via a minor number.
  31  */
  32 
  33 #pragma ident   "@(#)main.c     1.8     07/12/18 SMI"
  34 
  35 #include <sys/types.h>
  36 #include <sys/param.h>
  37 #include <sys/lofi.h>
  38 #include <sys/stat.h>
  39 #include <netinet/in.h>
  40 #include <stdio.h>
  41 #include <fcntl.h>
  42 #include <locale.h>
  43 #include <string.h>
  44 #include <strings.h>
  45 #include <errno.h>
  46 #include <stdlib.h>
  47 #include <unistd.h>
  48 #include <stropts.h>
  49 #include <libdevinfo.h>
  50 #include <libgen.h>
  51 #include <ctype.h>
  52 #include <dlfcn.h>
  53 #include "utils.h"


 287         (void) strlcpy(li.li_filename, filename, sizeof (li.li_filename));
 288         li.li_minor = minor;
 289         if (ioctl(lfd, LOFI_MAP_FILE_MINOR, &li) == -1) {
 290                 die(gettext("could not map file %s to %s"), filename,
 291                     devicename);
 292         }
 293         wait_until_dev_complete(minor);
 294 }
 295 
 296 /*
 297  * Remove an association. Delete by device name if non-NULL, or by
 298  * filename otherwise.
 299  */
 300 static void
 301 delete_mapping(int lfd, const char *devicename, const char *filename,
 302     boolean_t force)
 303 {
 304         struct lofi_ioctl li;
 305 
 306         li.li_force = force;


 307         if (devicename == NULL) {
 308                 /* delete by filename */
 309                 (void) strlcpy(li.li_filename, filename,
 310                     sizeof (li.li_filename));
 311                 li.li_minor = 0;
 312                 if (ioctl(lfd, LOFI_UNMAP_FILE, &li) == -1) {
 313                         die(gettext("could not unmap file %s"), filename);
 314                 }
 315                 return;
 316         }
 317         /* delete by device */
 318 
 319         li.li_minor = name_to_minor(devicename);
 320         if (li.li_minor == 0) {
 321                 die(gettext("malformed device name %s\n"), devicename);
 322         }
 323         if (ioctl(lfd, LOFI_UNMAP_FILE_MINOR, &li) == -1) {
 324                 die(gettext("could not unmap device %s"), devicename);
 325         }
 326 }




   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  * lofiadm - administer lofi(7d). Very simple, add and remove file<->device
  28  * associations, and display status. All the ioctls are private between
  29  * lofi and lofiadm, and so are very simple - device information is
  30  * communicated via a minor number.
  31  */
  32 
  33 #pragma ident   "@(#)main.c     1.9     08/05/07 SMI"
  34 
  35 #include <sys/types.h>
  36 #include <sys/param.h>
  37 #include <sys/lofi.h>
  38 #include <sys/stat.h>
  39 #include <netinet/in.h>
  40 #include <stdio.h>
  41 #include <fcntl.h>
  42 #include <locale.h>
  43 #include <string.h>
  44 #include <strings.h>
  45 #include <errno.h>
  46 #include <stdlib.h>
  47 #include <unistd.h>
  48 #include <stropts.h>
  49 #include <libdevinfo.h>
  50 #include <libgen.h>
  51 #include <ctype.h>
  52 #include <dlfcn.h>
  53 #include "utils.h"


 287         (void) strlcpy(li.li_filename, filename, sizeof (li.li_filename));
 288         li.li_minor = minor;
 289         if (ioctl(lfd, LOFI_MAP_FILE_MINOR, &li) == -1) {
 290                 die(gettext("could not map file %s to %s"), filename,
 291                     devicename);
 292         }
 293         wait_until_dev_complete(minor);
 294 }
 295 
 296 /*
 297  * Remove an association. Delete by device name if non-NULL, or by
 298  * filename otherwise.
 299  */
 300 static void
 301 delete_mapping(int lfd, const char *devicename, const char *filename,
 302     boolean_t force)
 303 {
 304         struct lofi_ioctl li;
 305 
 306         li.li_force = force;
 307         li.li_cleanup = 0;
 308 
 309         if (devicename == NULL) {
 310                 /* delete by filename */
 311                 (void) strlcpy(li.li_filename, filename,
 312                     sizeof (li.li_filename));
 313                 li.li_minor = 0;
 314                 if (ioctl(lfd, LOFI_UNMAP_FILE, &li) == -1) {
 315                         die(gettext("could not unmap file %s"), filename);
 316                 }
 317                 return;
 318         }
 319         /* delete by device */
 320 
 321         li.li_minor = name_to_minor(devicename);
 322         if (li.li_minor == 0) {
 323                 die(gettext("malformed device name %s\n"), devicename);
 324         }
 325         if (ioctl(lfd, LOFI_UNMAP_FILE_MINOR, &li) == -1) {
 326                 die(gettext("could not unmap device %s"), devicename);
 327         }
 328 }