2 * Low-level libblkid probing API
4 * Copyright (C) 2008-2009 Karel Zak <kzak@redhat.com>
6 * This file may be redistributed under the terms of the
7 * GNU Lesser General Public License.
12 * @title: Low-level probing
13 * @short_description: low-level prober initialization
15 * The low-level probing routines always and directly read information from
16 * the selected (see blkid_probe_set_device()) device.
18 * The probing routines are grouped together into separate chains. Currently,
19 * the librray provides superblocks, partitions and topology chains.
21 * The probing routines is possible to filter (enable/disable) by type (e.g.
22 * fstype "vfat" or partype "gpt") or by usage flags (e.g. BLKID_USAGE_RAID).
23 * These filters are per-chain. Note that always when you touch the chain
24 * filter the current probing position is reseted and probing starts from
25 * scratch. It means that the chain filter should not be modified during
26 * probing, for example in loop where you call blkid_do_probe().
28 * For more details see the chain specific documentation.
30 * The low-level API provides two ways how access to probing results.
32 * 1. The NAME=value (tag) interface. This interface is older and returns all data
33 * as strings. This interface is generic for all chains.
35 * 2. The binary interfaces. These interfaces return data in the native formats.
36 * The interface is always specific to the probing chain.
41 * SECTION: lowprobe-tags
42 * @title: Low-level tags
43 * @short_description: generic NAME=value interface.
45 * The probing routines inside the chain are mutually exclusive by default --
46 * only few probing routines are marked as "tolerant". The "tolerant" probing
47 * routines are used for filesystem which can share the same device with any
48 * other filesystem. The blkid_do_safeprobe() checks for the "tolerant" flag.
50 * The SUPERBLOCKS chain is enabled by default. The all others chains is
51 * necessary to enable by blkid_probe_enable_'CHAINNAME'(). See chains specific
54 * The blkid_do_probe() function returns a result from only one probing
55 * routine, and the next call from the next probing routine. It means you need
56 * to call the function in loop, for example:
60 * while((blkid_do_probe(pr) == 0)
65 * The blkid_do_safeprobe() is the same as blkid_do_probe(), but returns only
66 * first probing result for every enabled chain. This function checks for
67 * ambivalent results (e.g. more "intolerant" filesystems superblocks on the
70 * The probing result is set of NAME=value pairs (the NAME is always unique).
79 #include <sys/types.h>
80 #ifdef HAVE_SYS_STAT_H
83 #ifdef HAVE_SYS_MKDEV_H
84 #include <sys/mkdev.h>
93 # ifdef HAVE_UUID_UUID_H
94 # include <uuid/uuid.h>
104 extern const struct blkid_chaindrv superblocks_drv
;
105 extern const struct blkid_chaindrv topology_drv
;
106 extern const struct blkid_chaindrv partitions_drv
;
109 * All supported chains
111 static const struct blkid_chaindrv
*chains_drvs
[] = {
112 [BLKID_CHAIN_SUBLKS
] = &superblocks_drv
,
113 [BLKID_CHAIN_TOPLGY
] = &topology_drv
,
114 [BLKID_CHAIN_PARTS
] = &partitions_drv
117 static void blkid_probe_reset_vals(blkid_probe pr
);
122 * Returns: a pointer to the newly allocated probe struct.
124 blkid_probe
blkid_new_probe(void)
130 pr
= calloc(1, sizeof(struct blkid_struct_probe
));
134 /* initialize chains */
135 for (i
= 0; i
< BLKID_NCHAINS
; i
++) {
136 pr
->chains
[i
].driver
= chains_drvs
[i
];
137 pr
->chains
[i
].flags
= chains_drvs
[i
]->dflt_flags
;
138 pr
->chains
[i
].enabled
= chains_drvs
[i
]->dflt_enabled
;
144 * blkid_new_probe_from_filename:
145 * @filename: device or regular file
147 * This function is same as call open(filename), blkid_new_probe() and
148 * blkid_probe_set_device(pr, fd, 0, 0).
150 * The @filename is closed by blkid_free_probe() or by the
151 * blkid_probe_set_device() call.
153 * Returns: a pointer to the newly allocated probe struct or NULL in case of
156 blkid_probe
blkid_new_probe_from_filename(const char *filename
)
159 blkid_probe pr
= NULL
;
164 fd
= open(filename
, O_RDONLY
);
168 pr
= blkid_new_probe();
172 if (blkid_probe_set_device(pr
, fd
, 0, 0))
175 pr
->flags
|= BLKID_PRIVATE_FD
;
180 blkid_free_probe(pr
);
188 * Deallocates the probe struct, buffers and all allocated
189 * data that are associated with this probing control struct.
191 void blkid_free_probe(blkid_probe pr
)
198 for (i
= 0; i
< BLKID_NCHAINS
; i
++) {
199 struct blkid_chain
*ch
= &pr
->chains
[i
];
201 if (ch
->driver
->free_data
)
202 ch
->driver
->free_data(pr
, ch
->data
);
208 if ((pr
->flags
& BLKID_PRIVATE_FD
) && pr
->fd
>= 0)
213 static void blkid_probe_reset_buffer(blkid_probe pr
)
215 DBG(DEBUG_LOWPROBE
, printf("reseting blkid probe buffer\n"));
217 memset(pr
->buf
, 0, pr
->buf_max
);
221 memset(pr
->sbbuf
, 0, BLKID_SB_BUFSIZ
);
227 * Removes chain values from probing result.
229 void blkid_probe_chain_reset_vals(blkid_probe pr
, struct blkid_chain
*chn
)
231 int nvals
= pr
->nvals
;
234 for (x
= 0, i
= 0; i
< pr
->nvals
; i
++) {
235 struct blkid_prval
*v
= &pr
->vals
[i
];
237 if (v
->chain
!= chn
&& x
== i
) {
241 if (v
->chain
== chn
) {
245 memcpy(&pr
->vals
[x
++], v
, sizeof(struct blkid_prval
));
251 * Copies chain values from probing result to @vals, the max size of @vals is
252 * @nvals and returns real number of values.
254 int blkid_probe_chain_copy_vals(blkid_probe pr
, struct blkid_chain
*chn
,
255 struct blkid_prval
*vals
, int nvals
)
259 for (x
= 0, i
= 0; i
< pr
->nvals
&& x
< nvals
; i
++) {
260 struct blkid_prval
*v
= &pr
->vals
[i
];
264 memcpy(&vals
[x
++], v
, sizeof(struct blkid_prval
));
270 * Appends values from @vals to the probing result
272 void blkid_probe_append_vals(blkid_probe pr
, struct blkid_prval
*vals
, int nvals
)
276 while (i
< nvals
&& pr
->nvals
< BLKID_NVALS
) {
277 memcpy(&pr
->vals
[pr
->nvals
++], &vals
[i
++],
278 sizeof(struct blkid_prval
));
282 static void blkid_probe_reset_vals(blkid_probe pr
)
284 memset(pr
->vals
, 0, sizeof(pr
->vals
));
288 struct blkid_chain
*blkid_probe_get_chain(blkid_probe pr
)
290 return pr
->cur_chain
;
293 void *blkid_probe_get_binary_data(blkid_probe pr
, struct blkid_chain
*chn
)
301 chn
->idx
= -1; /* start probing from scratch */
304 rc
= chn
->driver
->probe(pr
, chn
);
307 pr
->cur_chain
= NULL
;
313 printf("returning %s binary data\n", chn
->driver
->name
));
322 * Cleanup probing result. This function does not touch probing filters
323 * and keeps assigned device.
325 void blkid_reset_probe(blkid_probe pr
)
332 blkid_probe_reset_buffer(pr
);
333 blkid_probe_reset_vals(pr
);
335 for (i
= 0; i
< BLKID_NCHAINS
; i
++)
336 pr
->chains
[i
].idx
= -1;
340 static int blkid_probe_dump_filter(blkid_probe pr, int chain)
342 struct blkid_chain *chn;
345 if (!pr || chain < 0 || chain >= BLKID_NCHAINS)
348 chn = &pr->chains[chain];
353 for (i = 0; i < chn->driver->nidinfos; i++) {
354 const struct blkid_idinfo *id = chn->driver->idinfos[i];
356 DBG(DEBUG_LOWPROBE, printf("%d: %s: %s\n",
359 blkid_bmp_get_item(chn->fltr, i)
360 ? "disabled" : "enabled <--"));
367 * Returns properly initialized chain filter
369 unsigned long *blkid_probe_get_filter(blkid_probe pr
, int chain
, int create
)
371 struct blkid_chain
*chn
;
373 if (!pr
|| chain
< 0 || chain
>= BLKID_NCHAINS
)
376 chn
= &pr
->chains
[chain
];
378 /* always when you touch the chain filter all indexes are reseted and
379 * probing starts from scratch
382 pr
->cur_chain
= NULL
;
384 if (!chn
->driver
->has_fltr
|| (!chn
->fltr
&& !create
))
388 chn
->fltr
= calloc(1, blkid_bmp_nbytes(chn
->driver
->nidinfos
));
390 memset(chn
->fltr
, 0, blkid_bmp_nbytes(chn
->driver
->nidinfos
));
392 /* blkid_probe_dump_filter(pr, chain); */
397 * Generic private functions for filter setting
399 int __blkid_probe_invert_filter(blkid_probe pr
, int chain
)
402 struct blkid_chain
*chn
;
405 fltr
= blkid_probe_get_filter(pr
, chain
, FALSE
);
409 chn
= &pr
->chains
[chain
];
411 for (i
= 0; i
< blkid_bmp_nwords(chn
->driver
->nidinfos
); i
++)
414 DBG(DEBUG_LOWPROBE
, printf("probing filter inverted\n"));
415 /* blkid_probe_dump_filter(pr, chain); */
419 int __blkid_probe_reset_filter(blkid_probe pr
, int chain
)
421 return blkid_probe_get_filter(pr
, chain
, FALSE
) ? 0 : -1;
424 int __blkid_probe_filter_types(blkid_probe pr
, int chain
, int flag
, char *names
[])
427 struct blkid_chain
*chn
;
430 fltr
= blkid_probe_get_filter(pr
, chain
, TRUE
);
434 chn
= &pr
->chains
[chain
];
436 for (i
= 0; i
< chn
->driver
->nidinfos
; i
++) {
438 const struct blkid_idinfo
*id
= chn
->driver
->idinfos
[i
];
441 for (n
= names
; *n
; n
++) {
442 if (!strcmp(id
->name
, *n
)) {
447 if (flag
& BLKID_FLTR_ONLYIN
) {
449 blkid_bmp_set_item(fltr
, i
);
450 } else if (flag
& BLKID_FLTR_NOTIN
) {
452 blkid_bmp_set_item(fltr
, i
);
457 printf("%s: a new probing type-filter initialized\n",
459 /* blkid_probe_dump_filter(pr, chain); */
464 * Note that we have two offsets:
466 * 1/ general device offset (pr->off), that's useful for example when we
467 * probe a partition from whole disk image:
468 * blkid-low --offset <partition_position> disk.img
470 * 2/ buffer offset (the 'off' argument), that useful for offsets in
473 * That means never use lseek(fd, 0, SEEK_SET), the zero position is always
474 * pr->off, so lseek(fd, pr->off, SEEK_SET).
477 unsigned char *blkid_probe_get_buffer(blkid_probe pr
,
478 blkid_loff_t off
, blkid_loff_t len
)
480 ssize_t ret_read
= 0;
482 if (off
< 0 || len
< 0) {
484 printf("unexpected offset or length of buffer requested\n"));
487 if (off
+ len
<= BLKID_SB_BUFSIZ
) {
489 pr
->sbbuf
= malloc(BLKID_SB_BUFSIZ
);
493 if (!pr
->sbbuf_len
) {
494 if (lseek(pr
->fd
, pr
->off
, SEEK_SET
) < 0)
496 ret_read
= read(pr
->fd
, pr
->sbbuf
, BLKID_SB_BUFSIZ
);
499 pr
->sbbuf_len
= ret_read
;
501 if (off
+ len
> pr
->sbbuf_len
)
503 return pr
->sbbuf
+ off
;
505 unsigned char *newbuf
= NULL
;
507 if (len
> pr
->buf_max
) {
508 newbuf
= realloc(pr
->buf
, len
);
516 if (newbuf
|| off
< pr
->buf_off
||
517 off
+ len
> pr
->buf_off
+ pr
->buf_len
) {
519 if (blkid_llseek(pr
->fd
, pr
->off
+ off
, SEEK_SET
) < 0)
522 ret_read
= read(pr
->fd
, pr
->buf
, len
);
523 if (ret_read
!= (ssize_t
) len
)
528 return off
? pr
->buf
+ (off
- pr
->buf_off
) : pr
->buf
;
533 * blkid_probe_set_device:
535 * @fd: device file descriptor
536 * @off: begin of probing area
537 * @size: size of probing area (zero means whole device/file)
539 * Assigns the device to probe control struct, resets internal buffers and
540 * reads 512 bytes from device to the buffers.
542 * Returns: -1 in case of failure, or 0 on success.
544 int blkid_probe_set_device(blkid_probe pr
, int fd
,
545 blkid_loff_t off
, blkid_loff_t size
)
550 blkid_reset_probe(pr
);
552 if ((pr
->flags
& BLKID_PRIVATE_FD
) && pr
->fd
>= 0)
555 pr
->flags
&= ~BLKID_PRIVATE_FD
;
571 pr
->mode
= sb
.st_mode
;
573 if (S_ISBLK(sb
.st_mode
))
574 blkdev_get_size(fd
, (unsigned long long *) &pr
->size
);
575 else if (S_ISCHR(sb
.st_mode
))
576 pr
->size
= 1; /* UBI devices are char... */
577 else if (S_ISREG(sb
.st_mode
))
578 pr
->size
= sb
.st_size
; /* regular file */
580 if (S_ISBLK(sb
.st_mode
) || S_ISCHR(sb
.st_mode
))
581 pr
->devno
= sb
.st_rdev
;
587 DBG(DEBUG_LOWPROBE
, printf("ready for low-probing, offset=%zd, size=%zd\n",
592 printf("failed to prepare a device for low-probing\n"));
597 int blkid_probe_get_dimension(blkid_probe pr
,
598 blkid_loff_t
*off
, blkid_loff_t
*size
)
608 int blkid_probe_set_dimension(blkid_probe pr
,
609 blkid_loff_t off
, blkid_loff_t size
)
614 DBG(DEBUG_LOWPROBE
, printf(
615 "changing probing area: size=%llu, off=%llu "
616 "-to-> size=%llu, off=%llu\n",
617 (unsigned long long) pr
->size
,
618 (unsigned long long) pr
->off
,
619 (unsigned long long) size
,
620 (unsigned long long) off
));
625 blkid_probe_reset_buffer(pr
);
634 * Calls probing functions in all enabled chains. The superblocks chain is
635 * enabled by default. The blkid_do_probe() stores result from only one
636 * probing function. It's necessary to call this routine in a loop to get
637 * resuluts from all probing functions in all chains.
639 * This is string-based NAME=value interface only.
642 * <title>basic case - use the first result only</title>
645 * if (blkid_do_probe(pr) == 0) {
646 * int nvals = blkid_probe_numof_values(pr);
647 * for (n = 0; n < nvals; n++) {
648 * if (blkid_probe_get_value(pr, n, &name, &data, &len) == 0)
649 * printf("%s = %s\n", name, data);
656 * <title>advanced case - probe for all signatures</title>
659 * while (blkid_do_probe(pr) == 0) {
660 * int nvals = blkid_probe_numof_values(pr);
666 * See also blkid_reset_probe().
668 * Returns: 0 on success, 1 when probing is done and -1 in case of error.
670 int blkid_do_probe(blkid_probe pr
)
678 struct blkid_chain
*chn
;
681 pr
->cur_chain
= &pr
->chains
[0];
683 int idx
= pr
->cur_chain
->driver
->id
+ 1;
685 if (idx
< BLKID_NCHAINS
)
686 pr
->cur_chain
= &pr
->chains
[idx
];
688 return 1; /* all chains already probed */
692 chn
->binary
= FALSE
; /* for sure... */
694 DBG(DEBUG_LOWPROBE
, printf("chain probe %s %s\n",
696 chn
->enabled
? "ENABLED" : "DISABLED"));
701 /* rc: -1 = error, 0 = success, 1 = no result */
702 rc
= chn
->driver
->probe(pr
, chn
);
710 * blkid_do_safeprobe:
713 * This function gathers probing results from all enabled chains and checks
714 * for ambivalent results (e.g. more filesystems on the device).
716 * This is string-based NAME=value interface only.
718 * Note about suberblocks chain -- the function does not check for filesystems
719 * when a RAID signature is detected. The function also does not check for
720 * collision between RAIDs. The first detected RAID is returned.
722 * Returns: 0 on success, 1 if nothing is detected, -2 if ambivalen result is
723 * detected and -1 on case of error.
725 int blkid_do_safeprobe(blkid_probe pr
)
727 int i
, count
= 0, rc
= 0;
732 for (i
= 0; i
< BLKID_NCHAINS
; i
++) {
733 struct blkid_chain
*chn
;
735 chn
= pr
->cur_chain
= &pr
->chains
[i
];
736 chn
->binary
= FALSE
; /* for sure... */
738 DBG(DEBUG_LOWPROBE
, printf("chain safeprobe %s %s\n",
740 chn
->enabled
? "ENABLED" : "DISABLED"));
747 /* rc: -2 ambivalent, -1 = error, 0 = success, 1 = no result */
748 rc
= chn
->driver
->safeprobe(pr
, chn
);
750 goto done
; /* error */
752 count
++; /* success */
756 pr
->cur_chain
= NULL
;
759 return count
? 0 : 1;
763 * blkid_do_fullprobe:
766 * This function gathers probing results from all enabled chains. Same as
767 * blkid_so_safeprobe() but does not check for collision between probing
770 * This is string-based NAME=value interface only.
772 * Returns: 0 on success, 1 if nothing is detected or -1 on case of error.
774 int blkid_do_fullprobe(blkid_probe pr
)
776 int i
, count
= 0, rc
= 0;
781 for (i
= 0; i
< BLKID_NCHAINS
; i
++) {
783 struct blkid_chain
*chn
;
785 chn
= pr
->cur_chain
= &pr
->chains
[i
];
786 chn
->binary
= FALSE
; /* for sure... */
788 DBG(DEBUG_LOWPROBE
, printf("chain fullprobe %s: %s\n",
790 chn
->enabled
? "ENABLED" : "DISABLED"));
797 /* rc: -1 = error, 0 = success, 1 = no result */
798 rc
= chn
->driver
->probe(pr
, chn
);
800 goto done
; /* error */
802 count
++; /* success */
806 pr
->cur_chain
= NULL
;
809 return count
? 0 : 1;
812 /* same sa blkid_probe_get_buffer() but works with 512-sectors */
813 unsigned char *blkid_probe_get_sector(blkid_probe pr
, unsigned int sector
)
815 return pr
? blkid_probe_get_buffer(pr
,
816 ((blkid_loff_t
) sector
) << 9, 0x200) : NULL
;
819 struct blkid_prval
*blkid_probe_assign_value(
820 blkid_probe pr
, const char *name
)
822 struct blkid_prval
*v
;
826 if (pr
->nvals
>= BLKID_NVALS
)
829 v
= &pr
->vals
[pr
->nvals
];
831 v
->chain
= pr
->cur_chain
;
835 printf("assigning %s [%s]\n", name
, v
->chain
->driver
->name
));
839 int blkid_probe_set_value(blkid_probe pr
, const char *name
,
840 unsigned char *data
, size_t len
)
842 struct blkid_prval
*v
;
844 if (len
> BLKID_PROBVAL_BUFSIZ
)
845 len
= BLKID_PROBVAL_BUFSIZ
;
847 v
= blkid_probe_assign_value(pr
, name
);
851 memcpy(v
->data
, data
, len
);
856 int blkid_probe_vsprintf_value(blkid_probe pr
, const char *name
,
857 const char *fmt
, va_list ap
)
859 struct blkid_prval
*v
;
862 v
= blkid_probe_assign_value(pr
, name
);
866 len
= vsnprintf((char *) v
->data
, sizeof(v
->data
), fmt
, ap
);
869 pr
->nvals
--; /* reset the latest assigned value */
876 int blkid_probe_sprintf_value(blkid_probe pr
, const char *name
,
877 const char *fmt
, ...)
883 rc
= blkid_probe_vsprintf_value(pr
, name
, fmt
, ap
);
890 * blkid_probe_get_devno:
893 * Returns: block device number, or 0 for regilar files.
895 dev_t
blkid_probe_get_devno(blkid_probe pr
)
900 if (fstat(pr
->fd
, &sb
) == 0 &&
901 (S_ISBLK(sb
.st_mode
) || S_ISCHR(sb
.st_mode
)))
902 pr
->devno
= sb
.st_rdev
;
908 * blkid_probe_get_size:
911 * Returns: block device (or file) size in bytes or -1 in case of error.
913 blkid_loff_t
blkid_probe_get_size(blkid_probe pr
)
915 return pr
? pr
->size
: -1;
919 * blkid_probe_get_sectorsize:
922 * Returns: block device hardware sector size (BLKSSZGET ioctl, default 512).
924 unsigned int blkid_probe_get_sectorsize(blkid_probe pr
)
927 return DEFAULT_SECTOR_SIZE
; /*... and good luck! */
933 if (fstat(pr
->fd
, &st
))
935 pr
->mode
= st
.st_mode
;
937 if (S_ISBLK(pr
->mode
)) {
938 if (blkdev_get_sector_size(pr
->fd
, (int *) &pr
->blkssz
))
945 pr
->blkssz
= DEFAULT_SECTOR_SIZE
;
950 * blkid_probe_numof_values:
953 * Returns: number of values in probing result or -1 in case of error.
955 int blkid_probe_numof_values(blkid_probe pr
)
963 * blkid_probe_get_value:
965 * @num: wanted value in range 0..N, where N is blkid_probe_numof_values() - 1
966 * @name: pointer to return value name or NULL
967 * @data: pointer to return value data or NULL
968 * @len: pointer to return value length or NULL
970 * Note, the @len returns length of the @data, including the terminating
973 * Returns: 0 on success, or -1 in case of error.
975 int blkid_probe_get_value(blkid_probe pr
, int num
, const char **name
,
976 const char **data
, size_t *len
)
978 struct blkid_prval
*v
= __blkid_probe_get_value(pr
, num
);
985 *data
= (char *) v
->data
;
989 DBG(DEBUG_LOWPROBE
, printf("returning %s value\n", v
->name
));
994 * blkid_probe_lookup_value:
996 * @name: name of value
997 * @data: pointer to return value data or NULL
998 * @len: pointer to return value length or NULL
1000 * Note, the @len returns length of the @data, including the terminating
1003 * Returns: 0 on success, or -1 in case of error.
1005 int blkid_probe_lookup_value(blkid_probe pr
, const char *name
,
1006 const char **data
, size_t *len
)
1008 struct blkid_prval
*v
= __blkid_probe_lookup_value(pr
, name
);
1013 *data
= (char *) v
->data
;
1016 DBG(DEBUG_LOWPROBE
, printf("returning %s value\n", v
->name
));
1021 * blkid_probe_has_value:
1023 * @name: name of value
1025 * Returns: 1 if value exist in probing result, otherwise 0.
1027 int blkid_probe_has_value(blkid_probe pr
, const char *name
)
1029 if (blkid_probe_lookup_value(pr
, name
, NULL
, NULL
) == 0)
1034 struct blkid_prval
*__blkid_probe_get_value(blkid_probe pr
, int num
)
1036 if (pr
== NULL
|| num
< 0 || num
>= pr
->nvals
)
1039 return &pr
->vals
[num
];
1042 struct blkid_prval
*__blkid_probe_lookup_value(blkid_probe pr
, const char *name
)
1046 if (pr
== NULL
|| pr
->nvals
== 0 || name
== NULL
)
1049 for (i
= 0; i
< pr
->nvals
; i
++) {
1050 struct blkid_prval
*v
= &pr
->vals
[i
];
1052 if (v
->name
&& strcmp(name
, v
->name
) == 0) {
1053 DBG(DEBUG_LOWPROBE
, printf("returning %s value\n", v
->name
));
1061 /* converts DCE UUID (uuid[16]) to human readable string
1062 * - the @len should be always 37 */
1063 void blkid_unparse_uuid(const unsigned char *uuid
, char *str
, size_t len
)
1066 uuid_unparse(uuid
, str
);
1069 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1070 uuid
[0], uuid
[1], uuid
[2], uuid
[3],
1074 uuid
[10], uuid
[11], uuid
[12], uuid
[13], uuid
[14],uuid
[15]);
1079 /* Removes whitespace from the right-hand side of a string (trailing
1082 * Returns size of the new string (without \0).
1084 size_t blkid_rtrim_whitespace(unsigned char *str
)
1086 size_t i
= strlen((char *) str
);
1089 if (!isspace(str
[i
]))