main.c (a1b1a2a0aac3d3c0533efa646a9d7a7dca91fc7c) main.c (406fc5100dac8d225a315a6def6be8d628f34e24)
1/*
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

--- 45 unchanged lines hidden (view full) ---

54#include <libgen.h>
55#include <ctype.h>
56#include <dlfcn.h>
57#include <limits.h>
58#include <security/cryptoki.h>
59#include <cryptoutil.h>
60#include <sys/crypto/ioctl.h>
61#include <sys/crypto/ioctladmin.h>
1/*
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

--- 45 unchanged lines hidden (view full) ---

54#include <libgen.h>
55#include <ctype.h>
56#include <dlfcn.h>
57#include <limits.h>
58#include <security/cryptoki.h>
59#include <cryptoutil.h>
60#include <sys/crypto/ioctl.h>
61#include <sys/crypto/ioctladmin.h>
62#include <sys/cmlb.h>
63#include <sys/mkdev.h>
62#include "utils.h"
63#include <LzmaEnc.h>
64
65/* Only need the IV len #defines out of these files, nothing else. */
66#include <aes/aes_impl.h>
67#include <des/des_impl.h>
68#include <blowfish/blowfish_impl.h>
69
70static const char USAGE[] =
64#include "utils.h"
65#include <LzmaEnc.h>
66
67/* Only need the IV len #defines out of these files, nothing else. */
68#include <aes/aes_impl.h>
69#include <des/des_impl.h>
70#include <blowfish/blowfish_impl.h>
71
72static const char USAGE[] =
71 "Usage: %s [-r] -a file [ device ]\n"
73 "Usage: %s [-r] [-l] -a file [ device ]\n"
72 " %s [-r] -c crypto_algorithm -a file [device]\n"
73 " %s [-r] -c crypto_algorithm -k raw_key_file -a file [device]\n"
74 " %s [-r] -c crypto_algorithm -T [token]:[manuf]:[serial]:key "
75 "-a file [device]\n"
76 " %s [-r] -c crypto_algorithm -T [token]:[manuf]:[serial]:key "
77 "-k wrapped_key_file -a file [device]\n"
78 " %s [-r] -c crypto_algorithm -e -a file [device]\n"
79 " %s -d file | device\n"

--- 133 unchanged lines hidden (view full) ---

