summaryrefslogtreecommitdiffstats
path: root/libsmartcols/src
Commit message (Expand)AuthorAgeFilesLines
* build-sys: remove generated headers from dist tar ballRuediger Meier2018-01-221-4/+1Star
* include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()Karel Zak2018-01-171-1/+1
* include/debug: don't print pointer address for SUID programsKarel Zak2018-01-121-0/+3
* libsmartcols: don't add blank padding after left aligned titleKarel Zak2017-12-121-4/+12
* misc: fix typosSami Kerola2017-11-281-1/+1
* libsmartcols: (sample) cleanup line separator usageKarel Zak2017-10-121-1/+2
* libsmartcols: (docs) add note about line separatorsKarel Zak2017-10-121-0/+4
* libsmartcols: don't call free_buffer() for uninitialized variable [coverity s...Karel Zak2017-10-111-2/+3
* libsmartcols: fix scols_line_move_cells() n+1 error [asan]Karel Zak2017-09-181-2/+2
* libsmartcols: fix heap-buffer-overflow when move columnsKarel Zak2017-09-151-4/+6
* libsmartcols: fix comment (to make gtk-docs happy)Karel Zak2017-07-311-1/+1
* libsmartcols: add scols_table_enable_noencoding()Karel Zak2017-07-315-18/+74
* misc: remove stray semicolonsSami Kerola2017-06-141-1/+1
* misc: fix reassigned values before old ones has been used [cppcheck]Sami Kerola2017-06-141-1/+1
* libsmartcols: fix warning "unused parameter"Ruediger Meier2017-06-131-2/+7
* libsmartcols: add header-repeat featureKarel Zak2017-06-135-3/+67
* libsmartcols: add missing symbolsKarel Zak2017-06-121-0/+6
* libsmartcols: add scols_table_{set,get}_termheight()Karel Zak2017-06-123-3/+42
* lib/ttyutils: return terminal lines tooKarel Zak2017-06-121-0/+4
* libsmartcols: (docs) add missing 'since' tagsKarel Zak2017-05-233-1/+11
* libsmartcols: check scols_table_set_default_symbols() return code [coverity s...Karel Zak2017-05-171-1/+3
* libsmartcols: add scols_line_is_ancestor()Karel Zak2017-05-053-0/+21
* libsmartcols: add debug mesg to see width changeKarel Zak2017-05-021-0/+1
* libsmartcols: fix typoKarel Zak2017-04-131-2/+2
* libsmartcols: add scols_sort_table_by_tree()Karel Zak2017-04-133-2/+56
* libsmartcols: fix relative width interpretationKarel Zak2017-04-072-5/+5
* libsmartcols: column width reduction refactoringKarel Zak2017-04-072-32/+80
* libsmartcols: add scols_line_move_cells()Karel Zak2017-04-073-3/+50
* libsmartcols: add scols_table_move_column()Karel Zak2017-04-073-0/+34
* libsmartcols: allow to add column to already used tableKarel Zak2017-03-031-7/+18
* libsmartcols: support columns separators greater than one output cellKarel Zak2017-03-022-4/+6
* libsmartcols: add scols_cell_get_alignment()Karel Zak2017-01-094-9/+38
* Merge branch 'ignatenko/libsmartcols-dead' of https://github.com/ignatenkobra...Karel Zak2017-01-091-2/+2
|\
| * libsmartcols: remove dead checksIgor Gnatenko2016-12-191-2/+2
* | libsmartcols: unused parameter [-Wunused-parameter]Karel Zak2017-01-051-2/+9
|/
* misc: fix typos using codespellRuediger Meier2016-12-012-3/+3
* libsmartcols: make scols_sort_table() usable for treesKarel Zak2016-11-021-3/+50
* libsmartcols: add scols_column_add_width()Karel Zak2016-09-303-0/+22
* libsmartcols: custom wrap fixesKarel Zak2016-09-273-8/+6Star
* docs: some random fixesKarel Zak2016-09-272-4/+6
* libsmartcols: (docs) add missing version notesKarel Zak2016-09-273-1/+20
* libsmartcols: fixes in doc generationIgor Gnatenko2016-09-275-30/+30
* libsmartcols: support custom wrap and remove SCOLS_FL_WRAPNLKarel Zak2016-09-265-56/+193
* Merge branch 'getters' of https://github.com/ignatenkobrain/util-linuxKarel Zak2016-09-233-3/+48
|\
| * libsmartcols: add scols_table_is_nolinesep()Igor Gnatenko2016-09-233-2/+17
| * libsmartcols: add scols_table_is_nowrap()Igor Gnatenko2016-09-233-1/+16
| * libsmartcols: add scols_table_get_name()Igor Gnatenko2016-09-233-0/+15
* | libsmartcols: cleanup scols_table_set_symbols() APIKarel Zak2016-09-235-34/+101
|/
* libsmartcols: use const qualifier for scols_table_get_termwidthIgor Gnatenko2016-09-232-2/+2
* Merge branch 'api_const' of https://github.com/ignatenkobrain/util-linuxKarel Zak2016-09-238-74/+67Star
|\
100 committer Karel Zak 2006-12-07 00:25:34 +0100 Imported from util-linux-2.7.1 tarball.' href='/openslx/kernel-qcow2-util-linux.git/commit/mount/lomount.c?h=kernel-qcow2&id=fd6b7a7ffc50400704beb41d5a23af5f9edb1eed'>fd6b7a7ff ^
6dbe3af94













6dbe3af94
6dbe3af94

fd6b7a7ff ^


6dbe3af94


fd6b7a7ff ^





6dbe3af94
fd6b7a7ff ^










6dbe3af94
fd6b7a7ff ^







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
                                                                     



                                            








                                             
                  


                      
                     
 

                    
 


                                                                        
                  



                          




                            

  

                             


        




                                                     

 


                   



                                              


                                    

 
            




                            
                                           















                                                              




















































                                                                              
                                                     



                                                                
                                                                    



                                                                          
                                                       



                                                          

   

                                                           

                            
                       

             







                                               
   

                                       

             
                               




                                                                        
                                                                     













































                                                                             

                                                                  













                                                         
                                  

             


                                              


           





                                                                               
 










                                                           
 







                                
/* Taken from Ted's losetup.c - Mitch <m.dsouza@mrc-apu.cam.ac.uk> */
/* Added vfs mount options - aeb - 960223 */
/* Removed lomount - aeb - 960224 */

#define PROC_DEVICES	"/proc/devices"

/*
 * losetup.c - setup and control loop devices
 */

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/stat.h>

#include "loop.h"
#include "lomount.h"

char *xstrdup (const char *s);		/* not: #include "sundries.h" */
void error (const char *fmt, ...);	/* idem */

#ifdef LOOP_SET_FD
struct crypt_type_struct {
  int id;
  char *name;
} crypt_type_tbl[] = {
  { LO_CRYPT_NONE, "no" },
  { LO_CRYPT_NONE, "none" },
  { LO_CRYPT_XOR, "xor" },
  { LO_CRYPT_DES, "DES" },
  { -1, NULL   }
};

static int 
crypt_type (const char *name)
{
  int i;

  if (name)
    for (i = 0; crypt_type_tbl[i].id != -1; i++)
      if (!strcasecmp (name, crypt_type_tbl[i].name))
	return crypt_type_tbl[i].id;
  return -1;
}

#if 0
static char *
crypt_name (int id)
{
  int i;

  for (i = 0; crypt_type_tbl[i].id != -1; i++)
    if (id == crypt_type_tbl[i].id)
      return crypt_type_tbl[i].name;
  return "undefined";
}

static void 
show_loop (char *device)
{
  struct loop_info loopinfo;
  int fd;

  if ((fd = open (device, O_RDONLY)) < 0) {
    fprintf(stderr, "loop: can't open device %s: %s\n",
	    device, strerror (errno));
    return;
  }
  if (ioctl (fd, LOOP_GET_STATUS, &loopinfo) < 0) {
    fprintf(stderr, "loop: can't get info on device %s: %s\n",
	    device, strerror (errno));
    close (fd);
    return;
  }
  printf ("%s: [%04x]:%ld (%s) offset %d, %s encryption\n",
	  device, loopinfo.lo_device, loopinfo.lo_inode,
	  loopinfo.lo_name, loopinfo.lo_offset,
	  crypt_name (loopinfo.lo_encrypt_type));
  close (fd);
}
#endif

char *
find_unused_loop_device (void)
{
    /* Just creating a device, say in /tmp, is probably a bad idea -
       people might have problems with backup or so.
       So, we just try /dev/loop[0-7]. */
    char dev[20];
    int i, fd, somedev = 0, someloop = 0, loop_known = 0;
    struct stat statbuf;
    struct loop_info loopinfo;
    FILE *procdev;

    for(i = 0; i < 256; i++) {
      sprintf(dev, "/dev/loop%d", i);
      if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
	somedev++;
	fd = open (dev, O_RDONLY);
	if (fd >= 0) {
	  if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == 0)
	    someloop++;			/* in use */
	  else if (errno == ENXIO) {
	    close (fd);
	    return xstrdup(dev);	/* probably free */
	  }
	  close (fd);
        }
	continue;		/* continue trying as long as devices exist */
      }
      if (i >= 7)
	break;
    }

    /* Nothing found. Why not? */
    if ((procdev = fopen(PROC_DEVICES, "r")) != NULL) {
      char line[100];
      while (fgets (line, sizeof(line), procdev))
	if (strstr (line, " loop\n")) {
	  loop_known = 1;
	  break;
	}
      fclose(procdev);
      if (!loop_known)
	loop_known = -1;
    }

    if (!somedev)
      error("mount: could not find any device /dev/loop#");
    else if(!someloop) {
      if (loop_known == 1)
	error(
"mount: Could not find any loop device.\n"
"       Maybe /dev/loop# has a wrong major number?");
      else if (loop_known == -1)
	error(
"mount: Could not find any loop device, and, according to %s,\n"
"       this kernel does not know about the loop device.\n"
"       (If so, then recompile or `insmod loop.o'.)", PROC_DEVICES);
      else
	error(
"mount: Could not find any loop device. Maybe this kernel does not know\n"
"       about the loop device (then recompile or `insmod loop.o'), or\n"
"       maybe /dev/loop# has the wrong major number?");
    } else
      error("mount: could not find any free loop device");
    return 0;
}

