Skip to content

Commit 0df15ad

Browse files
committed
udf{info,label,tune}: Migrate common code into {read,update}disc.[ch]
1 parent 370d8c6 commit 0df15ad

File tree

9 files changed

+471
-685
lines changed

9 files changed

+471
-685
lines changed

udfinfo/main.c

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -38,52 +38,6 @@
3838
#include "options.h"
3939
#include "readdisc.h"
4040

41-
static uint64_t get_size(int fd)
42-
{
43-
struct stat st;
44-
uint64_t size;
45-
off_t offset;
46-
47-
if (fstat(fd, &st) == 0)
48-
{
49-
if (S_ISBLK(st.st_mode) && ioctl(fd, BLKGETSIZE64, &size) == 0)
50-
return size;
51-
else if (S_ISREG(st.st_mode))
52-
return st.st_size;
53-
}
54-
55-
offset = lseek(fd, 0, SEEK_END);
56-
if (offset == (off_t)-1)
57-
{
58-
fprintf(stderr, "%s: Error: Cannot detect size of disk: %s\n", appname, strerror(errno));
59-
exit(1);
60-
}
61-
62-
if (lseek(fd, 0, SEEK_SET) != 0)
63-
{
64-
fprintf(stderr, "%s: Error: Cannot seek to start of disk: %s\n", appname, strerror(errno));
65-
exit(1);
66-
}
67-
68-
return offset;
69-
}
70-
71-
static int get_sector_size(int fd)
72-
{
73-
int size;
74-
75-
if (ioctl(fd, BLKSSZGET, &size) != 0)
76-
return 0;
77-
78-
if (size < 512 || size > 32768 || (size & (size - 1)))
79-
{
80-
fprintf(stderr, "%s: Warning: Disk logical sector size (%d) is not suitable for UDF\n", appname, size);
81-
return 0;
82-
}
83-
84-
return size;
85-
}
86-
8741
static uint32_t compute_windows_serial_num(struct udf_disc *disc)
8842
{
8943
uint8_t *buffer = (uint8_t *)disc->udf_fsd;

udfinfo/readdisc.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,3 +2398,49 @@ int read_disc(int fd, struct udf_disc *disc)
23982398

23992399
return 0;
24002400
}
2401+
2402+
uint64_t get_size(int fd)
2403+
{
2404+
struct stat st;
2405+
uint64_t size;
2406+
off_t offset;
2407+
2408+
if (fstat(fd, &st) == 0)
2409+
{
2410+
if (S_ISBLK(st.st_mode) && ioctl(fd, BLKGETSIZE64, &size) == 0)
2411+
return size;
2412+
else if (S_ISREG(st.st_mode))
2413+
return st.st_size;
2414+
}
2415+
2416+
offset = lseek(fd, 0, SEEK_END);
2417+
if (offset == (off_t)-1)
2418+
{
2419+
fprintf(stderr, "%s: Error: Cannot detect size of disk: %s\n", appname, strerror(errno));
2420+
exit(1);
2421+
}
2422+
2423+
if (lseek(fd, 0, SEEK_SET) != 0)
2424+
{
2425+
fprintf(stderr, "%s: Error: Cannot seek to start of disk: %s\n", appname, strerror(errno));
2426+
exit(1);
2427+
}
2428+
2429+
return offset;
2430+
}
2431+
2432+
int get_sector_size(int fd)
2433+
{
2434+
int size;
2435+
2436+
if (ioctl(fd, BLKSSZGET, &size) != 0)
2437+
return 0;
2438+
2439+
if (size < 512 || size > 32768 || (size & (size - 1)))
2440+
{
2441+
fprintf(stderr, "%s: Warning: Disk logical sector size (%d) is not suitable for UDF\n", appname, size);
2442+
return 0;
2443+
}
2444+
2445+
return size;
2446+
}

udfinfo/readdisc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
#ifndef READDISC_H
2020
#define READDISC_H
2121

22+
#include <linux/fs.h>
23+
2224
struct udf_disc;
2325

26+
uint64_t get_size(int);
27+
int get_sector_size(int);
2428
int read_disc(int, struct udf_disc *);
2529

2630
#endif /* READDISC_H */

udflabel/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
sbin_PROGRAMS = udflabel
22
udflabel_LDADD = $(top_builddir)/libudffs/libudffs.la
3-
udflabel_SOURCES = main.c options.c ../udfinfo/readdisc.c options.h ../udfinfo/readdisc.h ../include/ecma_167.h ../include/osta_udf.h ../include/libudffs.h ../include/bswap.h
3+
udflabel_SOURCES = main.c options.c ../udfinfo/readdisc.c ../udftune/updatedisc.c options.h ../udftune/updatedisc.h ../udfinfo/readdisc.h ../include/ecma_167.h ../include/osta_udf.h ../include/libudffs.h ../include/bswap.h
44
AM_CPPFLAGS = -I$(top_srcdir)/include

0 commit comments

Comments
 (0)