213};
214
215#define LZMA_UNCOMPRESSED_SIZE 8
216#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + LZMA_UNCOMPRESSED_SIZE)
217
218/*ARGSUSED*/
219static int
220lzma_compress(void *src, size_t srclen, void *dst,
74 " %s [-r] -c crypto_algorithm -a file [device]\n"
75 " %s [-r] -c crypto_algorithm -k raw_key_file -a file [device]\n"
76 " %s [-r] -c crypto_algorithm -T [token]:[manuf]:[serial]:key "
77 "-a file [device]\n"
78 " %s [-r] -c crypto_algorithm -T [token]:[manuf]:[serial]:key "
79 "-k wrapped_key_file -a file [device]\n"
80 " %s [-r] -c crypto_algorithm -e -a file [device]\n"
81 " %s -d file | device\n"

--- 133 unchanged lines hidden (view full) ---

215};
216
217#define LZMA_UNCOMPRESSED_SIZE 8
218#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + LZMA_UNCOMPRESSED_SIZE)
219
220/*ARGSUSED*/
221static int
222lzma_compress(void *src, size_t srclen, void *dst,
221 size_t *dstlen, int level)
223 size_t *dstlen, int level)
222{
223 CLzmaEncProps props;
224 size_t outsize2;
225 size_t outsizeprocessed;
226 size_t outpropssize = LZMA_PROPS_SIZE;
227 uint64_t t = 0;
228 SRes res;
229 Byte *dstp;

--- 45 unchanged lines hidden (view full) ---

275/*
276 * Translate a lofi device name to a minor number. We might be asked
277 * to do this when there is no association (such as when the user specifies
278 * a particular device), so we can only look at the string.
279 */
280static int
281name_to_minor(const char *devicename)
282{
224{
225 CLzmaEncProps props;
226 size_t outsize2;
227 size_t outsizeprocessed;
228 size_t outpropssize = LZMA_PROPS_SIZE;
229 uint64_t t = 0;
230 SRes res;
231 Byte *dstp;

--- 45 unchanged lines hidden (view full) ---

277/*
278 * Translate a lofi device name to a minor number. We might be asked
279 * to do this when there is no association (such as when the user specifies
280 * a particular device), so we can only look at the string.
281 */
282static int
283name_to_minor(const char *devicename)
284{
283 int minor;
285 struct stat st;
284
286
285 if (sscanf(devicename, "/dev/" LOFI_BLOCK_NAME "/%d", &minor) == 1) {
286 return (minor);
287 /*
288 * If devicename does not exist, then devicename contains
289 * the name of the device to be created.
290 * Note we only allow non-labeled devices here.
291 */
292 if (stat(devicename, &st)) {
293 int minor, rv;
294
295 rv = sscanf(devicename, "/dev/" LOFI_BLOCK_NAME "/%d", &minor);
296 if (rv == 1)
297 return (minor);
298 rv = sscanf(devicename, "/dev/" LOFI_CHAR_NAME "/%d", &minor);
299 if (rv == 1)
300 return (minor);
301
302 return (0);
287 }
303 }
288 if (sscanf(devicename, "/dev/" LOFI_CHAR_NAME "/%d", &minor) == 1) {
289 return (minor);
304
305 if (st.st_mode & S_IFCHR || st.st_mode & S_IFBLK) {
306 return (LOFI_MINOR2ID(minor(st.st_rdev)));
290 }
307 }
308
291 return (0);
292}
293
294/*
295 * This might be the first time we've used this minor number. If so,
296 * it might also be that the /dev links are in the process of being created
297 * by devfsadmd (or that they'll be created "soon"). We cannot return
298 * until they're there or the invoker of lofiadm might try to use them
299 * and not find them. This can happen if a shell script is running on
300 * an MP.
301 */
302static int sleeptime = 2; /* number of seconds to sleep between stat's */
303static int maxsleep = 120; /* maximum number of seconds to sleep */
304
305static void
309 return (0);
310}
311
312/*
313 * This might be the first time we've used this minor number. If so,
314 * it might also be that the /dev links are in the process of being created
315 * by devfsadmd (or that they'll be created "soon"). We cannot return
316 * until they're there or the invoker of lofiadm might try to use them
317 * and not find them. This can happen if a shell script is running on
318 * an MP.
319 */
320static int sleeptime = 2; /* number of seconds to sleep between stat's */
321static int maxsleep = 120; /* maximum number of seconds to sleep */
322
323static void
306wait_until_dev_complete(int minor)
324make_blkdevname(struct lofi_ioctl *li, char *path, size_t len)
307{
325{
326 char *r1, *r2;
327 size_t l1;
328
329 if (li->li_devpath[0] == '\0') {
330 if (li->li_labeled)
331 (void) strlcpy(path, "unknown", len);
332 else
333 (void) snprintf(path, len,
334 "/dev/" LOFI_BLOCK_NAME "/%d", li->li_id);
335 return;
336 }
337 (void) strlcpy(path, li->li_devpath, len);
338 r1 = strchr(path, 'r');
339 l1 = r1 - path;
340 r2 = strchr(li->li_devpath, 'r');
341 (void) strlcpy(r1, r2+1, len - l1);
342
343 if (li->li_labeled) {
344 (void) strlcat(path, "p0", len);
345 }
346}
347
348static void
349wait_until_dev_complete(struct lofi_ioctl *li)
350{
308 struct stat64 buf;
309 int cursleep;
310 char blkpath[MAXPATHLEN];
311 char charpath[MAXPATHLEN];
312 di_devlink_handle_t hdl;
313
351 struct stat64 buf;
352 int cursleep;
353 char blkpath[MAXPATHLEN];
354 char charpath[MAXPATHLEN];
355 di_devlink_handle_t hdl;
356
314 (void) snprintf(blkpath, sizeof (blkpath), "/dev/%s/%d",
315 LOFI_BLOCK_NAME, minor);
316 (void) snprintf(charpath, sizeof (charpath), "/dev/%s/%d",
317 LOFI_CHAR_NAME, minor);
357 make_blkdevname(li, blkpath, sizeof (blkpath));
358 (void) strlcpy(charpath, li->li_devpath, sizeof (charpath));
318
359
360 if (li->li_labeled) {
361 (void) strlcat(charpath, "p0", sizeof (charpath));
362 }
363
319 /* Check if links already present */
320 if (stat64(blkpath, &buf) == 0 && stat64(charpath, &buf) == 0)
321 return;
322
323 /* First use di_devlink_init() */
324 if (hdl = di_devlink_init("lofi", DI_MAKE_LINK)) {
325 (void) di_devlink_fini(&hdl);
326 goto out;

--- 20 unchanged lines hidden (view full) ---

347 }
348}
349
350/*
351 * Map the file and return the minor number the driver picked for the file
352 * DO NOT use this function if the filename is actually the device name.
353 */
354static int
364 /* Check if links already present */
365 if (stat64(blkpath, &buf) == 0 && stat64(charpath, &buf) == 0)
366 return;
367
368 /* First use di_devlink_init() */
369 if (hdl = di_devlink_init("lofi", DI_MAKE_LINK)) {
370 (void) di_devlink_fini(&hdl);
371 goto out;

--- 20 unchanged lines hidden (view full) ---

392 }
393}
394
395/*
396 * Map the file and return the minor number the driver picked for the file
397 * DO NOT use this function if the filename is actually the device name.
398 */
399static int
355lofi_map_file(int lfd, struct lofi_ioctl li, const char *filename)
400lofi_map_file(int lfd, struct lofi_ioctl *li, const char *filename)
356{
357 int minor;
358
401{
402 int minor;
403
359 li.li_minor = 0;
360 (void) strlcpy(li.li_filename, filename, sizeof (li.li_filename));
361 minor = ioctl(lfd, LOFI_MAP_FILE, &li);
404 li->li_id = 0;
405 (void) strlcpy(li->li_filename, filename, sizeof (li->li_filename));
406 minor = ioctl(lfd, LOFI_MAP_FILE, li);
362 if (minor == -1) {
363 if (errno == ENOTSUP)
364 warn(gettext("encrypting compressed files is "
365 "unsupported"));
366 die(gettext("could not map file %s"), filename);
367 }
407 if (minor == -1) {
408 if (errno == ENOTSUP)
409 warn(gettext("encrypting compressed files is "
410 "unsupported"));
411 die(gettext("could not map file %s"), filename);
412 }
368 wait_until_dev_complete(minor);
413 wait_until_dev_complete(li);
369 return (minor);
370}
371
372/*
373 * Add a device association. If devicename is NULL, let the driver
374 * pick a device.
375 */
376static void
377add_mapping(int lfd, const char *devicename, const char *filename,
414 return (minor);
415}
416
417/*
418 * Add a device association. If devicename is NULL, let the driver
419 * pick a device.
420 */
421static void
422add_mapping(int lfd, const char *devicename, const char *filename,
378 mech_alias_t *cipher, const char *rkey, size_t rksz, boolean_t rdonly)
423 mech_alias_t *cipher, const char *rkey, size_t rksz, boolean_t rdonly,
424 boolean_t label)
379{
380 struct lofi_ioctl li;
381
425{
426 struct lofi_ioctl li;
427
428 bzero(&li, sizeof (li));
382 li.li_readonly = rdonly;
429 li.li_readonly = rdonly;
430 li.li_labeled = label;
383
384 li.li_crypto_enabled = B_FALSE;
385 if (cipher != NULL) {
386 /* set up encryption for mapped file */
387 li.li_crypto_enabled = B_TRUE;
388 (void) strlcpy(li.li_cipher, cipher->name,
389 sizeof (li.li_cipher));
390 if (rksz > sizeof (li.li_key)) {

--- 13 unchanged lines hidden (view full) ---

404 /* FALLTHROUGH */
405 default:
406 break;
407 }
408 }
409
410 if (devicename == NULL) {
411 int minor;
431
432 li.li_crypto_enabled = B_FALSE;
433 if (cipher != NULL) {
434 /* set up encryption for mapped file */
435 li.li_crypto_enabled = B_TRUE;
436 (void) strlcpy(li.li_cipher, cipher->name,
437 sizeof (li.li_cipher));
438 if (rksz > sizeof (li.li_key)) {

--- 13 unchanged lines hidden (view full) ---

452 /* FALLTHROUGH */
453 default:
454 break;
455 }
456 }
457
458 if (devicename == NULL) {
459 int minor;
460 char path[MAXPATHLEN];
412
413 /* pick one via the driver */
461
462 /* pick one via the driver */
414 minor = lofi_map_file(lfd, li, filename);
415 /* if mapping succeeds, print the one picked */
416 (void) printf("/dev/%s/%d\n", LOFI_BLOCK_NAME, minor);
463 minor = lofi_map_file(lfd, &li, filename);
464 if (minor > 0) {
465 make_blkdevname(&li, path, sizeof (path));
466
467 /* if mapping succeeds, print the one picked */
468 (void) printf("%s\n", path);
469 }
417 return;
418 }
419
420 /* use device we were given */
470 return;
471 }
472
473 /* use device we were given */
421 li.li_minor = name_to_minor(devicename);
422 if (li.li_minor == 0) {
474 li.li_id = name_to_minor(devicename);
475 if (li.li_id == 0) {
423 die(gettext("malformed device name %s\n"), devicename);
424 }
425 (void) strlcpy(li.li_filename, filename, sizeof (li.li_filename));
426
427 /* if device is already in use li.li_minor won't change */
428 if (ioctl(lfd, LOFI_MAP_FILE_MINOR, &li) == -1) {
429 if (errno == ENOTSUP)
430 warn(gettext("encrypting compressed files is "
431 "unsupported"));
432 die(gettext("could not map file %s to %s"), filename,
433 devicename);
434 }
476 die(gettext("malformed device name %s\n"), devicename);
477 }
478 (void) strlcpy(li.li_filename, filename, sizeof (li.li_filename));
479
480 /* if device is already in use li.li_minor won't change */
481 if (ioctl(lfd, LOFI_MAP_FILE_MINOR, &li) == -1) {
482 if (errno == ENOTSUP)
483 warn(gettext("encrypting compressed files is "
484 "unsupported"));
485 die(gettext("could not map file %s to %s"), filename,
486 devicename);
487 }
435 wait_until_dev_complete(li.li_minor);
488 wait_until_dev_complete(&li);
436}
437
438/*
439 * Remove an association. Delete by device name if non-NULL, or by
440 * filename otherwise.
441 */
442static void
443delete_mapping(int lfd, const char *devicename, const char *filename,
444 boolean_t force)
445{
446 struct lofi_ioctl li;
447
448 li.li_force = force;
449 li.li_cleanup = B_FALSE;
450
451 if (devicename == NULL) {
452 /* delete by filename */
453 (void) strlcpy(li.li_filename, filename,
454 sizeof (li.li_filename));
489}
490
491/*
492 * Remove an association. Delete by device name if non-NULL, or by
493 * filename otherwise.
494 */
495static void
496delete_mapping(int lfd, const char *devicename, const char *filename,
497 boolean_t force)
498{
499 struct lofi_ioctl li;
500
501 li.li_force = force;
502 li.li_cleanup = B_FALSE;
503
504 if (devicename == NULL) {
505 /* delete by filename */
506 (void) strlcpy(li.li_filename, filename,
507 sizeof (li.li_filename));
455 li.li_minor = 0;
508 li.li_id = 0;
456 if (ioctl(lfd, LOFI_UNMAP_FILE, &li) == -1) {
457 die(gettext("could not unmap file %s"), filename);
458 }
459 return;
460 }
461
462 /* delete by device */
509 if (ioctl(lfd, LOFI_UNMAP_FILE, &li) == -1) {
510 die(gettext("could not unmap file %s"), filename);
511 }
512 return;
513 }
514
515 /* delete by device */
463 li.li_minor = name_to_minor(devicename);
464 if (li.li_minor == 0) {
516 li.li_id = name_to_minor(devicename);
517 if (li.li_id == 0) {
465 die(gettext("malformed device name %s\n"), devicename);
466 }
467 if (ioctl(lfd, LOFI_UNMAP_FILE_MINOR, &li) == -1) {
468 die(gettext("could not unmap device %s"), devicename);
469 }
470}
471
472/*
473 * Show filename given devicename, or devicename given filename.
474 */
475static void
476print_one_mapping(int lfd, const char *devicename, const char *filename)
477{
478 struct lofi_ioctl li;
518 die(gettext("malformed device name %s\n"), devicename);
519 }
520 if (ioctl(lfd, LOFI_UNMAP_FILE_MINOR, &li) == -1) {
521 die(gettext("could not unmap device %s"), devicename);
522 }
523}
524
525/*
526 * Show filename given devicename, or devicename given filename.
527 */
528static void
529print_one_mapping(int lfd, const char *devicename, const char *filename)
530{
531 struct lofi_ioctl li;
532 char blkpath[MAXPATHLEN];
479
480 if (devicename == NULL) {
481 /* given filename, print devicename */
533
534 if (devicename == NULL) {
535 /* given filename, print devicename */
482 li.li_minor = 0;
536 li.li_id = 0;
483 (void) strlcpy(li.li_filename, filename,
484 sizeof (li.li_filename));
485 if (ioctl(lfd, LOFI_GET_MINOR, &li) == -1) {
486 die(gettext("could not find device for %s"), filename);
487 }
537 (void) strlcpy(li.li_filename, filename,
538 sizeof (li.li_filename));
539 if (ioctl(lfd, LOFI_GET_MINOR, &li) == -1) {
540 die(gettext("could not find device for %s"), filename);
541 }
488 (void) printf("/dev/%s/%d\n", LOFI_BLOCK_NAME, li.li_minor);
542 make_blkdevname(&li, blkpath, sizeof (blkpath));
543 (void) printf("%s\n", blkpath);
489 return;
490 }
491
492 /* given devicename, print filename */
544 return;
545 }
546
547 /* given devicename, print filename */
493 li.li_minor = name_to_minor(devicename);
494 if (li.li_minor == 0) {
548 li.li_id = name_to_minor(devicename);
549 if (li.li_id == 0) {
495 die(gettext("malformed device name %s\n"), devicename);
496 }
497 if (ioctl(lfd, LOFI_GET_FILENAME, &li) == -1) {
498 die(gettext("could not find filename for %s"), devicename);
499 }
500 (void) printf("%s\n", li.li_filename);
501}
502

--- 4 unchanged lines hidden (view full) ---

507print_mappings(int fd)
508{
509 struct lofi_ioctl li;
510 int minor;
511 int maxminor;
512 char path[MAXPATHLEN];
513 char options[MAXPATHLEN] = { 0 };
514
550 die(gettext("malformed device name %s\n"), devicename);
551 }
552 if (ioctl(lfd, LOFI_GET_FILENAME, &li) == -1) {
553 die(gettext("could not find filename for %s"), devicename);
554 }
555 (void) printf("%s\n", li.li_filename);
556}
557

--- 4 unchanged lines hidden (view full) ---

562print_mappings(int fd)
563{
564 struct lofi_ioctl li;
565 int minor;
566 int maxminor;
567 char path[MAXPATHLEN];
568 char options[MAXPATHLEN] = { 0 };
569
515 li.li_minor = 0;
570 li.li_id = 0;
516 if (ioctl(fd, LOFI_GET_MAXMINOR, &li) == -1) {
517 die("ioctl");
518 }
571 if (ioctl(fd, LOFI_GET_MAXMINOR, &li) == -1) {
572 die("ioctl");
573 }
519 maxminor = li.li_minor;
574 maxminor = li.li_id;
520
521 (void) printf(FORMAT, gettext("Block Device"), gettext("File"),
522 gettext("Options"));
523 for (minor = 1; minor <= maxminor; minor++) {
575
576 (void) printf(FORMAT, gettext("Block Device"), gettext("File"),
577 gettext("Options"));
578 for (minor = 1; minor <= maxminor; minor++) {
524 li.li_minor = minor;
579 li.li_id = minor;
525 if (ioctl(fd, LOFI_GET_FILENAME, &li) == -1) {
526 if (errno == ENXIO)
527 continue;
528 warn("ioctl");
529 break;
530 }
580 if (ioctl(fd, LOFI_GET_FILENAME, &li) == -1) {
581 if (errno == ENXIO)
582 continue;
583 warn("ioctl");
584 break;
585 }
531 (void) snprintf(path, sizeof (path), "/dev/%s/%d",
532 LOFI_BLOCK_NAME, minor);
586 make_blkdevname(&li, path, sizeof (path));
533
534 options[0] = '\0';
535
536 /*
537 * Encrypted lofi and compressed lofi are mutually exclusive.
538 */
539 if (li.li_crypto_enabled)
540 (void) snprintf(options, sizeof (options),
541 gettext("Encrypted"));
542 else if (li.li_algorithm[0] != '\0')
543 (void) snprintf(options, sizeof (options),
544 gettext("Compressed(%s)"), li.li_algorithm);
545 if (li.li_readonly) {
546 if (strlen(options) != 0) {
587
588 options[0] = '\0';
589
590 /*
591 * Encrypted lofi and compressed lofi are mutually exclusive.
592 */
593 if (li.li_crypto_enabled)
594 (void) snprintf(options, sizeof (options),
595 gettext("Encrypted"));
596 else if (li.li_algorithm[0] != '\0')
597 (void) snprintf(options, sizeof (options),
598 gettext("Compressed(%s)"), li.li_algorithm);
599 if (li.li_readonly) {
600 if (strlen(options) != 0) {
547 (void) strlcat(options, ",", sizeof (options));
548 (void) strlcat(options, "Readonly",
601 (void) strlcat(options, ",Readonly",
549 sizeof (options));
550 } else {
551 (void) snprintf(options, sizeof (options),
552 gettext("Readonly"));
553 }
554 }
602 sizeof (options));
603 } else {
604 (void) snprintf(options, sizeof (options),
605 gettext("Readonly"));
606 }
607 }
608 if (li.li_labeled) {
609 if (strlen(options) != 0) {
610 (void) strlcat(options, ",Labeled",
611 sizeof (options));
612 } else {
613 (void) snprintf(options, sizeof (options),
614 gettext("Labeled"));
615 }
616 }
555 if (strlen(options) == 0)
556 (void) snprintf(options, sizeof (options), "-");
557
558 (void) printf(FORMAT, path, li.li_filename, options);
559 }
560}
561
562/*

--- 736 unchanged lines hidden (view full) ---

1299 int uncompfd = -1;
1300 ssize_t rbytes;
1301
1302 /*
1303 * Disallow uncompressing the file if it is
1304 * already mapped.
1305 */
1306 li.li_crypto_enabled = B_FALSE;
617 if (strlen(options) == 0)
618 (void) snprintf(options, sizeof (options), "-");
619
620 (void) printf(FORMAT, path, li.li_filename, options);
621 }
622}
623
624/*

--- 736 unchanged lines hidden (view full) ---

1361 int uncompfd = -1;
1362 ssize_t rbytes;
1363
1364 /*
1365 * Disallow uncompressing the file if it is
1366 * already mapped.
1367 */
1368 li.li_crypto_enabled = B_FALSE;
1307 li.li_minor = 0;
1369 li.li_id = 0;
1308 (void) strlcpy(li.li_filename, filename, sizeof (li.li_filename));
1309 if (ioctl(lfd, LOFI_GET_MINOR, &li) != -1)
1310 die(gettext("%s must be unmapped before uncompressing"),
1311 filename);
1312
1313 /* Zero length files don't need to be uncompressed */
1314 if (stat64(filename, &statbuf) == -1)
1315 die(gettext("stat: %s"), filename);
1316 if (statbuf.st_size == 0)
1317 return;
1318
1370 (void) strlcpy(li.li_filename, filename, sizeof (li.li_filename));
1371 if (ioctl(lfd, LOFI_GET_MINOR, &li) != -1)
1372 die(gettext("%s must be unmapped before uncompressing"),
1373 filename);
1374
1375 /* Zero length files don't need to be uncompressed */
1376 if (stat64(filename, &statbuf) == -1)
1377 die(gettext("stat: %s"), filename);
1378 if (statbuf.st_size == 0)
1379 return;
1380
1319 minor = lofi_map_file(lfd, li, filename);
1381 minor = lofi_map_file(lfd, &li, filename);
1320 (void) snprintf(devicename, sizeof (devicename), "/dev/%s/%d",
1321 LOFI_BLOCK_NAME, minor);
1322
1323 /* If the file isn't compressed, we just return */
1324 if ((ioctl(lfd, LOFI_CHECK_COMPRESSED, &li) == -1) ||
1325 (li.li_algorithm[0] == '\0')) {
1326 delete_mapping(lfd, devicename, filename, B_TRUE);
1327 die("%s is not compressed\n", filename);

--- 95 unchanged lines hidden (view full) ---

1423 int tfd = -1;
1424 ssize_t rbytes, wbytes, lastread;
1425 int i, type;
1426
1427 /*
1428 * Disallow compressing the file if it is
1429 * already mapped
1430 */
1382 (void) snprintf(devicename, sizeof (devicename), "/dev/%s/%d",
1383 LOFI_BLOCK_NAME, minor);
1384
1385 /* If the file isn't compressed, we just return */
1386 if ((ioctl(lfd, LOFI_CHECK_COMPRESSED, &li) == -1) ||
1387 (li.li_algorithm[0] == '\0')) {
1388 delete_mapping(lfd, devicename, filename, B_TRUE);
1389 die("%s is not compressed\n", filename);

--- 95 unchanged lines hidden (view full) ---

1485 int tfd = -1;
1486 ssize_t rbytes, wbytes, lastread;
1487 int i, type;
1488
1489 /*
1490 * Disallow compressing the file if it is
1491 * already mapped
1492 */
1431 lic.li_minor = 0;
1493 lic.li_id = 0;
1432 (void) strlcpy(lic.li_filename, filename, sizeof (lic.li_filename));
1433 if (ioctl(*lfd, LOFI_GET_MINOR, &lic) != -1)
1434 die(gettext("%s must be unmapped before compressing"),
1435 filename);
1436
1437 /*
1438 * Close the control device so other operations
1439 * can use it

--- 400 unchanged lines hidden (view full) ---

1840{
1841 int lfd;
1842 int c;
1843 const char *devicename = NULL;
1844 const char *filename = NULL;
1845 const char *algname = COMPRESS_ALGORITHM;
1846 int openflag;
1847 int minor;
1494 (void) strlcpy(lic.li_filename, filename, sizeof (lic.li_filename));
1495 if (ioctl(*lfd, LOFI_GET_MINOR, &lic) != -1)
1496 die(gettext("%s must be unmapped before compressing"),
1497 filename);
1498
1499 /*
1500 * Close the control device so other operations
1501 * can use it

--- 400 unchanged lines hidden (view full) ---

1902{
1903 int lfd;
1904 int c;
1905 const char *devicename = NULL;
1906 const char *filename = NULL;
1907 const char *algname = COMPRESS_ALGORITHM;
1908 int openflag;
1909 int minor;
1848 int compress_index;
1910 int compress_index;
1849 uint32_t segsize = SEGSIZE;
1850 static char *lofictl = "/dev/" LOFI_CTL_NAME;
1851 boolean_t force = B_FALSE;
1852 const char *pname;
1853 boolean_t errflag = B_FALSE;
1854 boolean_t addflag = B_FALSE;
1911 uint32_t segsize = SEGSIZE;
1912 static char *lofictl = "/dev/" LOFI_CTL_NAME;
1913 boolean_t force = B_FALSE;
1914 const char *pname;
1915 boolean_t errflag = B_FALSE;
1916 boolean_t addflag = B_FALSE;
1917 boolean_t labelflag = B_FALSE;
1855 boolean_t rdflag = B_FALSE;
1856 boolean_t deleteflag = B_FALSE;
1857 boolean_t ephflag = B_FALSE;
1858 boolean_t compressflag = B_FALSE;
1859 boolean_t uncompressflag = B_FALSE;
1860 /* the next two work together for -c, -k, -T, -e options only */
1861 boolean_t need_crypto = B_FALSE; /* if any -c, -k, -T, -e */
1862 boolean_t cipher_only = B_TRUE; /* if -c only */

--- 4 unchanged lines hidden (view full) ---

1867 size_t rksz = 0;
1868 char realfilename[MAXPATHLEN];
1869
1870 pname = getpname(argv[0]);
1871
1872 (void) setlocale(LC_ALL, "");
1873 (void) textdomain(TEXT_DOMAIN);
1874
1918 boolean_t rdflag = B_FALSE;
1919 boolean_t deleteflag = B_FALSE;
1920 boolean_t ephflag = B_FALSE;
1921 boolean_t compressflag = B_FALSE;
1922 boolean_t uncompressflag = B_FALSE;
1923 /* the next two work together for -c, -k, -T, -e options only */
1924 boolean_t need_crypto = B_FALSE; /* if any -c, -k, -T, -e */
1925 boolean_t cipher_only = B_TRUE; /* if -c only */

--- 4 unchanged lines hidden (view full) ---

1930 size_t rksz = 0;
1931 char realfilename[MAXPATHLEN];
1932
1933 pname = getpname(argv[0]);
1934
1935 (void) setlocale(LC_ALL, "");
1936 (void) textdomain(TEXT_DOMAIN);
1937
1875 while ((c = getopt(argc, argv, "a:c:Cd:efk:rs:T:U")) != EOF) {
1938 while ((c = getopt(argc, argv, "a:b:c:Cd:efk:lrRs:T:U")) != EOF) {
1876 switch (c) {
1877 case 'a':
1878 addflag = B_TRUE;
1879 if ((filename = realpath(optarg, realfilename)) == NULL)
1880 die("%s", optarg);
1881 if (((argc - optind) > 0) && (*argv[optind] != '-')) {
1882 /* optional device */
1883 devicename = argv[optind];

--- 38 unchanged lines hidden (view full) ---

1922 case 'f':
1923 force = B_TRUE;
1924 break;
1925 case 'k':
1926 keyfile = optarg;
1927 need_crypto = B_TRUE;
1928 cipher_only = B_FALSE; /* need to unset cipher_only */
1929 break;
1939 switch (c) {
1940 case 'a':
1941 addflag = B_TRUE;
1942 if ((filename = realpath(optarg, realfilename)) == NULL)
1943 die("%s", optarg);
1944 if (((argc - optind) > 0) && (*argv[optind] != '-')) {
1945 /* optional device */
1946 devicename = argv[optind];

--- 38 unchanged lines hidden (view full) ---

1985 case 'f':
1986 force = B_TRUE;
1987 break;
1988 case 'k':
1989 keyfile = optarg;
1990 need_crypto = B_TRUE;
1991 cipher_only = B_FALSE; /* need to unset cipher_only */
1992 break;
1993 case 'l':
1994 labelflag = B_TRUE;
1995 break;
1930 case 'r':
1931 rdflag = B_TRUE;
1932 break;
1933 case 's':
1934 segsize = convert_to_num(optarg);
1935 if (segsize < DEV_BSIZE || !ISP2(segsize))
1936 die(gettext("segment size %s is invalid "
1937 "or not a multiple of minimum block "

--- 17 unchanged lines hidden (view full) ---

1955 errflag = B_TRUE;
1956 break;
1957 }
1958 }
1959
1960 /* Check for mutually exclusive combinations of options */
1961 if (errflag ||
1962 (addflag && deleteflag) ||
1996 case 'r':
1997 rdflag = B_TRUE;
1998 break;
1999 case 's':
2000 segsize = convert_to_num(optarg);
2001 if (segsize < DEV_BSIZE || !ISP2(segsize))
2002 die(gettext("segment size %s is invalid "
2003 "or not a multiple of minimum block "

--- 17 unchanged lines hidden (view full) ---

2021 errflag = B_TRUE;
2022 break;
2023 }
2024 }
2025
2026 /* Check for mutually exclusive combinations of options */
2027 if (errflag ||
2028 (addflag && deleteflag) ||
2029 (labelflag && !addflag) ||
1963 (rdflag && !addflag) ||
1964 (!addflag && need_crypto) ||
2030 (rdflag && !addflag) ||
2031 (!addflag && need_crypto) ||
1965 ((compressflag || uncompressflag) && (addflag || deleteflag)))
2032 (need_crypto && labelflag) ||
2033 ((compressflag || uncompressflag) &&
2034 (labelflag || addflag || deleteflag)))
1966 usage(pname);
1967
1968 /* ephemeral key, and key from either file or token are incompatible */
1969 if (ephflag && (keyfile != NULL || token != NULL)) {
1970 die(gettext("ephemeral key cannot be used with keyfile"
1971 " or token key\n"));
1972 }
1973

--- 100 unchanged lines hidden (view full) ---

2074 end_crypto(sess);
2075 }
2076
2077 /*
2078 * Now to the real work.
2079 */
2080 if (addflag)
2081 add_mapping(lfd, devicename, filename, cipher, rkey, rksz,
2035 usage(pname);
2036
2037 /* ephemeral key, and key from either file or token are incompatible */
2038 if (ephflag && (keyfile != NULL || token != NULL)) {
2039 die(gettext("ephemeral key cannot be used with keyfile"
2040 " or token key\n"));
2041 }
2042

--- 100 unchanged lines hidden (view full) ---

2143 end_crypto(sess);
2144 }
2145
2146 /*
2147 * Now to the real work.
2148 */
2149 if (addflag)
2150 add_mapping(lfd, devicename, filename, cipher, rkey, rksz,
2082 rdflag);
2151 rdflag, labelflag);
2083 else if (compressflag)
2084 lofi_compress(&lfd, filename, compress_index, segsize);
2085 else if (uncompressflag)
2086 lofi_uncompress(lfd, filename);
2087 else if (deleteflag)
2088 delete_mapping(lfd, devicename, filename, force);
2089 else if (filename || devicename)
2090 print_one_mapping(lfd, devicename, filename);
2091 else
2092 print_mappings(lfd);
2093
2094 if (lfd != -1)
2095 (void) close(lfd);
2096 closelib();
2097 return (E_SUCCESS);
2098}
2152 else if (compressflag)
2153 lofi_compress(&lfd, filename, compress_index, segsize);
2154 else if (uncompressflag)
2155 lofi_uncompress(lfd, filename);
2156 else if (deleteflag)
2157 delete_mapping(lfd, devicename, filename, force);
2158 else if (filename || devicename)
2159 print_one_mapping(lfd, devicename, filename);
2160 else
2161 print_mappings(lfd);
2162
2163 if (lfd != -1)
2164 (void) close(lfd);
2165 closelib();
2166 return (E_SUCCESS);
2167}