int
set_loop (const char *device, const char *file, int offset,
	  const char *encryption, int *loopro)
{
  struct loop_info loopinfo;
  int fd, ffd, mode, i;
  char *pass;

  mode = (*loopro ? O_RDONLY : O_RDWR);
  if ((ffd = open (file, mode)) < 0) {
       if (!*loopro && errno == EROFS)
	    ffd = open (file, mode = O_RDONLY);
       if (ffd < 0) {
	    perror (file);
	    return 1;
       }
  }
  if ((fd = open (device, mode)) < 0) {
    perror (device);
    return 1;
  }
  *loopro = (mode == O_RDONLY);
  memset (&loopinfo, 0, sizeof (loopinfo));
  strncpy (loopinfo.lo_name, file, LO_NAME_SIZE);
  loopinfo.lo_name[LO_NAME_SIZE - 1] = 0;
  if (encryption && (loopinfo.lo_encrypt_type = crypt_type (encryption))
      < 0) {
    fprintf (stderr, "Unsupported encryption type %s\n", encryption);
    return 1;
  }
  loopinfo.lo_offset = offset;
  switch (loopinfo.lo_encrypt_type) {
  case LO_CRYPT_NONE:
    loopinfo.lo_encrypt_key_size = 0;
    break;
  case LO_CRYPT_XOR:
    pass = getpass ("Password: ");
    strncpy (loopinfo.lo_encrypt_key, pass, LO_KEY_SIZE);
    loopinfo.lo_encrypt_key[LO_KEY_SIZE - 1] = 0;
    loopinfo.lo_encrypt_key_size = strlen (loopinfo.lo_encrypt_key);
    break;
  case LO_CRYPT_DES:
    pass = getpass ("Password: ");
    strncpy (loopinfo.lo_encrypt_key, pass, 8);
    loopinfo.lo_encrypt_key[8] = 0;
    loopinfo.lo_encrypt_key_size = 8;
    pass = getpass ("Init (up to 16 hex digits): ");
    for (i = 0; i < 16 && pass[i]; i++)
      if (isxdigit (pass[i]))
	loopinfo.lo_init[i >> 3] |= (pass[i] > '9' ?
				     (islower (pass[i]) ? toupper (pass[i]) :
			pass[i]) - 'A' + 10 : pass[i] - '0') << (i & 7) * 4;
      else {
	fprintf (stderr, "Non-hex digit '%c'.\n", pass[i]);
	return 1;
      }
    break;
  default:
    fprintf (stderr,
	     "Don't know how to get key for encryption system %d\n",
	     loopinfo.lo_encrypt_type);
    return 1;
  }
  if (ioctl (fd, LOOP_SET_FD, ffd) < 0) {
    perror ("ioctl: LOOP_SET_FD");
    return 1;
  }
  if (ioctl (fd, LOOP_SET_STATUS, &loopinfo) < 0) {
    (void) ioctl (fd, LOOP_CLR_FD, 0);
    perror ("ioctl: LOOP_SET_STATUS");
    return 1;
  }
  close (fd);
  close (ffd);
  if (verbose > 1)
    printf("set_loop(%s,%s,%d): success\n", device, file, offset);
  return 0;
}

int 
del_loop (const char *device)
{
  int fd;

  if ((fd = open (device, O_RDONLY)) < 0) {
    fprintf(stderr, "loop: can't delete device %s: %s\n",
	    device, strerror (errno));
    return 1;
  }
  if (ioctl (fd, LOOP_CLR_FD, 0) < 0) {
    perror ("ioctl: LOOP_CLR_FD");
    return 1;
  }
  close (fd);
  if (verbose > 1)
    printf("del_loop(%s): success\n", device);
  return 0;
}

#else /* no LOOP_SET_FD defined */
static void
mutter(void) {
  fprintf(stderr,
	  "This mount was compiled without loop support. Please recompile.\n");
}  

int
set_loop (const char *device, const char *file, int offset,
	  const char *encryption, int *loopro) {
  mutter();
  return 1;
}

int
del_loop (const char *device) {
  mutter();
  return 1;
}

char *
find_unused_loop_device (void) {
  mutter();
  return 0;
}

#endif